@Override public void setValue(Locator value) { Check.valueNotNull(this, value); wrapped.setLocator(topicMap.unwrapLocator(value)); }
@Override public OccurrenceIF makeOccurrence(TopicIF topic, TopicIF occurs_type, LocatorIF locator) { if (topic == null) throw new NullPointerException(MSG_TOPIC_NOT_NULL); if (occurs_type == null) throw new NullPointerException(MSG_OCCURRENCE_TYPE_NOT_NULL); if (locator == null) throw new NullPointerException(MSG_OCCURRENCE_LOCATOR_NOT_NULL); CrossTopicMapException.check(topic, this.tm); CrossTopicMapException.check(occurs_type, this.tm); OccurrenceIF occurs = new Occurrence(txn); ((Topic)topic).addOccurrence(occurs); occurs.setType(occurs_type); occurs.setLocator(locator); return occurs; }
@Override public void modify(TMObjectIF object, Object v) { try { LocatorIF loc = new URILocator((String) v); if (object instanceof OccurrenceIF) ((OccurrenceIF) object).setLocator(loc); else if (object instanceof VariantNameIF) ((VariantNameIF) object).setLocator(loc); else throw new OntopiaRuntimeException("OUCH!"); } catch (MalformedURLException e) { throw new OntopiaRuntimeException(e); } } }
@Override public void run() { OccurrenceIF o = getOccurrence(); o.setLocator(URILocator.create("x:occurrence-locator")); this.objectId = o.getObjectId(); } });
occurs.setLocator(locator);
public void testGenericURILocator() { LocatorIF loc1 = new GenericLocator("URI", "foo:bar"); occurrence.setLocator(loc1); LocatorIF loc2 = occurrence.getLocator(); assertTrue("Locator notation is not URI", loc2.getNotation().equals("URI")); assertTrue("Locator value is not foo:bar", loc2.getAddress().equals("foo:bar")); assertTrue("Input locator is not equal output locator", loc2.equals(loc1)); assertTrue("Output locator is not equal input locator", loc1.equals(loc2)); }
public void perform(ActionParametersIF params, ActionResponseIF response) { //test params ActionSignature paramsType = ActionSignature.getSignature("o t? t?"); paramsType.validateArguments(params, this); OccurrenceIF occurrence = (OccurrenceIF) params.get(0); TopicIF topic = (TopicIF) params.get(1); String value = params.getStringValue(); // FIXME: what if value == null? if (occurrence == null) { // check if new occurrence should be created, otherwise do nothing if (value == null || value.trim().length() == 0) return; // create new occurrence TopicMapBuilderIF builder = topic.getTopicMap().getBuilder(); TopicIF occtype = (TopicIF) params.get(2); occurrence = builder.makeOccurrence(topic, occtype, ""); } try { URILocator loc = new URILocator(value); occurrence.setLocator(loc); } catch (MalformedURLException e) { throw new ActionRuntimeException("Malformed URL for occurrence: '" + value + "'", false); } }
public void testLocator() { assertTrue("initial locator not null", occurrence.getLocator() == null); try { URILocator loc = new URILocator("http://www.ontopia.net"); occurrence.setLocator(loc); assertTrue("locator identity not maintained after set", occurrence.getLocator().equals(loc)); assertTrue("data type is incorrect. should be xsd:anyURI", Objects.equals(occurrence.getDataType(), DataTypes.TYPE_URI)); try { occurrence.setLocator(null); fail("value could be set to null"); } catch (NullPointerException e) { } assertTrue("locator identity not maintained after set", occurrence.getLocator().equals(loc)); assertTrue("data type is incorrect. should be xsd:anyURI", Objects.equals(occurrence.getDataType(), DataTypes.TYPE_URI)); } catch (MalformedURLException e) { fail("(INTERNAL) given URI was malformed"); } }
public void testNonURILocator() { try { occurrence.setLocator(new GenericLocator("URG", "l/e")); fail("non URI-locator could be set"); } catch (ConstraintViolationException e) { } try { occurrence.setValue("foo", new GenericLocator("URG", "l/e")); fail("non URI datatype could be set"); } catch (ConstraintViolationException e) { } try { occurrence.setReader(new StringReader("foo"), 3, new GenericLocator("URG", "l/e")); fail("non URI datatype could be set"); } catch (ConstraintViolationException e) { } }
public void testOccurrenceIndexLocator() { // STATE 1: No Occurrence locators defined TopicIF topic = builder.makeTopic(); TopicIF otype = builder.makeTopic(); LocatorIF loc1 = URILocator.create("http://www.ontopia.net/test-data/occurrence-locator1.xml"); LocatorIF loc2 = URILocator.create("http://www.ontopia.net/test-data/occurrence-locator2.xml"); OccurrenceIF occ = builder.makeOccurrence(topic, otype, loc1); assertTrue("Index of occurrences by locator is not one.", ix.getOccurrences(loc1.getAddress(), DataTypes.TYPE_URI).size() == 1); assertTrue("Index of occurrences by locator is not empty.", ix.getOccurrences(loc2.getAddress(), DataTypes.TYPE_URI).isEmpty()); // STATE 2: Occurrence locator added occ.setLocator(loc2); assertTrue("Index of occurrences by locator does not contain test value.", ix.getOccurrences(loc2.getAddress(), DataTypes.TYPE_URI).contains(occ)); assertTrue("Index of occurrences by locator is not empty.", ix.getOccurrences(loc1.getAddress(), DataTypes.TYPE_URI).isEmpty()); // STATE 3: Duplicate occurrence locator added OccurrenceIF occ2 = builder.makeOccurrence(topic, otype, loc2); assertTrue("second occurrence not found by locator", ix.getOccurrences(loc2.getAddress(), DataTypes.TYPE_URI).size() == 2); }
oabc.setLocator(new GenericLocator(notation, "bcd"));
oc.setLocator(URILocator.create("x:occurrence-locator")); afterTest();