@Override public TopicIF getTopic() { return occ.getTopic(); }
@Override public Topic getParent() { return topicMap.wrapTopic(wrapped.getTopic()); }
@Override public void processEvent(Object object, String event, Object new_value, Object old_value) { OccurrenceIF occ = (OccurrenceIF)object; TopicIF topic = occ.getTopic(); if (topic != null) topicModified(topic); } }
public static TopicIF getTopic(TMObjectIF tmobject) { if (tmobject == null) return null; else if (tmobject instanceof TopicNameIF) return ((TopicNameIF)tmobject).getTopic(); else if (tmobject instanceof VariantNameIF) return ((VariantNameIF)tmobject).getTopic(); else if (tmobject instanceof OccurrenceIF) return ((OccurrenceIF)tmobject).getTopic(); else if (tmobject instanceof TopicIF) return ((TopicIF)tmobject); else return null; }
protected void addOccurrence(OccurrenceIF occurrence) { if (occurrence == null) throw new NullPointerException(MSG_NULL_ARGUMENT); // Check to see if occurrence is already a member of this topic if (occurrence.getTopic() == this) return; // Check if used elsewhere. if (occurrence.getTopic() != null) throw new ConstraintViolationException("Moving objects is not allowed."); // Notify listeners fireEvent(TopicIF.EVENT_ADD_OCCURRENCE, occurrence, null); // Set topic property ((Occurrence)occurrence).setTopic(this); // Notify transaction valueAdded(LF_occurrences, occurrence, false); }
protected void removeOccurrence(OccurrenceIF occurrence) { if (occurrence == null) throw new NullPointerException(MSG_NULL_ARGUMENT); // Check to see if occurrence is not a member of this topic if (occurrence.getTopic() != this) return; // Notify listeners fireEvent(TopicIF.EVENT_REMOVE_OCCURRENCE, null, occurrence); // Unset topic property ((Occurrence)occurrence).setTopic(null); // Notify transaction valueRemoved(LF_occurrences, occurrence, false); }
/** * Returns a Collection of all the topics containing duplicate occurrences. */ public Collection getDuplicateOccurrences() { Collection retur = new ArrayList(); Collection topics = tm.getTopics(); Iterator ittop = topics.iterator(); while (ittop.hasNext()) { TopicIF t = (TopicIF)ittop.next(); HashMap templocators = new HashMap(); HashMap temproles = new HashMap(); Collection occurences = t.getOccurrences(); Iterator itoccur = occurences.iterator(); while (itoccur.hasNext()) { OccurrenceIF o = (OccurrenceIF)itoccur.next(); LocatorIF l = o.getLocator(); if (l != null) { if (temproles.containsKey(l.getAddress())) { retur.add(t); } else { temproles.put(l.getAddress(), null); templocators.put(o.getTopic(), null); } } } } return retur; } }
private void addTo(QueryMatches result, Object[] occs, TopicIF type, Object[] oldrow, int topicix) { for (int oix = 0; oix < occs.length; oix++) { OccurrenceIF occ = (OccurrenceIF) occs[oix]; if (occ.getType().equals(type)) { // ok, it's a match: add it if (result.last+1 == result.size) result.increaseCapacity(); result.last++; Object[] newRow = (Object[]) oldrow.clone(); newRow[topicix] = occ.getTopic(); result.data[result.last] = newRow; } } }
public void testParentTopic() { assertTrue("parent not set to right object", occurrence.getTopic().equals(parent)); }
topics.add( ((VariantNameIF) obj).getTopic() ); } else if (obj instanceof OccurrenceIF) { topics.add( ((OccurrenceIF) obj).getTopic() ); } else if (obj instanceof TopicMapIF) { topics.addAll( ((TopicMapIF) obj).getTopics() );
private QueryMatches occurrenceToTopic(QueryMatches matches, int topicix, int occix) { QueryMatches result = new QueryMatches(matches); for (int ix = 0; ix <= matches.last; ix++) { if (!(matches.data[ix][occix] instanceof OccurrenceIF)) continue; if (result.last+1 == result.size) result.increaseCapacity(); result.last++; Object[] newRow = (Object[]) matches.data[ix].clone(); newRow[topicix] = ((OccurrenceIF) newRow[occix]).getTopic(); result.data[result.last] = newRow; } return result; } }
TopicIF topic = oc.getTopic();
SnapshotOccurrence(OccurrenceIF original, int snapshotType, Map<TMObjectIF, SnapshotTMObject> processed) { this.snapshotType = snapshotType; switch (snapshotType) { case SNAPSHOT_REFERENCE: this.objectId = original.getObjectId(); break; case SNAPSHOT_COMPLETE: this.objectId = original.getObjectId(); this.srclocs = new ArrayList<LocatorIF>(original.getItemIdentifiers()); this.topic = SnapshotTopic.makeSnapshot(original.getTopic(), SnapshotTopic.SNAPSHOT_REFERENCE, processed); this.datatype = original.getDataType(); this.value = original.getValue(); this.scope = new ArrayList<TopicIF>(); Iterator<TopicIF> siter = original.getScope().iterator(); while (siter.hasNext()) { this.scope.add(SnapshotTopic.makeSnapshot(siter.next(), snapshotType, processed)); } this.type = SnapshotTopic.makeSnapshot(original.getType(), SnapshotTopic.SNAPSHOT_REFERENCE, processed); this.reifier = SnapshotTopic.makeSnapshot(original.getReifier(), SnapshotTopic.SNAPSHOT_REFERENCE, processed); break; default: throw new OntopiaRuntimeException("Unknown snapshot type: " + snapshotType); } }
public static String toString(TMObjectIF tmobject) { if (tmobject == null) return "null"; else if (tmobject instanceof TopicNameIF) return ((TopicNameIF)tmobject).getTopic().getObjectId(); else if (tmobject instanceof VariantNameIF) return ((VariantNameIF)tmobject).getTopic().getObjectId(); else if (tmobject instanceof OccurrenceIF) return ((OccurrenceIF)tmobject).getTopic().getObjectId(); else if (tmobject instanceof TopicIF) return ((TopicIF)tmobject).getObjectId(); else return "null"; }
/** * Return true iff the type of the occurrence is accepted * @param occurrence The occurence to test for acceptance. It is assumed that * occurrence will only be tested for acceptance if its parent topic * has already been tested and passed. * @return true iff occurrence is accepted. */ public boolean ok(OccurrenceIF occurrence) { return filter.ok(occurrence) && ok(occurrence.getType()) && ok(occurrence.getScope()) && ok(occurrence.getTopic()); }
newRow[topicix] = occ.getTopic(); result.data[result.last] = newRow;
protected void validate(OccurrenceIF occ, OccurrenceConstraint constraint) throws SchemaViolationException { TopicIF topic = occ.getTopic(); validateScope(topic, occ, constraint); if (constraint.getInternal() == OccurrenceConstraint.RESOURCE_INTERNAL && occ.getLocator() != null) handler.violation("Occurrence " + occ + " is not internal", topic, occ, constraint); if (constraint.getInternal() == OccurrenceConstraint.RESOURCE_EXTERNAL && occ.getValue() != null) handler.violation("Occurrence " + occ + " is not external", topic, occ, constraint); }
/** * INTERNAL: Serialize an occurrence to the underlying JTM stream. * * @param occurrence the occurrence to be serialized. * @param topLevel if the element is serialized as top-level element. */ private void serializeOccurrence(OccurrenceIF occurrence, boolean topLevel) throws IOException { if (!topLevel) { writer.object(); } else { serializeParent(occurrence.getTopic()); } serializeValue(occurrence.getLocator(), occurrence.getValue()); serializeType(occurrence); serializeDataType(occurrence.getDataType()); serializeScope(occurrence); serializeItemIdentifiers(occurrence); serializeReifier(occurrence); writer.endObject(); }
@Test public void testOccurrence() throws Exception { OccurrenceIF occ = tm1.getBuilder().makeOccurrence(foo1, foo1, "foo"); occ.setReifier(foo1); // todo: occ.addTheme(foo1); pending #265 concurrentCommit(); // verify no inconsistenties were created occ = (OccurrenceIF) tm1.getObjectById(occ.getObjectId()); check(tm1, occ.getType(), "Occurrence", "type"); check(tm1, occ.getTopic(), "Occurrence", "topic"); check(tm1, occ.getReifier(), "Occurrence", "reifier"); // todo check(tm1, occ.getScope().iterator().next().getObjectId(), "Occurrence", "scope"); pending #265 }
@Test public void testImport() throws Exception { OccurrenceIF occ = tm1.getBuilder().makeOccurrence(foo1, foo1, "foo"); // concurrent import causing a merge MergeUtils.mergeInto(tm1, new LTMTopicMapReader( StreamUtils.getInputStream("classpath:net/ontopia/topicmaps/impl/rdbms/issue499.ltm"), URILocator.create("foo:bar")) .read()); store2.commit(); store1.commit(); occ = (OccurrenceIF) tm1.getObjectById(occ.getObjectId()); check(tm1, occ.getType(), "Occurrence", "type"); check(tm1, occ.getTopic(), "Occurrence", "topic"); // check(tm1, occ.getReifier(), "Occurrence", "reifier"); }