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); } }
public TMObjectModel(String topicMapId, TMObjectIF object) { super(object); if (object != null) { this.topicMapId = topicMapId; this.objectId = object.getObjectId(); } }
@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; }
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? } } }
/** * 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(); }
@Override public boolean matches(TMObjectIF object) { return object != null && object.getItemIdentifiers().contains(locator); }
public CrossTopicMapException(TMObjectIF tmobject, TopicMapIF target) { super("Cannot assign " + tmobject + " to topic map " + target + " as the object belongs to another topic map: " + tmobject.getTopicMap()); }
public TMObjectIFHandle(TMObjectIF o) { this.objectId = o.getObjectId(); TopicMapIF tm = o.getTopicMap(); this.topicmapId = tm.getObjectId(); TopicMapReferenceIF ref = tm.getStore().getReference(); if (ref != null) this.referenceId = ref.getId(); }
public void perform(ActionParametersIF params, ActionResponseIF response) { //test params ActionSignature paramsType = ActionSignature.getSignature("x& x?"); paramsType.validateArguments(params, this); Collection objects = params.getCollection(0); if (objects == null) { TMObjectIF object = params.getTMObjectValue(); if (object != null) objects = Collections.singleton(object); else objects = Collections.EMPTY_SET; } Iterator it = objects.iterator(); while (it.hasNext()) ((TMObjectIF) it.next()).remove(); TMObjectIF next = (TMObjectIF) params.get(1); if (next != null) response.addParameter(Constants.RP_TOPIC_ID, next.getObjectId()); }
case FILTER_SRCLOC: loc = getLocator(matches.data[ix][ix2]); if (((TMObjectIF) matches.data[ix][ix1]).getItemIdentifiers().contains(loc)) object = matches.data[ix][ix2]; break; case FILTER_ID: object = ((TMObjectIF) matches.data[ix][ix1]).getObjectId(); break; case FILTER_STR_STARTS_WITH:
protected static void removeObjects(TopicMapIF topicMap, DeclarationContextIF dc, String removalQuery) throws InvalidQueryException { QueryProcessorIF qp = QueryUtils.getQueryProcessor(topicMap); QueryResultIF qr = null; try { qr = qp.execute(removalQuery, dc); while (qr.next()) { TMObjectIF tmobject = (TMObjectIF)qr.getValue(0); if (tmobject.getTopicMap() != null) { tmobject.remove(); } } } finally { if (qr != null) qr.close(); } }
protected void registerSourceLocator(TMObjectIF tmobject, String id) { // No need to register source locator if id is null if (id == null) return; tmobject.addItemIdentifier(createLocator('#' + id)); }
object.addItemIdentifier(new URILocator(newAddress)); object.removeItemIdentifier(locator); } catch (MalformedURLException e) { throw new ActionRuntimeException("Malformed URL for source locator: '" + newAddress + "'", false);
@Override public void remove() { getWrapped().remove(); }
@Override public void modify(TMObjectIF object, Object v) { String value = (String) v; try { object.removeItemIdentifier(new URILocator(value)); } catch (MalformedURLException e) { throw new OntopiaRuntimeException("Invalid URI: " + value); } } }
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; }
TopicMapIF tm = tmobject.getTopicMap(); LocatorIF baseloc = (tm == null ? null : tm.getStore().getBaseAddress()); Iterator it = tmobject.getItemIdentifiers().iterator(); while (it.hasNext()) { LocatorIF sloc = (LocatorIF) it.next(); id = "id" + tmobject.getObjectId();
private void writeItemIdentities(TMObjectIF obj, ContentHandler dh) throws SAXException { if (export_itemids) write(obj.getItemIdentifiers(), "itemIdentity", dh); }
public CrossTopicMapException(TMObjectIF tmobject, TMObjectIF target) { super("Cannot assign " + tmobject + " to object " + target + " as they belong to two different topic maps: " + tmobject.getTopicMap() + " and " + target.getTopicMap()); }
public void perform(ActionParametersIF params, ActionResponseIF response) { QueryProcessorIF processor = QueryUtils.getQueryProcessor((TopicMapIF) params.get(1)); Collection queries = params.getCollection(0); try { // iterate over the queries and run them one by one Iterator it = queries.iterator(); while (it.hasNext()) { QueryResultIF result = processor.execute((String) it.next()); while (result.next()) { for (int ix = 0; ix < result.getWidth(); ix++) { ((TMObjectIF) result.getValue(ix)).remove(); } } result.close(); } TMObjectIF next = (TMObjectIF) params.get(2); if (next != null) response.addParameter(Constants.RP_TOPIC_ID, next.getObjectId()); } catch (InvalidQueryException e) { throw new ActionRuntimeException(e); } }