Exemple #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;
 }
Exemple #2
0
 /**
  * Load all transitively referenced *.ecore files and identify any EPackages identified as OCL AS
  * Metamodels.
  */
 protected void loadImports(@NonNull Resource ecoreResource) {
   URI baseURI = getBaseURI(ecoreResource);
   for (EObject eContent : ecoreResource.getContents()) {
     if (eContent instanceof EPackage) {
       loadImports((EPackage) eContent, baseURI);
     }
   }
   if ((asMetamodels != null) && (metamodelManager.getLibraryResource() == null)) {
     String nsURI = asMetamodels.iterator().next().getNsURI();
     if (nsURI != null) {
       //				String stdlibASUri = LibraryConstants.STDLIB_URI +
       // PivotConstants.DOT_OCL_AS_FILE_EXTENSION;
       OCLstdlib library = OCLstdlib.getDefault(); // create(stdlibASUri, "ocl", "ocl", nsURI);
       //				metamodelManager.addPackageNsURISynonym(OCLstdlib.STDLIB_URI,
       // PivotConstants.METAMODEL_URI);
       metamodelManager.installResource(library);
       //				metamodelManager.installAs(nsURI, OCLstdlibTables.PACKAGE);
     }
   }
 }