public static String getFragmentPath(EObject object) { SegmentSequence.Builder builder = SegmentSequence.newBuilder("/"); InternalEObject internalEObject = (InternalEObject) object; boolean isContained = internalEObject.eDirectResource() != null; for (InternalEObject container = internalEObject.eInternalContainer(); container != null && !isContained; container = internalEObject.eInternalContainer()) { builder.append(getFragmentPathSegment(container, internalEObject.eContainingFeature(), internalEObject)); internalEObject = container; if (container.eDirectResource() != null) { isContained = true; } } if (!isContained) { return "/-1"; } builder.append(getFragmentPathRootSegment(internalEObject)); builder.append(""); builder.reverse(); return builder.toSegmentSequence().toString(); }
public EObject getEObject(String uriFragment) { int length = uriFragment.length(); if (length > 0) { if (uriFragment.charAt(0) == '/') { return getEObject(SegmentSequence.create("/", uriFragment).subSegmentsList(1)); } else if (uriFragment.charAt(length - 1) == '?') { int index = uriFragment.lastIndexOf('?', length - 2); if (index > 0) { uriFragment = uriFragment.substring(0, index); } } } return getEObjectByID(uriFragment); }
/** * We don't use a {@link IFragmentProvider} here. The implementation is a complete copied from * {@link ResourceImpl#getURIFragment} * * @param eObject * the object the URI fragment should be calculated for. * @return the calculated URI fragment */ private String defaultGetURIFragment(EObject eObject) { // Copied from ResourceImpl.getURIFragment to avoid the caching // mechanism which will add a content // adapter which in turn will resolve / load the resource (while the // purpose of all the code is to // avoid resource loading) InternalEObject internalEObject = (InternalEObject) eObject; if (internalEObject.eDirectResource() == this || unloadingContents != null && unloadingContents.contains(internalEObject)) { return "/" + getURIFragmentRootSegment(eObject); } else { SegmentSequence.Builder builder = SegmentSequence.newBuilder("/"); boolean isContained = false; for (InternalEObject container = internalEObject .eInternalContainer(); container != null; container = internalEObject .eInternalContainer()) { builder.append(container.eURIFragmentSegment(internalEObject.eContainingFeature(), internalEObject)); internalEObject = container; if (container.eDirectResource() == this || unloadingContents != null && unloadingContents.contains(container)) { isContained = true; break; } } if (!isContained) { return "/-1"; } builder.append(getURIFragmentRootSegment(internalEObject)); builder.append(""); builder.reverse(); // This comment also resides in ResourceImpl.getURIFragment: // Note that we convert it to a segment sequence because the // most common use case is that callers of this method will call // URI.appendFragment. // By creating the segment sequence here, we ensure that it's // found in the cache. // return builder.toSegmentSequence().toString(); } }
public String getURIFragment(EObject eObject) { String id = EcoreUtil.getID(eObject); if (id != null) { return id; } else { InternalEObject internalEObject = (InternalEObject)eObject; if (internalEObject.eDirectResource() == this || unloadingContents != null && unloadingContents.contains(internalEObject)) { return "/" + getURIFragmentRootSegment(eObject); } else { SegmentSequence.Builder builder = SegmentSequence.newBuilder("/"); boolean isContained = false; for (InternalEObject container = internalEObject.eInternalContainer(); container != null; container = internalEObject.eInternalContainer()) { builder.append(container.eURIFragmentSegment(internalEObject.eContainingFeature(), internalEObject)); internalEObject = container; if (container.eDirectResource() == this || unloadingContents != null && unloadingContents.contains(container)) { isContained = true; break; } } if (!isContained) { return "/-1"; } builder.append(getURIFragmentRootSegment(internalEObject)); builder.append(""); builder.reverse(); // Note that we convert it to a segment sequence because the most common use case is that callers of this method will call URI.appendFragment. // By creating the segment sequence here, we ensure that it's found in the cache. // return builder.toSegmentSequence().toString(); } } }