public static List<OccurrenceIF> findOccurrences(TopicIF oType, TopicIF topicIF, String value, LocatorIF datatype, Collection<TopicIF> scope) { List<OccurrenceIF> result = new ArrayList<OccurrenceIF>(); Iterator<OccurrenceIF> it = topicIF.getOccurrences().iterator(); while (it.hasNext()) { OccurrenceIF occurIF = it.next(); if (ObjectUtils.equals(occurIF.getValue(), value) && ObjectUtils.equals(occurIF.getType(), oType) && ObjectUtils.equals(occurIF.getDataType(), datatype) && CollectionUtils.equalsUnorderedSet(occurIF.getScope(), scope)) result.add(occurIF); } return result; }
@Override public OccurrenceIF makeOccurrence(TopicIF topic, TopicIF occurs_type, String value) { if (topic == null) throw new NullPointerException(MSG_TOPIC_NOT_NULL); if (occurs_type == null) throw new NullPointerException(MSG_OCCURRENCE_TYPE_NOT_NULL); if (value == null) throw new NullPointerException(MSG_OCCURRENCE_VALUE_NOT_NULL); CrossTopicMapException.check(topic, this.tm); CrossTopicMapException.check(occurs_type, this.tm); OccurrenceIF occurs = new Occurrence(tm); ((Topic)topic).addOccurrence(occurs); occurs.setType(occurs_type); occurs.setValue(value, DataTypes.TYPE_STRING); return occurs; }
public FakeOccurrence(OccurrenceIF occ) { this.occ = occ; LocatorIF datatype = occ.getDataType(); if (datatype.equals(DataTypes.TYPE_URI)) { LocatorIF locator = occ.getLocator(); this.value = normaliseLocatorReference(locator.getAddress()); } else if (datatype.equals(DataTypes.TYPE_INTEGER) || datatype.equals(DataTypes.TYPE_DECIMAL)) this.value = normalizeNumber(occ.getValue()); else this.value = occ.getValue(); }
@Override public String toString(OccurrenceIF occ) { if (occ.getLocator() != null) return occ.getLocator().getExternalForm(); else return "$" + occ.getValue(); } }
public static OccurrenceIF findOccurrence(TopicIF oType, TopicIF topicIF, LocatorIF datatype, Collection<TopicIF> scope) { Iterator<OccurrenceIF> it = topicIF.getOccurrences().iterator(); while (it.hasNext()) { OccurrenceIF occurIF = it.next(); if (Objects.equals(occurIF.getType(), oType) && Objects.equals(occurIF.getDataType(), datatype) && CollectionUtils.equalsUnorderedSet(occurIF.getScope(), scope)) return occurIF; } return null; }
@Override public void run(MasterTest mt) { OccurrenceIF o = (OccurrenceIF)topicmap.getObjectById(mt.objectId); assertTrue("Added occurrence not found", o != null); if (testInitialProperties) { assertTrue("Source locators is set", o.getItemIdentifiers().isEmpty()); assertTrue("Scope is set", o.getScope().isEmpty()); assertTrue("Type is set", o.getType() == null); assertTrue("Value is set", o.getValue() == null); assertTrue("Locator is set", o.getLocator() == null); } } });
iocc.addTheme(theme); OccurrenceIF eocc = builder.makeOccurrence(topic, type, occloc); eocc.addTheme(theme); OccurrenceIF occ = (OccurrenceIF)oiter.next(); assertTrue("occurrence type not equals", occ.getType().getObjectId().equals(type_oid)); assertTrue("occurrence value not equal", occ.getValue().equals(occval) || occ.getLocator().equals(occloc)); assertTrue("occurrence scope size not equal 1", occ.getScope().size() == 1); assertTrue("occurrence theme not equal", ((TopicIF)occ.getScope().iterator().next()).getObjectId().equals(theme_oid));
public static List<OccurrenceIF> findOccurrences(TopicIF oType, TopicIF topicIF, String value, Collection<TopicIF> scope) { List<OccurrenceIF> result = new ArrayList<OccurrenceIF>(); Iterator<OccurrenceIF> it = topicIF.getOccurrences().iterator(); while (it.hasNext()) { OccurrenceIF occurIF = it.next(); if (Objects.equals(occurIF.getValue(), value) && Objects.equals(occurIF.getType(), oType) && CollectionUtils.equalsUnorderedSet(occurIF.getScope(), scope)) result.add(occurIF); } return result; }
int fieldOrderMax = (maxOcc == null ? 0 : Ordering.stringToOrder(maxOcc.getValue())); fieldOrderP2 = (fieldOrderMax == 0 ? 0 : fieldOrderMax + Ordering.ORDER_INCREMENTS); p2occ = builder.makeOccurrence(topicIf, typeIf, Ordering.orderToString(fieldOrderP2), datatype); p2occ.addTheme(fieldDefinitionIf); p2occ.addTheme(p2topic); } else { fieldOrderP2 = Ordering.stringToOrder(p2occ.getValue()); int fieldOrderNext = Ordering.stringToOrder(next_occ.getValue()); nextOrder = (fieldOrderP2 + fieldOrderNext)/2; if (nextOrder != fieldOrderP2) { p1occ = topics_occs.get(p1); if (p1occ != null) { p1occ.setValue(Ordering.orderToString(nextOrder)); } else { p1occ = builder.makeOccurrence(topicIf, typeIf, Ordering.orderToString(nextOrder), datatype); p1occ.addTheme(fieldDefinitionIf); p1occ.addTheme(p1topic); p1occ = topics_occs.get(p1); if (p1occ != null) { p1occ.setValue(Ordering.orderToString(nextOrder)); } else { p1occ = builder.makeOccurrence(topicIf, typeIf, Ordering.orderToString(nextOrder), datatype); p1occ.addTheme(fieldDefinitionIf); p1occ.addTheme(p1topic); OccurrenceIF occ = occs.get(i);
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); }
public void testValue() { assertTrue("initial locator not null", "".equals(occurrence.getValue())); String value = "foo"; occurrence.setValue(value); assertTrue("value not maintained after set", occurrence.getValue().equals(value)); assertTrue("data type is incorrect. should be xsd:string", Objects.equals(occurrence.getDataType(), DataTypes.TYPE_STRING)); try { occurrence.setValue(null); fail("value could be set to null"); } catch (NullPointerException e) { } assertTrue("value not maintained after set", occurrence.getValue().equals(value)); assertTrue("data type is incorrect. should be xsd:string", Objects.equals(occurrence.getDataType(), DataTypes.TYPE_STRING)); }
private void write(OccurrenceIF occurrence, int number) { AttributesImpl attributes = reifier(occurrence); attributes.addAttribute("", "", AT_NUMBER, null, "" + number); startElement(EL_OCCURRENCE, attributes); attributes.clear(); write(occurrence.getValue()); // normalized in FakeOccurrence below write(occurrence.getDataType(), "datatype"); writeType(occurrence); write(occurrence.getScope()); writeLocators(occurrence.getItemIdentifiers(), EL_ITEMIDENTIFIERS); endElement(EL_OCCURRENCE); }
@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 }
@Override public void processEvent(Object object, String event, OccurrenceIF new_value, OccurrenceIF old_value) { objects.remove(old_value.getValue(), old_value); } }
/** * 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()); }
private void set(TopicIF topic, String value, LocatorIF psi) { for (OccurrenceIF occ : topic.getOccurrences()) { TopicIF type = occ.getType(); if (type.getSubjectIdentifiers().contains(psi)) { occ.setValue(value); return; } } TopicMapIF tm = topic.getTopicMap(); TopicMapBuilderIF builder = tm.getBuilder(); TopicIF type = tm.getTopicBySubjectIdentifier(psi); builder.makeOccurrence(topic, type, value); }
public void remove(OccurrenceIF occurrence) { occurrence.remove(); }
public static List<OccurrenceIF> findOccurrences(TopicIF oType, TopicIF topicIF, LocatorIF datatype) { List<OccurrenceIF> result = new ArrayList<OccurrenceIF>(); Iterator<OccurrenceIF> it = topicIF.getOccurrences().iterator(); while (it.hasNext()) { OccurrenceIF occurIF = it.next(); if (Objects.equals(occurIF.getType(), oType) && Objects.equals(occurIF.getDataType(), datatype) ) result.add(occurIF); } return result; }
@Override public void removeValue(Topic topic, Object _value, LifeCycleListener listener) { TopicIF topicIf = topic.getTopicIF(); String value = (_value instanceof OccurrenceIF ? ((OccurrenceIF) _value) .getValue() : (String) _value); // LocatorIF datatype = getDataType().getLocator(); OccurrenceType otype = getOccurrenceType(); if (otype == null) return; TopicIF typeIf = otype.getTopicIF(); if (listener != null) listener.onBeforeRemove(topic, this, value); // HACK: we're ignoring the datatype when looking up existing ones // Collection occs = OntopolyModelUtils.findOccurrences(typeIf, // topicIf, value, datatype, Collections.EMPTY_SET); Collection<TopicIF> scope = Collections.emptySet(); Collection<OccurrenceIF> occs = OntopolyModelUtils.findOccurrences(typeIf, topicIf, value, scope); if (!occs.isEmpty()) { // remove all the matching Iterator<OccurrenceIF> iter = occs.iterator(); while (iter.hasNext()) { OccurrenceIF occ = iter.next(); occ.remove(); } } }