Java Code Examples for org.eclipse.emf.ecore.resource.impl.ResourceSetImpl#createResource()
The following examples show how to use
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl#createResource() .
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: ChartConfiguratorView.java From neoscada with Eclipse Public License 1.0 | 6 votes |
public void setChartConfiguration ( final Chart chart ) { if ( chart == null ) { this.viewer.setInput ( null ); } else { if ( chart.eResource () == null ) { final ResourceSetImpl rs = new ResourceSetImpl (); final Resource r = rs.createResource ( URI.createURI ( "urn:dummy" ) ); r.getContents ().add ( chart ); } if ( chart.eResource ().getURI () == null ) { chart.eResource ().setURI ( URI.createURI ( "urn:dummy" ) ); } this.viewer.setInput ( chart.eResource () ); } }
Example 2
Source File: ServerHostImpl.java From neoscada with Eclipse Public License 1.0 | 6 votes |
public Collection<? extends ServerDescriptor> startServer ( final URI exporterFileUri, final String locationLabel ) throws CoreException { final ResourceSetImpl resourceSet = new ResourceSetImpl (); resourceSet.getResourceFactoryRegistry ().getExtensionToFactoryMap ().put ( "*", new ExporterResourceFactoryImpl () ); final Resource resource = resourceSet.createResource ( exporterFileUri ); try { resource.load ( null ); } catch ( final IOException e ) { throw new CoreException ( StatusHelper.convertStatus ( HivesPlugin.PLUGIN_ID, "Failed to load configuration", e ) ); } final DocumentRoot root = (DocumentRoot)EcoreUtil.getObjectByType ( resource.getContents (), ExporterPackage.Literals.DOCUMENT_ROOT ); if ( root == null ) { throw new CoreException ( new Status ( IStatus.ERROR, HivesPlugin.PLUGIN_ID, "Failed to locate exporter configuration in: " + exporterFileUri ) ); } return startServer ( root, locationLabel ); }
Example 3
Source File: LazyLinkingResourceTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testResolveLazyCrossReferences_02() throws Exception { with(lazyLinkingTestLangaugeSetup()); ResourceSetImpl rs = new ResourceSetImpl(); final Resource res1 = rs.createResource(URI.createURI("file1.lazylinkingtestlanguage")); Resource res2 = rs.createResource(URI.createURI("file2.lazylinkingtestlanguage")); res1.load(new StringInputStream("type Foo { } type Baz { Foo Bar prop; } }"), null); res2.load(new StringInputStream("type Bar { }"), null); res1.eAdapters().add(notificationAlert); Model m = (Model) res1.getContents().get(0); Type t = m.getTypes().get(1); Property p = t.getProperties().get(0); final InternalEList<Type> types = (InternalEList<Type>) p.getType(); assertEquals(2, types.size()); for (Iterator<Type> it = types.basicIterator(); it.hasNext();) { final Type tt = it.next(); assertTrue(tt.eIsProxy()); } ((LazyLinkingResource) res1).resolveLazyCrossReferences(CancelIndicator.NullImpl); assertFalse(types.basicGet(0).eIsProxy()); assertTrue(types.basicGet(1).eIsProxy()); res1.eAdapters().remove(notificationAlert); EcoreUtil.resolveAll(res1); assertFalse(types.basicGet(0).eIsProxy()); assertFalse(types.basicGet(1).eIsProxy()); }
Example 4
Source File: EcoreUtil2Test.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testClone() throws Exception { Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); EPackage.Registry.INSTANCE.put(EcorePackage.eINSTANCE.getNsURI(), EcorePackage.eINSTANCE); ResourceSetImpl rs = new ResourceSetImpl(); Resource r1 = rs.createResource(URI.createURI("foo.xmi"), ContentHandler.UNSPECIFIED_CONTENT_TYPE); Resource r2 = rs.createResource(URI.createURI("bar.xmi"), ContentHandler.UNSPECIFIED_CONTENT_TYPE); EClass a = EcoreFactory.eINSTANCE.createEClass(); a.setName("a"); EClass b = EcoreFactory.eINSTANCE.createEClass(); r1.getContents().add(a); b.setName("b"); b.getESuperTypes().add(a); r2.getContents().add(b); ResourceSetImpl clone = EcoreUtil2.clone(new ResourceSetImpl(), rs); EList<Resource> list = clone.getResources(); Resource resA = list.get(0); assertEquals(URI.createURI("foo.xmi"),resA.getURI()); assertNotSame(resA, r1); Resource resB = list.get(1); assertEquals(URI.createURI("bar.xmi"),resB.getURI()); assertNotSame(resB, r2); EClass a1 = (EClass)resA.getContents().get(0); EClass b1 = (EClass)resB.getContents().get(0); assertEquals("a", a1.getName()); assertNotSame(a, a1); assertEquals("b", b1.getName()); assertNotSame(b, b1); assertSame(b1.getESuperTypes().get(0),a1); assertSame(b.getESuperTypes().get(0),a); }
Example 5
Source File: EcoreUtil2Test.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testClone_2() throws Exception { ResourceSetImpl sourceSet = new DerivedStateAwareResourceSet(); DerivedStateAwareResource resource = (DerivedStateAwareResource) sourceSet.createResource(URI .createURI("http://derived.res")); boolean stateToCheck = !resource.isFullyInitialized(); resource.setFullyInitialized(stateToCheck); Resource targetRes = EcoreUtil2.clone(new DerivedStateAwareResourceSet(), sourceSet).getResources().get(0); assertTrue(targetRes instanceof DerivedStateAwareResource); assertEquals("FullyInitialized flag not copied ", stateToCheck, ((DerivedStateAwareResource) targetRes).isFullyInitialized()); }
Example 6
Source File: LazyLinkingResourceTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testResolveLazyCrossReferences() throws Exception { with(testLangaugeSetup()); ResourceSetImpl rs = new ResourceSetImpl(); final Resource res1 = rs.createResource(URI.createURI("file1.indextestlanguage")); Resource res2 = rs.createResource(URI.createURI("file2.indextestlanguage")); res1.load(new StringInputStream( "foo { " + " import bar.Bar" + " entity Foo {" + " Bar a1" + " Foo a2" + " }" + "}"), null); res2.load(new StringInputStream( "bar {" + " entity Bar{}" + "}"), null); res1.eAdapters().add(notificationAlert); Entity e = (Entity) find(EcoreUtil2.eAllContents(res1.getContents().get(0)),new Predicate<EObject>() { @Override public boolean apply(EObject input) { return input instanceof Entity; } }); assertTrue(((EObject)e.getProperties().get(0).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); assertTrue(((EObject)e.getProperties().get(1).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); ((LazyLinkingResource)res1).resolveLazyCrossReferences(CancelIndicator.NullImpl); assertTrue(((EObject)e.getProperties().get(0).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); assertFalse(((EObject)e.getProperties().get(1).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); res1.eAdapters().remove(notificationAlert); EcoreUtil.resolveAll(res1); assertFalse(((EObject)e.getProperties().get(0).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); assertFalse(((EObject)e.getProperties().get(1).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); }
Example 7
Source File: FirstPage.java From slr-toolkit with Eclipse Public License 1.0 | 5 votes |
private void setUpExampleBibtex() throws Exception { Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put( "bib", new BibtexResourceFactoryImpl()); final String bib = "@INPROCEEDINGS{Test01, classes = {test}}"; resourceSet = new ResourceSetImpl(); resource = resourceSet.createResource(URI.createURI("test.bib")); resource.load(new URIConverter.ReadableInputStream(bib, "UTF-8"), Collections.EMPTY_MAP); }
Example 8
Source File: LazyLinkingResourceTest.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Test public void testResolveLazyCrossReferences_01() throws Exception { with(testLangaugeSetup()); ResourceSetImpl rs = new ResourceSetImpl(); final Resource res1 = rs.createResource(URI.createURI("file1.indextestlanguage")); Resource res2 = rs.createResource(URI.createURI("file2.indextestlanguage")); res1.load(new StringInputStream( "foo { " + " import bar.Bar" + " entity Foo {" + " Bar a1" + " Foo a2" + " Unresolvable a2" + " }" + "}"), null); res2.load(new StringInputStream( "bar {" + " entity Bar{}" + "}"), null); res1.eAdapters().add(notificationAlert); Entity e = (Entity) find(EcoreUtil2.eAllContents(res1.getContents().get(0)),new Predicate<EObject>() { @Override public boolean apply(EObject input) { return input instanceof Entity; } }); assertEquals(0,res1.getErrors().size()); assertTrue(((EObject)e.getProperties().get(0).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); assertTrue(((EObject)e.getProperties().get(1).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); assertTrue(((EObject)e.getProperties().get(2).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); ((LazyLinkingResource)res1).resolveLazyCrossReferences(CancelIndicator.NullImpl); assertEquals(1,res1.getErrors().size()); assertTrue(((EObject)e.getProperties().get(0).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); assertFalse(((EObject)e.getProperties().get(1).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); assertTrue(((EObject)e.getProperties().get(2).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); res1.eAdapters().remove(notificationAlert); EcoreUtil.resolveAll(res1); assertEquals(1,res1.getErrors().size()); assertFalse(((EObject)e.getProperties().get(0).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); assertFalse(((EObject)e.getProperties().get(1).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); assertTrue(((EObject)e.getProperties().get(2).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy()); }