Java Code Examples for org.eclipse.emf.ecore.resource.ResourceSet#getPackageRegistry()
The following examples show how to use
org.eclipse.emf.ecore.resource.ResourceSet#getPackageRegistry() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main.java From ArduinoML-kernel with GNU Lesser General Public License v3.0 | 6 votes |
private static void ArduinoML2xmi(String modelPath, String destinationPath) throws IOException{ // register ArduinoML ResourceSet resources = new ResourceSetImpl(); Map<String, Object> packageRegistry = resources.getPackageRegistry(); packageRegistry.put(arduinoML.ArduinoMLPackage.eNS_URI, arduinoML.ArduinoMLPackage.eINSTANCE); // load ArduinoML dependencies Injector injector = new ArduinoMLStandaloneSetup().createInjectorAndDoEMFRegistration(); XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class); // load the dsl file and parse it URI uri = URI.createURI(modelPath); Resource xtextResource = resourceSet.getResource(uri, true); EcoreUtil.resolveAll(xtextResource); Resource xmiResource = resourceSet.createResource(URI.createURI(destinationPath)); // add the root (often forgotten) xmiResource.getContents().add(xtextResource.getContents().get(0)); xmiResource.save(null); }
Example 2
Source File: Main.java From ArduinoML-kernel with GNU Lesser General Public License v3.0 | 6 votes |
private static String xmi2NativeArduino(String xmiPath) throws IOException{ // register ArduinoML ResourceSet resourceSet = new ResourceSetImpl(); Map<String, Object> packageRegistry = resourceSet.getPackageRegistry(); packageRegistry.put(arduinoML.ArduinoMLPackage.eNS_URI, arduinoML.ArduinoMLPackage.eINSTANCE); // load the xmi file XMIResource resource = new XMIResourceImpl(URI.createURI("file:"+xmiPath)); resource.load(null); // get the root of the model App app = (App) resource.getContents().get(0); // Launch the visitor on the root ArduinoMLSwitchPrinter visitor = new ArduinoMLSwitchPrinter(); return visitor.doSwitch(app); }
Example 3
Source File: ReleaseUtils.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
/** Extract the namespace URI from a model file using EMF Resource loading. */ public static String getNamespaceURI_Registry(URI modelURI) { final ResourceSet resourceSet = new ResourceSetImpl(); // register delegating package registry final PackageRegistry registry = new PackageRegistry( resourceSet.getPackageRegistry()); resourceSet.setPackageRegistry(registry); final Resource resource = resourceSet.createResource(modelURI); try { resource.load(null); } catch (final Exception e) { // loading should fail here } return registry.getNsURI(); }
Example 4
Source File: EClassifierInfo.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * Determine whether the class represented by {@code left} is either the same as * or is a superclass of the class represented by {@code right}. */ protected boolean isAssignableFrom(EClass left, EClass right) { if (right != null && left.isSuperTypeOf(right)) return true; EClass eObjectType = GrammarUtil.findEObject(grammar); if (left == eObjectType) return true; if (grammar != null) { Resource grammarResource = grammar.eResource(); if (grammarResource != null) { ResourceSet resourceSet = grammarResource.getResourceSet(); if (resourceSet != null) { EPackage.Registry registry = resourceSet.getPackageRegistry(); if (registry != null) { EPackage ecorePackage = registry.getEPackage(EcorePackage.eNS_URI); if (ecorePackage != null) { EClassifier eObjectFromRegistry = ecorePackage.getEClassifier(EcorePackage.Literals.EOBJECT.getName()); if (left == eObjectFromRegistry) { return true; } } } } } } if (right != null && left.getInstanceClass() != null && right.getInstanceClass() != null) { boolean result = left.getInstanceClass().isAssignableFrom(right.getInstanceClass()); return result; } return false; }