Beispiel #1
0
 public @NonNull Model importObjects(
     @NonNull Collection<EObject> ecoreContents, @NonNull URI pivotURI) {
   EPackage libraryEPackage = isLibrary(ecoreContents);
   if (libraryEPackage != null) {
     newCreateMap = new HashMap<@NonNull EObject, @NonNull Element>();
     org.eclipse.ocl.pivot.Package asLibrary = standardLibrary.getPackage();
     newCreateMap.put(libraryEPackage, asLibrary);
     List<org.eclipse.ocl.pivot.Class> ownedType = asLibrary.getOwnedClasses();
     //			int prefix = LibraryConstants.ECORE_STDLIB_PREFIX.length();
     for (@SuppressWarnings("null") @NonNull
     EClassifier eClassifier : libraryEPackage.getEClassifiers()) {
       String name =
           environmentFactory.getTechnology().getOriginalName(eClassifier); // .substring(prefix);
       Type asType = NameUtil.getNameable(ownedType, name);
       if (asType != null) {
         newCreateMap.put(eClassifier, asType);
       }
     }
     Model containingRoot = PivotUtil.getContainingModel(asLibrary);
     return ClassUtil.nonNullModel(containingRoot);
   }
   @NonNull
   ASResource asResource = metamodelManager.getResource(pivotURI, ASResource.ECORE_CONTENT_TYPE);
   //		try {
   if ((metamodelManager.getLibraryResource() == null) && isPivot(ecoreContents)) {
     String nsURI = ((EPackage) ecoreContents.iterator().next()).getNsURI();
     if (nsURI != null) {
       String stdlibASUri = LibraryConstants.STDLIB_URI + PivotConstants.DOT_OCL_AS_FILE_EXTENSION;
       OCLstdlib library = OCLstdlib.create(stdlibASUri);
       metamodelManager.installResource(library);
       //					metamodelManager.installAs(nsURI, OCLstdlibTables.PACKAGE);
     }
   }
   URI uri = ecoreURI != null ? ecoreURI : ecoreResource.getURI();
   Model pivotModel2 = null;
   if (asResource.getContents().size() > 0) {
     EObject eObject = asResource.getContents().get(0);
     if (eObject instanceof Model) {
       pivotModel2 = (Model) eObject;
     }
   }
   if (pivotModel2 == null) {
     pivotModel2 = pivotModel = PivotUtil.createModel(uri.toString());
   }
   pivotModel = pivotModel2;
   //			installImports();
   update(asResource, ecoreContents);
   //		}
   //		catch (Exception e) {
   //			if (errors == null) {
   //				errors = new ArrayList<Resource.Diagnostic>();
   //			}
   //			errors.add(new XMIException("Failed to load '" + pivotURI + "'", e));
   //		}
   List<Diagnostic> errors2 = errors;
   if (errors2 != null) {
     asResource.getErrors().addAll(ClassUtil.nullFree(errors2));
   }
   return pivotModel2;
 }
Beispiel #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;
  }