示例#1
0
文件: Ecore2AS.java 项目: eclipse/ocl
  public static Ecore2AS loadFromEcore(@NonNull ASResource ecoreASResource, @NonNull URI ecoreURI) {
    EnvironmentFactoryInternal environmentFactory =
        PivotUtilInternal.getEnvironmentFactory(ecoreASResource);
    ResourceSet resourceSet = environmentFactory.getResourceSet();
    Resource ecoreResource = resourceSet.getResource(ecoreURI, true);
    if (ecoreResource == null) {
      return null;
    }
    Ecore2AS conversion = getAdapter(ecoreResource, environmentFactory);
    conversion.loadImports(ecoreResource);
    //		if (asMetamodels != null) {
    //
    //		}
    PivotMetamodelManager metamodelManager = environmentFactory.getMetamodelManager();
    conversion.pivotModel = PivotUtil.createModel(ecoreASResource.getURI().toString());
    //		conversion.installImports();
    conversion.update(ecoreASResource, ClassUtil.nonNullEMF(ecoreResource.getContents()));

    AliasAdapter ecoreAdapter = AliasAdapter.findAdapter(ecoreResource);
    if (ecoreAdapter != null) {
      Map<EObject, String> ecoreAliasMap = ecoreAdapter.getAliasMap();
      AliasAdapter pivotAdapter = AliasAdapter.getAdapter(ecoreASResource);
      Map<EObject, String> pivotAliasMap = pivotAdapter.getAliasMap();
      for (EObject eObject : ecoreAliasMap.keySet()) {
        String alias = ecoreAliasMap.get(eObject);
        Element element = conversion.newCreateMap.get(eObject);
        pivotAliasMap.put(element, alias);
      }
    }
    metamodelManager.installResource(ecoreASResource);
    conversion.installImports();
    return conversion;
  }
 @SuppressWarnings("null")
 protected org.eclipse.ocl.pivot.Class getType(Type typeType) {
   if (typeType instanceof CollectionType) {
     CollectionType domainCollectionType = (CollectionType) typeType;
     return environmentFactory
         .getCompleteEnvironment()
         .getCollectionType(
             domainCollectionType.getContainerType(),
             domainCollectionType.getElementType(),
             domainCollectionType.isIsNullFree(),
             null,
             null);
   }
   if (typeMap == null) {
     typeMap = new HashMap<Type, org.eclipse.ocl.pivot.Class>();
   } else {
     org.eclipse.ocl.pivot.Class type = typeMap.get(typeType);
     if (type != null) {
       return type;
     }
   }
   if (packageMap == null) {
     packageMap = new HashMap<org.eclipse.ocl.pivot.Package, org.eclipse.ocl.pivot.Package>();
   }
   org.eclipse.ocl.pivot.Package domainPackage =
       ((org.eclipse.ocl.pivot.Class) typeType).getOwningPackage();
   org.eclipse.ocl.pivot.Package pivotPackage = packageMap.get(domainPackage);
   PivotMetamodelManager metamodelManager = environmentFactory.getMetamodelManager();
   if (pivotPackage == null) {
     String nsURI = domainPackage.getURI();
     if (nsURI != null) {
       pivotPackage = metamodelManager.getPrimaryPackage(nsURI);
     }
     if (pivotPackage == null) {
       pivotPackage = createPackage(domainPackage);
     }
   }
   @NonNull CompletePackage completePackage = metamodelManager.getCompletePackage(pivotPackage);
   return completePackage.getMemberType(typeType.getName());
 }