/** * Registers an {@link XMIResourceFactoryImpl} for the given extension. * @param ext The extension as a String. */ public static void registerExtensionForXmiSerializer(String ext) { Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; Map<String, Object> m = reg.getExtensionToFactoryMap(); m.computeIfAbsent(ext, e -> new XMIResourceFactoryImpl()); }
public void registerResourceFactories(ResourceSet resourceSet) { super.registerResourceFactories(resourceSet); // code added by me resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("systembehavior", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("peerbehavior", new XMIResourceFactoryImpl()); }
protected static void setDefaultResourceFactory() { //This is not done outside of Eclipse if (Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().get(Resource.Factory.Registry.DEFAULT_EXTENSION) == null) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); }
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); }
public static void initializeDefaults() { //EMF Standalone setup if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "ecore", new EcoreResourceFactoryImpl()); if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "xmi", new XMIResourceFactoryImpl()); if (!EPackage.Registry.INSTANCE.containsKey(EcorePackage.eNS_URI)) EPackage.Registry.INSTANCE.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE); if (!EPackage.Registry.INSTANCE.containsKey(XtextPackage.eNS_URI)) EPackage.Registry.INSTANCE.put(XtextPackage.eNS_URI, XtextPackage.eINSTANCE); }
ResourceSet resourceSet = new ResourceSetImpl(); // register UML Map packageRegistry = resourceSet.getPackageRegistry(); packageRegistry.put(list.ListPackage.eNS_URI, list.ListPackage.eINSTANCE); // Register XML resource as UMLResource.Factory.Instance Map extensionFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); extensionFactoryMap.put("xmi", new XMIResourceFactoryImpl()); Resource resource = (Resource) resourceSet.createResource(uri); // try to load the file into resource resource.load(null);
public static void initializeDefaults() { //EMF Standalone setup if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "ecore", new EcoreResourceFactoryImpl()); if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "xmi", new XMIResourceFactoryImpl()); if (!EPackage.Registry.INSTANCE.containsKey(EcorePackage.eNS_URI)) EPackage.Registry.INSTANCE.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE); if (!EPackage.Registry.INSTANCE.containsKey(XtextPackage.eNS_URI)) EPackage.Registry.INSTANCE.put(XtextPackage.eNS_URI, XtextPackage.eINSTANCE); }
public static void initializeDefaults() { //EMF Standalone setup if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "ecore", new EcoreResourceFactoryImpl()); if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "xmi", new XMIResourceFactoryImpl()); if (!EPackage.Registry.INSTANCE.containsKey(EcorePackage.eNS_URI)) EPackage.Registry.INSTANCE.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE); if (!EPackage.Registry.INSTANCE.containsKey(XtextPackage.eNS_URI)) EPackage.Registry.INSTANCE.put(XtextPackage.eNS_URI, XtextPackage.eINSTANCE); }
protected void registerCrossx() { // Create a resource set to hold the resources. // EPackage.Registry.INSTANCE.put(CrossxPackage.eNS_URI, CrossxPackage.eINSTANCE); ResourceSet resourceSet = new ResourceSetImpl(); // Register the appropriate resource factory to handle all file extensions. // resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put (Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); // Register the package to ensure it is available during loading. // resourceSet.getPackageRegistry().put (CrossxPackage.eNS_URI, CrossxPackage.eINSTANCE); }
protected void registerCrossx() { // Create a resource set to hold the resources. // EPackage.Registry.INSTANCE.put(CrossxPackage.eNS_URI, CrossxPackage.eINSTANCE); ResourceSet resourceSet = new ResourceSetImpl(); // Register the appropriate resource factory to handle all file extensions. // resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put (Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); // Register the package to ensure it is available during loading. // resourceSet.getPackageRegistry().put (CrossxPackage.eNS_URI, CrossxPackage.eINSTANCE); }
/* * load existing EPackage */ EcorePackage.eINSTANCE.eClass(); /*Initialize your EPackage*/ final Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; final Map<String, Object> m = reg.getExtensionToFactoryMap(); m.put(EcorePackage.eNAME, new XMIResourceFactoryImpl()); final ResourceSet resSet = new ResourceSetImpl(); Resource resource = null; try { resource = resSet.getResource(URI.createFileURI("/Your/Path/To/Directory/myTest.ecore"), true); } catch (Exception e) { e.printStackTrace(); } /*load root and cast to EPackage*/ final EPackage root = (EPackage) resource.getContents().get(0);
private void registerDefaultFactories() { if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore")) { Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); } if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi")) { Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); } if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xtextbin")) { Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xtextbin", new BinaryGrammarResourceFactoryImpl()); } if (!EPackage.Registry.INSTANCE.containsKey(XtextPackage.eNS_URI)) { EPackage.Registry.INSTANCE.put(XtextPackage.eNS_URI, XtextPackage.eINSTANCE); } }
public Injector createInjectorAndDoEMFRegistration() { // register default ePackages if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "ecore", new org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl()); if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "xmi", new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl()); if (!EPackage.Registry.INSTANCE.containsKey(org.eclipse.xtext.XtextPackage.eNS_URI)) EPackage.Registry.INSTANCE.put(org.eclipse.xtext.XtextPackage.eNS_URI, org.eclipse.xtext.XtextPackage.eINSTANCE); Injector injector = createInjector(); register(injector); return injector; }
/** * Factory method: Instantiates a new default {@link ResourceSet}. * * <p> * The new resource set will always have the XMI factory associated with the "*.xmi" file ending. * * @param ePackages * The {@link EPackage}s to register at the resource set. Must not be <code>null</code>. * * @return The new resource set. Never <code>null</code>. */ public static ResourceSet createResourceSet(final Set<EPackage> ePackages) { checkNotNull(ePackages, "Precondition violation - argument 'ePackages' must not be NULL!"); ResourceSet resSet = new ResourceSetImpl(); // make sure that XMI is available resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); for (EPackage ePackage : ePackages) { resSet.getPackageRegistry().put(ePackage.getNsURI(), ePackage); } return resSet; }
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; Map<String, Object> m = reg.getExtensionToFactoryMap(); m.put("key", new XMIResourceFactoryImpl()); ResourceSet resSet = new ResourceSetImpl(); Resource resource = resSet.createResource(URI.createFileURI(fileName)); resource.getContents().add(data); resource.save(Collections.EMPTY_MAP);
/** * Saves the given meta model project to the given file. * * @param file * The file in which the project will be stored. * @param project * The meta model project. * * @throws IOException * If something went wrong during the saving. */ public static final void saveProjectToFile(final File file, final MIProject project) throws IOException { // Create a resource and put the given project into it final ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()); final Resource resource = resourceSet.createResource(URI.createFileURI(file.getAbsolutePath())); resource.getContents().add(project); // Make sure that the controller uses utf8 instead of ascii. final Map<String, String> options = new HashMap<String, String>(); // NOPMD (no concurrent access) options.put(XMLResource.OPTION_ENCODING, "UTF-8"); // Now try to save the resource resource.save(options); }
public Injector createInjectorAndDoEMFRegistration() { // register default ePackages if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "ecore", new org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl()); if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "xmi", new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl()); if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xtextbin")) Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "xtextbin", new org.eclipse.xtext.resource.impl.BinaryGrammarResourceFactoryImpl()); if (!EPackage.Registry.INSTANCE.containsKey(org.eclipse.xtext.XtextPackage.eNS_URI)) EPackage.Registry.INSTANCE.put(org.eclipse.xtext.XtextPackage.eNS_URI, org.eclipse.xtext.XtextPackage.eINSTANCE); Injector injector = createInjector(); register(injector); return injector; }
/** * Saves the given meta model project to the given file. * * @param file * The file in which the project will be stored. * @param project * The meta model project. * * @throws IOException * If something went wrong during the saving. */ public static final void saveProjectToFile(final File file, final MIProject project) throws IOException { // Create a resource and put the given project into it final ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()); final Resource resource = resourceSet.createResource(URI.createFileURI(file.getAbsolutePath())); resource.getContents().add(project); // Make sure that the controller uses utf8 instead of ascii. final Map<String, String> options = new HashMap<String, String>(); // NOPMD (no concurrent access) options.put(XMLResource.OPTION_ENCODING, "UTF-8"); // Now try to save the resource resource.save(options); }
/* * Save your EPackage to file ecore file: */ /*Initialize your EPackage*/ myPackage.eClass(); Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; Map<String, Object> m = reg.getExtensionToFactoryMap(); /*add default .ecore extension for ecore file*/ m.put(EcorePackage.eNAME, new XMIResourceFactoryImpl()); // Obtain a new resource set ResourceSet resSet = new ResourceSetImpl(); // create a resource Resource resource = null; try { resource = resSet.createResource(URI.createFileURI("/Your/Path/To/Directory/myTest.ecore")); } catch (Exception e) { e.printStackTrace(); } /*add your EPackage as root, everything is hierarchical included in this first node*/ resource.getContents().add(myPackage); // now save the content. try { resource.save(Collections.EMPTY_MAP); } catch (IOException e) { e.printStackTrace(); }
/** * */ public void generate(final File output, final File ecoreFile) { final ResourceSet rs = new ResourceSetImpl(); rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new XMIResourceFactoryImpl()); if (ecoreFile != null && ecoreFile.exists()) { final URI uri = URI.createFileURI(ecoreFile.getAbsolutePath()); final Resource r = rs.getResource(uri, true); final List<EObject> objList = r.getContents(); for (final EObject obj : objList) { try { manageObject(output, obj); } catch (final IOException e) { e.printStackTrace(); } } } }