private static QvtOperationalModuleEnv initLibEnvironment(Library lib, Module libModule) {
    EPackage.Registry registry = new EPackageRegistryImpl();
    QvtOperationalModuleEnv libEnv =
        new QvtOperationalEnvFactory(registry).createModuleEnvironment(libModule);

    EPackage.Registry libEnvRegistry = libEnv.getEPackageRegistry();
    // set our desired stdlib version to be resolved by oclstdlib package name
    EPackage oclStdlibPackage = libEnv.getOCLStandardLibrary().getOclAny().getEPackage();
    libEnv.getEPackageRegistry().put(oclStdlibPackage.getNsURI(), oclStdlibPackage);

    if (lib.getInMetamodels() != null) {
      for (String mm : lib.getInMetamodels()) {
        EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(mm);
        if (ePackage != null) {
          libEnvRegistry.put(mm, ePackage);
        }
      }
    }
    if (lib.getOutMetamodels() != null) {
      for (String mm : lib.getOutMetamodels()) {
        EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(mm);
        if (ePackage != null) {
          libEnvRegistry.put(mm, ePackage);
        }
      }
    }
    return libEnv;
  }
Exemple #2
0
 /**
  * sets the org.eclipse.uml2.uml.resources uri for standalone execution
  *
  * @param pathToUMLResources which is typically "../org.eclipse.uml2.uml.resources"
  */
 public void setUmlResourcesUri(String pathToUMLResources) {
   File f = new File(pathToUMLResources);
   if (!f.exists())
     throw new ConfigurationException(
         "The pathToUMLResources location '" + pathToUMLResources + "' does not exist");
   if (!f.isDirectory())
     throw new ConfigurationException("The pathToUMLResources location must point to a directory");
   String path = f.getAbsolutePath();
   try {
     path = f.getCanonicalPath();
   } catch (IOException e) {
     log.error("Error when registering UML Resources location", e);
   }
   log.info("Registering UML Resources uri '" + path + "'");
   ResourceSet targetResourceSet = null;
   Resource.Factory.Registry resourceFactoryRegistry =
       targetResourceSet != null
           ? targetResourceSet.getResourceFactoryRegistry()
           : Resource.Factory.Registry.INSTANCE;
   resourceFactoryRegistry
       .getExtensionToFactoryMap()
       .put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
   resourceFactoryRegistry
       .getExtensionToFactoryMap()
       .put(CMOF2UMLResource.FILE_EXTENSION, CMOF2UMLResource.Factory.INSTANCE);
   Map<URI, URI> uriMap =
       targetResourceSet != null
           ? targetResourceSet.getURIConverter().getURIMap()
           : URIConverter.URI_MAP;
   //	uriMap.put(URI.createURI(UMLEnvironment.OCL_STANDARD_LIBRARY_NS_URI),
   // URI.createFileURI(oclLocation + "/model/oclstdlib.uml")); //$NON-NLS-1$
   uriMap.put(
       URI.createURI(UMLResource.PROFILES_PATHMAP),
       URI.createFileURI(path + "/profiles/")); // $NON-NLS-1$
   uriMap.put(
       URI.createURI(UMLResource.METAMODELS_PATHMAP),
       URI.createFileURI(path + "/metamodels/")); // $NON-NLS-1$
   uriMap.put(
       URI.createURI(UMLResource.LIBRARIES_PATHMAP),
       URI.createFileURI(path + "/libraries/")); // $NON-NLS-1$
   EPackage.Registry registry2 = registry; // Workaround JDT invisible class anomally
   registry2.put(Ecore2XMLPackage.eNS_URI, Ecore2XMLPackage.eINSTANCE);
   UMLPlugin.getEPackageNsURIToProfileLocationMap()
       .put(
           "http://www.eclipse.org/uml2/schemas/Ecore/5",
           URI.createURI("pathmap://UML_PROFILES/Ecore.profile.uml#_0"));
   UMLPlugin.getEPackageNsURIToProfileLocationMap()
       .put(
           "http://www.eclipse.org/uml2/schemas/Standard/1",
           URI.createURI("pathmap://UML_PROFILES/Standard.profile.uml#_0"));
 }
  /**
   * Registers metamodel for use with this environment.
   *
   * @return the metamodel package denoted by the given <code>URI</code> or <code>null</code> if no
   *     package was resolved
   */
  static List<EPackage> registerMetamodel(
      QvtOperationalEnv qvtEnv, String metamodelUri, List<String> path) {
    EPackage.Registry registry = qvtEnv.getFactory().getEPackageRegistry();
    List<EPackage> metamodels = new ArrayList<EPackage>(1);

    try {
      List<EPackage> desc = Collections.emptyList();
      if (metamodelUri != null && path.isEmpty()) {
        EPackage ePackage = registry.getEPackage(metamodelUri);
        if (ePackage != null) {
          desc = Collections.singletonList(ePackage);
        } else {
          ePackage = MetamodelRegistry.tryLookupEmptyRootPackage(metamodelUri, registry);
          if (ePackage != null) {
            desc = Collections.singletonList(ePackage);
          }
        }
      } else {
        desc = MetamodelRegistry.resolveMetamodels(registry, path);
      }

      for (EPackage model : desc) {
        // register meta-model for EClassifier lookup
        if (model.getNsURI() == null) {
          while (true) {
            if (model.getESuperPackage() == null) {
              break;
            }
            model = model.getESuperPackage();
          }
        }

        metamodels.add(model);
        if (metamodelUri != null) {
          qvtEnv.getEPackageRegistry().put(metamodelUri, model);
        }

        // break;
      }
    } catch (EmfException e) {
      // It's legal situation of unresolved metamodels
    }
    return metamodels;
  }
  private ExtendedMetaData getExtendedMetaData() {
    if (extendedMetaData == null) {
      final ResourceSet resourceSet = new ResourceSetImpl();
      final EPackage.Registry ePackageRegistry = resourceSet.getPackageRegistry();

      ePackageRegistry.put(BEFORE_NS_URI, PartitioncontainmentPackage.eINSTANCE);
      ePackageRegistry.put(AFTER_PLATFORM_URI, PartitioncontainmentPackage.eINSTANCE);

      Ecore2XMLRegistry ecore2xmlRegistry = new Ecore2XMLRegistryImpl(Ecore2XMLRegistry.INSTANCE);
      ecore2xmlRegistry.put(
          BEFORE_NS_URI,
          EcoreUtil.getObjectByType(
              resourceSet.getResource(URI.createURI(BEFORE_PLATFORM_URI), true).getContents(),
              Ecore2XMLPackage.Literals.XML_MAP));

      extendedMetaData = new Ecore2XMLExtendedMetaData(ePackageRegistry, ecore2xmlRegistry);
    }
    return extendedMetaData;
  }