示例#1
0
 /**
  * Convert a file to the EPackage containing a metamodel.
  *
  * @param iFile The file that is to be converted to the Epackage.
  * @return The EPackage containing the metamodel loaded from the file.
  * @throws CodeGenerationException
  */
 protected EPackage fileToEPack(IFile iFile) throws CodeGenerationException {
   ResourceSet resSet = new ResourceSetImpl();
   resSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap());
   URI fileURI =
       URI.createPlatformResourceURI(
           "/" + iFile.getProject().getName() + "/" + iFile.getProjectRelativePath().toString(),
           true);
   Resource resource = resSet.createResource(fileURI);
   Map<Object, Object> options = new HashMap<Object, Object>();
   options.put(XMLResource.OPTION_ENCODING, "UTF-8");
   try {
     resource.load(options);
   } catch (IOException e) {
     throw new CodeGenerationException(
         "Error while loading resource of File: " + iFile.getName(), e.getCause());
   }
   EList<EObject> sd = resource.getContents();
   for (EObject object : sd) {
     if (object instanceof EPackage) {
       EPackage ePack = (EPackage) object;
       pi.setNsURI(ePack.getNsURI());
       return ePack;
     }
   }
   return null;
 }
  private void initializeEditingDomain() {
    editingDomain =
        new AdapterFactoryEditingDomain(adapterFactory, new EFactoryCommandStack(), resourceSet) {
          @Override
          public boolean isReadOnly(Resource resource) {
            return super.isReadOnly(resource)
                || getResourceSet().getResources().indexOf(resource) != 0;
          }
        };

    resourceSet.eAdapters().add(new EditingDomainProvider());
    resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(true));
  }