Example #1
0
 @Override
 public @NonNull Model getASModel() {
   Model pivotModel2 = pivotModel;
   if (pivotModel2 == null) {
     loadImports(ecoreResource);
     pivotModel2 =
         pivotModel =
             importObjects(ClassUtil.nonNullEMF(ecoreResource.getContents()), createPivotURI());
     @SuppressWarnings("null")
     @NonNull
     Resource asResource = pivotModel2.eResource();
     AliasAdapter ecoreAdapter = AliasAdapter.findAdapter(ecoreResource);
     if (ecoreAdapter != null) {
       Map<EObject, String> ecoreAliasMap = ecoreAdapter.getAliasMap();
       AliasAdapter pivotAdapter = AliasAdapter.getAdapter(asResource);
       Map<EObject, String> pivotAliasMap = pivotAdapter.getAliasMap();
       for (EObject eObject : ecoreAliasMap.keySet()) {
         String alias = ecoreAliasMap.get(eObject);
         Element element = newCreateMap.get(eObject);
         pivotAliasMap.put(element, alias);
       }
     }
     metamodelManager.installResource(asResource);
     installImports();
   }
   return pivotModel2;
 }
Example #2
0
  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;
  }