Exemplo n.º 1
0
 public void propertyChange(PropertyChangeEvent event) {
   if (event.getProperty().equals(TefkatPlugin.URIMAP_PREFERENCE)) {
     if (null != event.getOldValue()) {
       List list = TefkatPlugin.convertFromString((String) event.getOldValue());
       for (final Iterator itr = list.iterator(); itr.hasNext(); ) {
         URIMap map = (URIMap) itr.next();
         if (map.enabled) {
           URI uri = URI.createURI(map.source);
           URIConverter.URI_MAP.remove(uri);
         }
       }
     }
     if (null != event.getNewValue()) {
       List list = TefkatPlugin.convertFromString((String) event.getNewValue());
       for (final Iterator itr = list.iterator(); itr.hasNext(); ) {
         URIMap map = (URIMap) itr.next();
         if (map.enabled) {
           URI sourceUri = URI.createURI(map.source);
           URI targetUri = URI.createURI(map.target);
           URIConverter.URI_MAP.put(sourceUri, targetUri);
         }
       }
     }
   }
 }
Exemplo n.º 2
0
  public void registerResourceFactories() {
    // in case a old version from last run is registered here
    EPackage.Registry.INSTANCE.remove("http://www.emftext.org/sdk/concretesyntax");
    registerFactory("cs", new CsResourceFactory());

    // TODO: the rest of this method is never used in our build scripts at the moment
    for (GenModelElement genModelElement : genModels) {
      String namespaceURI = genModelElement.getNamespaceURI();
      String genModelURI = genModelElement.getGenModelURI();
      try {
        log("Registering genmodel " + namespaceURI + " at " + genModelURI);

        // We ignore the deprecation warning until the method is not available
        // anymore to keep this code runnable against old versions of EMF as
        // long as possible.
        @SuppressWarnings("deprecation")
        Map<String, URI> ePackageNsURIToGenModelLocationMap =
            EcorePlugin.getEPackageNsURIToGenModelLocationMap();
        ePackageNsURIToGenModelLocationMap.put(namespaceURI, URI.createURI(genModelURI));

        // register a mapping for "resource:/plugin/..." URIs in case
        // one genmodel imports another genmodel using this URI
        String filesSystemURI = genModelURI;
        int startIdx = filesSystemURI.indexOf("/plugins");
        int versionStartIdx = filesSystemURI.indexOf("_", startIdx);
        int filePathStartIdx = filesSystemURI.lastIndexOf("!/") + 1;
        if (startIdx > -1 && versionStartIdx > startIdx && filePathStartIdx > versionStartIdx) {
          String platformPluginURI =
              "platform:" + filesSystemURI.substring(startIdx, versionStartIdx);
          platformPluginURI = platformPluginURI + filesSystemURI.substring(filePathStartIdx);
          platformPluginURI = platformPluginURI.replace("/plugins/", "/plugin/");

          // gen model
          log("adding mapping from " + platformPluginURI + " to " + filesSystemURI);
          URIConverter.URI_MAP.put(URI.createURI(platformPluginURI), URI.createURI(filesSystemURI));

          // ecore model (this code assumes that both files are named equally)
          filesSystemURI = filesSystemURI.replace(".genmodel", ".ecore");
          platformPluginURI = platformPluginURI.replace(".genmodel", ".ecore");
          log("adding mapping from " + platformPluginURI + " to " + filesSystemURI);
          URIConverter.URI_MAP.put(URI.createURI(platformPluginURI), URI.createURI(filesSystemURI));
        }
      } catch (Exception e) {
        throw new BuildException("Error while registering genmodel " + namespaceURI, e);
      }
    }

    for (GenPackageElement genPackage : genPackages) {
      String namespaceURI = genPackage.getNamespaceURI();
      String ePackageClassName = genPackage.getEPackageClassName();
      try {
        log("registering ePackage " + namespaceURI + " at " + ePackageClassName);
        Field factoryInstance = Class.forName(ePackageClassName).getField("eINSTANCE");
        Object ePackageObject = factoryInstance.get(null);
        EPackage.Registry.INSTANCE.put(namespaceURI, ePackageObject);
      } catch (Exception e) {
        e.printStackTrace();
        throw new BuildException("Error while registering EPackage " + namespaceURI, e);
      }
    }
  }