/** * Laods the package and any sub-packages from their serialized form. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void loadPackage() { if (isLoaded) return; isLoaded = true; URL url = getClass().getResource(packageFilename); if (url == null) { throw new RuntimeException("Missing serialized package: " + packageFilename); } URI uri = URI.createURI(url.toString()); Resource resource = new EcoreResourceFactoryImpl().createResource(uri); try { resource.load(null); } catch (IOException exception) { throw new WrappedException(exception); } initializeFromLoadedEPackage(this, (EPackage) resource.getContents().get(0)); createResource(eNS_URI); }
/** * Laods the package and any sub-packages from their serialized form. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void loadPackage() { if (isLoaded) return; isLoaded = true; URL url = getClass().getResource(packageFilename); if (url == null) { throw new RuntimeException("Missing serialized package: " + packageFilename); } URI uri = URI.createURI(url.toString()); Resource resource = new EcoreResourceFactoryImpl().createResource(uri); try { resource.load(null); } catch (IOException exception) { throw new WrappedException(exception); } initializeFromLoadedEPackage(this, (EPackage)resource.getContents().get(0)); createResource(eNS_URI); }
@Override public Injector createInjectorAndDoEMFRegistration() { // register default ePackages 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); Injector injector = createInjector(); register(injector); return injector; }
private static Survey loadSurveyModel(String modulePath) { // Initialize the model QueryITPackage.eINSTANCE.eClass(); Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; Map<String, Object> m = reg.getExtensionToFactoryMap(); m.put("xmi", new XMIResourceFactoryImpl()); m.put("ecore", new EcoreResourceFactoryImpl()); // Obtain a new resource set ResourceSet resSet = new ResourceSetImpl(); // Get the resource //Resource resource = resSet.getResource(URI.createFileURI(modulePath), true); Resource resource = resSet.getResource(URI.createURI(modulePath), true); // Get the first model element and cast it to the right type, in my // example everything is included in this first node Survey s = (Survey) resource.getContents().get(0); return s; }
@Before public void setUp() throws Exception { globalStateMemento = GlobalRegistries.makeCopyOfGlobalState(); EPackage.Registry.INSTANCE.put(XMLTypePackage.eNS_URI, XMLTypePackage.eINSTANCE); resourceSet = new XtextResourceSet(); resourceSet.getPackageRegistry().put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE); resourceSet.getPackageRegistry().put(GenModelPackage.eNS_URI, GenModelPackage.eINSTANCE); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("genmodel", new EcoreResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); resourceSet.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext/", false), URI.createURI("classpath:/")); resourceSet.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/")); resourceSet.getURIConverter().getURIMap().put(URI.createPlatformPluginURI("org.eclipse.xtext.common.types/", false), URI.createURI("classpath:/")); resourceSet.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.emf.ecore/", false), URI.createURI("classpath:/")); resourceSet.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.xtext.xbase/", false), URI.createURI("classpath:/")); resourceSet.getURIConverter().getURIMap().put(URI.createPlatformResourceURI("org.eclipse.xtext.common.types/", false), URI.createURI("classpath:/")); resourceSet.getLoadOptions().put(XMLResource.OPTION_URI_HANDLER, this); resourceSet.setClasspathURIContext(getClasspathURIContext()); }
@Before public void setUp() throws Exception { EcoreResourceFactoryImpl resFactory = new EcoreResourceFactoryImpl(); set.getResourceFactoryRegistry().getExtensionToFactoryMap() .put("ecore", resFactory); aRes = (XMIResource) set.createResource(URI.createPlatformResourceURI( "/myProject/main/src/some/package/a.ecore", true)); InputStream stream = new ByteArrayInputStream( aResContent.getBytes("US-ASCII")); aRes.load(stream, set.getLoadOptions()); stream.close(); bRes = (XMIResource) set.createResource(URI.createPlatformResourceURI( "/myProject/model/b.ecore", true)); stream = new ByteArrayInputStream( bResContent.getBytes("US-ASCII")); bRes.load(stream, set.getLoadOptions()); stream.close(); }
public static Resource loadModel(URL modelURL) { ResourceSet resSet = new ResourceSetImpl(); resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); EcoreResourceFactoryImpl ecoreResFact = new EcoreResourceFactoryImpl(); URI fileName = BasicTestCase.getURI(modelURL); LOGGER.info("Trying to load " + fileName); Resource ecoreRes = ecoreResFact.createResource(fileName); try { ecoreRes.load(null); } catch (IOException e) { fail("Could not load " + Files.EXAMPLEMODEL_ECORE.getFile() + ". Reason: " + e); } resSet.getResources().add(ecoreRes); return ecoreRes; }
private List<EObject> createPackage(GeneratedMetamodel generatedMetamodel, ILeafNode text) { final String nsURI = getMetamodelNsURI(text); final URI uri = URI.createURI(nsURI); if (uri == null || isReferencedByUsedGrammar(generatedMetamodel, nsURI)) return Collections.emptyList(); EPackage pack = ((GeneratedMetamodelImpl)generatedMetamodel).basicGetEPackage(); if (pack != null && !pack.eIsProxy()) return singletonList((EObject)pack); final EPackage generatedEPackage = EcoreFactory.eINSTANCE.createEPackage(); generatedEPackage.setName(generatedMetamodel.getName()); generatedEPackage.setNsPrefix(generatedMetamodel.getName()); generatedEPackage.setNsURI(nsURI); final Resource generatedPackageResource = new EcoreResourceFactoryImpl().createResource(uri); XtextResourceSet resourceSet = (XtextResourceSet) generatedMetamodel.eResource().getResourceSet(); if (!resourceSet.getURIResourceMap().containsKey(generatedPackageResource.getURI())) { generatedMetamodel.eResource().getResourceSet().getResources().add(generatedPackageResource); } else { generatedPackageResource.setURI(URI.createURI(nsURI+"_"+generatedMetamodel.hashCode())); generatedMetamodel.eResource().getResourceSet().getResources().add(generatedPackageResource); } generatedPackageResource.getContents().add(generatedEPackage); return Collections.<EObject>singletonList(generatedEPackage); }
@Before public void setUp() throws Exception { globalStateMemento = GlobalRegistries.makeCopyOfGlobalState(); EPackage.Registry.INSTANCE.put(XMLTypePackage.eNS_URI, XMLTypePackage.eINSTANCE); EcoreResourceFactoryImpl resFactory = new EcoreResourceFactoryImpl(); set.getResourceFactoryRegistry().getExtensionToFactoryMap() .put("ecore", resFactory); aRes = (XMIResource) set.createResource(URI.createPlatformResourceURI( "/myProject/main/src/some/package/a.ecore", true)); InputStream stream = new ByteArrayInputStream( aResContent.getBytes("US-ASCII")); aRes.load(stream, set.getLoadOptions()); stream.close(); bRes = (XMIResource) set.createResource(URI.createPlatformResourceURI( "/myProject/model/b.ecore", true)); stream = new ByteArrayInputStream( bResContent.getBytes("US-ASCII")); bRes.load(stream, set.getLoadOptions()); stream.close(); }
private String lazyMetamodelRegistration(String metamodelPath){ Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); ResourceSet rs = new ResourceSetImpl(); // Enables extended meta-data, weird we have to do this but well... final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(EPackage.Registry.INSTANCE); rs.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData); Resource r = rs.getResource(URI.createFileURI(metamodelPath), true); EObject eObject = r.getContents().get(0); // A meta-model might have multiple packages we assume the main package is the first one listed if (eObject instanceof EPackage) { EPackage p = (EPackage)eObject; System.out.println(p.getNsURI()); EPackage.Registry.INSTANCE.put(p.getNsURI(), p); return p.getNsURI(); } return null; }
/** * Laods the package and any sub-packages from their serialized form. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void loadPackage() { if (isLoaded) return; isLoaded = true; URL url = getClass().getResource(packageFilename); if (url == null) { throw new RuntimeException("Missing serialized package: " + packageFilename); } URI uri = URI.createURI(url.toString()); Resource resource = new EcoreResourceFactoryImpl().createResource(uri); try { resource.load(null); } catch (IOException exception) { throw new WrappedException(exception); } initializeFromLoadedEPackage(this, (EPackage) resource.getContents() .get(0)); createResource(eNS_URI); }