|
From: <lh...@us...> - 2009-07-21 14:54:43
|
Revision: 316
http://tinytim.svn.sourceforge.net/tinytim/?rev=316&view=rev
Author: lheuer
Date: 2009-07-21 14:54:31 +0000 (Tue, 21 Jul 2009)
Log Message:
-----------
Solves #2824834 partially.
Test testOntopiaIssue84VariantReifier3 fails :(
Modified Paths:
--------------
tinytim/trunk/src/main/java/org/tinytim/internal/utils/MergeUtils.java
tinytim/trunk/src/main/java/org/tinytim/internal/utils/SignatureGenerator.java
tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java
tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java
Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/MergeUtils.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/internal/utils/MergeUtils.java 2009-07-20 09:20:12 UTC (rev 315)
+++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/MergeUtils.java 2009-07-21 14:54:31 UTC (rev 316)
@@ -105,7 +105,7 @@
assert sourceReifiable != target.getReified();
throw new ModelConstraintException(target, "The topics cannot be merged. They reify different Topic Maps constructs");
}
- _moveItemIdentifiers(source, target);
+ moveItemIdentifiers(source, target);
if (sourceReifiable != null) {
sourceReifiable.setReifier(target);
}
@@ -226,7 +226,7 @@
* @param target The target Topic Maps construct.
*/
public static void handleExistingConstruct(Reifiable source, Reifiable target) {
- _moveItemIdentifiers(source, target);
+ moveItemIdentifiers(source, target);
if (source.getReifier() == null) {
return;
}
@@ -310,7 +310,7 @@
* @param source The source to remove the item identifiers from.
* @param target The target which get the item identifiers.
*/
- private static void _moveItemIdentifiers(Construct source, Construct target) {
+ public static void moveItemIdentifiers(Construct source, Construct target) {
List<Locator> iids = CollectionFactory.createList(source.getItemIdentifiers());
for (Locator iid: iids) {
source.removeItemIdentifier(iid);
Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/SignatureGenerator.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/internal/utils/SignatureGenerator.java 2009-07-20 09:20:12 UTC (rev 315)
+++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/SignatureGenerator.java 2009-07-21 14:54:31 UTC (rev 316)
@@ -18,6 +18,7 @@
import java.util.Arrays;
import java.util.Collection;
+import org.tinytim.internal.api.IConstruct;
import org.tinytim.internal.api.ILiteralAware;
import org.tinytim.internal.api.IScoped;
@@ -51,6 +52,25 @@
// noop.
}
+ public static int generateSignature(IConstruct construct) {
+ if (construct.isAssociation()) {
+ return generateSignature((Association) construct);
+ }
+ else if (construct.isOccurrence()) {
+ return generateSignature((Occurrence) construct);
+ }
+ else if (construct.isName()) {
+ return generateSignature((Name) construct);
+ }
+ else if (construct.isVariant()) {
+ return generateSignature((Variant) construct);
+ }
+ else if (construct.isRole()) {
+ return generateSignature((Role) construct);
+ }
+ throw new IllegalArgumentException("Only association, role, occurrence, name, and variant are supported");
+ }
+
/**
* Returns the signature of an association.
*
Modified: tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java
===================================================================
--- tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-20 09:20:12 UTC (rev 315)
+++ tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-21 14:54:31 UTC (rev 316)
@@ -16,6 +16,7 @@
package org.tinytim.mio;
import java.util.List;
+import java.util.Map;
import org.tinytim.core.Scope;
import org.tinytim.core.value.Literal;
@@ -29,6 +30,8 @@
import org.tinytim.internal.api.ITopicMap;
import org.tinytim.internal.api.IVariant;
import org.tinytim.internal.utils.CollectionFactory;
+import org.tinytim.internal.utils.MergeUtils;
+import org.tinytim.internal.utils.SignatureGenerator;
import org.tinytim.utils.TypeInstanceConverter;
import org.tinytim.voc.TMDM;
@@ -72,10 +75,12 @@
private static final int _CONSTRUCT_SIZE = 6;
private static final int _STATE_SIZE = 10;
private static final int _SCOPE_SIZE = 6;
+ private static final int _DELAYED_REIFICATION_SIZE = 2;
private final IConstructFactory _factory;
private final ITopicMap _tm;
private final List<Topic> _scope;
+ private final Map<Reifiable, Topic> _delayedReification;
private byte[] _stateStack;
private int _stateSize;
private IConstruct[] _constructStack;
@@ -88,11 +93,13 @@
_tm = (ITopicMap) topicMap;
_factory = _tm.getConstructFactory();
_scope = CollectionFactory.createList(_SCOPE_SIZE);
+ _delayedReification = CollectionFactory.createIdentityMap(_DELAYED_REIFICATION_SIZE);
}
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startTopicMap()
*/
+ @Override
public void startTopicMap() throws MIOException {
_constructStack = new IConstruct[_CONSTRUCT_SIZE];
_stateStack = new byte[_STATE_SIZE];
@@ -104,6 +111,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endTopicMap()
*/
+ @Override
public void endTopicMap() throws MIOException {
TypeInstanceConverter.convertAssociationsToTypes(_tm);
_constructStack = null;
@@ -114,6 +122,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startTopic(com.semagia.mio.IRef)
*/
+ @Override
public void startTopic(IRef identity) throws MIOException {
_enterState(TOPIC, _createTopic(identity));
}
@@ -121,6 +130,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endTopic()
*/
+ @Override
public void endTopic() throws MIOException {
_handleTopic((Topic) _leaveStatePopConstruct(TOPIC));
}
@@ -128,6 +138,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startAssociation()
*/
+ @Override
public void startAssociation() throws MIOException {
_enterState(ASSOCIATION, _factory.createAssociation());
}
@@ -135,13 +146,15 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endAssociation()
*/
+ @Override
public void endAssociation() throws MIOException {
- _leaveStatePopConstruct(ASSOCIATION);
+ _leaveStatePopReifiable(ASSOCIATION);
}
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startRole()
*/
+ @Override
public void startRole() throws MIOException {
assert _state() == ASSOCIATION;
_enterState(ROLE, _factory.createRole((Association) _peekConstruct()));
@@ -150,6 +163,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endRole()
*/
+ @Override
public void endRole() throws MIOException {
_leaveStatePopConstruct(ROLE);
}
@@ -157,6 +171,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startPlayer()
*/
+ @Override
public void startPlayer() throws MIOException {
assert _state() == ROLE;
_enterState(PLAYER);
@@ -165,6 +180,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endPlayer()
*/
+ @Override
public void endPlayer() throws MIOException {
_leaveState(PLAYER);
assert _state() == ROLE;
@@ -173,6 +189,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startOccurrence()
*/
+ @Override
public void startOccurrence() throws MIOException {
_enterState(OCCURRENCE, _factory.createOccurrence(_peekTopic()));
}
@@ -180,13 +197,15 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endOccurrence()
*/
+ @Override
public void endOccurrence() throws MIOException {
- _leaveStatePopConstruct(OCCURRENCE);
+ _leaveStatePopReifiable(OCCURRENCE);
}
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startName()
*/
+ @Override
public void startName() throws MIOException {
_enterState(NAME, _factory.createName(_peekTopic()));
}
@@ -194,16 +213,19 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endName()
*/
+ @Override
public void endName() throws MIOException {
IName name = (IName) _leaveStatePopConstruct(NAME);
if (name.getType() == null) {
name.setType(_tm.createTopicBySubjectIdentifier(TMDM.TOPIC_NAME));
}
+ _handleDelayedReifier(name);
}
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startVariant()
*/
+ @Override
public void startVariant() throws MIOException {
assert _state() == NAME;
_enterState(VARIANT, _factory.createVariant((IName) _peekConstruct()));
@@ -212,6 +234,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endVariant()
*/
+ @Override
public void endVariant() throws MIOException {
IVariant variant = (IVariant) _leaveStatePopConstruct(VARIANT);
IName name = (IName) _peekConstruct();
@@ -219,11 +242,13 @@
if (scope.isUnconstrained() || name.getScopeObject().equals(scope)) {
_reportError("The variant has no scope");
}
+ _handleDelayedReifier(variant);
}
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startType()
*/
+ @Override
public void startType() throws MIOException {
assert _peekConstruct() instanceof Typed;
_enterState(TYPE);
@@ -232,6 +257,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endType()
*/
+ @Override
public void endType() throws MIOException {
_leaveState(TYPE);
assert _peekConstruct() instanceof Typed;
@@ -240,6 +266,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startScope()
*/
+ @Override
public void startScope() throws MIOException {
assert _peekConstruct() instanceof Scoped;
_enterState(SCOPE);
@@ -248,6 +275,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endScope()
*/
+ @Override
public void endScope() throws MIOException {
_leaveState(SCOPE);
((IScoped) _peekConstruct()).setScopeObject(Scope.create(_scope));
@@ -257,6 +285,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startTheme()
*/
+ @Override
public void startTheme() throws MIOException {
assert _state() == SCOPE;
_enterState(THEME);
@@ -265,6 +294,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endTheme()
*/
+ @Override
public void endTheme() throws MIOException {
_leaveState(THEME);
assert _state() == SCOPE;
@@ -273,6 +303,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#subjectIdentifier(java.lang.String)
*/
+ @Override
public void subjectIdentifier(String subjectIdentifier) throws MIOException {
Locator sid = _tm.createLocator(subjectIdentifier);
ITopic topic = _peekTopic();
@@ -292,6 +323,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#subjectLocator(java.lang.String)
*/
+ @Override
public void subjectLocator(String subjectLocator) throws MIOException {
Locator slo = _tm.createLocator(subjectLocator);
ITopic topic = _peekTopic();
@@ -305,6 +337,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#itemIdentifier(java.lang.String)
*/
+ @Override
public void itemIdentifier(String itemIdentifier) throws MIOException {
Locator iid = _tm.createLocator(itemIdentifier);
IConstruct tmo = _peekConstruct();
@@ -326,6 +359,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startIsa()
*/
+ @Override
public void startIsa() throws MIOException {
assert _state() == TOPIC;
_enterState(ISA);
@@ -334,6 +368,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endIsa()
*/
+ @Override
public void endIsa() throws MIOException {
_leaveState(ISA);
assert _state() == TOPIC;
@@ -342,6 +377,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#startReifier()
*/
+ @Override
public void startReifier() throws MIOException {
assert _peekConstruct() instanceof Reifiable;
_enterState(REIFIER);
@@ -350,6 +386,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#endReifier()
*/
+ @Override
public void endReifier() throws MIOException {
_leaveState(REIFIER);
assert _peekConstruct() instanceof Reifiable;
@@ -358,6 +395,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#topicRef(com.semagia.mio.IRef)
*/
+ @Override
public void topicRef(IRef identity) throws MIOException {
_handleTopic(_createTopic(identity));
}
@@ -365,6 +403,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#value(java.lang.String)
*/
+ @Override
public void value(String value) throws MIOException {
assert _state() == NAME;
((IName) _peekConstruct()).setValue(value);
@@ -373,6 +412,7 @@
/* (non-Javadoc)
* @see com.semagia.mio.IMapHandler#value(java.lang.String, java.lang.String)
*/
+ @Override
public void value(String value, String datatype) throws MIOException {
((ILiteralAware) _peekConstruct()).setLiteral(Literal.create(value, datatype));
}
@@ -436,6 +476,12 @@
return construct;
}
+ private Reifiable _leaveStatePopReifiable(byte state) throws MIOException {
+ final Reifiable reifiable = (Reifiable) _leaveStatePopConstruct(state);
+ _handleDelayedReifier(reifiable);
+ return reifiable;
+ }
+
/**
* Returns the Topic Maps construct on top of the stack.
*
@@ -446,6 +492,75 @@
}
/**
+ *
+ *
+ * @param reifiable
+ * @throws MIOException
+ */
+ private void _handleDelayedReifier(final Reifiable reifiable) throws MIOException {
+ Topic reifier = _delayedReification.remove(reifiable);
+ final IConstruct c = (IConstruct) reifiable;
+ if (reifier != null) {
+ _handleDelayedReifier(reifiable, reifier);
+ return;
+ }
+ List<? extends Reifiable> reifiables = null;
+ if (c.isAssociation()) {
+ reifiables = CollectionFactory.createList(((Association) c).getRoles());
+ }
+ else if (c.isName()) {
+ reifiables = CollectionFactory.createList(((IName) c).getVariants());
+ }
+ if (reifiables == null || _delayedReification.isEmpty()) {
+ return;
+ }
+ boolean foundReifier = false;
+ final int parentSignature = SignatureGenerator.generateSignature(c);
+ for (Reifiable r: reifiables) {
+ reifier = _delayedReification.remove(r);
+ if (reifier == null) {
+ continue;
+ }
+ if (parentSignature == SignatureGenerator.generateSignature((IConstruct) reifier.getReified().getParent())) {
+ _handleDelayedReifier(r, reifier);
+ foundReifier = true;
+ }
+ else {
+ throw new MIOException("The topic '" + reifier + "' reifies another construct");
+ }
+ }
+ if (foundReifier) {
+ c.remove();
+ }
+ }
+
+ /**
+ *
+ *
+ * @param reifiable
+ * @param reifier
+ * @throws MIOException
+ */
+ private void _handleDelayedReifier(final Reifiable reifiable, final Topic reifier) throws MIOException {
+ IConstruct c = (IConstruct) reifiable;
+ if (SignatureGenerator.generateSignature(c) ==
+ SignatureGenerator.generateSignature((IConstruct) reifier.getReified())) {
+ MergeUtils.moveItemIdentifiers(reifiable, reifier.getReified());
+ if (c.isAssociation()) {
+ MergeUtils.moveRoleCharacteristics((Association) c, (Association) reifier.getReified());
+ }
+ else if (c.isName()) {
+ MergeUtils.moveVariants((IName) c, (IName) reifier.getReified());
+ }
+ reifiable.remove();
+ _delayedReification.remove(reifiable);
+ }
+ else {
+ throw new MIOException("The topic " + reifier + " reifies another construct");
+ }
+ }
+
+ /**
* Returns the topic on top of the stack.
*
* @return The topic.
@@ -467,18 +582,60 @@
* Handles the topic dependent on the current state.
*
* @param topic The topic to handle.
+ * @throws MIOException
*/
- private void _handleTopic(Topic topic) {
+ private void _handleTopic(Topic topic) throws MIOException {
switch (_state()) {
case ISA: _peekTopic().addType(topic); break;
case TYPE: ((Typed) _peekConstruct()).setType(topic); break;
case PLAYER: ((Role) _peekConstruct()).setPlayer(topic); break;
case THEME: _scope.add(topic); break;
- case REIFIER: ((Reifiable) _peekConstruct()).setReifier(topic); break;
+ case REIFIER: _handleReifier((Reifiable) _peekConstruct(), topic); break;
}
}
/**
+ *
+ *
+ * @param reifiable
+ * @param reifier
+ * @throws MIOException
+ */
+ private void _handleReifier(Reifiable reifiable, Topic reifier) throws MIOException {
+ final Reifiable reified = reifier.getReified();
+ if (reified != null && !reifiable.equals(reified)) {
+ if (!_sameConstructKind((IConstruct) reifiable, (IConstruct) reified)
+ || !_areMergable((IConstruct) reifiable, (IConstruct) reified)) {
+ throw new MIOException("The topic " + reifier + " reifies another construct");
+ }
+ // The construct reified by 'reifier' has the same parent as the
+ // construct which should be reified and both are of the same kind
+ // Try to merge them once we have collected all information about
+ // the 'reifiable'
+ _delayedReification.put(reifiable, reifier);
+ }
+ else {
+ reifiable.setReifier(reifier);
+ }
+ }
+
+ private boolean _sameConstructKind(IConstruct a, IConstruct b) {
+ return a.isAssociation() && b.isAssociation()
+ || a.isName() && b.isName()
+ || a.isOccurrence() && b.isOccurrence()
+ || a.isVariant() && b.isVariant()
+ || a.isRole() && b.isRole()
+ || a.isTopicMap() && b.isTopicMap()
+ || a.isTopic() && b.isTopic();
+ }
+
+ private boolean _areMergable(IConstruct a, IConstruct b) {
+ return a.isRole() && b.isRole()
+ || (a.isVariant() && b.isVariant() && a.getParent().getParent().equals(b.getParent().getParent()))
+ || a.getParent().equals(b.getParent());
+ }
+
+ /**
* Merges the <tt>source</tt> topic with the <tt>target</tt>.
*
* Further, this method ensures that the construct stack stays valid: If
@@ -494,6 +651,12 @@
_constructStack[i] = target;
}
}
+ for (Reifiable reifiable: CollectionFactory.createList(_delayedReification.keySet())) {
+ Topic topic = _delayedReification.get(reifiable);
+ if (topic.equals(target)) {
+ _delayedReification.put(reifiable, target);
+ }
+ }
target.mergeIn(source);
}
Modified: tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java
===================================================================
--- tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-20 09:20:12 UTC (rev 315)
+++ tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-21 14:54:31 UTC (rev 316)
@@ -18,6 +18,8 @@
import org.tinytim.core.TinyTimTestCase;
import org.tinytim.voc.TMDM;
import org.tinytim.voc.XSD;
+import org.tmapi.core.Association;
+import org.tmapi.core.Construct;
import org.tmapi.core.Locator;
import org.tmapi.core.Name;
import org.tmapi.core.Occurrence;
@@ -49,12 +51,14 @@
_handler = new TinyTimMapInputHandler(_tm);
}
+ /**
+ * <a href="http://code.google.com/p/mappa/issues/detail?id=23">http://code.google.com/p/mappa/issues/detail?id=23</a>
+ */
public void testMappaIssue23() throws Exception {
- // http://code.google.com/p/mappa/issues/detail?id=23
String iid = "http://mappa.semagia.com/issue-23";
String iid2 = "http://mappa.semagia.com/issue-23_";
final IRef TOPIC_NAME = Ref.createSubjectIdentifier(TMDM.TOPIC_NAME.getReference());
- TinyTimMapInputHandler handler = this._handler;
+ TinyTimMapInputHandler handler = _handler;
handler.startTopicMap();
handler.startTopic(Ref.createItemIdentifier(iid));
handler.startName();
@@ -77,6 +81,376 @@
}
/**
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a>
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a>
+ */
+ public void testOntopiaIssue84() throws Exception {
+ TinyTimMapInputHandler handler = _handler;
+ final IRef assocType = Ref.createItemIdentifier("http://test.semagia.com/assoc-type");
+ final IRef roleType = Ref.createItemIdentifier("http://test.semagia.com/role-type");
+ final IRef rolePlayer = Ref.createItemIdentifier("http://test.semagia.com/role-player");
+ final IRef reifier = Ref.createItemIdentifier("http://test.semagia.com/reifier");
+ final String roleIID = "http://test.semagia.com/role-iid";
+ handler.startTopicMap();
+ handler.startAssociation();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.startType();
+ handler.topicRef(assocType);
+ handler.endType();
+ handler.startRole();
+ handler.itemIdentifier(roleIID);
+ handler.startType();
+ handler.topicRef(roleType);
+ handler.endType();
+ handler.startPlayer();
+ handler.topicRef(rolePlayer);
+ handler.endPlayer();
+ handler.endRole();
+ handler.endAssociation();
+
+ handler.startAssociation();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.startType();
+ handler.topicRef(assocType);
+ handler.endType();
+ handler.startRole();
+ handler.startType();
+ handler.topicRef(roleType);
+ handler.endType();
+ handler.startPlayer();
+ handler.topicRef(rolePlayer);
+ handler.endPlayer();
+ handler.endRole();
+ handler.endAssociation();
+ handler.endTopicMap();
+ assertEquals(1, _tm.getAssociations().size());
+ final Association assoc = _tm.getAssociations().iterator().next();
+ assertNotNull(assoc.getReifier());
+ final Construct tmc = _tm.getConstructByItemIdentifier(createLocator(roleIID));
+ assertNotNull(tmc);
+ assertEquals(assoc, tmc.getParent());
+ }
+
+ /**
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a>
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a>
+ */
+ public void testOntopiaIssue84_2() throws Exception {
+ TinyTimMapInputHandler handler = _handler;
+ final IRef assocType = Ref.createItemIdentifier("http://test.semagia.com/assoc-type");
+ final IRef roleType = Ref.createItemIdentifier("http://test.semagia.com/role-type");
+ final IRef rolePlayer = Ref.createItemIdentifier("http://test.semagia.com/role-player");
+ final IRef reifier = Ref.createItemIdentifier("http://test.semagia.com/reifier");
+ final String roleIID = "http://test.semagia.com/role-iid";
+ handler.startTopicMap();
+ handler.startAssociation();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.startType();
+ handler.topicRef(assocType);
+ handler.endType();
+ handler.startRole();
+ handler.startType();
+ handler.topicRef(roleType);
+ handler.endType();
+ handler.startPlayer();
+ handler.topicRef(rolePlayer);
+ handler.endPlayer();
+ handler.endRole();
+ handler.endAssociation();
+
+ handler.startAssociation();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.startType();
+ handler.topicRef(assocType);
+ handler.endType();
+ handler.startRole();
+ handler.itemIdentifier(roleIID);
+ handler.startType();
+ handler.topicRef(roleType);
+ handler.endType();
+ handler.startPlayer();
+ handler.topicRef(rolePlayer);
+ handler.endPlayer();
+ handler.endRole();
+ handler.endAssociation();
+ handler.endTopicMap();
+ assertEquals(1, _tm.getAssociations().size());
+ final Association assoc = _tm.getAssociations().iterator().next();
+ assertNotNull(assoc.getReifier());
+ final Construct tmc = _tm.getConstructByItemIdentifier(createLocator(roleIID));
+ assertNotNull(tmc);
+ assertEquals(assoc, tmc.getParent());
+ }
+
+ /**
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a>
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a>
+ */
+ public void testOntopiaIssue84RoleReifier() throws Exception {
+ TinyTimMapInputHandler handler = _handler;
+ final IRef assocType = Ref.createItemIdentifier("http://test.semagia.com/assoc-type");
+ final IRef roleType = Ref.createItemIdentifier("http://test.semagia.com/role-type");
+ final IRef rolePlayer = Ref.createItemIdentifier("http://test.semagia.com/role-player");
+ final IRef reifier = Ref.createItemIdentifier("http://test.semagia.com/reifier");
+ final String roleIID = "http://test.semagia.com/role-iid";
+ handler.startTopicMap();
+ handler.startAssociation();
+ handler.startType();
+ handler.topicRef(assocType);
+ handler.endType();
+ handler.startRole();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.itemIdentifier(roleIID);
+ handler.startType();
+ handler.topicRef(roleType);
+ handler.endType();
+ handler.startPlayer();
+ handler.topicRef(rolePlayer);
+ handler.endPlayer();
+ handler.endRole();
+ handler.endAssociation();
+
+ handler.startAssociation();
+ handler.startType();
+ handler.topicRef(assocType);
+ handler.endType();
+ handler.startRole();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.startType();
+ handler.topicRef(roleType);
+ handler.endType();
+ handler.startPlayer();
+ handler.topicRef(rolePlayer);
+ handler.endPlayer();
+ handler.endRole();
+ handler.endAssociation();
+ handler.endTopicMap();
+ assertEquals(1, _tm.getAssociations().size());
+ final Association assoc = _tm.getAssociations().iterator().next();
+ assertNull(assoc.getReifier());
+ final Construct tmc = _tm.getConstructByItemIdentifier(createLocator(roleIID));
+ assertNotNull(tmc);
+ assertEquals(assoc, tmc.getParent());
+ }
+
+ /**
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a>
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a>
+ */
+ public void testOntopiaIssue84RoleReifier2() throws Exception {
+ TinyTimMapInputHandler handler = _handler;
+ final IRef assocType = Ref.createItemIdentifier("http://test.semagia.com/assoc-type");
+ final IRef assocType2 = Ref.createItemIdentifier("http://test.semagia.com/assoc-type2");
+ final IRef roleType = Ref.createItemIdentifier("http://test.semagia.com/role-type");
+ final IRef rolePlayer = Ref.createItemIdentifier("http://test.semagia.com/role-player");
+ final String reifierIID = "http://test.semagia.com/reifier";
+ final IRef reifier = Ref.createItemIdentifier(reifierIID);
+ final String roleIID = "http://test.semagia.com/role-iid";
+ handler.startTopicMap();
+ handler.startAssociation();
+ handler.startType();
+ handler.topicRef(assocType);
+ handler.endType();
+ handler.startRole();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.itemIdentifier(roleIID);
+ handler.startType();
+ handler.topicRef(roleType);
+ handler.endType();
+ handler.startPlayer();
+ handler.topicRef(rolePlayer);
+ handler.endPlayer();
+ handler.endRole();
+ handler.endAssociation();
+ try {
+ handler.startAssociation();
+ handler.startType();
+ handler.topicRef(assocType2);
+ handler.endType();
+ handler.startRole();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.startType();
+ handler.topicRef(roleType);
+ handler.endType();
+ handler.startPlayer();
+ handler.topicRef(rolePlayer);
+ handler.endPlayer();
+ handler.endRole();
+ handler.endAssociation();
+ handler.endTopicMap();
+ fail("The topic " + reifierIID + " reifies another role");
+ }
+ catch (MIOException ex) {
+ // noop.
+ }
+ }
+
+ /**
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a>
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a>
+ */
+ public void testOntopiaIssue84VariantReifier() throws Exception {
+ TinyTimMapInputHandler handler = _handler;
+ final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic");
+ final String reifierIID = "http://test.semagia.com/reifier";
+ final String variantIID = "http://test.semagia.com/variant";
+ final IRef reifier = Ref.createItemIdentifier(reifierIID);
+ final IRef theme = Ref.createItemIdentifier("http://test.semagia.com/theme");
+ handler.startTopicMap();
+ handler.startTopic(theTopic);
+ handler.startName();
+ handler.value("Semagia");
+ handler.startVariant();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.itemIdentifier(variantIID);
+ handler.startScope();
+ handler.startTheme();
+ handler.topicRef(theme);
+ handler.endTheme();
+ handler.endScope();
+ handler.endVariant();
+ handler.endName();
+
+ handler.startName();
+ handler.value("Semagia");
+ handler.startVariant();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.startScope();
+ handler.startTheme();
+ handler.topicRef(theme);
+ handler.endTheme();
+ handler.endScope();
+ handler.endVariant();
+ handler.endName();
+ handler.endTopic();
+ handler.endTopicMap();
+ Topic reifying = (Topic) _tm.getConstructByItemIdentifier(createLocator(reifierIID));
+ assertNotNull(reifying);
+ assertNotNull(reifying.getReified());
+ assertEquals(reifying.getReified(), _tm.getConstructByItemIdentifier(createLocator(variantIID)));
+ }
+
+ /**
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a>
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a>
+ */
+ public void testOntopiaIssue84VariantReifier2() throws Exception {
+ TinyTimMapInputHandler handler = _handler;
+ final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic");
+ final String reifierIID = "http://test.semagia.com/reifier";
+ final String variantIID = "http://test.semagia.com/variant";
+ final IRef reifier = Ref.createItemIdentifier(reifierIID);
+ final IRef theme = Ref.createItemIdentifier("http://test.semagia.com/theme");
+ handler.startTopicMap();
+ handler.startTopic(theTopic);
+ handler.startName();
+ handler.value("Semagia");
+ handler.startVariant();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.startScope();
+ handler.startTheme();
+ handler.topicRef(theme);
+ handler.endTheme();
+ handler.endScope();
+ handler.endVariant();
+ handler.endName();
+
+ handler.startName();
+ handler.value("Semagia");
+ handler.startVariant();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.itemIdentifier(variantIID);
+ handler.startScope();
+ handler.startTheme();
+ handler.topicRef(theme);
+ handler.endTheme();
+ handler.endScope();
+ handler.endVariant();
+ handler.endName();
+ handler.endTopic();
+ handler.endTopicMap();
+ Topic reifying = (Topic) _tm.getConstructByItemIdentifier(createLocator(reifierIID));
+ assertNotNull(reifying);
+ assertNotNull(reifying.getReified());
+ assertEquals(reifying.getReified(), _tm.getConstructByItemIdentifier(createLocator(variantIID)));
+ }
+
+ /**
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=84">http://code.google.com/p/ontopia/issues/detail?id=84</a>
+ * <a href="http://code.google.com/p/ontopia/issues/detail?id=77">http://code.google.com/p/ontopia/issues/detail?id=77</a>
+ */
+ public void testOntopiaIssue84VariantReifier3() throws Exception {
+ TinyTimMapInputHandler handler = _handler;
+ final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic");
+ final String reifierIID = "http://test.semagia.com/reifier";
+ final String variantIID = "http://test.semagia.com/variant";
+ final IRef reifier = Ref.createItemIdentifier(reifierIID);
+ final IRef theme = Ref.createItemIdentifier("http://test.semagia.com/theme");
+ handler.startTopicMap();
+ handler.startTopic(theTopic);
+ handler.startName();
+ handler.value("Semagia");
+ handler.startVariant();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.startScope();
+ handler.startTheme();
+ handler.topicRef(theme);
+ handler.endTheme();
+ handler.endScope();
+ handler.endVariant();
+ handler.endName();
+
+ try {
+ handler.startName();
+ handler.value("Not Semagia");
+ handler.startVariant();
+ handler.startReifier();
+ handler.topicRef(reifier);
+ handler.endReifier();
+ handler.itemIdentifier(variantIID);
+ handler.startScope();
+ handler.startTheme();
+ handler.topicRef(theme);
+ handler.endTheme();
+ handler.endScope();
+ handler.endVariant();
+ handler.endName();
+ handler.endTopic();
+ handler.endTopicMap();
+ fail("The topic " + reifierIID + " reifies a variant of another name which is not equal");
+ }
+ catch (MIOException ex) {
+ // noop.
+ }
+ }
+
+ /**
* Simple startTopicMap, followed by an endTopicMap event.
*/
public void testEmpty() throws Exception {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|