Refine search
public void writeToEcore(File file) { ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); Resource resource = resourceSet.createResource(URI.createFileURI(file.getAbsolutePath())); for (EPackage ePackage : packages.values()) { resource.getContents().add(ePackage); } try { resource.save(null); } catch (IOException e) { LOGGER.error("", e); } }
public List<GenPackage> createGenPackages(GenModel genModel, VirtualFile basedir) throws DatabaseException { ResourceSetImpl resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); Map<VirtualFile, Resource> resources = new HashMap<VirtualFile, Resource>(); genModel.initialize(schema.getEPackages()); Resource resource = resourceSet.createResource(URI.createURI(ePackage.getName() + ".ecore")); resource.getContents().add(ePackage); VirtualFile ecoreFile = basedir.createFile(MODEL_PACKAGE.replace(".", "/") + ePackage.getName() + "/impl/" + ePackage.getName() + ".ecore"); resources.put(ecoreFile, resource); Resource resource = resources.get(virtualFile); OutputStream openOutputStream = virtualFile.openOutputStream(); resource.save(openOutputStream, null); openOutputStream.close(); } catch (IOException e) {
@SuppressWarnings("rawtypes") public void loadEcore(String name, InputStream inputStream) { ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); Resource resource = resourceSet.createResource(URI.createURI(name)); try { resource.load(inputStream, new HashMap()); for (EObject eObject : resource.getContents()) { if (eObject instanceof EPackage) { EPackage ePackage = (EPackage)eObject; addEPackage(ePackage); } } } catch (IOException e) { LOGGER.error("", e); } }
private static SecurityModel read(final String modelString) throws IOException { final ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); final org.eclipse.emf.ecore.resource.Resource xmlResource = resourceSet.createResource(URI.createURI("dummy.deploy")); //$NON-NLS-1$ // Register the package -- only needed for stand-alone! resourceSet.getPackageRegistry().put(UamPackage.eNS_URI, UamPackage.eINSTANCE); resourceSet.getPackageRegistry().put(ExpressionPackage.eNS_URI, ExpressionPackage.eINSTANCE); resourceSet.getPackageRegistry().put(StdlibPackage.eNS_URI, StdlibPackage.eINSTANCE); final ByteArrayInputStream bais = new ByteArrayInputStream(modelString.getBytes()); xmlResource.load(bais, Collections.emptyMap()); return (SecurityModel) xmlResource.getContents().get(0); }
@Override protected void readTableOfContents(File tocFile) throws IOException { ResourceSet resourceSet = new ResourceSetImpl(); URI fileURI = URI.createFileURI(tocFile.getAbsolutePath()); Resource resource = resourceSet.createResource(fileURI); resource.load(null); ncxTOC = (Ncx) resource.getContents().get(0); }
public void writeEMF(String fileName) { ResourceSet metaResourceSet = new ResourceSetImpl(); metaResourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new XMLResourceFactoryImpl()); URI resUri = URI.createURI(fileName); Resource metaResource = metaResourceSet.createResource(resUri); metaResource.getContents().add(schemaPack); try { metaResource.save(null); } catch (Exception e) { LOGGER.error("", e); } } }
public static final XSDSchema parse( String location, List locators, List resolvers ) throws IOException { //check for case of file url, make sure it is an absolute reference if (new File(location).exists()) { location = new File( location ).getCanonicalFile().toURI().toString(); //location = new File(location).getCanonicalPath(); } URI uri = URI.createURI(location); final ResourceSet resourceSet = new ResourceSetImpl(); //add the specialized schema location resolvers if ((resolvers != null) && !resolvers.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocationResolverAdapterFactory(resolvers); resourceSet.getAdapterFactories().add(adapterFactory); } //add the specialized schema locators as adapters if ((locators != null) && !locators.isEmpty()) { AdapterFactory adapterFactory = new SchemaLocatorAdapterFactory(locators); resourceSet.getAdapterFactories().add(adapterFactory); } XSDResourceImpl xsdMainResource = (XSDResourceImpl) resourceSet .createResource(URI.createURI(".xsd")); // LOGGER.info("About to parse xsd schema: " + uri); xsdMainResource.setURI(uri); xsdMainResource.load(resourceSet.getLoadOptions()); return xsdMainResource.getSchema(); }
Resource resource = schema.eResource(); if (resource == null) { final ResourceSet resourceSet = new ResourceSetImpl(); resource = (XSDResourceImpl) resourceSet.createResource(URI.createURI(".xsd")); resource.getContents().add(schema); schema.getContents().add(imprt); resource.getResourceSet().getAdapterFactories().add(adapterFactory); return imprt;
String location, List locators, List resolvers, List<URIHandler> uriHandlers) throws IOException { ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getAdapterFactories().add(adapterFactory); resourceSet.getAdapterFactories().add(adapterFactory); resourceSet.getURIConverter().getURIHandlers().addAll(0, uriHandlers);
private void save(Model model, XMAComponent xmaComponent) { URI xmaResourceUri = null; if (xmaComponent.eResource() != null) { xmaResourceUri = xmaComponent.eResource().getURI(); xmaComponent = (XMAComponent) EcoreUtil.copy(xmaComponent); } else { xmaResourceUri = model.eResource().getURI().trimFileExtension().appendFileExtension( DslConstants.OPENXMA_XMA_FILE_EXTENSION); } ResourceSet xmaResourceSet = new ResourceSetImpl(); Resource xmaResource = xmaResourceSet.createResource(xmaResourceUri); xmaResource.getContents().add(xmaComponent); try { xmaResource.save(Collections.emptyMap()); } catch (IOException ioException) { throw new WrappedException(ioException); } }
/** * Gets the resource for a model. * * @param modelPath the model path * @return the resource */ public static Resource getResource(String modelPath) { URI modelUri = URI.createFileURI(modelPath); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE); resourceSet.createResource(modelUri); return resourceSet.getResource(modelUri, true); }
private Bpmn2Resource createBpmn2Resource() { DroolsFactoryImpl.init(); BpsimFactoryImpl.init(); ResourceSet rSet = new ResourceSetImpl(); rSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn2", new JBPMBpmn2ResourceFactoryImpl()); Bpmn2Resource resource = (Bpmn2Resource) rSet.createResource(URI.createURI("virtual.bpmn2")); rSet.getResources().add(resource); return resource; }
protected void load () throws Exception { // register model VisualInterfacePackage.eINSTANCE.eClass (); this.symbol = null; final ResourceSet resourceSet = new ResourceSetImpl (); // set resource factory to XMI on extension map resourceSet.getResourceFactoryRegistry ().getExtensionToFactoryMap ().put ( "vi", FACTORY_INSTANCE ); //$NON-NLS-1$ final Resource resource = resourceSet.getResource ( this.uri, true ); this.symbol = (Symbol)EcoreUtil.getObjectByType ( resource.getContents (), VisualInterfacePackage.Literals.SYMBOL ); } }
private static Definitions parseDefinitions(final InputStream inputStream) throws IOException { DroolsPackageImpl.init(); BpsimPackageImpl.init(); final ResourceSet resourceSet = new ResourceSetImpl(); Resource.Factory.Registry resourceFactoryRegistry = resourceSet.getResourceFactoryRegistry(); resourceFactoryRegistry.getExtensionToFactoryMap().put( Resource.Factory.Registry.DEFAULT_EXTENSION, new JBPMBpmn2ResourceFactoryImpl()); EPackage.Registry packageRegistry = resourceSet.getPackageRegistry(); packageRegistry.put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE); packageRegistry.put("http://www.jboss.org/drools", DroolsPackage.eINSTANCE); final JBPMBpmn2ResourceImpl resource = (JBPMBpmn2ResourceImpl) resourceSet .createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8"); resource.setEncoding("UTF-8"); final Map<String, Object> options = new HashMap<>(); options.put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8"); options.put(JBPMBpmn2ResourceImpl.OPTION_DEFER_IDREF_RESOLUTION, true); options.put(JBPMBpmn2ResourceImpl.OPTION_DISABLE_NOTIFY, true); options.put(JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF, JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF_RECORD); resource.load(inputStream, options); final DocumentRoot root = (DocumentRoot) resource.getContents().get(0); return root.getDefinitions(); }
/** * @return resource with security object and package */ public static Resource loadSecurityModel(final URI securityFileURI) { assert securityFileURI != null; // Create a resource set. final ResourceSet resourceSet = new ResourceSetImpl(); try { return resourceSet.getResource(securityFileURI, true); } catch (final Exception e) { // in case of resource not exists final Resource secResource = resourceSet.createResource(securityFileURI); final EPackage secPackage = UamFactory.eINSTANCE.createSecurityModel(); secPackage.setName(getModelName(securityFileURI)); secResource.getContents().add(secPackage); return secResource; } }
/** * Inject the CA bootstrap property to the profile * * @param file * the profile.xml file in the package target * @throws IOException */ protected void patchProfile ( final String appName, final File file ) throws IOException { final ResourceSet rs = new ResourceSetImpl (); final Resource r = rs.createResource ( URI.createFileURI ( file.toString () ) ); r.load ( null ); final Profile profile = (Profile)EcoreUtil.getObjectByType ( r.getContents (), ProfilePackage.Literals.PROFILE ); Profiles.addSystemProperty ( profile, "org.eclipse.scada.ca.file.provisionJsonUrl", "file:///usr/share/eclipsescada/ca.bootstrap/bootstrap." + appName + ".json" ); r.save ( null ); }
/** * Loads the {@code uri} with standard EMF. * * @param uri the URI to load * * @return the the loaded content */ @Nonnull public static EObject load(URI uri) throws IOException { Map<String, Object> options = new HashMap<>(); if (uri.fileExtension().endsWith("zxmi")) { options.put(XMIResource.OPTION_ZIP, true); } Resource resource = new ResourceSetImpl().createResource(uri); resource.load(options); return resource.getContents().get(0); }
protected ZenModel doLoad(URI modelLocation) { validateFile(modelLocation); ResourceSet resourceSet = new ResourceSetImpl(); org.eclipse.emf.ecore.resource.Resource resource = resourceSet.getResource(modelLocation, true); ZenModel model = (ZenModel) resource.getContents().get(0); return model; }
/** * Initializes the standard library package along with its content. */ public AcceleoStandardLibrary() { final ResourceSet resourceSet = new ResourceSetImpl(); /* * Crude workaround : We try not to reload the std lib for no reason, but that means the OCL standard * lib used for our references must be the sole instance used by OCL. FIXME : For now, use internals * ... try and find a way to use it without restricted access. */ resourceSet.getResources().add(OCLStandardLibraryImpl.INSTANCE.getString().eResource()); try { if (stdLibPackage == null) { stdLibPackage = (EPackage)ModelUtils.load(URI.createURI(NS_URI), resourceSet); stringType = (EClass)stdLibPackage.getEClassifier(PRIMITIVE_STRING_NAME); integerType = (EClass)stdLibPackage.getEClassifier(PRIMITIVE_INTEGER_NAME); realType = (EClass)stdLibPackage.getEClassifier(PRIMITIVE_REAL_NAME); } } catch (IOException e) { AcceleoCommonPlugin.log( AcceleoCommonMessages.getString("AcceleoStandardLibrary.LoadFailure"), false); //$NON-NLS-1$ } }
/** * Create the java context. To be used outside of Eclipse. * Within normal Eclipse JEM usage the JEM EMF nature should be used instead. * @return * * @since 1.2.0 */ public static ResourceSet createJavaContext() { org.eclipse.jem.internal.java.init.JavaInit.init(); ResourceSet set = new ResourceSetImpl(); set.getAdapterFactories().add(createJavaReflectionAdapterFactory()); return set; }