public static String toString(String impl, VariantNameIF variant) { String id = UNASSIGNED; try { if (variant.getTopicMap() != null) id = variant.getObjectId(); if (Objects.equals(variant.getDataType(), DataTypes.TYPE_URI)) { return "[" + impl + ", " + id + " (" + variant.getValue() + ")]"; } else { String value = variant.getValue(); if (value == null) return "[" + impl + ", " + id + " null]"; else if (value.length() > MAX_STRING) return "[" + impl + ", " + id + " <" + value.substring(0, MAX_STRING) + "...>]"; else return "[" + impl + ", " + id + " <" + value + ">]"; } } catch (Throwable t) { return "[" + impl + ", " + variant.getObjectId() + "!]"; } }
/** * Write the given TopicNameIF to the given Writer, after line breaks with the * given indentString. */ private void writeVariant(VariantNameIF variant, Writer out) throws IOException { if (Objects.equals(variant.getDataType(), DataTypes.TYPE_STRING)) { String value = variant.getValue(); if (value != null) { out.write("(\""); out.write(escapeString(value)); out.write('"'); // Write the names of the scoping topics of this variant. writeScope(variant, out); out.write(')'); } } else { out.write("/* WARNING: LTM 1.3 cannot represent variant names that"); out.write(" are not of xsd:string type, hence cannot represent object ["); out.write(variant.getObjectId()); out.write("] */"); } }
@Override public void run() { TopicNameIF bn = getTopicName(); VariantNameIF vn = builder.makeVariantName(bn, ""); this.data.put("VariantNameIF", vn); this.objectId = vn.getObjectId(); } });
SnapshotVariantName(VariantNameIF 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.basename = SnapshotTopicName.makeSnapshot(original.getTopicName(), SnapshotTopic.SNAPSHOT_REFERENCE, processed); 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.reifier = SnapshotTopic.makeSnapshot(original.getReifier(), SnapshotTopic.SNAPSHOT_REFERENCE, processed); break; default: throw new OntopiaRuntimeException("Unknown snapshot type: " + snapshotType); } }
@Override public void run() { TopicNameIF bn = getTopicName(); VariantNameIF vn = (VariantNameIF)this.data.remove("VariantNameIF"); this.objectId = vn.getObjectId(); vn.remove(); } });
public void testBothBoundTrueVariant() throws InvalidQueryException, IOException { load("uri-vn.xtm"); TopicIF ontopia = getTopicById("ontopia"); TopicNameIF bn = (TopicNameIF) ontopia.getTopicNames().iterator().next(); VariantNameIF vn = (VariantNameIF) bn.getVariants().iterator().next(); List matches = new ArrayList(); matches.add(new HashMap()); verifyQuery(matches, "resource(@" + vn.getObjectId() +", \"http://www.ontopia.net/topicmaps/materials/logo.gif\")?"); closeStore(); }
@Override public void run() { VariantNameIF vn = getVariantName(); vn.setValue("New variant"); this.objectId = vn.getObjectId(); } });
@Override public void run() { VariantNameIF vn = getVariantName(); vn.setValue(""); this.objectId = vn.getObjectId(); } });
public void testWithBothBoundTrue() throws InvalidQueryException, IOException { load("family.ltm"); List matches = new ArrayList(); TopicIF topic = getTopicById("petter"); TopicNameIF bn = (TopicNameIF) topic.getTopicNames().iterator().next(); VariantNameIF vn = (VariantNameIF) bn.getVariants().iterator().next(); matches.add(new HashMap()); verifyQuery(matches, "variant(@" + bn.getObjectId() + ", @" + vn.getObjectId() + ")?"); closeStore(); }
@Override public void run() { VariantNameIF vn = getVariantName(); TopicIF theme = (TopicIF)this.data.remove("scope"); vn.removeTheme(theme); this.objectId = vn.getObjectId(); this.value = theme.getObjectId(); } });
public void testBothBoundFalseVariant() throws InvalidQueryException, IOException { load("uri-vn.xtm"); TopicIF ontopia = getTopicById("ontopia"); TopicNameIF bn = (TopicNameIF) ontopia.getTopicNames().iterator().next(); VariantNameIF vn = (VariantNameIF) bn.getVariants().iterator().next(); List matches = new ArrayList(); verifyQuery(matches, "resource(@" + vn.getObjectId() +", \"http://www.ontopia.com/topicmaps/materials/logo.gif\")?"); closeStore(); }
public void testWithBothBoundFalse() throws InvalidQueryException, IOException { load("family.ltm"); List matches = new ArrayList(); TopicIF topic1 = getTopicById("petter"); TopicNameIF bn1 = (TopicNameIF) topic1.getTopicNames().iterator().next(); TopicIF topic2 = getTopicById("asle"); TopicNameIF bn2 = (TopicNameIF) topic2.getTopicNames().iterator().next(); VariantNameIF vn = (VariantNameIF) bn2.getVariants().iterator().next(); verifyQuery(matches, "variant(@" + bn1.getObjectId() + ", @" + vn.getObjectId() + ")?"); closeStore(); }
public void testWithSpecificVariant() throws InvalidQueryException, IOException { load("family.ltm"); List matches = new ArrayList(); TopicIF topic = getTopicById("kfg"); TopicNameIF bn = (TopicNameIF) topic.getTopicNames().iterator().next(); VariantNameIF vn = (VariantNameIF) bn.getVariants().iterator().next(); addMatch(matches, "TN", bn); verifyQuery(matches, "variant($TN, @" + vn.getObjectId() + ")?"); closeStore(); }
public void testGetVariantLocator() throws InvalidQueryException, IOException { load("uri-vn.xtm"); TopicIF ontopia = getTopicById("ontopia"); TopicNameIF bn = (TopicNameIF) ontopia.getTopicNames().iterator().next(); VariantNameIF vn = (VariantNameIF) bn.getVariants().iterator().next(); List matches = new ArrayList(); addMatch(matches, "LOCATOR", "http://www.ontopia.net/topicmaps/materials/logo.gif"); verifyQuery(matches, "resource(@" + vn.getObjectId() +", $LOCATOR)?"); closeStore(); }
@Override public void run() { VariantNameIF vn = getVariantName(); vn.addItemIdentifier(URILocator.create("x:source-locator")); this.objectId = vn.getObjectId(); } });
@Override public void run() { VariantNameIF vn = getVariantName(); vn.setLocator(URILocator.create("x:variant-locator")); this.objectId = vn.getObjectId(); } });
@Override public void run() { VariantNameIF vn = getVariantName(); vn.setLocator(URILocator.create("x:variant-locator:clear")); this.objectId = vn.getObjectId(); } });
@Override public void run() { VariantNameIF vn = getVariantName(); vn.removeItemIdentifier(URILocator.create("x:source-locator")); this.objectId = vn.getObjectId(); } });
@Override public void run() { VariantNameIF vn = getVariantName(); TopicIF theme = builder.makeTopic(); this.data.put("scope", theme); vn.addTheme(theme); this.objectId = vn.getObjectId(); this.value = theme.getObjectId(); } });
@Put public void addVariantName(VariantName variant) { if (variant == null) { throw OntopiaRestErrors.MANDATORY_OBJECT_IS_NULL.build("VariantName"); } VariantNameIF result = getController(VariantNameController.class).add( getTopicMap(), Parameters.TOPICNAME.required(this), variant); store.commit(); // todo: maybe this should be '302 Found' instead redirectSeeOther("../../variants/" + result.getObjectId()); // todo: how to make this stable? } }