@Override public Resource createResource(URI uri) { return new XMIResourceImpl(uri); } }
@Override public Resource createResource(URI uri) { return new XMIResourceImpl(uri); } }
XMIResource resource = new XMIResourceImpl(URI.create("file:/path/to/mymodel.xmi")); resource.load(null); System.out.println( resource.eContents().get(0) );
XMIResourceImpl resource = new XMIResourceImpl(); File source = new File(fileName); resource.load( new FileInputStream(source), new HashMap<Object,Object>()); Data data = (Data)resource.getContents().get(0);
XMIResourceImpl resource = new XMIResourceImpl(); File source = new File(xmlName.xml); resource.load( new FileInputStream(source), new HashMap<Object,Object>()); Data data = (Data)resource.getContents().get(0);
ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("arxml", new XMIResourceImpl()); URI uri = URI.createURI("http://example.myorganization.com/"); Resource res = resourceSet.createResource(uri); // TODO add some content here // res.getContents().add(...) try{ resource.save(new FileOutputStream("D:/User/file.xml")); java.lang.System.out.println("success"); } catch (IOException e){ java.lang.System.out.print("no"); }
@Override protected Entry<ComponentFactory> createService ( final UserInformation userInformation, final String configurationId, final BundleContext context, final Map<String, String> parameters ) throws Exception { final ConfigurationDataHelper cfg = new ConfigurationDataHelper ( parameters ); final String xml = cfg.getStringNonEmpty ( "configuration" ); final XMIResource xmi = new XMIResourceImpl (); final Map<?, ?> options = new HashMap<Object, Object> (); final InputSource is = new InputSource ( new StringReader ( xml ) ); xmi.load ( is, options ); final Object c = EcoreUtil.getObjectByType ( xmi.getContents (), ParserPackage.Literals.COMPONENT ); if ( ! ( c instanceof Component ) ) { throw new RuntimeException ( String.format ( "Configuration did not contain an object of type %s", Component.class.getName () ) ); } final ComponentFactoryWrapper wrapper = new ComponentFactoryWrapper ( this.executor, (Component)c ); final Dictionary<String, ?> properties = new Hashtable<> (); final ServiceRegistration<ComponentFactory> handle = context.registerService ( ComponentFactory.class, wrapper, properties ); return new Entry<ComponentFactory> ( configurationId, wrapper, handle ); }
public Resource createResource(URI uri) { XMIResourceImpl resource = new XMIResourceImpl(uri); // make it a binary resource resource.getDefaultLoadOptions().put(XMLResource.OPTION_BINARY, Boolean.TRUE); resource.getDefaultSaveOptions().put(XMLResource.OPTION_BINARY, Boolean.TRUE); // don't do any resolution, since the only external references point to Ecore elements from EPackages in the registry. XMLResource.URIHandler uriHandler = new XMLResource.URIHandler() { public void setBaseURI(URI uri) { } public URI resolve(URI uri) { return uri; } public URI deresolve(URI uri) { return uri; } }; resource.getDefaultLoadOptions().put(XMLResource.OPTION_URI_HANDLER, uriHandler); resource.getDefaultSaveOptions().put(XMLResource.OPTION_URI_HANDLER, uriHandler); return resource; }
@Override public void close() throws IOException { byte[] bytes = toByteArray(); InputStream in = new ByteArrayInputStream(bytes); XMIResource xmiResource = new XMIResourceImpl(); xmiResource.load(in, null); String path = getPath(); getWorkspaceStore().setLastModified(path, System.currentTimeMillis()); SaveContext saveContext = getWorkspaceStore().getSaveContext(); saveContext.save(xmiResource, path); } };