@Override public boolean matches(TMObjectIF object) { return object != null && object.getItemIdentifiers().contains(locator); }
private void writeItemIdentities(TMObjectIF obj, ContentHandler dh) throws SAXException { if (export_itemids) write(obj.getItemIdentifiers(), "itemIdentity", dh); }
/** * INTERNAL: Serialize the item identifiers of a {@link TMObjectIF}. If the * object does not have an item identifier, nothing will be serialized. * * @param obj the {@link TMObjectIF} to be serialized. */ private void serializeItemIdentifiers(TMObjectIF obj) throws IOException { Collection<LocatorIF> ids = obj.getItemIdentifiers(); serializeIdentifiers("item_identifiers", ids); }
@Override public Collection process(Collection tmObjs) throws JspTagException { // find all source locators of all topic map objects in collection if (tmObjs == null || tmObjs.isEmpty()) return Collections.EMPTY_SET; else { List sourceLocators = new ArrayList(); Iterator iter = tmObjs.iterator(); while (iter.hasNext()) { try { TMObjectIF tmObj = (TMObjectIF) iter.next(); // get all source locators as LocatorIF objects if (tmObj != null) sourceLocators.addAll( tmObj.getItemIdentifiers() ); } catch (ClassCastException e) { } } return sourceLocators; } }
private static void moveItemIdentifiers(TMObjectIF target, TMObjectIF source) { Iterator<LocatorIF> it = new ArrayList<LocatorIF>(source.getItemIdentifiers()).iterator(); while (it.hasNext()) { LocatorIF itemid = it.next(); source.removeItemIdentifier(itemid); target.addItemIdentifier(itemid); } }
private static void copySourceLocators(TMObjectIF target, TMObjectIF source) { Collection<LocatorIF> srclocs = source.getItemIdentifiers(); if (srclocs.isEmpty()) return; LocatorIF[] list = srclocs.toArray(new LocatorIF[srclocs.size()]); for (int i = 0; i < list.length; i++) { LocatorIF loc = list[i]; source.removeItemIdentifier(loc); target.addItemIdentifier(loc); } }
@Override public void processEvent(Object object, String event, Object new_value, Object old_value) { TMObjectIF added = (TMObjectIF) new_value; // Register object registerObject(added); // Add source locators Object[] sources = added.getItemIdentifiers().toArray(); for (int i = 0; i < sources.length; i++) addEvent(added, TMObjectIF.EVENT_ADD_ITEMIDENTIFIER, sources[i]); } }
@Override public void processEvent(Object object, String event, Object new_value, Object old_value) { TMObjectIF removed = (TMObjectIF) old_value; // Remove source locators Object[] sources = removed.getItemIdentifiers().toArray(); for (int i = 0; i < sources.length; i++) removeEvent(removed, TMObjectIF.EVENT_REMOVE_ITEMIDENTIFIER, sources[i]); // Unregister object unregisterObject(removed); } }
@Override public Set<Locator> getItemIdentifiers() { return topicMap.wrapSet(getWrapped().getItemIdentifiers()); }
/** * INTERNAL: Returns a stable identifier for the topic map object. * This will either be the fragment of a source locator, or the * object ID if no suitable source locator is found. */ public static String getStableId(TMObjectIF object) { if (!object.getItemIdentifiers().isEmpty()) { LocatorIF base = object.getTopicMap().getStore().getBaseAddress(); if (base != null && base.getNotation().equals("URI")) { String basestr = base.getAddress() + "#"; Iterator it = object.getItemIdentifiers().iterator(); while (it.hasNext()) { LocatorIF loc = (LocatorIF) it.next(); String locstr = loc.getAddress(); if (locstr.startsWith(basestr)) return locstr.substring(basestr.length()); } } } return object.getObjectId(); }
private static void copySourceLocators(TMObjectIF target, TMObjectIF source) { Iterator<LocatorIF> it = source.getItemIdentifiers().iterator(); while (it.hasNext()) { LocatorIF srcloc = it.next(); try { target.addItemIdentifier(srcloc); } catch (UniquenessViolationException e) { TopicMapIF tm = target.getTopicMap(); TMObjectIF other = tm.getObjectByItemIdentifier(srcloc); if (!equals(target, other)) throw e; // so, they were equal. that means they should merge. so what // do we do now? is it enough to transfer the source locators? // and what happens if we lose 'target'? surely it's needed // elsewhere? } } }
private String getId(TMObjectIF object) { Iterator it = object.getItemIdentifiers().iterator(); if (it.hasNext()) { LocatorIF loc = (LocatorIF) it.next(); String address = loc.getAddress(); int pos = address.indexOf("#"); if (pos != -1) return address.substring(pos + 1); } // for the case where the object has no source locator at all, or // it doesn't contain '#' TopicMapIF topicmap = object.getTopicMap(); String id = makeRandomId(topicmap); LocatorIF base = topicmap.getStore().getBaseAddress(); object.addItemIdentifier(base.resolveAbsolute("#" + id)); return id; }
private void addSrclocsOf(List matches, Collection objects) { Iterator it = objects.iterator(); while (it.hasNext()) { TMObjectIF object = (TMObjectIF) it.next(); Iterator it2 = object.getItemIdentifiers().iterator(); while (it2.hasNext()) addMatch(matches, "OBJ", object, "LOCATOR", ((LocatorIF) it2.next()).getAddress()); } }
private String getId(TMObjectIF object) { Iterator<LocatorIF> it = object.getItemIdentifiers().iterator(); if (it.hasNext()) { // FIXME: this doesn't check the base address! LocatorIF loc = it.next(); String address = loc.getAddress(); int pos = address.indexOf('#'); if (pos != -1) return address.substring(pos + 1); } // for the case where the object has no source locator at all, or // it doesn't contain '#' TopicMapIF topicmap = object.getTopicMap(); String id = makeRandomId(topicmap); LocatorIF base = topicmap.getStore().getBaseAddress(); object.addItemIdentifier(base.resolveAbsolute("#" + id)); return id; }
private void addSrclocsOf(List matches, Collection objects) { Iterator it = objects.iterator(); while (it.hasNext()) { TMObjectIF object = (TMObjectIF) it.next(); Iterator it2 = object.getItemIdentifiers().iterator(); while (it2.hasNext()) addMatch(matches, "OBJ", object, "LOCATOR", ((LocatorIF) it2.next()).getAddress()); } }
private void check(String what, TMObjectIF obj, LocatorIF srcloc) { Iterator it = obj.getItemIdentifiers().iterator(); Assert.assertTrue(what + " id lost on export and re-import", it.hasNext()); Assert.assertTrue(what + " source locator corrupted", it.next().equals(srcloc)); }
@SuppressWarnings("unchecked") private static <O extends TMObjectIF> O resolveIdentities(O target, O source) { TopicMapIF targettm = target.getTopicMap(); Iterator<LocatorIF> it = source.getItemIdentifiers().iterator(); while (it.hasNext()) { LocatorIF loc = it.next(); TMObjectIF object = targettm.getObjectByItemIdentifier(loc); if (object != null) { if (!equals(target, object)) { throw new ConstraintViolationException("Different topic map objects have " + "the same source locator (" + loc + "): " + target + " and " + object); } else { target.remove(); return (O) object; // this is a duplicate } } else target.addItemIdentifier(loc); } return target; }
public void setItemIdentifiers(TMObjectIF object, TMObject pojo) { if (pojo.getItemIdentifiers() != null) { Collection<LocatorIF> toRemove = CollectionUtils.subtract(object.getItemIdentifiers(), pojo.getItemIdentifiers()); for (LocatorIF ii : pojo.getItemIdentifiers()) { object.addItemIdentifier(ii); } for (LocatorIF ii : toRemove) { object.removeItemIdentifier(ii); } } }
if (tmobject.getItemIdentifiers().contains(locator)) expressions.add(JDOBoolean.TRUE); else
public void testSourceLocators() { object.getItemIdentifiers().size() == 0); object.getItemIdentifiers().size() == 1); object.getItemIdentifiers().iterator().next().equals(loc)); object.getItemIdentifiers().size() == 1); object.getItemIdentifiers().size() == 0);