Java Code Examples for org.eclipse.emf.ecore.resource.Resource#getURIFragment()
The following examples show how to use
org.eclipse.emf.ecore.resource.Resource#getURIFragment() .
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: DirectLinkingEObjectOutputStream.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Writes a binary representation of the given object's URI to this output stream. For objects contained by the given resource the object's * {@link Resource#getURIFragment(EObject) URI fragment} will be used. For objects in other resources the * {@link org.eclipse.emf.ecore.util.EcoreUtil#getURI(EObject) full URI} will be written. * * @param obj * object to write, must not be {@code null} * @param context * resource being serialized, must not be {@code null} * @throws IOException * if an I/O exception occurred */ public void writeEObjectURI(final EObject obj, final Resource context) throws IOException { Resource resource = obj.eResource(); if (resource == context) { // NOPMD writeBoolean(LOCAL_EOBJECT); writeEObjectURIFragmentPath(obj); } else { String uriString = null; if (obj.eIsProxy()) { URI proxyURI = ((InternalEObject) obj).eProxyURI(); uriString = proxyURI.fragment().startsWith(LazyURIEncoder.XTEXT_LINK) ? null : proxyURI.toString(); } else if (resource != null) { uriString = resource.getURI().toString() + '#' + resource.getURIFragment(obj); } else { LOG.warn("Encountered dangling object while serializing " + context.getURI() + ": " + obj); //$NON-NLS-1$ //$NON-NLS-2$ } writeBoolean(!LOCAL_EOBJECT); writeString(uriString); } }
Example 2
Source File: UimaTypeSystem2Ecore.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Load uima builtins ecore. * * @param resourceSet the resource set * @param aSchemaLocationMap the a schema location map * @return the resource */ private static Resource loadUimaBuiltinsEcore(ResourceSet resourceSet, Map aSchemaLocationMap) { // load Ecore model for UIMA built-in types (use classloader to locate) URL uimaEcoreUrl = UimaTypeSystem2Ecore.class.getResource("/uima.ecore"); if (uimaEcoreUrl == null) { throw new UIMARuntimeException(UIMARuntimeException.UIMA_ECORE_NOT_FOUND, new Object[0]); } Resource uimaEcoreResource = resourceSet.getResource(URI.createURI(uimaEcoreUrl.toString()), true); // register core UIMA packages (I'm surprised I need to do this manually) TreeIterator iter = uimaEcoreResource.getAllContents(); while (iter.hasNext()) { Object current = iter.next(); if (current instanceof EPackage) { EPackage pkg = (EPackage) current; EPackage.Registry.INSTANCE.put(pkg.getNsURI(), pkg); if (aSchemaLocationMap != null) { String schemaLoc = uimaEcoreResource.getURI() + "#" + uimaEcoreResource.getURIFragment(pkg); aSchemaLocationMap.put(pkg.getNsURI(), schemaLoc); } } } return uimaEcoreResource; }
Example 3
Source File: ApiCompareView.java From n4js with Eclipse Public License 1.0 | 5 votes |
private void showInEditor(EObject eobj) { final Resource res = eobj.eResource(); final URI uriBase = res.getURI(); final String frag = res.getURIFragment(eobj); final URI uri = uriBase.appendFragment(frag); uriOpener.open(uri, true); }
Example 4
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void getAndResolveAllFragments(Resource resource) { Iterator<EObject> iter = EcoreUtil.getAllContents(resource, false); while (iter.hasNext()) { EObject next = iter.next(); String fragment = resource.getURIFragment(next); EObject resolved = resource.getEObject(fragment); assertSame(fragment + " / " + next.eClass().getName(), next, resolved); } }
Example 5
Source File: AbstractTypeProviderTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void getAndResolveAllFragments(Resource resource) { Iterator<EObject> iter = EcoreUtil.getAllContents(resource, false); while (iter.hasNext()) { EObject next = iter.next(); String fragment = resource.getURIFragment(next); EObject resolved = resource.getEObject(fragment); assertSame(fragment + " / " + next.eClass().getName(), next, resolved); } }
Example 6
Source File: AbstractTypeProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void getAndResolveAllFragments(Resource resource) { Iterator<EObject> iter = EcoreUtil.getAllContents(resource, false); while (iter.hasNext()) { EObject next = iter.next(); String fragment = resource.getURIFragment(next); EObject resolved = resource.getEObject(fragment); assertSame(fragment + " / " + next.eClass().getName(), next, resolved); } }
Example 7
Source File: AbstractCodeBuilder.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected <T extends EObject> T findByFragment(final XtextResource resource, final T object) { final Resource myResource = object.eResource(); boolean _equals = Objects.equal(myResource, resource); if (_equals) { return object; } final String fragment = myResource.getURIFragment(object); EObject _eObject = resource.getEObject(fragment); final T result = ((T) _eObject); return result; }
Example 8
Source File: EditModelHelper.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
public static String getEObjectID(EObject eObject) { Resource eResource = eObject.eResource(); if (eResource != null) { return eResource.getURIFragment(eObject); } return null; }
Example 9
Source File: ModelHelper.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
public static String getEObjectID(final EObject eObject) { if (eObject == null) { return null; } final Resource eResource = eObject.eResource(); if (eResource != null) { return eResource.getURIFragment(eObject); } return null; }
Example 10
Source File: ModelSearch.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public String getEObjectID(final EObject eObject) { if (eObject == null) { return null; } final Resource eResource = eObject.eResource(); if (eResource != null) { return eResource.getURIFragment(eObject); } return null; }
Example 11
Source File: N4JSUnloader.java From n4js with Eclipse Public License 1.0 | 4 votes |
private String getInitialFragment(EObject root) { Resource resource = root.eResource(); if (resource != null) return resource.getURIFragment(root); return EcoreUtil.getURI(root).fragment(); }
Example 12
Source File: EcoreUtil2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public static String getURIFragment(EObject eObject) { Resource resource = eObject.eResource(); String fragment = resource.getURIFragment(eObject); return fragment; }
Example 13
Source File: AbstractSelectorFragmentProviderTest.java From dsl-devkit with Eclipse Public License 1.0 | 4 votes |
private void assertFragmentMatchesAndResolves(final Resource res, final String expectedFragment, final EObject obj) { String fragment = res.getURIFragment(obj); assertEquals(expectedFragment, fragment); assertSame(obj, res.getEObject(fragment)); }