@Override protected void setUp() throws Exception { resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put (Resource.Factory.Registry.DEFAULT_EXTENSION, new ColorResourceFactoryImpl()); resourceSet.getPackageRegistry().put (ColorPackage.eNS_URI, ColorPackage.eINSTANCE); }
private static URIConverter getUriConverter(ResourceSet resourceSet) { URIConverter uriConverter = resourceSet.getURIConverter(); return uriConverter; }
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); } } }
@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); } }
public void testImportElement() throws Exception { XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); inResource.setEncoding("UTF-8"); XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); outResource.setEncoding("UTF-8");
ResourceSet resourceSet = xsdSchema.eResource().getResourceSet(); Resource resolvedResource = resourceSet.getResource( URI.createURI( resolvedSchemaLocationURI == null
/** * Remove all references to this schema, and all schemas built in the same resource set It is * important to call this method for every dynamic schema created that is not needed anymore, * because references in the static schema's will otherwise keep it alive forever */ public void dispose() { if (schema != null) { ResourceSet rs = schema.eResource().getResourceSet(); for (Resource r : rs.getResources()) { if (r instanceof XSDResourceImpl) { Schemas.dispose(((XSDResourceImpl) r).getSchema()); } } schema = null; } } }
@BeforeClass public static void oneTimeSetUp() { reader = EmfComplexFeatureReader.newInstance(); // need to register custom factory to load schema resources Resource.Factory.Registry.INSTANCE .getExtensionToFactoryMap() .put("xsd", new XSDResourceFactoryImpl()); }
ResourceSet resourceSet = ResourceSetFactory.createResourceSet(); Resource resource = resourceSet.getResource(xmlURI, true); resource.load(Collections.EMPTY_MAP); EObject root = resource.getContents().get(0);
/** * Fetches the contents of the URI into a byte[]. * * @param uri * @param options * @param response * @return The resource data * @throws IOException */ private static byte[] readUriResource(URI uri, ResourceSet resourceSet, Map<?, ?> response) throws IOException { Map<Object, Object> options = resourceSet.getLoadOptions(); URIConverter uriConverter = getUriConverter(resourceSet); Map<Object, Object> loadMap = new HashMap<>(options); loadMap.put(URIConverter.OPTION_RESPONSE, response); ByteArrayOutputStream out = new ByteArrayOutputStream(); try (InputStream inputStream = uriConverter.createInputStream(uri, loadMap)) { IOUtils.copy(inputStream, out); } return out.toByteArray(); }
/** * Creates an input stream for the URI, assuming it's a URL, and returns it. * * @return an open input stream. * @exception IOException if there is a problem obtaining an open input stream. */ @Override public InputStream createInputStream(URI uri, Map<?, ?> options) throws IOException { try { final HttpURLConnection httpConnection = getConnection(uri); httpConnection.setConnectTimeout(connectionTimeout); httpConnection.setReadTimeout(readTimeout); InputStream result = httpConnection.getInputStream(); Map<Object, Object> response = getResponse(options); if (response != null) { response.put( URIConverter.RESPONSE_TIME_STAMP_PROPERTY, httpConnection.getLastModified()); } return result; } catch (RuntimeException exception) { throw new Resource.IOWrappedException(exception); } }
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); } }
@Override protected void setUp() throws Exception { resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put (Resource.Factory.Registry.DEFAULT_EXTENSION, new DroolsResourceFactoryImpl()); resourceSet.getPackageRegistry().put (DroolsPackage.eNS_URI, DroolsPackage.eINSTANCE); }
public void testOnEntryScriptElement() throws Exception { XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); inResource.setEncoding("UTF-8"); XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); outResource.setEncoding("UTF-8");
@Override protected void setUp() throws Exception { resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put (Resource.Factory.Registry.DEFAULT_EXTENSION, new BpsimResourceFactoryImpl()); resourceSet.getPackageRegistry().put (BpsimPackage.eNS_URI, BpsimPackage.eINSTANCE); }
public void testOnExitScriptElement() throws Exception { XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); inResource.setEncoding("UTF-8"); XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); outResource.setEncoding("UTF-8");
public void testGlobalElement() throws Exception { XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); inResource.setEncoding("UTF-8"); XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); outResource.setEncoding("UTF-8");
@SuppressWarnings("unchecked") public void testColorAttributes() throws Exception { XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); inResource.setEncoding("UTF-8"); DocumentRoot documentRoot = ColorFactory.eINSTANCE.createDocumentRoot(); documentRoot.setBackgroundColor("#FFFFFF"); documentRoot.setBorderColor("#000000"); documentRoot.setColor("#AAAAAA"); inResource.getContents().add(documentRoot); DocumentRoot outRoot = (DocumentRoot) inResource.getContents().get(0); assertNotNull(outRoot); assertEquals(outRoot.getBackgroundColor(), "#FFFFFF"); assertEquals(outRoot.getBorderColor(), "#000000"); assertEquals(outRoot.getColor(), "#AAAAAA"); } }
@SuppressWarnings("unchecked") public void testMetadataElement() throws Exception { XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); inResource.setEncoding("UTF-8"); XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); outResource.setEncoding("UTF-8");
@SuppressWarnings("unchecked") public void testBpsimData() throws Exception { XMLResource inResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); inResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); inResource.setEncoding("UTF-8"); XMLResource outResource = (XMLResource) resourceSet.createResource(URI.createURI("inputStream://dummyUriWithValidSuffix.xml")); outResource.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODING, "UTF-8"); outResource.setEncoding("UTF-8");