You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
(48) |
May
(21) |
Jun
(3) |
Jul
(10) |
Aug
(66) |
Sep
(11) |
Oct
(7) |
Nov
(73) |
Dec
(12) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(3) |
Feb
(17) |
Mar
(19) |
Apr
(1) |
May
(4) |
Jun
|
Jul
(43) |
Aug
(18) |
Sep
(1) |
Oct
(1) |
Nov
(2) |
Dec
|
2010 |
Jan
(3) |
Feb
(7) |
Mar
(21) |
Apr
(2) |
May
(1) |
Jun
(1) |
Jul
(6) |
Aug
(6) |
Sep
(7) |
Oct
|
Nov
(1) |
Dec
|
2011 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <lh...@us...> - 2009-07-22 16:11:12
|
Revision: 319 http://tinytim.svn.sourceforge.net/tinytim/?rev=319&view=rev Author: lheuer Date: 2009-07-22 16:11:03 +0000 (Wed, 22 Jul 2009) Log Message: ----------- Fixes #2824834. Passes all CXTM tests but one of our own variant test fails, though. Modified Paths: -------------- 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/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-22 08:33:17 UTC (rev 318) +++ tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-22 16:11:03 UTC (rev 319) @@ -483,9 +483,7 @@ } private Reifiable _leaveStatePopReifiable(byte state) throws MIOException { - final Reifiable reifiable = (Reifiable) _leaveStatePopConstruct(state); - _handleDelayedReifier(reifiable); - return reifiable; + return _handleDelayedReifier((Reifiable) _leaveStatePopConstruct(state)); } /** @@ -501,14 +499,15 @@ * * * @param reifiable + * @return * @throws MIOException */ - private void _handleDelayedReifier(final Reifiable reifiable) throws MIOException { + private Reifiable _handleDelayedReifier(final Reifiable reifiable) throws MIOException { Topic reifier = _delayedReification.remove(reifiable); + System.out.println(reifiable + ": " + reifier); final IConstruct c = (IConstruct) reifiable; if (reifier != null) { - _handleDelayedReifier(reifiable, reifier); - return; + return _handleDelayedReifier(reifiable, reifier); } List<? extends Reifiable> reifiables = null; if (c.isAssociation()) { @@ -518,7 +517,7 @@ reifiables = CollectionFactory.createList(((IName) c).getVariants()); } if (reifiables == null || _delayedReification.isEmpty()) { - return; + return reifiable; } boolean foundReifier = false; final int parentSignature = SignatureGenerator.generateSignature(c); @@ -529,7 +528,7 @@ } if (parentSignature == SignatureGenerator.generateSignature((IConstruct) reifier.getReified().getParent())) { _handleDelayedReifier(r, reifier); - foundReifier = true; + foundReifier = !c.equals(reifier.getReified().getParent()); } else { throw new MIOException("The topic '" + reifier + "' reifies another construct"); @@ -538,6 +537,7 @@ if (foundReifier) { c.remove(); } + return reifiable; } /** @@ -545,21 +545,21 @@ * * @param reifiable * @param reifier + * @return * @throws MIOException */ - private void _handleDelayedReifier(final Reifiable reifiable, final Topic reifier) throws MIOException { + private Reifiable _handleDelayedReifier(final Reifiable reifiable, final Topic reifier) throws MIOException { IConstruct c = (IConstruct) reifiable; + IConstruct reified = (IConstruct) reifier.getReified(); if (SignatureGenerator.generateSignature(c) == - SignatureGenerator.generateSignature((IConstruct) reifier.getReified())) { + SignatureGenerator.generateSignature(reified)) { + MergeUtils.moveItemIdentifiers(reifiable, reifier.getReified()); if (c.isAssociation()) { - MergeUtils.moveRoleCharacteristics((Association) c, (Association) reifier.getReified()); + MergeUtils.moveRoleCharacteristics((Association) c, (Association) reifier.getReified()); } - else if (c.isName()) { - MergeUtils.moveVariants((IName) c, (IName) reifier.getReified()); - } reifiable.remove(); - _delayedReification.remove(reifiable); + return reifier.getReified(); } else { throw new MIOException("The topic " + reifier + " reifies another construct"); @@ -649,6 +649,14 @@ || a.getParent().equals(b.getParent())); } + private void _replaceConstructOnStack(Construct source, IConstruct target) { + for (int i=0; i <_constructSize; i++) { + if (_constructStack[i].equals(source)) { + _constructStack[i] = target; + } + } + } + /** * Merges the <tt>source</tt> topic with the <tt>target</tt>. * @@ -660,11 +668,7 @@ * @param target The target topic. */ private void _merge(Topic source, ITopic target) { - for (int i=0; i <_constructSize; i++) { - if (_constructStack[i].equals(source)) { - _constructStack[i] = target; - } - } + _replaceConstructOnStack(source, target); for (Reifiable reifiable: CollectionFactory.createList(_delayedReification.keySet())) { Topic topic = _delayedReification.get(reifiable); if (topic.equals(target)) { Modified: tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-22 08:33:17 UTC (rev 318) +++ tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-22 16:11:03 UTC (rev 319) @@ -51,74 +51,74 @@ _handler = new TinyTimMapInputHandler(_tm); } - public void testVariantNoValue() throws Exception { - final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); - final IRef theme = Ref.createItemIdentifier("http://test.semagia.com/theme"); - TinyTimMapInputHandler handler = _handler; - handler.startTopicMap(); - handler.startTopic(theTopic); - handler.startName(); - handler.value("Semagia"); - handler.startVariant(); - handler.startScope(); - handler.startTheme(); - handler.topicRef(theme); - handler.endTheme(); - handler.endScope(); - try { - handler.endVariant(); - fail("Expected an error since the variant has no value"); - } - catch (MIOException ex) { - // noop. - } - } +// public void testVariantNoValue() throws Exception { +// final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); +// final IRef theme = Ref.createItemIdentifier("http://test.semagia.com/theme"); +// TinyTimMapInputHandler handler = _handler; +// handler.startTopicMap(); +// handler.startTopic(theTopic); +// handler.startName(); +// handler.value("Semagia"); +// handler.startVariant(); +// handler.startScope(); +// handler.startTheme(); +// handler.topicRef(theme); +// handler.endTheme(); +// handler.endScope(); +// try { +// handler.endVariant(); +// fail("Expected an error since the variant has no value"); +// } +// catch (MIOException ex) { +// // noop. +// } +// } +// +// public void testNameNoValue() throws Exception { +// final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); +// TinyTimMapInputHandler handler = _handler; +// handler.startTopicMap(); +// handler.startTopic(theTopic); +// handler.startName(); +// try { +// handler.endName(); +// fail("Expected an error since the name has no value"); +// } +// catch (MIOException ex) { +// // noop. +// } +// } +// +// /** +// * <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 { +// 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 = _handler; +// handler.startTopicMap(); +// handler.startTopic(Ref.createItemIdentifier(iid)); +// handler.startName(); +// handler.value("test"); +// handler.startType(); +// handler.topicRef(TOPIC_NAME); +// handler.endType(); +// handler.endName(); +// handler.endTopic(); +// handler.startTopic(Ref.createItemIdentifier(iid2)); +// handler.startName(); +// handler.value("a test"); +// handler.startType(); +// handler.topicRef(TOPIC_NAME); +// handler.endType(); +// handler.endName(); +// handler.subjectIdentifier(TOPIC_NAME.getIRI()); +// handler.endTopic(); +// handler.endTopicMap(); +// } - public void testNameNoValue() throws Exception { - final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); - TinyTimMapInputHandler handler = _handler; - handler.startTopicMap(); - handler.startTopic(theTopic); - handler.startName(); - try { - handler.endName(); - fail("Expected an error since the name has no value"); - } - catch (MIOException ex) { - // noop. - } - } - /** - * <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 { - 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 = _handler; - handler.startTopicMap(); - handler.startTopic(Ref.createItemIdentifier(iid)); - handler.startName(); - handler.value("test"); - handler.startType(); - handler.topicRef(TOPIC_NAME); - handler.endType(); - handler.endName(); - handler.endTopic(); - handler.startTopic(Ref.createItemIdentifier(iid2)); - handler.startName(); - handler.value("a test"); - handler.startType(); - handler.topicRef(TOPIC_NAME); - handler.endType(); - handler.endName(); - handler.subjectIdentifier(TOPIC_NAME.getIRI()); - handler.endTopic(); - handler.endTopicMap(); - } - - /** * <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> */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-22 08:33:22
|
Revision: 318 http://tinytim.svn.sourceforge.net/tinytim/?rev=318&view=rev Author: lheuer Date: 2009-07-22 08:33:17 +0000 (Wed, 22 Jul 2009) Log Message: ----------- - Added MapHander test case to AllTests - MapHandler checks for invalid names / variants (no value) - Updated TMAPI tests Modified Paths: -------------- tinytim/trunk/lib/tmapi-2.0a2-tests.jar tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java Modified: tinytim/trunk/lib/tmapi-2.0a2-tests.jar =================================================================== (Binary files differ) Modified: tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-21 15:03:43 UTC (rev 317) +++ tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-22 08:33:17 UTC (rev 318) @@ -216,6 +216,9 @@ @Override public void endName() throws MIOException { IName name = (IName) _leaveStatePopConstruct(NAME); + if (name.getLiteral() == null) { + throw new MIOException("The name '" + name + "' has no value"); + } if (name.getType() == null) { name.setType(_tm.createTopicBySubjectIdentifier(TMDM.TOPIC_NAME)); } @@ -237,6 +240,9 @@ @Override public void endVariant() throws MIOException { IVariant variant = (IVariant) _leaveStatePopConstruct(VARIANT); + if (variant.getLiteral() == null) { + throw new MIOException("The variant '" + variant + "' has no value"); + } IName name = (IName) _peekConstruct(); IScope scope = variant.getScopeObject(); if (scope.isUnconstrained() || name.getScopeObject().equals(scope)) { @@ -604,8 +610,7 @@ 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)) { + if (!_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 @@ -619,6 +624,14 @@ } } + /** + * Returns if <tt>a</tt> and <tt>b</tt> represent the same information + * item (i.e. both are associations). + * + * @param a A Topic Maps construct. + * @param b A Topic Maps construct. + * @return <tt>true</tt> if they represent the same information item, otherwise <tt>false</tt>. + */ private boolean _sameConstructKind(IConstruct a, IConstruct b) { return a.isAssociation() && b.isAssociation() || a.isName() && b.isName() @@ -630,9 +643,10 @@ } 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()); + return _sameConstructKind(a, b) + && (a.isRole() && b.isRole() + || (a.isVariant() && b.isVariant() && a.getParent().getParent().equals(b.getParent().getParent())) + || a.getParent().equals(b.getParent())); } /** Modified: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2009-07-21 15:03:43 UTC (rev 317) +++ tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2009-07-22 08:33:17 UTC (rev 318) @@ -19,6 +19,7 @@ import org.tinytim.core.value.TestLiteralNormalizer; import org.tinytim.core.value.TestLocatorImpl; import org.tinytim.internal.utils.TestSignatureGenerator; +import org.tinytim.mio.TestTinyTimMapInputHandler; import org.tinytim.utils.TestDuplicateRemovalUtils; import org.tinytim.utils.TestTopicUtils; @@ -45,6 +46,7 @@ suite.addTestSuite(TestIConstructFactory.class); suite.addTestSuite(TestScope.class); suite.addTestSuite(TestLiteral.class); + suite.addTestSuite(TestTinyTimMapInputHandler.class); suite.addTestSuite(TestLiteralNormalizer.class); suite.addTestSuite(TestSignatureGenerator.class); suite.addTest(TestTMAPICore.suite()); Modified: tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-21 15:03:43 UTC (rev 317) +++ tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-22 08:33:17 UTC (rev 318) @@ -51,6 +51,44 @@ _handler = new TinyTimMapInputHandler(_tm); } + public void testVariantNoValue() throws Exception { + final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); + final IRef theme = Ref.createItemIdentifier("http://test.semagia.com/theme"); + TinyTimMapInputHandler handler = _handler; + handler.startTopicMap(); + handler.startTopic(theTopic); + handler.startName(); + handler.value("Semagia"); + handler.startVariant(); + handler.startScope(); + handler.startTheme(); + handler.topicRef(theme); + handler.endTheme(); + handler.endScope(); + try { + handler.endVariant(); + fail("Expected an error since the variant has no value"); + } + catch (MIOException ex) { + // noop. + } + } + + public void testNameNoValue() throws Exception { + final IRef theTopic = Ref.createItemIdentifier("http://test.semagia.com/the-topic"); + TinyTimMapInputHandler handler = _handler; + handler.startTopicMap(); + handler.startTopic(theTopic); + handler.startName(); + try { + handler.endName(); + fail("Expected an error since the name has no value"); + } + catch (MIOException ex) { + // noop. + } + } + /** * <a href="http://code.google.com/p/mappa/issues/detail?id=23">http://code.google.com/p/mappa/issues/detail?id=23</a> */ @@ -320,6 +358,7 @@ handler.startReifier(); handler.topicRef(reifier); handler.endReifier(); + handler.value("variant", _XSD_STRING); handler.itemIdentifier(variantIID); handler.startScope(); handler.startTheme(); @@ -335,6 +374,7 @@ handler.startReifier(); handler.topicRef(reifier); handler.endReifier(); + handler.value("variant", _XSD_STRING); handler.startScope(); handler.startTheme(); handler.topicRef(theme); @@ -369,6 +409,7 @@ handler.startReifier(); handler.topicRef(reifier); handler.endReifier(); + handler.value("variant", _XSD_STRING); handler.startScope(); handler.startTheme(); handler.topicRef(theme); @@ -383,6 +424,7 @@ handler.startReifier(); handler.topicRef(reifier); handler.endReifier(); + handler.value("variant", _XSD_STRING); handler.itemIdentifier(variantIID); handler.startScope(); handler.startTheme(); @@ -418,6 +460,7 @@ handler.startReifier(); handler.topicRef(reifier); handler.endReifier(); + handler.value("variant", _XSD_STRING); handler.startScope(); handler.startTheme(); handler.topicRef(theme); @@ -433,6 +476,7 @@ handler.startReifier(); handler.topicRef(reifier); handler.endReifier(); + handler.value("variant", _XSD_STRING); handler.itemIdentifier(variantIID); handler.startScope(); handler.startTheme(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-21 15:03:51
|
Revision: 317 http://tinytim.svn.sourceforge.net/tinytim/?rev=317&view=rev Author: lheuer Date: 2009-07-21 15:03:43 +0000 (Tue, 21 Jul 2009) Log Message: ----------- Empty and releative IRIs are detected now to some extend Fixes #2683175. Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java 2009-07-21 14:54:31 UTC (rev 316) +++ tinytim/trunk/src/main/java/org/tinytim/core/value/LocatorImpl.java 2009-07-21 15:03:43 UTC (rev 317) @@ -33,6 +33,7 @@ import org.tinytim.voc.XSD; import org.tmapi.core.Locator; +import org.tmapi.core.MalformedIRIException; import org.tmapi.core.TMAPIRuntimeException; /** @@ -47,11 +48,15 @@ */ final class LocatorImpl implements ILocator { + private static final String _EMPTY = ""; private static final WeakObjectRegistry<ILocator> _IRIS = new WeakObjectRegistry<ILocator>(IConstant.LITERAL_IRI_SIZE); private final URI _uri; private final String _reference; private LocatorImpl(String reference) { + if (_EMPTY.equals(reference) || reference.charAt(0) == '#') { + throw new MalformedIRIException("Illegal absolute IRI: '" + reference + "'"); + } try { _reference = URLDecoder.decode(reference, "utf-8"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <bo...@us...> - 2009-07-20 09:20:22
|
Revision: 315 http://tinytim.svn.sourceforge.net/tinytim/?rev=315&view=rev Author: bosso Date: 2009-07-20 09:20:12 +0000 (Mon, 20 Jul 2009) Log Message: ----------- updated TMCL identifier according to new draft Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java Modified: tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java 2009-07-15 11:12:44 UTC (rev 314) +++ tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java 2009-07-20 09:20:12 UTC (rev 315) @@ -24,6 +24,7 @@ * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @author Hannes Niederhausen * @version $Rev$ - $Date$ */ public final class TMCL extends Vocabulary { @@ -126,9 +127,11 @@ public static final Locator REIFIER_CONSTRAINT = _createLocator(_BASE + "reifier-constraint"); + public static final Locator TOPIC_REIFIES_CONSTRAINT = _createLocator(_BASE + "topic-reifies-constraint"); + public static final Locator ASSOCIATION_ROLE_CONSTRAINT = _createLocator(_BASE + "association-role-constraint"); - public static final Locator OTHER_ROLE_CONSTRAINT = _createLocator(_BASE + "other-role-constraint"); + public static final Locator ROLE_COMBINATION_CONSTRAINT = _createLocator(_BASE + "role-combination-constraint"); public static final Locator OCCURRENCE_DATATYPE_CONSTRAINT = _createLocator(_BASE + "occurrence-datatype-constraint"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-15 11:12:55
|
Revision: 314 http://tinytim.svn.sourceforge.net/tinytim/?rev=314&view=rev Author: lheuer Date: 2009-07-15 11:12:44 +0000 (Wed, 15 Jul 2009) Log Message: ----------- Applied patch provided by Hannes Niederhausen (CTMWriter & co). Modified Paths: -------------- tinytim-mio/trunk/build.xml tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java Added Paths: ----------- tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907151305.jar Removed Paths: ------------- tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-20090702.jar Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-07-14 15:54:26 UTC (rev 313) +++ tinytim-mio/trunk/build.xml 2009-07-15 11:12:44 UTC (rev 314) @@ -10,7 +10,7 @@ <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a2.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a5-snapshot-20090702.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a5-snapshot-200907151305.jar"/> <property name="lib.tinytim.tests" value="${dir.lib}/tinytim-2.0.0a4-tests.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.8.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> @@ -131,7 +131,6 @@ <javac destdir="${dir.build.classes}" debug="${debug}" target="1.5" - excludes="**/CTMTopicMapWriter.java, **/internal/**" > <classpath> <pathelement location="${lib.tmapi}"/> Deleted: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-20090702.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907151305.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-200907151305.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-07-14 15:54:26 UTC (rev 313) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-07-15 11:12:44 UTC (rev 314) @@ -68,6 +68,7 @@ * representation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @author Hannes Niederhausen * @version $Rev$ - $Date$ */ public class CTMTopicMapWriter implements TopicMapWriter { @@ -541,33 +542,32 @@ case TOPIC: { if (_tmcl) { toFilter = new Locator[] { + // Topic types TMCL.TOPIC_TYPE, - TMCL.OCCURRENCE_TYPE, TMCL.ASSOCIATION_TYPE, TMCL.ROLE_TYPE, + TMCL.OCCURRENCE_TYPE, TMCL.NAME_TYPE, TMCL.SCOPE_TYPE, + + // Model topics + TMCL.SCHEMA, TMCL.CONSTRAINT, + // Constraint types - TMCL.TOPIC_TYPE_CONSTRAINT, - TMCL.ASSOCIATION_TYPE_CONSTRAINT, - TMCL.ASSOCIATION_ROLE_TYPE, - TMCL.OCCURRENCE_TYPE_CONSTRAINT, - TMCL.NAME_TYPE_CONSTRAINT, TMCL.ABSTRACT_TOPIC_TYPE_CONSTRAINT, - TMCL.EXCLUSIVE_INSTANCE, + TMCL.OVERLAP_DECLARATION, TMCL.SUBJECT_IDENTIFIER_CONSTRAINT, TMCL.SUBJECT_LOCATOR_CONSTRAINT, - TMCL.NAME_TYPE, - TMCL.NAME_TYPE_SCOPE_CONSTRAINT, - TMCL.TOPIC_OCCURRENCE_TYPE, - TMCL.ASSOCIATION_TYPE_SCOPE_CONSTRAINT, - TMCL.OCCURRENCE_DATATYPE_CONSTRAINT, + TMCL.TOPIC_NAME_CONSTRAINT, TMCL.TOPIC_OCCURRENCE_CONSTRAINT, + TMCL.ROLE_PLAYER_CONSTRAINT, TMCL.SCOPE_CONSTRAINT, + TMCL.REIFIER_CONSTRAINT, TMCL.ASSOCIATION_ROLE_CONSTRAINT, - TMCL.ASSOCIATION_ROLE_PLAYER, - TMCL.OTHERROLE_CONSTRAINT, - TMCL.UNIQUE_OCCURRENCE_CONSTRAINT, + TMCL.OTHER_ROLE_CONSTRAINT, + TMCL.OCCURRENCE_DATATYPE_CONSTRAINT, + TMCL.UNIQUE_VALUE_CONSTRAINT, + TMCL.REGULAR_EXPRESSION_CONSTRAINT }; } break; @@ -578,7 +578,16 @@ toFilter = new Locator[] { toFilter[0], toFilter[1], - TMCL.APPLIES_TO + // Association types - applies-to is no more + TMCL.CONSTRAINED_TOPIC_TYPE, + TMCL.CONSTRAINED_STATEMENT, + TMCL.CONSTRAINED_ROLE, + TMCL.OVERLAPS, + TMCL.ALLOWED_SCOPE, + TMCL.ALLOWED_REIFIER, + TMCL.OTHER_CONSTRAINED_TOPIC_TYPE, + TMCL.OTHER_CONSTRAINED_ROLE, + TMCL.BELONGS_TO_SCHEMA, }; } break; @@ -587,14 +596,13 @@ toFilter = new Locator[] {TMDM.TYPE, TMDM.INSTANCE, TMDM.SUPERTYPE, TMDM.SUBTYPE}; if (_tmcl) { toFilter = new Locator[] {toFilter[0], toFilter[1], toFilter[2], toFilter[3], - TMCL.TOPIC_TYPE_ROLE, - TMCL.OCCURRENCE_TYPE_ROLE, - TMCL.ASSOCIATION_TYPE_ROLE, - TMCL.ROLE_TYPE_ROLE, - TMCL.OTHERROLE_TYPE_ROLE, - TMCL.NAME_TYPE_ROLE, - TMCL.SCOPE_TYPE_ROLE, - TMCL.CONSTRAINT_ROLE + // Role types + TMCL.ALLOWS, + TMCL.ALLOWED, + TMCL.CONSTRAINS, + TMCL.CONSTRAINED, + TMCL.CONTAINER, + TMCL.CONTAINEE }; } break; @@ -606,7 +614,7 @@ TMCL.CARD_MAX, TMCL.DATATYPE, TMCL.REGEXP, - TMCL.VALIDATION_EXPRESSION, + TMCL.VALIDATION_EXPRESSION }; } break; @@ -793,10 +801,7 @@ _writeSupertypeSubtype(supertype, wantSemicolon); wantSemicolon = true; } - for (ITemplate tpl: _getTemplates(topic)) { - _writeTemplate(tpl, wantSemicolon); - wantSemicolon = true; - } + for (Name name: _getNames(topic)) { _writeName((IName) name, wantSemicolon); wantSemicolon = true; @@ -813,6 +818,10 @@ _writeTopicRef(slo, wantSemicolon); wantSemicolon = true; } + for (ITemplate tpl: _getTemplates(topic)) { + _writeTemplate(tpl, wantSemicolon); + wantSemicolon = true; + } if (_exportIIDs) { for (Reference iid: _getItemIdentifiers(topic)) { _writeTopicRef(iid, wantSemicolon); Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-07-14 15:54:26 UTC (rev 313) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-07-15 11:12:44 UTC (rev 314) @@ -19,17 +19,18 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Logger; -import org.tinytim.mio.internal.ctm.ITMCLPreprocessor; -import org.tinytim.mio.internal.ctm.ITemplate; +import org.tinytim.core.value.Literal; import org.tinytim.internal.api.IIndexManagerAware; import org.tinytim.internal.api.ILiteral; import org.tinytim.internal.api.IOccurrence; +import org.tinytim.mio.internal.ctm.ITMCLPreprocessor; +import org.tinytim.mio.internal.ctm.ITemplate; import org.tinytim.voc.TMCL; - import org.tmapi.core.Association; import org.tmapi.core.Locator; import org.tmapi.core.Occurrence; @@ -42,20 +43,46 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @author Hannes Niederhausen + * @version $Rev$ - $Date$ */ public class DefaultTMCLPreprocessor implements ITMCLPreprocessor { - private static final Logger LOG = Logger.getLogger(DefaultTMCLPreprocessor.class.getName()); + private static final Logger LOG = Logger + .getLogger(DefaultTMCLPreprocessor.class.getName()); private final Map<Topic, Collection<ITemplate>> _topic2Templates; - private Topic _topicType; + private Topic _constrains; - private Topic _appliesTo; + private Topic _constrained; - private Topic _constraintRole; + private Topic _container; + private Topic _containee; + + private Topic _constrained_topic_type; + + private Topic _other_constrained_topic_type; + + private Topic _constrained_statement; + + private Topic _constrained_role; + + private Topic _belongs_to_schema; + + private Topic _other_constrained_role; + + private Topic _overlaps; + + private Topic _allowed_scope; + + private Topic _allowed_reifier; + + private Topic _allowed; + + private Topic _allows; + private Topic _cardMin; private Topic _cardMax; @@ -64,19 +91,21 @@ private Topic _regEx; - private Topic _topicTypeRole; + private ILiteral _cardMinDefault; - private Topic _scopeTypeRole; + private ILiteral _cardMaxDefault; - private Topic _assocTypeRole; + private ILiteral _regExDefault; - public DefaultTMCLPreprocessor() { _topic2Templates = new HashMap<Topic, Collection<ITemplate>>(); } - /* (non-Javadoc) - * @see org.tinytim.mio.internal.ctm.ITMCLPreprocessor#getSuppressableSubjectIdentifiers() + /* + * (non-Javadoc) + * + * @seeorg.tinytim.mio.internal.ctm.ITMCLPreprocessor# + * getSuppressableSubjectIdentifiers() */ @Override public Set<Locator> getSuppressableSubjectIdentifiers() { @@ -84,68 +113,176 @@ return null; } - /* (non-Javadoc) - * @see org.tinytim.mio.internal.ctm.ITMCLPreprocessor#getTopicToTemplatesMapping() + /* + * (non-Javadoc) + * + * @see + * org.tinytim.mio.internal.ctm.ITMCLPreprocessor#getTopicToTemplatesMapping + * () */ @Override public Map<Topic, Collection<ITemplate>> getTopicToTemplatesMapping() { - return _topic2Templates; + return _topic2Templates; } - /* (non-Javadoc) - * @see org.tinytim.mio.internal.ctm.ITMCLPreprocessor#process(org.tmapi.core.TopicMap, java.util.Collection, java.util.Collection) + /* + * (non-Javadoc) + * + * @see + * org.tinytim.mio.internal.ctm.ITMCLPreprocessor#process(org.tmapi.core + * .TopicMap, java.util.Collection, java.util.Collection) */ @Override public void process(TopicMap topicMap, Collection<Topic> topics, Collection<Association> assocs) { _init(topicMap); - TypeInstanceIndex tiIdx = ((IIndexManagerAware) topicMap).getIndexManager().getTypeInstanceIndex(); + TypeInstanceIndex tiIdx = ((IIndexManagerAware) topicMap) + .getIndexManager().getTypeInstanceIndex(); if (!tiIdx.isAutoUpdated()) { tiIdx.reindex(); } _processAbstractTopicConstraints(topicMap, tiIdx, topics, assocs); + _processUniqueConstraints(topicMap, tiIdx, topics, assocs); + _processDatatypeConstraints(topicMap, tiIdx, topics, assocs); + _processRegExConstraints(topicMap, tiIdx, topics, assocs); _processSubjectIdentifierConstraints(topicMap, tiIdx, topics, assocs); _processSubjectLocatorConstraints(topicMap, tiIdx, topics, assocs); - _processAssociationTypeScopeConstraints(topicMap, tiIdx, topics, assocs); - _processRoleConstraints(topicMap, tiIdx, topics, assocs); - _processPlayerConstraints(topicMap, tiIdx, topics, assocs); + _processOverlapConstraints(topicMap, tiIdx, topics, assocs); + _processAssociationRoleConstraints(topicMap, tiIdx, topics, assocs); + _processRolePlayerConstraints(topicMap, tiIdx, topics, assocs); + _processOtherRoleConstraints(topicMap, tiIdx, topics, assocs); _processOccurrenceConstraints(topicMap, tiIdx, topics, assocs); - _processOccurrenceTypeScopeConstraints(topicMap, tiIdx, topics, assocs); _processNameConstraints(topicMap, tiIdx, topics, assocs); - _processNameTypeScopeConstraints(topicMap, tiIdx, topics, assocs); + _processScopeConstraints(topicMap, tiIdx, topics, assocs); + _processReifierConstraints(topicMap, tiIdx, topics, assocs); + _processBelongsToSchema(topicMap, tiIdx, topics, assocs); } - private Collection<Topic> _getConstraintInstances(TopicMap topicMap, TypeInstanceIndex tiIdx, Locator subjectIdentifier) { - final Topic constraintType = topicMap.getTopicBySubjectIdentifier(subjectIdentifier); + private Collection<Topic> _getConstraintInstances(TopicMap topicMap, + TypeInstanceIndex tiIdx, Locator subjectIdentifier) { + final Topic constraintType = topicMap + .getTopicBySubjectIdentifier(subjectIdentifier); if (constraintType == null) { return Collections.emptySet(); } return tiIdx.getTopics(constraintType); } - private Collection<Topic> _getTopicTypeRolePlayers(Topic constraint, Collection<Association> assocs) { - return _getPlayers(constraint, _constraintRole, _topicTypeRole, assocs); + private Topic _getConstrainedTopicTypePlayer(Topic constraint, + Collection<Association> assocs) { + for (Role role : constraint.getRolesPlayed(_constrains, + _constrained_topic_type)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + for (Role otherRole : assoc.getRoles(_constrained)) { + assocs.remove(assoc); + return otherRole.getPlayer(); + } + } + return null; } - private Collection<Topic> _getPlayers(Topic constraint, Topic constraintRoleType, Topic otherRoleType, Collection<Association> assocs) { - Collection<Topic> result = new ArrayList<Topic>(); - for (Role role: constraint.getRolesPlayed(constraintRoleType, _appliesTo)) { + private Topic _getConstrainedRolePlayer(Topic constraint, + Collection<Association> assocs) { + for (Role role : constraint.getRolesPlayed(_constrains, + _constrained_role)) { Association assoc = role.getParent(); if (!_isBinary(assoc)) { continue; } - for (Role otherRole: assoc.getRoles(otherRoleType)) { + for (Role otherRole : assoc.getRoles(_constrained)) { assocs.remove(assoc); - result.add(otherRole.getPlayer()); + return otherRole.getPlayer(); } } - return result; + return null; } + private Topic _getOtherConstrainedTopicTypePlayer(Topic constraint, + Collection<Association> assocs) { + for (Role role : constraint.getRolesPlayed(_constrains, + _other_constrained_topic_type)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + for (Role otherRole : assoc.getRoles(_constrained)) { + assocs.remove(assoc); + return otherRole.getPlayer(); + } + } + return null; + } + + private Topic _getOtherConstrainedRolePlayer(Topic constraint, + Collection<Association> assocs) { + for (Role role : constraint.getRolesPlayed(_constrains, + _other_constrained_role)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + for (Role otherRole : assoc.getRoles(_constrained)) { + assocs.remove(assoc); + return otherRole.getPlayer(); + } + } + return null; + } + + private Topic _getConstrainedStatementPlayer(Topic constraint, + Collection<Association> assocs) { + Topic player = null; + for (Role role : constraint.getRolesPlayed(_constrains, + _constrained_statement)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + + player = assoc.getRoles(_constrained).iterator().next().getPlayer(); + assocs.remove(assoc); + } + return player; + } + + private Topic _getAllowedScopePlayer(Topic constraint, + Collection<Association> assocs) { + Topic player = null; + for (Role role : constraint.getRolesPlayed(_allows, _allowed_scope)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + + player = assoc.getRoles(_allowed).iterator().next().getPlayer(); + assocs.remove(assoc); + } + return player; + } + + private Topic _getAllowedReifierPlayer(Topic constraint, + Collection<Association> assocs) { + Topic player = null; + for (Role role : constraint.getRolesPlayed(_allows, _allowed_reifier)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + + player = assoc.getRoles(_allowed).iterator().next().getPlayer(); + assocs.remove(assoc); + } + return player; + } + private void _processAbstractTopicConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ABSTRACT_TOPIC_TYPE_CONSTRAINT)) { + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.ABSTRACT_TOPIC_TYPE_CONSTRAINT)) { _processAbstractTopicConstraint(constraint, topics, assocs); } } @@ -153,213 +290,397 @@ private void _processAbstractTopicConstraint(Topic constraint, Collection<Topic> topics, Collection<Association> assocs) { ITemplate tpl = new DefaultTemplate("isAbstract"); - Collection<Topic> players = _getTopicTypeRolePlayers(constraint, assocs); - for (Topic player: players) { - _registerTemplate(player, tpl); - } - if (players.size() == constraint.getRolesPlayed().size() - && constraint.getOccurrences().isEmpty() - && constraint.getNames().isEmpty() - && constraint.getTypes().size() == 1 - && constraint.getSubjectLocators().isEmpty() - && constraint.getSubjectIdentifiers().isEmpty()) { - topics.remove(constraint); - } + Topic player = _getConstrainedTopicTypePlayer(constraint, assocs); + _registerTemplate(player, tpl); + removeConstraint(constraint, topics, 0); } - private void _processSubjectIdentifierConstraints(TopicMap topicMap, + private void _processAssociationRoleConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - _processLocatorConstraints(topicMap, tiIdx, "has-subjectidentifier", TMCL.SUBJECT_IDENTIFIER_CONSTRAINT, topics, assocs); + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.ASSOCIATION_ROLE_CONSTRAINT)) { + _processAssociationRoleConstraint(constraint, topics, assocs); + } + } - private void _processSubjectLocatorConstraints(TopicMap topicMap, + private void _processAssociationRoleConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + Topic player = _getConstrainedStatementPlayer(constraint, assocs); + Topic roleType = _getConstrainedRolePlayer(constraint, assocs); + + DefaultTemplate tpl = new DefaultTemplate("has-role"); + tpl.addParameter(roleType); + + int occCounter = _assignCardinality(constraint, tpl, 2); + + _registerTemplate(player, tpl); + removeConstraint(constraint, topics, occCounter); + } + + private void _processBelongsToSchema(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - _processLocatorConstraints(topicMap, tiIdx, "has-subjectlocator", TMCL.SUBJECT_LOCATOR_CONSTRAINT, topics, assocs); + for (Topic schema : _getConstraintInstances(topicMap, tiIdx, + TMCL.SCHEMA)) { + _processBelongsToSchema(schema, topics, assocs); + } } - private void _processLocatorConstraints(TopicMap topicMap, - TypeInstanceIndex tiIdx, String templateName, Locator constraintSID, Collection<Topic> topics, + private void _processBelongsToSchema(Topic schema, + Collection<Topic> topics, Collection<Association> assocs) { + + DefaultTemplate tpl = new DefaultTemplate("belongs-to"); + tpl.addParameter(schema); + + for (Role role : schema.getRolesPlayed(_container, _belongs_to_schema)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + Topic construct = assoc.getRoles(_containee).iterator().next() + .getPlayer(); + + _registerTemplate(construct, tpl); + } + } + + private void _processReifierConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, constraintSID)) { - _processLocatorConstraint(constraint, templateName, constraintSID, topics, assocs); + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.BELONGS_TO_SCHEMA)) { + _processReifierConstraint(constraint, topics, assocs); } + } - private void _processLocatorConstraint(Topic constraint, - String templateName, Locator constraintSID, Collection<Topic> topics, - Collection<Association> assocs) { + private void _processReifierConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + Topic reifierType = _getConstrainedStatementPlayer(constraint, assocs); + Topic reifiableType = _getAllowedReifierPlayer(constraint, assocs); + ILiteral cardMin = _getCardMin(constraint); ILiteral cardMax = _getCardMax(constraint); - ILiteral regEx = _getRegEx(constraint); - //TODO: Default values? - if (cardMin == null || cardMax == null || regEx == null) { - return; + DefaultTemplate tpl = null; + if (cardMin.getValue().equals(cardMax.getValue())) { + if (cardMin.getValue().equals("0")) { + tpl = new DefaultTemplate("cannot-have-reifier"); + } + else { + tpl = new DefaultTemplate("must-have-reifier"); + tpl.addParameter(reifierType); + } } - DefaultTemplate tpl = new DefaultTemplate(templateName); - tpl.addParameter(cardMin); - tpl.addParameter(cardMax); - tpl.addParameter(regEx); - Collection<Topic> players = _getTopicTypeRolePlayers(constraint, assocs); - for (Topic player: players) { - _registerTemplate(player, tpl); + else { + tpl = new DefaultTemplate("may-have-reifier"); + tpl.addParameter(reifierType); + } - if (players.size() == constraint.getRolesPlayed().size() - && constraint.getOccurrences().size() == 3 - && constraint.getNames().isEmpty() - && constraint.getTypes().size() == 1 - && constraint.getSubjectLocators().isEmpty() - && constraint.getSubjectIdentifiers().isEmpty()) { - topics.remove(constraint); + + _registerTemplate(reifiableType, tpl); + removeConstraint(constraint, topics, 2); + } + + private void _processRolePlayerConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.ROLE_PLAYER_CONSTRAINT)) { + _processRolePlayerConstraint(constraint, topics, assocs); } + } - private void _processAssociationTypeScopeConstraints(TopicMap topicMap, + private void _processRolePlayerConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + Topic type = _getConstrainedTopicTypePlayer(constraint, assocs); + Topic assocType = _getConstrainedStatementPlayer(constraint, assocs); + Topic roleType = _getConstrainedRolePlayer(constraint, assocs); + + DefaultTemplate tpl = new DefaultTemplate("plays-role"); + tpl.addParameter(roleType); + tpl.addParameter(assocType); + int occCounter = _assignCardinality(constraint, tpl, 2); + + _registerTemplate(type, tpl); + removeConstraint(constraint, topics, occCounter); + } + + private void _processOtherRoleConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.ASSOCIATION_TYPE_ROLE); - if (type == null) { - return; + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.OTHER_ROLE_CONSTRAINT)) { + _processOtherRoleConstraint(constraint, topics, assocs); } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ASSOCIATION_TYPE_SCOPE_CONSTRAINT)) { - _processTypeScopeConstraint(constraint, "has-association-scope", type, topics, assocs); + + } + + private void _processOtherRoleConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + Topic type = _getConstrainedTopicTypePlayer(constraint, assocs); + Topic assocType = _getConstrainedStatementPlayer(constraint, assocs); + Topic roleType = _getConstrainedRolePlayer(constraint, assocs); + Topic otherRole = _getOtherConstrainedRolePlayer(constraint, assocs); + Topic otherPlayer = _getOtherConstrainedTopicTypePlayer(constraint, + assocs); + + DefaultTemplate tpl = new DefaultTemplate("other-role"); + tpl.addParameter(roleType); + tpl.addParameter(type); + tpl.addParameter(otherRole); + tpl.addParameter(otherPlayer); + + _registerTemplate(assocType, tpl); + removeConstraint(constraint, topics, 0); + } + + private void _processUniqueConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.UNIQUE_VALUE_CONSTRAINT)) { + _processUniqueConstraint(constraint, topics, assocs); } } - private void _processRoleConstraints(TopicMap topicMap, + private void _processUniqueConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + ITemplate tpl = new DefaultTemplate("is-unique"); + Topic player = _getConstrainedStatementPlayer(constraint, assocs); + + _registerTemplate(player, tpl); + topics.remove(constraint); + + } + + private void _processDatatypeConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.ROLE_TYPE_ROLE); - if (type == null) { - return; + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.OCCURRENCE_DATATYPE_CONSTRAINT)) { + _processDatatypeConstraint(constraint, topics, assocs); } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ASSOCIATION_ROLE_CONSTRAINT)) { - _processRoleConstraint(constraint, type, topics, assocs); - } } - //TODO: Merge with {@link #_processTypeScopeConstraint} - private void _processRoleConstraint(Topic constraint, Topic type, Collection<Topic> topics, + private void _processDatatypeConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + + ILiteral datatype = _getDatatype(constraint); + DefaultTemplate tpl = new DefaultTemplate("has-datatype"); + tpl.addParameter(datatype); + + Topic player = _getConstrainedStatementPlayer(constraint, assocs); + + _registerTemplate(player, tpl); + + removeConstraint(constraint, topics, 1); + } + + private void _processRegExConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - Topic topic = _getRolePlayer(constraint, type, assocs); - ILiteral cardMin = _getCardMin(constraint); - ILiteral cardMax = _getCardMax(constraint); - if (topic == null || cardMin == null || cardMax == null) { - return; + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.REGULAR_EXPRESSION_CONSTRAINT)) { + _processRegExConstraint(constraint, topics, assocs); } - DefaultTemplate tpl = new DefaultTemplate("has-role"); - tpl.addParameter(topic); - tpl.addParameter(cardMin); - tpl.addParameter(cardMax); - Collection<Topic> players = _getPlayers(constraint, _constraintRole, _assocTypeRole, assocs); - for (Topic player: players) { - _registerTemplate(player, tpl); - } - if (players.size() * 2 == constraint.getRolesPlayed().size() - && constraint.getOccurrences().size() == 2 - && constraint.getNames().isEmpty() - && constraint.getTypes().size() == 1 - && constraint.getSubjectLocators().isEmpty() - && constraint.getSubjectIdentifiers().isEmpty()) { - topics.remove(constraint); - } } - private void _processPlayerConstraints(TopicMap topicMap, + private void _processRegExConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + + ILiteral regExp = _getRegEx(constraint); + DefaultTemplate tpl = new DefaultTemplate("matches-regexp"); + tpl.addParameter(regExp); + + Topic player = _getConstrainedStatementPlayer(constraint, assocs); + + _registerTemplate(player, tpl); + // removing instance from topics if it has no further informations + removeConstraint(constraint, topics, 1); + } + + private void _processOverlapConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.ROLE_TYPE_ROLE); - if (type == null) { - return; + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.OVERLAP_DECLARATION)) { + _processOverlapConstraint(constraint, topics, assocs); } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ASSOCIATION_ROLE_CONSTRAINT)) { - _processRoleConstraint(constraint, type, topics, assocs); + + } + + private void _processOverlapConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + + List<Topic> players = new ArrayList<Topic>(2); + for (Role role : constraint.getRolesPlayed(_allows, _overlaps)) { + Association assoc = role.getParent(); + players.add(assoc.getRoles(_allowed).iterator().next().getPlayer()); + + assocs.remove(assoc); } + DefaultTemplate tpl = new DefaultTemplate("overlaps"); + tpl.addParameter(players.get(1)); + + _registerTemplate(players.get(0), tpl); + removeConstraint(constraint, topics, 0); + } - private void _processOccurrenceConstraints(TopicMap topicMap, + private void _processSubjectIdentifierConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.OCCURRENCE_TYPE_ROLE); - if (type == null) { - return; + _processLocatorConstraints(topicMap, tiIdx, "has-subject-identifier", + TMCL.SUBJECT_IDENTIFIER_CONSTRAINT, topics, assocs); + } + + private void _processSubjectLocatorConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + _processLocatorConstraints(topicMap, tiIdx, "has-subject-locator", + TMCL.SUBJECT_LOCATOR_CONSTRAINT, topics, assocs); + } + + private void _processLocatorConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, String templateName, + Locator constraintSID, Collection<Topic> topics, + Collection<Association> assocs) { + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + constraintSID)) { + _processLocatorConstraint(constraint, templateName, constraintSID, + topics, assocs); } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.TOPIC_OCCURRENCE_CONSTRAINT)) { - _processHasTopicChildConstraint(constraint, "has-occurrence", type, topics, assocs); + } + + private void _processLocatorConstraint(Topic constraint, + String templateName, Locator constraintSID, + Collection<Topic> topics, Collection<Association> assocs) { + + int occCounter = 3; + + ILiteral regEx = _getRegEx(constraint); + if (regEx == null) { + regEx = _regExDefault; + occCounter--; } + + DefaultTemplate tpl = new DefaultTemplate(templateName); + tpl.addParameter(regEx); + + occCounter = _assignCardinality(constraint, tpl, occCounter); + + Topic player = _getConstrainedTopicTypePlayer(constraint, assocs); + _registerTemplate(player, tpl); + removeConstraint(constraint, topics, occCounter); } - private void _processOccurrenceTypeScopeConstraints(TopicMap topicMap, + private void _processScopeConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.OCCURRENCE_TYPE_ROLE); + final Topic type = topicMap + .getTopicBySubjectIdentifier(TMCL.SCOPE_TYPE); if (type == null) { return; } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.TOPIC_OCCURRENCE_TYPE)) { - _processTypeScopeConstraint(constraint, "has-occurrence-scope", type, topics, assocs); + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.SCOPE_CONSTRAINT)) { + _processScopeConstraint(constraint, type, topics, assocs); } } - private void _processTypeScopeConstraint(Topic constraint, String templateName, Topic type, + private void _processScopeConstraint(Topic constraint, Topic type, Collection<Topic> topics, Collection<Association> assocs) { - Topic topic = _getRolePlayer(constraint, type, assocs); - ILiteral cardMin = _getCardMin(constraint); - ILiteral cardMax = _getCardMax(constraint); - if (topic == null || cardMin == null || cardMax == null) { + Topic scope = _getAllowedScopePlayer(constraint, assocs); + + DefaultTemplate tpl = new DefaultTemplate("has-scope"); + tpl.addParameter(scope); + + int occCounter = _assignCardinality(constraint, tpl, 2); + + Topic player = _getConstrainedStatementPlayer(constraint, assocs); + _registerTemplate(player, tpl); + removeConstraint(constraint, topics, occCounter); + } + + private void _processOccurrenceConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap + .getTopicBySubjectIdentifier(TMCL.OCCURRENCE_TYPE); + if (type == null) { return; } - DefaultTemplate tpl = new DefaultTemplate(templateName); - tpl.addParameter(topic); - tpl.addParameter(cardMin); - tpl.addParameter(cardMax); - Collection<Topic> players = _getPlayers(constraint, _constraintRole, _scopeTypeRole, assocs); - for (Topic player: players) { - _registerTemplate(player, tpl); + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.TOPIC_OCCURRENCE_CONSTRAINT)) { + _processHasTopicChildConstraint(constraint, "has-occurrence", type, + topics, assocs); } - if (players.size() * 2 == constraint.getRolesPlayed().size() - && constraint.getOccurrences().size() == 2 - && constraint.getNames().isEmpty() - && constraint.getTypes().size() == 1 - && constraint.getSubjectLocators().isEmpty() - && constraint.getSubjectIdentifiers().isEmpty()) { - topics.remove(constraint); - } } private void _processNameConstraints(TopicMap topicMap, TypeInstanceIndex tiIdx, Collection<Topic> topics, Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.NAME_TYPE_ROLE); + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.NAME_TYPE); if (type == null) { return; } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.NAME_TYPE)) { - _processHasTopicChildConstraint(constraint, "has-name", type, topics, assocs); + for (Topic constraint : _getConstraintInstances(topicMap, tiIdx, + TMCL.TOPIC_NAME_CONSTRAINT)) { + _processHasTopicChildConstraint(constraint, "has-name", type, + topics, assocs); } } - private void _processHasTopicChildConstraint(Topic constraint, String templateName, - Topic type, Collection<Topic> topics, Collection<Association> assocs) { - Topic topic = _getRolePlayer(constraint, type, assocs); - ILiteral cardMin = _getCardMin(constraint); - ILiteral cardMax = _getCardMax(constraint); - ILiteral regEx = _getRegEx(constraint); - if (topic == null || cardMin == null || cardMax == null || regEx == null) { + private void _processHasTopicChildConstraint(Topic constraint, + String templateName, Topic type, Collection<Topic> topics, + Collection<Association> assocs) { + Topic topic = _getConstrainedStatementPlayer(constraint, assocs); + + if (topic == null) { return; } + DefaultTemplate tpl = new DefaultTemplate(templateName); tpl.addParameter(topic); + + int occCounter = _assignCardinality(constraint, tpl, 2); + + Topic player = _getConstrainedTopicTypePlayer(constraint, assocs); + + _registerTemplate(player, tpl); + + removeConstraint(constraint, topics, occCounter); + } + + private int _assignCardinality(Topic constraint, DefaultTemplate tpl, + int counter) { + ILiteral cardMin = _getCardMin(constraint); + ILiteral cardMax = _getCardMax(constraint); + + int occCounter = counter; + + if (cardMin == null) { + occCounter--; + cardMin = _cardMinDefault; + } + if (cardMax == null) { + occCounter--; + cardMax = _cardMaxDefault; + } tpl.addParameter(cardMin); tpl.addParameter(cardMax); - tpl.addParameter(regEx); - Collection<Topic> players = _getTopicTypeRolePlayers(constraint, assocs); - for (Topic player: players) { - _registerTemplate(player, tpl); - } - if (players.size() * 2 == constraint.getRolesPlayed().size() - && constraint.getOccurrences().size() == 3 + return occCounter; + } + + /* + * removing instance from topics if it has no further informations + */ + private void removeConstraint(Topic constraint, Collection<Topic> topics, + int expectedOccurrences) { + if (constraint.getOccurrences().size() == expectedOccurrences && constraint.getNames().isEmpty() && constraint.getTypes().size() == 1 && constraint.getSubjectLocators().isEmpty() @@ -368,23 +689,6 @@ } } - private void _processNameTypeScopeConstraints(TopicMap topicMap, - TypeInstanceIndex tiIdx, Collection<Topic> topics, - Collection<Association> assocs) { - final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.NAME_TYPE_ROLE); - if (type == null) { - return; - } - for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.NAME_TYPE_SCOPE_CONSTRAINT)) { - _processTypeScopeConstraint(constraint, "has-name-scope", type, topics, assocs); - } - } - - private Topic _getRolePlayer(Topic constraint, Topic roleType, Collection<Association> assocs) { - Collection<Topic> players = _getPlayers(constraint, _constraintRole, roleType, assocs); - return players.isEmpty() ? null : players.iterator().next(); - } - private ILiteral _getValue(Topic topic, Topic type) { if (type == null) { return null; @@ -400,6 +704,10 @@ return _getValue(constraint, _cardMin); } + private ILiteral _getDatatype(Topic constraint) { + return _getValue(constraint, _datatype); + } + private ILiteral _getCardMax(Topic constraint) { return _getValue(constraint, _cardMax); } @@ -413,15 +721,39 @@ } private void _init(TopicMap topicMap) { - _appliesTo = topicMap.getTopicBySubjectIdentifier(TMCL.APPLIES_TO); - _constraintRole = topicMap.getTopicBySubjectIdentifier(TMCL.CONSTRAINT_ROLE); + _overlaps = topicMap.getTopicBySubjectIdentifier(TMCL.OVERLAPS); + _constrained_statement = topicMap + .getTopicBySubjectIdentifier(TMCL.CONSTRAINED_STATEMENT); + _constrained_topic_type = topicMap + .getTopicBySubjectIdentifier(TMCL.CONSTRAINED_TOPIC_TYPE); + _constrained_role = topicMap + .getTopicBySubjectIdentifier(TMCL.CONSTRAINED_ROLE); + _other_constrained_topic_type = topicMap + .getTopicBySubjectIdentifier(TMCL.OTHER_CONSTRAINED_TOPIC_TYPE); + _other_constrained_role = topicMap + .getTopicBySubjectIdentifier(TMCL.OTHER_CONSTRAINED_ROLE); + _belongs_to_schema = topicMap + .getTopicBySubjectIdentifier(TMCL.BELONGS_TO_SCHEMA); + + _allowed_scope = topicMap + .getTopicBySubjectIdentifier(TMCL.ALLOWED_SCOPE); + _allowed_reifier = topicMap + .getTopicBySubjectIdentifier(TMCL.ALLOWED_REIFIER); + _allowed = topicMap.getTopicBySubjectIdentifier(TMCL.ALLOWED); + _allows = topicMap.getTopicBySubjectIdentifier(TMCL.ALLOWS); + _constrained = topicMap.getTopicBySubjectIdentifier(TMCL.CONSTRAINED); + _constrains = topicMap.getTopicBySubjectIdentifier(TMCL.CONSTRAINS); + _containee = topicMap.getTopicBySubjectIdentifier(TMCL.CONTAINEE); + _container = topicMap.getTopicBySubjectIdentifier(TMCL.CONTAINER); + _cardMin = topicMap.getTopicBySubjectIdentifier(TMCL.CARD_MIN); _cardMax = topicMap.getTopicBySubjectIdentifier(TMCL.CARD_MAX); _datatype = topicMap.getTopicBySubjectIdentifier(TMCL.DATATYPE); _regEx = topicMap.getTopicBySubjectIdentifier(TMCL.REGEXP); - _topicTypeRole = topicMap.getTopicBySubjectIdentifier(TMCL.TOPIC_TYPE_ROLE); - _scopeTypeRole = topicMap.getTopicBySubjectIdentifier(TMCL.SCOPE_TYPE_ROLE); - _assocTypeRole = topicMap.getTopicBySubjectIdentifier(TMCL.ASSOCIATION_TYPE_ROLE); + + _cardMinDefault = Literal.create(0); + _cardMaxDefault = Literal.create("*", "ctm:integer"); + _regExDefault = Literal.create(".*"); } private void _registerTemplate(Topic topic, ITemplate tpl) { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java 2009-07-14 15:54:26 UTC (rev 313) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java 2009-07-15 11:12:44 UTC (rev 314) @@ -24,7 +24,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class DefaultTemplate implements ITemplate { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-14 15:54:39
|
Revision: 313 http://tinytim.svn.sourceforge.net/tinytim/?rev=313&view=rev Author: lheuer Date: 2009-07-14 15:54:26 +0000 (Tue, 14 Jul 2009) Log Message: ----------- Applied TMCL patch provided by Hannes Niederhausen Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java Modified: tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java 2009-07-02 15:21:01 UTC (rev 312) +++ tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java 2009-07-14 15:54:26 UTC (rev 313) @@ -47,8 +47,7 @@ public static final Locator NAME_TYPE = _createLocator(_BASE + "name-type"); public static final Locator SCOPE_TYPE = _createLocator(_BASE + "scope-type"); - - + // Role types public static final Locator ALLOWS = _createLocator(_BASE + "allows"); @@ -57,7 +56,13 @@ public static final Locator CONSTRAINS = _createLocator(_BASE + "constrains"); public static final Locator CONSTRAINED = _createLocator(_BASE + "constrained"); + + public static final Locator CONTAINER = _createLocator(_BASE + "container"); + + public static final Locator CONTAINEE = _createLocator(_BASE + "containee"); + + // Association types - applies-to is no more public static final Locator CONSTRAINED_TOPIC_TYPE = _createLocator(_BASE + "constrained-topic-type"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-03 06:54:10
|
Revision: 299 http://tinytim.svn.sourceforge.net/tinytim/?rev=299&view=rev Author: lheuer Date: 2009-07-02 11:07:24 +0000 (Thu, 02 Jul 2009) Log Message: ----------- - Applied patch from Hannes Niederhausen (TMCL voc) - Internal change: All constructs are now checked if they belong to the same topic map - Fixes issue #2812460 Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java 2009-07-02 11:07:24 UTC (rev 299) @@ -50,7 +50,7 @@ if (supported == null) { TopicMapSystemFactoryImpl.reportFeatureNotRecognized(featureName); } - return supported; + return supported.booleanValue(); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -103,6 +103,7 @@ public Role createRole(Topic type, Topic player) { Check.typeNotNull(this, type); Check.playerNotNull(this, player); + Check.sameTopicMap(this, type, player); RoleImpl role = new RoleImpl(_tm, type, player); addRole(role); return role; @@ -130,9 +131,7 @@ * @see org.tmapi.core.Association#getRoles(org.tmapi.core.Topic) */ public Set<Role> getRoles(Topic type) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(type); Set<Role> roles = CollectionFactory.createIdentitySet(_roles.size()); for (Role role: _roles) { if (type == role.getType()) { Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -22,11 +22,11 @@ import org.tinytim.internal.api.IConstant; import org.tinytim.internal.api.IConstruct; import org.tinytim.internal.api.ITopicMap; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Construct; import org.tmapi.core.Locator; -import org.tmapi.core.ModelConstraintException; import org.tmapi.core.TopicMap; /** @@ -78,18 +78,16 @@ /* (non-Javadoc) * @see org.tmapi.core.Construct#addItemIdentifier(org.tmapi.core.Locator) */ - public void addItemIdentifier(Locator itemIdentifier) { - if (itemIdentifier == null) { - throw new ModelConstraintException(this, "The item identifier must not be null"); - } - if (_iids != null && _iids.contains(itemIdentifier)) { + public void addItemIdentifier(Locator iid) { + Check.itemIdentifierNotNull(this, iid); + if (_iids != null && _iids.contains(iid)) { return; } - _fireEvent(Event.ADD_IID, null, itemIdentifier); + _fireEvent(Event.ADD_IID, null, iid); if (_iids == null) { _iids = CollectionFactory.createIdentitySet(IConstant.CONSTRUCT_IID_SIZE); } - _iids.add(itemIdentifier); + _iids.add(iid); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2009-07-02 11:07:24 UTC (rev 299) @@ -36,7 +36,6 @@ import org.tmapi.core.Association; import org.tmapi.core.IdentityConstraintException; -import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Role; import org.tmapi.core.Locator; import org.tmapi.core.Occurrence; @@ -127,9 +126,7 @@ * @see org.tmapi.core.TopicMap#createTopicByItemIdentifier(org.tmapi.core.Locator) */ public Topic createTopicByItemIdentifier(Locator iid) { - if (iid == null) { - throw new ModelConstraintException(null, "The item identifier must not be null"); - } + Check.itemIdentifierNotNull(this, iid); Construct construct = getConstructByItemIdentifier(iid); if (construct != null) { if (construct instanceof Topic) { @@ -153,9 +150,7 @@ * @see org.tmapi.core.TopicMap#createTopicBySubjectIdentifier(org.tmapi.core.Locator) */ public Topic createTopicBySubjectIdentifier(Locator sid) { - if (sid == null) { - throw new ModelConstraintException(null, "The subject identifier must not be null"); - } + Check.subjectIdentifierNotNull(this, sid); Topic topic = getTopicBySubjectIdentifier(sid); if (topic != null) { return topic; @@ -177,9 +172,7 @@ * @see org.tmapi.core.TopicMap#createTopicBySubjectLocator(org.tmapi.core.Locator) */ public Topic createTopicBySubjectLocator(Locator slo) { - if (slo == null) { - throw new ModelConstraintException(null, "The subject locator must not be null"); - } + Check.subjectLocatorNotNull(this, slo); Topic topic = getTopicBySubjectLocator(slo); if (topic != null) { return topic; @@ -229,6 +222,8 @@ public Association createAssociation(Topic type, Collection<Topic> scope) { Check.typeNotNull(this, type); Check.scopeNotNull(this, scope); + Check.sameTopicMap(this, type); + Check.sameTopicMap(this, scope); AssociationImpl assoc = new AssociationImpl(this, type, Scope.create(scope)); addAssociation(assoc); return assoc; @@ -270,22 +265,25 @@ /* (non-Javadoc) * @see org.tmapi.core.TopicMap#getTopicBySubjectIdentifier(org.tmapi.core.Locator) */ - public Topic getTopicBySubjectIdentifier(Locator subjectIdentifier) { - return _identityManager.getTopicBySubjectIdentifier(subjectIdentifier); + public Topic getTopicBySubjectIdentifier(Locator sid) { + Check.subjectIdentifierNotNull(sid); + return _identityManager.getTopicBySubjectIdentifier(sid); } /* (non-Javadoc) * @see org.tmapi.core.TopicMap#getTopicBySubjectLocator(org.tmapi.core.Locator) */ - public Topic getTopicBySubjectLocator(Locator subjectLocator) { - return _identityManager.getTopicBySubjectLocator(subjectLocator); + public Topic getTopicBySubjectLocator(Locator slo) { + Check.subjectLocatorNotNull(slo); + return _identityManager.getTopicBySubjectLocator(slo); } /* (non-Javadoc) * @see org.tmapi.core.TopicMap#getConstructByItemIdentifier(org.tmapi.core.Locator) */ - public Construct getConstructByItemIdentifier(Locator itemIdentifier) { - return _identityManager.getConstructByItemIdentifier(itemIdentifier); + public Construct getConstructByItemIdentifier(Locator iid) { + Check.itemIdentifierNotNull(iid); + return _identityManager.getConstructByItemIdentifier(iid); } /* (non-Javadoc) @@ -299,6 +297,7 @@ * @see org.tmapi.core.Reifiable#setReifier(org.tmapi.core.Topic) */ public void setReifier(Topic reifier) { + Check.sameTopicMap(this, reifier); if (_reifier == reifier) { return; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -186,6 +186,7 @@ } public IVariant createVariant(ILiteral literal, Collection<Topic> scope) { + Check.sameTopicMap(this, scope); if (scope.isEmpty()) { throw new ModelConstraintException(this, "The scope of the variant must not be unconstrained"); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -61,6 +61,7 @@ */ public void setPlayer(Topic player) { Check.playerNotNull(this, player); + Check.sameTopicMap(this, player); if (_player == player) { return; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -21,8 +21,8 @@ import org.tinytim.internal.api.IScope; import org.tinytim.internal.api.IScoped; import org.tinytim.internal.api.ITopicMap; +import org.tinytim.internal.utils.Check; -import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Topic; /** @@ -77,9 +77,8 @@ * @see org.tmapi.core.Scoped#addTheme(org.tmapi.core.Topic) */ public void addTheme(Topic theme) { - if (theme == null) { - throw new ModelConstraintException(this, "The theme must not be null"); - } + Check.themeNotNull(this, theme); + Check.sameTopicMap(this, theme); setScopeObject(_scope.add(theme)); } @@ -87,6 +86,9 @@ * @see org.tmapi.core.Scoped#removeTheme(org.tmapi.core.Topic) */ public void removeTheme(Topic theme) { + if (theme == null) { + return; + } setScopeObject(_scope.remove(theme)); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -35,7 +35,6 @@ import org.tinytim.voc.TMDM; import org.tmapi.core.Locator; -import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; import org.tmapi.core.Reifiable; @@ -86,9 +85,7 @@ * @see org.tmapi.core.Topic#addSubjectIdentifier(org.tmapi.core.Locator) */ public void addSubjectIdentifier(Locator sid) { - if (sid == null) { - throw new ModelConstraintException(this, "The subject identifier must not be null"); - } + Check.subjectIdentifierNotNull(this, sid); if (_sids.contains(sid)) { return; } @@ -119,9 +116,7 @@ * @see org.tmapi.core.Topic#addSubjectLocator(org.tmapi.core.Locator) */ public void addSubjectLocator(Locator slo) { - if (slo == null) { - throw new ModelConstraintException(this, "The subject locator must not be null"); - } + Check.subjectLocatorNotNull(this, slo); if (_slos != null && _sids.contains(slo)) { return; } @@ -201,6 +196,8 @@ public IOccurrence createOccurrence(Topic type, ILiteral literal, Collection<Topic> scope) { Check.typeNotNull(this, type); Check.scopeNotNull(this, scope); + Check.sameTopicMap(this, type); + Check.sameTopicMap(this, scope); IOccurrence occ = new OccurrenceImpl(_tm, type, literal, Scope.create(scope)); addOccurrence(occ); return occ; @@ -261,9 +258,7 @@ * @see org.tmapi.core.Topic#getNames(org.tmapi.core.Topic) */ public Set<Name> getNames(Topic type) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(type); Set<Name> names = CollectionFactory.createIdentitySet(); for (Name name: _names) { if (type == name.getType()) { @@ -293,9 +288,7 @@ * @see org.tmapi.core.Topic#getOccurrences(org.tmapi.core.Topic) */ public Set<Occurrence> getOccurrences(Topic type) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(type); Set<Occurrence> occs = CollectionFactory.createIdentitySet(); for (Occurrence occ: _occs) { if (type == occ.getType()) { @@ -323,6 +316,8 @@ public IName createName(Topic type, ILiteral literal, Collection<Topic> scope) { Check.typeNotNull(this, type); Check.scopeNotNull(this, scope); + Check.sameTopicMap(this, type); + Check.sameTopicMap(this, scope); NameImpl name = new NameImpl(_tm, type, literal, Scope.create(scope)); addName(name); return name; @@ -382,9 +377,7 @@ * @see org.tmapi.core.Topic#getRolesPlayed(org.tmapi.core.Topic) */ public Set<Role> getRolesPlayed(Topic type) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(type); if (_rolesPlayed == null) { return Collections.emptySet(); } @@ -401,9 +394,7 @@ * @see org.tmapi.core.Topic#getRolesPlayed(org.tmapi.core.Topic, org.tmapi.core.Topic) */ public Set<Role> getRolesPlayed(Topic type, Topic assoc) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(type); if (assoc == null) { throw new IllegalArgumentException("The association type must not be null"); } @@ -446,6 +437,7 @@ */ public void addType(Topic type) { Check.typeNotNull(this, type); + Check.sameTopicMap(this, type); if (_types != null && _types.contains(type)) { return; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -40,11 +40,7 @@ private static final FeatureInfo[] _FEATURES = new FeatureInfo[] { // Feature IRI, default value, fixed? - new FeatureInfo(Feature.NOTATION_URI, true, true), - new FeatureInfo(Feature.XTM_1_0, false, true), - new FeatureInfo(Feature.XTM_1_1, true, true), new FeatureInfo(Feature.AUTOMERGE, false, true), - new FeatureInfo(Feature.TNC, false, true), new FeatureInfo(Feature.READ_ONLY, false, true) }; @@ -114,7 +110,7 @@ if (supported == null) { reportFeatureNotRecognized(featureName); } - return supported; + return supported.booleanValue(); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -59,6 +59,7 @@ */ public void setType(Topic type) { Check.typeNotNull(this, type); + Check.sameTopicMap(this, type); if (_type == type) { return; } @@ -77,6 +78,7 @@ * @see org.tmapi.core.Reifiable#setReifier(org.tmapi.core.Topic) */ public void setReifier(Topic reifier) { + Check.sameTopicMap(this, reifier); if (_reifier == reifier) { return; } Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2009-07-02 11:07:24 UTC (rev 299) @@ -21,6 +21,7 @@ import org.tmapi.core.Locator; import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; /** * Provides various argument constraint checks. @@ -41,11 +42,20 @@ * @param sender The sender * @param msg The error message */ - private static void _reportError(Construct sender, String msg) { + private static void _reportModelConstraintViolation(Construct sender, String msg) { throw new ModelConstraintException(sender, msg); } /** + * + * + * @param msg + */ + private static void _reportIllegalArgument(String msg) { + throw new IllegalArgumentException(msg); + } + + /** * Throws a {@link ModelConstraintException} iff the <tt>scope</tt> is * <tt>null</tt>. * @@ -54,7 +64,7 @@ */ public static void scopeNotNull(Construct sender, Topic[] scope) { if (scope == null) { - _reportError(sender, "The scope must not be null"); + _reportModelConstraintViolation(sender, "The scope must not be null"); } } @@ -67,7 +77,7 @@ */ public static void scopeNotNull(Construct sender, Collection<Topic> scope) { if (scope == null) { - _reportError(sender, "The scope must not be null"); + _reportModelConstraintViolation(sender, "The scope must not be null"); } } @@ -80,7 +90,7 @@ */ public static void typeNotNull(Construct sender, Topic type) { if (type == null) { - _reportError(sender, "The type must not be null"); + _reportModelConstraintViolation(sender, "The type must not be null"); } } @@ -93,7 +103,7 @@ */ public static void valueNotNull(Construct sender, Object value) { if (value == null) { - _reportError(sender, "The value must not be null"); + _reportModelConstraintViolation(sender, "The value must not be null"); } } @@ -108,7 +118,7 @@ public static void valueNotNull(Construct sender, Object value, Locator datatype) { valueNotNull(sender, value); if (datatype == null) { - _reportError(sender, "The datatype must not be null"); + _reportModelConstraintViolation(sender, "The datatype must not be null"); } } @@ -121,8 +131,147 @@ */ public static void playerNotNull(Construct sender, Topic player) { if (player == null) { - _reportError(sender, "The role player must not be null"); + _reportModelConstraintViolation(sender, "The role player must not be null"); } } + /** + * Throws a {@link ModelConstraintException} iff the <tt>iid</tt> is + * <tt>null</tt>. + * + * @param sender The sender + * @param iid The item identifier. + */ + public static void itemIdentifierNotNull(Construct sender, Locator iid) { + if (iid == null) { + _reportModelConstraintViolation(sender, "The item identifier must not be null"); + } + } + + /** + * Throws a {@link ModelConstraintException} iff the <tt>sid</tt> is + * <tt>null</tt>. + * + * @param sender The sender + * @param sid The subject identifier. + */ + public static void subjectIdentifierNotNull(Construct sender, Locator sid) { + if (sid == null) { + _reportModelConstraintViolation(sender, "The subject identifier must not be null"); + } + } + + /** + * Throws a {@link ModelConstraintException} iff the <tt>slo</tt> is + * <tt>null</tt>. + * + * @param sender The sender + * @param slo The subject locator. + */ + public static void subjectLocatorNotNull(Construct sender, Locator slo) { + if (slo == null) { + _reportModelConstraintViolation(sender, "The subject locator must not be null"); + } + } + + /** + * Throws an {@link ModelConstraintException} iff the <tt>theme</tt> is + * <tt>null</tt>. + * + * @param theme The theme. + */ + public static void themeNotNull(Construct sender, Topic theme) { + if (theme == null) { + _reportModelConstraintViolation(sender, "The theme must not be null"); + } + } + + /** + * Reports a {@link ModelConstraintException} iff the <tt>sender<tt> and + * the <tt>construct</tt> do not belong to the same topic map. + * + * @param sender The sender. + * @param construct The construct. + */ + public static void sameTopicMap(Construct sender, Construct construct) { + if (construct == null) { + return; + } + _sameTopicMap(sender, sender.getTopicMap(), construct); + } + + public static void sameTopicMap(Construct sender, Construct...constructs) { + if (constructs == null || constructs.length == 0) { + return; + } + TopicMap tm = sender.getTopicMap(); + for (Construct construct: constructs) { + _sameTopicMap(sender, tm, construct); + } + } + + public static void sameTopicMap(Construct sender, Collection<? extends Construct> constructs) { + if (constructs == null) { + return; + } + TopicMap tm = sender.getTopicMap(); + for (Construct construct: constructs) { + _sameTopicMap(sender, tm, construct); + } + } + + private static void _sameTopicMap(Construct sender, TopicMap tm, Construct other) { + if (!tm.equals(other.getTopicMap())) { + _reportModelConstraintViolation(sender, "All constructs must belong to the same topic map"); + } + } + + /** + * Throws an {@link IllegalArgumentException} iff the <tt>type</tt> is + * <tt>null</tt>. + * + * @param type The type. + */ + public static void typeNotNull(Topic type) { + if (type == null) { + _reportIllegalArgument("The type must not be null"); + } + } + + /** + * Reports an {@link IllegalArgumentException} iff the <tt>sid</tt> is + * <tt>null</tt>. + * + * @param sid The subject identifier. + */ + public static void subjectIdentifierNotNull(Locator sid) { + if (sid == null) { + _reportIllegalArgument("The subject identifier must not be null"); + } + } + + /** + * Reports an {@link IllegalArgumentException} iff the <tt>slo</tt> is + * <tt>null</tt>. + * + * @param slo The subject locator. + */ + public static void subjectLocatorNotNull(Locator slo) { + if (slo == null) { + _reportIllegalArgument("The subject locator must not be null"); + } + } + + /** + * Reports an {@link IllegalArgumentException} iff the <tt>iid</tt> is + * <tt>null</tt>. + * + * @param iid The item identifier. + */ + public static void itemIdentifierNotNull(Locator iid) { + if (iid == null) { + _reportIllegalArgument("The item identifier must not be null"); + } + } + } Modified: tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java 2009-07-02 11:07:24 UTC (rev 299) @@ -36,92 +36,98 @@ // Topic types - public static final Locator TOPIC_TYPE = _createLocator(_BASE + "topictype"); + public static final Locator TOPIC_TYPE = _createLocator(_BASE + "topic-type"); - public static final Locator ASSOCIATION_TYPE = _createLocator(_BASE + "associationtype"); + public static final Locator ASSOCIATION_TYPE = _createLocator(_BASE + "association-type"); - public static final Locator ROLE_TYPE = _createLocator(_BASE + "roletype"); + public static final Locator ROLE_TYPE = _createLocator(_BASE + "role-type"); - public static final Locator OCCURRENCE_TYPE = _createLocator(_BASE + "occurrencetype"); + public static final Locator OCCURRENCE_TYPE = _createLocator(_BASE + "occurrence-type"); - public static final Locator NAME_TYPE = _createLocator(_BASE + "nametype"); + public static final Locator NAME_TYPE = _createLocator(_BASE + "name-type"); - public static final Locator SCOPE_TYPE = _createLocator(_BASE + "scopetype"); + public static final Locator SCOPE_TYPE = _createLocator(_BASE + "scope-type"); // Role types + public static final Locator ALLOWS = _createLocator(_BASE + "allows"); + + public static final Locator ALLOWED = _createLocator(_BASE + "allowed"); + + public static final Locator CONSTRAINS = _createLocator(_BASE + "constrains"); + + public static final Locator CONSTRAINED = _createLocator(_BASE + "constrained"); - public static final Locator TOPIC_TYPE_ROLE = _createLocator(_BASE + "topictype-role"); - - public static final Locator ASSOCIATION_TYPE_ROLE = _createLocator(_BASE + "associationtype-role"); - - public static final Locator ROLE_TYPE_ROLE = _createLocator(_BASE + "roletype-role"); - - public static final Locator OTHERROLE_TYPE_ROLE = _createLocator(_BASE + "roletype-role"); - - public static final Locator OCCURRENCE_TYPE_ROLE = _createLocator(_BASE + "occurrencetype-role"); - - public static final Locator NAME_TYPE_ROLE = _createLocator(_BASE + "nametype-role"); - - public static final Locator SCOPE_TYPE_ROLE = _createLocator(_BASE + "scopetype-role"); - - public static final Locator CONSTRAINT_ROLE = _createLocator(_BASE + "constraint-role"); - - + // Association types - applies-to is no more + public static final Locator CONSTRAINED_TOPIC_TYPE = _createLocator(_BASE + "constrained-topic-type"); + + public static final Locator CONSTRAINED_STATEMENT = _createLocator(_BASE + "constrained-statement"); + + public static final Locator CONSTRAINED_ROLE = _createLocator(_BASE + "constrained-role"); + + public static final Locator OVERLAPS = _createLocator(_BASE + "overlaps"); + + public static final Locator ALLOWED_SCOPE = _createLocator(_BASE + "allowed-scope"); + + public static final Locator ALLOWED_REIFIER = _createLocator(_BASE + "allowed-reifier"); + + public static final Locator OTHER_CONSTRAINED_TOPIC_TYPE = _createLocator(_BASE + "other-constrained-topic-type"); + + public static final Locator OTHER_CONSTRAINED_ROLE = _createLocator(_BASE + "other-constrained-role"); + + public static final Locator BELONGS_TO_SCHEMA = _createLocator(_BASE + "belongs-to-schema"); + // Model topics + + public static final Locator SCHEMA = _createLocator(_BASE + "schema"); + public static final Locator CONSTRAINT = _createLocator(_BASE + "constraint"); public static final Locator VALIDATION_EXPRESSION = _createLocator(_BASE + "validation-expression"); - public static final Locator APPLIES_TO = _createLocator(_BASE + "applies-to"); - public static final Locator CARD_MIN = _createLocator(_BASE + "card-min"); public static final Locator CARD_MAX = _createLocator(_BASE + "card-max"); - //TODO: TMCL uses sometimes "regexp" and sometimes "reg-exp" - public static final Locator REGEXP = _createLocator(_BASE + "reg-exp"); + public static final Locator REGEXP = _createLocator(_BASE + "regexp"); public static final Locator DATATYPE = _createLocator(_BASE + "datatype"); + + public static final Locator VERSION = _createLocator(_BASE + "version"); + public static final Locator DESCRIPTION = _createLocator(_BASE + "description"); + + public static final Locator COMMENT = _createLocator(_BASE + "comment"); + + public static final Locator SEE_ALSO = _createLocator(_BASE + "see-also"); // Constraint types - public static final Locator TOPIC_TYPE_CONSTRAINT = _createLocator(_BASE + "topictype-constraint"); + + public static final Locator ABSTRACT_TOPIC_TYPE_CONSTRAINT = _createLocator(_BASE + "abstract-constraint"); + + public static final Locator OVERLAP_DECLARATION = _createLocator(_BASE + "overlap-declaration"); + + public static final Locator SUBJECT_IDENTIFIER_CONSTRAINT = _createLocator(_BASE + "subject-identifier-constraint"); - public static final Locator ASSOCIATION_TYPE_CONSTRAINT = _createLocator(_BASE + "associationtype-constraint"); + public static final Locator SUBJECT_LOCATOR_CONSTRAINT = _createLocator(_BASE + "subject-locator-constraint"); + + public static final Locator TOPIC_NAME_CONSTRAINT = _createLocator(_BASE + "topic-name-constraint"); + + public static final Locator TOPIC_OCCURRENCE_CONSTRAINT = _createLocator(_BASE + "topic-occurrence-constraint"); + + public static final Locator ROLE_PLAYER_CONSTRAINT = _createLocator(_BASE + "role-player-constraint"); + + public static final Locator SCOPE_CONSTRAINT = _createLocator(_BASE + "scope-constraint"); + + public static final Locator REIFIER_CONSTRAINT = _createLocator(_BASE + "reifier-constraint"); - public static final Locator ROLE_TYPE_CONSTRAINT = _createLocator(_BASE + "roletype-constraint"); + public static final Locator ASSOCIATION_ROLE_CONSTRAINT = _createLocator(_BASE + "association-role-constraint"); + + public static final Locator OTHER_ROLE_CONSTRAINT = _createLocator(_BASE + "other-role-constraint"); + + public static final Locator OCCURRENCE_DATATYPE_CONSTRAINT = _createLocator(_BASE + "occurrence-datatype-constraint"); - public static final Locator OCCURRENCE_TYPE_CONSTRAINT = _createLocator(_BASE + "occurrencetype-constraint"); - - public static final Locator NAME_TYPE_CONSTRAINT = _createLocator(_BASE + "nametype-constraint"); - - public static final Locator ABSTRACT_TOPIC_TYPE_CONSTRAINT = _createLocator(_BASE + "abstract-topictype-constraint"); + public static final Locator UNIQUE_VALUE_CONSTRAINT = _createLocator(_BASE + "unique-value-constraint"); - public static final Locator EXCLUSIVE_INSTANCE = _createLocator(_BASE + "exclusive-instance"); - - public static final Locator SUBJECT_IDENTIFIER_CONSTRAINT = _createLocator(_BASE + "subjectidentifier-constraint"); - - public static final Locator SUBJECT_LOCATOR_CONSTRAINT = _createLocator(_BASE + "subjectlocator-constraint"); - - public static final Locator NAME_CONSTRAINT = _createLocator(_BASE + "topicname-constraint"); - - public static final Locator NAME_TYPE_SCOPE_CONSTRAINT = _createLocator(_BASE + "nametypescope-constraint"); - - public static final Locator OCCURRENCE_TYPE_SCOPE_CONSTRAINT = _createLocator(_BASE + "occurrencetypescope-constraint"); - - public static final Locator OCCURRENCE_DATATYPE_CONSTRAINT = _createLocator(_BASE + "occurrencedatatype-constraint"); - - public static final Locator ASSOCIATION_TYPE_SCOPE_CONSTRAINT = _createLocator(_BASE + "associationtypescope-constraint"); - - public static final Locator ASSOCIATION_ROLE_CONSTRAINT = _createLocator(_BASE + "associationrole-constraint"); - - public static final Locator ROLE_PLAYER_CONSTRAINT = _createLocator(_BASE + "roleplayer-constraint"); - - public static final Locator OTHERROLE_CONSTRAINT = _createLocator(_BASE + "otherrole-constraint"); - - public static final Locator TOPIC_OCCURRENCE_CONSTRAINT = _createLocator(_BASE + "topicoccurrence-constraint"); - - public static final Locator UNIQUE_OCCURRENCE_CONSTRAINT = _createLocator(_BASE + "uniqueoccurrence-constraint"); - + public static final Locator REGULAR_EXPRESSION_CONSTRAINT = _createLocator(_BASE + "regular-expression-constraint"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 15:21:03
|
Revision: 312 http://tinytim.svn.sourceforge.net/tinytim/?rev=312&view=rev Author: lheuer Date: 2009-07-02 15:21:01 +0000 (Thu, 02 Jul 2009) Log Message: ----------- SLF4J 1.5.6 -> 1.5.8 Modified Paths: -------------- tinytim-mio/trunk/build.xml Added Paths: ----------- tinytim-mio/trunk/lib/slf4j-api-1.5.8.jar tinytim-mio/trunk/lib/slf4j-jdk14-1.5.8.jar Removed Paths: ------------- tinytim-mio/trunk/lib/slf4j-api-1.5.6.jar tinytim-mio/trunk/lib/slf4j-jdk14-1.5.6.jar Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-07-02 15:07:25 UTC (rev 311) +++ tinytim-mio/trunk/build.xml 2009-07-02 15:21:01 UTC (rev 312) @@ -12,7 +12,7 @@ <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a2.jar"/> <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a5-snapshot-20090702.jar"/> <property name="lib.tinytim.tests" value="${dir.lib}/tinytim-2.0.0a4-tests.jar"/> - <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> + <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.8.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> <target name="help"> Deleted: tinytim-mio/trunk/lib/slf4j-api-1.5.6.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/slf4j-api-1.5.8.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/slf4j-api-1.5.8.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/lib/slf4j-jdk14-1.5.6.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/slf4j-jdk14-1.5.8.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/slf4j-jdk14-1.5.8.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 15:07:31
|
Revision: 311 http://tinytim.svn.sourceforge.net/tinytim/?rev=311&view=rev Author: lheuer Date: 2009-07-02 15:07:25 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Added update of voc/TMCL to CHANGES.txt Modified Paths: -------------- tinytim/trunk/CHANGES.txt Modified: tinytim/trunk/CHANGES.txt =================================================================== --- tinytim/trunk/CHANGES.txt 2009-07-02 14:51:22 UTC (rev 310) +++ tinytim/trunk/CHANGES.txt 2009-07-02 15:07:25 UTC (rev 311) @@ -5,6 +5,8 @@ 2.0.0 a5 (xx.yy.2009) --------------------- +* Updated TMCL constants (implemented by Hannes Niederhausen) + Bugfixes: --------- * Bug #2812460 -- Port the Check class from Ontopia back to This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 14:51:47
|
Revision: 310 http://tinytim.svn.sourceforge.net/tinytim/?rev=310&view=rev Author: lheuer Date: 2009-07-02 14:51:22 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Added newer CTMWriter version which does not work Excluded CTMWriter & co from build process Modified Paths: -------------- tinytim-mio/trunk/build.xml tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java Added Paths: ----------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITMCLPreprocessor.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITemplate.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-07-02 14:27:30 UTC (rev 309) +++ tinytim-mio/trunk/build.xml 2009-07-02 14:51:22 UTC (rev 310) @@ -130,7 +130,9 @@ <target name="compile" depends="clean, prepare"> <javac destdir="${dir.build.classes}" debug="${debug}" - target="1.5"> + target="1.5" + excludes="**/CTMTopicMapWriter.java, **/internal/**" + > <classpath> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tinytim}"/> Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-07-02 14:27:30 UTC (rev 309) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-07-02 14:51:22 UTC (rev 310) @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.logging.Logger; @@ -37,6 +38,11 @@ import org.tinytim.internal.api.IScope; import org.tinytim.internal.api.IScoped; import org.tinytim.internal.api.IVariant; +import org.tinytim.mio.internal.ctm.ITMCLPreprocessor; +import org.tinytim.mio.internal.ctm.ITemplate; +import org.tinytim.mio.internal.ctm.impl.DefaultTMCLPreprocessor; +import org.tinytim.voc.Namespace; +import org.tinytim.voc.TMCL; import org.tinytim.voc.TMDM; import org.tinytim.voc.XSD; @@ -68,12 +74,38 @@ private static final Logger LOG = Logger.getLogger(CTMTopicMapWriter.class.getName()); - //TODO: Unicode ranges in patterns - private static final Pattern _ID_PATTERN = Pattern.compile("[A-Za-z_](\\.*[\\-A-Za-z_0-9])*"); + private static final String _ID_START = "[a-zA-Z_]" + + "|[\\u00C0-\\u00D6]" + + "|[\\u00D8-\\u00F6]" + + "|[\\u00F8-\\u02FF]" + + "|[\\u0370-\\u037D]" + + "|[\\u037F-\\u1FFF]" + + "|[\\u200C-\\u200D]" + + "|[\\u2070-\\u218F]" + + "|[\\u2C00-\\u2FEF]" + + "|[\\u3001-\\uD7FF]" + + "|[\\uF900-\\uFDCF]" + + "|[\\uFDF0-\\uFFFD]" + + "|[\\u10000-\\uEFFFF]"; + private static final String _ID_PART = _ID_START + + "|[\\-\\.0-9]" + + "|\\u00B7" + + "|[\\u0300-\\u036F]" + + "|[\\u203F-\\u2040]"; + private static final String _ID_END = _ID_START + + "|[\\-0-9]" + + "|\\u00B7" + + "|[\\u0300-\\u036F]" + + "|[\\u203F-\\u2040]"; + private static final Pattern _ID_PATTERN = Pattern.compile(String.format("%s(%s*%s)*", _ID_START, _ID_PART, _ID_END)); private static final Pattern _LOCAL_PATTERN = Pattern.compile("([0-9]*\\.*[\\-A-Za-z_0-9])*"); + private static final Pattern _IRI_PATTERN = Pattern.compile("[^<>\"\\{\\}\\`\\\\ ]+"); private static final char[] _TRIPLE_QUOTES = new char[] { '"', '"', '"' }; private static final Reference[] _EMPTY_REFERENCE_ARRAY = new Reference[0]; + private static final ITemplate[] _EMPTY_TEMPLATE_ARRAY = new ITemplate[0]; + private static final Topic[] _EMPTY_TOPIC_ARRAY = new Topic[0]; private static final Reference _UNTYPED_REFERENCE = Reference.createId("[untyped]"); + private static final String _TMCL_TEMPLATE = "http://www.topicmaps.org/tmcl/templates.ctm"; private final Writer _out; private final String _baseIRI; @@ -96,8 +128,20 @@ private final Comparator<Variant> _variantComparator; private final Map<Topic, Reference> _topic2Reference; //TODO: LRU? private final Map<String, String> _prefixes; + private final Set<String> _imports; + private final Map<Topic, Collection<ITemplate>> _topic2Templates; + private final Map<Topic, Collection<Topic>> _topic2Supertypes; private Reference _lastReference; + private boolean _tmcl; + private static enum TypeFilter { + TOPIC, + ASSOCIATION, + ROLE, + OCCURRENCE, + NAME + } + /** * Constructs a new instance using "utf-8" encoding. * <p> @@ -158,8 +202,12 @@ _roleComparator = new RoleComparator(); _variantComparator = new VariantComparator(); _prefixes = new HashMap<String, String>(); + _imports = new HashSet<String>(); + _topic2Templates = new HashMap<Topic, Collection<ITemplate>>(); + _topic2Supertypes = new HashMap<Topic, Collection<Topic>>(); setIdentation(4); setExportItemIdentifiers(false); + setTMCL(true); } /** @@ -243,6 +291,13 @@ return _comment; } + public void setTMCL(boolean enable) { + _imports.add(_TMCL_TEMPLATE); + addPrefix("tmcl", Namespace.TMCL); + addPrefix("tmdm", Namespace.TMDM_MODEL); + _tmcl = true; + } + /** * Adds a prefix to the writer. * <p> @@ -261,6 +316,18 @@ * @param reference The IRI to which the prefix should be assigned to. */ public void addPrefix(String prefix, String reference) { + if (prefix == null) { + throw new IllegalArgumentException("The prefix must not be null"); + } + if (!_isValidId(prefix)) { + throw new IllegalArgumentException("The prefix is an invalid CTM identifier: " + prefix); + } + if (reference == null) { + throw new IllegalArgumentException("The reference must not be null"); + } + if (!_IRI_PATTERN.matcher(reference).matches()) { + throw new IllegalArgumentException("The reference is an invalid CTM IRI: " + reference); + } _prefixes.put(prefix, reference); } @@ -275,7 +342,7 @@ /** * Sets the identation level, by default the identation level is set to 4 - * which means four whitespace characters are written. + * which means that four whitespace characters are written. * <p> * If the size is set to <tt>0</tt>, no identation will be done. * </p> @@ -352,9 +419,19 @@ _newline(); _out.write("%version 1.0"); _writeFileHeader(); + _writeImports(); _writePrefixes(); _newline(); Collection<Topic> topics = new ArrayList<Topic>(topicMap.getTopics()); + Collection<Association> assocs = new ArrayList<Association>(topicMap.getAssociations()); + TypeInstanceIndex tiIdx = ((IIndexManagerAware) topicMap).getIndexManager().getTypeInstanceIndex(); + if (!tiIdx.isAutoUpdated()) { + tiIdx.reindex(); + } + _createSupertypeSubtypeRelationships(tiIdx, topicMap, assocs); + if (_tmcl) { + _createTMCLTemplates(topicMap, topics, assocs); + } if (topicMap.getReifier() != null) { // Special handling of the tm reifier to avoid an additional // whitespace character in front of the ~ @@ -366,37 +443,16 @@ _writeTopic(reifier, false); topics.remove(reifier); } - TypeInstanceIndex tiIdx = ((IIndexManagerAware) topicMap).getIndexManager().getTypeInstanceIndex(); - if (!tiIdx.isAutoUpdated()) { - tiIdx.reindex(); - } _writeSection("ONTOLOGY"); - _writeOntologySection(tiIdx.getTopicTypes(), topics, "Topic Types"); - Collection<Topic> types = tiIdx.getAssociationTypes(); - final Topic typeInstance = topicMap.getTopicBySubjectIdentifier(TMDM.TYPE_INSTANCE); - if (_omitTopic(typeInstance)) { - types.remove(typeInstance); - topics.remove(typeInstance); - } + Collection<Topic> types = _filter(topicMap, tiIdx.getTopicTypes(), topics, TypeFilter.TOPIC); + _writeOntologySection(types, topics, "Topic Types"); + types = _filter(topicMap, tiIdx.getAssociationTypes(), topics, TypeFilter.ASSOCIATION); _writeOntologySection(types, topics, "Association Types"); - types = tiIdx.getRoleTypes(); - final Topic type = topicMap.getTopicBySubjectIdentifier(TMDM.TYPE); - final Topic instance = topicMap.getTopicBySubjectIdentifier(TMDM.INSTANCE); - if (_omitTopic(type)) { - types.remove(type); - topics.remove(type); - } - if (_omitTopic(instance)) { - types.remove(instance); - topics.remove(instance); - } + types = _filter(topicMap, tiIdx.getRoleTypes(), topics, TypeFilter.ROLE); _writeOntologySection(types, topics, "Role Types"); - _writeOntologySection(tiIdx.getOccurrenceTypes(), topics, "Occurrence Types"); - types = new ArrayList<Topic>(tiIdx.getNameTypes()); - if (_omitTopic(_defaultNameType)) { - types.remove(_defaultNameType); - topics.remove(_defaultNameType); - } + types = _filter(topicMap, tiIdx.getOccurrenceTypes(), topics, TypeFilter.OCCURRENCE); + _writeOntologySection(types, topics, "Occurrence Types"); + types = _filter(topicMap, tiIdx.getNameTypes(), topics, TypeFilter.NAME); _writeOntologySection(types, topics, "Name Types"); tiIdx.close(); ScopedIndex scopeIdx = ((IIndexManagerAware) topicMap).getIndexManager().getScopedIndex(); @@ -412,7 +468,6 @@ _writeSection("INSTANCES"); _writeSection("Topics"); _writeTopics(topics); - Collection<Association> assocs = new ArrayList<Association>(topicMap.getAssociations()); if (!assocs.isEmpty()) { Association[] assocArray = assocs.toArray(new Association[assocs.size()]); _writeSection("Associations"); @@ -426,8 +481,160 @@ _newline(); _out.flush(); _topic2Reference.clear(); + _topic2Supertypes.clear(); + _topic2Templates.clear(); } + private void _createSupertypeSubtypeRelationships(TypeInstanceIndex tiIdx, + TopicMap tm, Collection<Association> assocs) { + final Topic supertypeSubtype = tm.getTopicBySubjectIdentifier(TMDM.SUPERTYPE_SUBTYPE); + final Topic supertype = tm.getTopicBySubjectIdentifier(TMDM.SUPERTYPE); + final Topic subtype = tm.getTopicBySubjectIdentifier(TMDM.SUBTYPE); + if (supertypeSubtype == null || supertype == null || subtype == null) { + return; + } + for (Association assoc: tiIdx.getAssociations(supertypeSubtype)) { + if (!assoc.getScope().isEmpty()) { + continue; + } + if (assoc.getReifier() != null) { + continue; + } + Collection<Role> roles = assoc.getRoles(); + if (roles.size() != 2) { + continue; + } + Topic supertypePlayer = null; + Topic subtypePlayer = null; + for (Role role: roles) { + if (role.getType().equals(supertype)) { + supertypePlayer = role.getPlayer(); + } + else if (role.getType().equals(subtype)) { + subtypePlayer = role.getPlayer(); + } + } + if (supertypePlayer == null || subtypePlayer == null) { + continue; + } + Collection<Topic> supertypes = _topic2Supertypes.get(subtypePlayer); + if (supertypes == null) { + supertypes = new HashSet<Topic>(); + _topic2Supertypes.put(subtypePlayer, supertypes); + } + supertypes.add(supertypePlayer); + assocs.remove(assoc); + } + } + + private void _createTMCLTemplates(TopicMap topicMap, + Collection<Topic> topics, + Collection<Association> assocs) { + ITMCLPreprocessor tmclProcessor = new DefaultTMCLPreprocessor(); + tmclProcessor.process(topicMap, topics, assocs); + _topic2Templates.putAll(tmclProcessor.getTopicToTemplatesMapping()); + } + + private Locator[] _getSubjectIdentifiersToFilter(TypeFilter mode) { + Locator[] toFilter = new Locator[0]; + switch (mode) { + case TOPIC: { + if (_tmcl) { + toFilter = new Locator[] { + TMCL.TOPIC_TYPE, + TMCL.OCCURRENCE_TYPE, + TMCL.ASSOCIATION_TYPE, + TMCL.ROLE_TYPE, + TMCL.NAME_TYPE, + TMCL.SCOPE_TYPE, + TMCL.CONSTRAINT, + // Constraint types + TMCL.TOPIC_TYPE_CONSTRAINT, + TMCL.ASSOCIATION_TYPE_CONSTRAINT, + TMCL.ASSOCIATION_ROLE_TYPE, + TMCL.OCCURRENCE_TYPE_CONSTRAINT, + TMCL.NAME_TYPE_CONSTRAINT, + TMCL.ABSTRACT_TOPIC_TYPE_CONSTRAINT, + TMCL.EXCLUSIVE_INSTANCE, + TMCL.SUBJECT_IDENTIFIER_CONSTRAINT, + TMCL.SUBJECT_LOCATOR_CONSTRAINT, + TMCL.NAME_TYPE, + TMCL.NAME_TYPE_SCOPE_CONSTRAINT, + TMCL.TOPIC_OCCURRENCE_TYPE, + TMCL.ASSOCIATION_TYPE_SCOPE_CONSTRAINT, + TMCL.OCCURRENCE_DATATYPE_CONSTRAINT, + TMCL.TOPIC_OCCURRENCE_CONSTRAINT, + TMCL.ASSOCIATION_ROLE_CONSTRAINT, + TMCL.ASSOCIATION_ROLE_PLAYER, + TMCL.OTHERROLE_CONSTRAINT, + TMCL.UNIQUE_OCCURRENCE_CONSTRAINT, + }; + } + break; + } + case ASSOCIATION: { + toFilter = new Locator[] {TMDM.TYPE_INSTANCE, TMDM.SUPERTYPE_SUBTYPE}; + if (_tmcl) { + toFilter = new Locator[] { + toFilter[0], + toFilter[1], + TMCL.APPLIES_TO + }; + } + break; + } + case ROLE: { + toFilter = new Locator[] {TMDM.TYPE, TMDM.INSTANCE, TMDM.SUPERTYPE, TMDM.SUBTYPE}; + if (_tmcl) { + toFilter = new Locator[] {toFilter[0], toFilter[1], toFilter[2], toFilter[3], + TMCL.TOPIC_TYPE_ROLE, + TMCL.OCCURRENCE_TYPE_ROLE, + TMCL.ASSOCIATION_TYPE_ROLE, + TMCL.ROLE_TYPE_ROLE, + TMCL.OTHERROLE_TYPE_ROLE, + TMCL.NAME_TYPE_ROLE, + TMCL.SCOPE_TYPE_ROLE, + TMCL.CONSTRAINT_ROLE + }; + } + break; + } + case OCCURRENCE: { + if (_tmcl) { + toFilter = new Locator[] { + TMCL.CARD_MIN, + TMCL.CARD_MAX, + TMCL.DATATYPE, + TMCL.REGEXP, + TMCL.VALIDATION_EXPRESSION, + }; + } + break; + } + case NAME: { + toFilter = new Locator[] {TMDM.TOPIC_NAME}; + break; + } + } + return toFilter; + } + + private Collection<Topic> _filter(TopicMap topicMap, Collection<Topic> types, + Collection<Topic> allTopics, TypeFilter mode) { + return _filter(topicMap, types, allTopics, _getSubjectIdentifiersToFilter(mode)); + } + + private Collection<Topic> _filter(TopicMap topicMap, Collection<Topic> topics, Collection<Topic> allTopics, Locator...subjectIdentifiers) { + for (Locator loc: subjectIdentifiers) { + Topic topic = topicMap.getTopicBySubjectIdentifier(loc); + if (_omitTopic(topic)) { + topics.remove(topic); + allTopics.remove(topic); + } + } + return topics; + } + /** * Indicates if the provided <tt>topic</tt> has just one subject identifier * and provides no further properties. @@ -437,14 +644,14 @@ */ private boolean _omitTopic(Topic topic) { return topic != null - && topic.getSubjectIdentifiers().size() == 1 - && topic.getSubjectLocators().isEmpty() - && (!_exportIIDs || topic.getItemIdentifiers().isEmpty()) - && topic.getTypes().isEmpty() - && topic.getNames().isEmpty() - && topic.getOccurrences().isEmpty() - && topic.getRolesPlayed().isEmpty() - && topic.getReified() == null; + && topic.getSubjectIdentifiers().size() == 1 + && topic.getSubjectLocators().isEmpty() + && (!_exportIIDs || topic.getItemIdentifiers().isEmpty()) + && topic.getTypes().isEmpty() + && topic.getNames().isEmpty() + && topic.getOccurrences().isEmpty() + && topic.getRolesPlayed().isEmpty() + && topic.getReified() == null; } /** @@ -501,6 +708,25 @@ } /** + * Writes the registered imports. + * + * @throws IOException In case of an error. + */ + private void _writeImports() throws IOException { + if (_imports.isEmpty()) { + return; + } + _writeSection("Included Topic Maps"); + String[] imports = _imports.toArray(new String[_imports.size()]); + Arrays.sort(imports); + for (String imp: imports) { + _out.write("%include "); + _writeLocator(imp); + _newline(); + } + } + + /** * If <tt>topics</tt> is not empty, the topics will be removed from * <tt>allTopics</tt> and written out under the specified section <tt>title</tt>. * @@ -564,9 +790,13 @@ wantSemicolon = true; } for (Topic supertype: _getSupertypes(topic)) { - this._writeSupertypeSubtype(supertype, wantSemicolon); + _writeSupertypeSubtype(supertype, wantSemicolon); wantSemicolon = true; } + for (ITemplate tpl: _getTemplates(topic)) { + _writeTemplate(tpl, wantSemicolon); + wantSemicolon = true; + } for (Name name: _getNames(topic)) { _writeName((IName) name, wantSemicolon); wantSemicolon = true; @@ -636,7 +866,7 @@ if (iids.isEmpty()) { return _EMPTY_REFERENCE_ARRAY; } - Collection<Reference> refs = new ArrayList<Reference>(); + Collection<Reference> refs = new ArrayList<Reference>(iids.size()); for (Locator iid: iids) { refs.add(Reference.createItemIdentifier(iid)); } @@ -703,25 +933,42 @@ * @return A sorted array of supertypes. */ private Topic[] _getSupertypes(Topic topic) { - //FIXME - return new Topic[0]; -// Set<Topic> supertypes_ = TypeInstanceUtils.getSupertypes(topic); -// Topic[] supertypes = supertypes_.toArray(new Topic[supertypes_.size()]); -// Arrays.sort(supertypes, _topicIdComparator); -// return supertypes; + Collection<Topic> supertypes_ = _topic2Supertypes.get(topic); + if (supertypes_ == null) { + return _EMPTY_TOPIC_ARRAY; + } + Topic[] supertypes = supertypes_.toArray(new Topic[supertypes_.size()]); + Arrays.sort(supertypes, _topicIdComparator); + return supertypes; } /** + * Returns a sorted array of templates for the specified topic. + * + * @param topic The topic to retrieve the templates from. + * @return A sorted array of templates. + */ + private ITemplate[] _getTemplates(Topic topic) { + Collection<ITemplate> templates = _topic2Templates.get(topic); + if (templates == null) { + return _EMPTY_TEMPLATE_ARRAY; + } + ITemplate[] tplArray = templates.toArray(new ITemplate[templates.size()]); + Arrays.sort(tplArray); + return tplArray; + } + + /** * Returns a sorted array of names for the specified topic. * * @param topic The topic to retrieve the names from. * @return A sorted array of names. */ private Name[] _getNames(Topic topic) { - Set<Name> names_ = topic.getNames(); - Name[] names = names_.toArray(new Name[names_.size()]); - Arrays.sort(names, _nameComparator); - return names; + Collection<Name> names = topic.getNames(); + Name[] nameArray = names.toArray(new Name[names.size()]); + Arrays.sort(nameArray, _nameComparator); + return nameArray; } /** @@ -731,10 +978,10 @@ * @return A sorted array of occurrences. */ private Occurrence[] _getOccurrences(Topic topic) { - Set<Occurrence> occs_ = topic.getOccurrences(); - Occurrence[] occs = occs_.toArray(new Occurrence[occs_.size()]); - Arrays.sort(occs, _occComparator); - return occs; + Collection<Occurrence> occs = topic.getOccurrences(); + Occurrence[] occArray = occs.toArray(new Occurrence[occs.size()]); + Arrays.sort(occArray, _occComparator); + return occArray; } /** @@ -764,6 +1011,36 @@ } /** + * Writes a template invocation. + * + * @param tpl The template invocation to write. + * @param wantSemicolon Indicates if a semicolon should be written. + * @throws IOException In case of an error. + */ + private void _writeTemplate(ITemplate tpl, boolean wantSemicolon) throws IOException { + _writeSemicolon(wantSemicolon); + _out.write(tpl.getName()); + _out.write('('); + boolean wantComma = false; + for (Object param: tpl.getParameters()) { + if (wantComma) { + _out.write(", "); + } + if (param instanceof ILiteral) { + _writeLiteral((ILiteral) param); + } + else if (param instanceof Topic) { + _writeTopicRef((Topic) param); + } + else { + _writeTopicRef((Reference) param); + } + wantComma = true; + } + _out.write(')'); + } + + /** * Serializes the specified occurrence. * * @param occ The occurrence to serialize @@ -1111,7 +1388,7 @@ int idx = addr.indexOf('#'); if (idx > 0) { String id = addr.substring(idx+1); - if (_isValidId(id)) { + if (_isValidId(id) && !_isKeyword(id)) { if (_keepAbsoluteIIDs && !addr.startsWith(_baseIRI)) { refs.add(Reference.createItemIdentifier(iid)); } @@ -1146,6 +1423,20 @@ } /** + * Returns if the provided identifier is a CTM keyword. + * + * @param id The id to check. + * @return <tt>true</tt> if <tt>id</tt> is a keyword, otherwise <tt>false</tt>. + */ + private boolean _isKeyword(String id) { + return id.length() == 3 + && ("def".equals(id) + || "end".equals(id) + || "isa".equals(id) + || "ako".equals(id)); + } + + /** * Returns if the provided <tt>id</tt> is a valid CTM topic identifier. * * @param id The id to check. @@ -1179,9 +1470,7 @@ || XSD.INTEGER.equals(datatype) || XSD.DATE.equals(datatype) || XSD.DATE_TIME.equals(datatype) - || (XSD.DOUBLE.equals(datatype) - && ("INF".equals(literal.getValue())) - || "-INF".equals(literal.getValue())); + || XSD.DOUBLE.equals(datatype); } /** @@ -1218,10 +1507,27 @@ LOG.warning("Invalid CTM: '" + msg + "'"); } + static final class Template implements Comparable<Template> { + private final String name; + private final Collection<Object> params; + private Template(String name) { + this.name = name; + this.params = new ArrayList<Object>(); + } + @Override + public int compareTo(Template o) { + int res = name.compareTo(o.name); + if (res == 0) { + res = params.size() - o.params.size(); + } + return res; + } + } + /** * Represents a reference to a topic. */ - static final class Reference implements Comparable<Reference> { + private static final class Reference implements Comparable<Reference> { static final int ID = 0, SID = 1, Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITMCLPreprocessor.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITMCLPreprocessor.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITMCLPreprocessor.java 2009-07-02 14:51:22 UTC (rev 310) @@ -0,0 +1,41 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio.internal.ctm; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import org.tmapi.core.Association; +import org.tmapi.core.Locator; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface ITMCLPreprocessor { + + public void process(TopicMap topicMap, Collection<Topic> topics, Collection<Association> assocs); + + public Set<Locator> getSuppressableSubjectIdentifiers(); + + public Map<Topic, Collection<ITemplate>> getTopicToTemplatesMapping(); + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITMCLPreprocessor.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITemplate.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITemplate.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITemplate.java 2009-07-02 14:51:22 UTC (rev 310) @@ -0,0 +1,32 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio.internal.ctm; + +import java.util.List; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface ITemplate extends Comparable<ITemplate> { + + public String getName(); + + public List<Object> getParameters(); + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITemplate.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-07-02 14:51:22 UTC (rev 310) @@ -0,0 +1,436 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio.internal.ctm.impl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.logging.Logger; + +import org.tinytim.mio.internal.ctm.ITMCLPreprocessor; +import org.tinytim.mio.internal.ctm.ITemplate; +import org.tinytim.internal.api.IIndexManagerAware; +import org.tinytim.internal.api.ILiteral; +import org.tinytim.internal.api.IOccurrence; +import org.tinytim.voc.TMCL; + +import org.tmapi.core.Association; +import org.tmapi.core.Locator; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.index.TypeInstanceIndex; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class DefaultTMCLPreprocessor implements ITMCLPreprocessor { + + private static final Logger LOG = Logger.getLogger(DefaultTMCLPreprocessor.class.getName()); + + private final Map<Topic, Collection<ITemplate>> _topic2Templates; + + private Topic _topicType; + + private Topic _appliesTo; + + private Topic _constraintRole; + + private Topic _cardMin; + + private Topic _cardMax; + + private Topic _datatype; + + private Topic _regEx; + + private Topic _topicTypeRole; + + private Topic _scopeTypeRole; + + private Topic _assocTypeRole; + + + public DefaultTMCLPreprocessor() { + _topic2Templates = new HashMap<Topic, Collection<ITemplate>>(); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.internal.ctm.ITMCLPreprocessor#getSuppressableSubjectIdentifiers() + */ + @Override + public Set<Locator> getSuppressableSubjectIdentifiers() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.tinytim.mio.internal.ctm.ITMCLPreprocessor#getTopicToTemplatesMapping() + */ + @Override + public Map<Topic, Collection<ITemplate>> getTopicToTemplatesMapping() { + return _topic2Templates; + } + + /* (non-Javadoc) + * @see org.tinytim.mio.internal.ctm.ITMCLPreprocessor#process(org.tmapi.core.TopicMap, java.util.Collection, java.util.Collection) + */ + @Override + public void process(TopicMap topicMap, Collection<Topic> topics, + Collection<Association> assocs) { + _init(topicMap); + TypeInstanceIndex tiIdx = ((IIndexManagerAware) topicMap).getIndexManager().getTypeInstanceIndex(); + if (!tiIdx.isAutoUpdated()) { + tiIdx.reindex(); + } + _processAbstractTopicConstraints(topicMap, tiIdx, topics, assocs); + _processSubjectIdentifierConstraints(topicMap, tiIdx, topics, assocs); + _processSubjectLocatorConstraints(topicMap, tiIdx, topics, assocs); + _processAssociationTypeScopeConstraints(topicMap, tiIdx, topics, assocs); + _processRoleConstraints(topicMap, tiIdx, topics, assocs); + _processPlayerConstraints(topicMap, tiIdx, topics, assocs); + _processOccurrenceConstraints(topicMap, tiIdx, topics, assocs); + _processOccurrenceTypeScopeConstraints(topicMap, tiIdx, topics, assocs); + _processNameConstraints(topicMap, tiIdx, topics, assocs); + _processNameTypeScopeConstraints(topicMap, tiIdx, topics, assocs); + } + + private Collection<Topic> _getConstraintInstances(TopicMap topicMap, TypeInstanceIndex tiIdx, Locator subjectIdentifier) { + final Topic constraintType = topicMap.getTopicBySubjectIdentifier(subjectIdentifier); + if (constraintType == null) { + return Collections.emptySet(); + } + return tiIdx.getTopics(constraintType); + } + + private Collection<Topic> _getTopicTypeRolePlayers(Topic constraint, Collection<Association> assocs) { + return _getPlayers(constraint, _constraintRole, _topicTypeRole, assocs); + } + + private Collection<Topic> _getPlayers(Topic constraint, Topic constraintRoleType, Topic otherRoleType, Collection<Association> assocs) { + Collection<Topic> result = new ArrayList<Topic>(); + for (Role role: constraint.getRolesPlayed(constraintRoleType, _appliesTo)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + for (Role otherRole: assoc.getRoles(otherRoleType)) { + assocs.remove(assoc); + result.add(otherRole.getPlayer()); + } + } + return result; + } + + private void _processAbstractTopicConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ABSTRACT_TOPIC_TYPE_CONSTRAINT)) { + _processAbstractTopicConstraint(constraint, topics, assocs); + } + } + + private void _processAbstractTopicConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + ITemplate tpl = new DefaultTemplate("isAbstract"); + Collection<Topic> players = _getTopicTypeRolePlayers(constraint, assocs); + for (Topic player: players) { + _registerTemplate(player, tpl); + } + if (players.size() == constraint.getRolesPlayed().size() + && constraint.getOccurrences().isEmpty() + && constraint.getNames().isEmpty() + && constraint.getTypes().size() == 1 + && constraint.getSubjectLocators().isEmpty() + && constraint.getSubjectIdentifiers().isEmpty()) { + topics.remove(constraint); + } + } + + private void _processSubjectIdentifierConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + _processLocatorConstraints(topicMap, tiIdx, "has-subjectidentifier", TMCL.SUBJECT_IDENTIFIER_CONSTRAINT, topics, assocs); + } + + private void _processSubjectLocatorConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + _processLocatorConstraints(topicMap, tiIdx, "has-subjectlocator", TMCL.SUBJECT_LOCATOR_CONSTRAINT, topics, assocs); + } + + private void _processLocatorConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, String templateName, Locator constraintSID, Collection<Topic> topics, + Collection<Association> assocs) { + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, constraintSID)) { + _processLocatorConstraint(constraint, templateName, constraintSID, topics, assocs); + } + } + + private void _processLocatorConstraint(Topic constraint, + String templateName, Locator constraintSID, Collection<Topic> topics, + Collection<Association> assocs) { + ILiteral cardMin = _getCardMin(constraint); + ILiteral cardMax = _getCardMax(constraint); + ILiteral regEx = _getRegEx(constraint); + //TODO: Default values? + if (cardMin == null || cardMax == null || regEx == null) { + return; + } + DefaultTemplate tpl = new DefaultTemplate(templateName); + tpl.addParameter(cardMin); + tpl.addParameter(cardMax); + tpl.addParameter(regEx); + Collection<Topic> players = _getTopicTypeRolePlayers(constraint, assocs); + for (Topic player: players) { + _registerTemplate(player, tpl); + } + if (players.size() == constraint.getRolesPlayed().size() + && constraint.getOccurrences().size() == 3 + && constraint.getNames().isEmpty() + && constraint.getTypes().size() == 1 + && constraint.getSubjectLocators().isEmpty() + && constraint.getSubjectIdentifiers().isEmpty()) { + topics.remove(constraint); + } + } + + private void _processAssociationTypeScopeConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.ASSOCIATION_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ASSOCIATION_TYPE_SCOPE_CONSTRAINT)) { + _processTypeScopeConstraint(constraint, "has-association-scope", type, topics, assocs); + } + } + + private void _processRoleConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.ROLE_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ASSOCIATION_ROLE_CONSTRAINT)) { + _processRoleConstraint(constraint, type, topics, assocs); + } + } + + //TODO: Merge with {@link #_processTypeScopeConstraint} + private void _processRoleConstraint(Topic constraint, Topic type, Collection<Topic> topics, + Collection<Association> assocs) { + Topic topic = _getRolePlayer(constraint, type, assocs); + ILiteral cardMin = _getCardMin(constraint); + ILiteral cardMax = _getCardMax(constraint); + if (topic == null || cardMin == null || cardMax == null) { + return; + } + DefaultTemplate tpl = new DefaultTemplate("has-role"); + tpl.addParameter(topic); + tpl.addParameter(cardMin); + tpl.addParameter(cardMax); + Collection<Topic> players = _getPlayers(constraint, _constraintRole, _assocTypeRole, assocs); + for (Topic player: players) { + _registerTemplate(player, tpl); + } + if (players.size() * 2 == constraint.getRolesPlayed().size() + && constraint.getOccurrences().size() == 2 + && constraint.getNames().isEmpty() + && constraint.getTypes().size() == 1 + && constraint.getSubjectLocators().isEmpty() + && constraint.getSubjectIdentifiers().isEmpty()) { + topics.remove(constraint); + } + } + + private void _processPlayerConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.ROLE_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ASSOCIATION_ROLE_CONSTRAINT)) { + _processRoleConstraint(constraint, type, topics, assocs); + } + } + + private void _processOccurrenceConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.OCCURRENCE_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.TOPIC_OCCURRENCE_CONSTRAINT)) { + _processHasTopicChildConstraint(constraint, "has-occurrence", type, topics, assocs); + } + } + + private void _processOccurrenceTypeScopeConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.OCCURRENCE_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.TOPIC_OCCURRENCE_TYPE)) { + _processTypeScopeConstraint(constraint, "has-occurrence-scope", type, topics, assocs); + } + } + + private void _processTypeScopeConstraint(Topic constraint, String templateName, Topic type, + Collection<Topic> topics, Collection<Association> assocs) { + Topic topic = _getRolePlayer(constraint, type, assocs); + ILiteral cardMin = _getCardMin(constraint); + ILiteral cardMax = _getCardMax(constraint); + if (topic == null || cardMin == null || cardMax == null) { + return; + } + DefaultTemplate tpl = new DefaultTemplate(templateName); + tpl.addParameter(topic); + tpl.addParameter(cardMin); + tpl.addParameter(cardMax); + Collection<Topic> players = _getPlayers(constraint, _constraintRole, _scopeTypeRole, assocs); + for (Topic player: players) { + _registerTemplate(player, tpl); + } + if (players.size() * 2 == constraint.getRolesPlayed().size() + && constraint.getOccurrences().size() == 2 + && constraint.getNames().isEmpty() + && constraint.getTypes().size() == 1 + && constraint.getSubjectLocators().isEmpty() + && constraint.getSubjectIdentifiers().isEmpty()) { + topics.remove(constraint); + } + } + + private void _processNameConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.NAME_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.NAME_TYPE)) { + _processHasTopicChildConstraint(constraint, "has-name", type, topics, assocs); + } + } + + private void _processHasTopicChildConstraint(Topic constraint, String templateName, + Topic type, Collection<Topic> topics, Collection<Association> assocs) { + Topic topic = _getRolePlayer(constraint, type, assocs); + ILiteral cardMin = _getCardMin(constraint); + ILiteral cardMax = _getCardMax(constraint); + ILiteral regEx = _getRegEx(constraint); + if (topic == null || cardMin == null || cardMax == null || regEx == null) { + return; + } + DefaultTemplate tpl = new DefaultTemplate(templateName); + tpl.addParameter(topic); + tpl.addParameter(cardMin); + tpl.addParameter(cardMax); + tpl.addParameter(regEx); + Collection<Topic> players = _getTopicTypeRolePlayers(constraint, assocs); + for (Topic player: players) { + _registerTemplate(player, tpl); + } + if (players.size() * 2 == constraint.getRolesPlayed().size() + && constraint.getOccurrences().size() == 3 + && constraint.getNames().isEmpty() + && constraint.getTypes().size() == 1 + && constraint.getSubjectLocators().isEmpty() + && constraint.getSubjectIdentifiers().isEmpty()) { + topics.remove(constraint); + } + } + + private void _processNameTypeScopeConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.NAME_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.NAME_TYPE_SCOPE_CONSTRAINT)) { + _processTypeScopeConstraint(constraint, "has-name-scope", type, topics, assocs); + } + } + + private Topic _getRolePlayer(Topic constraint, Topic roleType, Collection<Association> assocs) { + Collection<Topic> players = _getPlayers(constraint, _constraintRole, roleType, assocs); + return players.isEmpty() ? null : players.iterator().next(); + } + + private ILiteral _getValue(Topic topic, Topic type) { + if (type == null) { + return null; + } + Collection<Occurrence> occs = topic.getOccurrences(type); + if (occs.size() != 1) { + return null; + } + return ((IOccurrence) occs.iterator().next()).getLiteral(); + } + + private ILiteral _getCardMin(Topic constraint) { + return _getValue(constraint, _cardMin); + } + + private ILiteral _getCardMax(Topic constraint) { + return _getValue(constraint, _cardMax); + } + + private ILiteral _getRegEx(Topic constraint) { + return _getValue(constraint, _regEx); + } + + private boolean _isBinary(Association assoc) { + return assoc.getRoles().size() == 2; + } + + private void _init(TopicMap topicMap) { + _appliesTo = topicMap.getTopicBySubjectIdentifier(TMCL.APPLIES_TO); + _constraintRole = topicMap.getTopicBySubjectIdentifier(TMCL.CONSTRAINT_ROLE); + _cardMin = topicMap.getTopicBySubjectIdentifier(TMCL.CARD_MIN); + _cardMax = topicMap.getTopicBySubjectIdentifier(TMCL.CARD_MAX); + _datatype = topicMap.getTopicBySubjectIdentifier(TMCL.DATATYPE); + _regEx = topicMap.getTopicBySubjectIdentifier(TMCL.REGEXP); + _topicTypeRole = topicMap.getTopicBySubjectIdentifier(TMCL.TOPIC_TYPE_ROLE); + _scopeTypeRole = topicMap.getTopicBySubjectIdentifier(TMCL.SCOPE_TYPE_ROLE); + _assocTypeRole = topicMap.getTopicBySubjectIdentifier(TMCL.ASSOCIATION_TYPE_ROLE); + } + + private void _registerTemplate(Topic topic, ITemplate tpl) { + Collection<ITemplate> templates = _topic2Templates.get(topic); + if (templates == null) { + templates = new ArrayList<ITemplate>(); + _topic2Templates.put(topic, templates); + } + templates.add(tpl); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java 2009-07-02 14:51:22 UTC (rev 310) @@ -0,0 +1,68 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio.internal.ctm.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.tinytim.mio.internal.ctm.ITemplate; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class DefaultTemplate implements ITemplate { + + private final String _name; + private List<Object> _params; + + public DefaultTemplate(String name) { + _name = name; + _params = new ArrayList<Object>(); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.internal.ctm.ITemplate#getName() + */ + @Override + public String getName() { + return _name; + } + + /* (non-Javadoc) + * @see org.tinytim.mio.internal.ctm.ITemplate#getParameters() + */ + @Override + public List<Object> getParameters() { + return _params; + } + + public void addParameter(Object param) { + if (param == null) { + throw new IllegalArgumentException("The paramater must not be null"); + } + _params.add(param); + } + + @Override + public int compareTo(ITemplate o) { + // TODO Auto-generated method stub + return 0; + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 14:27:35
|
Revision: 309 http://tinytim.svn.sourceforge.net/tinytim/?rev=309&view=rev Author: lheuer Date: 2009-07-02 14:27:30 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Updated CHANGES.txt for 2.0 Modified Paths: -------------- tinytim/trunk/CHANGES.txt tinytim-mio/trunk/CHANGES.txt Modified: tinytim/trunk/CHANGES.txt =================================================================== --- tinytim/trunk/CHANGES.txt 2009-07-02 12:49:30 UTC (rev 308) +++ tinytim/trunk/CHANGES.txt 2009-07-02 14:27:30 UTC (rev 309) @@ -10,7 +10,7 @@ * Bug #2812460 -- Port the Check class from Ontopia back to tinyTiM * Bug #2809821 -- Ensure same topic map constraint -* +* Bug #2561306 -- Move TinyTimMapInputHandler to the core 2.0.0 a4 (06.12.2008) Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2009-07-02 12:49:30 UTC (rev 308) +++ tinytim-mio/trunk/CHANGES.txt 2009-07-02 14:27:30 UTC (rev 309) @@ -2,8 +2,10 @@ Changes Log =========== -1.5.0 (02.07.2009) +2.0.0 a5 (xx.07.2009) --------------------- +* JTMTopicMapReader / JTMTopicMapWriter implement the new JSON Topic Maps + specification (<http://www.cerny-online.com/jtm/1.0/> * LTMTopicMapReader: Configurable reification handling Bugfixes: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 13:17:10
|
Revision: 306 http://tinytim.svn.sourceforge.net/tinytim/?rev=306&view=rev Author: lheuer Date: 2009-07-02 12:45:44 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Added Paths: ----------- tinytim-mio/tags/release-1_5_0/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 13:17:09
|
Revision: 307 http://tinytim.svn.sourceforge.net/tinytim/?rev=307&view=rev Author: lheuer Date: 2009-07-02 12:47:54 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Removed references to tinyTiM 1.5 Removed Paths: ------------- tinytim-mio/trunk/build-15.properties tinytim-mio/trunk/build-15.xml tinytim-mio/trunk/lib/tinytim-1.5.0.jar tinytim-mio/trunk/lib/tmapi-1_0SP1.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio15/ Deleted: tinytim-mio/trunk/build-15.properties =================================================================== --- tinytim-mio/trunk/build-15.properties 2009-07-02 12:45:44 UTC (rev 306) +++ tinytim-mio/trunk/build-15.properties 2009-07-02 12:47:54 UTC (rev 307) @@ -1,5 +0,0 @@ -version=1.5.0 -version_suffix= -release_type= -debug=off -optimize=on Deleted: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2009-07-02 12:45:44 UTC (rev 306) +++ tinytim-mio/trunk/build-15.xml 2009-07-02 12:47:54 UTC (rev 307) @@ -1,199 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<project name="tinyTiM" default="jar" basedir="."> - <property file="build-15.properties"/> - <tstamp/> - <property name="release_type" value="-snapshot-${DSTAMP}${TSTAMP}"/> - - <property name="dir.src" value="${basedir}/src/main/java"/> - <property name="dir.test" value="${basedir}/src/test/java"/> - <property name="dir.lib" value="${basedir}/lib"/> - - <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> - <property name="lib.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0.jar"/> - <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> - <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> - - <target name="help"> - <echo message="------------------------"/> - <echo message="tinyTiM MIO - Build file"/> - <echo message="------------------------"/> - <echo message=""/> - <echo message="Available targets:"/> - <echo message=""/> - <echo message=" jar Creates the jar"/> - <echo message=" doc Generates the Java Docs"/> - <echo message=" release Creates the jar and a distributable file"/> - </target> - - <target name="init"> - <property name="dist.version" value="${version}${version_suffix}${release_type}"/> - <property name="dist.name" value="tinytim-mio-${dist.version}"/> - - <property name="tinytim-mio.jar" value="${dist.name}.jar"/> - <property name="tinytim-mio.tar" value="${dist.name}.tar"/> - <property name="tinytim-mio.tar.gz" value="${tinytim-mio.tar}.gz"/> - <property name="tinytim-mio.zip" value="${dist.name}.zip"/> - - <property name="dir.build" value="${basedir}/build"/> - <property name="dir.dist.root" value="${dir.build}/dist"/> - <property name="dir.dist" value="${dir.dist.root}/${dist.name}"/> - <property name="dir.build.classes" value="${dir.build}/classes"/> - <property name="dir.build.tests" value="${dir.build}/tests"/> - <property name="dir.javadocs" value="${dir.dist}/docs/api"/> - </target> - - <!-- =================================================================== --> - <!-- Clean targets --> - <!-- =================================================================== --> - <target name="clean" depends="init"> - <delete dir="${dir.build}"/> - <delete dir="${dir.javadocs}"/> - </target> - - <!-- =================================================================== --> - <!-- Prepares the build directory --> - <!-- =================================================================== --> - <target name="prepare" depends="init"> - <mkdir dir="${dir.build}"/> - <mkdir dir="${dir.build.classes}"/> - </target> - - <!-- =================================================================== --> - <!-- Creates the Java Docs --> - <!-- =================================================================== --> - <target name="doc" depends="init"> - <mkdir dir="${dir.javadocs}"/> - <javadoc destdir="${dir.javadocs}" - packagenames="org.tinytim.*" - author="true" - version="false" - use="true" - splitindex="true" - noindex="false" - windowtitle="tinyTiM MIO API v${dist.version}" - doctitle="tinyTiM API MIO v${dist.version}"> - <fileset dir="${dir.src}"> - <exclude name="org/tinytim/mio/JTM*Writer*"/> -<!-- <include name="org/tinytim/mio/** org/tinytim/mio/*TopicMapReader* org/tinytim/mio/*TopicMapImporter*"/> --> - </fileset> - <link href="http://www.tmapi.org/apiDocs/"/> - </javadoc> - </target> - - <!-- =================================================================== --> - <!-- Tests --> - <!-- =================================================================== --> - <target name="test" depends="compile"> - <mkdir dir="${dir.build.tests}"/> - <javac destdir="${dir.build.tests}" - debug="${debug}" - optimize="${optimize}" - target="1.5" - excludes="org/tinytim/mio/TinyTimMapInputHandler*" - > - <classpath> - <pathelement location="${dir.build.classes}"/> - <pathelement location="${lib.junit}"/> - <pathelement location="${lib.tmapi}"/> - <pathelement location="${lib.tinytim}"/> - <pathelement location="${lib.mio}"/> - </classpath> - <src path="${dir.test}"/> - </javac> - <junit printsummary="true" showoutput="false" - errorProperty="test.failed" failureProperty="test.failed"> - <classpath> - <pathelement location="${dir.build.classes}"/> - <pathelement location="${dir.build.tests}"/> - <pathelement location="${lib.junit}"/> - <pathelement location="${lib.tmapi}"/> - <pathelement location="${lib.tinytim}"/> - <pathelement location="${lib.mio}"/> - </classpath> - <formatter type="brief" usefile="false"/> - <batchtest fork="no" todir="${dir.build}"> - <fileset dir="${dir.build.tests}/"> - <include name="**/Test**.class"/> - </fileset> - </batchtest> - </junit> - <fail message="Tests failed. Check test output." if="test.failed"/> - </target> - - <!-- =================================================================== --> - <!-- Compile source files --> - <!-- =================================================================== --> - <target name="compile" depends="clean, prepare"> - <javac destdir="${dir.build.classes}" - debug="${debug}" - excludes="org/tinytim/mio/AbstractTopicMapWriter* org/tinytim/mio/CXTMTopicMapWriter* org/tinytim/mio/XTM*TopicMapWriter* org/tinytim/mio/JTM*Writer* org/tinytim/mio/JSON*" - includes="org/tinytim/mio15/** org/tinytim/mio/*TopicMapReader* org/tinytim/mio/*TopicMapImporter*" - target="1.5"> - <classpath> - <pathelement location="${lib.tmapi}"/> - <pathelement location="${lib.tinytim}"/> - <pathelement location="${lib.mio}"/> - <pathelement location="${lib.logging}"/> - </classpath> - <src path="${dir.src}"/> - </javac> - </target> - - <!-- =================================================================== --> - <!-- Creates the jar --> - <!-- =================================================================== --> - <target name="jar" depends="compile"> - <jar destfile="${dir.build}/${tinytim-mio.jar}"> - <fileset dir="${dir.build.classes}"> - <include name="**/*.*"/> - </fileset> - <manifest> - <attribute name="Implementation-Title" value="tinyTiM MIO"/> - <attribute name="Implementation-Version" value="${dist.version}"/> - <attribute name="Implementation-URL" value="http://tinytim.sourceforge.net/"/> - </manifest> - </jar> - </target> - - <!-- =================================================================== --> - <!-- Prepares a distribution --> - <!-- =================================================================== --> - <target name="dist" depends="jar"> - <mkdir dir="${dir.dist}"/> - - <copy todir="${dir.dist}" file="${dir.build}/${tinytim-mio.jar}"/> -<!-- - <copy todir="${dir.dist}/src"> - <fileset dir="${dir.src}"/> - </copy> - <copy todir="${dir.dist}/test"> - <fileset dir="${dir.test}"/> - </copy> ---> - <copy todir="${dir.dist}/lib"> - <fileset dir="${dir.lib}"> - <exclude name="**/tmapi*.jar"/> - <exclude name="**/tinytim*.jar"/> - </fileset> - </copy> - - <copy todir="${dir.dist}" file="CHANGES.txt"/> - <copy todir="${dir.dist}" file="LICENSE.txt"/> - <copy todir="${dir.dist}" file="README.txt"/> - </target> - - <!-- =================================================================== --> - <!-- Creates the distribution files (.zip and .tar.gz) --> - <!-- --> - <!-- Won't create the distribution files if a test fails --> - <!-- =================================================================== --> - <target name="release" depends="jar, doc, dist"> - <tar destfile="${dir.dist.root}/${tinytim-mio.tar}" - basedir="${dir.dist.root}"/> - <gzip src="${dir.dist.root}/${tinytim-mio.tar}" - destfile="${dir.build}/${tinytim-mio.tar.gz}" /> - <delete file="${dir.dist.root}/${tinytim-mio.tar}" /> - <zip destfile="${dir.build}/${tinytim-mio.zip}" basedir="${dir.dist.root}"/> - </target> -</project> Deleted: tinytim-mio/trunk/lib/tinytim-1.5.0.jar =================================================================== (Binary files differ) Deleted: tinytim-mio/trunk/lib/tmapi-1_0SP1.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 13:17:08
|
Revision: 305 http://tinytim.svn.sourceforge.net/tinytim/?rev=305&view=rev Author: lheuer Date: 2009-07-02 12:44:13 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Preparation for 1.5.0 mio release Modified Paths: -------------- tinytim-mio/trunk/CHANGES.txt tinytim-mio/trunk/build-15.properties tinytim-mio/trunk/build-15.xml Added Paths: ----------- tinytim-mio/trunk/lib/tinytim-1.5.0.jar Removed Paths: ------------- tinytim-mio/trunk/lib/tinytim-1.5.0b2.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio15/TinyTimMapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/mio15/ Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2009-07-02 12:24:57 UTC (rev 304) +++ tinytim-mio/trunk/CHANGES.txt 2009-07-02 12:44:13 UTC (rev 305) @@ -2,10 +2,8 @@ Changes Log =========== -2.0.0 a5 (xx.05.2009) +1.5.0 (02.07.2009) --------------------- -* JTMTopicMapReader / JTMTopicMapWriter implement the new JSON Topic Maps - specification (<http://www.cerny-online.com/jtm/1.0/> * LTMTopicMapReader: Configurable reification handling Bugfixes: Modified: tinytim-mio/trunk/build-15.properties =================================================================== --- tinytim-mio/trunk/build-15.properties 2009-07-02 12:24:57 UTC (rev 304) +++ tinytim-mio/trunk/build-15.properties 2009-07-02 12:44:13 UTC (rev 305) @@ -1,5 +1,5 @@ version=1.5.0 -version_suffix=b2 -#release_type= +version_suffix= +release_type= debug=off optimize=on Modified: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2009-07-02 12:24:57 UTC (rev 304) +++ tinytim-mio/trunk/build-15.xml 2009-07-02 12:44:13 UTC (rev 305) @@ -10,7 +10,7 @@ <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0b2.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> Added: tinytim-mio/trunk/lib/tinytim-1.5.0.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-1.5.0.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/lib/tinytim-1.5.0b2.jar =================================================================== (Binary files differ) Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/TinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio15/TinyTimMapInputHandler.java 2009-07-02 12:24:57 UTC (rev 304) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/TinyTimMapInputHandler.java 2009-07-02 12:44:13 UTC (rev 305) @@ -1,590 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.mio; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.logging.Logger; - -import org.tinytim.IReifiable; -import org.tinytim.ITyped; -import org.tinytim.TopicMapImpl; -import org.tinytim.TypeInstanceConverter; -import org.tinytim.voc.TMDM; -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.Locator; -import org.tmapi.core.Occurrence; -import org.tmapi.core.ScopedObject; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.TopicMapObject; -import org.tmapi.core.TopicName; -import org.tmapi.core.Variant; - -import com.semagia.mio.IMapHandler; -import com.semagia.mio.IRef; -import com.semagia.mio.MIOException; -import com.semagia.mio.voc.XSD; - -/** - * {@link com.semagia.mio.IMapHandler} implementation. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TinyTimMapInputHandler implements IMapHandler { - - private enum State { - INITIAL, TOPIC, ASSOCIATION, ROLE, OCCURRENCE, NAME, VARIANT, - SCOPE, THEME, REIFIER, PLAYER, ISA, TYPE; - } - - private static final Logger LOG = Logger.getLogger(TinyTimMapInputHandler.class.getName()); - - private TopicMapImpl _tm; - private List<State> _stateStack; - private List<TopicMapObject> _constructStack; - - public TinyTimMapInputHandler() { - } - - public TinyTimMapInputHandler(TopicMap topicMap) { - this(); - setTopicMap(topicMap); - } - - /** - * Sets the topic map instance to operate on. - * - * @param topicMap The topic map. - */ - public void setTopicMap(TopicMap topicMap) { - if (topicMap == null) { - throw new IllegalArgumentException("The topic map must not be null"); - } - _tm = (TopicMapImpl) topicMap; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTopicMap() - */ - public void startTopicMap() throws MIOException { - _constructStack = new ArrayList<TopicMapObject>(); - _stateStack = new ArrayList<State>(); - _enterState(State.INITIAL, _tm); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTopicMap() - */ - public void endTopicMap() throws MIOException { - TypeInstanceConverter.convertAssociationsToTypes(_tm); - _constructStack = null; - _stateStack = null; - _tm = null; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTopic(com.semagia.mio.IRef) - */ - public void startTopic(IRef identity) throws MIOException { - _enterState(State.TOPIC, _createTopic(identity)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTopic() - */ - public void endTopic() throws MIOException { - Topic topic = (Topic) _leaveStatePopConstruct(State.TOPIC); - _handleTopic(topic); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startAssociation() - */ - public void startAssociation() throws MIOException { - _enterState(State.ASSOCIATION, _tm.createAssociation()); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endAssociation() - */ - public void endAssociation() throws MIOException { - _leaveStatePopConstruct(State.ASSOCIATION); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startRole() - */ - public void startRole() throws MIOException { - assert _state() == State.ASSOCIATION; - _enterState(State.ROLE, ((Association) _peekConstruct()).createAssociationRole(null, null)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endRole() - */ - public void endRole() throws MIOException { - _leaveStatePopConstruct(State.ROLE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startPlayer() - */ - public void startPlayer() throws MIOException { - assert _state() == State.ROLE; - _enterState(State.PLAYER); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endPlayer() - */ - public void endPlayer() throws MIOException { - _leaveState(State.PLAYER); - assert _state() == State.ROLE; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startOccurrence() - */ - public void startOccurrence() throws MIOException { - _enterState(State.OCCURRENCE, _peekTopic().createOccurrence((Locator) null, null, null)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endOccurrence() - */ - public void endOccurrence() throws MIOException { - _leaveStatePopConstruct(State.OCCURRENCE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startName() - */ - public void startName() throws MIOException { - _enterState(State.NAME, _peekTopic().createTopicName(null, null)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endName() - */ - public void endName() throws MIOException { - TopicName name = (TopicName) _leaveStatePopConstruct(State.NAME); - if (name.getType() == null) { - name.setType(_topicBySubjectIdentifier(TMDM.TOPIC_NAME)); - } - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startVariant() - */ - public void startVariant() throws MIOException { - assert _state() == State.NAME; - _enterState(State.VARIANT, ((TopicName) _peekConstruct()).createVariant((Locator) null, null)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endVariant() - */ - @SuppressWarnings("unchecked") - public void endVariant() throws MIOException { - Variant variant = (Variant) _leaveStatePopConstruct(State.VARIANT); - Collection<Topic> scope = variant.getScope(); - if (scope.isEmpty() || variant.getTopicName().getScope().equals(scope)) { - throw new MIOException("The variant has no scope"); - } - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startType() - */ - public void startType() throws MIOException { - assert _peekConstruct() instanceof ITyped; - _enterState(State.TYPE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endType() - */ - public void endType() throws MIOException { - _leaveState(State.TYPE); - assert _peekConstruct() instanceof ITyped; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startScope() - */ - public void startScope() throws MIOException { - assert _peekConstruct() instanceof ScopedObject; - _enterState(State.SCOPE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endScope() - */ - public void endScope() throws MIOException { - _leaveState(State.SCOPE); - assert _peekConstruct() instanceof ScopedObject; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTheme() - */ - public void startTheme() throws MIOException { - assert _state() == State.SCOPE; - _enterState(State.THEME); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTheme() - */ - public void endTheme() throws MIOException { - _leaveState(State.THEME); - assert _state() == State.SCOPE; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#subjectIdentifier(java.lang.String) - */ - public void subjectIdentifier(String subjectIdentifier) throws MIOException { - Locator sid = _tm.createLocator(subjectIdentifier); - Topic topic = _peekTopic(); - Topic existing = _tm.getTopicBySubjectIdentifier(sid); - if (existing != null && !existing.equals(topic)) { - _merge(existing, topic); - } - else { - TopicMapObject tmo = _tm.getObjectByItemIdentifier(sid); - if (tmo != null && tmo instanceof Topic && !tmo.equals(topic)) { - _merge((Topic) tmo, topic); - } - } - topic.addSubjectIdentifier(sid); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#subjectLocator(java.lang.String) - */ - public void subjectLocator(String subjectLocator) throws MIOException { - Locator slo = _tm.createLocator(subjectLocator); - Topic topic = _peekTopic(); - Topic existing = _tm.getTopicBySubjectLocator(slo); - if (existing != null && !existing.equals(topic)) { - _merge(existing, topic); - } - topic.addSubjectLocator(slo); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#itemIdentifier(java.lang.String) - */ - public void itemIdentifier(String itemIdentifier) throws MIOException { - Locator iid = _tm.createLocator(itemIdentifier); - TopicMapObject tmo = _peekConstruct(); - if (_state() == State.TOPIC) { - TopicMapObject existing = _tm.getObjectByItemIdentifier(iid); - if (existing != null && existing instanceof Topic && !existing.equals(tmo)) { - _merge((Topic) existing, (Topic) tmo); - } - else { - Topic topic = _tm.getTopicBySubjectIdentifier(iid); - if (topic != null && !topic.equals(tmo)) { - _merge(topic, (Topic) tmo); - } - } - } - tmo.addSourceLocator(iid); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startIsa() - */ - public void startIsa() throws MIOException { - assert _state() == State.TOPIC; - _enterState(State.ISA); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endIsa() - */ - public void endIsa() throws MIOException { - _leaveState(State.ISA); - assert _state() == State.TOPIC; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startReifier() - */ - public void startReifier() throws MIOException { - assert _peekConstruct() instanceof IReifiable; - _enterState(State.REIFIER); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endReifier() - */ - public void endReifier() throws MIOException { - _leaveState(State.REIFIER); - assert _peekConstruct() instanceof IReifiable; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#topicRef(com.semagia.mio.IRef) - */ - public void topicRef(IRef identity) throws MIOException { - _handleTopic(_createTopic(identity)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#value(java.lang.String) - */ - public void value(String value) throws MIOException { - assert _state() == State.NAME; - ((TopicName) _peekConstruct()).setValue(value); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#value(java.lang.String, java.lang.String) - */ - public void value(String value, String datatype) throws MIOException { - boolean isLocator = XSD.ANY_URI.equals(datatype); - if (!isLocator && !XSD.STRING.equals(datatype)) { - LOG.warning("The datatype '" + datatype + "' was converted into xsd:string"); - } - if (_state() == State.OCCURRENCE) { - Occurrence occ = (Occurrence) _peekConstruct(); - if (isLocator) { - occ.setResource(_tm.createLocator(value)); - } - else { - occ.setValue(value); - } - } - else { - assert _state() == State.VARIANT; - Variant variant = (Variant) _peekConstruct(); - if (isLocator) { - variant.setResource(_tm.createLocator(value)); - } - else { - variant.setValue(value); - } - } - } - - /** - * Enters a state. - * - * @param state The state to push ontop of the state stack. - */ - private void _enterState(State state) { - _stateStack.add(state); - } - - /** - * Enters a state and pushes the Topic Maps construct ontop of the construct - * stack. - * - * @param state The state to enter. - * @param tmo The Topic Maps construct which should be pushed to the stack. - */ - private void _enterState(State state, TopicMapObject tmo) { - _enterState(state); - _constructStack.add(tmo); - } - - /** - * Leaves a state. - * - * @param state The state to leave. - * @throws MIOException If the state is not equals to the current state. - */ - private void _leaveState(State state) throws MIOException { - State current = _stateStack.remove(_stateStack.size()-1); - if (state != current) { - _reportError("Unexpected state: " + current + ", expected: " + state); - } - } - - /** - * Leaves a state and removed the Topic Maps construct from the top of the - * construct stack. - * - * @param state The state to leave. - * @return The removed construct. - * @throws MIOException If the state is not equals to the current state. - */ - private TopicMapObject _leaveStatePopConstruct(State state) throws MIOException { - _leaveState(state); - return _constructStack.remove(_constructStack.size()-1); - } - - /** - * Returns the Topic Maps construct on top of the stack. - * - * @return The Topic Maps construct. - */ - private TopicMapObject _peekConstruct() { - return _constructStack.get(_constructStack.size()-1); - } - - /** - * Returns the topic on top of the stack. - * - * @return The topic. - */ - private Topic _peekTopic() { - return (Topic) _peekConstruct(); - } - - /** - * Returns the current state. - * - * @return The current state. - */ - private State _state() { - return _stateStack.get(_stateStack.size()-1); - } - - /** - * Handles the topic dependent on the current state. - * - * @param topic The topic to handle. - */ - private void _handleTopic(Topic topic) { - switch (_state()) { - case ISA: _peekTopic().addType(topic); break; - case TYPE: ((ITyped) _peekConstruct()).setType(topic); break; - case PLAYER: ((AssociationRole) _peekConstruct()).setPlayer(topic); break; - case THEME: ((ScopedObject) _peekConstruct()).addScopingTopic(topic); break; - case REIFIER: ((IReifiable) _peekConstruct()).setReifier(topic); break; - } - } - - /** - * Merges the <tt>source</tt> topic with the <tt>target</tt>. - * - * Further, this method ensures that the construct stack stays valid: If - * the <tt>source</tt> is part of the stack, it is replaced with - * <tt>target</tt>. - * - * @param source The source topic (will be removed). - * @param target The target topic. - */ - private void _merge(Topic source, Topic target) { - int i = _constructStack.indexOf(source); - while (i > -1) { - _constructStack.set(i, target); - i = _constructStack.indexOf(source); - } - target.mergeIn(source); - } - - /** - * Returns either an existing topic with the specified identity or creates - * a topic with the given identity. - * - * @param ref The identity of the topic. - * @return A topic instance. - * @throws MIOException - */ - private Topic _createTopic(IRef ref) throws MIOException { - Locator loc = _tm.createLocator(ref.getIRI()); - switch (ref.getType()) { - case IRef.ITEM_IDENTIFIER: return _topicByItemIdentifier(loc); - case IRef.SUBJECT_IDENTIFIER: return _topicBySubjectIdentifier(loc); - case IRef.SUBJECT_LOCATOR: return _topicBySubjectLocator(loc); - default: _reportError("Unknown reference type " + ref.getType()); - } - // Never returned, an exception was thrown - return null; - } - - /** - * Returns either an existing topic with the specified item identfier, - * or creates a topic with the given item identifier. - * - * @param iid The item identifier of the topic. - * @return A topic instance. - */ - private Topic _topicByItemIdentifier(Locator iid) { - TopicMapObject tmo = _tm.getObjectByItemIdentifier(iid); - Topic topic = (tmo instanceof Topic) ? (Topic) tmo : null; - if (topic == null) { - topic = _tm.getTopicBySubjectIdentifier(iid); - if (topic != null) { - topic.addSourceLocator(iid); - } - } - if (topic == null) { - topic = _tm.createTopic(); - topic.addSourceLocator(iid); - } - return topic; - } - - /** - * Returns either an existing topic with the specified subject identfier, - * or creates a topic with the given subject identifier. - * - * @param sid The subject identifier of the topic. - * @return A topic instance. - */ - private Topic _topicBySubjectIdentifier(Locator sid) { - Topic topic = _tm.getTopicBySubjectIdentifier(sid); - if (topic == null) { - TopicMapObject tmo = _tm.getObjectByItemIdentifier(sid); - if (tmo instanceof Topic) { - topic = (Topic) tmo; - topic.addSubjectIdentifier(sid); - } - } - if (topic == null) { - topic = _tm.createTopic(); - topic.addSubjectIdentifier(sid); - } - return topic; - } - - /** - * Returns either an existing topic with the specified subject locator, - * or creates a topic with the given subject locator. - * - * @param slo The subject locator of the topic. - * @return A topic instance. - */ - private Topic _topicBySubjectLocator(Locator slo) { - Topic topic = _tm.getTopicBySubjectLocator(slo); - if (topic == null) { - topic = _tm.createTopic(); - topic.addSubjectLocator(slo); - } - return topic; - } - - /** - * Reports an error. - * - * @param msg The error message. - * @throws MIOException Thrown in any case. - */ - private static void _reportError(String msg) throws MIOException { - throw new MIOException(msg); - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 13:17:07
|
Revision: 308 http://tinytim.svn.sourceforge.net/tinytim/?rev=308&view=rev Author: lheuer Date: 2009-07-02 12:49:30 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Updated 2.0 build file Modified Paths: -------------- tinytim-mio/trunk/build.xml Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-07-02 12:47:54 UTC (rev 307) +++ tinytim-mio/trunk/build.xml 2009-07-02 12:49:30 UTC (rev 308) @@ -74,9 +74,6 @@ noindex="false" windowtitle="tinyTiM MIO API v${dist.version}" doctitle="tinyTiM API MIO v${dist.version}"> - <fileset dir="${dir.src}"> - <exclude name="org/tinytim/mio15/**"/> - </fileset> <!-- <doclet name="net.gleamynode.apiviz.APIviz" path="${dir.lib}/apiviz-1.2.5.GA.jar"> @@ -95,7 +92,6 @@ debug="${debug}" optimize="${optimize}" target="1.5" - excludes="org/tinytim/mio15/**" > <classpath> <pathelement location="${dir.build.classes}"/> @@ -134,8 +130,7 @@ <target name="compile" depends="clean, prepare"> <javac destdir="${dir.build.classes}" debug="${debug}" - target="1.5" - excludes="org/tinytim/mio15/**"> + target="1.5"> <classpath> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tinytim}"/> @@ -173,7 +168,6 @@ <copy todir="${dir.dist}/src"> <fileset dir="${dir.src}"> - <exclude name="**/mio15/**"/> </fileset> </copy> <copy todir="${dir.dist}/test"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 13:16:52
|
Revision: 304 http://tinytim.svn.sourceforge.net/tinytim/?rev=304&view=rev Author: lheuer Date: 2009-07-02 12:24:57 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Preparation for the final release of tinyTiM 1.5. Yes. Markus, final. Aus die Maus. ;) Modified Paths: -------------- tinytim/tags/release-1_5_0/CHANGES.txt tinytim/tags/release-1_5_0/build.properties tinytim/tags/release-1_5_0/build.xml Added Paths: ----------- tinytim/tags/release-1_5_0/lib/semagia-mio-0.9.4.jar tinytim/tags/release-1_5_0/lib/trove-2.0.4.jar tinytim/tags/release-1_5_0/src/main/java/org/tinytim/mio/ tinytim/tags/release-1_5_0/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java tinytim/tags/release-1_5_0/src/test/java/org/tinytim/mio/ tinytim/tags/release-1_5_0/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java Removed Paths: ------------- tinytim/tags/release-1_5_0/lib/trove-2.0.3.jar Modified: tinytim/tags/release-1_5_0/CHANGES.txt =================================================================== --- tinytim/tags/release-1_5_0/CHANGES.txt 2009-07-02 11:48:24 UTC (rev 303) +++ tinytim/tags/release-1_5_0/CHANGES.txt 2009-07-02 12:24:57 UTC (rev 304) @@ -2,6 +2,15 @@ Changes Log =========== +1.5.0 (02.07.2009) +------------------ +This is the final release of tinyTiM for TMAPI 1.0 + +Bugfixes: +--------- +* Bug #2561306 -- Move TinyTimMapInputHandler to the core + + 1.5.0 b2 (20.11.2008) ----------------------- Bugfixes: Modified: tinytim/tags/release-1_5_0/build.properties =================================================================== --- tinytim/tags/release-1_5_0/build.properties 2009-07-02 11:48:24 UTC (rev 303) +++ tinytim/tags/release-1_5_0/build.properties 2009-07-02 12:24:57 UTC (rev 304) @@ -1,4 +1,4 @@ version=1.5.0 -version_suffix=b2 +version_suffix= debug=off optimize=on Modified: tinytim/tags/release-1_5_0/build.xml =================================================================== --- tinytim/tags/release-1_5_0/build.xml 2009-07-02 11:48:24 UTC (rev 303) +++ tinytim/tags/release-1_5_0/build.xml 2009-07-02 12:24:57 UTC (rev 304) @@ -29,7 +29,8 @@ <property name="dir.res" value="${basedir}/src/main/resources"/> <property name="lib.junit" value="${dir.lib}/junit-4.4.jar"/> - <property name="lib.trove" value="${dir.lib}/trove-2.0.3.jar"/> + <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> + <property name="lib.trove" value="${dir.lib}/trove-2.0.4.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> <property name="lib.tmapi.tests" value="${dir.lib}/tmapi-test-1_0SP1.jar"/> @@ -93,6 +94,7 @@ <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tmapi.tests}"/> <pathelement location="${lib.trove}"/> + <pathelement location="${lib.mio}"/> </classpath> <src path="${dir.test}"/> </javac> @@ -105,6 +107,7 @@ <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tmapi.tests}"/> <pathelement location="${lib.trove}"/> + <pathelement location="${lib.mio}"/> </classpath> <formatter type="brief" usefile="false"/> <batchtest fork="no" todir="${dir.build}"> @@ -127,6 +130,7 @@ <classpath> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.trove}"/> + <pathelement location="${lib.mio}"/> </classpath> <src path="${dir.src}"/> </javac> @@ -193,7 +197,14 @@ <fileset dir="${dir.test}"/> </copy> <copy todir="${dir.dist}/lib"> - <fileset dir="${dir.lib}"/> + <fileset dir="${dir.lib}"> + <include name="tmapi*"/> + <include name="junit*"/> + <include name="trove*"/> + <include name="LICENSE.tmapi*"/> + <include name="LICENSE.junit*"/> + <include name="LICENSE.trove*"/> + </fileset> </copy> <copy todir="${dir.dist}" file="CHANGES.txt"/> Added: tinytim/tags/release-1_5_0/lib/semagia-mio-0.9.4.jar =================================================================== (Binary files differ) Property changes on: tinytim/tags/release-1_5_0/lib/semagia-mio-0.9.4.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim/tags/release-1_5_0/lib/trove-2.0.3.jar =================================================================== (Binary files differ) Added: tinytim/tags/release-1_5_0/lib/trove-2.0.4.jar =================================================================== (Binary files differ) Property changes on: tinytim/tags/release-1_5_0/lib/trove-2.0.4.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: tinytim/tags/release-1_5_0/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim/tags/release-1_5_0/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java (rev 0) +++ tinytim/tags/release-1_5_0/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-02 12:24:57 UTC (rev 304) @@ -0,0 +1,590 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.logging.Logger; + +import org.tinytim.IReifiable; +import org.tinytim.ITyped; +import org.tinytim.TopicMapImpl; +import org.tinytim.TypeInstanceConverter; +import org.tinytim.voc.TMDM; +import org.tmapi.core.Association; +import org.tmapi.core.AssociationRole; +import org.tmapi.core.Locator; +import org.tmapi.core.Occurrence; +import org.tmapi.core.ScopedObject; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.core.TopicMapObject; +import org.tmapi.core.TopicName; +import org.tmapi.core.Variant; + +import com.semagia.mio.IMapHandler; +import com.semagia.mio.IRef; +import com.semagia.mio.MIOException; +import com.semagia.mio.voc.XSD; + +/** + * {@link com.semagia.mio.IMapHandler} implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev: 223 $ - $Date: 2008-11-21 14:17:29 +0100 (Fr, 21 Nov 2008) $ + */ +public class TinyTimMapInputHandler implements IMapHandler { + + private enum State { + INITIAL, TOPIC, ASSOCIATION, ROLE, OCCURRENCE, NAME, VARIANT, + SCOPE, THEME, REIFIER, PLAYER, ISA, TYPE; + } + + private static final Logger LOG = Logger.getLogger(TinyTimMapInputHandler.class.getName()); + + private TopicMapImpl _tm; + private List<State> _stateStack; + private List<TopicMapObject> _constructStack; + + public TinyTimMapInputHandler() { + } + + public TinyTimMapInputHandler(TopicMap topicMap) { + this(); + setTopicMap(topicMap); + } + + /** + * Sets the topic map instance to operate on. + * + * @param topicMap The topic map. + */ + public void setTopicMap(TopicMap topicMap) { + if (topicMap == null) { + throw new IllegalArgumentException("The topic map must not be null"); + } + _tm = (TopicMapImpl) topicMap; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startTopicMap() + */ + public void startTopicMap() throws MIOException { + _constructStack = new ArrayList<TopicMapObject>(); + _stateStack = new ArrayList<State>(); + _enterState(State.INITIAL, _tm); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTopicMap() + */ + public void endTopicMap() throws MIOException { + TypeInstanceConverter.convertAssociationsToTypes(_tm); + _constructStack = null; + _stateStack = null; + _tm = null; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startTopic(com.semagia.mio.IRef) + */ + public void startTopic(IRef identity) throws MIOException { + _enterState(State.TOPIC, _createTopic(identity)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTopic() + */ + public void endTopic() throws MIOException { + Topic topic = (Topic) _leaveStatePopConstruct(State.TOPIC); + _handleTopic(topic); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startAssociation() + */ + public void startAssociation() throws MIOException { + _enterState(State.ASSOCIATION, _tm.createAssociation()); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endAssociation() + */ + public void endAssociation() throws MIOException { + _leaveStatePopConstruct(State.ASSOCIATION); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startRole() + */ + public void startRole() throws MIOException { + assert _state() == State.ASSOCIATION; + _enterState(State.ROLE, ((Association) _peekConstruct()).createAssociationRole(null, null)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endRole() + */ + public void endRole() throws MIOException { + _leaveStatePopConstruct(State.ROLE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startPlayer() + */ + public void startPlayer() throws MIOException { + assert _state() == State.ROLE; + _enterState(State.PLAYER); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endPlayer() + */ + public void endPlayer() throws MIOException { + _leaveState(State.PLAYER); + assert _state() == State.ROLE; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startOccurrence() + */ + public void startOccurrence() throws MIOException { + _enterState(State.OCCURRENCE, _peekTopic().createOccurrence((Locator) null, null, null)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endOccurrence() + */ + public void endOccurrence() throws MIOException { + _leaveStatePopConstruct(State.OCCURRENCE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startName() + */ + public void startName() throws MIOException { + _enterState(State.NAME, _peekTopic().createTopicName(null, null)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endName() + */ + public void endName() throws MIOException { + TopicName name = (TopicName) _leaveStatePopConstruct(State.NAME); + if (name.getType() == null) { + name.setType(_topicBySubjectIdentifier(TMDM.TOPIC_NAME)); + } + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startVariant() + */ + public void startVariant() throws MIOException { + assert _state() == State.NAME; + _enterState(State.VARIANT, ((TopicName) _peekConstruct()).createVariant((Locator) null, null)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endVariant() + */ + @SuppressWarnings("unchecked") + public void endVariant() throws MIOException { + Variant variant = (Variant) _leaveStatePopConstruct(State.VARIANT); + Collection<Topic> scope = variant.getScope(); + if (scope.isEmpty() || variant.getTopicName().getScope().equals(scope)) { + throw new MIOException("The variant has no scope"); + } + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startType() + */ + public void startType() throws MIOException { + assert _peekConstruct() instanceof ITyped; + _enterState(State.TYPE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endType() + */ + public void endType() throws MIOException { + _leaveState(State.TYPE); + assert _peekConstruct() instanceof ITyped; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startScope() + */ + public void startScope() throws MIOException { + assert _peekConstruct() instanceof ScopedObject; + _enterState(State.SCOPE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endScope() + */ + public void endScope() throws MIOException { + _leaveState(State.SCOPE); + assert _peekConstruct() instanceof ScopedObject; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startTheme() + */ + public void startTheme() throws MIOException { + assert _state() == State.SCOPE; + _enterState(State.THEME); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTheme() + */ + public void endTheme() throws MIOException { + _leaveState(State.THEME); + assert _state() == State.SCOPE; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#subjectIdentifier(java.lang.String) + */ + public void subjectIdentifier(String subjectIdentifier) throws MIOException { + Locator sid = _tm.createLocator(subjectIdentifier); + Topic topic = _peekTopic(); + Topic existing = _tm.getTopicBySubjectIdentifier(sid); + if (existing != null && !existing.equals(topic)) { + _merge(existing, topic); + } + else { + TopicMapObject tmo = _tm.getObjectByItemIdentifier(sid); + if (tmo != null && tmo instanceof Topic && !tmo.equals(topic)) { + _merge((Topic) tmo, topic); + } + } + topic.addSubjectIdentifier(sid); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#subjectLocator(java.lang.String) + */ + public void subjectLocator(String subjectLocator) throws MIOException { + Locator slo = _tm.createLocator(subjectLocator); + Topic topic = _peekTopic(); + Topic existing = _tm.getTopicBySubjectLocator(slo); + if (existing != null && !existing.equals(topic)) { + _merge(existing, topic); + } + topic.addSubjectLocator(slo); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#itemIdentifier(java.lang.String) + */ + public void itemIdentifier(String itemIdentifier) throws MIOException { + Locator iid = _tm.createLocator(itemIdentifier); + TopicMapObject tmo = _peekConstruct(); + if (_state() == State.TOPIC) { + TopicMapObject existing = _tm.getObjectByItemIdentifier(iid); + if (existing != null && existing instanceof Topic && !existing.equals(tmo)) { + _merge((Topic) existing, (Topic) tmo); + } + else { + Topic topic = _tm.getTopicBySubjectIdentifier(iid); + if (topic != null && !topic.equals(tmo)) { + _merge(topic, (Topic) tmo); + } + } + } + tmo.addSourceLocator(iid); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startIsa() + */ + public void startIsa() throws MIOException { + assert _state() == State.TOPIC; + _enterState(State.ISA); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endIsa() + */ + public void endIsa() throws MIOException { + _leaveState(State.ISA); + assert _state() == State.TOPIC; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startReifier() + */ + public void startReifier() throws MIOException { + assert _peekConstruct() instanceof IReifiable; + _enterState(State.REIFIER); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endReifier() + */ + public void endReifier() throws MIOException { + _leaveState(State.REIFIER); + assert _peekConstruct() instanceof IReifiable; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#topicRef(com.semagia.mio.IRef) + */ + public void topicRef(IRef identity) throws MIOException { + _handleTopic(_createTopic(identity)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#value(java.lang.String) + */ + public void value(String value) throws MIOException { + assert _state() == State.NAME; + ((TopicName) _peekConstruct()).setValue(value); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#value(java.lang.String, java.lang.String) + */ + public void value(String value, String datatype) throws MIOException { + boolean isLocator = XSD.ANY_URI.equals(datatype); + if (!isLocator && !XSD.STRING.equals(datatype)) { + LOG.warning("The datatype '" + datatype + "' was converted into xsd:string"); + } + if (_state() == State.OCCURRENCE) { + Occurrence occ = (Occurrence) _peekConstruct(); + if (isLocator) { + occ.setResource(_tm.createLocator(value)); + } + else { + occ.setValue(value); + } + } + else { + assert _state() == State.VARIANT; + Variant variant = (Variant) _peekConstruct(); + if (isLocator) { + variant.setResource(_tm.createLocator(value)); + } + else { + variant.setValue(value); + } + } + } + + /** + * Enters a state. + * + * @param state The state to push ontop of the state stack. + */ + private void _enterState(State state) { + _stateStack.add(state); + } + + /** + * Enters a state and pushes the Topic Maps construct ontop of the construct + * stack. + * + * @param state The state to enter. + * @param tmo The Topic Maps construct which should be pushed to the stack. + */ + private void _enterState(State state, TopicMapObject tmo) { + _enterState(state); + _constructStack.add(tmo); + } + + /** + * Leaves a state. + * + * @param state The state to leave. + * @throws MIOException If the state is not equals to the current state. + */ + private void _leaveState(State state) throws MIOException { + State current = _stateStack.remove(_stateStack.size()-1); + if (state != current) { + _reportError("Unexpected state: " + current + ", expected: " + state); + } + } + + /** + * Leaves a state and removed the Topic Maps construct from the top of the + * construct stack. + * + * @param state The state to leave. + * @return The removed construct. + * @throws MIOException If the state is not equals to the current state. + */ + private TopicMapObject _leaveStatePopConstruct(State state) throws MIOException { + _leaveState(state); + return _constructStack.remove(_constructStack.size()-1); + } + + /** + * Returns the Topic Maps construct on top of the stack. + * + * @return The Topic Maps construct. + */ + private TopicMapObject _peekConstruct() { + return _constructStack.get(_constructStack.size()-1); + } + + /** + * Returns the topic on top of the stack. + * + * @return The topic. + */ + private Topic _peekTopic() { + return (Topic) _peekConstruct(); + } + + /** + * Returns the current state. + * + * @return The current state. + */ + private State _state() { + return _stateStack.get(_stateStack.size()-1); + } + + /** + * Handles the topic dependent on the current state. + * + * @param topic The topic to handle. + */ + private void _handleTopic(Topic topic) { + switch (_state()) { + case ISA: _peekTopic().addType(topic); break; + case TYPE: ((ITyped) _peekConstruct()).setType(topic); break; + case PLAYER: ((AssociationRole) _peekConstruct()).setPlayer(topic); break; + case THEME: ((ScopedObject) _peekConstruct()).addScopingTopic(topic); break; + case REIFIER: ((IReifiable) _peekConstruct()).setReifier(topic); break; + } + } + + /** + * Merges the <tt>source</tt> topic with the <tt>target</tt>. + * + * Further, this method ensures that the construct stack stays valid: If + * the <tt>source</tt> is part of the stack, it is replaced with + * <tt>target</tt>. + * + * @param source The source topic (will be removed). + * @param target The target topic. + */ + private void _merge(Topic source, Topic target) { + int i = _constructStack.indexOf(source); + while (i > -1) { + _constructStack.set(i, target); + i = _constructStack.indexOf(source); + } + target.mergeIn(source); + } + + /** + * Returns either an existing topic with the specified identity or creates + * a topic with the given identity. + * + * @param ref The identity of the topic. + * @return A topic instance. + * @throws MIOException + */ + private Topic _createTopic(IRef ref) throws MIOException { + Locator loc = _tm.createLocator(ref.getIRI()); + switch (ref.getType()) { + case IRef.ITEM_IDENTIFIER: return _topicByItemIdentifier(loc); + case IRef.SUBJECT_IDENTIFIER: return _topicBySubjectIdentifier(loc); + case IRef.SUBJECT_LOCATOR: return _topicBySubjectLocator(loc); + default: _reportError("Unknown reference type " + ref.getType()); + } + // Never returned, an exception was thrown + return null; + } + + /** + * Returns either an existing topic with the specified item identfier, + * or creates a topic with the given item identifier. + * + * @param iid The item identifier of the topic. + * @return A topic instance. + */ + private Topic _topicByItemIdentifier(Locator iid) { + TopicMapObject tmo = _tm.getObjectByItemIdentifier(iid); + Topic topic = (tmo instanceof Topic) ? (Topic) tmo : null; + if (topic == null) { + topic = _tm.getTopicBySubjectIdentifier(iid); + if (topic != null) { + topic.addSourceLocator(iid); + } + } + if (topic == null) { + topic = _tm.createTopic(); + topic.addSourceLocator(iid); + } + return topic; + } + + /** + * Returns either an existing topic with the specified subject identfier, + * or creates a topic with the given subject identifier. + * + * @param sid The subject identifier of the topic. + * @return A topic instance. + */ + private Topic _topicBySubjectIdentifier(Locator sid) { + Topic topic = _tm.getTopicBySubjectIdentifier(sid); + if (topic == null) { + TopicMapObject tmo = _tm.getObjectByItemIdentifier(sid); + if (tmo instanceof Topic) { + topic = (Topic) tmo; + topic.addSubjectIdentifier(sid); + } + } + if (topic == null) { + topic = _tm.createTopic(); + topic.addSubjectIdentifier(sid); + } + return topic; + } + + /** + * Returns either an existing topic with the specified subject locator, + * or creates a topic with the given subject locator. + * + * @param slo The subject locator of the topic. + * @return A topic instance. + */ + private Topic _topicBySubjectLocator(Locator slo) { + Topic topic = _tm.getTopicBySubjectLocator(slo); + if (topic == null) { + topic = _tm.createTopic(); + topic.addSubjectLocator(slo); + } + return topic; + } + + /** + * Reports an error. + * + * @param msg The error message. + * @throws MIOException Thrown in any case. + */ + private static void _reportError(String msg) throws MIOException { + throw new MIOException(msg); + } + +} Added: tinytim/tags/release-1_5_0/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java =================================================================== --- tinytim/tags/release-1_5_0/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java (rev 0) +++ tinytim/tags/release-1_5_0/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-02 12:24:57 UTC (rev 304) @@ -0,0 +1,333 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.util.Properties; + +import org.tinytim.TinyTimTestCase; +import org.tinytim.Property; +import org.tinytim.TopicMapImpl; +import org.tinytim.voc.TMDM; +import org.tmapi.core.Locator; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMapSystem; +import org.tmapi.core.TopicMapSystemFactory; +import org.tmapi.core.TopicName; + +import com.semagia.mio.MIOException; +import com.semagia.mio.helpers.Ref; + +import junit.framework.TestCase; + +/** + * Tests against the {@link TinyTimMapInputHandler}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev: 226 $ - $Date: 2008-11-21 16:16:07 +0100 (Fr, 21 Nov 2008) $ + */ +public class TestTinyTimMapInputHandler extends TinyTimTestCase { + + private static final String _XSD_STRING = "http://www.w3.org/2001/XMLSchema#string"; + private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; + + private TinyTimMapInputHandler _handler; + + @Override + protected Properties getAdditionalProperties() { + Properties props = new Properties(); + props.setProperty(Property.XTM10_REIFICATION, "false"); + return props; + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + _handler = new TinyTimMapInputHandler(); + _handler.setTopicMap(_tm); + } + + /** + * Simple startTopicMap, followed by an endTopicMap event. + */ + public void testEmpty() throws Exception { + assertEquals(0, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + _handler.startTopicMap(); + _handler.endTopicMap(); + assertEquals(0, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + } + + /** + * Tests reifying a topic map. + */ + public void testTMReifier() throws Exception { + String itemIdent = "http://sf.net/projects/tinytim/test#1"; + assertEquals(0, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + _handler.startTopicMap(); + _handler.startReifier(); + _handler.startTopic(Ref.createItemIdentifier(itemIdent)); + _handler.endTopic(); + _handler.endReifier(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + Topic topic = (Topic) _tm.getObjectByItemIdentifier(_tm.createLocator(itemIdent)); + assertNotNull(topic); + assertNotNull(_tm.getReifier()); + assertEquals(topic, _tm.getReifier()); + } + + /** + * Tests topic creation with an item identifier. + */ + public void testTopicIdentityItemIdentifier() throws Exception { + String itemIdent = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createItemIdentifier(itemIdent)); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = (Topic) _tm.getObjectByItemIdentifier(_tm.createLocator(itemIdent)); + assertNotNull(topic); + } + + /** + * Tests topic creation with a subject identifier. + */ + public void testTopicIdentitySubjectIdentifier() throws Exception { + String subjIdent = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(subjIdent)); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(subjIdent)); + assertNotNull(topic); + } + + /** + * Tests topic creation with a subject locator. + */ + public void testTopicIdentitySubjectLocator() throws Exception { + String subjLoc = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectLocator(subjLoc)); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = _tm.getTopicBySubjectLocator(_tm.createLocator(subjLoc)); + assertNotNull(topic); + } + + /** + * Tests transparent merging. + */ + public void testTopicMerging() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String itemIdent = "http://example.org/1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + // Topic in topic event + _handler.startTopic(Ref.createItemIdentifier(itemIdent)); + _handler.itemIdentifier(ref); + _handler.endTopic(); + _handler.startOccurrence(); + _handler.value("tinyTiM", _XSD_STRING); + _handler.endOccurrence(); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + assertEquals(topic, _tm.getObjectByItemIdentifier(_tm.createLocator(ref))); + assertEquals(topic, _tm.getObjectByItemIdentifier(_tm.createLocator(itemIdent))); + assertEquals(1, topic.getOccurrences().size()); + Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); + assertEquals("tinyTiM", occ.getValue()); + } + + /** + * Tests assigning identities to a topic. + */ + public void testTopicIdentities1() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.itemIdentifier(ref); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Locator loc = _tm.createLocator(ref); + Topic topic = _tm.getTopicBySubjectIdentifier(loc); + assertNotNull(topic); + assertEquals(topic, _tm.getObjectByItemIdentifier(loc)); + } + + /** + * Tests assigning identities to a topic. + */ + public void testTopicIdentities2() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createItemIdentifier(ref)); + _handler.subjectIdentifier(ref); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Locator loc = _tm.createLocator(ref); + Topic topic = _tm.getTopicBySubjectIdentifier(loc); + assertNotNull(topic); + assertEquals(topic, _tm.getObjectByItemIdentifier(loc)); + } + + /** + * Tests reifying the topic map. + */ + public void testTopicMapReifier() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startReifier(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.endTopic(); + _handler.endReifier(); + _handler.endTopicMap(); + assertNotNull(_tm.getReifier()); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + assertEquals(topic, _tm.getReifier()); + } + + /** + * Tests occurrence creation with a value of datatype xsd:string. + */ + public void testOccurrenceValueString() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startOccurrence(); + _handler.value(val, _XSD_STRING); + _handler.endOccurrence(); + _handler.endTopic(); + _handler.endTopicMap(); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); + assertEquals(val, occ.getValue()); + } + + /** + * Tests occurrence creation with a value of datatype xsd:anyURI. + */ + public void testOccurrenceValueURI() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "http://sf.net/projects/tinytim"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startOccurrence(); + _handler.value(val, _XSD_ANY_URI); + _handler.endOccurrence(); + _handler.endTopic(); + _handler.endTopicMap(); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); + assertNull(occ.getValue()); + assertEquals(val, occ.getResource().getReference()); + } + + /** + * Tests if the name type is automatically set. + */ + public void testDefaultNameType() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startName(); + _handler.value(val); + _handler.endName(); + _handler.endTopic(); + _handler.endTopicMap(); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + TopicName name = (TopicName) topic.getTopicNames().iterator().next(); + assertEquals(val, name.getValue()); + assertNotNull(name.getType()); + assertTrue(name.getType().getSubjectIdentifiers().contains(TMDM.TOPIC_NAME)); + } + + /** + * Tests if a variant with no scope is reported as error. + */ + public void testVariantNoScopeError() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startName(); + _handler.value(val); + _handler.startVariant(); + _handler.value(val, _XSD_STRING); + try { + _handler.endVariant(); + fail("A variant with no scope shouldn't be allowed"); + } + catch (MIOException ex) { + // noop. + } + } + + /** + * Tests if a variant with a scope equals to the parent's scope is rejected. + */ + public void testVariantNoScopeError2() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String theme = "http://sf.net/projects/tinytim/test#theme"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startName(); + _handler.startScope(); + _handler.startTheme(); + _handler.topicRef(Ref.createItemIdentifier(theme)); + _handler.endTheme(); + _handler.endScope(); + _handler.value(val); + + _handler.startVariant(); + _handler.value(val, _XSD_STRING); + _handler.startScope(); + _handler.startTheme(); + _handler.topicRef(Ref.createItemIdentifier(theme)); + _handler.endTheme(); + _handler.endScope(); + try { + _handler.endVariant(); + fail("A variant with a scope equals to the parent's scope shouldn't be allowed"); + } + catch (MIOException ex) { + // noop. + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 11:48:27
|
Revision: 303 http://tinytim.svn.sourceforge.net/tinytim/?rev=303&view=rev Author: lheuer Date: 2009-07-02 11:48:24 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Added Paths: ----------- tinytim/tags/release-1_5_0/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 11:34:55
|
Revision: 302 http://tinytim.svn.sourceforge.net/tinytim/?rev=302&view=rev Author: lheuer Date: 2009-07-02 11:34:33 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Removed TinyTimMapInputHandler from 2.0 mio, updated build script, updated TMAPI Modified Paths: -------------- tinytim-mio/trunk/build.xml Added Paths: ----------- tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-20090702.jar tinytim-mio/trunk/lib/tmapi-2.0a2.jar Removed Paths: ------------- tinytim-mio/trunk/lib/tinytim-2.0.0a4.jar tinytim-mio/trunk/lib/tmapi-2.0a1.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/mio/ Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-07-02 11:27:40 UTC (rev 301) +++ tinytim-mio/trunk/build.xml 2009-07-02 11:34:33 UTC (rev 302) @@ -9,8 +9,8 @@ <property name="dir.lib" value="${basedir}/lib"/> <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> - <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a1.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a4.jar"/> + <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a2.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a5-snapshot-20090702.jar"/> <property name="lib.tinytim.tests" value="${dir.lib}/tinytim-2.0.0a4-tests.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> Deleted: tinytim-mio/trunk/lib/tinytim-2.0.0a4.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-20090702.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-20090702.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/lib/tmapi-2.0a1.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/tmapi-2.0a2.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tmapi-2.0a2.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-02 11:27:40 UTC (rev 301) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-02 11:34:33 UTC (rev 302) @@ -1,530 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.mio; - -import java.util.List; - -import org.tinytim.core.Scope; -import org.tinytim.core.value.Literal; -import org.tinytim.internal.api.IConstruct; -import org.tinytim.internal.api.IConstructFactory; -import org.tinytim.internal.api.ILiteralAware; -import org.tinytim.internal.api.IName; -import org.tinytim.internal.api.IScope; -import org.tinytim.internal.api.IScoped; -import org.tinytim.internal.api.ITopic; -import org.tinytim.internal.api.ITopicMap; -import org.tinytim.internal.api.IVariant; -import org.tinytim.internal.utils.CollectionFactory; -import org.tinytim.utils.TypeInstanceConverter; -import org.tinytim.voc.TMDM; - -import org.tmapi.core.Association; -import org.tmapi.core.Construct; -import org.tmapi.core.Locator; -import org.tmapi.core.Reifiable; -import org.tmapi.core.Role; -import org.tmapi.core.Scoped; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.Typed; - -import com.semagia.mio.IMapHandler; -import com.semagia.mio.IRef; -import com.semagia.mio.MIOException; - -/** - * Implementation of a {@link com.semagia.mio.IMapHandler} for tinyTiM. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public final class TinyTimMapInputHandler implements IMapHandler { - - private static final byte - INITIAL = 1, - TOPIC = 2, - ASSOCIATION = 3, - ROLE = 4, - OCCURRENCE = 5, - NAME = 6, - VARIANT = 7, - SCOPE = 8, - THEME = 9, - REIFIER = 10, - PLAYER = 11, - ISA = 12, - TYPE = 13; - - private static final int _CONSTRUCT_SIZE = 6; - private static final int _STATE_SIZE = 10; - private static final int _SCOPE_SIZE = 6; - - private final IConstructFactory _factory; - private final ITopicMap _tm; - private final List<Topic> _scope; - private byte[] _stateStack; - private int _stateSize; - private IConstruct[] _constructStack; - private int _constructSize; - - public TinyTimMapInputHandler(TopicMap topicMap) { - if (topicMap == null) { - throw new IllegalArgumentException("The topic map must not be null"); - } - _tm = (ITopicMap) topicMap; - _factory = _tm.getConstructFactory(); - _scope = CollectionFactory.createList(_SCOPE_SIZE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTopicMap() - */ - public void startTopicMap() throws MIOException { - _constructStack = new IConstruct[_CONSTRUCT_SIZE]; - _stateStack = new byte[_STATE_SIZE]; - _constructSize = 0; - _stateSize = 0; - _enterState(INITIAL, _tm); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTopicMap() - */ - public void endTopicMap() throws MIOException { - TypeInstanceConverter.convertAssociationsToTypes(_tm); - _constructStack = null; - _stateStack = null; - _scope.clear(); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTopic(com.semagia.mio.IRef) - */ - public void startTopic(IRef identity) throws MIOException { - _enterState(TOPIC, _createTopic(identity)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTopic() - */ - public void endTopic() throws MIOException { - _handleTopic((Topic) _leaveStatePopConstruct(TOPIC)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startAssociation() - */ - public void startAssociation() throws MIOException { - _enterState(ASSOCIATION, _factory.createAssociation()); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endAssociation() - */ - public void endAssociation() throws MIOException { - _leaveStatePopConstruct(ASSOCIATION); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startRole() - */ - public void startRole() throws MIOException { - assert _state() == ASSOCIATION; - _enterState(ROLE, _factory.createRole((Association) _peekConstruct())); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endRole() - */ - public void endRole() throws MIOException { - _leaveStatePopConstruct(ROLE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startPlayer() - */ - public void startPlayer() throws MIOException { - assert _state() == ROLE; - _enterState(PLAYER); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endPlayer() - */ - public void endPlayer() throws MIOException { - _leaveState(PLAYER); - assert _state() == ROLE; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startOccurrence() - */ - public void startOccurrence() throws MIOException { - _enterState(OCCURRENCE, _factory.createOccurrence(_peekTopic())); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endOccurrence() - */ - public void endOccurrence() throws MIOException { - _leaveStatePopConstruct(OCCURRENCE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startName() - */ - public void startName() throws MIOException { - _enterState(NAME, _factory.createName(_peekTopic())); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endName() - */ - public void endName() throws MIOException { - IName name = (IName) _leaveStatePopConstruct(NAME); - if (name.getType() == null) { - name.setType(_tm.createTopicBySubjectIdentifier(TMDM.TOPIC_NAME)); - } - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startVariant() - */ - public void startVariant() throws MIOException { - assert _state() == NAME; - _enterState(VARIANT, _factory.createVariant((IName) _peekConstruct())); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endVariant() - */ - public void endVariant() throws MIOException { - IVariant variant = (IVariant) _leaveStatePopConstruct(VARIANT); - IName name = (IName) _peekConstruct(); - IScope scope = variant.getScopeObject(); - if (scope.isUnconstrained() || name.getScopeObject().equals(scope)) { - _reportError("The variant has no scope"); - } - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startType() - */ - public void startType() throws MIOException { - assert _peekConstruct() instanceof Typed; - _enterState(TYPE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endType() - */ - public void endType() throws MIOException { - _leaveState(TYPE); - assert _peekConstruct() instanceof Typed; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startScope() - */ - public void startScope() throws MIOException { - assert _peekConstruct() instanceof Scoped; - _enterState(SCOPE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endScope() - */ - public void endScope() throws MIOException { - _leaveState(SCOPE); - ((IScoped) _peekConstruct()).setScopeObject(Scope.create(_scope)); - _scope.clear(); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTheme() - */ - public void startTheme() throws MIOException { - assert _state() == SCOPE; - _enterState(THEME); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTheme() - */ - public void endTheme() throws MIOException { - _leaveState(THEME); - assert _state() == SCOPE; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#subjectIdentifier(java.lang.String) - */ - public void subjectIdentifier(String subjectIdentifier) throws MIOException { - Locator sid = _tm.createLocator(subjectIdentifier); - ITopic topic = _peekTopic(); - Topic existing = _tm.getTopicBySubjectIdentifier(sid); - if (existing != null && !(existing.equals(topic))) { - _merge(existing, topic); - } - else { - IConstruct tmo = (IConstruct) _tm.getConstructByItemIdentifier(sid); - if (tmo != null && tmo.isTopic() && !tmo.equals(topic)) { - _merge((Topic) tmo, topic); - } - } - topic.addSubjectIdentifier(sid); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#subjectLocator(java.lang.String) - */ - public void subjectLocator(String subjectLocator) throws MIOException { - Locator slo = _tm.createLocator(subjectLocator); - ITopic topic = _peekTopic(); - Topic existing = _tm.getTopicBySubjectLocator(slo); - if (existing != null && !(existing.equals(topic))) { - _merge(existing, topic); - } - topic.addSubjectLocator(slo); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#itemIdentifier(java.lang.String) - */ - public void itemIdentifier(String itemIdentifier) throws MIOException { - Locator iid = _tm.createLocator(itemIdentifier); - IConstruct tmo = _peekConstruct(); - if (_state() == TOPIC) { - IConstruct existing = (IConstruct) _tm.getConstructByItemIdentifier(iid); - if (existing != null && existing.isTopic() && !existing.equals(tmo)) { - _merge((Topic) existing, (ITopic) tmo); - } - else { - Topic topic = _tm.getTopicBySubjectIdentifier(iid); - if (topic != null && !topic.equals(tmo)) { - _merge(topic, (ITopic) tmo); - } - } - } - tmo.addItemIdentifier(iid); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startIsa() - */ - public void startIsa() throws MIOException { - assert _state() == TOPIC; - _enterState(ISA); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endIsa() - */ - public void endIsa() throws MIOException { - _leaveState(ISA); - assert _state() == TOPIC; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startReifier() - */ - public void startReifier() throws MIOException { - assert _peekConstruct() instanceof Reifiable; - _enterState(REIFIER); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endReifier() - */ - public void endReifier() throws MIOException { - _leaveState(REIFIER); - assert _peekConstruct() instanceof Reifiable; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#topicRef(com.semagia.mio.IRef) - */ - public void topicRef(IRef identity) throws MIOException { - _handleTopic(_createTopic(identity)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#value(java.lang.String) - */ - public void value(String value) throws MIOException { - assert _state() == NAME; - ((IName) _peekConstruct()).setValue(value); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#value(java.lang.String, java.lang.String) - */ - public void value(String value, String datatype) throws MIOException { - ((ILiteralAware) _peekConstruct()).setLiteral(Literal.create(value, datatype)); - } - - /** - * Enters a state. - * - * @param state The state to push ontop of the state stack. - */ - private void _enterState(byte state) { - if (_stateSize >= _stateStack.length) { - byte[] states = new byte[_stateStack.length*2]; - System.arraycopy(_stateStack, 0, states, 0, _stateStack.length); - _stateStack = states; - } - _stateStack[_stateSize++] = state; - } - - /** - * Enters a state and pushes the Topic Maps construct ontop of the construct - * stack. - * - * @param state The state to enter. - * @param tmo The Topic Maps construct which should be pushed to the stack. - */ - private void _enterState(byte state, Construct tmo) { - _enterState(state); - if (_constructSize >= _constructStack.length) { - IConstruct[] constructs = new IConstruct[_constructStack.length*2]; - System.arraycopy(_constructStack, 0, constructs, 0, _constructStack.length); - _constructStack = constructs; - } - _constructStack[_constructSize++] = (IConstruct) tmo; - } - - /** - * Leaves a state. - * - * @param state The state to leave. - * @throws MIOException If the state is not equals to the current state. - */ - private void _leaveState(byte state) throws MIOException { - if (state != _state()) { - _reportError("Unexpected state: " + _state() + ", expected: " + state); - } - _stateSize--; - } - - /** - * Leaves a state and removed the Topic Maps construct from the top of the - * construct stack. - * - * @param state The state to leave. - * @throws MIOException If the state is not equals to the current state. - */ - private IConstruct _leaveStatePopConstruct(byte state) throws MIOException { - _leaveState(state); - final IConstruct construct = _peekConstruct(); - _constructSize--; - _constructStack[_constructSize] = null; - return construct; - } - - /** - * Returns the Topic Maps construct on top of the stack. - * - * @return The Topic Maps construct. - */ - private IConstruct _peekConstruct() { - return _constructStack[_constructSize-1]; - } - - /** - * Returns the topic on top of the stack. - * - * @return The topic. - */ - private ITopic _peekTopic() { - return (ITopic) _peekConstruct(); - } - - /** - * Returns the current state. - * - * @return The current state. - */ - private byte _state() { - return _stateStack[_stateSize-1]; - } - - /** - * Handles the topic dependent on the current state. - * - * @param topic The topic to handle. - */ - private void _handleTopic(Topic topic) { - 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; - } - } - - /** - * Merges the <tt>source</tt> topic with the <tt>target</tt>. - * - * Further, this method ensures that the construct stack stays valid: If - * the <tt>source</tt> is part of the stack, it is replaced with - * <tt>target</tt>. - * - * @param source The source topic (will be removed). - * @param target The target topic. - */ - private void _merge(Topic source, ITopic target) { - for (int i=0; i <_constructSize; i++) { - if (_constructStack[i].equals(source)) { - _constructStack[i] = target; - } - } - target.mergeIn(source); - } - - /** - * Returns either an existing topic with the specified identity or creates - * a topic with the given identity. - * - * @param ref The identity of the topic. - * @return A topic instance. - * @throws MIOException - */ - private ITopic _createTopic(IRef ref) throws MIOException { - Locator loc = _tm.createLocator(ref.getIRI()); - switch (ref.getType()) { - case IRef.ITEM_IDENTIFIER: return (ITopic) _tm.createTopicByItemIdentifier(loc); - case IRef.SUBJECT_IDENTIFIER: return (ITopic) _tm.createTopicBySubjectIdentifier(loc); - case IRef.SUBJECT_LOCATOR: return (ITopic) _tm.createTopicBySubjectLocator(loc); - default: _reportError("Unknown reference type " + ref.getType()); - } - // Never returned, an exception was thrown - return null; - } - - /** - * Reports an error. - * - * @param msg The error message. - * @throws MIOException Thrown in any case. - */ - private static void _reportError(String msg) throws MIOException { - throw new MIOException(msg); - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 11:27:55
|
Revision: 301 http://tinytim.svn.sourceforge.net/tinytim/?rev=301&view=rev Author: lheuer Date: 2009-07-02 11:27:40 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Forgot to check in modified TestTopicMapSystemFac. Done Modified Paths: -------------- tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java 2009-07-02 11:20:22 UTC (rev 300) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestTopicMapSystemFactoryImpl.java 2009-07-02 11:27:40 UTC (rev 301) @@ -33,12 +33,8 @@ * @throws Exception */ public void testDefaultFeatureValues() throws Exception { - assertTrue(_sysFactory.getFeature(Feature.NOTATION_URI)); - assertTrue(_sysFactory.getFeature(Feature.XTM_1_1)); - assertFalse(_sysFactory.getFeature(Feature.XTM_1_0)); assertFalse(_sysFactory.getFeature(Feature.READ_ONLY)); assertFalse(_sysFactory.getFeature(Feature.AUTOMERGE)); - assertFalse(_sysFactory.getFeature(Feature.TNC)); } @@ -68,18 +64,10 @@ * @throws Exception */ public void testSetFeatureValues() throws Exception { - _setFeatureToAcceptedValue(Feature.NOTATION_URI, true); - _setFeatureToUnacceptedValue(Feature.NOTATION_URI, false); - _setFeatureToAcceptedValue(Feature.XTM_1_0, false); - _setFeatureToUnacceptedValue(Feature.XTM_1_0, true); - _setFeatureToAcceptedValue(Feature.XTM_1_1, true); - _setFeatureToUnacceptedValue(Feature.XTM_1_1, false); _setFeatureToAcceptedValue(Feature.READ_ONLY, false); _setFeatureToUnacceptedValue(Feature.READ_ONLY, true); _setFeatureToAcceptedValue(Feature.AUTOMERGE, false); _setFeatureToUnacceptedValue(Feature.AUTOMERGE, true); - _setFeatureToAcceptedValue(Feature.TNC, false); - _setFeatureToUnacceptedValue(Feature.TNC, true); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 11:20:44
|
Revision: 300 http://tinytim.svn.sourceforge.net/tinytim/?rev=300&view=rev Author: lheuer Date: 2009-07-02 11:20:22 +0000 (Thu, 02 Jul 2009) Log Message: ----------- - Update to the inofficial TMAPI 2.0 a2 version - Moved TinyTimMapInputHandler into the core - Updated changes, and build.xml to reflect these changes Modified Paths: -------------- tinytim/trunk/CHANGES.txt tinytim/trunk/build.xml Added Paths: ----------- tinytim/trunk/lib/semagia-mio-0.9.4.jar tinytim/trunk/lib/tmapi-2.0a2-tests.jar tinytim/trunk/lib/tmapi-2.0a2.jar tinytim/trunk/src/main/java/org/tinytim/mio/ tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java tinytim/trunk/src/test/java/org/tinytim/mio/ tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java Removed Paths: ------------- tinytim/trunk/lib/tmapi-2.0a1-tests.jar tinytim/trunk/lib/tmapi-2.0a1.jar Modified: tinytim/trunk/CHANGES.txt =================================================================== --- tinytim/trunk/CHANGES.txt 2009-07-02 11:07:24 UTC (rev 299) +++ tinytim/trunk/CHANGES.txt 2009-07-02 11:20:22 UTC (rev 300) @@ -2,6 +2,17 @@ Changes Log =========== +2.0.0 a5 (xx.yy.2009) +--------------------- + +Bugfixes: +--------- +* Bug #2812460 -- Port the Check class from Ontopia back to + tinyTiM +* Bug #2809821 -- Ensure same topic map constraint +* + + 2.0.0 a4 (06.12.2008) --------------------- Modified: tinytim/trunk/build.xml =================================================================== --- tinytim/trunk/build.xml 2009-07-02 11:07:24 UTC (rev 299) +++ tinytim/trunk/build.xml 2009-07-02 11:20:22 UTC (rev 300) @@ -12,8 +12,9 @@ <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> <property name="lib.trove" value="${dir.lib}/trove-2.0.4.jar"/> - <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a1.jar"/> - <property name="lib.tmapi.tests" value="${dir.lib}/tmapi-2.0a1-tests.jar"/> + <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> + <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a2.jar"/> + <property name="lib.tmapi.tests" value="${dir.lib}/tmapi-2.0a2-tests.jar"/> <property name="lib.emma" value="${dir.lib}/emma.jar"/> <property name="lib.emma.task" value="${dir.lib}/emma_ant.jar"/> @@ -64,6 +65,7 @@ <pathelement location="${dir.build.classes}" /> <pathelement location="${dir.build.tests}" /> <pathelement location="${lib.junit}"/> + <pathelement location="${lib.mio}"/> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tmapi.tests}"/> <pathelement location="${lib.trove}"/> @@ -98,6 +100,7 @@ <classpath> <pathelement location="${dir.build.classes}"/> <pathelement location="${lib.junit}"/> + <pathelement location="${lib.mio}"/> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tmapi.tests}"/> <pathelement location="${lib.trove}"/> @@ -128,6 +131,7 @@ <classpath> <pathelement location="${dir.build.classes}"/> <pathelement location="${lib.junit}"/> + <pathelement location="${lib.mio}"/> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tmapi.tests}"/> <pathelement location="${lib.trove}"/> @@ -155,6 +159,7 @@ <classpath> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.trove}"/> + <pathelement location="${lib.mio}"/> </classpath> <src path="${dir.src}"/> </javac> Added: tinytim/trunk/lib/semagia-mio-0.9.4.jar =================================================================== (Binary files differ) Property changes on: tinytim/trunk/lib/semagia-mio-0.9.4.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim/trunk/lib/tmapi-2.0a1-tests.jar =================================================================== (Binary files differ) Deleted: tinytim/trunk/lib/tmapi-2.0a1.jar =================================================================== (Binary files differ) Added: tinytim/trunk/lib/tmapi-2.0a2-tests.jar =================================================================== (Binary files differ) Property changes on: tinytim/trunk/lib/tmapi-2.0a2-tests.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: tinytim/trunk/lib/tmapi-2.0a2.jar =================================================================== (Binary files differ) Property changes on: tinytim/trunk/lib/tmapi-2.0a2.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-02 11:20:22 UTC (rev 300) @@ -0,0 +1,530 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.util.List; + +import org.tinytim.core.Scope; +import org.tinytim.core.value.Literal; +import org.tinytim.internal.api.IConstruct; +import org.tinytim.internal.api.IConstructFactory; +import org.tinytim.internal.api.ILiteralAware; +import org.tinytim.internal.api.IName; +import org.tinytim.internal.api.IScope; +import org.tinytim.internal.api.IScoped; +import org.tinytim.internal.api.ITopic; +import org.tinytim.internal.api.ITopicMap; +import org.tinytim.internal.api.IVariant; +import org.tinytim.internal.utils.CollectionFactory; +import org.tinytim.utils.TypeInstanceConverter; +import org.tinytim.voc.TMDM; + +import org.tmapi.core.Association; +import org.tmapi.core.Construct; +import org.tmapi.core.Locator; +import org.tmapi.core.Reifiable; +import org.tmapi.core.Role; +import org.tmapi.core.Scoped; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.core.Typed; + +import com.semagia.mio.IMapHandler; +import com.semagia.mio.IRef; +import com.semagia.mio.MIOException; + +/** + * Implementation of a {@link com.semagia.mio.IMapHandler} for tinyTiM. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev: 267 $ - $Date: 2009-02-24 14:56:47 +0100 (Di, 24 Feb 2009) $ + */ +public final class TinyTimMapInputHandler implements IMapHandler { + + private static final byte + INITIAL = 1, + TOPIC = 2, + ASSOCIATION = 3, + ROLE = 4, + OCCURRENCE = 5, + NAME = 6, + VARIANT = 7, + SCOPE = 8, + THEME = 9, + REIFIER = 10, + PLAYER = 11, + ISA = 12, + TYPE = 13; + + private static final int _CONSTRUCT_SIZE = 6; + private static final int _STATE_SIZE = 10; + private static final int _SCOPE_SIZE = 6; + + private final IConstructFactory _factory; + private final ITopicMap _tm; + private final List<Topic> _scope; + private byte[] _stateStack; + private int _stateSize; + private IConstruct[] _constructStack; + private int _constructSize; + + public TinyTimMapInputHandler(TopicMap topicMap) { + if (topicMap == null) { + throw new IllegalArgumentException("The topic map must not be null"); + } + _tm = (ITopicMap) topicMap; + _factory = _tm.getConstructFactory(); + _scope = CollectionFactory.createList(_SCOPE_SIZE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startTopicMap() + */ + public void startTopicMap() throws MIOException { + _constructStack = new IConstruct[_CONSTRUCT_SIZE]; + _stateStack = new byte[_STATE_SIZE]; + _constructSize = 0; + _stateSize = 0; + _enterState(INITIAL, _tm); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTopicMap() + */ + public void endTopicMap() throws MIOException { + TypeInstanceConverter.convertAssociationsToTypes(_tm); + _constructStack = null; + _stateStack = null; + _scope.clear(); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startTopic(com.semagia.mio.IRef) + */ + public void startTopic(IRef identity) throws MIOException { + _enterState(TOPIC, _createTopic(identity)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTopic() + */ + public void endTopic() throws MIOException { + _handleTopic((Topic) _leaveStatePopConstruct(TOPIC)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startAssociation() + */ + public void startAssociation() throws MIOException { + _enterState(ASSOCIATION, _factory.createAssociation()); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endAssociation() + */ + public void endAssociation() throws MIOException { + _leaveStatePopConstruct(ASSOCIATION); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startRole() + */ + public void startRole() throws MIOException { + assert _state() == ASSOCIATION; + _enterState(ROLE, _factory.createRole((Association) _peekConstruct())); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endRole() + */ + public void endRole() throws MIOException { + _leaveStatePopConstruct(ROLE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startPlayer() + */ + public void startPlayer() throws MIOException { + assert _state() == ROLE; + _enterState(PLAYER); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endPlayer() + */ + public void endPlayer() throws MIOException { + _leaveState(PLAYER); + assert _state() == ROLE; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startOccurrence() + */ + public void startOccurrence() throws MIOException { + _enterState(OCCURRENCE, _factory.createOccurrence(_peekTopic())); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endOccurrence() + */ + public void endOccurrence() throws MIOException { + _leaveStatePopConstruct(OCCURRENCE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startName() + */ + public void startName() throws MIOException { + _enterState(NAME, _factory.createName(_peekTopic())); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endName() + */ + public void endName() throws MIOException { + IName name = (IName) _leaveStatePopConstruct(NAME); + if (name.getType() == null) { + name.setType(_tm.createTopicBySubjectIdentifier(TMDM.TOPIC_NAME)); + } + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startVariant() + */ + public void startVariant() throws MIOException { + assert _state() == NAME; + _enterState(VARIANT, _factory.createVariant((IName) _peekConstruct())); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endVariant() + */ + public void endVariant() throws MIOException { + IVariant variant = (IVariant) _leaveStatePopConstruct(VARIANT); + IName name = (IName) _peekConstruct(); + IScope scope = variant.getScopeObject(); + if (scope.isUnconstrained() || name.getScopeObject().equals(scope)) { + _reportError("The variant has no scope"); + } + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startType() + */ + public void startType() throws MIOException { + assert _peekConstruct() instanceof Typed; + _enterState(TYPE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endType() + */ + public void endType() throws MIOException { + _leaveState(TYPE); + assert _peekConstruct() instanceof Typed; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startScope() + */ + public void startScope() throws MIOException { + assert _peekConstruct() instanceof Scoped; + _enterState(SCOPE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endScope() + */ + public void endScope() throws MIOException { + _leaveState(SCOPE); + ((IScoped) _peekConstruct()).setScopeObject(Scope.create(_scope)); + _scope.clear(); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startTheme() + */ + public void startTheme() throws MIOException { + assert _state() == SCOPE; + _enterState(THEME); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTheme() + */ + public void endTheme() throws MIOException { + _leaveState(THEME); + assert _state() == SCOPE; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#subjectIdentifier(java.lang.String) + */ + public void subjectIdentifier(String subjectIdentifier) throws MIOException { + Locator sid = _tm.createLocator(subjectIdentifier); + ITopic topic = _peekTopic(); + Topic existing = _tm.getTopicBySubjectIdentifier(sid); + if (existing != null && !(existing.equals(topic))) { + _merge(existing, topic); + } + else { + IConstruct tmo = (IConstruct) _tm.getConstructByItemIdentifier(sid); + if (tmo != null && tmo.isTopic() && !tmo.equals(topic)) { + _merge((Topic) tmo, topic); + } + } + topic.addSubjectIdentifier(sid); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#subjectLocator(java.lang.String) + */ + public void subjectLocator(String subjectLocator) throws MIOException { + Locator slo = _tm.createLocator(subjectLocator); + ITopic topic = _peekTopic(); + Topic existing = _tm.getTopicBySubjectLocator(slo); + if (existing != null && !(existing.equals(topic))) { + _merge(existing, topic); + } + topic.addSubjectLocator(slo); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#itemIdentifier(java.lang.String) + */ + public void itemIdentifier(String itemIdentifier) throws MIOException { + Locator iid = _tm.createLocator(itemIdentifier); + IConstruct tmo = _peekConstruct(); + if (_state() == TOPIC) { + IConstruct existing = (IConstruct) _tm.getConstructByItemIdentifier(iid); + if (existing != null && existing.isTopic() && !existing.equals(tmo)) { + _merge((Topic) existing, (ITopic) tmo); + } + else { + Topic topic = _tm.getTopicBySubjectIdentifier(iid); + if (topic != null && !topic.equals(tmo)) { + _merge(topic, (ITopic) tmo); + } + } + } + tmo.addItemIdentifier(iid); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startIsa() + */ + public void startIsa() throws MIOException { + assert _state() == TOPIC; + _enterState(ISA); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endIsa() + */ + public void endIsa() throws MIOException { + _leaveState(ISA); + assert _state() == TOPIC; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startReifier() + */ + public void startReifier() throws MIOException { + assert _peekConstruct() instanceof Reifiable; + _enterState(REIFIER); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endReifier() + */ + public void endReifier() throws MIOException { + _leaveState(REIFIER); + assert _peekConstruct() instanceof Reifiable; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#topicRef(com.semagia.mio.IRef) + */ + public void topicRef(IRef identity) throws MIOException { + _handleTopic(_createTopic(identity)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#value(java.lang.String) + */ + public void value(String value) throws MIOException { + assert _state() == NAME; + ((IName) _peekConstruct()).setValue(value); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#value(java.lang.String, java.lang.String) + */ + public void value(String value, String datatype) throws MIOException { + ((ILiteralAware) _peekConstruct()).setLiteral(Literal.create(value, datatype)); + } + + /** + * Enters a state. + * + * @param state The state to push ontop of the state stack. + */ + private void _enterState(byte state) { + if (_stateSize >= _stateStack.length) { + byte[] states = new byte[_stateStack.length*2]; + System.arraycopy(_stateStack, 0, states, 0, _stateStack.length); + _stateStack = states; + } + _stateStack[_stateSize++] = state; + } + + /** + * Enters a state and pushes the Topic Maps construct ontop of the construct + * stack. + * + * @param state The state to enter. + * @param tmo The Topic Maps construct which should be pushed to the stack. + */ + private void _enterState(byte state, Construct tmo) { + _enterState(state); + if (_constructSize >= _constructStack.length) { + IConstruct[] constructs = new IConstruct[_constructStack.length*2]; + System.arraycopy(_constructStack, 0, constructs, 0, _constructStack.length); + _constructStack = constructs; + } + _constructStack[_constructSize++] = (IConstruct) tmo; + } + + /** + * Leaves a state. + * + * @param state The state to leave. + * @throws MIOException If the state is not equals to the current state. + */ + private void _leaveState(byte state) throws MIOException { + if (state != _state()) { + _reportError("Unexpected state: " + _state() + ", expected: " + state); + } + _stateSize--; + } + + /** + * Leaves a state and removed the Topic Maps construct from the top of the + * construct stack. + * + * @param state The state to leave. + * @throws MIOException If the state is not equals to the current state. + */ + private IConstruct _leaveStatePopConstruct(byte state) throws MIOException { + _leaveState(state); + final IConstruct construct = _peekConstruct(); + _constructSize--; + _constructStack[_constructSize] = null; + return construct; + } + + /** + * Returns the Topic Maps construct on top of the stack. + * + * @return The Topic Maps construct. + */ + private IConstruct _peekConstruct() { + return _constructStack[_constructSize-1]; + } + + /** + * Returns the topic on top of the stack. + * + * @return The topic. + */ + private ITopic _peekTopic() { + return (ITopic) _peekConstruct(); + } + + /** + * Returns the current state. + * + * @return The current state. + */ + private byte _state() { + return _stateStack[_stateSize-1]; + } + + /** + * Handles the topic dependent on the current state. + * + * @param topic The topic to handle. + */ + private void _handleTopic(Topic topic) { + 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; + } + } + + /** + * Merges the <tt>source</tt> topic with the <tt>target</tt>. + * + * Further, this method ensures that the construct stack stays valid: If + * the <tt>source</tt> is part of the stack, it is replaced with + * <tt>target</tt>. + * + * @param source The source topic (will be removed). + * @param target The target topic. + */ + private void _merge(Topic source, ITopic target) { + for (int i=0; i <_constructSize; i++) { + if (_constructStack[i].equals(source)) { + _constructStack[i] = target; + } + } + target.mergeIn(source); + } + + /** + * Returns either an existing topic with the specified identity or creates + * a topic with the given identity. + * + * @param ref The identity of the topic. + * @return A topic instance. + * @throws MIOException + */ + private ITopic _createTopic(IRef ref) throws MIOException { + Locator loc = _tm.createLocator(ref.getIRI()); + switch (ref.getType()) { + case IRef.ITEM_IDENTIFIER: return (ITopic) _tm.createTopicByItemIdentifier(loc); + case IRef.SUBJECT_IDENTIFIER: return (ITopic) _tm.createTopicBySubjectIdentifier(loc); + case IRef.SUBJECT_LOCATOR: return (ITopic) _tm.createTopicBySubjectLocator(loc); + default: _reportError("Unknown reference type " + ref.getType()); + } + // Never returned, an exception was thrown + return null; + } + + /** + * Reports an error. + * + * @param msg The error message. + * @throws MIOException Thrown in any case. + */ + private static void _reportError(String msg) throws MIOException { + throw new MIOException(msg); + } + +} Added: tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2009-07-02 11:20:22 UTC (rev 300) @@ -0,0 +1,368 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import org.tinytim.core.TinyTimTestCase; +import org.tinytim.voc.TMDM; +import org.tinytim.voc.XSD; +import org.tmapi.core.Locator; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Topic; + +import com.semagia.mio.IRef; +import com.semagia.mio.MIOException; +import com.semagia.mio.helpers.Ref; + +/** + * Tests against the {@link org.tinytim.mio.TinyTimMapInputHandler}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev: 209 $ - $Date: 2008-11-19 14:45:23 +0100 (Mi, 19 Nov 2008) $ + */ +public class TestTinyTimMapInputHandler extends TinyTimTestCase { + + private static final String _XSD_STRING = XSD.STRING.getReference(); + private static final String _XSD_ANY_URI = XSD.ANY_URI.getReference(); + + private TinyTimMapInputHandler _handler; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + _handler = new TinyTimMapInputHandler(_tm); + } + + 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; + handler.startTopicMap(); + handler.startTopic(Ref.createItemIdentifier(iid)); + handler.startName(); + handler.value("test"); + handler.startType(); + handler.topicRef(TOPIC_NAME); + handler.endType(); + handler.endName(); + handler.endTopic(); + handler.startTopic(Ref.createItemIdentifier(iid2)); + handler.startName(); + handler.value("a test"); + handler.startType(); + handler.topicRef(TOPIC_NAME); + handler.endType(); + handler.endName(); + handler.subjectIdentifier(TOPIC_NAME.getIRI()); + handler.endTopic(); + handler.endTopicMap(); + } + + /** + * Simple startTopicMap, followed by an endTopicMap event. + */ + public void testEmpty() throws Exception { + assertEquals(0, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + _handler.startTopicMap(); + _handler.endTopicMap(); + assertEquals(0, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + } + + /** + * Tests reifying a topic map. + */ + public void testTMReifier() throws Exception { + String itemIdent = "http://sf.net/projects/tinytim/test#1"; + assertEquals(0, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + _handler.startTopicMap(); + _handler.startReifier(); + _handler.startTopic(Ref.createItemIdentifier(itemIdent)); + _handler.endTopic(); + _handler.endReifier(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + Topic topic = (Topic) _tm.getConstructByItemIdentifier(_tm.createLocator(itemIdent)); + assertNotNull(topic); + assertNotNull(_tm.getReifier()); + assertEquals(topic, _tm.getReifier()); + } + + /** + * Tests topic creation with an item identifier. + */ + public void testTopicIdentityItemIdentifier() throws Exception { + String itemIdent = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createItemIdentifier(itemIdent)); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = (Topic) _tm.getConstructByItemIdentifier(_tm.createLocator(itemIdent)); + assertNotNull(topic); + } + + /** + * Tests topic creation with a subject identifier. + */ + public void testTopicIdentitySubjectIdentifier() throws Exception { + String subjIdent = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(subjIdent)); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(subjIdent)); + assertNotNull(topic); + } + + /** + * Tests topic creation with a subject locator. + */ + public void testTopicIdentitySubjectLocator() throws Exception { + String subjLoc = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectLocator(subjLoc)); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = _tm.getTopicBySubjectLocator(_tm.createLocator(subjLoc)); + assertNotNull(topic); + } + + /** + * Tests transparent merging. + */ + public void testTopicMerging() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String itemIdent = "http://example.org/1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + // Topic in topic event + _handler.startTopic(Ref.createItemIdentifier(itemIdent)); + _handler.itemIdentifier(ref); + _handler.endTopic(); + _handler.startOccurrence(); + _handler.value("tinyTiM", _XSD_STRING); + _handler.endOccurrence(); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + assertEquals(topic, _tm.getConstructByItemIdentifier(_tm.createLocator(ref))); + assertEquals(topic, _tm.getConstructByItemIdentifier(_tm.createLocator(itemIdent))); + assertEquals(1, topic.getOccurrences().size()); + Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); + assertEquals("tinyTiM", occ.getValue()); + } + + /** + * Tests assigning identities to a topic. + */ + public void testTopicIdentities1() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.itemIdentifier(ref); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Locator loc = _tm.createLocator(ref); + Topic topic = _tm.getTopicBySubjectIdentifier(loc); + assertNotNull(topic); + assertEquals(topic, _tm.getConstructByItemIdentifier(loc)); + } + + /** + * Tests assigning identities to a topic. + */ + public void testTopicIdentities2() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createItemIdentifier(ref)); + _handler.subjectIdentifier(ref); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Locator loc = _tm.createLocator(ref); + Topic topic = _tm.getTopicBySubjectIdentifier(loc); + assertNotNull(topic); + assertEquals(topic, _tm.getConstructByItemIdentifier(loc)); + } + + /** + * Tests reifying the topic map. + */ + public void testTopicMapReifier() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startReifier(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.endTopic(); + _handler.endReifier(); + _handler.endTopicMap(); + assertNotNull(_tm.getReifier()); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + assertEquals(topic, _tm.getReifier()); + } + + /** + * Tests occurrence creation with a value of datatype xsd:string. + */ + public void testOccurrenceValueString() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startOccurrence(); + _handler.value(val, _XSD_STRING); + _handler.endOccurrence(); + _handler.endTopic(); + _handler.endTopicMap(); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); + assertEquals(val, occ.getValue()); + assertEquals(XSD.STRING, occ.getDatatype()); + } + + /** + * Tests occurrence creation with a value of datatype xsd:anyURI. + */ + public void testOccurrenceValueURI() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "http://sf.net/projects/tinytim"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startOccurrence(); + _handler.value(val, _XSD_ANY_URI); + _handler.endOccurrence(); + _handler.endTopic(); + _handler.endTopicMap(); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); + assertEquals(val, occ.getValue()); + assertEquals(XSD.ANY_URI, occ.getDatatype()); + } + + /** + * Tests if the name type is automatically set. + */ + public void testDefaultNameType() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startName(); + _handler.value(val); + _handler.endName(); + _handler.endTopic(); + _handler.endTopicMap(); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + Name name = topic.getNames().iterator().next(); + assertEquals(val, name.getValue()); + assertNotNull(name.getType()); + assertTrue(name.getType().getSubjectIdentifiers().contains(TMDM.TOPIC_NAME)); + } + + /** + * Tests if a variant with no scope is reported as error. + */ + public void testVariantNoScopeError() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startName(); + _handler.value(val); + _handler.startVariant(); + _handler.value(val, _XSD_STRING); + try { + _handler.endVariant(); + fail("A variant with no scope shouldn't be allowed"); + } + catch (MIOException ex) { + // noop. + } + } + + /** + * Tests if a variant with a scope equals to the parent's scope is rejected. + */ + public void testVariantNoScopeError2() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String theme = "http://sf.net/projects/tinytim/test#theme"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startName(); + _handler.startScope(); + _handler.startTheme(); + _handler.topicRef(Ref.createItemIdentifier(theme)); + _handler.endTheme(); + _handler.endScope(); + _handler.value(val); + + _handler.startVariant(); + _handler.value(val, _XSD_STRING); + _handler.startScope(); + _handler.startTheme(); + _handler.topicRef(Ref.createItemIdentifier(theme)); + _handler.endTheme(); + _handler.endScope(); + try { + _handler.endVariant(); + fail("A variant with a scope equals to the parent's scope shouldn't be allowed"); + } + catch (MIOException ex) { + // noop. + } + } + + /** + * Tests nested startTopic/endTopic events. + */ + public void testNestedTopics() throws Exception { + String base = "http://tinytim.sourceforge.net/test-nesting#"; + final int MAX = 10000; + String[] iids = new String[MAX]; + _handler.startTopicMap(); + for (int i=0; i<MAX; i++) { + iids[i] = base + i; + _handler.startTopic(Ref.createItemIdentifier(iids[i])); + } + for (int i=0; i<MAX; i++) { + _handler.endTopic(); + } + _handler.endTopicMap(); + for (String iid: iids) { + assertNotNull(_tm.getConstructByItemIdentifier(createLocator(iid))); + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-05-13 15:03:12
|
Revision: 298 http://tinytim.svn.sourceforge.net/tinytim/?rev=298&view=rev Author: lheuer Date: 2009-05-13 15:02:57 +0000 (Wed, 13 May 2009) Log Message: ----------- Added missing interface Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/internal/api/IAssociation.java Added: tinytim/trunk/src/main/java/org/tinytim/internal/api/IAssociation.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/api/IAssociation.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/internal/api/IAssociation.java 2009-05-13 15:02:57 UTC (rev 298) @@ -0,0 +1,28 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.internal.api; + +import org.tmapi.core.Association; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IAssociation extends Association, IScoped { + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/internal/api/IAssociation.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-05-11 12:34:28
|
Revision: 297 http://tinytim.svn.sourceforge.net/tinytim/?rev=297&view=rev Author: lheuer Date: 2009-05-11 12:34:25 +0000 (Mon, 11 May 2009) Log Message: ----------- Fixed wrong imports in XTM10TopicMapWriter (tinyTiM 2.0) and fixed the XTM 1.0 writer of tinyTiM 1.5 (<variantName/> element was forgotten) Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2009-05-10 15:17:05 UTC (rev 296) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2009-05-11 12:34:25 UTC (rev 297) @@ -33,10 +33,10 @@ import org.tmapi.core.TopicMap; import org.tmapi.core.Typed; import org.tmapi.core.Variant; -import org.topicmap.internal.api.IScope; -import org.topicmap.internal.api.IScoped; -import org.topicmap.voc.Namespace; -import org.topicmap.voc.XSD; +import org.tinytim.internal.api.IScope; +import org.tinytim.internal.api.IScoped; +import org.tinytim.voc.Namespace; +import org.tinytim.voc.XSD; import org.xml.sax.helpers.AttributesImpl; Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java 2009-05-10 15:17:05 UTC (rev 296) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java 2009-05-11 12:34:25 UTC (rev 297) @@ -193,7 +193,9 @@ _writeTopicRef(theme); } _out.endElement("parameters"); + _out.startElement("variantName"); _writeDatatypeAware(variant); + _out.endElement("variantName"); _out.endElement("variant"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-05-10 15:17:09
|
Revision: 296 http://tinytim.svn.sourceforge.net/tinytim/?rev=296&view=rev Author: lheuer Date: 2009-05-10 15:17:05 +0000 (Sun, 10 May 2009) Log Message: ----------- Updated changes Modified Paths: -------------- tinytim-mio/trunk/CHANGES.txt Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2009-05-10 15:15:34 UTC (rev 295) +++ tinytim-mio/trunk/CHANGES.txt 2009-05-10 15:17:05 UTC (rev 296) @@ -2,7 +2,7 @@ Changes Log =========== -2.0.0 a5 (xx.03.2009) +2.0.0 a5 (xx.05.2009) --------------------- * JTMTopicMapReader / JTMTopicMapWriter implement the new JSON Topic Maps specification (<http://www.cerny-online.com/jtm/1.0/> @@ -20,6 +20,7 @@ reported by Jens Rummler * Bug #2540490 -- Using QName in isa/ako throws syntax error (CTM libs) reported by Stefan Kesberg +* XTM 1.0 writer forgot to add a <variantName/> element to the output. 2.0.0 a4 / 1.5.0 b2 (06.12.2008) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-05-10 15:15:44
|
Revision: 295 http://tinytim.svn.sourceforge.net/tinytim/?rev=295&view=rev Author: lheuer Date: 2009-05-10 15:15:34 +0000 (Sun, 10 May 2009) Log Message: ----------- Fixed XTM 1.0 syntax for variants. The <variantName/> element was not in the output. Did I ever mention that variants suck? Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2009-04-03 11:35:36 UTC (rev 294) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2009-05-10 15:15:34 UTC (rev 295) @@ -20,10 +20,6 @@ import java.util.Set; import java.util.logging.Logger; -import org.tinytim.internal.api.IScope; -import org.tinytim.internal.api.IScoped; -import org.tinytim.voc.Namespace; -import org.tinytim.voc.XSD; import org.tmapi.core.Association; import org.tmapi.core.DatatypeAware; @@ -37,6 +33,10 @@ import org.tmapi.core.TopicMap; import org.tmapi.core.Typed; import org.tmapi.core.Variant; +import org.topicmap.internal.api.IScope; +import org.topicmap.internal.api.IScoped; +import org.topicmap.voc.Namespace; +import org.topicmap.voc.XSD; import org.xml.sax.helpers.AttributesImpl; @@ -185,7 +185,9 @@ _writeTopicRef(theme); } _out.endElement("parameters"); + _out.startElement("variantName"); _writeDatatypeAware(variant); + _out.endElement("variantName"); _out.endElement("variant"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |