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...> - 2008-08-21 15:30:28
|
Revision: 144 http://tinytim.svn.sourceforge.net/tinytim/?rev=144&view=rev Author: lheuer Date: 2008-08-21 15:30:38 +0000 (Thu, 21 Aug 2008) Log Message: ----------- Small mods. TODO: This test should be part of the TMAPI test suite Modified Paths: -------------- tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java 2008-08-21 15:12:39 UTC (rev 143) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestItemIdentifierConstraint.java 2008-08-21 15:30:38 UTC (rev 144) @@ -40,11 +40,11 @@ * * @param tmo The Topic Maps construct to test. */ - private void _testConstraint(Construct tmo) throws Exception { + private void _testConstraint(final Construct tmo) { assertTrue(tmo.getItemIdentifiers().isEmpty()); - Locator iid = createLocator("http://sf.net/projects/tinytim"); - Locator iid2 = createLocator("http://sf.net/projects/tinytim2"); - Association assoc = createAssociation(); + final Locator iid = createLocator("http://sf.net/projects/tinytim"); + final Locator iid2 = createLocator("http://sf.net/projects/tinytim2"); + final Association assoc = createAssociation(); assoc.addItemIdentifier(iid); assertFalse(tmo.getItemIdentifiers().contains(iid)); try { @@ -72,16 +72,16 @@ /** * Tests against a topic map. */ - public void testTopicMap() throws Exception { + public void testTopicMap() { _testConstraint(_tm); } /** * Tests againts a topic. */ - public void testTopic() throws Exception { - Topic topic = createTopic(); - Locator iid = createLocator("http://sf.net/projects/tinytim"); + public void testTopic() { + final Topic topic = createTopic(); + final Locator iid = createLocator("http://sf.net/projects/tinytim"); topic.addItemIdentifier(iid); assertTrue(topic.getItemIdentifiers().contains(iid)); Topic topic2 = createTopic(); @@ -107,35 +107,35 @@ /** * Tests against an association. */ - public void testAssociation() throws Exception { + public void testAssociation() { _testConstraint(createAssociation()); } /** * Tests against a role. */ - public void testRole() throws Exception { + public void testRole() { _testConstraint(createRole()); } /** * Tests against an occurrence. */ - public void testOccurrence() throws Exception { + public void testOccurrence() { _testConstraint(createOccurrence()); } /** * Tests against a name. */ - public void testName() throws Exception { + public void testName() { _testConstraint(createName()); } /** * Tests against a variant. */ - public void testVariant() throws Exception { + public void testVariant() { _testConstraint(createVariant()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-21 15:12:32
|
Revision: 143 http://tinytim.svn.sourceforge.net/tinytim/?rev=143&view=rev Author: lheuer Date: 2008-08-21 15:12:39 +0000 (Thu, 21 Aug 2008) Log Message: ----------- Initial TypeInstanceConverter test. More todo Modified Paths: -------------- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java Added Paths: ----------- tinytim/trunk/src/test/java/org/tinytim/utils/TestTypeInstanceConverter.java Modified: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-08-21 14:43:03 UTC (rev 142) +++ tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-08-21 15:12:39 UTC (rev 143) @@ -22,6 +22,7 @@ import org.tinytim.utils.TestDuplicateRemovalUtils; import org.tinytim.utils.TestTopicUtils; +import org.tinytim.utils.TestTypeInstanceConverter; import junit.framework.Test; import junit.framework.TestSuite; @@ -51,6 +52,7 @@ suite.addTest(TestTMAPIIndex.suite()); suite.addTestSuite(TestTopicMapSystemFactoryImpl.class); suite.addTestSuite(TestTopicUtils.class); + suite.addTestSuite(TestTypeInstanceConverter.class); return suite; } } Added: tinytim/trunk/src/test/java/org/tinytim/utils/TestTypeInstanceConverter.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/utils/TestTypeInstanceConverter.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/utils/TestTypeInstanceConverter.java 2008-08-21 15:12:39 UTC (rev 143) @@ -0,0 +1,108 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.utils; + +import org.tinytim.core.TinyTimTestCase; +import org.tinytim.voc.TMDM; +import org.tinytim.voc.XTM10; +import org.tmapi.core.Association; +import org.tmapi.core.Locator; +import org.tmapi.core.Topic; + +/** + * Tests against the {@link TypeInstanceConverter}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestTypeInstanceConverter extends TinyTimTestCase { + + + public void testTMDMTypeInstanceAssociation() { + final Topic type = createTopic(); + final Topic instance = createTopic(); + final Association assoc = _tm.createAssociation(_createTMDMTypeInstanceTopic()); + assoc.createRole(_createTMDMTypeTopic(), type); + assoc.createRole(_createTMDMInstanceTopic(), instance); + assertEquals(1, _tm.getAssociations().size()); + assertEquals(2, _tm.getAssociations().iterator().next().getRoles().size()); + assertEquals(0, instance.getTypes().size()); + // XTM 1.0 class-instance assocs cannot be found + TypeInstanceConverter.convertXTMAssociationsToTypes(_tm); + assertEquals(1, _tm.getAssociations().size()); + assertEquals(2, _tm.getAssociations().iterator().next().getRoles().size()); + assertEquals(0, instance.getTypes().size()); + // Now remove the type-instance assocs. + TypeInstanceConverter.convertTMDMAssociationsToTypes(_tm); + assertEquals(0, _tm.getAssociations().size()); + assertEquals(1, instance.getTypes().size()); + assertTrue(instance.getTypes().contains(type)); + } + + public void testXTM10TypeInstanceAssociation() { + final Topic type = createTopic(); + final Topic instance = createTopic(); + final Association assoc = _tm.createAssociation(_createXTM10TypeInstanceTopic()); + assoc.createRole(_createXTM10TypeTopic(), type); + assoc.createRole(_createXTM10InstanceTopic(), instance); + assertEquals(1, _tm.getAssociations().size()); + assertEquals(2, _tm.getAssociations().iterator().next().getRoles().size()); + assertEquals(0, instance.getTypes().size()); + // TMDM type-instance assocs cannot be found + TypeInstanceConverter.convertTMDMAssociationsToTypes(_tm); + assertEquals(1, _tm.getAssociations().size()); + assertEquals(2, _tm.getAssociations().iterator().next().getRoles().size()); + assertEquals(0, instance.getTypes().size()); + // Now remove the class-instance assocs. + TypeInstanceConverter.convertXTMAssociationsToTypes(_tm); + assertEquals(0, _tm.getAssociations().size()); + assertEquals(1, instance.getTypes().size()); + assertTrue(instance.getTypes().contains(type)); + } + + private Topic _createTMDMTypeInstanceTopic() { + return _createTopic(TMDM.TYPE_INSTANCE); + } + + private Topic _createTMDMTypeTopic() { + return _createTopic(TMDM.TYPE); + } + + private Topic _createTMDMInstanceTopic() { + return _createTopic(TMDM.INSTANCE); + } + + private Topic _createXTM10TypeInstanceTopic() { + return _createTopic(XTM10.CLASS_INSTANCE); + } + + private Topic _createXTM10TypeTopic() { + return _createTopic(XTM10.CLASS); + } + + private Topic _createXTM10InstanceTopic() { + return _createTopic(XTM10.INSTANCE); + } + + private Topic _createTopic(final Locator loc) { + return _tm.createTopicBySubjectIdentifier(loc); + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/utils/TestTypeInstanceConverter.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...> - 2008-08-21 14:42:55
|
Revision: 142 http://tinytim.svn.sourceforge.net/tinytim/?rev=142&view=rev Author: lheuer Date: 2008-08-21 14:43:03 +0000 (Thu, 21 Aug 2008) Log Message: ----------- - More docs, Check is final, private constructor Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-08-21 14:35:44 UTC (rev 141) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-08-21 14:43:03 UTC (rev 142) @@ -35,44 +35,93 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -public class Check { +public final class Check { - private static void _reportError(Construct sender, String msg) { + private Check() { + // noop. + } + + /** + * Throws a {@link ModelConstraintException} with the specified <tt>sender</tt> + * and <tt>msg</tt> + * + * @param sender The sender + * @param msg The error message + */ + private static void _reportError(final Construct sender, final String msg) { throw new ModelConstraintException(sender, msg); } - public static void scopeNotNull(Construct sender, Topic[] scope) { + /** + * Throws a {@link ModelConstraintException} if the <tt>scope</tt> is <tt>null</tt>. + * + * @param sender The sender + * @param scope The scope array. + */ + public static void scopeNotNull(final Construct sender, final Topic[] scope) { if (scope == null) { _reportError(sender, "The scope must not be null"); } } - public static void scopeNotNull(Construct sender, Collection<Topic> scope) { + /** + * Throws a {@link ModelConstraintException} if the <tt>scope</tt> is <tt>null</tt>. + * + * @param sender The sender + * @param scope A collection. + */ + public static void scopeNotNull(final Construct sender, final Collection<Topic> scope) { if (scope == null) { _reportError(sender, "The scope must not be null"); } } - public static void typeNotNull(Construct sender, Topic type) { + /** + * Throws a {@link ModelConstraintException} if the <tt>type</tt> is <tt>null</tt>. + * + * @param sender The sender + * @param type The topic to check. + */ + public static void typeNotNull(final Construct sender, final Topic type) { if (type == null) { _reportError(sender, "The type must not be null"); } } - public static void valueNotNull(Construct sender, Object value) { + /** + * Throws a {@link ModelConstraintException} if the <tt>value</tt> is <tt>null</tt>. + * + * @param sender The sender + * @param value The value. + */ + public static void valueNotNull(final Construct sender, final Object value) { if (value == null) { _reportError(sender, "The value must not be null"); } } - public static void valueNotNull(Construct sender, Object value, Locator datatype) { + /** + * Throws a {@link ModelConstraintException} if the <tt>value</tt> or + * <tt>datatype</tt> is <tt>null</tt>. + * + * @param sender The sender + * @param value The value. + * @param datatype The locator indicating the datatype. + */ + public static void valueNotNull(final Construct sender, final Object value, Locator datatype) { valueNotNull(sender, value); if (datatype == null) { _reportError(sender, "The datatype must not be null"); } } - public static void playerNotNull(Construct sender, Topic player) { + /** + * Throws a {@link ModelConstraintException} if the <tt>player</tt> is <tt>null</tt>. + * + * @param sender The sender + * @param player The topic to check. + */ + public static void playerNotNull(final Construct sender, final Topic player) { if (player == null) { _reportError(sender, "The role player must not be null"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-21 14:35:35
|
Revision: 141 http://tinytim.svn.sourceforge.net/tinytim/?rev=141&view=rev Author: lheuer Date: 2008-08-21 14:35:44 +0000 (Thu, 21 Aug 2008) Log Message: ----------- - Added a few private constructors - Some Check docs Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-21 12:08:07 UTC (rev 140) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-21 14:35:44 UTC (rev 141) @@ -47,6 +47,10 @@ */ final class CopyUtils { + private CopyUtils() { + // noop. + } + /** * Copies the topics and associations from the <tt>source</tt> to the * <tt>target</tt> topic map. Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-21 12:08:07 UTC (rev 140) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-21 14:35:44 UTC (rev 141) @@ -34,6 +34,10 @@ private static final AtomicLong _COUNTER = new AtomicLong(); + private IdGenerator() { + // noop. + } + /** * Returns the next identifier. * Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-08-21 12:08:07 UTC (rev 140) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-08-21 14:35:44 UTC (rev 141) @@ -28,8 +28,10 @@ import org.tmapi.core.Topic; /** + * Utility class to check arguments and to throw + * {@link org.tmapi.core.ModelConstraintException}s if the arg violates a + * constraint. * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-21 12:07:59
|
Revision: 140 http://tinytim.svn.sourceforge.net/tinytim/?rev=140&view=rev Author: lheuer Date: 2008-08-21 12:08:07 +0000 (Thu, 21 Aug 2008) Log Message: ----------- Aligned version numbers in README.txt Modified Paths: -------------- tinytim/trunk/README.txt Modified: tinytim/trunk/README.txt =================================================================== --- tinytim/trunk/README.txt 2008-08-21 12:04:16 UTC (rev 139) +++ tinytim/trunk/README.txt 2008-08-21 12:08:07 UTC (rev 140) @@ -11,8 +11,8 @@ Installation ------------ -No real installation needed, simply put the ``tinytim-<VERSION>.jar`` and -``tmapi-1_0SP1.jar`` into your classpath. That's all. :) +No real installation needed, simply put the ``tinytim-2.0.0a1.jar`` and +``tmapi-2.0a1.jar`` into your classpath. That's all. :) Optionally, you can put the ``trove-<VERSION>.jar`` into your classpath which makes tinyTiM slightly more memory efficient and faster. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-21 12:04:10
|
Revision: 139 http://tinytim.svn.sourceforge.net/tinytim/?rev=139&view=rev Author: lheuer Date: 2008-08-21 12:04:16 +0000 (Thu, 21 Aug 2008) Log Message: ----------- - Updated to unofficial TMAPI 2.0 a1 - Minor tweaks - Prepared build for tinyTiM 2.0 a1 Modified Paths: -------------- tinytim/trunk/build.properties tinytim/trunk/build.xml tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java tinytim/trunk/src/main/java/org/tinytim/core/IScope.java tinytim/trunk/src/main/java/org/tinytim/core/Scope.java tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/WeakObjectRegistry.java tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java Added Paths: ----------- tinytim/trunk/lib/tmapi-2.0a1-tests.jar tinytim/trunk/lib/tmapi-2.0a1.jar tinytim/trunk/src/test/java/org/tinytim/core/TestIConstruct.java Modified: tinytim/trunk/build.properties =================================================================== --- tinytim/trunk/build.properties 2008-08-19 14:03:18 UTC (rev 138) +++ tinytim/trunk/build.properties 2008-08-21 12:04:16 UTC (rev 139) @@ -1,4 +1,4 @@ version=2.0.0 -version_suffix=alpha1 +version_suffix=a1 debug=off optimize=on Modified: tinytim/trunk/build.xml =================================================================== --- tinytim/trunk/build.xml 2008-08-19 14:03:18 UTC (rev 138) +++ tinytim/trunk/build.xml 2008-08-21 12:04:16 UTC (rev 139) @@ -27,12 +27,27 @@ <property name="dir.test" value="${basedir}/src/test/java"/> <property name="dir.lib" value="${basedir}/lib"/> <property name="dir.res" value="${basedir}/src/main/resources"/> + <property name="dir.coverage" value="${basedir}/coverage"/> <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.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> - <property name="lib.tmapi.tests" value="${dir.lib}/tmapi-test-1_0SP1.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.emma" value="${dir.lib}/emma.jar"/> + <property name="lib.emma.task" value="${dir.lib}/emma_ant.jar"/> + <!-- directory that contains emma.jar and emma_ant.jar: --> + <property name="dir.emma" value="${dir.lib}" /> + + <!-- path element used by EMMA taskdef below: --> + <path id="emma.lib" > + <pathelement location="${dir.emma}/emma.jar" /> + <pathelement location="${dir.emma}/emma_ant.jar" /> + </path> + + <!-- this loads <emma> and <emmajava> custom tasks: --> + <taskdef resource="emma_ant.properties" classpathref="emma.lib" /> + <target name="help"> <echo message="--------------------"/> <echo message="tinyTiM - Build file"/> @@ -40,9 +55,11 @@ <echo message=""/> <echo message="Available targets:"/> <echo message=""/> - <echo message=" jar Creates the jar"/> - <echo message=" doc Creates the API documentation"/> - <echo message=" release Creates the jar and a distributable file"/> + <echo message=" jar Creates the jar"/> + <echo message=" testjar Creates the jar with the tests"/> + <echo message=" doc Creates the API documentation"/> + <echo message=" coverage Creates a coverage report"/> + <echo message=" release Creates the jar and a distributable file"/> </target> <target name="init"> @@ -50,6 +67,7 @@ <property name="dist.name" value="tinytim-${dist.version}"/> <property name="tinytim.jar" value="${dist.name}.jar"/> + <property name="tinytim-test.jar" value="${dist.name}-tests.jar"/> <property name="tinytim.tar" value="${dist.name}.tar"/> <property name="tinytim.tar.gz" value="${tinytim.tar}.gz"/> <property name="tinytim.zip" value="${dist.name}.zip"/> @@ -60,6 +78,15 @@ <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"/> + + <path id="run.classpath" > + <pathelement location="${dir.build.classes}" /> + <pathelement location="${dir.build.tests}" /> + <pathelement location="${lib.junit}"/> + <pathelement location="${lib.tmapi}"/> + <pathelement location="${lib.tmapi.tests}"/> + <pathelement location="${lib.trove}"/> + </path> </target> <!-- =================================================================== --> @@ -79,9 +106,9 @@ </target> <!-- =================================================================== --> - <!-- Tests --> + <!-- Coverage Tests --> <!-- =================================================================== --> - <target name="test" depends="compile"> + <target name="coverage" depends="compile"> <mkdir dir="${dir.build.tests}"/> <javac destdir="${dir.build.tests}" debug="${debug}" @@ -96,23 +123,42 @@ </classpath> <src path="${dir.test}"/> </javac> - <junit printsummary="true" showoutput="false" - errorProperty="test.failed" failureProperty="test.failed"> + <mkdir dir="${dir.coverage}"/> + <emmajava libclasspathref="emma.lib" + sourcepath="${dir.src}" + fullmetadata="yes" + classname="org.tinytim.core.AllTests" + classpathref="run.classpath" + > + <filter includes="org.tinytim.*" excludes="org.tinytim.*Test*, org.tinytim.*$*" /> + <html outfile="${dir.coverage}/index.html" /> + </emmajava> + </target> + + <!-- =================================================================== --> + <!-- Tests --> + <!-- =================================================================== --> + <target name="test" depends="compile"> + <mkdir dir="${dir.build.tests}"/> + <javac destdir="${dir.build.tests}" + debug="${debug}" + optimize="${optimize}" + target="1.5"> <classpath> <pathelement location="${dir.build.classes}"/> - <pathelement location="${dir.build.tests}"/> <pathelement location="${lib.junit}"/> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tmapi.tests}"/> <pathelement location="${lib.trove}"/> </classpath> + <src path="${dir.test}"/> + </javac> + <junit printsummary="true" showoutput="false" + errorProperty="test.failed" failureProperty="test.failed" + fork="true"> + <classpath refid="run.classpath"/> <formatter type="brief" usefile="false"/> - <batchtest fork="no" todir="${dir.build}"> - <fileset dir="${dir.build.tests}/"> - <include name="**/Test**.class"/> - <exclude name="**/Test*$**.class"/> - </fileset> - </batchtest> + <test name="org.tinytim.core.AllTests"/> </junit> <fail message="Tests failed. Check test output." if="test.failed"/> </target> @@ -147,15 +193,16 @@ windowtitle="tinyTiM API v${dist.version}" doctitle="tinyTiM API v${dist.version}"> <fileset dir="${dir.src}"> - <exclude name="**/*Impl.*"/> + <exclude name="org/tinytim/core/**"/> <exclude name="org/tinytim/index/**"/> - <exclude name="org/tinytim/IConstruct*"/> - <exclude name="org/tinytim/IDatatypeAware*"/> - <exclude name="org/tinytim/IRI*"/> - <exclude name="org/tinytim/IEvent*"/> - <exclude name="org/tinytim/Event*"/> + <exclude name="org/tinytim/internal/**"/> </fileset> - <link href="http://www.tmapi.org/apiDocs/"/> +<!-- + <doclet name="net.gleamynode.apiviz.APIviz" + path="${dir.lib}/apiviz-1.1.3.jar"> + </doclet> +--> + <link href="http://www.tmapi.org/2.0/api/"/> </javadoc> </target> @@ -179,12 +226,29 @@ </target> <!-- =================================================================== --> + <!-- Creates the test jar --> + <!-- =================================================================== --> + <target name="testjar" depends="compile, test"> + <jar destfile="${dir.build}/${tinytim-test.jar}"> + <fileset dir="${dir.build.tests}"> + <include name="**/*.*"/> + </fileset> + <manifest> + <attribute name="Implementation-Title" value="tinyTiM Tests"/> + <attribute name="Implementation-Version" value="${dist.version}"/> + <attribute name="Implementation-URL" value="http://sourceforge.net/projects/tinytim"/> + </manifest> + </jar> + </target> + + <!-- =================================================================== --> <!-- Prepares a distribution --> <!-- =================================================================== --> - <target name="dist" depends="jar, doc"> + <target name="dist" depends="jar, testjar, doc"> <mkdir dir="${dir.dist}"/> <copy todir="${dir.dist}" file="${dir.build}/${tinytim.jar}"/> + <copy todir="${dir.dist}" file="${dir.build}/${tinytim-test.jar}"/> <copy todir="${dir.dist}/src"> <fileset dir="${dir.src}"/> @@ -193,7 +257,12 @@ <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="LICENSE.junit*"/> + <include name="LICENSE.tmapi*"/> + </fileset> </copy> <copy todir="${dir.dist}" file="CHANGES.txt"/> Property changes on: tinytim/trunk/lib/tmapi-2.0a1-tests.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Property changes on: tinytim/trunk/lib/tmapi-2.0a1.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-19 14:03:18 UTC (rev 138) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-21 12:04:16 UTC (rev 139) @@ -116,7 +116,7 @@ */ @Override public final int hashCode() { - return _id.hashCode(); + return super.hashCode(); } /** Modified: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-08-19 14:03:18 UTC (rev 138) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-08-21 12:04:16 UTC (rev 139) @@ -20,6 +20,7 @@ */ package org.tinytim.core; +import java.util.Collection; import java.util.Set; import org.tmapi.core.Topic; @@ -83,4 +84,6 @@ */ public int size(); + public boolean containsAll(Collection<Topic> scope); + } Modified: tinytim/trunk/src/main/java/org/tinytim/core/Scope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-08-19 14:03:18 UTC (rev 138) +++ tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-08-21 12:04:16 UTC (rev 139) @@ -99,6 +99,13 @@ } /* (non-Javadoc) + * @see org.tinytim.core.IScope#containsAll(java.util.Collection) + */ + public boolean containsAll(Collection<Topic> scope) { + return _set.containsAll(scope); + } + + /* (non-Javadoc) * @see org.tinytim.core.IScope#add(org.tmapi.core.Topic) */ public IScope add(Topic theme) { Modified: tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java 2008-08-19 14:03:18 UTC (rev 138) +++ tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java 2008-08-21 12:04:16 UTC (rev 139) @@ -87,6 +87,9 @@ */ public Collection<Association> getAssociations(Topic[] themes, boolean matchAll) { + if (themes == null) { + throw new IllegalArgumentException("The themes must not be null"); + } Set<Association> result = CollectionFactory.createIdentitySet(); if (!matchAll) { for (Topic theme: themes) { @@ -125,6 +128,9 @@ */ public Collection<Occurrence> getOccurrences(Topic[] themes, boolean matchAll) { + if (themes == null) { + throw new IllegalArgumentException("The themes must not be null"); + } Set<Occurrence> result = CollectionFactory.createIdentitySet(); if (!matchAll) { for (Topic theme: themes) { @@ -162,6 +168,9 @@ * @see org.tmapi.index.ScopedIndex#getNames(org.tmapi.core.Topic[], boolean) */ public Collection<Name> getNames(Topic[] themes, boolean matchAll) { + if (themes == null) { + throw new IllegalArgumentException("The themes must not be null"); + } Set<Name> result = CollectionFactory.createIdentitySet(); if (!matchAll) { for (Topic theme: themes) { @@ -190,6 +199,9 @@ * @see org.tmapi.index.ScopedIndex#getVariants(org.tmapi.core.Topic) */ public Collection<Variant> getVariants(Topic theme) { + if (theme == null) { + throw new IllegalArgumentException("The theme must not be null"); + } Collection<Variant> vars = _theme2Variants.get(theme); return vars == null ? Collections.<Variant>emptySet() : CollectionFactory.createList(vars); @@ -199,6 +211,9 @@ * @see org.tmapi.index.ScopedIndex#getVariants(org.tmapi.core.Topic[], boolean) */ public Collection<Variant> getVariants(Topic[] themes, boolean matchAll) { + if (themes == null) { + throw new IllegalArgumentException("The themes must not be null"); + } Set<Variant> result = CollectionFactory.createIdentitySet(); if (!matchAll) { for (Topic theme: themes) { Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-08-19 14:03:18 UTC (rev 138) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-08-21 12:04:16 UTC (rev 139) @@ -31,7 +31,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class Check { Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/WeakObjectRegistry.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/WeakObjectRegistry.java 2008-08-19 14:03:18 UTC (rev 138) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/WeakObjectRegistry.java 2008-08-21 12:04:16 UTC (rev 139) @@ -21,8 +21,6 @@ package org.tinytim.internal.utils; import java.lang.ref.WeakReference; -import java.util.AbstractSet; -import java.util.Iterator; import java.util.Map; import java.util.WeakHashMap; @@ -32,7 +30,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -public final class WeakObjectRegistry<E> extends AbstractSet<E> { +public final class WeakObjectRegistry<E> { private final Map<E, WeakReference<E>> _obj2Ref; @@ -60,7 +58,6 @@ /* (non-Javadoc) * @see java.util.AbstractCollection#add(java.lang.Object) */ - @Override public boolean add(E obj) { WeakReference<E> ref = new WeakReference<E>(obj); ref = _obj2Ref.put(obj, ref); @@ -68,42 +65,15 @@ } /* (non-Javadoc) - * @see java.util.AbstractCollection#remove(java.lang.Object) - */ - @Override - public boolean remove(Object obj) { - WeakReference<E> ref = _obj2Ref.remove(obj); - return ref != null && ref.get() != null; - } - - /* (non-Javadoc) * @see java.util.AbstractCollection#clear() */ - @Override public void clear() { _obj2Ref.clear(); } /* (non-Javadoc) - * @see java.util.AbstractCollection#contains(java.lang.Object) - */ - @Override - public boolean contains(Object obj) { - return get(obj) != null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#iterator() - */ - @Override - public Iterator<E> iterator() { - return _obj2Ref.keySet().iterator(); - } - - /* (non-Javadoc) * @see java.util.AbstractCollection#size() */ - @Override public int size() { return _obj2Ref.size(); } Modified: tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-08-19 14:03:18 UTC (rev 138) +++ tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java 2008-08-21 12:04:16 UTC (rev 139) @@ -42,6 +42,7 @@ TestSuite suite = new TestSuite(); suite.addTestSuite(TestDuplicateRemovalUtils.class); suite.addTestSuite(TestIRI.class); + suite.addTestSuite(TestIConstruct.class); suite.addTestSuite(TestScope.class); suite.addTestSuite(TestLiteral.class); suite.addTestSuite(TestItemIdentifierConstraint.class); Added: tinytim/trunk/src/test/java/org/tinytim/core/TestIConstruct.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestIConstruct.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestIConstruct.java 2008-08-21 12:04:16 UTC (rev 139) @@ -0,0 +1,79 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.Association; +import org.tmapi.core.Construct; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.core.Variant; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestIConstruct extends TinyTimTestCase { + + + private void _testConstruct(Construct construct) { + IConstruct c = (IConstruct) construct; + assertEquals(c.isTopicMap(), c instanceof TopicMap); + assertEquals(c.isTopic(), c instanceof Topic); + assertEquals(c.isAssociation(), c instanceof Association); + assertEquals(c.isRole(), c instanceof Role); + assertEquals(c.isOccurrence(), c instanceof Occurrence); + assertEquals(c.isName(), c instanceof Name); + assertEquals(c.isVariant(), c instanceof Variant); + } + + public void testTopicMap() { + _testConstruct(_tm); + } + + public void testTopic() { + _testConstruct(createTopic()); + } + + public void testAssociation() { + _testConstruct(createAssociation()); + } + + public void testRole() { + _testConstruct(createRole()); + } + + public void testOccurrence() { + _testConstruct(createOccurrence()); + } + + public void testName() { + _testConstruct(createName()); + } + + public void testVariant() { + _testConstruct(createVariant()); + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/core/TestIConstruct.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...> - 2008-08-19 14:03:09
|
Revision: 138 http://tinytim.svn.sourceforge.net/tinytim/?rev=138&view=rev Author: lheuer Date: 2008-08-19 14:03:18 +0000 (Tue, 19 Aug 2008) Log Message: ----------- Initial doc import Added Paths: ----------- website/ website/trunk/ website/trunk/1.5/ website/trunk/1.5/source/ website/trunk/1.5/source/_static/ website/trunk/1.5/source/_static/default.css website/trunk/1.5/source/_templates/ website/trunk/1.5/source/conf.py website/trunk/1.5/source/index.txt website/trunk/1.5/source/mio/ website/trunk/1.5/source/mio/index.txt website/trunk/1.5/source/mio/topicmaps-export.txt website/trunk/1.5/source/mio/topicmaps-import.txt website/trunk/1.5/source/quickstart.txt website/trunk/2.0/ website/trunk/2.0/source/ website/trunk/2.0/source/_static/ website/trunk/2.0/source/_static/default.css website/trunk/2.0/source/_templates/ website/trunk/2.0/source/conf.py website/trunk/2.0/source/index.txt website/trunk/2.0/source/mio/ website/trunk/2.0/source/mio/index.txt website/trunk/2.0/source/mio/topicmaps-export.txt website/trunk/2.0/source/mio/topicmaps-import.txt website/trunk/2.0/source/quickstart.txt Added: website/trunk/1.5/source/_static/default.css =================================================================== --- website/trunk/1.5/source/_static/default.css (rev 0) +++ website/trunk/1.5/source/_static/default.css 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,838 @@ +/** + * Sphinx Doc Design + */ + +body { + font-family: sans-serif; + font-size: 100%; + background-color: #FFF; + color: #000; + margin: 0; + padding: 0; +} + +.field-list { + font-size: 68%; + color: #666; +} + +/* :::: LAYOUT :::: */ + +div.document { + background-color: #FFF; +} + +div.documentwrapper { + float: left; + width: 100%; +} + +div.bodywrapper { + margin: 0 0 0 230px; +} + +div.body { + background-color: white; + padding: 0 20px 30px 20px; +} + +div.sphinxsidebarwrapper { + padding: 10px 5px 0 10px; +} + +div.sphinxsidebar { + float: left; + width: 230px; + margin-left: -100%; + font-size: 90%; +} + +div.clearer { + clear: both; +} + +div.footer { + color: #666; + width: 100%; + padding: 9px 0 9px 0; + text-align: center; + font-size: 75%; +} + +div.footer a { + color: #666; + text-decoration: underline; +} + +div.related { + background-color: #fff; + color: #666; + width: 100%; + height: 30px; + line-height: 30px; + font-size: 90%; +} + +div.related h3 { + display: none; +} + +div.related ul { + margin: 0; + padding: 0 0 0 10px; + list-style: none; +} + +div.related li { + display: inline; +} + +div.related li.right { + float: right; + margin-right: 5px; +} + +div.related a { + color: #666; +} + +/* ::: TOC :::: */ +div.sphinxsidebar h3 { + font-family: 'Trebuchet MS', sans-serif; + color: white; + font-size: 1.4em; + font-weight: normal; + margin: 0; + padding: 0; +} + +div.sphinxsidebar h4 { + font-family: 'Trebuchet MS', sans-serif; + color: white; + font-size: 1.3em; + font-weight: normal; + margin: 5px 0 0 0; + padding: 0; +} + +div.sphinxsidebar p { + color: white; +} + +div.sphinxsidebar p.topless { + margin: 5px 10px 10px 10px; +} + +div.sphinxsidebar ul { + margin: 10px; + padding: 0; + list-style: none; + color: white; +} + +div.sphinxsidebar ul ul, +div.sphinxsidebar ul.want-points { + margin-left: 20px; + list-style: square; +} + +div.sphinxsidebar ul ul { + margin-top: 0; + margin-bottom: 0; +} + +div.sphinxsidebar a { + color: #666; +} + +div.sphinxsidebar form { + margin-top: 10px; +} + +div.sphinxsidebar input { + border: 1px solid #98dbcc; + font-family: sans-serif; + font-size: 1em; +} + +/* :::: MODULE CLOUD :::: */ +div.modulecloud { + margin: -5px 10px 5px 10px; + padding: 10px; + line-height: 160%; + border: 1px solid #cbe7e5; + background-color: #f2fbfd; +} + +div.modulecloud a { + padding: 0 5px 0 5px; +} + +/* :::: SEARCH :::: */ +ul.search { + margin: 10px 0 0 20px; + padding: 0; +} + +ul.search li { + padding: 5px 0 5px 20px; + background-image: url(file.png); + background-repeat: no-repeat; + background-position: 0 7px; +} + +ul.search li a { + font-weight: bold; +} + +ul.search li div.context { + color: #888; + margin: 2px 0 0 30px; + text-align: left; +} + +ul.keywordmatches li.goodmatch a { + font-weight: bold; +} + +/* :::: COMMON FORM STYLES :::: */ + +div.actions { + padding: 5px 10px 5px 10px; + border-top: 1px solid #666; + border-bottom: 1px solid #666; + background-color: #e0f6f4; +} + +form dl { + color: #333; +} + +form dt { + clear: both; + float: left; + min-width: 110px; + margin-right: 10px; + padding-top: 2px; +} + +input#homepage { + display: none; +} + +div.error { + margin: 5px 20px 0 0; + padding: 5px; + border: 1px solid #d00; + font-weight: bold; +} + +/* :::: INLINE COMMENTS :::: */ + +div.inlinecomments { + position: absolute; + right: 20px; +} + +div.inlinecomments a.bubble { + display: block; + float: right; + background-image: url(style/comment.png); + background-repeat: no-repeat; + width: 25px; + height: 25px; + text-align: center; + padding-top: 3px; + font-size: 0.9em; + line-height: 14px; + font-weight: bold; + color: black; +} + +div.inlinecomments a.bubble span { + display: none; +} + +div.inlinecomments a.emptybubble { + background-image: url(style/nocomment.png); +} + +div.inlinecomments a.bubble:hover { + background-image: url(style/hovercomment.png); + text-decoration: none; + color: #3ca0a4; +} + +div.inlinecomments div.comments { + float: right; + margin: 25px 5px 0 0; + max-width: 50em; + min-width: 30em; + border: 1px solid #2eabb0; + background-color: #f2fbfd; + z-index: 150; +} + +div#comments { + border: 1px solid #2eabb0; + margin-top: 20px; +} + +div#comments div.nocomments { + padding: 10px; + font-weight: bold; +} + +div.inlinecomments div.comments h3, +div#comments h3 { + margin: 0; + padding: 0; + background-color: #2eabb0; + color: white; + border: none; + padding: 3px; +} + +div.inlinecomments div.comments div.actions { + padding: 4px; + margin: 0; + border-top: none; +} + +div#comments div.comment { + margin: 10px; + border: 1px solid #2eabb0; +} + +div.inlinecomments div.comment h4, +div.commentwindow div.comment h4, +div#comments div.comment h4 { + margin: 10px 0 0 0; + background-color: #2eabb0; + color: white; + border: none; + padding: 1px 4px 1px 4px; +} + +div#comments div.comment h4 { + margin: 0; +} + +div#comments div.comment h4 a { + color: #d5f4f4; +} + +div.inlinecomments div.comment div.text, +div.commentwindow div.comment div.text, +div#comments div.comment div.text { + margin: -5px 0 -5px 0; + padding: 0 10px 0 10px; +} + +div.inlinecomments div.comment div.meta, +div.commentwindow div.comment div.meta, +div#comments div.comment div.meta { + text-align: right; + padding: 2px 10px 2px 0; + font-size: 95%; + color: #538893; + border-top: 1px solid #cbe7e5; + background-color: #e0f6f4; +} + +div.commentwindow { + position: absolute; + width: 500px; + border: 1px solid #cbe7e5; + background-color: #f2fbfd; + display: none; + z-index: 130; +} + +div.commentwindow h3 { + margin: 0; + background-color: #2eabb0; + color: white; + border: none; + padding: 5px; + font-size: 1.5em; + cursor: pointer; +} + +div.commentwindow div.actions { + margin: 10px -10px 0 -10px; + padding: 4px 10px 4px 10px; + color: #538893; +} + +div.commentwindow div.actions input { + border: 1px solid #2eabb0; + background-color: white; + color: #135355; + cursor: pointer; +} + +div.commentwindow div.form { + padding: 0 10px 0 10px; +} + +div.commentwindow div.form input, +div.commentwindow div.form textarea { + border: 1px solid #3c9ea2; + background-color: white; + color: black; +} + +div.commentwindow div.error { + margin: 10px 5px 10px 5px; + background-color: #fbe5dc; + display: none; +} + +div.commentwindow div.form textarea { + width: 99%; +} + +div.commentwindow div.preview { + margin: 10px 0 10px 0; + background-color: #70d0d4; + padding: 0 1px 1px 25px; +} + +div.commentwindow div.preview h4 { + margin: 0 0 -5px -20px; + padding: 4px 0 0 4px; + color: white; + font-size: 1.3em; +} + +div.commentwindow div.preview div.comment { + background-color: #f2fbfd; +} + +div.commentwindow div.preview div.comment h4 { + margin: 10px 0 0 0!important; + padding: 1px 4px 1px 4px!important; + font-size: 1.2em; +} + +/* :::: SUGGEST CHANGES :::: */ +div#suggest-changes-box input, div#suggest-changes-box textarea { + border: 1px solid #ccc; + background-color: white; + color: black; +} + +div#suggest-changes-box textarea { + width: 99%; + height: 400px; +} + + +/* :::: PREVIEW :::: */ +div.preview { + background-image: url(style/preview.png); + padding: 0 20px 20px 20px; + margin-bottom: 30px; +} + + +/* :::: INDEX PAGE :::: */ + +table.contentstable { + width: 90%; +} + +table.contentstable p.biglink { + line-height: 150%; +} + +a.biglink { + font-size: 1.3em; +} + +span.linkdescr { + font-style: italic; + padding-top: 5px; + font-size: 90%; +} + +/* :::: INDEX STYLES :::: */ + +table.indextable td { + text-align: left; + vertical-align: top; +} + +table.indextable dl, table.indextable dd { + margin-top: 0; + margin-bottom: 0; +} + +table.indextable tr.pcap { + height: 10px; +} + +table.indextable tr.cap { + margin-top: 10px; + background-color: #f2f2f2; +} + +img.toggler { + margin-right: 3px; + margin-top: 3px; + cursor: pointer; +} + +form.pfform { + margin: 10px 0 20px 0; +} + +/* :::: GLOBAL STYLES :::: */ + +.docwarning { + background-color: #ffe4e4; + padding: 10px; + margin: 0 -20px 0 -20px; + border-bottom: 1px solid #f66; +} + +p.subhead { + font-weight: bold; + margin-top: 20px; +} + +a { + color: #355f7c; + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + +div.body h1, +div.body h2, +div.body h3, +div.body h4, +div.body h5, +div.body h6 { + font-family: 'Trebuchet MS', sans-serif; + background-color: #f2f2f2; + font-weight: normal; + color: #20435c; + border-bottom: 1px solid #ccc; + margin: 20px -20px 10px -20px; + padding: 3px 0 3px 10px; +} + +div.body h1 { margin-top: 0; font-size: 200%; } +div.body h2 { font-size: 160%; } +div.body h3 { font-size: 140%; } +div.body h4 { font-size: 120%; } +div.body h5 { font-size: 110%; } +div.body h6 { font-size: 100%; } + +a.headerlink { + color: #c60f0f; + font-size: 0.8em; + padding: 0 4px 0 4px; + text-decoration: none; + visibility: hidden; +} + +h1:hover > a.headerlink, +h2:hover > a.headerlink, +h3:hover > a.headerlink, +h4:hover > a.headerlink, +h5:hover > a.headerlink, +h6:hover > a.headerlink, +dt:hover > a.headerlink { + visibility: visible; +} + +a.headerlink:hover { + background-color: #c60f0f; + color: white; +} + +div.body p, div.body dd, div.body li { + text-align: justify; + line-height: 130%; +} + +div.body p.caption { + text-align: inherit; +} + +div.body td { + text-align: left; +} + +ul.fakelist { + list-style: none; + margin: 10px 0 10px 20px; + padding: 0; +} + +.field-list ul { + padding-left: 1em; +} + +.first { + margin-top: 0 !important; +} + +/* "Footnotes" heading */ +p.rubric { + margin-top: 30px; + font-weight: bold; +} + +/* "Topics" */ + +div.topic { + background-color: #eee; + border: 1px solid #ccc; + padding: 0 7px 0 7px; + margin: 10px 0 10px 0; +} + +p.topic-title { + font-size: 1.1em; + font-weight: bold; + margin-top: 10px; +} + +/* Admonitions */ + +div.admonition { + margin-top: 10px; + margin-bottom: 10px; + padding: 7px; +} + +div.admonition dt { + font-weight: bold; +} + +div.admonition dl { + margin-bottom: 0; +} + +div.admonition p { + display: inline; +} + +div.seealso { + background-color: #ffc; + border: 1px solid #ff6; +} + +div.warning { + background-color: #ffe4e4; + border: 1px solid #f66; +} + +div.note { + background-color: #eee; + border: 1px solid #ccc; +} + +p.admonition-title { + margin: 0px 10px 5px 0px; + font-weight: bold; + display: inline; +} + +p.admonition-title:after { + content: ":"; +} + +div.body p.centered { + text-align: center; + margin-top: 25px; +} + +table.docutils { + border: 0; +} + +table.docutils td, table.docutils th { + padding: 1px 8px 1px 0; + border-top: 0; + border-left: 0; + border-right: 0; + border-bottom: 1px solid #aaa; +} + +table.field-list td, table.field-list th { + border: 0 !important; +} + +table.footnote td, table.footnote th { + border: 0 !important; +} + +.field-list ul { + margin: 0; + padding-left: 1em; +} + +.field-list p { + margin: 0; +} + +dl { + margin-bottom: 15px; + clear: both; +} + +dd p { + margin-top: 0px; +} + +dd ul, dd table { + margin-bottom: 10px; +} + +dd { + margin-top: 3px; + margin-bottom: 10px; + margin-left: 30px; +} + +.refcount { + color: #060; +} + +dt:target, +.highlight { + background-color: #eee; +} + +dl.glossary dt { + font-weight: bold; + font-size: 1.1em; +} + +th { + text-align: left; + padding-right: 5px; +} + +pre { + padding: 5px; + background-color: #fefefe; + color: #333; + border: 1px solid #EEE; + border-left: none; + border-right: none; + overflow: auto; +} + +td.linenos pre { + padding: 5px 0px; + border: 0; + background-color: transparent; + color: #aaa; +} + +table.highlighttable { + margin-left: 0.5em; +} + +table.highlighttable td { + padding: 0 0.5em 0 0.5em; +} + +tt { + background-color: #ecf0f3; + padding: 0 1px 0 1px; + font-size: 0.95em; +} + +tt.descname { + background-color: transparent; + font-weight: bold; + font-size: 1.2em; +} + +tt.descclassname { + background-color: transparent; +} + +tt.xref, a tt { + background-color: transparent; + font-weight: bold; +} + +.footnote:target { background-color: #ffa } + +h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt { + background-color: transparent; +} + +.optional { + font-size: 1.3em; +} + +.versionmodified { + font-style: italic; +} + +form.comment { + margin: 0; + padding: 10px 30px 10px 30px; + background-color: #eee; +} + +form.comment h3 { + background-color: #326591; + color: white; + margin: -10px -30px 10px -30px; + padding: 5px; + font-size: 1.4em; +} + +form.comment input, +form.comment textarea { + border: 1px solid #ccc; + padding: 2px; + font-family: sans-serif; + font-size: 100%; +} + +form.comment input[type="text"] { + width: 240px; +} + +form.comment textarea { + width: 100%; + height: 200px; + margin-bottom: 10px; +} + +.system-message { + background-color: #fda; + padding: 5px; + border: 3px solid red; +} + +/* :::: PRINT :::: */ +@media print { + div.document, + div.documentwrapper, + div.bodywrapper { + margin: 0; + width : 100%; + } + + div.sphinxsidebar, + div.related, + div.footer, + div#comments div.new-comment-box, + #top-link { + display: none; + } +} Added: website/trunk/1.5/source/conf.py =================================================================== --- website/trunk/1.5/source/conf.py (rev 0) +++ website/trunk/1.5/source/conf.py 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,178 @@ +# -*- coding: utf-8 -*- +# +# tinyTiM documentation build configuration file, created by +# sphinx-quickstart on Sun Aug 17 19:14:56 2008. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# The contents of this file are pickled, so don't put values in the namespace +# that aren't pickleable (module imports are okay, they're removed automatically). +# +# All configuration values have a default value; values that are commented out +# serve to show the default value. + +import sys, os + +# If your extensions are in another directory, add it here. If the directory +# is relative to the documentation root, use os.path.abspath to make it +# absolute, like shown here. +#sys.path.append(os.path.abspath('some/directory')) + +# General configuration +# --------------------- + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = [] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.txt' + +# The master toctree document. +master_doc = 'index' + +# General substitutions. +project = 'tinyTiM' +copyright = '2008, tinyTiM project' + +# The default replacements for |version| and |release|, also used in various +# other places throughout the built documents. +# +# The short X.Y version. +version = '1.5' +# The full version, including alpha/beta/rc tags. +release = '1.5' + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +today_fmt = '%B %d, %Y' + +# List of documents that shouldn't be included in the build. +#unused_docs = [] + +# List of directories, relative to source directories, that shouldn't be searched +# for source files. +#exclude_dirs = [] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'emacs' + + +# Options for HTML output +# ----------------------- + +# The style sheet to use for HTML and HTML Help pages. A file of that name +# must exist either in Sphinx' static/ path, or in one of the custom paths +# given in html_static_path. +html_style = 'default.css' + +# The name for this set of Sphinx documents. If None, it defaults to +# "<project> v<release> documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (within the static path) to place at the top of +# the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +html_use_modindex = False + +# If false, no index is generated. +html_use_index = False + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, the reST sources are included in the HTML build as _sources/<name>. +html_copy_source = False + +# If true, an OpenSearch description file will be output, and all pages will +# contain a <link> tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = '' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'tinyTiMdoc' + + +# Options for LaTeX output +# ------------------------ + +# The paper size ('letter' or 'a4'). +#latex_paper_size = 'letter' + +# The font size ('10pt', '11pt' or '12pt'). +#latex_font_size = '10pt' + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, document class [howto/manual]). +latex_documents = [ + ('index', 'tinyTiM.tex', 'tinyTiM Documentation', 'tinyTiM project', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# Additional stuff for the LaTeX preamble. +#latex_preamble = '' + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_use_modindex = True Added: website/trunk/1.5/source/index.txt =================================================================== --- website/trunk/1.5/source/index.txt (rev 0) +++ website/trunk/1.5/source/index.txt 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,10 @@ +Documentation +============= + +Contents: + +.. toctree:: + :maxdepth: 2 + + quickstart + mio/index Added: website/trunk/1.5/source/mio/index.txt =================================================================== --- website/trunk/1.5/source/mio/index.txt (rev 0) +++ website/trunk/1.5/source/mio/index.txt 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,18 @@ +Importing and Exporting Topic Maps +================================== + +:Author: Lars Heuer (heuer[at]semagia.com) +:Date: $Date:$ +:Version: $Rev:$ + +tinyTiM provides a native, not TMAPI-compatible, way to import +and export topic maps. Even if the ``mio.TopicMapImporter`` accepts an instance of +``org.tmapi.core.TopicMap``, it cannot be used to deserialize ``org.tmapi.core.TopicMap`` +instances in a generic, TMAPI-compatible way. + + +.. toctree:: + :maxdepth: 2 + + topicmaps-import + topicmaps-export \ No newline at end of file Added: website/trunk/1.5/source/mio/topicmaps-export.txt =================================================================== --- website/trunk/1.5/source/mio/topicmaps-export.txt (rev 0) +++ website/trunk/1.5/source/mio/topicmaps-export.txt 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,20 @@ +.. highlight:: java + +Topic Maps Export +================= + +:Author: Lars Heuer (heuer[at]semagia.com) +:Date: $Date:$ +:Version: $Rev:$ + +:: + + import org.tinytim.mio.ITopicMapWriter; + import org.tinytim.mio.XTM20Writer; + // [...] Import the usual TMAPI suspects + + ITopicMapWriter writer = new XTM20Writer(); + + writer.write(topicMap); + +xxx \ No newline at end of file Added: website/trunk/1.5/source/mio/topicmaps-import.txt =================================================================== --- website/trunk/1.5/source/mio/topicmaps-import.txt (rev 0) +++ website/trunk/1.5/source/mio/topicmaps-import.txt 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,7 @@ +Topic Maps Import +================= + +:Author: Lars Heuer (heuer[at]semagia.com) +:Date: $Date:$ +:Version: $Rev:$ + Added: website/trunk/1.5/source/quickstart.txt =================================================================== --- website/trunk/1.5/source/quickstart.txt (rev 0) +++ website/trunk/1.5/source/quickstart.txt 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,40 @@ +.. highlight:: java + +Quickstart +========== + +:Author: Lars Heuer (heuer[at]semagia.com) +:Date: $Date:$ +:Version: $Rev:$ + +This section presents some examples how to get started with tinyTiM and TMAPI. +These examples should work with any TMAPI-compatible Topic Maps processor but +the focus stays clearly on tinyTiM. + +tinyTiM requires almost no installation since the core Topic Maps engine +was designed to require nothing more than the TMAPI interfaces. + +Optional packages like ``mio`` introduce dependencies, though. Anyway, +any TMAPI conformant application should be executable with tinyTiM and the +TMAPI 1.0SP1 lib in the classpath. If `Trove for Java <http://sourceforge.net/projects/trove4j>`_ +is available, tinyTiM will use that library for its collections; this +may enable tinyTiM to use less memory and / or to run faster. But this library represents no +strong dependency, tinyTiM detects it automatically and can be executed without it. + +Once tinyTiM and TMAPI is in the classpath the following example should +work:: + + import org.tmapi.core.TopicMapSystemFactory; + import org.tmapi.core.TopicMapSystem; + import org.tmapi.core.TopicMap; + import org.tmapi.core.Topic; + import org.tmapi.core.TopicName; + + TopicMapSystemFactory tmSysFactory = TopicMapSystemFactory.newInstance(); + TopicMapSystem tmSys = tmSysFactory.newTopicMapSystem(); + + TopicMap tm = tmSys.createTopicMap("http://www.example.org/map1"); + Topic example = tm.createTopic(); + + TopicName name = example.createName("Example", null); + Added: website/trunk/2.0/source/_static/default.css =================================================================== --- website/trunk/2.0/source/_static/default.css (rev 0) +++ website/trunk/2.0/source/_static/default.css 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,838 @@ +/** + * Sphinx Doc Design + */ + +body { + font-family: sans-serif; + font-size: 100%; + background-color: #FFF; + color: #000; + margin: 0; + padding: 0; +} + +.field-list { + font-size: 68%; + color: #666; +} + +/* :::: LAYOUT :::: */ + +div.document { + background-color: #FFF; +} + +div.documentwrapper { + float: left; + width: 100%; +} + +div.bodywrapper { + margin: 0 0 0 230px; +} + +div.body { + background-color: white; + padding: 0 20px 30px 20px; +} + +div.sphinxsidebarwrapper { + padding: 10px 5px 0 10px; +} + +div.sphinxsidebar { + float: left; + width: 230px; + margin-left: -100%; + font-size: 90%; +} + +div.clearer { + clear: both; +} + +div.footer { + color: #666; + width: 100%; + padding: 9px 0 9px 0; + text-align: center; + font-size: 75%; +} + +div.footer a { + color: #666; + text-decoration: underline; +} + +div.related { + background-color: #fff; + color: #666; + width: 100%; + height: 30px; + line-height: 30px; + font-size: 90%; +} + +div.related h3 { + display: none; +} + +div.related ul { + margin: 0; + padding: 0 0 0 10px; + list-style: none; +} + +div.related li { + display: inline; +} + +div.related li.right { + float: right; + margin-right: 5px; +} + +div.related a { + color: #666; +} + +/* ::: TOC :::: */ +div.sphinxsidebar h3 { + font-family: 'Trebuchet MS', sans-serif; + color: white; + font-size: 1.4em; + font-weight: normal; + margin: 0; + padding: 0; +} + +div.sphinxsidebar h4 { + font-family: 'Trebuchet MS', sans-serif; + color: white; + font-size: 1.3em; + font-weight: normal; + margin: 5px 0 0 0; + padding: 0; +} + +div.sphinxsidebar p { + color: white; +} + +div.sphinxsidebar p.topless { + margin: 5px 10px 10px 10px; +} + +div.sphinxsidebar ul { + margin: 10px; + padding: 0; + list-style: none; + color: white; +} + +div.sphinxsidebar ul ul, +div.sphinxsidebar ul.want-points { + margin-left: 20px; + list-style: square; +} + +div.sphinxsidebar ul ul { + margin-top: 0; + margin-bottom: 0; +} + +div.sphinxsidebar a { + color: #666; +} + +div.sphinxsidebar form { + margin-top: 10px; +} + +div.sphinxsidebar input { + border: 1px solid #98dbcc; + font-family: sans-serif; + font-size: 1em; +} + +/* :::: MODULE CLOUD :::: */ +div.modulecloud { + margin: -5px 10px 5px 10px; + padding: 10px; + line-height: 160%; + border: 1px solid #cbe7e5; + background-color: #f2fbfd; +} + +div.modulecloud a { + padding: 0 5px 0 5px; +} + +/* :::: SEARCH :::: */ +ul.search { + margin: 10px 0 0 20px; + padding: 0; +} + +ul.search li { + padding: 5px 0 5px 20px; + background-image: url(file.png); + background-repeat: no-repeat; + background-position: 0 7px; +} + +ul.search li a { + font-weight: bold; +} + +ul.search li div.context { + color: #888; + margin: 2px 0 0 30px; + text-align: left; +} + +ul.keywordmatches li.goodmatch a { + font-weight: bold; +} + +/* :::: COMMON FORM STYLES :::: */ + +div.actions { + padding: 5px 10px 5px 10px; + border-top: 1px solid #cbe7e5; + border-bottom: 1px solid #cbe7e5; + background-color: #e0f6f4; +} + +form dl { + color: #333; +} + +form dt { + clear: both; + float: left; + min-width: 110px; + margin-right: 10px; + padding-top: 2px; +} + +input#homepage { + display: none; +} + +div.error { + margin: 5px 20px 0 0; + padding: 5px; + border: 1px solid #d00; + font-weight: bold; +} + +/* :::: INLINE COMMENTS :::: */ + +div.inlinecomments { + position: absolute; + right: 20px; +} + +div.inlinecomments a.bubble { + display: block; + float: right; + background-image: url(style/comment.png); + background-repeat: no-repeat; + width: 25px; + height: 25px; + text-align: center; + padding-top: 3px; + font-size: 0.9em; + line-height: 14px; + font-weight: bold; + color: black; +} + +div.inlinecomments a.bubble span { + display: none; +} + +div.inlinecomments a.emptybubble { + background-image: url(style/nocomment.png); +} + +div.inlinecomments a.bubble:hover { + background-image: url(style/hovercomment.png); + text-decoration: none; + color: #3ca0a4; +} + +div.inlinecomments div.comments { + float: right; + margin: 25px 5px 0 0; + max-width: 50em; + min-width: 30em; + border: 1px solid #2eabb0; + background-color: #f2fbfd; + z-index: 150; +} + +div#comments { + border: 1px solid #2eabb0; + margin-top: 20px; +} + +div#comments div.nocomments { + padding: 10px; + font-weight: bold; +} + +div.inlinecomments div.comments h3, +div#comments h3 { + margin: 0; + padding: 0; + background-color: #2eabb0; + color: white; + border: none; + padding: 3px; +} + +div.inlinecomments div.comments div.actions { + padding: 4px; + margin: 0; + border-top: none; +} + +div#comments div.comment { + margin: 10px; + border: 1px solid #2eabb0; +} + +div.inlinecomments div.comment h4, +div.commentwindow div.comment h4, +div#comments div.comment h4 { + margin: 10px 0 0 0; + background-color: #2eabb0; + color: white; + border: none; + padding: 1px 4px 1px 4px; +} + +div#comments div.comment h4 { + margin: 0; +} + +div#comments div.comment h4 a { + color: #d5f4f4; +} + +div.inlinecomments div.comment div.text, +div.commentwindow div.comment div.text, +div#comments div.comment div.text { + margin: -5px 0 -5px 0; + padding: 0 10px 0 10px; +} + +div.inlinecomments div.comment div.meta, +div.commentwindow div.comment div.meta, +div#comments div.comment div.meta { + text-align: right; + padding: 2px 10px 2px 0; + font-size: 95%; + color: #538893; + border-top: 1px solid #cbe7e5; + background-color: #e0f6f4; +} + +div.commentwindow { + position: absolute; + width: 500px; + border: 1px solid #cbe7e5; + background-color: #f2fbfd; + display: none; + z-index: 130; +} + +div.commentwindow h3 { + margin: 0; + background-color: #2eabb0; + color: white; + border: none; + padding: 5px; + font-size: 1.5em; + cursor: pointer; +} + +div.commentwindow div.actions { + margin: 10px -10px 0 -10px; + padding: 4px 10px 4px 10px; + color: #538893; +} + +div.commentwindow div.actions input { + border: 1px solid #2eabb0; + background-color: white; + color: #135355; + cursor: pointer; +} + +div.commentwindow div.form { + padding: 0 10px 0 10px; +} + +div.commentwindow div.form input, +div.commentwindow div.form textarea { + border: 1px solid #3c9ea2; + background-color: white; + color: black; +} + +div.commentwindow div.error { + margin: 10px 5px 10px 5px; + background-color: #fbe5dc; + display: none; +} + +div.commentwindow div.form textarea { + width: 99%; +} + +div.commentwindow div.preview { + margin: 10px 0 10px 0; + background-color: #70d0d4; + padding: 0 1px 1px 25px; +} + +div.commentwindow div.preview h4 { + margin: 0 0 -5px -20px; + padding: 4px 0 0 4px; + color: white; + font-size: 1.3em; +} + +div.commentwindow div.preview div.comment { + background-color: #f2fbfd; +} + +div.commentwindow div.preview div.comment h4 { + margin: 10px 0 0 0!important; + padding: 1px 4px 1px 4px!important; + font-size: 1.2em; +} + +/* :::: SUGGEST CHANGES :::: */ +div#suggest-changes-box input, div#suggest-changes-box textarea { + border: 1px solid #ccc; + background-color: white; + color: black; +} + +div#suggest-changes-box textarea { + width: 99%; + height: 400px; +} + + +/* :::: PREVIEW :::: */ +div.preview { + background-image: url(style/preview.png); + padding: 0 20px 20px 20px; + margin-bottom: 30px; +} + + +/* :::: INDEX PAGE :::: */ + +table.contentstable { + width: 90%; +} + +table.contentstable p.biglink { + line-height: 150%; +} + +a.biglink { + font-size: 1.3em; +} + +span.linkdescr { + font-style: italic; + padding-top: 5px; + font-size: 90%; +} + +/* :::: INDEX STYLES :::: */ + +table.indextable td { + text-align: left; + vertical-align: top; +} + +table.indextable dl, table.indextable dd { + margin-top: 0; + margin-bottom: 0; +} + +table.indextable tr.pcap { + height: 10px; +} + +table.indextable tr.cap { + margin-top: 10px; + background-color: #f2f2f2; +} + +img.toggler { + margin-right: 3px; + margin-top: 3px; + cursor: pointer; +} + +form.pfform { + margin: 10px 0 20px 0; +} + +/* :::: GLOBAL STYLES :::: */ + +.docwarning { + background-color: #ffe4e4; + padding: 10px; + margin: 0 -20px 0 -20px; + border-bottom: 1px solid #f66; +} + +p.subhead { + font-weight: bold; + margin-top: 20px; +} + +a { + color: #355f7c; + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + +div.body h1, +div.body h2, +div.body h3, +div.body h4, +div.body h5, +div.body h6 { + font-family: 'Trebuchet MS', sans-serif; + background-color: #f2f2f2; + font-weight: normal; + color: #20435c; + border-bottom: 1px solid #ccc; + margin: 20px -20px 10px -20px; + padding: 3px 0 3px 10px; +} + +div.body h1 { margin-top: 0; font-size: 200%; } +div.body h2 { font-size: 160%; } +div.body h3 { font-size: 140%; } +div.body h4 { font-size: 120%; } +div.body h5 { font-size: 110%; } +div.body h6 { font-size: 100%; } + +a.headerlink { + color: #c60f0f; + font-size: 0.8em; + padding: 0 4px 0 4px; + text-decoration: none; + visibility: hidden; +} + +h1:hover > a.headerlink, +h2:hover > a.headerlink, +h3:hover > a.headerlink, +h4:hover > a.headerlink, +h5:hover > a.headerlink, +h6:hover > a.headerlink, +dt:hover > a.headerlink { + visibility: visible; +} + +a.headerlink:hover { + background-color: #c60f0f; + color: white; +} + +div.body p, div.body dd, div.body li { + text-align: justify; + line-height: 130%; +} + +div.body p.caption { + text-align: inherit; +} + +div.body td { + text-align: left; +} + +ul.fakelist { + list-style: none; + margin: 10px 0 10px 20px; + padding: 0; +} + +.field-list ul { + padding-left: 1em; +} + +.first { + margin-top: 0 !important; +} + +/* "Footnotes" heading */ +p.rubric { + margin-top: 30px; + font-weight: bold; +} + +/* "Topics" */ + +div.topic { + background-color: #eee; + border: 1px solid #ccc; + padding: 0 7px 0 7px; + margin: 10px 0 10px 0; +} + +p.topic-title { + font-size: 1.1em; + font-weight: bold; + margin-top: 10px; +} + +/* Admonitions */ + +div.admonition { + margin-top: 10px; + margin-bottom: 10px; + padding: 7px; +} + +div.admonition dt { + font-weight: bold; +} + +div.admonition dl { + margin-bottom: 0; +} + +div.admonition p { + display: inline; +} + +div.seealso { + background-color: #ffc; + border: 1px solid #ff6; +} + +div.warning { + background-color: #ffe4e4; + border: 1px solid #f66; +} + +div.note { + background-color: #eee; + border: 1px solid #ccc; +} + +p.admonition-title { + margin: 0px 10px 5px 0px; + font-weight: bold; + display: inline; +} + +p.admonition-title:after { + content: ":"; +} + +div.body p.centered { + text-align: center; + margin-top: 25px; +} + +table.docutils { + border: 0; +} + +table.docutils td, table.docutils th { + padding: 1px 8px 1px 0; + border-top: 0; + border-left: 0; + border-right: 0; + border-bottom: 1px solid #aaa; +} + +table.field-list td, table.field-list th { + border: 0 !important; +} + +table.footnote td, table.footnote th { + border: 0 !important; +} + +.field-list ul { + margin: 0; + padding-left: 1em; +} + +.field-list p { + margin: 0; +} + +dl { + margin-bottom: 15px; + clear: both; +} + +dd p { + margin-top: 0px; +} + +dd ul, dd table { + margin-bottom: 10px; +} + +dd { + margin-top: 3px; + margin-bottom: 10px; + margin-left: 30px; +} + +.refcount { + color: #060; +} + +dt:target, +.highlight { + background-color: #eee; +} + +dl.glossary dt { + font-weight: bold; + font-size: 1.1em; +} + +th { + text-align: left; + padding-right: 5px; +} + +pre { + padding: 5px; + background-color: #fefefe; + color: #333; + border: 1px solid #EEE; + border-left: none; + border-right: none; + overflow: auto; +} + +td.linenos pre { + padding: 5px 0px; + border: 0; + background-color: transparent; + color: #aaa; +} + +table.highlighttable { + margin-left: 0.5em; +} + +table.highlighttable td { + padding: 0 0.5em 0 0.5em; +} + +tt { + background-color: #ecf0f3; + padding: 0 1px 0 1px; + font-size: 0.95em; +} + +tt.descname { + background-color: transparent; + font-weight: bold; + font-size: 1.2em; +} + +tt.descclassname { + background-color: transparent; +} + +tt.xref, a tt { + background-color: transparent; + font-weight: bold; +} + +.footnote:target { background-color: #ffa } + +h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt { + background-color: transparent; +} + +.optional { + font-size: 1.3em; +} + +.versionmodified { + font-style: italic; +} + +form.comment { + margin: 0; + padding: 10px 30px 10px 30px; + background-color: #eee; +} + +form.comment h3 { + background-color: #326591; + color: white; + margin: -10px -30px 10px -30px; + padding: 5px; + font-size: 1.4em; +} + +form.comment input, +form.comment textarea { + border: 1px solid #ccc; + padding: 2px; + font-family: sans-serif; + font-size: 100%; +} + +form.comment input[type="text"] { + width: 240px; +} + +form.comment textarea { + width: 100%; + height: 200px; + margin-bottom: 10px; +} + +.system-message { + background-color: #fda; + padding: 5px; + border: 3px solid red; +} + +/* :::: PRINT :::: */ +@media print { + div.document, + div.documentwrapper, + div.bodywrapper { + margin: 0; + width : 100%; + } + + div.sphinxsidebar, + div.related, + div.footer, + div#comments div.new-comment-box, + #top-link { + display: none; + } +} Added: website/trunk/2.0/source/conf.py =================================================================== --- website/trunk/2.0/source/conf.py (rev 0) +++ website/trunk/2.0/source/conf.py 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,178 @@ +# -*- coding: utf-8 -*- +# +# tinyTiM documentation build configuration file, created by +# sphinx-quickstart on Sun Aug 17 19:14:56 2008. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# The contents of this file are pickled, so don't put values in the namespace +# that aren't pickleable (module imports are okay, they're removed automatically). +# +# All configuration values have a default value; values that are commented out +# serve to show the default value. + +import sys, os + +# If your extensions are in another directory, add it here. If the directory +# is relative to the documentation root, use os.path.abspath to make it +# absolute, like shown here. +#sys.path.append(os.path.abspath('some/directory')) + +# General configuration +# --------------------- + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = [] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.txt' + +# The master toctree document. +master_doc = 'index' + +# General substitutions. +project = 'tinyTiM' +copyright = '2008, tinyTiM project' + +# The default replacements for |version| and |release|, also used in various +# other places throughout the built documents. +# +# The short X.Y version. +version = '2.0' +# The full version, including alpha/beta/rc tags. +release = '2.0a1' + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +today_fmt = '%B %d, %Y' + +# List of documents that shouldn't be included in the build. +#unused_docs = [] + +# List of directories, relative to source directories, that shouldn't be searched +# for source files. +#exclude_dirs = [] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'emacs' + + +# Options for HTML output +# ----------------------- + +# The style sheet to use for HTML and HTML Help pages. A file of that name +# must exist either in Sphinx' static/ path, or in one of the custom paths +# given in html_static_path. +html_style = 'default.css' + +# The name for this set of Sphinx documents. If None, it defaults to +# "<project> v<release> documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (within the static path) to place at the top of +# the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +html_use_modindex = False + +# If false, no index is generated. +html_use_index = False + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, the reST sources are included in the HTML build as _sources/<name>. +html_copy_source = False + +# If true, an OpenSearch description file will be output, and all pages will +# contain a <link> tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = '' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'tinyTiMdoc' + + +# Options for LaTeX output +# ------------------------ + +# The paper size ('letter' or 'a4'). +#latex_paper_size = 'letter' + +# The font size ('10pt', '11pt' or '12pt'). +#latex_font_size = '10pt' + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, document class [howto/manual]). +latex_documents = [ + ('index', 'tinyTiM.tex', 'tinyTiM Documentation', 'tinyTiM project', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# Additional stuff for the LaTeX preamble. +#latex_preamble = '' + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_use_modindex = True Added: website/trunk/2.0/source/index.txt =================================================================== --- website/trunk/2.0/source/index.txt (rev 0) +++ website/trunk/2.0/source/index.txt 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,10 @@ +Documentation +============= + +Contents: + +.. toctree:: + :maxdepth: 2 + + quickstart + mio/index Added: website/trunk/2.0/source/mio/index.txt =================================================================== --- website/trunk/2.0/source/mio/index.txt (rev 0) +++ website/trunk/2.0/source/mio/index.txt 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,20 @@ +Importing and Exporting Topic Maps +================================== + +:Author: Lars Heuer (heuer[at]semagia.com) +:Date: $Date:$ +:Version: $Rev:$ + +tinyTiM provides a native, not TMAPI-compatible, way to import +and export topic maps. Even if every ``ITopicMapReader`` and ``ITopicMapWriter`` +accepts an instance of ``org.tmapi.core.TopicMap``, these (de-)serializers cannot +be used to (de-)serialize ``org.tmapi.core.TopicMap`` instances in a generic, +TMAPI-compatible way. These (de-)serializers are bound to tinyTiM and introduce +a dependency to this Topic Maps processor. + + +.. toctree:: + :maxdepth: 2 + + topicmaps-import + topicmaps-export \ No newline at end of file Added: website/trunk/2.0/source/mio/topicmaps-export.txt =================================================================== --- website/trunk/2.0/source/mio/topicmaps-export.txt (rev 0) +++ website/trunk/2.0/source/mio/topicmaps-export.txt 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,20 @@ +.. highlight:: java + +Topic Maps Export +================= + +:Author: Lars Heuer (heuer[at]semagia.com) +:Date: $Date:$ +:Version: $Rev:$ + +:: + + import org.tinytim.mio.ITopicMapWriter; + import org.tinytim.mio.XTM20Writer; + // [...] Import the usual TMAPI suspects + + ITopicMapWriter writer = new XTM20Writer(); + + writer.write(topicMap); + +xxx \ No newline at end of file Added: website/trunk/2.0/source/mio/topicmaps-import.txt =================================================================== --- website/trunk/2.0/source/mio/topicmaps-import.txt (rev 0) +++ website/trunk/2.0/source/mio/topicmaps-import.txt 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,7 @@ +Topic Maps Import +================= + +:Author: Lars Heuer (heuer[at]semagia.com) +:Date: $Date:$ +:Version: $Rev:$ + Added: website/trunk/2.0/source/quickstart.txt =================================================================== --- website/trunk/2.0/source/quickstart.txt (rev 0) +++ website/trunk/2.0/source/quickstart.txt 2008-08-19 14:03:18 UTC (rev 138) @@ -0,0 +1,43 @@ +.. highlight:: java + +Quickstart +========== + +:Author: Lars Heuer (heuer[at]semagia.com) +:Date: $Date:$ +:Version: $Rev:$ + +This section presents some examples how to get started with tinyTiM and TMAPI. +These examples should work with any TMAPI-compatible Topic Maps processor but +the focus stays clearly on tinyTiM. + +tinyTiM requires almost no installation since the core Topic Maps engine +was designed to require nothing more than the TMAPI interfaces. + +Optional packages like ``mio`` introduce dependencies, though. Anyway, +any TMAPI conformant application should be executable with tinyTiM and the +TMAPI 2.0 lib in the classpath. If `Trove for Java <http://sourceforge.net/projects/trove4j>`_ +is available, tinyTiM will use that library for its collections; this +may enable tinyTiM to use less memory and / or to run faster. But this library represents no +strong dependency, tinyTiM detects it automatically and can be executed without it. + +Once tinyTiM and TMAPI is in the classpath the following example should +work:: + + import org.tmapi.core.TopicMapSystemFactory; + import org.tmapi.core.TopicMapSystem; + import org.tmapi.core.TopicMap; + import org.tmapi.core.Topic; + import org.tmapi.core.Name; + + TopicMapSystemFactory tmSysFactory = TopicMapSystemFactory.newInstance(); + TopicMapSystem tmSys = tmSysFactory.newTopicMapSystem(); + + TopicMap tm = tmSys.createTopicMap("http://www.example.org/map1"); + // Creates a topic with an automatically assigned item identifier + // Note: This is method IS NOT recommended, creating a topic with an + // explicit identity should be preferred + Topic example = tm.createTopic(); + + Name name = example.createName("Example"); + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-19 13:51:56
|
Revision: 137 http://tinytim.svn.sourceforge.net/tinytim/?rev=137&view=rev Author: lheuer Date: 2008-08-19 13:52:06 +0000 (Tue, 19 Aug 2008) Log Message: ----------- Modified Paths: -------------- tinytim/trunk/CHANGES.txt Modified: tinytim/trunk/CHANGES.txt =================================================================== --- tinytim/trunk/CHANGES.txt 2008-08-19 13:41:00 UTC (rev 136) +++ tinytim/trunk/CHANGES.txt 2008-08-19 13:52:06 UTC (rev 137) @@ -2,6 +2,11 @@ Changes Log =========== +2.0.0 a1 (xx.08.2008) +--------------------- +* Implementation of the TMAPI 2.0 interfaces + + 1.5.0 beta (08.08.2008) ----------------------- Bugfixes: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-19 13:40:53
|
Revision: 136 http://tinytim.svn.sourceforge.net/tinytim/?rev=136&view=rev Author: lheuer Date: 2008-08-19 13:41:00 +0000 (Tue, 19 Aug 2008) Log Message: ----------- Added Emma lic Added Paths: ----------- tinytim/trunk/lib/LICENSE.emma.html Removed Paths: ------------- tinytim/trunk/lib/LICENSE.emma..html Deleted: tinytim/trunk/lib/LICENSE.emma..html =================================================================== --- tinytim/trunk/lib/LICENSE.emma..html 2008-08-19 13:40:02 UTC (rev 135) +++ tinytim/trunk/lib/LICENSE.emma..html 2008-08-19 13:41:00 UTC (rev 136) @@ -1,125 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> -<HTML> -<HEAD> -<TITLE>Common Public License - v 1.0</TITLE> -<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> -</HEAD> - -<BODY BGCOLOR="#FFFFFF" VLINK="#800000"> - - -<P ALIGN="CENTER"><B>Common Public License - v 1.0</B> -<P><B></B><FONT SIZE="3"></FONT> -<P><FONT SIZE="3"></FONT><FONT SIZE="2">THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.</FONT> -<P><FONT SIZE="2"></FONT> -<P><FONT SIZE="2"><B>1. DEFINITIONS</B></FONT> -<P><FONT SIZE="2">"Contribution" means:</FONT> - -<UL><FONT SIZE="2">a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and<BR CLEAR="LEFT"> -b) in the case of each subsequent Contributor:</FONT></UL> - - -<UL><FONT SIZE="2">i) changes to the Program, and</FONT></UL> - - -<UL><FONT SIZE="2">ii) additions to the Program;</FONT></UL> - - -<UL><FONT SIZE="2">where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. </FONT><FONT SIZE="2">A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. </FONT><FONT SIZE="2">Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. </FONT></UL> - -<P><FONT SIZE="2"></FONT> -<P><FONT SIZE="2">"Contributor" means any person or entity that distributes the Program.</FONT> -<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT> -<P><FONT SIZE="2">"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. </FONT> -<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT> -<P><FONT SIZE="2"></FONT><FONT SIZE="2">"Program" means the Contributions distributed in accordance with this Agreement.</FONT> -<P><FONT SIZE="2"></FONT> -<P><FONT SIZE="2">"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.</FONT> -<P><FONT SIZE="2"><B></B></FONT> -<P><FONT SIZE="2"><B>2. GRANT OF RIGHTS</B></FONT> - -<UL><FONT SIZE="2"></FONT><FONT SIZE="2">a) </FONT><FONT SIZE="2">Subject to the terms of this Agreement, each Contributor hereby grants</FONT><FONT SIZE="2"> Recipient a non-exclusive, worldwide, royalty-free copyright license to</FONT><FONT SIZE="2" COLOR="#FF0000"> </FONT><FONT SIZE="2">reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.</FONT></UL> - - -<UL><FONT SIZE="2"></FONT></UL> - - -<UL><FONT SIZE="2"></FONT><FONT SIZE="2">b) Subject to the terms of this Agreement, each Contributor hereby grants </FONT><FONT SIZE="2">Recipient a non-exclusive, worldwide,</FONT><FONT SIZE="2" COLOR="#008000"> </FONT><FONT SIZE="2">royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. </FONT></UL> - - -<UL><FONT SIZE="2"></FONT></UL> - - -<UL><FONT SIZE="2">c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.</FONT></UL> - - -<UL><FONT SIZE="2"></FONT></UL> - - -<UL><FONT SIZE="2">d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. </FONT></UL> - - -<UL><FONT SIZE="2"></FONT></UL> - -<P><FONT SIZE="2"><B>3. REQUIREMENTS</B></FONT> -<P><FONT SIZE="2"><B></B>A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:</FONT> - -<UL><FONT SIZE="2">a) it complies with the terms and conditions of this Agreement; and</FONT></UL> - - -<UL><FONT SIZE="2">b) its license agreement:</FONT></UL> - - -<UL><FONT SIZE="2">i) effectively disclaims</FONT><FONT SIZE="2"> on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; </FONT></UL> - - -<UL><FONT SIZE="2">ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; </FONT></UL> - - -<UL><FONT SIZE="2">iii)</FONT><FONT SIZE="2"> states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and</FONT></UL> - - -<UL><FONT SIZE="2">iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.</FONT><FONT SIZE="2" COLOR="#0000FF"> </FONT><FONT SIZE="2" COLOR="#FF0000"></FONT></UL> - - -<UL><FONT SIZE="2" COLOR="#FF0000"></FONT><FONT SIZE="2"></FONT></UL> - -<P><FONT SIZE="2">When the Program is made available in source code form:</FONT> - -<UL><FONT SIZE="2">a) it must be made available under this Agreement; and </FONT></UL> - - -<UL><FONT SIZE="2">b) a copy of this Agreement must be included with each copy of the Program. </FONT></UL> - -<P><FONT SIZE="2"></FONT><FONT SIZE="2" COLOR="#0000FF"><STRIKE></STRIKE></FONT> -<P><FONT SIZE="2" COLOR="#0000FF"><STRIKE></STRIKE></FONT><FONT SIZE="2">Contributors may not remove or alter any copyright notices contained within the Program. </FONT> -<P><FONT SIZE="2"></FONT> -<P><FONT SIZE="2">Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. </FONT> -<P><FONT SIZE="2"></FONT> -<P><FONT SIZE="2"><B>4. COMMERCIAL DISTRIBUTION</B></FONT> -<P><FONT SIZE="2">Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.</FONT> -<P><FONT SIZE="2"></FONT> -<P><FONT SIZE="2">For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.</FONT> -<P><FONT SIZE="2"></FONT><FONT SIZE="2" COLOR="#0000FF"></FONT> -<P><FONT SIZE="2" COLOR="#0000FF"></FONT><FONT SIZE="2"><B>5. NO WARRANTY</B></FONT> -<P><FONT SIZE="2">EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is</FONT><FONT SIZE="2"> solely responsible for determining the appropriateness of using and distributing </FONT><FONT SIZE="2">the Program</FONT><FONT SIZE="2"> and assumes all risks associated with its exercise of rights under this Agreement</FONT><FONT SIZE="2">, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, </FONT><FONT SIZE="2">programs or equipment, and unavailability or interruption of operations</FONT><FONT SIZE="2">. </FONT><FONT SIZE="2"></FONT> -<P><FONT SIZE="2"></FONT> -<P><FONT SIZE="2"></FONT><FONT SIZE="2"><B>6. DISCLAIMER OF LIABILITY</B></FONT> -<P><FONT SIZE="2"></FONT><FONT SIZE="2">EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES </FONT><FONT SIZE="2">(INCLUDING WITHOUT LIMITATION LOST PROFITS),</FONT><FONT SIZE="2"> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</FONT> -<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT> -<P><FONT SIZE="2"><B>7. GENERAL</B></FONT> -<P><FONT SIZE="2"></FONT><FONT SIZE="2">If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.</FONT> -<P><FONT SIZE="2"></FONT> -<P><FONT SIZE="2">If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. </FONT><FONT SIZE="2"></FONT> -<P><FONT SIZE="2"></FONT> -<P><FONT SIZE="2">All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. </FONT><FONT SIZE="2"></FONT> -<P><FONT SIZE="2"></FONT> -<P><FONT SIZE="2"></FONT><FONT SIZE="2">Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to </FONT><FONT SIZE="2">publish new versions (including revisions) of this Agreement from time to </FONT><FONT SIZE="2">time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. </FONT><FONT SIZE="2">Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new </FONT><FONT SIZE="2">version. </FONT><FONT SIZE="2">Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, </FONT><FONT SIZE="2">by implication, estoppel or otherwise</FONT><FONT SIZE="2">.</FONT><FONT SIZE="2"> All rights in the Program not expressly granted under this Agreement are reserved.</FONT> -<P><FONT SIZE="2"></FONT> -<P><FONT SIZE="2">This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.</FONT> -<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT> -<P><FONT SIZE="2"></FONT> - -</BODY> - -</HTML> \ No newline at end of file Added: tinytim/trunk/lib/LICENSE.emma.html =================================================================== --- tinytim/trunk/lib/LICENSE.emma.html (rev 0) +++ tinytim/trunk/lib/LICENSE.emma.html 2008-08-19 13:41:00 UTC (rev 136) @@ -0,0 +1,125 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> +<HTML> +<HEAD> +<TITLE>Common Public License - v 1.0</TITLE> +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> +</HEAD> + +<BODY BGCOLOR="#FFFFFF" VLINK="#800000"> + + +<P ALIGN="CENTER"><B>Common Public License - v 1.0</B> +<P><B></B><FONT SIZE="3"></FONT> +<P><FONT SIZE="3"></FONT><FONT SIZE="2">THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.</FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"><B>1. DEFINITIONS</B></FONT> +<P><FONT SIZE="2">"Contribution" means:</FONT> + +<UL><FONT SIZE="2">a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and<BR CLEAR="LEFT"> +b) in the case of each subsequent Contributor:</FONT></UL> + + +<UL><FONT SIZE="2">i) changes to the Program, and</FONT></UL> + + +<UL><FONT SIZE="2">ii) additions to the Program;</FONT></UL> + + +<UL><FONT SIZE="2">where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. </FONT><FONT SIZE="2">A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. </FONT><FONT SIZE="2">Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. </FONT></UL> + +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">"Contributor" means any person or entity that distributes the Program.</FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. </FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2">"Program" means the Contributions distributed in accordance with this Agreement.</FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.</FONT> +<P><FONT SIZE="2"><B></B></FONT> +<P><FONT SIZE="2"><B>2. GRANT OF RIGHTS</B></FONT> + +<UL><FONT SIZE="2"></FONT><FONT SIZE="2">a) </FONT><FONT SIZE="2">Subject to the terms of this Agreement, each Contributor hereby grants</FONT><FONT SIZE="2"> Recipient a non-exclusive, worldwide, royalty-free copyright license to</FONT><FONT SIZE="2" COLOR="#FF0000"> </FONT><FONT SIZE="2">reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.</FONT></UL> + + +<UL><FONT SIZE="2"></FONT></UL> + + +<UL><FONT SIZE="2"></FONT><FONT SIZE="2">b) Subject to the terms of this Agreement, each Contributor hereby grants </FONT><FONT SIZE="2">Recipient a non-exclusive, worldwide,</FONT><FONT SIZE="2" COLOR="#008000"> </FONT><FONT SIZE="2">royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. </FONT></UL> + + +<UL><FONT SIZE="2"></FONT></UL> + + +<UL><FONT SIZE="2">c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.</FONT></UL> + + +<UL><FONT SIZE="2"></FONT></UL> + + +<UL><FONT SIZE="2">d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. </FONT></UL> + + +<UL><FONT SIZE="2"></FONT></UL> + +<P><FONT SIZE="2"><B>3. REQUIREMENTS</B></FONT> +<P><FONT SIZE="2"><B></B>A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:</FONT> + +<UL><FONT SIZE="2">a) it complies with the terms and conditions of this Agreement; and</FONT></UL> + + +<UL><FONT SIZE="2">b) its license agreement:</FONT></UL> + + +<UL><FONT SIZE="2">i) effectively disclaims</FONT><FONT SIZE="2"> on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; </FONT></UL> + + +<UL><FONT SIZE="2">ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; </FONT></UL> + + +<UL><FONT SIZE="2">iii)</FONT><FONT SIZE="2"> states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and</FONT></UL> + + +<UL><FONT SIZE="2">iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.</FONT><FONT SIZE="2" COLOR="#0000FF"> </FONT><FONT SIZE="2" COLOR="#FF0000"></FONT></UL> + + +<UL><FONT SIZE="2" COLOR="#FF0000"></FONT><FONT SIZE="2"></FONT></UL> + +<P><FONT SIZE="2">When the Program is made available in source code form:</FONT> + +<UL><FONT SIZE="2">a) it must be made available under this Agreement; and </FONT></UL> + + +<UL><FONT SIZE="2">b) a copy of this Agreement must be included with each copy of the Program. </FONT></UL> + +<P><FONT SIZE="2"></FONT><FONT SIZE="2" COLOR="#0000FF"><STRIKE></STRIKE></FONT> +<P><FONT SIZE="2" COLOR="#0000FF"><STRIKE></STRIKE></FONT><FONT SIZE="2">Contributors may not remove or alter any copyright notices contained within the Program. </FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. </FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"><B>4. COMMERCIAL DISTRIBUTION</B></FONT> +<P><FONT SIZE="2">Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.</FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.</FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2" COLOR="#0000FF"></FONT> +<P><FONT SIZE="2" COLOR="#0000FF"></FONT><FONT SIZE="2"><B>5. NO WARRANTY</B></FONT> +<P><FONT SIZE="2">EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is</FONT><FONT SIZE="2"> solely responsible for determining the appropriateness of using and distributing </FONT><FONT SIZE="2">the Program</FONT><FONT SIZE="2"> and assumes all risks associated with its exercise of rights under this Agreement</FONT><FONT SIZE="2">, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, </FONT><FONT SIZE="2">programs or equipment, and unavailability or interruption of operations</FONT><FONT SIZE="2">. </FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2"><B>6. DISCLAIMER OF LIABILITY</B></FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2">EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES </FONT><FONT SIZE="2">(INCLUDING WITHOUT LIMITATION LOST PROFITS),</FONT><FONT SIZE="2"> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"><B>7. GENERAL</B></FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2">If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.</FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. </FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. </FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2">Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to </FONT><FONT SIZE="2">publish new versions (including revisions) of this Agreement from time to </FONT><FONT SIZE="2">time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. </FONT><FONT SIZE="2">Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new </FONT><FONT SIZE="2">version. </FONT><FONT SIZE="2">Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, </FONT><FONT SIZE="2">by implication, estoppel or otherwise</FONT><FONT SIZE="2">.</FONT><FONT SIZE="2"> All rights in the Program not expressly granted under this Agreement are reserved.</FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.</FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT> + +</BODY> + +</HTML> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-19 13:39:54
|
Revision: 135 http://tinytim.svn.sourceforge.net/tinytim/?rev=135&view=rev Author: lheuer Date: 2008-08-19 13:40:02 +0000 (Tue, 19 Aug 2008) Log Message: ----------- - Update from trove-2.0.3.jar to trove-2.0.4.jar - Added Emma code coverage tool <http://emma.sourceforge.net/> Added Paths: ----------- tinytim/trunk/lib/LICENSE.emma..html tinytim/trunk/lib/emma.jar tinytim/trunk/lib/emma_ant.jar tinytim/trunk/lib/trove-2.0.4.jar Removed Paths: ------------- tinytim/trunk/lib/trove-2.0.3.jar Added: tinytim/trunk/lib/LICENSE.emma..html =================================================================== --- tinytim/trunk/lib/LICENSE.emma..html (rev 0) +++ tinytim/trunk/lib/LICENSE.emma..html 2008-08-19 13:40:02 UTC (rev 135) @@ -0,0 +1,125 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> +<HTML> +<HEAD> +<TITLE>Common Public License - v 1.0</TITLE> +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> +</HEAD> + +<BODY BGCOLOR="#FFFFFF" VLINK="#800000"> + + +<P ALIGN="CENTER"><B>Common Public License - v 1.0</B> +<P><B></B><FONT SIZE="3"></FONT> +<P><FONT SIZE="3"></FONT><FONT SIZE="2">THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.</FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"><B>1. DEFINITIONS</B></FONT> +<P><FONT SIZE="2">"Contribution" means:</FONT> + +<UL><FONT SIZE="2">a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and<BR CLEAR="LEFT"> +b) in the case of each subsequent Contributor:</FONT></UL> + + +<UL><FONT SIZE="2">i) changes to the Program, and</FONT></UL> + + +<UL><FONT SIZE="2">ii) additions to the Program;</FONT></UL> + + +<UL><FONT SIZE="2">where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. </FONT><FONT SIZE="2">A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. </FONT><FONT SIZE="2">Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. </FONT></UL> + +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">"Contributor" means any person or entity that distributes the Program.</FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. </FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2">"Program" means the Contributions distributed in accordance with this Agreement.</FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.</FONT> +<P><FONT SIZE="2"><B></B></FONT> +<P><FONT SIZE="2"><B>2. GRANT OF RIGHTS</B></FONT> + +<UL><FONT SIZE="2"></FONT><FONT SIZE="2">a) </FONT><FONT SIZE="2">Subject to the terms of this Agreement, each Contributor hereby grants</FONT><FONT SIZE="2"> Recipient a non-exclusive, worldwide, royalty-free copyright license to</FONT><FONT SIZE="2" COLOR="#FF0000"> </FONT><FONT SIZE="2">reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.</FONT></UL> + + +<UL><FONT SIZE="2"></FONT></UL> + + +<UL><FONT SIZE="2"></FONT><FONT SIZE="2">b) Subject to the terms of this Agreement, each Contributor hereby grants </FONT><FONT SIZE="2">Recipient a non-exclusive, worldwide,</FONT><FONT SIZE="2" COLOR="#008000"> </FONT><FONT SIZE="2">royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. </FONT></UL> + + +<UL><FONT SIZE="2"></FONT></UL> + + +<UL><FONT SIZE="2">c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.</FONT></UL> + + +<UL><FONT SIZE="2"></FONT></UL> + + +<UL><FONT SIZE="2">d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. </FONT></UL> + + +<UL><FONT SIZE="2"></FONT></UL> + +<P><FONT SIZE="2"><B>3. REQUIREMENTS</B></FONT> +<P><FONT SIZE="2"><B></B>A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:</FONT> + +<UL><FONT SIZE="2">a) it complies with the terms and conditions of this Agreement; and</FONT></UL> + + +<UL><FONT SIZE="2">b) its license agreement:</FONT></UL> + + +<UL><FONT SIZE="2">i) effectively disclaims</FONT><FONT SIZE="2"> on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; </FONT></UL> + + +<UL><FONT SIZE="2">ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; </FONT></UL> + + +<UL><FONT SIZE="2">iii)</FONT><FONT SIZE="2"> states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and</FONT></UL> + + +<UL><FONT SIZE="2">iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.</FONT><FONT SIZE="2" COLOR="#0000FF"> </FONT><FONT SIZE="2" COLOR="#FF0000"></FONT></UL> + + +<UL><FONT SIZE="2" COLOR="#FF0000"></FONT><FONT SIZE="2"></FONT></UL> + +<P><FONT SIZE="2">When the Program is made available in source code form:</FONT> + +<UL><FONT SIZE="2">a) it must be made available under this Agreement; and </FONT></UL> + + +<UL><FONT SIZE="2">b) a copy of this Agreement must be included with each copy of the Program. </FONT></UL> + +<P><FONT SIZE="2"></FONT><FONT SIZE="2" COLOR="#0000FF"><STRIKE></STRIKE></FONT> +<P><FONT SIZE="2" COLOR="#0000FF"><STRIKE></STRIKE></FONT><FONT SIZE="2">Contributors may not remove or alter any copyright notices contained within the Program. </FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. </FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"><B>4. COMMERCIAL DISTRIBUTION</B></FONT> +<P><FONT SIZE="2">Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.</FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.</FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2" COLOR="#0000FF"></FONT> +<P><FONT SIZE="2" COLOR="#0000FF"></FONT><FONT SIZE="2"><B>5. NO WARRANTY</B></FONT> +<P><FONT SIZE="2">EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is</FONT><FONT SIZE="2"> solely responsible for determining the appropriateness of using and distributing </FONT><FONT SIZE="2">the Program</FONT><FONT SIZE="2"> and assumes all risks associated with its exercise of rights under this Agreement</FONT><FONT SIZE="2">, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, </FONT><FONT SIZE="2">programs or equipment, and unavailability or interruption of operations</FONT><FONT SIZE="2">. </FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2"><B>6. DISCLAIMER OF LIABILITY</B></FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2">EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES </FONT><FONT SIZE="2">(INCLUDING WITHOUT LIMITATION LOST PROFITS),</FONT><FONT SIZE="2"> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"><B>7. GENERAL</B></FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2">If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.</FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. </FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. </FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2">Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to </FONT><FONT SIZE="2">publish new versions (including revisions) of this Agreement from time to </FONT><FONT SIZE="2">time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. </FONT><FONT SIZE="2">Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new </FONT><FONT SIZE="2">version. </FONT><FONT SIZE="2">Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, </FONT><FONT SIZE="2">by implication, estoppel or otherwise</FONT><FONT SIZE="2">.</FONT><FONT SIZE="2"> All rights in the Program not expressly granted under this Agreement are reserved.</FONT> +<P><FONT SIZE="2"></FONT> +<P><FONT SIZE="2">This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.</FONT> +<P><FONT SIZE="2"></FONT><FONT SIZE="2"></FONT> +<P><FONT SIZE="2"></FONT> + +</BODY> + +</HTML> \ No newline at end of file Property changes on: tinytim/trunk/lib/emma.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Property changes on: tinytim/trunk/lib/emma_ant.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Property changes on: tinytim/trunk/lib/trove-2.0.4.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...> - 2008-08-19 12:01:52
|
Revision: 134 http://tinytim.svn.sourceforge.net/tinytim/?rev=134&view=rev Author: lheuer Date: 2008-08-19 12:02:01 +0000 (Tue, 19 Aug 2008) Log Message: ----------- - Updated Scope handling for Variants. The solution sucks but passes the TMAPI tests. Anyway, better solution needed Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-17 18:49:30 UTC (rev 133) +++ tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-19 12:02:01 UTC (rev 134) @@ -98,10 +98,13 @@ */ @Override public void addTheme(Topic theme) { + IScope scope = _scope; super.addTheme(theme); - if (_variants != null) { - for (Variant variant: _variants) { - variant.addTheme(theme); + if (scope != _scope) { + if (_variants != null) { + for (Variant variant: _variants) { + ((VariantImpl) variant)._addNameTheme(theme); + } } } } @@ -111,10 +114,13 @@ */ @Override public void removeTheme(Topic theme) { + IScope scope = _scope; super.removeTheme(theme); - if (_variants != null) { - for (Variant variant: _variants) { - variant.removeTheme(theme); + if (scope != _scope) { + if (_variants != null) { + for (Variant variant: _variants) { + ((VariantImpl) variant)._removeNameTheme(theme); + } } } } @@ -185,15 +191,14 @@ if (scope.isEmpty()) { throw new ModelConstraintException(this, "The scope of the variant must not be unconstrained"); } - Set<Topic> nameScope = super.getScope(); - if (nameScope.containsAll(scope)) { + if (_scope.containsAll(scope)) { throw new ModelConstraintException(this, "The variant's scope is not a true superset of the parent's scope"); } - Set<Topic> scope_ = CollectionFactory.createIdentitySet(scope.size() + nameScope.size()); - scope_.addAll(scope); - scope_.addAll(nameScope); - Variant variant = new VariantImpl(_tm, literal, Scope.create(scope_)); + VariantImpl variant = new VariantImpl(_tm, literal, Scope.create(scope)); addVariant(variant); + for (Topic theme: _scope) { + variant._addNameTheme(theme); + } return variant; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-17 18:49:30 UTC (rev 133) +++ tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-19 12:02:01 UTC (rev 134) @@ -36,7 +36,7 @@ //NOTE: This class does NOT implement IScoped by intention! - private IScope _scope; + protected IScope _scope; ScopedImpl(TopicMapImpl tm) { super(tm); Modified: tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-08-17 18:49:30 UTC (rev 133) +++ tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-08-19 12:02:01 UTC (rev 134) @@ -20,7 +20,11 @@ */ package org.tinytim.core; +import java.util.Set; + +import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Name; +import org.tmapi.core.Topic; import org.tmapi.core.Variant; /** @@ -72,4 +76,25 @@ super.dispose(); } + /* (non-Javadoc) + * @see org.tinytim.core.ScopedImpl#getScope() + */ + @Override + public Set<Topic> getScope() { + Set<Topic> scope = CollectionFactory.createIdentitySet(getParent().getScope()); + scope.addAll(_scope.asSet()); + return scope; + } + + void _addNameTheme(Topic theme) { + if (!_scope.contains(theme)) { + _fireEvent(Event.SET_SCOPE, _scope, _scope.add(theme)); + } + } + + void _removeNameTheme(Topic theme) { + IScope scope = Scope.create(getScope()); + _fireEvent(Event.SET_SCOPE, scope.add(theme), scope); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-17 18:49:21
|
Revision: 133 http://tinytim.svn.sourceforge.net/tinytim/?rev=133&view=rev Author: lheuer Date: 2008-08-17 18:49:30 +0000 (Sun, 17 Aug 2008) Log Message: ----------- - Usage of the _attrs field consequently, no new AttributesImpl are created, _attrs is always cleared Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java 2008-08-17 10:12:37 UTC (rev 132) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java 2008-08-17 18:49:30 UTC (rev 133) @@ -159,9 +159,9 @@ typeInstanceIndex.close(); _createIndex(topics, assocs); _out.startDocument(); - AttributesImpl attrs = new AttributesImpl(); - _addReifier(attrs, topicMap); - _out.startElement("topicMap", attrs); + _attrs.clear(); + _addReifier(_attrs, topicMap); + _out.startElement("topicMap", _attrs); _out.newline(); _writeItemIdentifiers(topicMap); for (Topic topic: topics) { @@ -174,6 +174,7 @@ _out.newline(); _out.endDocument(); _out = null; + _attrs = null; _construct2Id = null; _locator2Norm = null; _assoc2Roles = null; @@ -355,9 +356,9 @@ * @throws IOException If an error occurs. */ private void _writeTopic(final Topic topic) throws IOException { - AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute("", "number", "", "CDATA", Integer.toString(_indexOf(topic))); - _out.startElement("topic", attrs); + _attrs.clear(); + _attrs.addAttribute("", "number", "", "CDATA", Integer.toString(_indexOf(topic))); + _out.startElement("topic", _attrs); _out.newline(); _writeLocatorSet("subjectIdentifiers", topic.getSubjectIdentifiers()); _writeLocatorSet("subjectLocators", topic.getSubjectLocators()); @@ -377,19 +378,18 @@ } Role[] roles = roles_.toArray(new Role[roles_.size()]); Arrays.sort(roles, _roleComparator); - AttributesImpl roleAttrs = new AttributesImpl(); StringBuilder sb = new StringBuilder(20); for (int i=0; i < roles.length; i++) { sb.append("association.") .append(_indexOf(roles[i].getParent())) .append(".role.") .append(_indexOf(roles[i])); - roleAttrs.addAttribute("", "ref", "", "CDATA", sb.toString()); - _out.startElement("rolePlayed", roleAttrs); + _attrs.clear(); + _attrs.addAttribute("", "ref", "", "CDATA", sb.toString()); + _out.startElement("rolePlayed", _attrs); _out.endElement("rolePlayed"); _out.newline(); sb.setLength(0); - roleAttrs.clear(); } _out.endElement("topic"); _out.newline(); @@ -593,9 +593,9 @@ _reportInvalid("The topic reference is null"); return XMLC14NWriter.EMPTY_ATTRS; } - AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute("", "topicref", "", "CDATA", Integer.toString(_indexOf(topic))); - return attrs; + _attrs.clear(); + _attrs.addAttribute("", "topicref", "", "CDATA", Integer.toString(_indexOf(topic))); + return _attrs; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-17 10:12:28
|
Revision: 132 http://tinytim.svn.sourceforge.net/tinytim/?rev=132&view=rev Author: lheuer Date: 2008-08-17 10:12:37 +0000 (Sun, 17 Aug 2008) Log Message: ----------- "" + int -> Integer.toString(int) Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java 2008-08-17 10:04:59 UTC (rev 131) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java 2008-08-17 10:12:37 UTC (rev 132) @@ -356,7 +356,7 @@ */ private void _writeTopic(final Topic topic) throws IOException { AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute("", "number", "", "CDATA", "" +_indexOf(topic)); + attrs.addAttribute("", "number", "", "CDATA", Integer.toString(_indexOf(topic))); _out.startElement("topic", attrs); _out.newline(); _writeLocatorSet("subjectIdentifiers", topic.getSubjectIdentifiers()); @@ -594,7 +594,7 @@ return XMLC14NWriter.EMPTY_ATTRS; } AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute("", "topicref", "", "CDATA", "" + _indexOf(topic)); + attrs.addAttribute("", "topicref", "", "CDATA", Integer.toString(_indexOf(topic))); return attrs; } @@ -603,14 +603,14 @@ * of the provided Topic Maps construct (not a topic). * * @param reifiable The Topic Maps construct. - * @param The position of the reifiable within the parent container. + * @param pos The position of the reifiable within the parent container. * @return Attributes which contain a reference to the reifier (if any) and * the number of the provided Topic Maps construct. */ - private Attributes _attributes(final Reifiable reifiable, int i) { + private Attributes _attributes(final Reifiable reifiable, int pos) { _attrs.clear(); _addReifier(_attrs, reifiable); - _attrs.addAttribute("", "number", "", "CDATA", "" + i); + _attrs.addAttribute("", "number", "", "CDATA", Integer.toString(pos)); return _attrs; } @@ -625,7 +625,7 @@ private void _addReifier(final AttributesImpl attrs, final Reifiable reifiable) { Topic reifier = reifiable.getReifier(); if (reifier != null) { - attrs.addAttribute("", "reifier", "", "CDATA", "" + _indexOf(reifier)); + attrs.addAttribute("", "reifier", "", "CDATA", Integer.toString(_indexOf(reifier))); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-17 10:04:56
|
Revision: 131 http://tinytim.svn.sourceforge.net/tinytim/?rev=131&view=rev Author: lheuer Date: 2008-08-17 10:04:59 +0000 (Sun, 17 Aug 2008) Log Message: ----------- - Added forgotten TinyTimMapInputHandler test (previously TestMapInputHandler) Added Paths: ----------- tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java Added: tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java (rev 0) +++ tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.java 2008-08-17 10:04:59 UTC (rev 131) @@ -0,0 +1,324 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +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.MIOException; +import com.semagia.mio.helpers.Ref; + +/** + * Tests against the {@link org.tinytim.core.AbstractMapInputHandler}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +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); + } + + /** + * 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. + } + } + +} Property changes on: tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestTinyTimMapInputHandler.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...> - 2008-08-17 10:03:00
|
Revision: 130 http://tinytim.svn.sourceforge.net/tinytim/?rev=130&view=rev Author: lheuer Date: 2008-08-17 10:03:04 +0000 (Sun, 17 Aug 2008) Log Message: ----------- - Renamed MapInputHandler into TinyTimMapInputHandler (again) :/ - CXTMWriter creates valid sax.Attributes (no null for QName and type) - XMLC14NWriter avoids creating StringBuilder and emits escaped characters directly Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/SnelloReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLC14NWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTMReader.java Added Paths: ----------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java Removed Paths: ------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -41,7 +41,7 @@ * the discovery of an appropriate deserializer transparently. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ abstract class AbstractTopicMapReader implements ITopicMapReader { @@ -52,7 +52,7 @@ if (_deserializer == null) { throw new TMAPIRuntimeException("Appropriate deserializer not found for syntax " + syntax.getName()); } - _deserializer.setMapHandler(new MapInputHandler(topicMap)); + _deserializer.setMapHandler(new TinyTimMapInputHandler(topicMap)); } /* (non-Javadoc) Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -29,7 +29,7 @@ * <a href="http://www.semagia.com/tr/btm/1.0/">Binary Topic Maps (BTM) 1.0</a>. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class BTMReader extends AbstractTopicMapReader { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -32,7 +32,7 @@ * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class CTMReader extends AbstractTopicMapReader { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java 2008-08-17 10:03:04 UTC (rev 130) @@ -85,6 +85,8 @@ private static final Role[] _EMPTY_ROLES = new Role[0]; + private AttributesImpl _attrs; + private Topic _type; private Topic _instance; private Topic _typeInstance; @@ -119,6 +121,7 @@ throw new IllegalArgumentException("The base locator must not be null"); } _out = new XMLC14NWriter(out); + _attrs = new AttributesImpl(); _normBase = _normalizeBaseLocator(baseLocator); _topicComparator = new TopicComparator(); _assocComparator = new AssociationComparator(); @@ -353,7 +356,7 @@ */ private void _writeTopic(final Topic topic) throws IOException { AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute("", "number", null, null, "" +_indexOf(topic)); + attrs.addAttribute("", "number", "", "CDATA", "" +_indexOf(topic)); _out.startElement("topic", attrs); _out.newline(); _writeLocatorSet("subjectIdentifiers", topic.getSubjectIdentifiers()); @@ -381,7 +384,7 @@ .append(_indexOf(roles[i].getParent())) .append(".role.") .append(_indexOf(roles[i])); - roleAttrs.addAttribute("", "ref", null, null, sb.toString()); + roleAttrs.addAttribute("", "ref", "", "CDATA", sb.toString()); _out.startElement("rolePlayed", roleAttrs); _out.endElement("rolePlayed"); _out.newline(); @@ -591,7 +594,7 @@ return XMLC14NWriter.EMPTY_ATTRS; } AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute("", "topicref", null, null, "" + _indexOf(topic)); + attrs.addAttribute("", "topicref", "", "CDATA", "" + _indexOf(topic)); return attrs; } @@ -605,10 +608,10 @@ * the number of the provided Topic Maps construct. */ private Attributes _attributes(final Reifiable reifiable, int i) { - AttributesImpl attrs = new AttributesImpl(); - _addReifier(attrs, reifiable); - attrs.addAttribute("", "number", null, null, "" + i); - return attrs; + _attrs.clear(); + _addReifier(_attrs, reifiable); + _attrs.addAttribute("", "number", "", "CDATA", "" + i); + return _attrs; } /** @@ -622,7 +625,7 @@ private void _addReifier(final AttributesImpl attrs, final Reifiable reifiable) { Topic reifier = reifiable.getReifier(); if (reifier != null) { - attrs.addAttribute("", "reifier", null, null, "" + _indexOf(reifier)); + attrs.addAttribute("", "reifier", "", "CDATA", "" + _indexOf(reifier)); } } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -34,7 +34,7 @@ * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface ITopicMapReader { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapWriter.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapWriter.java 2008-08-17 10:03:04 UTC (rev 130) @@ -28,7 +28,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface ITopicMapWriter { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -29,7 +29,7 @@ * <a href="http://www.ontopia.net/download/ltm.html">Linear Topic Map Notation (LTM) 1.3</a>. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class LTMReader extends AbstractTopicMapReader { Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-08-17 10:03:04 UTC (rev 130) @@ -1,44 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim.mio; - -import org.tinytim.core.AbstractMapInputHandler; -import org.tmapi.core.TopicMap; - -/** - * {@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 final class MapInputHandler extends AbstractMapInputHandler { - - /** - * Intitializes a new <tt>MapInputHandler</tt> instance with the specified - * <tt>topicMap</tt>. - * - * @param topicMap The {@link TopicMap} instance. - */ - public MapInputHandler(final TopicMap topicMap) { - super(topicMap); - } - -} Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/SnelloReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/SnelloReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/SnelloReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -29,7 +29,7 @@ * <a href="http://www.semagia.com/tr/snello/1.0/">Snello Topic Maps (STM) 1.0</a>. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class SnelloReader extends AbstractTopicMapReader { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -28,7 +28,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class TMXMLReader extends AbstractTopicMapReader { Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2008-08-17 10:03:04 UTC (rev 130) @@ -0,0 +1,44 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.mio; + +import org.tinytim.core.AbstractMapInputHandler; +import org.tmapi.core.TopicMap; + +/** + * {@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 final class TinyTimMapInputHandler extends AbstractMapInputHandler { + + /** + * Intitializes a new <tt>MapInputHandler</tt> instance with the specified + * <tt>topicMap</tt>. + * + * @param topicMap The {@link TopicMap} instance. + */ + public TinyTimMapInputHandler(final TopicMap topicMap) { + super(topicMap); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLC14NWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLC14NWriter.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLC14NWriter.java 2008-08-17 10:03:04 UTC (rev 130) @@ -100,7 +100,7 @@ _out.write(' '); _out.write(names[i]); _out.write("=\""); - _out.write(_escapeAttributeValue(attrs.getValue("", names[i]))); + _writeEscapedAttributeValue(attrs.getValue("", names[i])); _out.write('"'); } _out.write('>'); @@ -136,7 +136,7 @@ * @throws IOException If an error occurs. */ public void characters(String data) throws IOException { - _out.write(_escapeTextContent(data)); + _writeEscapedTextContent(data); } /** @@ -144,29 +144,28 @@ * * @param value The value. * @return The escaped value. + * @throws IOException */ - private String _escapeTextContent(String value) { - char[] data = value.toCharArray(); - StringBuilder sb = new StringBuilder(data.length); - for (int i=0; i < data.length; i++) { - char c = data[i]; - if (c == '\r') { - sb.append("
"); + private void _writeEscapedTextContent(String value) throws IOException { + char[] ch = value.toCharArray(); + for (int i=0; i < ch.length; i++) { + switch(ch[i]) { + case '\r': + _out.write("
"); + break; + case '&': + _out.write("&"); + break; + case '<': + _out.write("<"); + break; + case '>': + _out.write(">"); + break; + default: + _out.write(ch[i]); } - else if (c == '&') { - sb.append("&"); - } - else if (c == '<') { - sb.append("<"); - } - else if (c == '>') { - sb.append(">"); - } - else { - sb.append(c); - } } - return sb.toString(); } /** @@ -174,34 +173,33 @@ * * @param value The value to escape. * @return The escaped value. + * @throws IOException */ - private String _escapeAttributeValue(String value) { - char[] data = value.toCharArray(); - StringBuilder sb = new StringBuilder(data.length); - for (int i=0; i<data.length; i++) { - char c = data[i]; - if (c == '\t') { - sb.append("	"); + private void _writeEscapedAttributeValue(String value) throws IOException { + char[] ch = value.toCharArray(); + for (int i=0; i<ch.length; i++) { + switch(ch[i]) { + case '\t': + _out.write("	"); + break; + case '\n': + _out.write("
"); + break; + case '\r': + _out.write("
"); + break; + case '\"': + _out.write("""); + break; + case '&': + _out.write("&"); + break; + case '<': + _out.write("<"); + break; + default: + _out.write(ch[i]); } - else if (c == '\n') { - sb.append("
"); - } - else if (c == '\r') { - sb.append("
"); - } - else if (c == '\"') { - sb.append("""); - } - else if (c == '&') { - sb.append("&"); - } - else if (c == '<') { - sb.append("<"); - } - else { - sb.append(c); - } } - return sb.toString(); } } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTMReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTMReader.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTMReader.java 2008-08-17 10:03:04 UTC (rev 130) @@ -33,7 +33,7 @@ * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class XTMReader extends AbstractTopicMapReader { Deleted: tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-08-16 17:12:35 UTC (rev 129) +++ tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-08-17 10:03:04 UTC (rev 130) @@ -1,324 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -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.MIOException; -import com.semagia.mio.helpers.Ref; - -/** - * Tests against the {@link org.tinytim.core.AbstractMapInputHandler}. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TestMapInputHandler extends TinyTimTestCase { - - private static final String _XSD_STRING = XSD.STRING.getReference(); - private static final String _XSD_ANY_URI = XSD.ANY_URI.getReference(); - - private MapInputHandler _handler; - - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - _handler = new MapInputHandler(_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.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. - } - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-16 17:12:25
|
Revision: 129 http://tinytim.svn.sourceforge.net/tinytim/?rev=129&view=rev Author: lheuer Date: 2008-08-16 17:12:35 +0000 (Sat, 16 Aug 2008) Log Message: ----------- - Notice that .cxtm is outdated for version > 1.5 Added Paths: ----------- tinytim-cxtm/THIS_PACKAGE_IS_NOT_USED_FOR_VERSIONS_LATER_THAN_1_5.txt Removed Paths: ------------- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java Added: tinytim-cxtm/THIS_PACKAGE_IS_NOT_USED_FOR_VERSIONS_LATER_THAN_1_5.txt =================================================================== --- tinytim-cxtm/THIS_PACKAGE_IS_NOT_USED_FOR_VERSIONS_LATER_THAN_1_5.txt (rev 0) +++ tinytim-cxtm/THIS_PACKAGE_IS_NOT_USED_FOR_VERSIONS_LATER_THAN_1_5.txt 2008-08-16 17:12:35 UTC (rev 129) @@ -0,0 +1,2 @@ +2008-08-16: The .cxtm package has been moved into the .mio package. +The Canonicalizer is the .mio.CXTMWriter and implements .mio.ITopicMapWriter Deleted: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java 2008-08-16 17:00:53 UTC (rev 128) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java 2008-08-16 17:12:35 UTC (rev 129) @@ -1,207 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim.cxtm; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.util.Arrays; - -import org.xml.sax.Attributes; -import org.xml.sax.helpers.AttributesImpl; - -/** - * Simple SAX-alike XML writer that respects canonical XML to some extend. - * - * This class is not meant to be a generic XML-C14N writer, but it should be - * good enough to support CXTM. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -final class CXTMWriter { - - public static final Attributes EMPTY_ATTRS = new AttributesImpl(); - - private static final char _NL = '\n'; - - private OutputStreamWriter _out; - - public CXTMWriter(OutputStream out) throws IOException { - _out = new OutputStreamWriter(out, "UTF-8"); - } - - /** - * Indicates the start of the serialization process. - * - * @throws IOException If an error occurs. - */ - public void startDocument() throws IOException { - // noop - } - - /** - * Indicates the end of the serialization process. - * - * @throws IOException If an error occurs. - */ - public void endDocument() throws IOException { - _out.flush(); - } - - /** - * Indicates the start of an element with the specified local name. - * - * @see #startElement(String, Attributes). - * - * @param localName The element's name. - * @throws IOException If an error occurs. - */ - public void startElement(String localName) throws IOException { - startElement(localName, EMPTY_ATTRS); - } - - /** - * Indicates the start of an element with the provided local name. - * - * The attributes written in canonical XML. - * - * @param localName The name of the element. - * @param attrs The element's attributes. - * @throws IOException If an error occurs. - */ - public void startElement(String localName, Attributes attrs) throws IOException { - String[] names = new String[attrs.getLength()]; - for (int i=0; i < names.length; i++) { - names[i] = attrs.getLocalName(i); - } - Arrays.sort(names); - _out.write('<'); - _out.write(localName); - for (int i=0; i < names.length; i++) { - _out.write(' '); - _out.write(names[i]); - _out.write("=\""); - _out.write(_escapeAttributeValue(attrs.getValue("", names[i]))); - _out.write('"'); - } - _out.write('>'); - } - - /** - * Indicates the end of an elemnt. - * - * @param localName The element's name. - * @throws IOException If an error occurs. - */ - public void endElement(String localName) throws IOException { - _out.write("</"); - _out.write(localName); - _out.write('>'); - } - - /** - * Writes a <tt>#x0A</tt> to the output. - * - * @throws IOException If an error occurs. - */ - public void newline() throws IOException { - _out.write(_NL); - } - - /** - * Writes the specified characters to the output. - * - * The data is written according to the rules of canonicalized XML. - * - * @param data The data to write. - * @throws IOException If an error occurs. - */ - public void characters(String data) throws IOException { - _out.write(_escapeTextContent(data)); - } - - /** - * Escapes the data according to the canonical XML rules. - * - * @param value The value. - * @return The escaped value. - */ - private String _escapeTextContent(String value) { - char[] data = value.toCharArray(); - StringBuilder sb = new StringBuilder(data.length); - for (int i=0; i < data.length; i++) { - char c = data[i]; - if (c == '\r') { - sb.append("
"); - } - else if (c == '&') { - sb.append("&"); - } - else if (c == '<') { - sb.append("<"); - } - else if (c == '>') { - sb.append(">"); - } - else { - sb.append(c); - } - } - return sb.toString(); - } - - /** - * Escapes the attribute's value according to canonical XML. - * - * @param value The value to escape. - * @return The escaped value. - */ - private String _escapeAttributeValue(String value) { - char[] data = value.toCharArray(); - StringBuilder sb = new StringBuilder(data.length); - for (int i=0; i<data.length; i++) { - char c = data[i]; - if (c == '\t') { - sb.append("	"); - } - else if (c == '\n') { - sb.append("
"); - } - else if (c == '\r') { - sb.append("
"); - } - else if (c == '\"') { - sb.append("""); - } - else if (c == '&') { - sb.append("&"); - } - else if (c == '<') { - sb.append("<"); - } - else { - sb.append(c); - } - } - return sb.toString(); - } -} Deleted: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-08-16 17:00:53 UTC (rev 128) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-08-16 17:12:35 UTC (rev 129) @@ -1,1237 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim.cxtm; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.AbstractSet; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Set; -import java.util.logging.Logger; - -import org.tinytim.core.TopicMapImpl; -import org.tinytim.internal.utils.CollectionFactory; -import org.tinytim.utils.DuplicateRemovalUtils; -import org.tinytim.voc.TMDM; -import org.tinytim.voc.XSD; -import org.tmapi.core.Association; -import org.tmapi.core.Construct; -import org.tmapi.core.DatatypeAware; -import org.tmapi.core.Locator; -import org.tmapi.core.Name; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Reifiable; -import org.tmapi.core.Role; -import org.tmapi.core.Scoped; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicInUseException; -import org.tmapi.core.TopicMap; -import org.tmapi.core.Typed; -import org.tmapi.core.Variant; -import org.tmapi.index.TypeInstanceIndex; - -import org.xml.sax.Attributes; -import org.xml.sax.helpers.AttributesImpl; - -/** - * Provides serialization of topic maps into Canonical XTM (CXTM). - * <p> - * CXTM is a format that guarantees that two equivalent Topic Maps Data Model - * instances [ISO/IEC 13250-2] will always produce byte-by-byte identical - * serializations, and that non-equivalent instances will always produce - * different serializations. - * </p> - * <p> - * See <a href="http://www.isotopicmaps.org/cxtm/">http://www.isotopicmaps.org/cxtm/</a> - * for details. - * </p> - * <p> - * <em>CAUTION</em>: This class implements the - * <a href="http://www.isotopicmaps.org/cxtm/">CXTM draft dtd. 2008-05-15</a>, - * the output may change in the future. - * </p> - * <p> - * The canonicalizer IS NOT a generic TMAPI-compatible implementation. It - * requires tinyTiM. - * </p> - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public final class Canonicalizer { - - private static final Logger LOG = Logger.getLogger(Canonicalizer.class.getName()); - - private static final Role[] _EMPTY_ROLES = new Role[0]; - - private Topic _type; - private Topic _instance; - private Topic _typeInstance; - - private CXTMWriter _out; - private final String _normBase; - private Map<Construct, Integer> _construct2Id; - private Map<Topic, List<Role>> _topic2Roles; - private Map<Locator, String> _locator2Norm; - - private Comparator<Topic> _topicComparator; - private Comparator<Association> _assocComparator; - private Comparator<Role> _roleComparator; - private Comparator<Occurrence> _occComparator; - private Comparator<Name> _nameComparator; - private Comparator<Variant> _variantComparator; - private Comparator<Set<Locator>> _locSetComparator; - private Comparator<Locator> _locComparator; - private Comparator<Set<Topic>> _scopeComparator; - - private Map<Association, Role[]> _assoc2Roles; - - /** - * Creates a canonicalizer. - * - * @param out The stream the CXTM is written onto. - * @param baseLocator The base locator which is used to resolve IRIs against. - * @throws IOException If an error occurs. - */ - public Canonicalizer(OutputStream out, String baseLocator) throws IOException { - if (baseLocator == null) { - throw new IllegalArgumentException("The base locator must not be null"); - } - _out = new CXTMWriter(out); - _normBase = _normalizeBaseLocator(baseLocator); - _topicComparator = new TopicComparator(); - _assocComparator = new AssociationComparator(); - _roleComparator = new RoleComparator(); - _occComparator = new OccurrenceComparator(); - _nameComparator = new NameComparator(); - _variantComparator = new VariantComparator(); - _locSetComparator = new LocatorSetComparator(); - _locComparator = new LocatorComparator(); - _scopeComparator = new ScopeComparator(); - } - - /** - * Serializes the specified <tt>topicMap</tt> into the CXTM format. - * <p> - * <em>CAUTION</em>: This method MAY modify the topic map since duplicate - * Topic Maps constructs (if any) are removed in advance. - * </p> - * - * @param topicMap The topic map to serialize. - * @throws IOException If an error occurs. - */ - public void write(TopicMap topicMap) throws IOException { - DuplicateRemovalUtils.removeDuplicates(topicMap); - _construct2Id = CollectionFactory.createIdentityMap(); - _locator2Norm = CollectionFactory.createIdentityMap(); - _assoc2Roles = CollectionFactory.createIdentityMap(); - _topic2Roles = CollectionFactory.createIdentityMap(); - TypeInstanceIndex typeInstanceIndex = ((TopicMapImpl) topicMap).getIndexManager().getTypeInstanceIndex(); - if (!typeInstanceIndex.isAutoUpdated()) { - typeInstanceIndex.reindex(); - } - Topic[] topics = _fetchTopics(topicMap, typeInstanceIndex); - Association[] assocs = _fetchAssociations(topicMap, typeInstanceIndex); - typeInstanceIndex.close(); - _createIndex(topics, assocs); - _out.startDocument(); - AttributesImpl attrs = new AttributesImpl(); - _addReifier(attrs, topicMap); - _out.startElement("topicMap", attrs); - _out.newline(); - _writeItemIdentifiers(topicMap); - for (Topic topic: topics) { - _writeTopic(topic); - } - for (Association assoc: assocs) { - _writeAssociation(assoc); - } - _out.endElement("topicMap"); - _out.newline(); - _out.endDocument(); - _out = null; - _construct2Id = null; - _locator2Norm = null; - _assoc2Roles = null; - _topic2Roles = null; - } - - /** - * Returns an unsorted array of topics which should be included into - * the output. - * - * This method may return more topics than {@link TopicMap#getTopics()} - * since this method creates virtual topics to model type-instance - * relationships properly. - * - * @param topicMap The topic map from which the topic should be serialized. - * @param idx A (upto date) type instance index. - * @return All topics which must be included into the output. - */ - private Topic[] _fetchTopics(final TopicMap topicMap, final TypeInstanceIndex idx) { - Collection<Topic> types = idx.getTopicTypes(); - if (types.isEmpty()) { - Set<Topic> topics = topicMap.getTopics(); - return topics.toArray(new Topic[topics.size()]); - } - else { - List<Topic> topics = CollectionFactory.createList(topicMap.getTopics()); - TopicMapImpl tm = (TopicMapImpl) topicMap; - _typeInstance = _getTopicBySubjectIdentifier(tm, topics, TMDM.TYPE_INSTANCE); - _type = _getTopicBySubjectIdentifier(tm, topics, TMDM.TYPE); - _instance = _getTopicBySubjectIdentifier(tm, topics, TMDM.INSTANCE); - return topics.toArray(new Topic[topics.size()]); - } - } - - /** - * Returns a topic by its subject identifier. If the topic is null, a - * {@link TypeInstanceTopic} is created, added to the <tt>topics</tt> - * and returned. - * - * @param tm The topic map to fetch the topic from. - * @param topics A modifiable collection of topics. - * @param sid The subject identifier. - * @return A topic with the specified subject identifier. - */ - private Topic _getTopicBySubjectIdentifier(TopicMap tm, Collection<Topic> topics, Locator sid) { - Topic topic = tm.getTopicBySubjectIdentifier(sid); - if (topic == null) { - topic = new TypeInstanceTopic(sid); - topics.add(topic); - } - return topic; - } - - /** - * Returns an unsorted array of associations which should be serialized. - * - * This method may return more association than {@link TopicMap#getAssociations()} - * since this method may create virtual associations which are used to - * model type-instance relationships properly. - * - * @param tm The topic map from which the associations should be serialized. - * @param idx A (upto date) type instance index. - * @return An unsorted array of associations which must be included into the output. - */ - private Association[] _fetchAssociations(final TopicMap tm, final TypeInstanceIndex idx) { - Collection<Topic> types = idx.getTopicTypes(); - if (types.isEmpty()) { - Set<Association> assocs = tm.getAssociations(); - return assocs.toArray(new Association[assocs.size()]); - } - else { - List<Association> assocs = CollectionFactory.createList(tm.getAssociations()); - for (Topic type: types) { - for (Topic instance: idx.getTopics(type)) { - assocs.add(new TypeInstanceAssociation(type, instance)); - } - } - return assocs.toArray(new Association[assocs.size()]); - } - } - - /** - * Creates the index on which the canonicalizer operates. - * - * As sideeffect, the provided topic and association arrays get sorted. - * - * @param topics An array of topics. - * @param assocs An array of associations. - */ - private void _createIndex(Topic[] topics, Association[] assocs) { - Arrays.sort(topics, _topicComparator); - Topic topic = null; - for (int i=0; i < topics.length; i++) { - topic = topics[i]; - _construct2Id.put(topic, Integer.valueOf(i+1)); - } - Arrays.sort(assocs, _assocComparator); - Association assoc = null; - for (int i=0; i < assocs.length; i++) { - assoc = assocs[i]; - _construct2Id.put(assoc, Integer.valueOf(i+1)); - Set<Role> roles_ = assoc.getRoles(); - Role[] roles = roles_.toArray(new Role[roles_.size()]); - Arrays.sort(roles, _roleComparator); - _assoc2Roles.put(assoc, roles); - for (int j=0; j < roles.length; j++) { - _construct2Id.put(roles[j], Integer.valueOf(j+1)); - } - } - } - - /** - * Returns a sorted array of roles of the provided association. - * - * @param assoc The association to retrieve the roles from. - * @return A (maybe empty) sorted array of roles. - */ - private Role[] _getRoles(final Association assoc) { - Role[] roles = _assoc2Roles.get(assoc); - return roles != null ? roles : _EMPTY_ROLES; - } - - /** - * Returns a sorted array of names of the provided topic. - * - * @param topic The topic to retrieve the names from. - * @return A (maybe empty) sorted array of names. - */ - private Name[] _getNames(final Topic topic) { - Set<Name> names_ = topic.getNames(); - Name[] names = names_.toArray(new Name[names_.size()]); - Arrays.sort(names, _nameComparator); - return names; - } - - /** - * Returs a sorted array of variants of the provided name. - * - * @param name The name to retrieve the variants from. - * @return A (maybe empty) sorted array of variants. - */ - private Variant[] _getVariants(final Name name) { - Set<Variant> variants_ = name.getVariants(); - Variant[] variants = variants_.toArray(new Variant[variants_.size()]); - Arrays.sort(variants, _variantComparator); - return variants; - } - - /** - * Returns a sorted array of occurrences of the provided topic. - * - * @param topic The topic to retrieve the occurrences from. - * @return A (maybe emtpy) sorted array of occurrences. - */ - private Occurrence[] _getOccurrences(final Topic topic) { - Set<Occurrence> occs_ = topic.getOccurrences(); - Occurrence[] occs = occs_.toArray(new Occurrence[occs_.size()]); - Arrays.sort(occs, _occComparator); - return occs; - } - - /** - * Returns the index of the provided Topic Maps construct. - * - * The "index" is <cite>"[...] the string encoding of the position of this - * information item in the canonically ordered list of the values from - * that set".</cite> (CXTM 3.20 Constructing the number attribute). - * - * @param tmo The Topic Maps construct to return the index of. - * @return The index of the Topic Maps construct. - */ - private int _indexOf(final Construct tmo) { - return _construct2Id.get(tmo).intValue(); - } - - /** - * Serializes the <tt>topic</tt>. - * - * @param topic The topic to serialize. - * @throws IOException If an error occurs. - */ - private void _writeTopic(final Topic topic) throws IOException { - AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute("", "number", null, null, "" +_indexOf(topic)); - _out.startElement("topic", attrs); - _out.newline(); - _writeLocatorSet("subjectIdentifiers", topic.getSubjectIdentifiers()); - _writeLocatorSet("subjectLocators", topic.getSubjectLocators()); - _writeItemIdentifiers(topic); - Name[] names = _getNames(topic); - for (int i=0; i < names.length; i++) { - _writeName(names[i], i+1); - } - Occurrence[] occs = _getOccurrences(topic); - for (int i=0; i < occs.length; i++) { - _writeOccurrence(occs[i], i+1); - } - List<Role> roles_ = CollectionFactory.createList(topic.getRolesPlayed()); - List<Role> alienRoles = _topic2Roles.get(topic); - if (alienRoles != null) { - roles_.addAll(alienRoles); - } - Role[] roles = roles_.toArray(new Role[roles_.size()]); - Arrays.sort(roles, _roleComparator); - AttributesImpl roleAttrs = new AttributesImpl(); - StringBuilder sb = new StringBuilder(20); - for (int i=0; i < roles.length; i++) { - sb.append("association.") - .append(_indexOf(roles[i].getParent())) - .append(".role.") - .append(_indexOf(roles[i])); - roleAttrs.addAttribute("", "ref", null, null, sb.toString()); - _out.startElement("rolePlayed", roleAttrs); - _out.endElement("rolePlayed"); - _out.newline(); - sb.setLength(0); - roleAttrs.clear(); - } - _out.endElement("topic"); - _out.newline(); - } - - /** - * Serializes an association. - * - * @param assoc The association to serialize. - * @throws IOException If an error occurs. - */ - private void _writeAssociation(final Association assoc) throws IOException { - _out.startElement("association", _attributes(assoc, _indexOf(assoc))); - _out.newline(); - _writeType(assoc); - for (Role role: _getRoles(assoc)) { - _out.startElement("role", _attributes(role, _indexOf(role))); - _out.newline(); - _out.startElement("player", _topicRef(role.getPlayer())); - _out.endElement("player"); - _out.newline(); - _writeType(role); - _writeItemIdentifiers(role); - _out.endElement("role"); - _out.newline(); - } - _writeScope(assoc); - _writeItemIdentifiers(assoc); - _out.endElement("association"); - _out.newline(); - } - - /** - * Serializes an occurrence. - * - * @param occ The occurrence to serialize. - * @param pos The position of the occurrence within the parent container. - * @throws IOException If an error occurs. - */ - private void _writeOccurrence(final Occurrence occ, int pos) throws IOException { - _out.startElement("occurrence", _attributes(occ, pos)); - _out.newline(); - _writeDatatyped(occ); - _writeType(occ); - _writeScope(occ); - _writeItemIdentifiers(occ); - _out.endElement("occurrence"); - _out.newline(); - } - - /** - * Writes the value/datatype pair of an occurrence or variant. - * - * @param obj The construct to serialize. - * @throws IOException If an error occurs. - */ - private void _writeDatatyped(final DatatypeAware obj) throws IOException { - final String value = XSD.ANY_URI.equals(obj.getDatatype()) - ? _normalizeLocator(obj.locatorValue()) - : obj.getValue(); - _out.startElement("value"); - _out.characters(value); - _out.endElement("value"); - _out.newline(); - _out.startElement("datatype"); - _out.characters(_normalizeLocator(obj.getDatatype())); - _out.endElement("datatype"); - _out.newline(); - } - - /** - * Serializes a topic name. - * - * @param name The name to serialize. - * @param pos The position of the name within the parent container. - * @throws IOException If an error occurs. - */ - private void _writeName(final Name name, int pos) throws IOException { - _out.startElement("name", _attributes(name, pos)); - _out.newline(); - _out.startElement("value"); - _out.characters(name.getValue()); - _out.endElement("value"); - _out.newline(); - _writeType(name); - _writeScope(name); - Variant[] variants = _getVariants(name); - Variant variant = null; - for (int i=0; i<variants.length; i++) { - variant = variants[i]; - _out.startElement("variant", _attributes(variant, i+1)); - _out.newline(); - _writeDatatyped(variant); - _writeScope(variant); - _writeItemIdentifiers(variant); - _out.endElement("variant"); - _out.newline(); - } - _writeItemIdentifiers(name); - _out.endElement("name"); - _out.newline(); - } - - /** - * Serializes the type of a typed Topic Maps construct. - * - * @param typed The typed Topic Maps construct from which the type should be - * serialized. - * @throws IOException If an error occurs. - */ - private void _writeType(final Typed typed) throws IOException { - _out.startElement("type", _topicRef(typed.getType())); - _out.endElement("type"); - _out.newline(); - } - - /** - * Serializes the scope of a scoped Topic Maps construct. - * - * If the scope is unconstrained, this method does nothing. - * - * @param scoped The scoped Topic Maps construct. - * @throws IOException If an error occurs. - */ - private void _writeScope(final Scoped scoped) throws IOException { - Set<Topic> scope = scoped.getScope(); - if (scope.isEmpty()) { - return; - } - _out.startElement("scope"); - _out.newline(); - Topic[] themes = scope.toArray(new Topic[scope.size()]); - Arrays.sort(themes, _topicComparator); - for (int i=0; i < themes.length; i++) { - _out.startElement("scopingTopic", _topicRef(themes[i])); - _out.endElement("scopingTopic"); - _out.newline(); - } - _out.endElement("scope"); - _out.newline(); - } - - /** - * Serializes a locator. - * - * A normalized locator value is created which is serialized. - * - * @param loc The locator to serialize. - * @throws IOException If an error occurs. - */ - private void _writeLocator(final Locator loc) throws IOException { - _out.startElement("locator"); - _out.characters(_normalizeLocator(loc)); - _out.endElement("locator"); - _out.newline(); - } - - /** - * Serializes the item identifiers of the specified Topic Maps construct. - * - * @param tmo The Topic Maps construct to take the item identifiers from. - * @throws IOException If an error occurs. - */ - private void _writeItemIdentifiers(final Construct tmo) throws IOException { - _writeLocatorSet("itemIdentifiers", tmo.getItemIdentifiers()); - } - - /** - * Serializes the <tt>locators</tt> using the <tt>localName</tt> as - * element name. - * - * If the set of <tt>locators</tt> is empty, this method does nothing. - * - * @param localName The element's name. - * @param locators The locators to serialize. - * @throws IOException If an error occurs. - */ - private void _writeLocatorSet(final String localName, final Set<Locator> locators) throws IOException { - if (locators.isEmpty()) { - return; - } - Locator[] locs = locators.toArray(new Locator[locators.size()]); - Arrays.sort(locs, _locComparator); - _out.startElement(localName); - _out.newline(); - for (int i=0; i < locs.length; i++) { - _writeLocator(locs[i]); - } - _out.endElement(localName); - _out.newline(); - } - - /** - * Returns attributes which contains a reference to the provided topic. - * - * @param topic The topic to which the reference should point to. - * @return Attributes with a topic reference. - */ - private Attributes _topicRef(final Topic topic) { - if (topic == null) { - _reportInvalid("The topic reference is null"); - return CXTMWriter.EMPTY_ATTRS; - } - AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute("", "topicref", null, null, "" + _indexOf(topic)); - return attrs; - } - - /** - * Returns attributes which contain the reifier (if any) and the number - * of the provided Topic Maps construct (not a topic). - * - * @param reifiable The Topic Maps construct. - * @param The position of the reifiable within the parent container. - * @return Attributes which contain a reference to the reifier (if any) and - * the number of the provided Topic Maps construct. - */ - private Attributes _attributes(final Reifiable reifiable, int i) { - AttributesImpl attrs = new AttributesImpl(); - _addReifier(attrs, reifiable); - attrs.addAttribute("", "number", null, null, "" + i); - return attrs; - } - - /** - * Adds a reference to the reifier of the Topic Maps construct to the - * provided attributes. If the Topic Maps construct has no reifier, the - * provided attributes are not modified. - * - * @param attrs The attributes. - * @param reifiable The reifiable Topic Maps construct. - */ - private void _addReifier(final AttributesImpl attrs, final Reifiable reifiable) { - Topic reifier = reifiable.getReifier(); - if (reifier != null) { - attrs.addAttribute("", "reifier", null, null, "" + _indexOf(reifier)); - } - } - - /** - * Normalizes the locator according to CXTM 3.19. - * - * @param locator The locator to normalize. - * @return A normalized representation of the locator. - */ - private String _normalizeLocator(final Locator locator) { - String normLoc = _locator2Norm.get(locator); - if (normLoc != null) { - return normLoc; - } - normLoc = locator.getReference(); - if (normLoc.startsWith(_normBase)) { - normLoc = normLoc.substring(_normBase.length()); - } - else { - int i = 0; - int slashPos = -1; - final int max = Math.min(_normBase.length(), normLoc.length()); - while(i < max && _normBase.charAt(i) == normLoc.charAt(i)) { - if (_normBase.charAt(i) == '/') { - slashPos = i; - } - i++; - } - if (slashPos > -1) { - normLoc = normLoc.substring(slashPos); - } - } - if (normLoc.startsWith("/")) { - normLoc = normLoc.substring(1); - } - _locator2Norm.put(locator, normLoc); - return normLoc; - } - - /** - * Normalizes the base locator according to the following procedure - * (CXTM 3.19 - 1.): - * <cite>[...] the base locator with any fragment identifier and query - * removed and any trailing "/" character removed.[...]</cite> - * - * @param baseLocator - * @return - */ - private static String _normalizeBaseLocator(final String baseLocator) { - String loc = baseLocator; - int i = loc.indexOf('#'); - if (i > 0) { - loc = loc.substring(0, i); - } - i = loc.indexOf('?'); - if (i > 0) { - loc = loc.substring(0, i); - } - if (loc.endsWith("/")) { - loc = loc.substring(0, loc.length()-1); - } - return loc; - } - - /** - * Writes a warning msg to the log. - * - * This method is used to inform the user that the serialized topic map - * is not valid acc. to CXTM. - * - * @param msg The warning message. - */ - private static void _reportInvalid(final String msg) { - LOG.warning("Invalid CXTM: '" + msg + "'"); - } - - - /* - * Comparators. - */ - - private final class TopicComparator implements Comparator<Topic> { - - public int compare(Topic o1, Topic o2) { - if (o1 == o2) { - return 0; - } - if (o1 != null && o2 == null) { - _reportInvalid("Comparing topics where one topic is null"); - return +1; - } - else if (o1 == null && o2 != null) { - _reportInvalid("Comparing topics where one topic is null"); - return -1; - } - int res = _locSetComparator.compare(o1.getSubjectIdentifiers(), o2.getSubjectIdentifiers()); - if (res == 0) { - res = _locSetComparator.compare(o1.getSubjectLocators(), o2.getSubjectLocators()); - if (res == 0) { - res = _locSetComparator.compare(o1.getItemIdentifiers(), o2.getItemIdentifiers()); - } - } - return res; - } - } - - /** - * Abstract comparator that provides some utility methods which handle common - * comparisons. - */ - private abstract class AbstractComparator<T> implements Comparator<T> { - int compareString(String o1, String o2) { - if (o1 == null && o2 != null) { - _reportInvalid("The first string value is null"); - return -1; - } - if (o1 != null && o2 == null) { - _reportInvalid("The second string value is null"); - return +1; - } - return o1.compareTo(o2); - } - /** - * Extracts the type of the typed Topic Maps constructs and compares - * the topics. - * - * @param o1 The first typed Topic Maps construct. - * @param o2 The second typed Topic Maps construct. - * @return A negative integer, zero, or a positive integer as the - * first argument is less than, equal to, or greater than the - * second. - */ - int compareType(Typed o1, Typed o2) { - return _topicComparator.compare(o1.getType(), o2.getType()); - } - /** - * Extracts the scope of the scoped Topic Maps constructs and compares - * them. - * - * @param o1 The first scoped Topic Maps construct. - * @param o2 The second scoped Topic Maps construct. - * @return A negative integer, zero, or a positive integer as the - * first argument is less than, equal to, or greater than the - * second. - */ - int compareScope(Scoped o1, Scoped o2) { - return _scopeComparator.compare(o1.getScope(), o2.getScope()); - } - } - - /** - * Enhances the {@link AbstractComparator} with a method to compare the - * value and datatype of an occurrence or variant. - */ - private abstract class AbstractDatatypeAwareComparator<T> extends AbstractComparator<T> { - /** - * Compares the value and datatype of the occurrences / variants. - * - * @param o1 The first occurrence / variant. - * @param o2 The second occurrence / variant. - * @return A negative integer, zero, or a positive integer as the - * first argument is less than, equal to, or greater than the - * second. - */ - int _compareValueDatatype(DatatypeAware o1, DatatypeAware o2) { - int res = compareString(o1.getValue(), o2.getValue()); - if (res == 0) { - res = compareString(o1.getDatatype().getReference(), o2.getDatatype().getReference()); - } - return res; - } - } - - /** - * Canonical sort order: - * 1. [type] - * 2. [roles] - * 3. [scope] - * 4. [parent] - */ - private final class AssociationComparator extends AbstractComparator<Association> { - - private Comparator<Set<Role>> _roleSetComparator; - - AssociationComparator() { - _roleSetComparator = new RoleSetComparator(); - } - - public int compare(Association o1, Association o2) { - if (o1 == o2) { - return 0; - } - int res = compareType(o1, o2); - if (res == 0) { - res = _roleSetComparator.compare(o1.getRoles(), o2.getRoles()); - if (res == 0) { - res = compareScope(o1, o2); - } - } - return res; - } - } - - /** - * Role comparator which ignores the parent association. This comparator - * is meant to be used for roles where the parent is known to be equal or - * unequal. - */ - private class RoleIgnoreParentComparator extends AbstractComparator<Role> { - - public int compare(Role o1, Role o2) { - if (o1 == o2) { - return 0; - } - int res = _topicComparator.compare(o1.getPlayer(), o2.getPlayer()); - if (res == 0) { - res = compareType(o1, o2); - } - return res; - } - } - - /** - * Canonical sort order: - * 1. [player] - * 2. [type] - * 3. [parent] - */ - private final class RoleComparator extends RoleIgnoreParentComparator { - - public int compare(Role o1, Role o2) { - if (o1 == o2) { - return 0; - } - int res = super.compare(o1, o2); - if (res == 0) { - res = _assocComparator.compare(o1.getParent(), o2.getParent()); - } - return res; - } - } - - /** - * Canonical sort order: - * 1. [value] - * 2. [datatype] - * 3. [type] - * 4. [scope] - * 5. [parent] - */ - private final class OccurrenceComparator extends AbstractDatatypeAwareComparator<Occurrence> { - - public int compare(Occurrence o1, Occurrence o2) { - if (o1 == o2) { - return 0; - } - int res = _compareValueDatatype(o1, o2); - if (res == 0) { - res = compareType(o1, o2); - if (res == 0) { - res = compareScope(o1, o2); - } - } - return res; - } - - } - - /** - * Canonical sort order: - * 1. [value] - * 2. [type] - * 3. [scope] - * 4. [parent] - */ - private final class NameComparator extends AbstractComparator<Name> { - - public int compare(Name o1, Name o2) { - if (o1 == o2) { - return 0; - } - int res = compareString(o1.getValue(), o2.getValue()); - if (res == 0) { - res = compareType(o1, o2); - if (res == 0) { - res = compareScope(o1, o2); - } - } - return res; - } - } - - /** - * Canonical sort order: - * 1. [value] - * 2. [datatype] - * 3. [scope] - * 4. [parent] - */ - private final class VariantComparator extends AbstractDatatypeAwareComparator<Variant> { - - public int compare(Variant o1, Variant o2) { - if (o1 == o2) { - return 0; - } - int res = _compareValueDatatype(o1, o2); - if (res == 0) { - res = compareScope(o1, o2); - } - return res; - } - } - - /** - * Comparator which compares the size of the provided set. - * - * Iff the size of the sets are equal, another comparison method is used - * to compare the content of the sets. - */ - private abstract class AbstractSetComparator<T> implements Comparator<Set<T>> { - - public int compare(Set<T> o1, Set<T> o2) { - int s1 = o1.size(); - int s2 = o2.size(); - int res = s1 - s2; - if (res == 0) { - res = compareContent(o1, o2, s1); - } - return res; - } - - /** - * Called iff the size of the sets is equal. - * - * This method is used to compare the content of the sets. - * - * @param o1 The first set. - * @param o2 The second set. - * @param size The size of the set(s). - * @return A negative integer, zero, or a positive integer as the - * first argument is less than, equal to, or greater than the - * second. - */ - abstract int compareContent(Set<T> o1, Set<T> o2, int size); - } - - /** - * Compares role sets. The parent of the roles is ignored! - */ - private final class RoleSetComparator extends AbstractSetComparator<Role> { - - private RoleIgnoreParentComparator _roleCmp; - - RoleSetComparator() { - _roleCmp = new RoleIgnoreParentComparator(); - } - - @Override - int compareContent(Set<Role> o1, Set<Role> o2, - int size) { - int res = 0; - Role[] roles1 = o1.toArray(new Role[size]); - Role[] roles2 = o2.toArray(new Role[size]); - Arrays.sort(roles1, _roleCmp); - Arrays.sort(roles2, _roleCmp); - for (int i=0; i < size && res == 0; i++) { - res = _roleCmp.compare(roles1[i], roles2[i]); - } - return res; - } - - } - - /** - * Compares the scope of two scoped Topic Maps constructs. - */ - private final class ScopeComparator extends AbstractSetComparator<Topic> { - - @Override - int compareContent(Set<Topic> o1, Set<Topic> o2, int size) { - int res = 0 ; - Topic[] topics1 = o1.toArray(new Topic[size]); - Topic[] topics2 = o2.toArray(new Topic[size]); - Arrays.sort(topics1, _topicComparator); - Arrays.sort(topics2, _topicComparator); - for (int i=0; i < size && res == 0; i++) { - res = _topicComparator.compare(topics1[i], topics2[i]); - } - return res; - } - - } - - /** - * Comparator for sets of {@link org.tmapi.core.Locator}s. - */ - private final class LocatorSetComparator extends AbstractSetComparator<Locator> { - - @Override - int compareContent(Set<Locator> o1, Set<Locator> o2, int size) { - int res = 0; - Locator[] locs1 = o1.toArray(new Locator[size]); - Locator[] locs2 = o2.toArray(new Locator[size]); - Arrays.sort(locs1, _locComparator); - Arrays.sort(locs2, _locComparator); - for (int i=0; i < size && res == 0; i++) { - res = _locComparator.compare(locs1[i], locs2[i]); - } - return res; - } - } - - /** - * Compares {@link org.tmapi.core.Locator}s. - */ - private final class LocatorComparator implements Comparator<Locator> { - - public int compare(Locator o1, Locator o2) { - if (o1 == o2) { - return 0; - } - return _normalizeLocator(o1).compareTo(_normalizeLocator(o2)); - } - - } - - - /* - * Helper classes to treat type-instance relationships, modelled as property - * of a topic, as associations. - */ - - private final class TypeInstanceTopic implements Topic { - - private final Set<Locator> _sids; - - TypeInstanceTopic(Locator sid) { - _sids = Collections.singleton(sid); - } - - public Set<Locator> getSubjectIdentifiers() { - return _sids; - } - - public void addItemIdentifier(Locator arg0) { } - public void addSubjectIdentifier(Locator arg0) {} - public void addSubjectLocator(Locator arg0) {} - public void addType(Topic arg0) {} - public Set<Occurrence> getOccurrences() { return Collections.emptySet(); } - public Reifiable getReified() { return null; } - public Set<Role> getRolesPlayed() { return Collections.emptySet(); } - public Set<Locator> getSubjectLocators() { return Collections.emptySet(); } - public Set<Name> getNames() { return Collections.emptySet(); } - public Set<Topic> getTypes() { return null; } - public void mergeIn(Topic arg0) { } - public void remove() throws TopicInUseException { } - public void removeSubjectIdentifier(Locator arg0) { } - public void removeSubjectLocator(Locator arg0) { } - public void removeType(Topic arg0) { } - public String getId() { return null; } - public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } - public TopicMap getTopicMap() { return null; } - public void removeItemIdentifier(Locator arg0) { } - public Name createName(String value, Collection<Topic> scope) { return null; } - public Name createName(String value, Topic... scope) {return null;} - public Name createName(Topic type, String value, Collection<Topic> scope) { return null; } - public Name createName(Topic type, String value, Topic... scope) { return null; } - public Occurrence createOccurrence(Topic type, Locator value, Collection<Topic> scope) { return null;} - public Occurrence createOccurrence(Topic type, Locator value, Topic... scope) {return null;} - public Occurrence createOccurrence(Topic type, String value, Collection<Topic> scope) { return null; } - public Occurrence createOccurrence(Topic type, String value, Locator datatype, Collection<Topic> scope) { return null; } - public Occurrence createOccurrence(Topic type, String value, Locator datatype, Topic... scope) { return null; } - public Occurrence createOccurrence(Topic type, String value, Topic... scope) { return null; } - public Set<Name> getNames(Topic type) { return null; } - public Set<Occurrence> getOccurrences(Topic type) { return null;} - public TopicMap getParent() { return null; } - public Set<Role> getRolesPlayed(Topic type, Topic assocType) { return null; } - public Set<Role> getRolesPlayed(Topic type) { return null; } - - } - - /** - * Used to represent type-instance relationships which are modelled as - * [type] property of topics. - */ - private final class TypeInstanceAssociation implements Association { - - final Set<Role> _roles; - - TypeInstanceAssociation(Topic type, Topic instance) { - Role typeRole = new TypeInstanceRole(this, _type, type); - Role instanceRole = new TypeInstanceRole(this, _instance, instance); - _roles = new TypeInstanceRoleSet(typeRole, instanceRole); - } - - public Set<Role> getRoles() { - return _roles; - } - - public Topic getType() { - return _typeInstance; - } - - public Set<Topic> getRoleTypes() { return null; } - public Set<Role> getRoles(Topic type) { return null; } - public void setReifier(Topic reifier) { } - public void addItemIdentifier(Locator itemIdentifier) { } - public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } - public TopicMap getParent() { return null; } - public void removeItemIdentifier(Locator itemIdentifier) { } - public Role createRole(Topic arg0, Topic arg1) { return null; } - public Topic getReifier() { return null; } - public void remove() {} - public void setType(Topic arg0) {} - public void addTheme(Topic arg0) {} - public Set<Topic> getScope() { return Collections.emptySet(); } - public void removeTheme(Topic arg0) {} - public String getId() { return null; } - public TopicMap getTopicMap() { return null; } - } - - /** - * Immutable association role. - */ - private class TypeInstanceRole implements Role { - private final Topic _type; - private final Topic _player; - private final Association _parent; - - TypeInstanceRole(Association parent, Topic type, Topic player) { - _type = type; - _player = player; - _parent = parent; - List<Role> roles = _topic2Roles.get(player); - if (roles == null) { - roles = CollectionFactory.createList(); - _topic2Roles.put(player, roles); - } - roles.add(this); - } - - public Topic getType() { - return _type; - } - - public Topic getPlayer() { - return _player; - } - - public void setReifier(Topic reifier) { } - public void addItemIdentifier(Locator itemIdentifier) { } - public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } - public Association getParent() { return _parent; } - public void removeItemIdentifier(Locator itemIdentifier) { } - public Association getAssociation() { return _parent; } - public Topic getReifier() { return null; } - public void remove() {} - public void setPlayer(Topic arg0) {} - public void setType(Topic arg0) {} - public String getId() { return null; } - public TopicMap getTopicMap() { return null; } - } - - /** - * Immutable 'set' of two roles. - */ - private static class TypeInstanceRoleSet extends AbstractSet<Role> { - - private final Role _role1; - private final Role _role2; - - TypeInstanceRoleSet(Role role1, Role role2) { - _role1 = role1; - _role2 = role2; - } - - @Override - public Iterator<Role> iterator() { - return new TypeInstanceRoleSetIterator(); - } - - @Override - public int size() { - return 2; - } - - private class TypeInstanceRoleSetIterator implements Iterator<Role> { - - private int _idx; - - public boolean hasNext() { - return _idx < 2; - } - - public Role next() { - if (_idx > 1) { - throw new NoSuchElementException(); - } - return 0 == _idx++ ? _role1 : _role2; - } - - public void remove() { - new UnsupportedOperationException(); - } - } - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-16 17:00:45
|
Revision: 128 http://tinytim.svn.sourceforge.net/tinytim/?rev=128&view=rev Author: lheuer Date: 2008-08-16 17:00:53 +0000 (Sat, 16 Aug 2008) Log Message: ----------- - Removed stopgab TopicMapImporter in favour of several specialized Readers - Added ITopicMapReader / ITopicMapWriter - Moved Canonicalizer from the .cxtm package into the .mio package (CXTMWriter) Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/core/AbstractMapInputHandler.java Added Paths: ----------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/SnelloReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLC14NWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTMReader.java Removed Paths: ------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/core/AbstractMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/core/AbstractMapInputHandler.java 2008-08-15 12:10:43 UTC (rev 127) +++ tinytim-mio/trunk/src/main/java/org/tinytim/core/AbstractMapInputHandler.java 2008-08-16 17:00:53 UTC (rev 128) @@ -48,23 +48,23 @@ public abstract class AbstractMapInputHandler implements IMapHandler { private final int - INITIAL = 0, - TOPIC = 1, - ASSOCIATION = 2, - ROLE = 3, - OCCURRENCE = 4, - NAME = 5, - VARIANT = 6, - SCOPE = 7, - THEME = 8, - REIFIER = 9, - PLAYER = 10, - ISA = 11, - TYPE = 12; + 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 final int _CONSTRUCTS = 6; - private final int _STATES = 8; - private final int _SCOPE = 4; + private final int _STATES = 10; + private final int _SCOPE = 6; private TopicMapImpl _tm; private int[] _stateStack; @@ -388,7 +388,7 @@ */ private void _enterState(int state) { if (_stateSize + 1 > _stateStack.length) { - int[] states = new int[_stateSize*2]; + int[] states = new int[Math.min(_stateSize*2, Integer.MAX_VALUE)]; System.arraycopy(_stateStack, 0, states, 0, _stateSize); _stateStack = states; } @@ -406,7 +406,7 @@ private void _enterState(int state, IConstruct tmo) { _enterState(state); if (_constructSize + 1 > _constructStack.length) { - IConstruct[] constructs = new IConstruct[_constructSize*2]; + IConstruct[] constructs = new IConstruct[Math.min(_constructSize*2, Integer.MAX_VALUE)]; System.arraycopy(_constructStack, 0, constructs, 0, _constructSize); _constructStack = constructs; } Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java 2008-08-16 17:00:53 UTC (rev 128) @@ -0,0 +1,92 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.mio; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.tmapi.core.TMAPIRuntimeException; +import org.tmapi.core.TopicMap; +import org.xml.sax.InputSource; + +import com.semagia.mio.DeserializerRegistry; +import com.semagia.mio.IDeserializer; +import com.semagia.mio.MIOException; +import com.semagia.mio.Syntax; + +/** + * Base class for {@link ITopicMapReader} implementations. + * + * This class provides a layer to <tt>com.semagia.mio</tt> and handles + * the discovery of an appropriate deserializer transparently. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +abstract class AbstractTopicMapReader implements ITopicMapReader { + + protected IDeserializer _deserializer; + + AbstractTopicMapReader(final TopicMap topicMap, final Syntax syntax) { + _deserializer = DeserializerRegistry.createDeserializer(syntax); + if (_deserializer == null) { + throw new TMAPIRuntimeException("Appropriate deserializer not found for syntax " + syntax.getName()); + } + _deserializer.setMapHandler(new MapInputHandler(topicMap)); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.ITopicMapReader#read(java.io.File, java.lang.String) + */ + public void read(File source, String baseIRI) throws IOException { + read(new FileInputStream(source), baseIRI); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.ITopicMapReader#read(java.io.InputStream, java.lang.String) + */ + public void read(InputStream source, String baseIRI) throws IOException { + read(new InputSource(source), baseIRI); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.ITopicMapReader#read(org.xml.sax.InputSource, java.lang.String) + */ + public void read(InputSource source, String baseIRI) throws IOException { + try { + _deserializer.parse(source, baseIRI); + } + catch (MIOException ex) { + if (ex.getException() instanceof IOException) { + throw (IOException) ex.getException(); + } + else { + throw new TMAPIRuntimeException(ex); + } + } + finally { + _deserializer = null; + } + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java 2008-08-16 17:00:53 UTC (rev 128) @@ -0,0 +1,45 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.mio; + +import org.tmapi.core.TopicMap; + +import com.semagia.mio.Syntax; + +/** + * {@link ITopicMapReader} implementation that is able to deserialize + * <a href="http://www.semagia.com/tr/btm/1.0/">Binary Topic Maps (BTM) 1.0</a>. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class BTMReader extends AbstractTopicMapReader { + + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + */ + public BTMReader(final TopicMap topicMap) { + super(topicMap, Syntax.BTM); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/BTMReader.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java 2008-08-16 17:00:53 UTC (rev 128) @@ -0,0 +1,48 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.mio; + +import org.tmapi.core.TopicMap; + +import com.semagia.mio.Syntax; + +/** + * {@link ITopicMapReader} implementation that is able to deserialize + * <a href="http://www.isotopicmaps.org/ctm">Compact Topic Maps (CTM) 1.0</a>. + * <p> + * Note that this reader implements the CTM draft dtd. 2008-05-15. + * </p> + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class CTMReader extends AbstractTopicMapReader { + + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + */ + public CTMReader(final TopicMap topicMap) { + super(topicMap, Syntax.CTM); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMReader.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java 2008-08-16 17:00:53 UTC (rev 128) @@ -0,0 +1,1233 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.mio; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.AbstractSet; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.logging.Logger; + +import org.tinytim.core.TopicMapImpl; +import org.tinytim.internal.utils.CollectionFactory; +import org.tinytim.utils.DuplicateRemovalUtils; +import org.tinytim.voc.TMDM; +import org.tinytim.voc.XSD; +import org.tmapi.core.Association; +import org.tmapi.core.Construct; +import org.tmapi.core.DatatypeAware; +import org.tmapi.core.Locator; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Reifiable; +import org.tmapi.core.Role; +import org.tmapi.core.Scoped; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicInUseException; +import org.tmapi.core.TopicMap; +import org.tmapi.core.Typed; +import org.tmapi.core.Variant; +import org.tmapi.index.TypeInstanceIndex; + +import org.xml.sax.Attributes; +import org.xml.sax.helpers.AttributesImpl; + +/** + * Provides serialization of topic maps into Canonical XTM (CXTM). + * <p> + * CXTM is a format that guarantees that two equivalent Topic Maps Data Model + * instances [ISO/IEC 13250-2] will always produce byte-by-byte identical + * serializations, and that non-equivalent instances will always produce + * different serializations. + * </p> + * <p> + * See <a href="http://www.isotopicmaps.org/cxtm/">http://www.isotopicmaps.org/cxtm/</a> + * for details. + * </p> + * <p> + * <em>CAUTION</em>: This class implements the + * <a href="http://www.isotopicmaps.org/cxtm/">CXTM draft dtd. 2008-05-15</a>, + * the output may change in the future. + * </p> + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class CXTMWriter implements ITopicMapWriter { + + private static final Logger LOG = Logger.getLogger(CXTMWriter.class.getName()); + + private static final Role[] _EMPTY_ROLES = new Role[0]; + + private Topic _type; + private Topic _instance; + private Topic _typeInstance; + + private XMLC14NWriter _out; + private final String _normBase; + private Map<Construct, Integer> _construct2Id; + private Map<Topic, List<Role>> _topic2Roles; + private Map<Locator, String> _locator2Norm; + + private Comparator<Topic> _topicComparator; + private Comparator<Association> _assocComparator; + private Comparator<Role> _roleComparator; + private Comparator<Occurrence> _occComparator; + private Comparator<Name> _nameComparator; + private Comparator<Variant> _variantComparator; + private Comparator<Set<Locator>> _locSetComparator; + private Comparator<Locator> _locComparator; + private Comparator<Set<Topic>> _scopeComparator; + + private Map<Association, Role[]> _assoc2Roles; + + /** + * Creates a canonicalizer. + * + * @param out The stream the CXTM is written onto. + * @param baseLocator The base locator which is used to resolve IRIs against. + * @throws IOException If an error occurs. + */ + public CXTMWriter(OutputStream out, String baseLocator) throws IOException { + if (baseLocator == null) { + throw new IllegalArgumentException("The base locator must not be null"); + } + _out = new XMLC14NWriter(out); + _normBase = _normalizeBaseLocator(baseLocator); + _topicComparator = new TopicComparator(); + _assocComparator = new AssociationComparator(); + _roleComparator = new RoleComparator(); + _occComparator = new OccurrenceComparator(); + _nameComparator = new NameComparator(); + _variantComparator = new VariantComparator(); + _locSetComparator = new LocatorSetComparator(); + _locComparator = new LocatorComparator(); + _scopeComparator = new ScopeComparator(); + } + + /** + * Serializes the specified <tt>topicMap</tt> into the CXTM format. + * <p> + * <em>CAUTION</em>: This method MAY modify the topic map since duplicate + * Topic Maps constructs (if any) are removed in advance. + * </p> + * + * @param topicMap The topic map to serialize. + * @throws IOException If an error occurs. + */ + public void write(TopicMap topicMap) throws IOException { + DuplicateRemovalUtils.removeDuplicates(topicMap); + _construct2Id = CollectionFactory.createIdentityMap(); + _locator2Norm = CollectionFactory.createIdentityMap(); + _assoc2Roles = CollectionFactory.createIdentityMap(); + _topic2Roles = CollectionFactory.createIdentityMap(); + TypeInstanceIndex typeInstanceIndex = ((TopicMapImpl) topicMap).getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIndex.isAutoUpdated()) { + typeInstanceIndex.reindex(); + } + Topic[] topics = _fetchTopics(topicMap, typeInstanceIndex); + Association[] assocs = _fetchAssociations(topicMap, typeInstanceIndex); + typeInstanceIndex.close(); + _createIndex(topics, assocs); + _out.startDocument(); + AttributesImpl attrs = new AttributesImpl(); + _addReifier(attrs, topicMap); + _out.startElement("topicMap", attrs); + _out.newline(); + _writeItemIdentifiers(topicMap); + for (Topic topic: topics) { + _writeTopic(topic); + } + for (Association assoc: assocs) { + _writeAssociation(assoc); + } + _out.endElement("topicMap"); + _out.newline(); + _out.endDocument(); + _out = null; + _construct2Id = null; + _locator2Norm = null; + _assoc2Roles = null; + _topic2Roles = null; + } + + /** + * Returns an unsorted array of topics which should be included into + * the output. + * + * This method may return more topics than {@link TopicMap#getTopics()} + * since this method creates virtual topics to model type-instance + * relationships properly. + * + * @param topicMap The topic map from which the topic should be serialized. + * @param idx A (upto date) type instance index. + * @return All topics which must be included into the output. + */ + private Topic[] _fetchTopics(final TopicMap topicMap, final TypeInstanceIndex idx) { + Collection<Topic> types = idx.getTopicTypes(); + if (types.isEmpty()) { + Set<Topic> topics = topicMap.getTopics(); + return topics.toArray(new Topic[topics.size()]); + } + else { + List<Topic> topics = CollectionFactory.createList(topicMap.getTopics()); + _typeInstance = _getTopicBySubjectIdentifier(topicMap, topics, TMDM.TYPE_INSTANCE); + _type = _getTopicBySubjectIdentifier(topicMap, topics, TMDM.TYPE); + _instance = _getTopicBySubjectIdentifier(topicMap, topics, TMDM.INSTANCE); + return topics.toArray(new Topic[topics.size()]); + } + } + + /** + * Returns a topic by its subject identifier. If the topic is null, a + * {@link TypeInstanceTopic} is created, added to the <tt>topics</tt> + * and returned. + * + * @param tm The topic map to fetch the topic from. + * @param topics A modifiable collection of topics. + * @param sid The subject identifier. + * @return A topic with the specified subject identifier. + */ + private Topic _getTopicBySubjectIdentifier(TopicMap tm, Collection<Topic> topics, Locator sid) { + Topic topic = tm.getTopicBySubjectIdentifier(sid); + if (topic == null) { + topic = new TypeInstanceTopic(sid); + topics.add(topic); + } + return topic; + } + + /** + * Returns an unsorted array of associations which should be serialized. + * + * This method may return more association than {@link TopicMap#getAssociations()} + * since this method may create virtual associations which are used to + * model type-instance relationships properly. + * + * @param tm The topic map from which the associations should be serialized. + * @param idx A (upto date) type instance index. + * @return An unsorted array of associations which must be included into the output. + */ + private Association[] _fetchAssociations(final TopicMap tm, final TypeInstanceIndex idx) { + Collection<Topic> types = idx.getTopicTypes(); + if (types.isEmpty()) { + Set<Association> assocs = tm.getAssociations(); + return assocs.toArray(new Association[assocs.size()]); + } + else { + List<Association> assocs = CollectionFactory.createList(tm.getAssociations()); + for (Topic type: types) { + for (Topic instance: idx.getTopics(type)) { + assocs.add(new TypeInstanceAssociation(type, instance)); + } + } + return assocs.toArray(new Association[assocs.size()]); + } + } + + /** + * Creates the index on which the canonicalizer operates. + * + * As sideeffect, the provided topic and association arrays get sorted. + * + * @param topics An array of topics. + * @param assocs An array of associations. + */ + private void _createIndex(Topic[] topics, Association[] assocs) { + Arrays.sort(topics, _topicComparator); + Topic topic = null; + for (int i=0; i < topics.length; i++) { + topic = topics[i]; + _construct2Id.put(topic, Integer.valueOf(i+1)); + } + Arrays.sort(assocs, _assocComparator); + Association assoc = null; + for (int i=0; i < assocs.length; i++) { + assoc = assocs[i]; + _construct2Id.put(assoc, Integer.valueOf(i+1)); + Set<Role> roles_ = assoc.getRoles(); + Role[] roles = roles_.toArray(new Role[roles_.size()]); + Arrays.sort(roles, _roleComparator); + _assoc2Roles.put(assoc, roles); + for (int j=0; j < roles.length; j++) { + _construct2Id.put(roles[j], Integer.valueOf(j+1)); + } + } + } + + /** + * Returns a sorted array of roles of the provided association. + * + * @param assoc The association to retrieve the roles from. + * @return A (maybe empty) sorted array of roles. + */ + private Role[] _getRoles(final Association assoc) { + Role[] roles = _assoc2Roles.get(assoc); + return roles != null ? roles : _EMPTY_ROLES; + } + + /** + * Returns a sorted array of names of the provided topic. + * + * @param topic The topic to retrieve the names from. + * @return A (maybe empty) sorted array of names. + */ + private Name[] _getNames(final Topic topic) { + Set<Name> names_ = topic.getNames(); + Name[] names = names_.toArray(new Name[names_.size()]); + Arrays.sort(names, _nameComparator); + return names; + } + + /** + * Returs a sorted array of variants of the provided name. + * + * @param name The name to retrieve the variants from. + * @return A (maybe empty) sorted array of variants. + */ + private Variant[] _getVariants(final Name name) { + Set<Variant> variants_ = name.getVariants(); + Variant[] variants = variants_.toArray(new Variant[variants_.size()]); + Arrays.sort(variants, _variantComparator); + return variants; + } + + /** + * Returns a sorted array of occurrences of the provided topic. + * + * @param topic The topic to retrieve the occurrences from. + * @return A (maybe emtpy) sorted array of occurrences. + */ + private Occurrence[] _getOccurrences(final Topic topic) { + Set<Occurrence> occs_ = topic.getOccurrences(); + Occurrence[] occs = occs_.toArray(new Occurrence[occs_.size()]); + Arrays.sort(occs, _occComparator); + return occs; + } + + /** + * Returns the index of the provided Topic Maps construct. + * + * The "index" is <cite>"[...] the string encoding of the position of this + * information item in the canonically ordered list of the values from + * that set".</cite> (CXTM 3.20 Constructing the number attribute). + * + * @param tmo The Topic Maps construct to return the index of. + * @return The index of the Topic Maps construct. + */ + private int _indexOf(final Construct tmo) { + return _construct2Id.get(tmo).intValue(); + } + + /** + * Serializes the <tt>topic</tt>. + * + * @param topic The topic to serialize. + * @throws IOException If an error occurs. + */ + private void _writeTopic(final Topic topic) throws IOException { + AttributesImpl attrs = new AttributesImpl(); + attrs.addAttribute("", "number", null, null, "" +_indexOf(topic)); + _out.startElement("topic", attrs); + _out.newline(); + _writeLocatorSet("subjectIdentifiers", topic.getSubjectIdentifiers()); + _writeLocatorSet("subjectLocators", topic.getSubjectLocators()); + _writeItemIdentifiers(topic); + Name[] names = _getNames(topic); + for (int i=0; i < names.length; i++) { + _writeName(names[i], i+1); + } + Occurrence[] occs = _getOccurrences(topic); + for (int i=0; i < occs.length; i++) { + _writeOccurrence(occs[i], i+1); + } + List<Role> roles_ = CollectionFactory.createList(topic.getRolesPlayed()); + List<Role> alienRoles = _topic2Roles.get(topic); + if (alienRoles != null) { + roles_.addAll(alienRoles); + } + Role[] roles = roles_.toArray(new Role[roles_.size()]); + Arrays.sort(roles, _roleComparator); + AttributesImpl roleAttrs = new AttributesImpl(); + StringBuilder sb = new StringBuilder(20); + for (int i=0; i < roles.length; i++) { + sb.append("association.") + .append(_indexOf(roles[i].getParent())) + .append(".role.") + .append(_indexOf(roles[i])); + roleAttrs.addAttribute("", "ref", null, null, sb.toString()); + _out.startElement("rolePlayed", roleAttrs); + _out.endElement("rolePlayed"); + _out.newline(); + sb.setLength(0); + roleAttrs.clear(); + } + _out.endElement("topic"); + _out.newline(); + } + + /** + * Serializes an association. + * + * @param assoc The association to serialize. + * @throws IOException If an error occurs. + */ + private void _writeAssociation(final Association assoc) throws IOException { + _out.startElement("association", _attributes(assoc, _indexOf(assoc))); + _out.newline(); + _writeType(assoc); + for (Role role: _getRoles(assoc)) { + _out.startElement("role", _attributes(role, _indexOf(role))); + _out.newline(); + _out.startElement("player", _topicRef(role.getPlayer())); + _out.endElement("player"); + _out.newline(); + _writeType(role); + _writeItemIdentifiers(role); + _out.endElement("role"); + _out.newline(); + } + _writeScope(assoc); + _writeItemIdentifiers(assoc); + _out.endElement("association"); + _out.newline(); + } + + /** + * Serializes an occurrence. + * + * @param occ The occurrence to serialize. + * @param pos The position of the occurrence within the parent container. + * @throws IOException If an error occurs. + */ + private void _writeOccurrence(final Occurrence occ, int pos) throws IOException { + _out.startElement("occurrence", _attributes(occ, pos)); + _out.newline(); + _writeDatatyped(occ); + _writeType(occ); + _writeScope(occ); + _writeItemIdentifiers(occ); + _out.endElement("occurrence"); + _out.newline(); + } + + /** + * Writes the value/datatype pair of an occurrence or variant. + * + * @param obj The construct to serialize. + * @throws IOException If an error occurs. + */ + private void _writeDatatyped(final DatatypeAware obj) throws IOException { + final String value = XSD.ANY_URI.equals(obj.getDatatype()) + ? _normalizeLocator(obj.locatorValue()) + : obj.getValue(); + _out.startElement("value"); + _out.characters(value); + _out.endElement("value"); + _out.newline(); + _out.startElement("datatype"); + _out.characters(_normalizeLocator(obj.getDatatype())); + _out.endElement("datatype"); + _out.newline(); + } + + /** + * Serializes a topic name. + * + * @param name The name to serialize. + * @param pos The position of the name within the parent container. + * @throws IOException If an error occurs. + */ + private void _writeName(final Name name, int pos) throws IOException { + _out.startElement("name", _attributes(name, pos)); + _out.newline(); + _out.startElement("value"); + _out.characters(name.getValue()); + _out.endElement("value"); + _out.newline(); + _writeType(name); + _writeScope(name); + Variant[] variants = _getVariants(name); + Variant variant = null; + for (int i=0; i<variants.length; i++) { + variant = variants[i]; + _out.startElement("variant", _attributes(variant, i+1)); + _out.newline(); + _writeDatatyped(variant); + _writeScope(variant); + _writeItemIdentifiers(variant); + _out.endElement("variant"); + _out.newline(); + } + _writeItemIdentifiers(name); + _out.endElement("name"); + _out.newline(); + } + + /** + * Serializes the type of a typed Topic Maps construct. + * + * @param typed The typed Topic Maps construct from which the type should be + * serialized. + * @throws IOException If an error occurs. + */ + private void _writeType(final Typed typed) throws IOException { + _out.startElement("type", _topicRef(typed.getType())); + _out.endElement("type"); + _out.newline(); + } + + /** + * Serializes the scope of a scoped Topic Maps construct. + * + * If the scope is unconstrained, this method does nothing. + * + * @param scoped The scoped Topic Maps construct. + * @throws IOException If an error occurs. + */ + private void _writeScope(final Scoped scoped) throws IOException { + Set<Topic> scope = scoped.getScope(); + if (scope.isEmpty()) { + return; + } + _out.startElement("scope"); + _out.newline(); + Topic[] themes = scope.toArray(new Topic[scope.size()]); + Arrays.sort(themes, _topicComparator); + for (int i=0; i < themes.length; i++) { + _out.startElement("scopingTopic", _topicRef(themes[i])); + _out.endElement("scopingTopic"); + _out.newline(); + } + _out.endElement("scope"); + _out.newline(); + } + + /** + * Serializes a locator. + * + * A normalized locator value is created which is serialized. + * + * @param loc The locator to serialize. + * @throws IOException If an error occurs. + */ + private void _writeLocator(final Locator loc) throws IOException { + _out.startElement("locator"); + _out.characters(_normalizeLocator(loc)); + _out.endElement("locator"); + _out.newline(); + } + + /** + * Serializes the item identifiers of the specified Topic Maps construct. + * + * @param tmo The Topic Maps construct to take the item identifiers from. + * @throws IOException If an error occurs. + */ + private void _writeItemIdentifiers(final Construct tmo) throws IOException { + _writeLocatorSet("itemIdentifiers", tmo.getItemIdentifiers()); + } + + /** + * Serializes the <tt>locators</tt> using the <tt>localName</tt> as + * element name. + * + * If the set of <tt>locators</tt> is empty, this method does nothing. + * + * @param localName The element's name. + * @param locators The locators to serialize. + * @throws IOException If an error occurs. + */ + private void _writeLocatorSet(final String localName, final Set<Locator> locators) throws IOException { + if (locators.isEmpty()) { + return; + } + Locator[] locs = locators.toArray(new Locator[locators.size()]); + Arrays.sort(locs, _locComparator); + _out.startElement(localName); + _out.newline(); + for (int i=0; i < locs.length; i++) { + _writeLocator(locs[i]); + } + _out.endElement(localName); + _out.newline(); + } + + /** + * Returns attributes which contains a reference to the provided topic. + * + * @param topic The topic to which the reference should point to. + * @return Attributes with a topic reference. + */ + private Attributes _topicRef(final Topic topic) { + if (topic == null) { + _reportInvalid("The topic reference is null"); + return XMLC14NWriter.EMPTY_ATTRS; + } + AttributesImpl attrs = new AttributesImpl(); + attrs.addAttribute("", "topicref", null, null, "" + _indexOf(topic)); + return attrs; + } + + /** + * Returns attributes which contain the reifier (if any) and the number + * of the provided Topic Maps construct (not a topic). + * + * @param reifiable The Topic Maps construct. + * @param The position of the reifiable within the parent container. + * @return Attributes which contain a reference to the reifier (if any) and + * the number of the provided Topic Maps construct. + */ + private Attributes _attributes(final Reifiable reifiable, int i) { + AttributesImpl attrs = new AttributesImpl(); + _addReifier(attrs, reifiable); + attrs.addAttribute("", "number", null, null, "" + i); + return attrs; + } + + /** + * Adds a reference to the reifier of the Topic Maps construct to the + * provided attributes. If the Topic Maps construct has no reifier, the + * provided attributes are not modified. + * + * @param attrs The attributes. + * @param reifiable The reifiable Topic Maps construct. + */ + private void _addReifier(final AttributesImpl attrs, final Reifiable reifiable) { + Topic reifier = reifiable.getReifier(); + if (reifier != null) { + attrs.addAttribute("", "reifier", null, null, "" + _indexOf(reifier)); + } + } + + /** + * Normalizes the locator according to CXTM 3.19. + * + * @param locator The locator to normalize. + * @return A normalized representation of the locator. + */ + private String _normalizeLocator(final Locator locator) { + String normLoc = _locator2Norm.get(locator); + if (normLoc != null) { + return normLoc; + } + normLoc = locator.getReference(); + if (normLoc.startsWith(_normBase)) { + normLoc = normLoc.substring(_normBase.length()); + } + else { + int i = 0; + int slashPos = -1; + final int max = Math.min(_normBase.length(), normLoc.length()); + while(i < max && _normBase.charAt(i) == normLoc.charAt(i)) { + if (_normBase.charAt(i) == '/') { + slashPos = i; + } + i++; + } + if (slashPos > -1) { + normLoc = normLoc.substring(slashPos); + } + } + if (normLoc.startsWith("/")) { + normLoc = normLoc.substring(1); + } + _locator2Norm.put(locator, normLoc); + return normLoc; + } + + /** + * Normalizes the base locator according to the following procedure + * (CXTM 3.19 - 1.): + * <cite>[...] the base locator with any fragment identifier and query + * removed and any trailing "/" character removed.[...]</cite> + * + * @param baseLocator + * @return + */ + private static String _normalizeBaseLocator(final String baseLocator) { + String loc = baseLocator; + int i = loc.indexOf('#'); + if (i > 0) { + loc = loc.substring(0, i); + } + i = loc.indexOf('?'); + if (i > 0) { + loc = loc.substring(0, i); + } + if (loc.endsWith("/")) { + loc = loc.substring(0, loc.length()-1); + } + return loc; + } + + /** + * Writes a warning msg to the log. + * + * This method is used to inform the user that the serialized topic map + * is not valid acc. to CXTM. + * + * @param msg The warning message. + */ + private static void _reportInvalid(final String msg) { + LOG.warning("Invalid CXTM: '" + msg + "'"); + } + + + /* + * Comparators. + */ + + private final class TopicComparator implements Comparator<Topic> { + + public int compare(Topic o1, Topic o2) { + if (o1 == o2) { + return 0; + } + if (o1 != null && o2 == null) { + _reportInvalid("Comparing topics where one topic is null"); + return +1; + } + else if (o1 == null && o2 != null) { + _reportInvalid("Comparing topics where one topic is null"); + return -1; + } + int res = _locSetComparator.compare(o1.getSubjectIdentifiers(), o2.getSubjectIdentifiers()); + if (res == 0) { + res = _locSetComparator.compare(o1.getSubjectLocators(), o2.getSubjectLocators()); + if (res == 0) { + res = _locSetComparator.compare(o1.getItemIdentifiers(), o2.getItemIdentifiers()); + } + } + return res; + } + } + + /** + * Abstract comparator that provides some utility methods which handle common + * comparisons. + */ + private abstract class AbstractComparator<T> implements Comparator<T> { + int compareString(String o1, String o2) { + if (o1 == null && o2 != null) { + _reportInvalid("The first string value is null"); + return -1; + } + if (o1 != null && o2 == null) { + _reportInvalid("The second string value is null"); + return +1; + } + return o1.compareTo(o2); + } + /** + * Extracts the type of the typed Topic Maps constructs and compares + * the topics. + * + * @param o1 The first typed Topic Maps construct. + * @param o2 The second typed Topic Maps construct. + * @return A negative integer, zero, or a positive integer as the + * first argument is less than, equal to, or greater than the + * second. + */ + int compareType(Typed o1, Typed o2) { + return _topicComparator.compare(o1.getType(), o2.getType()); + } + /** + * Extracts the scope of the scoped Topic Maps constructs and compares + * them. + * + * @param o1 The first scoped Topic Maps construct. + * @param o2 The second scoped Topic Maps construct. + * @return A negative integer, zero, or a positive integer as the + * first argument is less than, equal to, or greater than the + * second. + */ + int compareScope(Scoped o1, Scoped o2) { + return _scopeComparator.compare(o1.getScope(), o2.getScope()); + } + } + + /** + * Enhances the {@link AbstractComparator} with a method to compare the + * value and datatype of an occurrence or variant. + */ + private abstract class AbstractDatatypeAwareComparator<T> extends AbstractComparator<T> { + /** + * Compares the value and datatype of the occurrences / variants. + * + * @param o1 The first occurrence / variant. + * @param o2 The second occurrence / variant. + * @return A negative integer, zero, or a positive integer as the + * first argument is less than, equal to, or greater than the + * second. + */ + int _compareValueDatatype(DatatypeAware o1, DatatypeAware o2) { + int res = compareString(o1.getValue(), o2.getValue()); + if (res == 0) { + res = compareString(o1.getDatatype().getReference(), o2.getDatatype().getReference()); + } + return res; + } + } + + /** + * Canonical sort order: + * 1. [type] + * 2. [roles] + * 3. [scope] + * 4. [parent] + */ + private final class AssociationComparator extends AbstractComparator<Association> { + + private Comparator<Set<Role>> _roleSetComparator; + + AssociationComparator() { + _roleSetComparator = new RoleSetComparator(); + } + + public int compare(Association o1, Association o2) { + if (o1 == o2) { + return 0; + } + int res = compareType(o1, o2); + if (res == 0) { + res = _roleSetComparator.compare(o1.getRoles(), o2.getRoles()); + if (res == 0) { + res = compareScope(o1, o2); + } + } + return res; + } + } + + /** + * Role comparator which ignores the parent association. This comparator + * is meant to be used for roles where the parent is known to be equal or + * unequal. + */ + private class RoleIgnoreParentComparator extends AbstractComparator<Role> { + + public int compare(Role o1, Role o2) { + if (o1 == o2) { + return 0; + } + int res = _topicComparator.compare(o1.getPlayer(), o2.getPlayer()); + if (res == 0) { + res = compareType(o1, o2); + } + return res; + } + } + + /** + * Canonical sort order: + * 1. [player] + * 2. [type] + * 3. [parent] + */ + private final class RoleComparator extends RoleIgnoreParentComparator { + + public int compare(Role o1, Role o2) { + if (o1 == o2) { + return 0; + } + int res = super.compare(o1, o2); + if (res == 0) { + res = _assocComparator.compare(o1.getParent(), o2.getParent()); + } + return res; + } + } + + /** + * Canonical sort order: + * 1. [value] + * 2. [datatype] + * 3. [type] + * 4. [scope] + * 5. [parent] + */ + private final class OccurrenceComparator extends AbstractDatatypeAwareComparator<Occurrence> { + + public int compare(Occurrence o1, Occurrence o2) { + if (o1 == o2) { + return 0; + } + int res = _compareValueDatatype(o1, o2); + if (res == 0) { + res = compareType(o1, o2); + if (res == 0) { + res = compareScope(o1, o2); + } + } + return res; + } + + } + + /** + * Canonical sort order: + * 1. [value] + * 2. [type] + * 3. [scope] + * 4. [parent] + */ + private final class NameComparator extends AbstractComparator<Name> { + + public int compare(Name o1, Name o2) { + if (o1 == o2) { + return 0; + } + int res = compareString(o1.getValue(), o2.getValue()); + if (res == 0) { + res = compareType(o1, o2); + if (res == 0) { + res = compareScope(o1, o2); + } + } + return res; + } + } + + /** + * Canonical sort order: + * 1. [value] + * 2. [datatype] + * 3. [scope] + * 4. [parent] + */ + private final class VariantComparator extends AbstractDatatypeAwareComparator<Variant> { + + public int compare(Variant o1, Variant o2) { + if (o1 == o2) { + return 0; + } + int res = _compareValueDatatype(o1, o2); + if (res == 0) { + res = compareScope(o1, o2); + } + return res; + } + } + + /** + * Comparator which compares the size of the provided set. + * + * Iff the size of the sets are equal, another comparison method is used + * to compare the content of the sets. + */ + private abstract class AbstractSetComparator<T> implements Comparator<Set<T>> { + + public int compare(Set<T> o1, Set<T> o2) { + int s1 = o1.size(); + int s2 = o2.size(); + int res = s1 - s2; + if (res == 0) { + res = compareContent(o1, o2, s1); + } + return res; + } + + /** + * Called iff the size of the sets is equal. + * + * This method is used to compare the content of the sets. + * + * @param o1 The first set. + * @param o2 The second set. + * @param size The size of the set(s). + * @return A negative integer, zero, or a positive integer as the + * first argument is less than, equal to, or greater than the + * second. + */ + abstract int compareContent(Set<T> o1, Set<T> o2, int size); + } + + /** + * Compares role sets. The parent of the roles is ignored! + */ + private final class RoleSetComparator extends AbstractSetComparator<Role> { + + private RoleIgnoreParentComparator _roleCmp; + + RoleSetComparator() { + _roleCmp = new RoleIgnoreParentComparator(); + } + + @Override + int compareContent(Set<Role> o1, Set<Role> o2, + int size) { + int res = 0; + Role[] roles1 = o1.toArray(new Role[size]); + Role[] roles2 = o2.toArray(new Role[size]); + Arrays.sort(roles1, _roleCmp); + Arrays.sort(roles2, _roleCmp); + for (int i=0; i < size && res == 0; i++) { + res = _roleCmp.compare(roles1[i], roles2[i]); + } + return res; + } + + } + + /** + * Compares the scope of two scoped Topic Maps constructs. + */ + private final class ScopeComparator extends AbstractSetComparator<Topic> { + + @Override + int compareContent(Set<Topic> o1, Set<Topic> o2, int size) { + int res = 0 ; + Topic[] topics1 = o1.toArray(new Topic[size]); + Topic[] topics2 = o2.toArray(new Topic[size]); + Arrays.sort(topics1, _topicComparator); + Arrays.sort(topics2, _topicComparator); + for (int i=0; i < size && res == 0; i++) { + res = _topicComparator.compare(topics1[i], topics2[i]); + } + return res; + } + + } + + /** + * Comparator for sets of {@link org.tmapi.core.Locator}s. + */ + private final class LocatorSetComparator extends AbstractSetComparator<Locator> { + + @Override + int compareContent(Set<Locator> o1, Set<Locator> o2, int size) { + int res = 0; + Locator[] locs1 = o1.toArray(new Locator[size]); + Locator[] locs2 = o2.toArray(new Locator[size]); + Arrays.sort(locs1, _locComparator); + Arrays.sort(locs2, _locComparator); + for (int i=0; i < size && res == 0; i++) { + res = _locComparator.compare(locs1[i], locs2[i]); + } + return res; + } + } + + /** + * Compares {@link org.tmapi.core.Locator}s. + */ + private final class LocatorComparator implements Comparator<Locator> { + + public int compare(Locator o1, Locator o2) { + if (o1 == o2) { + return 0; + } + return _normalizeLocator(o1).compareTo(_normalizeLocator(o2)); + } + + } + + + /* + * Helper classes to treat type-instance relationships, modelled as property + * of a topic, as associations. + */ + + private final class TypeInstanceTopic implements Topic { + + private final Set<Locator> _sids; + + TypeInstanceTopic(Locator sid) { + _sids = Collections.singleton(sid); + } + + public Set<Locator> getSubjectIdentifiers() { + return _sids; + } + + public void addItemIdentifier(Locator arg0) { } + public void addSubjectIdentifier(Locator arg0) {} + public void addSubjectLocator(Locator arg0) {} + public void addType(Topic arg0) {} + public Set<Occurrence> getOccurrences() { return Collections.emptySet(); } + public Reifiable getReified() { return null; } + public Set<Role> getRolesPlayed() { return Collections.emptySet(); } + public Set<Locator> getSubjectLocators() { return Collections.emptySet(); } + public Set<Name> getNames() { return Collections.emptySet(); } + public Set<Topic> getTypes() { return null; } + public void mergeIn(Topic arg0) { } + public void remove() throws TopicInUseException { } + public void removeSubjectIdentifier(Locator arg0) { } + public void removeSubjectLocator(Locator arg0) { } + public void removeType(Topic arg0) { } + public String getId() { return null; } + public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } + public TopicMap getTopicMap() { return null; } + public void removeItemIdentifier(Locator arg0) { } + public Name createName(String value, Collection<Topic> scope) { return null; } + public Name createName(String value, Topic... scope) {return null;} + public Name createName(Topic type, String value, Collection<Topic> scope) { return null; } + public Name createName(Topic type, String value, Topic... scope) { return null; } + public Occurrence createOccurrence(Topic type, Locator value, Collection<Topic> scope) { return null;} + public Occurrence createOccurrence(Topic type, Locator value, Topic... scope) {return null;} + public Occurrence createOccurrence(Topic type, String value, Collection<Topic> scope) { return null; } + public Occurrence createOccurrence(Topic type, String value, Locator datatype, Collection<Topic> scope) { return null; } + public Occurrence createOccurrence(Topic type, String value, Locator datatype, Topic... scope) { return null; } + public Occurrence createOccurrence(Topic type, String value, Topic... scope) { return null; } + public Set<Name> getNames(Topic type) { return null; } + public Set<Occurrence> getOccurrences(Topic type) { return null;} + public TopicMap getParent() { return null; } + public Set<Role> getRolesPlayed(Topic type, Topic assocType) { return null; } + public Set<Role> getRolesPlayed(Topic type) { return null; } + + } + + /** + * Used to represent type-instance relationships which are modelled as + * [type] property of topics. + */ + private final class TypeInstanceAssociation implements Association { + + final Set<Role> _roles; + + TypeInstanceAssociation(Topic type, Topic instance) { + Role typeRole = new TypeInstanceRole(this, _type, type); + Role instanceRole = new TypeInstanceRole(this, _instance, instance); + _roles = new TypeInstanceRoleSet(typeRole, instanceRole); + } + + public Set<Role> getRoles() { + return _roles; + } + + public Topic getType() { + return _typeInstance; + } + + public Set<Topic> getRoleTypes() { return null; } + public Set<Role> getRoles(Topic type) { return null; } + public void setReifier(Topic reifier) { } + public void addItemIdentifier(Locator itemIdentifier) { } + public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } + public TopicMap getParent() { return null; } + public void removeItemIdentifier(Locator itemIdentifier) { } + public Role createRole(Topic arg0, Topic arg1) { return null; } + public Topic getReifier() { return null; } + public void remove() {} + public void setType(Topic arg0) {} + public void addTheme(Topic arg0) {} + public Set<Topic> getScope() { return Collections.emptySet(); } + public void removeTheme(Topic arg0) {} + public String getId() { return null; } + public TopicMap getTopicMap() { return null; } + } + + /** + * Immutable association role. + */ + private class TypeInstanceRole implements Role { + private final Topic _type; + private final Topic _player; + private final Association _parent; + + TypeInstanceRole(Association parent, Topic type, Topic player) { + _type = type; + _player = player; + _parent = parent; + List<Role> roles = _topic2Roles.get(player); + if (roles == null) { + roles = CollectionFactory.createList(); + _topic2Roles.put(player, roles); + } + roles.add(this); + } + + public Topic getType() { + return _type; + } + + public Topic getPlayer() { + return _player; + } + + public void setReifier(Topic reifier) { } + public void addItemIdentifier(Locator itemIdentifier) { } + public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } + public Association getParent() { return _parent; } + public void removeItemIdentifier(Locator itemIdentifier) { } + public Association getAssociation() { return _parent; } + public Topic getReifier() { return null; } + public void remove() {} + public void setPlayer(Topic arg0) {} + public void setType(Topic arg0) {} + public String getId() { return null; } + public TopicMap getTopicMap() { return null; } + } + + /** + * Immutable 'set' of two roles. + */ + private static class TypeInstanceRoleSet extends AbstractSet<Role> { + + private final Role _role1; + private final Role _role2; + + TypeInstanceRoleSet(Role role1, Role role2) { + _role1 = role1; + _role2 = role2; + } + + @Override + public Iterator<Role> iterator() { + return new TypeInstanceRoleSetIterator(); + } + + @Override + public int size() { + return 2; + } + + private class TypeInstanceRoleSetIterator implements Iterator<Role> { + + private int _idx; + + public boolean hasNext() { + return _idx < 2; + } + + public Role next() { + if (_idx > 1) { + throw new NoSuchElementException(); + } + return 0 == _idx++ ? _role1 : _role2; + } + + public void remove() { + new UnsupportedOperationException(); + } + } + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMWriter.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapReader.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapReader.java 2008-08-16 17:00:53 UTC (rev 128) @@ -0,0 +1,71 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.mio; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +import org.xml.sax.InputSource; + +/** + * This interface represents a reader to deserialize a topic map from a source. + * <p> + * The reader is not meant to be reused and should be thrown away once one + * of the <tt>read</tt> methods were invoked. + * </p> + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface ITopicMapReader { + + /** + * Reads a topic map from <tt>source</tt> using the provided <tt>docIRI</tt> + * to resolve IRIs against. + * + * @param source The source to read the serialized topic map from. + * @param docIRI The IRI which is used to resolve IRIs against. + * @throws IOException If an error occurs. + */ + public void read(InputSource source, String docIRI) throws IOException; + + /** + * Reads a topic map from <tt>source</tt> using the provided <tt>docIRI</tt> + * to resolve IRIs against. + * + * @param source The file to read the serialized topic map from. + * @param docIRI The IRI which is used to resolve IRIs against. + * @throws IOException If an error occurs. + */ + public void read(File source, String docIRI)throws IOException; + + /** + * Reads a topic map from <tt>source</tt> using the provided <tt>docIRI</tt> + * to resolve IRIs against. + * + * @param source The stream to read the serialized topic map from. + * @param docIRI The IRI which is used to resolve IRIs against. + * @throws IOException If an error occurs. + */ + public void read(InputStream source, String docIRI)throws IOException; + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapReader.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/ITopicMapWriter.java ... [truncated message content] |
From: <lh...@us...> - 2008-08-15 12:10:35
|
Revision: 127 http://tinytim.svn.sourceforge.net/tinytim/?rev=127&view=rev Author: lheuer Date: 2008-08-15 12:10:43 +0000 (Fri, 15 Aug 2008) Log Message: ----------- - Code reorg: Added abstract handler implementation into .core and created concrete class in .mio Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java Added Paths: ----------- tinytim-mio/trunk/src/main/java/org/tinytim/core/AbstractMapInputHandler.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/mio/ tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java Removed Paths: ------------- tinytim-mio/trunk/src/main/java/org/tinytim/core/TinyTimMapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/core/ Added: tinytim-mio/trunk/src/main/java/org/tinytim/core/AbstractMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/core/AbstractMapInputHandler.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/core/AbstractMapInputHandler.java 2008-08-15 12:10:43 UTC (rev 127) @@ -0,0 +1,537 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import java.util.List; + +import org.tinytim.internal.utils.CollectionFactory; +import org.tinytim.utils.TypeInstanceConverter; +import org.tinytim.voc.TMDM; +import org.tmapi.core.Locator; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; +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; + +/** + * Abstract {@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 abstract class AbstractMapInputHandler implements IMapHandler { + + private final int + INITIAL = 0, + TOPIC = 1, + ASSOCIATION = 2, + ROLE = 3, + OCCURRENCE = 4, + NAME = 5, + VARIANT = 6, + SCOPE = 7, + THEME = 8, + REIFIER = 9, + PLAYER = 10, + ISA = 11, + TYPE = 12; + + private final int _CONSTRUCTS = 6; + private final int _STATES = 8; + private final int _SCOPE = 4; + + private TopicMapImpl _tm; + private int[] _stateStack; + private int _stateSize = -1; + private IConstruct[] _constructStack; + private int _constructSize = -1; + private List<Topic> _scope; + + protected AbstractMapInputHandler(TopicMap topicMap) { + setTopicMap(topicMap); + } + + /** + * Sets the topic map instance to operate on. + * + * @param topicMap The topic map. + */ + private final 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 final void startTopicMap() throws MIOException { + _constructStack = new IConstruct[_CONSTRUCTS]; + _stateStack = new int[_STATES]; + _scope = CollectionFactory.createList(_SCOPE); + _enterState(INITIAL, _tm); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTopicMap() + */ + public final void endTopicMap() throws MIOException { + TypeInstanceConverter.convertAssociationsToTypes(_tm); + _constructStack = null; + _stateStack = null; + _scope = null; + _tm = null; + } + + /* (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 final void endTopic() throws MIOException { + _handleTopic((Topic) _leaveStatePopConstruct(TOPIC)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startAssociation() + */ + public final void startAssociation() throws MIOException { + _enterState(ASSOCIATION, new AssociationImpl(_tm)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endAssociation() + */ + public final void endAssociation() throws MIOException { + AssociationImpl assoc = (AssociationImpl) _leaveStatePopConstruct(ASSOCIATION); + _tm.addAssociation(assoc); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startRole() + */ + public final void startRole() throws MIOException { + assert _state() == ASSOCIATION; + _enterState(ROLE, new RoleImpl(_tm)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endRole() + */ + public final void endRole() throws MIOException { + Role role = (Role) _leaveStatePopConstruct(ROLE); + ((AssociationImpl) _peekConstruct()).addRole(role); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startPlayer() + */ + public final void startPlayer() throws MIOException { + assert _state() == ROLE; + _enterState(PLAYER); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endPlayer() + */ + public final void endPlayer() throws MIOException { + _leaveState(PLAYER); + assert _state() == ROLE; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startOccurrence() + */ + public final void startOccurrence() throws MIOException { + _enterState(OCCURRENCE, new OccurrenceImpl(_tm)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endOccurrence() + */ + public final void endOccurrence() throws MIOException { + Occurrence occ = (Occurrence) _leaveStatePopConstruct(OCCURRENCE); + _peekTopic().addOccurrence(occ); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startName() + */ + public final void startName() throws MIOException { + _enterState(NAME, new NameImpl(_tm)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endName() + */ + public final void endName() throws MIOException { + Name name = (Name) _leaveStatePopConstruct(NAME); + if (name.getType() == null) { + name.setType(_tm.createTopicBySubjectIdentifier(TMDM.TOPIC_NAME)); + } + _peekTopic().addName(name); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startVariant() + */ + public final void startVariant() throws MIOException { + assert _state() == NAME; + _enterState(VARIANT, new VariantImpl(_tm)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endVariant() + */ + public final void endVariant() throws MIOException { + VariantImpl variant = (VariantImpl) _leaveStatePopConstruct(VARIANT); + NameImpl name = (NameImpl) _peekConstruct(); + IScope scope = variant.getScopeObject(); + if (scope.isUnconstrained() || name.getScopeObject() == scope) { + throw new MIOException("The variant has no scope"); + } + name.addVariant(variant); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startType() + */ + public final void startType() throws MIOException { + assert _peekConstruct() instanceof Typed; + _enterState(TYPE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endType() + */ + public final void endType() throws MIOException { + _leaveState(TYPE); + assert _peekConstruct() instanceof Typed; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startScope() + */ + public final void startScope() throws MIOException { + assert _peekConstruct() instanceof Scoped; + _enterState(SCOPE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endScope() + */ + public final void endScope() throws MIOException { + _leaveState(SCOPE); + ((IScoped) _peekConstruct()).setScopeObject(Scope.create(_scope)); + _scope.clear(); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startTheme() + */ + public final void startTheme() throws MIOException { + assert _state() == SCOPE; + _enterState(THEME); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTheme() + */ + public final void endTheme() throws MIOException { + _leaveState(THEME); + assert _state() == SCOPE; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#subjectIdentifier(java.lang.String) + */ + public final void subjectIdentifier(String subjectIdentifier) throws MIOException { + Locator sid = _tm.createLocator(subjectIdentifier); + TopicImpl topic = _peekTopic(); + Topic existing = _tm.getTopicBySubjectIdentifier(sid); + if (existing != null && !(existing == 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 final void subjectLocator(String subjectLocator) throws MIOException { + Locator slo = _tm.createLocator(subjectLocator); + TopicImpl topic = _peekTopic(); + Topic existing = _tm.getTopicBySubjectLocator(slo); + if (existing != null && !(existing == topic)) { + _merge(existing, topic); + } + topic.addSubjectLocator(slo); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#itemIdentifier(java.lang.String) + */ + public final 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, (TopicImpl) tmo); + } + else { + Topic topic = _tm.getTopicBySubjectIdentifier(iid); + if (topic != null && !topic.equals(tmo)) { + _merge(topic, (TopicImpl) tmo); + } + } + } + tmo.addItemIdentifier(iid); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startIsa() + */ + public final void startIsa() throws MIOException { + assert _state() == TOPIC; + _enterState(ISA); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endIsa() + */ + public final void endIsa() throws MIOException { + _leaveState(ISA); + assert _state() == TOPIC; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startReifier() + */ + public final void startReifier() throws MIOException { + assert _peekConstruct() instanceof Reifiable; + _enterState(REIFIER); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endReifier() + */ + public final void endReifier() throws MIOException { + _leaveState(REIFIER); + assert _peekConstruct() instanceof Reifiable; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#topicRef(com.semagia.mio.IRef) + */ + public final void topicRef(IRef identity) throws MIOException { + _handleTopic(_createTopic(identity)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#value(java.lang.String) + */ + public final void value(String value) throws MIOException { + assert _state() == NAME; + ((Name) _peekConstruct()).setValue(value); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#value(java.lang.String, java.lang.String) + */ + public final 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(int state) { + if (_stateSize + 1 > _stateStack.length) { + int[] states = new int[_stateSize*2]; + System.arraycopy(_stateStack, 0, states, 0, _stateSize); + _stateStack = states; + } + _stateSize++; + _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(int state, IConstruct tmo) { + _enterState(state); + if (_constructSize + 1 > _constructStack.length) { + IConstruct[] constructs = new IConstruct[_constructSize*2]; + System.arraycopy(_constructStack, 0, constructs, 0, _constructSize); + _constructStack = constructs; + } + _constructSize++; + _constructStack[_constructSize] = 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(int state) throws MIOException { + final int current = _stateStack[_stateSize]; + if (state != current) { + _reportError("Unexpected state: " + current + ", 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(int state) throws MIOException { + _leaveState(state); + final IConstruct construct = _peekConstruct(); + _constructStack[_constructSize] = null; + _constructSize--; + return construct; + } + + /** + * Returns the Topic Maps construct on top of the stack. + * + * @return The Topic Maps construct. + */ + private IConstruct _peekConstruct() { + return _constructStack[_constructSize]; + } + + /** + * Returns the topic on top of the stack. + * + * @return The topic. + */ + private TopicImpl _peekTopic() { + return (TopicImpl) _peekConstruct(); + } + + /** + * Returns the current state. + * + * @return The current state. + */ + private int _state() { + return _stateStack[_stateSize]; + } + + /** + * 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, TopicImpl target) { + for (int i=0; i<_constructSize; i++) { + if (_constructStack[i] == 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 TopicImpl _createTopic(IRef ref) throws MIOException { + Locator loc = _tm.createLocator(ref.getIRI()); + switch (ref.getType()) { + case IRef.ITEM_IDENTIFIER: return (TopicImpl) _tm.createTopicByItemIdentifier(loc); + case IRef.SUBJECT_IDENTIFIER: return (TopicImpl) _tm.createTopicBySubjectIdentifier(loc); + case IRef.SUBJECT_LOCATOR: return (TopicImpl) _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); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/core/AbstractMapInputHandler.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/core/TinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/core/TinyTimMapInputHandler.java 2008-08-14 12:11:54 UTC (rev 126) +++ tinytim-mio/trunk/src/main/java/org/tinytim/core/TinyTimMapInputHandler.java 2008-08-15 12:10:43 UTC (rev 127) @@ -1,512 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim.core; - -import java.util.ArrayList; -import java.util.List; - -import org.tinytim.utils.TypeInstanceConverter; -import org.tinytim.voc.TMDM; -import org.tmapi.core.Construct; -import org.tmapi.core.Locator; -import org.tmapi.core.Name; -import org.tmapi.core.Occurrence; -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; - -/** - * {@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 TopicMapImpl _tm; - private List<State> _stateStack; - private List<Construct> _constructStack; - private List<Topic> _scope; - - public TinyTimMapInputHandler() { - // noop. - } - - 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<Construct>(); - _stateStack = new ArrayList<State>(); - _scope = new ArrayList<Topic>(); - _enterState(State.INITIAL, _tm); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTopicMap() - */ - public void endTopicMap() throws MIOException { - TypeInstanceConverter.convertAssociationsToTypes(_tm); - _constructStack = null; - _stateStack = null; - _scope = 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, new AssociationImpl(_tm)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endAssociation() - */ - public void endAssociation() throws MIOException { - AssociationImpl assoc = (AssociationImpl) _leaveStatePopConstruct(State.ASSOCIATION); - _tm.addAssociation(assoc); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startRole() - */ - public void startRole() throws MIOException { - assert _state() == State.ASSOCIATION; - _enterState(State.ROLE, new RoleImpl(_tm)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endRole() - */ - public void endRole() throws MIOException { - Role role = (Role) _leaveStatePopConstruct(State.ROLE); - ((AssociationImpl) _peekConstruct()).addRole(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, new OccurrenceImpl(_tm)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endOccurrence() - */ - public void endOccurrence() throws MIOException { - Occurrence occ = (Occurrence) _leaveStatePopConstruct(State.OCCURRENCE); - _peekTopic().addOccurrence(occ); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startName() - */ - public void startName() throws MIOException { - _enterState(State.NAME, new NameImpl(_tm)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endName() - */ - public void endName() throws MIOException { - Name name = (Name) _leaveStatePopConstruct(State.NAME); - if (name.getType() == null) { - name.setType(_tm.createTopicBySubjectIdentifier(TMDM.TOPIC_NAME)); - } - _peekTopic().addName(name); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startVariant() - */ - public void startVariant() throws MIOException { - assert _state() == State.NAME; - _enterState(State.VARIANT, new VariantImpl(_tm)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endVariant() - */ - public void endVariant() throws MIOException { - VariantImpl variant = (VariantImpl) _leaveStatePopConstruct(State.VARIANT); - NameImpl name = (NameImpl) _peekConstruct(); - IScope scope = variant.getScopeObject(); - if (scope.isUnconstrained() || name.getScopeObject() == scope) { - throw new MIOException("The variant has no scope"); - } - name.addVariant(variant); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startType() - */ - public void startType() throws MIOException { - assert _peekConstruct() instanceof Typed; - _enterState(State.TYPE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endType() - */ - public void endType() throws MIOException { - _leaveState(State.TYPE); - assert _peekConstruct() instanceof Typed; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startScope() - */ - public void startScope() throws MIOException { - assert _peekConstruct() instanceof Scoped; - _enterState(State.SCOPE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endScope() - */ - public void endScope() throws MIOException { - _leaveState(State.SCOPE); - ((IScoped) _peekConstruct()).setScopeObject(Scope.create(_scope)); - _scope.clear(); - } - - /* (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 == topic)) { - _merge(existing, topic); - } - else { - Construct tmo = _tm.getConstructByItemIdentifier(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 == 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); - Construct tmo = _peekConstruct(); - if (_state() == State.TOPIC) { - Construct existing = _tm.getConstructByItemIdentifier(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.addItemIdentifier(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 Reifiable; - _enterState(State.REIFIER); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endReifier() - */ - public void endReifier() throws MIOException { - _leaveState(State.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() == State.NAME; - ((Name) _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(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, Construct 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. - * @throws MIOException If the state is not equals to the current state. - */ - private Construct _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 Construct _peekConstruct() { - return _constructStack.get(_constructStack.size()-1); - } - - /** - * Returns the topic on top of the stack. - * - * @return The topic. - */ - private TopicImpl _peekTopic() { - return (TopicImpl) _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: ((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, 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 _tm.createTopicByItemIdentifier(loc); - case IRef.SUBJECT_IDENTIFIER: return _tm.createTopicBySubjectIdentifier(loc); - case IRef.SUBJECT_LOCATOR: return _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-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-08-15 12:10:43 UTC (rev 127) @@ -0,0 +1,44 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.mio; + +import org.tinytim.core.AbstractMapInputHandler; +import org.tmapi.core.TopicMap; + +/** + * {@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 final class MapInputHandler extends AbstractMapInputHandler { + + /** + * Intitializes a new <tt>MapInputHandler</tt> instance with the specified + * <tt>topicMap</tt>. + * + * @param topicMap The {@link TopicMap} instance. + */ + public MapInputHandler(final TopicMap topicMap) { + super(topicMap); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java 2008-08-14 12:11:54 UTC (rev 126) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java 2008-08-15 12:10:43 UTC (rev 127) @@ -25,7 +25,6 @@ import java.io.IOException; import java.io.InputStream; -import org.tinytim.core.TinyTimMapInputHandler; import org.tmapi.core.TMAPIRuntimeException; import org.tmapi.core.TopicMap; @@ -207,7 +206,7 @@ if (deser == null) { throw new IOException("No deserializer found for the syntax '" + syntax.getName() + "'"); } - deser.setMapHandler(new TinyTimMapInputHandler(topicMap)); + deser.setMapHandler(new MapInputHandler(topicMap)); try { deser.parse(input, docIRI); } Added: tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java (rev 0) +++ tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-08-15 12:10:43 UTC (rev 127) @@ -0,0 +1,324 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +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.MIOException; +import com.semagia.mio.helpers.Ref; + +/** + * Tests against the {@link org.tinytim.core.AbstractMapInputHandler}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public class TestMapInputHandler extends TinyTimTestCase { + + private static final String _XSD_STRING = XSD.STRING.getReference(); + private static final String _XSD_ANY_URI = XSD.ANY_URI.getReference(); + + private MapInputHandler _handler; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + _handler = new MapInputHandler(_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.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. + } + } + +} Property changes on: tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.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...> - 2008-08-14 12:11:47
|
Revision: 126 http://tinytim.svn.sourceforge.net/tinytim/?rev=126&view=rev Author: lheuer Date: 2008-08-14 12:11:54 +0000 (Thu, 14 Aug 2008) Log Message: ----------- - Initial import of the MIO 2.0 stuff Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java Added Paths: ----------- tinytim-mio/trunk/src/main/java/org/tinytim/core/ tinytim-mio/trunk/src/main/java/org/tinytim/core/TinyTimMapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/core/ tinytim-mio/trunk/src/test/java/org/tinytim/core/TestTinyTimMapInputHandler.java Removed Paths: ------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/mio/ tinytim-mio/trunk/src/test/parseRoles.xtm tinytim-mio/trunk/src/test/parseRoles2.xtm Added: tinytim-mio/trunk/src/main/java/org/tinytim/core/TinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/core/TinyTimMapInputHandler.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/core/TinyTimMapInputHandler.java 2008-08-14 12:11:54 UTC (rev 126) @@ -0,0 +1,512 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import java.util.ArrayList; +import java.util.List; + +import org.tinytim.utils.TypeInstanceConverter; +import org.tinytim.voc.TMDM; +import org.tmapi.core.Construct; +import org.tmapi.core.Locator; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; +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; + +/** + * {@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 TopicMapImpl _tm; + private List<State> _stateStack; + private List<Construct> _constructStack; + private List<Topic> _scope; + + public TinyTimMapInputHandler() { + // noop. + } + + 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<Construct>(); + _stateStack = new ArrayList<State>(); + _scope = new ArrayList<Topic>(); + _enterState(State.INITIAL, _tm); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTopicMap() + */ + public void endTopicMap() throws MIOException { + TypeInstanceConverter.convertAssociationsToTypes(_tm); + _constructStack = null; + _stateStack = null; + _scope = 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, new AssociationImpl(_tm)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endAssociation() + */ + public void endAssociation() throws MIOException { + AssociationImpl assoc = (AssociationImpl) _leaveStatePopConstruct(State.ASSOCIATION); + _tm.addAssociation(assoc); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startRole() + */ + public void startRole() throws MIOException { + assert _state() == State.ASSOCIATION; + _enterState(State.ROLE, new RoleImpl(_tm)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endRole() + */ + public void endRole() throws MIOException { + Role role = (Role) _leaveStatePopConstruct(State.ROLE); + ((AssociationImpl) _peekConstruct()).addRole(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, new OccurrenceImpl(_tm)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endOccurrence() + */ + public void endOccurrence() throws MIOException { + Occurrence occ = (Occurrence) _leaveStatePopConstruct(State.OCCURRENCE); + _peekTopic().addOccurrence(occ); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startName() + */ + public void startName() throws MIOException { + _enterState(State.NAME, new NameImpl(_tm)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endName() + */ + public void endName() throws MIOException { + Name name = (Name) _leaveStatePopConstruct(State.NAME); + if (name.getType() == null) { + name.setType(_tm.createTopicBySubjectIdentifier(TMDM.TOPIC_NAME)); + } + _peekTopic().addName(name); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startVariant() + */ + public void startVariant() throws MIOException { + assert _state() == State.NAME; + _enterState(State.VARIANT, new VariantImpl(_tm)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endVariant() + */ + public void endVariant() throws MIOException { + VariantImpl variant = (VariantImpl) _leaveStatePopConstruct(State.VARIANT); + NameImpl name = (NameImpl) _peekConstruct(); + IScope scope = variant.getScopeObject(); + if (scope.isUnconstrained() || name.getScopeObject() == scope) { + throw new MIOException("The variant has no scope"); + } + name.addVariant(variant); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startType() + */ + public void startType() throws MIOException { + assert _peekConstruct() instanceof Typed; + _enterState(State.TYPE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endType() + */ + public void endType() throws MIOException { + _leaveState(State.TYPE); + assert _peekConstruct() instanceof Typed; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startScope() + */ + public void startScope() throws MIOException { + assert _peekConstruct() instanceof Scoped; + _enterState(State.SCOPE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endScope() + */ + public void endScope() throws MIOException { + _leaveState(State.SCOPE); + ((IScoped) _peekConstruct()).setScopeObject(Scope.create(_scope)); + _scope.clear(); + } + + /* (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 == topic)) { + _merge(existing, topic); + } + else { + Construct tmo = _tm.getConstructByItemIdentifier(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 == 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); + Construct tmo = _peekConstruct(); + if (_state() == State.TOPIC) { + Construct existing = _tm.getConstructByItemIdentifier(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.addItemIdentifier(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 Reifiable; + _enterState(State.REIFIER); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endReifier() + */ + public void endReifier() throws MIOException { + _leaveState(State.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() == State.NAME; + ((Name) _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(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, Construct 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. + * @throws MIOException If the state is not equals to the current state. + */ + private Construct _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 Construct _peekConstruct() { + return _constructStack.get(_constructStack.size()-1); + } + + /** + * Returns the topic on top of the stack. + * + * @return The topic. + */ + private TopicImpl _peekTopic() { + return (TopicImpl) _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: ((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, 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 _tm.createTopicByItemIdentifier(loc); + case IRef.SUBJECT_IDENTIFIER: return _tm.createTopicBySubjectIdentifier(loc); + case IRef.SUBJECT_LOCATOR: return _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); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/core/TinyTimMapInputHandler.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-08-14 12:08:07 UTC (rev 125) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-08-14 12:11:54 UTC (rev 126) @@ -1,595 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -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 MapInputHandler 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(MapInputHandler.class.getName()); - - private TopicMapImpl _tm; - private List<State> _stateStack; - private List<TopicMapObject> _constructStack; - - public MapInputHandler() { - } - - public MapInputHandler(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); - } - -} Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java 2008-08-14 12:08:07 UTC (rev 125) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java 2008-08-14 12:11:54 UTC (rev 126) @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.InputStream; +import org.tinytim.core.TinyTimMapInputHandler; import org.tmapi.core.TMAPIRuntimeException; import org.tmapi.core.TopicMap; @@ -33,7 +34,6 @@ import com.semagia.mio.DeserializerRegistry; import com.semagia.mio.IDeserializer; import com.semagia.mio.MIOException; -import com.semagia.mio.Property; import com.semagia.mio.Syntax; /** @@ -207,8 +207,7 @@ if (deser == null) { throw new IOException("No deserializer found for the syntax '" + syntax.getName() + "'"); } - deser.setProperty(Property.VALIDATE, "false"); - deser.setMapHandler(new MapInputHandler(topicMap)); + deser.setMapHandler(new TinyTimMapInputHandler(topicMap)); try { deser.parse(input, docIRI); } @@ -217,7 +216,6 @@ throw (IOException) ex.getException(); } else { - ex.printStackTrace(); throw new TMAPIRuntimeException(ex); } } Added: tinytim-mio/trunk/src/test/java/org/tinytim/core/TestTinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/test/java/org/tinytim/core/TestTinyTimMapInputHandler.java (rev 0) +++ tinytim-mio/trunk/src/test/java/org/tinytim/core/TestTinyTimMapInputHandler.java 2008-08-14 12:11:54 UTC (rev 126) @@ -0,0 +1,325 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +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.MIOException; +import com.semagia.mio.helpers.Ref; + +/** + * Tests against the {@link org.tinytim.core.TinyTimMapInputHandler}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +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; + + /* (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.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. + } + } + +} Property changes on: tinytim-mio/trunk/src/test/java/org/tinytim/core/TestTinyTimMapInputHandler.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Deleted: tinytim-mio/trunk/src/test/parseRoles.xtm =================================================================== --- tinytim-mio/trunk/src/test/parseRoles.xtm 2008-08-14 12:08:07 UTC (rev 125) +++ tinytim-mio/trunk/src/test/parseRoles.xtm 2008-08-14 12:11:54 UTC (rev 126) @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<topicMap xmlns="http://www.topicmaps.org/xtm/1.0/"> - <topic id="1073409678563"> - <instanceOf> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#picture"></topicRef> - </instanceOf> - <subjectIdentity> - <resourceRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.ivs.tu-berlin.de/Lischke/bilderbuch/1mai/images/Foto(03).jpg"></resourceRef> - </subjectIdentity> - </topic> - <topic id="1073409692594"> - <instanceOf> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#person"></topicRef> - </instanceOf> - <baseName id="1073409692595"> - <baseNameString>Joachim Fuchs</baseNameString> - </baseName> - </topic> - - <association id="1073409717985"> - <instanceOf> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#personinaction"></topicRef> - </instanceOf> - <member id="1073409717986"> - <roleSpec> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#picture"></topicRef> - </roleSpec> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#1073409678563"></topicRef> - </member> - <member id="1073409717987"> - <roleSpec> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#person"></topicRef> - </roleSpec> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#1073409692594"></topicRef> - </member> - </association> -</topicMap> \ No newline at end of file Deleted: tinytim-mio/trunk/src/test/parseRoles2.xtm =================================================================== --- tinytim-mio/trunk/src/test/parseRoles2.xtm 2008-08-14 12:08:07 UTC (rev 125) +++ tinytim-mio/trunk/src/test/parseRoles2.xtm 2008-08-14 12:11:54 UTC (rev 126) @@ -1,107 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<topicMap xmlns="http://www.topicmaps.org/xtm/1.0/"> - <topic id="picture"> - <baseName> - <baseNameString>a picture</baseNameString> - </baseName> - </topic> - - <topic id="person"> - <baseName> - <baseNameString>a person</baseNameString> - </baseName> - </topic> - - <topic id="group"> - <baseName> - <baseNameString>a person</baseNameString> - </baseName> - </topic> - - <topic id="item"> - <baseName> - <baseNameString>an item</baseNameString> - </baseName> - </topic> - - <topic id="action"> - <baseName> - <baseNameString>an action</baseNameString> - </baseName> - </topic> - - <topic id="place"> - <baseName> - <baseNameString>a place</baseNameString> - </baseName> - </topic> - - <topic id="event"> - <baseName> - <baseNameString>an event</baseNameString> - </baseName> - </topic> - -<!-- Association standards --> - - <topic id="isgroup"> - <baseName> - <baseNameString>some persons and a group</baseNameString> - </baseName> - </topic> - - <topic id="personinaction"> - <baseName> - <baseNameString>person in an action</baseNameString> - </baseName> - </topic> - - <topic id="where"> - <baseName> - <baseNameString>something is somewhere</baseNameString> - </baseName> - </topic> - - <topic id="ispartof"> - <baseName> - <baseNameString>something belongs to an event</baseNameString> - </baseName> - </topic> - - - <topic id="1073409678563"> - <instanceOf> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#picture"></topicRef> - </instanceOf> - <subjectIdentity> - <resourceRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.ivs.tu-berlin.de/Lischke/bilderbuch/1mai/images/Foto(03).jpg"></resourceRef> - </subjectIdentity> - </topic> - <topic id="1073409692594"> - <instanceOf> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#person"></topicRef> - </instanceOf> - <baseName id="1073409692595"> - <baseNameString>Joachim Fuchs</baseNameString> - </baseName> - </topic> - - <association id="1073409717985"> - <instanceOf> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#personinaction"></topicRef> - </instanceOf> - <member id="1073409717986"> - <roleSpec> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#picture"></topicRef> - </roleSpec> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#1073409678563"></topicRef> - </member> - <member id="1073409717987"> - <roleSpec> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#person"></topicRef> - </roleSpec> - <topicRef xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#1073409692594"></topicRef> - </member> - </association> -</topicMap> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-14 12:07:57
|
Revision: 125 http://tinytim.svn.sourceforge.net/tinytim/?rev=125&view=rev Author: lheuer Date: 2008-08-14 12:08:07 +0000 (Thu, 14 Aug 2008) Log Message: ----------- - Tagged MIO 1.5.0beta Added Paths: ----------- tinytim-mio/tags/release-1_5_0beta/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-14 12:06:30
|
Revision: 124 http://tinytim.svn.sourceforge.net/tinytim/?rev=124&view=rev Author: lheuer Date: 2008-08-14 12:06:38 +0000 (Thu, 14 Aug 2008) Log Message: ----------- - Committed missing Changes and build.xml Modified Paths: -------------- tinytim-mio/trunk/CHANGES.txt tinytim-mio/trunk/build.xml Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2008-08-14 12:05:34 UTC (rev 123) +++ tinytim-mio/trunk/CHANGES.txt 2008-08-14 12:06:38 UTC (rev 124) @@ -2,10 +2,10 @@ Changes Log =========== -1.5.0 beta (08.08.2008) ------------------------ -* Moved the package from ``org.tinytim.io`` to ``org.tinytim.mio`` -* Aligned version number to the tinyTiM's version scheme +1.5.0 beta (13.08.2008) +------------------------- +* Renamed ``org.tinyim.io`` to ``org.tinytim.mio`` +* Aligned version numbering scheme 1.0.0 alpha1 (08.05.2008) Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2008-08-14 12:05:34 UTC (rev 123) +++ tinytim-mio/trunk/build.xml 2008-08-14 12:06:38 UTC (rev 124) @@ -29,10 +29,9 @@ <property name="lib.junit" value="${dir.lib}/junit-4.4.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0alpha2.jar"/> - <property name="lib.log.api" value="${dir.lib}/slf4j-api-1.5.0.jar"/> - <property name="lib.log" value="${dir.lib}/slf4j-jdk14-1.5.0.jar"/> - <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.0.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0beta.jar"/> + <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.2.jar"/> + <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.2.jar"/> <target name="help"> <echo message="------------------------"/> @@ -87,14 +86,13 @@ <javadoc destdir="${dir.javadocs}" packagenames="org.tinytim.*" author="true" - version="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="**/MapInputHandler.*"/> </fileset> <link href="http://www.tmapi.org/apiDocs/"/> </javadoc> @@ -149,8 +147,7 @@ <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tinytim}"/> <pathelement location="${lib.mio}"/> - <pathelement location="${lib.log.api}"/> - <pathelement location="${lib.log}"/> + <pathelement location="${lib.logging}"/> </classpath> <src path="${dir.src}"/> </javac> @@ -188,8 +185,8 @@ </copy> <copy todir="${dir.dist}/lib"> <fileset dir="${dir.lib}"> - <exclude name="**/tinytim-*"/> - <exclude name="**/tmapi-*"/> + <exclude name="**/tmapi*.jar"/> + <exclude name="**/tinytim*.jar"/> </fileset> </copy> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-14 12:05:25
|
Revision: 123 http://tinytim.svn.sourceforge.net/tinytim/?rev=123&view=rev Author: lheuer Date: 2008-08-14 12:05:34 +0000 (Thu, 14 Aug 2008) Log Message: ----------- - 1.5.0beta version changes Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-08-14 11:58:37 UTC (rev 122) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-08-14 12:05:34 UTC (rev 123) @@ -115,8 +115,7 @@ * @see com.semagia.mio.IMapHandler#endTopic() */ public void endTopic() throws MIOException { - Topic topic = _peekTopic(); - _leaveStatePopConstruct(State.TOPIC); + Topic topic = (Topic) _leaveStatePopConstruct(State.TOPIC); _handleTopic(topic); } @@ -190,8 +189,7 @@ * @see com.semagia.mio.IMapHandler#endName() */ public void endName() throws MIOException { - TopicName name = (TopicName) _peekConstruct(); - _leaveStatePopConstruct(State.NAME); + TopicName name = (TopicName) _leaveStatePopConstruct(State.NAME); if (name.getType() == null) { name.setType(_topicBySubjectIdentifier(TMDM.TOPIC_NAME)); } @@ -210,8 +208,7 @@ */ @SuppressWarnings("unchecked") public void endVariant() throws MIOException { - Variant variant = (Variant) _peekConstruct(); - _leaveStatePopConstruct(State.VARIANT); + 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"); @@ -434,11 +431,12 @@ * 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 void _leaveStatePopConstruct(State state) throws MIOException { + private TopicMapObject _leaveStatePopConstruct(State state) throws MIOException { _leaveState(state); - _constructStack.remove(_constructStack.size()-1); + return _constructStack.remove(_constructStack.size()-1); } /** @@ -484,11 +482,11 @@ } /** - * Merges the <code>source</code> topic with the <code>target</code>. + * Merges the <tt>source</tt> topic with the <tt>target</tt>. * * Further, this method ensures that the construct stack stays valid: If - * the <code>source</code> is part of the stack, it is replaced with - * <code>target</code>. + * 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. Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java 2008-08-14 11:58:37 UTC (rev 122) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java 2008-08-14 12:05:34 UTC (rev 123) @@ -33,6 +33,7 @@ import com.semagia.mio.DeserializerRegistry; import com.semagia.mio.IDeserializer; import com.semagia.mio.MIOException; +import com.semagia.mio.Property; import com.semagia.mio.Syntax; /** @@ -48,8 +49,8 @@ } /** - * Reads a XML topic map from <code>input</code> and adds the content to the - * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * Reads a XML topic map from <tt>input</tt> and adds the content to the + * specified <tt>topicMap</tt>. The <tt>docIRI</tt> is used to * resolve IRIs against. * * @param topicMap The topic map instance which receives the @@ -63,8 +64,8 @@ } /** - * Reads a XML topic map from <code>input</code> and adds the content to the - * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * Reads a XML topic map from <tt>input</tt> and adds the content to the + * specified <tt>topicMap</tt>. The <tt>docIRI</tt> is used to * resolve IRIs against. * * @param topicMap The topic map instance which receives the @@ -78,8 +79,8 @@ } /** - * Reads a topic map from <code>file</code> and adds the content to the - * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * Reads a topic map from <tt>file</tt> and adds the content to the + * specified <tt>topicMap</tt>. The <tt>docIRI</tt> is used to * resolve IRIs against. * * The syntax of the serialized topic map is guessed by the file name. If @@ -97,11 +98,11 @@ } /** - * Reads a topic map from <code>file</code> and adds the content to the - * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * Reads a topic map from <tt>file</tt> and adds the content to the + * specified <tt>topicMap</tt>. The <tt>docIRI</tt> is used to * resolve IRIs against. * - * The <code>syntax</code> is a string with the abbreviated Topic Maps syntax + * The <tt>syntax</tt> is a string with the abbreviated Topic Maps syntax * name; i.e. "xtm", "ltm", "ctm". The name is matched case-insensitve, that * means "xtm" is the same as "xTm", "XTM" etc. * @@ -117,11 +118,11 @@ } /** - * Reads a topic map from <code>input</code> and adds the content to the - * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * Reads a topic map from <tt>input</tt> and adds the content to the + * specified <tt>topicMap</tt>. The <tt>docIRI</tt> is used to * resolve IRIs against. * - * The <code>syntax</code> is a string with the abbreviated Topic Maps syntax + * The <tt>syntax</tt> is a string with the abbreviated Topic Maps syntax * name; i.e. "xtm", "ltm", "ctm". The name is matched case-insensitve, that * means "xtm" is the same as "xTm", "XTM" etc. * @@ -137,11 +138,11 @@ } /** - * Reads a topic map from <code>input</code> and adds the content to the - * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * Reads a topic map from <tt>input</tt> and adds the content to the + * specified <tt>topicMap</tt>. The <tt>docIRI</tt> is used to * resolve IRIs against. * - * The <code>syntax</code> is a string with the abbreviated Topic Maps syntax + * The <tt>syntax</tt> is a string with the abbreviated Topic Maps syntax * name; i.e. "xtm", "ltm", "ctm". The name is matched case-insensitve, that * means "xtm" is the same as "xTm", "XTM" etc. * @@ -176,8 +177,8 @@ } /** - * Reads a topic map from <code>input</code> and adds the content to the - * <code>topicMap</code>. + * Reads a topic map from <tt>input</tt> and adds the content to the + * <tt>topicMap</tt>. * * @param syntax A syntax instance. * @param topicMap A topic map instance. @@ -191,8 +192,8 @@ } /** - * Reads a topic map from <code>input</code> and adds the content to the - * <code>topicMap</code>. + * Reads a topic map from <tt>input</tt> and adds the content to the + * <tt>topicMap</tt>. * * @param syntax A syntax instance. * @param topicMap A topic map instance. @@ -206,6 +207,7 @@ if (deser == null) { throw new IOException("No deserializer found for the syntax '" + syntax.getName() + "'"); } + deser.setProperty(Property.VALIDATE, "false"); deser.setMapHandler(new MapInputHandler(topicMap)); try { deser.parse(input, docIRI); @@ -215,6 +217,7 @@ throw (IOException) ex.getException(); } else { + ex.printStackTrace(); throw new TMAPIRuntimeException(ex); } } Modified: tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-08-14 11:58:37 UTC (rev 122) +++ tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-08-14 12:05:34 UTC (rev 123) @@ -36,7 +36,7 @@ import junit.framework.TestCase; /** - * Tests against the {@link org.tinytim.io.MapInputHandler}. + * Tests against the {@link org.tinytim.mio.MapInputHandler}. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-14 11:58:31
|
Revision: 122 http://tinytim.svn.sourceforge.net/tinytim/?rev=122&view=rev Author: lheuer Date: 2008-08-14 11:58:37 +0000 (Thu, 14 Aug 2008) Log Message: ----------- - Adapted TMAPI 2.0 changes - Simplified argument checks Modified Paths: -------------- 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/DatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.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/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -23,9 +23,9 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Association; -import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Role; import org.tmapi.core.Topic; import org.tmapi.core.TopicMap; @@ -101,12 +101,8 @@ * @see org.tmapi.core.Association#createRole(org.tmapi.core.Topic, org.tmapi.core.Topic) */ public Role createRole(Topic type, Topic player) { - if (type == null) { - throw new ModelConstraintException(this, "The type must not be null"); - } - if (player == null) { - throw new ModelConstraintException(this, "The player must not be null"); - } + Check.typeNotNull(this, type); + Check.playerNotNull(this, player); RoleImpl role = new RoleImpl(_tm, type, player); addRole(role); return role; Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -26,6 +26,7 @@ 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; /** @@ -79,7 +80,7 @@ */ public void addItemIdentifier(Locator itemIdentifier) { if (itemIdentifier == null) { - throw new IllegalArgumentException("The item identifier must not be null"); + throw new ModelConstraintException(this, "The item identifier must not be null"); } if (_iids != null && _iids.contains(itemIdentifier)) { return; Modified: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-14 11:58:37 UTC (rev 122) @@ -23,6 +23,7 @@ import java.math.BigDecimal; import java.math.BigInteger; +import org.tinytim.internal.utils.Check; import org.tinytim.voc.XSD; import org.tmapi.core.DatatypeAware; import org.tmapi.core.Locator; @@ -82,6 +83,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(java.lang.String) */ public void setValue(String value) { + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } @@ -89,6 +91,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(java.math.BigDecimal) */ public void setValue(BigDecimal value) { + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } @@ -96,6 +99,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(java.math.BigInteger) */ public void setValue(BigInteger value) { + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } @@ -117,6 +121,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(org.tmapi.core.Locator) */ public void setValue(Locator value) { + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } @@ -131,6 +136,7 @@ * @see org.tmapi.core.DatatypeAware#setValue(java.lang.String, org.tmapi.core.Locator) */ public void setValue(String value, Locator datatype) { + Check.valueNotNull(this, value, datatype); setLiteral(Literal.create(value, datatype)); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-08-14 11:58:37 UTC (rev 122) @@ -26,7 +26,7 @@ * This interface is not meant to be used outside of the tinyTiM package. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ interface IConstant { /** Modified: tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,7 +20,6 @@ */ package org.tinytim.core; -import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -107,12 +106,12 @@ if (sourceReifiable != null) { sourceReifiable.setReifier(target); } - List<Locator> locs = new ArrayList<Locator>(source.getSubjectIdentifiers()); + List<Locator> locs = CollectionFactory.createList(source.getSubjectIdentifiers()); for (Locator sid: locs) { source.removeSubjectIdentifier(sid); target.addSubjectIdentifier(sid); } - locs = new ArrayList<Locator>(source.getSubjectLocators()); + locs = CollectionFactory.createList(source.getSubjectLocators()); for (Locator slo: locs) { source.removeSubjectLocator(slo); target.addSubjectLocator(slo); @@ -126,7 +125,7 @@ sigs.put(SignatureGenerator.generateSignature(occ), occ); } Reifiable existing = null; - for (Occurrence occ: new ArrayList<Occurrence>(source.getOccurrences())) { + for (Occurrence occ: CollectionFactory.createList(source.getOccurrences())) { existing = sigs.get(SignatureGenerator.generateSignature(occ)); if (existing != null) { handleExistingConstruct(occ, existing); @@ -140,7 +139,7 @@ for (Name name: target.getNames()) { sigs.put(SignatureGenerator.generateSignature(name), name); } - for (Name name: new ArrayList<Name>(source.getNames())) { + for (Name name: CollectionFactory.createList(source.getNames())) { existing = sigs.get(SignatureGenerator.generateSignature(name)); if (existing != null) { handleExistingConstruct(name, existing); @@ -156,7 +155,7 @@ Association parent = role.getParent(); sigs.put(SignatureGenerator.generateSignature(parent), parent); } - for (Role role: new ArrayList<Role>(source.getRolesPlayed())) { + for (Role role: CollectionFactory.createList(source.getRolesPlayed())) { role.setPlayer(target); Association parent = role.getParent(); existing = sigs.get(SignatureGenerator.generateSignature(parent)); @@ -181,8 +180,7 @@ for (Role role: target.getRoles()) { sigs.put(SignatureGenerator.generateSignature(role), role); } - List<Role> roles = new ArrayList<Role>(source.getRoles()); - for (Role role: roles) { + for (Role role: CollectionFactory.createList(source.getRoles())) { handleExistingConstruct(role, sigs.get(SignatureGenerator.generateSignature(role))); role.remove(); } @@ -200,7 +198,7 @@ sigs.put(SignatureGenerator.generateSignature(var), var); } Variant existing = null; - for (Variant var: new ArrayList<Variant>(source.getVariants())) { + for (Variant var: CollectionFactory.createList(source.getVariants())) { existing = sigs.get(SignatureGenerator.generateSignature(var)); if (existing != null) { handleExistingConstruct(var, existing); @@ -311,7 +309,7 @@ * @param target The target which get the item identifiers. */ private static void _moveItemIdentifiers(Construct source, Construct target) { - List<Locator> iids = new ArrayList<Locator>(source.getItemIdentifiers()); + List<Locator> iids = CollectionFactory.createList(source.getItemIdentifiers()); for (Locator iid: iids) { source.removeItemIdentifier(iid); target.addItemIdentifier(iid); Modified: tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Locator; import org.tmapi.core.ModelConstraintException; @@ -88,44 +89,49 @@ * @see org.tmapi.core.Name#setValue(java.lang.String) */ public void setValue(String value) { - if (value == null) { - throw new ModelConstraintException(this, "The value must not be null"); - } + Check.valueNotNull(this, value); setLiteral(Literal.create(value)); } /* (non-Javadoc) - * @see org.tmapi.core.TopicName#getVariants() + * @see org.tinytim.core.ScopedImpl#addTheme(org.tmapi.core.Topic) */ - public Set<Variant> getVariants() { - return _variants == null ? Collections.<Variant>emptySet() - : Collections.unmodifiableSet(_variants); - } - - private void _checkVariantValue(Object value) { - if (value == null) { - throw new ModelConstraintException(this, "The variant's value must not be null"); + @Override + public void addTheme(Topic theme) { + super.addTheme(theme); + if (_variants != null) { + for (Variant variant: _variants) { + variant.addTheme(theme); + } } } - private void _checkVariantValue(String value, Locator datatype) { - _checkVariantValue(value); - if (datatype == null) { - throw new ModelConstraintException(this, "The variant's datatype must not be null"); + /* (non-Javadoc) + * @see org.tinytim.core.ScopedImpl#removeTheme(org.tmapi.core.Topic) + */ + @Override + public void removeTheme(Topic theme) { + super.removeTheme(theme); + if (_variants != null) { + for (Variant variant: _variants) { + variant.removeTheme(theme); + } } } - private void _checkVariantScope(Topic[] scope) { - if (scope == null) { - throw new ModelConstraintException(this, "The variant's scope must not be null"); - } + /* (non-Javadoc) + * @see org.tmapi.core.TopicName#getVariants() + */ + public Set<Variant> getVariants() { + return _variants == null ? Collections.<Variant>emptySet() + : Collections.unmodifiableSet(_variants); } /* (non-Javadoc) * @see org.tmapi.core.Name#createVariant(org.tmapi.core.Locator, java.util.Collection) */ public Variant createVariant(Locator value, Collection<Topic> scope) { - _checkVariantValue(value); + Check.valueNotNull(this, value); return _createVariant(Literal.create(value), scope); } @@ -133,7 +139,7 @@ * @see org.tmapi.core.Name#createVariant(java.lang.String, java.util.Collection) */ public Variant createVariant(String value, Collection<Topic> scope) { - _checkVariantValue(value); + Check.valueNotNull(this, value); return _createVariant(Literal.create(value), scope); } @@ -141,7 +147,7 @@ * @see org.tmapi.core.Name#createVariant(org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ public Variant createVariant(Locator value, Topic... scope) { - _checkVariantScope(scope); + Check.scopeNotNull(this, scope); return createVariant(value, Arrays.asList(scope)); } @@ -150,7 +156,7 @@ */ public Variant createVariant(String value, Locator datatype, Collection<Topic> scope) { - _checkVariantValue(value, datatype); + Check.valueNotNull(this, value, datatype); return _createVariant(value, datatype, scope); } @@ -158,7 +164,7 @@ * @see org.tmapi.core.Name#createVariant(java.lang.String, org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ public Variant createVariant(String value, Locator datatype, Topic... scope) { - _checkVariantScope(scope); + Check.scopeNotNull(this, scope); return createVariant(value, datatype, Arrays.asList(scope)); } @@ -166,12 +172,12 @@ * @see org.tmapi.core.Name#createVariant(java.lang.String, org.tmapi.core.Topic[]) */ public Variant createVariant(String value, Topic... scope) { - _checkVariantScope(scope); + Check.scopeNotNull(this, scope); return createVariant(value, Arrays.asList(scope)); } private Variant _createVariant(String value, Locator datatype, Collection<Topic> scope) { - _checkVariantValue(value, datatype); + Check.valueNotNull(this, value, datatype); return _createVariant(Literal.create(value, datatype), scope); } @@ -179,12 +185,13 @@ if (scope.isEmpty()) { throw new ModelConstraintException(this, "The scope of the variant must not be unconstrained"); } - Set<Topic> scope_ = CollectionFactory.createIdentitySet(scope.size()); - scope_.addAll(scope); - scope_.removeAll(super.getScope()); - if (scope_.isEmpty()) { + Set<Topic> nameScope = super.getScope(); + if (nameScope.containsAll(scope)) { throw new ModelConstraintException(this, "The variant's scope is not a true superset of the parent's scope"); } + Set<Topic> scope_ = CollectionFactory.createIdentitySet(scope.size() + nameScope.size()); + scope_.addAll(scope); + scope_.addAll(nameScope); Variant variant = new VariantImpl(_tm, literal, Scope.create(scope_)); addVariant(variant); return variant; Modified: tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,8 +20,8 @@ */ package org.tinytim.core; +import org.tinytim.internal.utils.Check; import org.tmapi.core.Association; -import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Role; import org.tmapi.core.Topic; @@ -62,9 +62,7 @@ * @see org.tmapi.core.Role#setPlayer(org.tmapi.core.Topic) */ public void setPlayer(Topic player) { - if (player == null) { - throw new ModelConstraintException(this, "The role player must not be null"); - } + Check.playerNotNull(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 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -22,6 +22,7 @@ import java.util.Set; +import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Topic; /** @@ -77,7 +78,7 @@ */ public void addTheme(Topic theme) { if (theme == null) { - throw new IllegalArgumentException("The theme must not be null"); + throw new ModelConstraintException(this, "The theme must not be null"); } setScopeObject(_scope.add(theme)); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -25,9 +25,11 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tinytim.utils.TopicUtils; 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; @@ -79,7 +81,7 @@ */ public void addSubjectIdentifier(Locator sid) { if (sid == null) { - throw new IllegalArgumentException("The subject identifier must not be null"); + throw new ModelConstraintException(this, "The subject identifier must not be null"); } if (_sids.contains(sid)) { return; @@ -112,7 +114,7 @@ */ public void addSubjectLocator(Locator slo) { if (slo == null) { - throw new IllegalArgumentException("The subject locator must not be null"); + throw new ModelConstraintException(this, "The subject locator must not be null"); } if (_slos != null && _sids.contains(slo)) { return; @@ -146,6 +148,7 @@ * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, java.lang.String, java.util.Collection) */ public Occurrence createOccurrence(Topic type, String value, Collection<Topic> scope) { + Check.valueNotNull(this, value); return _createOccurrence(type, Literal.create(value), scope); } @@ -153,6 +156,7 @@ * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Locator, org.tmapi.core.Topic, java.util.Collection) */ public Occurrence createOccurrence(Topic type, Locator value, Collection<Topic> scope) { + Check.valueNotNull(this, value); return _createOccurrence(type, Literal.create(value), scope); } @@ -160,41 +164,37 @@ * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, java.lang.String, org.tmapi.core.Locator, java.util.Collection) */ public Occurrence createOccurrence(Topic type, String value, Locator datatype, Collection<Topic> scope) { + Check.valueNotNull(this, value, datatype); return _createOccurrence(type, Literal.create(value, datatype), scope); } /* (non-Javadoc) * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, java.lang.String, org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ - public Occurrence createOccurrence(Topic type, String value, Locator datatype, Topic... themes) { - return _createOccurrence(type, Literal.create(value, datatype), Arrays.asList(themes)); + public Occurrence createOccurrence(Topic type, String value, Locator datatype, Topic... scope) { + Check.scopeNotNull(this, scope); + return createOccurrence(type, value, datatype, Arrays.asList(scope)); } /* (non-Javadoc) * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, org.tmapi.core.Locator, org.tmapi.core.Topic[]) */ - public Occurrence createOccurrence(Topic type, Locator value, - Topic... scope) { - return _createOccurrence(type, Literal.create(value), Arrays.asList(scope)); + public Occurrence createOccurrence(Topic type, Locator value, Topic... scope) { + Check.scopeNotNull(this, scope); + return createOccurrence(type, value, Arrays.asList(scope)); } /* (non-Javadoc) * @see org.tmapi.core.Topic#createOccurrence(org.tmapi.core.Topic, java.lang.String, org.tmapi.core.Topic[]) */ public Occurrence createOccurrence(Topic type, String value, Topic... scope) { + Check.scopeNotNull(this, scope); return createOccurrence(type, value, Arrays.asList(scope)); } Occurrence _createOccurrence(Topic type, ILiteral literal, Collection<Topic> scope) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } - if (literal == null) { - throw new IllegalArgumentException("The value must not be null"); - } - if (scope == null) { - throw new IllegalArgumentException("The scope must not be null"); - } + Check.typeNotNull(this, type); + Check.scopeNotNull(this, scope); Occurrence occ = new OccurrenceImpl(_tm, type, literal, Scope.create(scope)); addOccurrence(occ); return occ; @@ -265,6 +265,7 @@ * @see org.tmapi.core.Topic#createName(java.lang.String, org.tmapi.core.Topic[]) */ public Name createName(String value, Topic... scope) { + Check.scopeNotNull(this, scope); return createName(value, Arrays.asList(scope)); } @@ -272,6 +273,7 @@ * @see org.tmapi.core.Topic#createName(org.tmapi.core.Topic, java.lang.String, org.tmapi.core.Topic[]) */ public Name createName(Topic type, String value, Topic... scope) { + Check.scopeNotNull(this, scope); return createName(type, value, Arrays.asList(scope)); } @@ -302,19 +304,13 @@ * @see org.tmapi.core.Topic#createName(org.tmapi.core.Topic, java.lang.String, java.util.Collection) */ public Name createName(Topic type, String value, Collection<Topic> scope) { + Check.valueNotNull(this, value); return _createName(type, Literal.create(value), scope); } public Name _createName(Topic type, ILiteral literal, Collection<Topic> scope) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } - if (literal == null) { - throw new IllegalArgumentException("The value must not be null"); - } - if (scope == null) { - throw new IllegalArgumentException("The scope must not be null"); - } + Check.typeNotNull(this, type); + Check.scopeNotNull(this, scope); NameImpl name = new NameImpl(_tm, type, literal, Scope.create(scope)); addName(name); return name; @@ -431,9 +427,7 @@ * @see org.tmapi.core.Topic#addType(org.tmapi.core.Topic) */ public void addType(Topic type) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(this, type); if (_types != null && _types.contains(type)) { return; } @@ -475,7 +469,7 @@ */ public void remove() throws TopicInUseException { if (!TopicUtils.isRemovable(this, true)) { - throw new TopicInUseException(this, "The topic is used as type, player, or theme"); + throw new TopicInUseException(this, "The topic is used as type, player, reifier, or theme"); } if (_reified != null) { _reified.setReifier(null); Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,7 +20,6 @@ */ package org.tinytim.core; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -30,10 +29,12 @@ import org.tinytim.index.IndexManager; import org.tinytim.index.IIndexManager; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tinytim.voc.TMDM; 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; @@ -117,7 +118,7 @@ */ public Topic createTopicByItemIdentifier(Locator iid) { if (iid == null) { - throw new IllegalArgumentException("The item identifier must not be null"); + throw new ModelConstraintException(null, "The item identifier must not be null"); } Construct construct = getConstructByItemIdentifier(iid); if (construct != null) { @@ -148,7 +149,7 @@ */ public Topic createTopicBySubjectIdentifier(Locator sid) { if (sid == null) { - throw new IllegalArgumentException("The subject identifier must not be null"); + throw new ModelConstraintException(null, "The subject identifier must not be null"); } Topic topic = getTopicBySubjectIdentifier(sid); if (topic != null) { @@ -170,7 +171,7 @@ public Topic createTopicBySubjectLocator(Locator slo) { if (slo == null) { - throw new IllegalArgumentException("The subject locator must not be null"); + throw new ModelConstraintException(null, "The subject locator must not be null"); } Topic topic = getTopicBySubjectLocator(slo); if (topic != null) { @@ -223,16 +224,13 @@ } public Association createAssociation(Topic type, Topic... scope) { + Check.scopeNotNull(this, scope); return createAssociation(type, Arrays.asList(scope)); } public Association createAssociation(Topic type, Collection<Topic> scope) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } - if (scope == null) { - throw new IllegalArgumentException("The scope must not be null"); - } + Check.typeNotNull(this, type); + Check.scopeNotNull(this, scope); AssociationImpl assoc = new AssociationImpl(this, type, Scope.create(scope)); addAssociation(assoc); return assoc; @@ -399,7 +397,7 @@ public void subscribe(Event event, IEventHandler handler) { List<IEventHandler> handlers = _evtHandlers.get(event); if (handlers == null) { - handlers = new ArrayList<IEventHandler>(); + handlers = CollectionFactory.createList(); _evtHandlers.put(event, handlers); } handlers.add(handler); Modified: tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,7 +20,7 @@ */ package org.tinytim.core; -import org.tmapi.core.ModelConstraintException; +import org.tinytim.internal.utils.Check; import org.tmapi.core.Reifiable; import org.tmapi.core.Topic; @@ -60,9 +60,7 @@ * @see org.tinytim.ITyped#setType(org.tmapi.core.Topic) */ public void setType(Topic type) { - if (type == null) { - throw new ModelConstraintException(this, "The type cannot be set to null"); - } + Check.typeNotNull(this, type); if (_type == type) { return; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java 2008-08-14 11:58:37 UTC (rev 122) @@ -20,12 +20,7 @@ */ package org.tinytim.core; -import java.util.Set; - -import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Name; -import org.tmapi.core.Scoped; -import org.tmapi.core.Topic; import org.tmapi.core.Variant; /** @@ -53,20 +48,6 @@ } /* (non-Javadoc) - * @see org.tinytim.core.ScopedImpl#getScope() - */ - @Override - public Set<Topic> getScope() { - if (_tm == null || _parent == null) { - return super.getScope(); - } - Set<Topic> scope = CollectionFactory.createIdentitySet(4); - scope.addAll(super.getScope()); - scope.addAll(((Scoped) _parent).getScope()); - return scope; - } - - /* (non-Javadoc) * @see org.tinytim.IMovable#moveTo(java.lang.Object) */ public void moveTo(Name newParent) { Added: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-08-14 11:58:37 UTC (rev 122) @@ -0,0 +1,79 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.internal.utils; + +import java.util.Collection; + +import org.tmapi.core.Construct; +import org.tmapi.core.Locator; +import org.tmapi.core.ModelConstraintException; +import org.tmapi.core.Topic; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class Check { + + private static void _reportError(Construct sender, String msg) { + throw new ModelConstraintException(sender, msg); + } + + public static void scopeNotNull(Construct sender, Topic[] scope) { + if (scope == null) { + _reportError(sender, "The scope must not be null"); + } + } + + public static void scopeNotNull(Construct sender, Collection<Topic> scope) { + if (scope == null) { + _reportError(sender, "The scope must not be null"); + } + } + + public static void typeNotNull(Construct sender, Topic type) { + if (type == null) { + _reportError(sender, "The type must not be null"); + } + } + + public static void valueNotNull(Construct sender, Object value) { + if (value == null) { + _reportError(sender, "The value must not be null"); + } + } + + public static void valueNotNull(Construct sender, Object value, Locator datatype) { + valueNotNull(sender, value); + if (datatype == null) { + _reportError(sender, "The datatype must not be null"); + } + } + + public static void playerNotNull(Construct sender, Topic player) { + if (player == null) { + _reportError(sender, "The role player must not be null"); + } + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/DefaultIntObjectMap.java 2008-08-14 11:58:37 UTC (rev 122) @@ -26,7 +26,7 @@ * Default implementation of the {@link IIntObjectMap} which wraps a map. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class DefaultIntObjectMap<E> implements IIntObjectMap<E> { Modified: tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java 2008-08-12 12:01:10 UTC (rev 121) +++ tinytim/trunk/src/test/java/org/tinytim/core/TestScope.java 2008-08-14 11:58:37 UTC (rev 122) @@ -28,7 +28,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestScope extends TinyTimTestCase { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-12 12:01:03
|
Revision: 121 http://tinytim.svn.sourceforge.net/tinytim/?rev=121&view=rev Author: lheuer Date: 2008-08-12 12:01:10 +0000 (Tue, 12 Aug 2008) Log Message: ----------- - Removed LiteralCanonicalizer; Literals should be responsible to provide their canonical value - Small code modifications Modified Paths: -------------- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java Removed Paths: ------------- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java Modified: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-08-12 11:41:25 UTC (rev 120) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-08-12 12:01:10 UTC (rev 121) @@ -23,7 +23,6 @@ import java.io.IOException; import java.io.OutputStream; import java.util.AbstractSet; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -35,10 +34,9 @@ import java.util.Set; import java.util.logging.Logger; -import org.tinytim.core.DuplicateRemovalUtils; -import org.tinytim.core.ILiteralAware; import org.tinytim.core.TopicMapImpl; -import org.tinytim.utils.CollectionFactory; +import org.tinytim.internal.utils.CollectionFactory; +import org.tinytim.utils.DuplicateRemovalUtils; import org.tinytim.voc.TMDM; import org.tinytim.voc.XSD; import org.tmapi.core.Association; @@ -137,15 +135,11 @@ } /** - * Serializes the specified <code>topicMap</code> into the CXTM format. + * Serializes the specified <tt>topicMap</tt> into the CXTM format. * <p> * <em>CAUTION</em>: This method MAY modify the topic map since duplicate * Topic Maps constructs (if any) are removed in advance. * </p> - * <p> - * The topic map's base locator - * ({@link org.tmapi.core.TopicMap#getBaseLocator()}) is ignored. - * </p> * * @param topicMap The topic map to serialize. * @throws IOException If an error occurs. @@ -198,14 +192,14 @@ * @param idx A (upto date) type instance index. * @return All topics which must be included into the output. */ - private Topic[] _fetchTopics(TopicMap topicMap, TypeInstanceIndex idx) { + private Topic[] _fetchTopics(final TopicMap topicMap, final TypeInstanceIndex idx) { Collection<Topic> types = idx.getTopicTypes(); if (types.isEmpty()) { Set<Topic> topics = topicMap.getTopics(); return topics.toArray(new Topic[topics.size()]); } else { - List<Topic> topics = new ArrayList<Topic>(topicMap.getTopics()); + List<Topic> topics = CollectionFactory.createList(topicMap.getTopics()); TopicMapImpl tm = (TopicMapImpl) topicMap; _typeInstance = _getTopicBySubjectIdentifier(tm, topics, TMDM.TYPE_INSTANCE); _type = _getTopicBySubjectIdentifier(tm, topics, TMDM.TYPE); @@ -216,7 +210,7 @@ /** * Returns a topic by its subject identifier. If the topic is null, a - * {@link TypeInstanceTopic} is created, added to the <code>topics</code> + * {@link TypeInstanceTopic} is created, added to the <tt>topics</tt> * and returned. * * @param tm The topic map to fetch the topic from. @@ -224,7 +218,7 @@ * @param sid The subject identifier. * @return A topic with the specified subject identifier. */ - private Topic _getTopicBySubjectIdentifier(TopicMapImpl tm, Collection<Topic> topics, Locator sid) { + private Topic _getTopicBySubjectIdentifier(TopicMap tm, Collection<Topic> topics, Locator sid) { Topic topic = tm.getTopicBySubjectIdentifier(sid); if (topic == null) { topic = new TypeInstanceTopic(sid); @@ -244,14 +238,14 @@ * @param idx A (upto date) type instance index. * @return An unsorted array of associations which must be included into the output. */ - private Association[] _fetchAssociations(TopicMap tm, TypeInstanceIndex idx) { + private Association[] _fetchAssociations(final TopicMap tm, final TypeInstanceIndex idx) { Collection<Topic> types = idx.getTopicTypes(); if (types.isEmpty()) { Set<Association> assocs = tm.getAssociations(); return assocs.toArray(new Association[assocs.size()]); } else { - List<Association> assocs = new ArrayList<Association>(tm.getAssociations()); + List<Association> assocs = CollectionFactory.createList(tm.getAssociations()); for (Topic type: types) { for (Topic instance: idx.getTopics(type)) { assocs.add(new TypeInstanceAssociation(type, instance)); @@ -297,7 +291,7 @@ * @param assoc The association to retrieve the roles from. * @return A (maybe empty) sorted array of roles. */ - private Role[] _getRoles(Association assoc) { + private Role[] _getRoles(final Association assoc) { Role[] roles = _assoc2Roles.get(assoc); return roles != null ? roles : _EMPTY_ROLES; } @@ -308,7 +302,7 @@ * @param topic The topic to retrieve the names from. * @return A (maybe empty) sorted array of names. */ - private Name[] _getNames(Topic topic) { + private Name[] _getNames(final Topic topic) { Set<Name> names_ = topic.getNames(); Name[] names = names_.toArray(new Name[names_.size()]); Arrays.sort(names, _nameComparator); @@ -321,7 +315,7 @@ * @param name The name to retrieve the variants from. * @return A (maybe empty) sorted array of variants. */ - private Variant[] _getVariants(Name name) { + private Variant[] _getVariants(final Name name) { Set<Variant> variants_ = name.getVariants(); Variant[] variants = variants_.toArray(new Variant[variants_.size()]); Arrays.sort(variants, _variantComparator); @@ -334,7 +328,7 @@ * @param topic The topic to retrieve the occurrences from. * @return A (maybe emtpy) sorted array of occurrences. */ - private Occurrence[] _getOccurrences(Topic topic) { + private Occurrence[] _getOccurrences(final Topic topic) { Set<Occurrence> occs_ = topic.getOccurrences(); Occurrence[] occs = occs_.toArray(new Occurrence[occs_.size()]); Arrays.sort(occs, _occComparator); @@ -351,17 +345,17 @@ * @param tmo The Topic Maps construct to return the index of. * @return The index of the Topic Maps construct. */ - private int _indexOf(Construct tmo) { + private int _indexOf(final Construct tmo) { return _construct2Id.get(tmo).intValue(); } /** - * Serializes the <code>topic</code>. + * Serializes the <tt>topic</tt>. * * @param topic The topic to serialize. * @throws IOException If an error occurs. */ - private void _writeTopic(Topic topic) throws IOException { + private void _writeTopic(final Topic topic) throws IOException { AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute("", "number", null, null, "" +_indexOf(topic)); _out.startElement("topic", attrs); @@ -377,7 +371,7 @@ for (int i=0; i < occs.length; i++) { _writeOccurrence(occs[i], i+1); } - List<Role> roles_ = new ArrayList<Role>(topic.getRolesPlayed()); + List<Role> roles_ = CollectionFactory.createList(topic.getRolesPlayed()); List<Role> alienRoles = _topic2Roles.get(topic); if (alienRoles != null) { roles_.addAll(alienRoles); @@ -385,7 +379,7 @@ Role[] roles = roles_.toArray(new Role[roles_.size()]); Arrays.sort(roles, _roleComparator); AttributesImpl roleAttrs = new AttributesImpl(); - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(20); for (int i=0; i < roles.length; i++) { sb.append("association.") .append(_indexOf(roles[i].getParent())) @@ -408,7 +402,7 @@ * @param assoc The association to serialize. * @throws IOException If an error occurs. */ - private void _writeAssociation(Association assoc) throws IOException { + private void _writeAssociation(final Association assoc) throws IOException { _out.startElement("association", _attributes(assoc, _indexOf(assoc))); _out.newline(); _writeType(assoc); @@ -433,9 +427,10 @@ * Serializes an occurrence. * * @param occ The occurrence to serialize. + * @param pos The position of the occurrence within the parent container. * @throws IOException If an error occurs. */ - private void _writeOccurrence(Occurrence occ, int pos) throws IOException { + private void _writeOccurrence(final Occurrence occ, int pos) throws IOException { _out.startElement("occurrence", _attributes(occ, pos)); _out.newline(); _writeDatatyped(occ); @@ -452,9 +447,10 @@ * @param obj The construct to serialize. * @throws IOException If an error occurs. */ - private void _writeDatatyped(DatatypeAware obj) throws IOException { - String value = XSD.ANY_URI.equals(obj.getDatatype()) ? _normalizeLocator(obj.locatorValue()) - : LiteralCanonicalizer.canonicalize((ILiteralAware) obj); + private void _writeDatatyped(final DatatypeAware obj) throws IOException { + final String value = XSD.ANY_URI.equals(obj.getDatatype()) + ? _normalizeLocator(obj.locatorValue()) + : obj.getValue(); _out.startElement("value"); _out.characters(value); _out.endElement("value"); @@ -469,9 +465,10 @@ * Serializes a topic name. * * @param name The name to serialize. + * @param pos The position of the name within the parent container. * @throws IOException If an error occurs. */ - private void _writeName(Name name, int pos) throws IOException { + private void _writeName(final Name name, int pos) throws IOException { _out.startElement("name", _attributes(name, pos)); _out.newline(); _out.startElement("value"); @@ -504,11 +501,7 @@ * serialized. * @throws IOException If an error occurs. */ - private void _writeType(Typed typed) throws IOException { - Topic type = typed.getType(); - if (type == null) { - _reportInvalid("The type of " + typed + " is null"); - } + private void _writeType(final Typed typed) throws IOException { _out.startElement("type", _topicRef(typed.getType())); _out.endElement("type"); _out.newline(); @@ -522,7 +515,7 @@ * @param scoped The scoped Topic Maps construct. * @throws IOException If an error occurs. */ - private void _writeScope(Scoped scoped) throws IOException { + private void _writeScope(final Scoped scoped) throws IOException { Set<Topic> scope = scoped.getScope(); if (scope.isEmpty()) { return; @@ -548,7 +541,7 @@ * @param loc The locator to serialize. * @throws IOException If an error occurs. */ - private void _writeLocator(Locator loc) throws IOException { + private void _writeLocator(final Locator loc) throws IOException { _out.startElement("locator"); _out.characters(_normalizeLocator(loc)); _out.endElement("locator"); @@ -561,21 +554,21 @@ * @param tmo The Topic Maps construct to take the item identifiers from. * @throws IOException If an error occurs. */ - private void _writeItemIdentifiers(Construct tmo) throws IOException { + private void _writeItemIdentifiers(final Construct tmo) throws IOException { _writeLocatorSet("itemIdentifiers", tmo.getItemIdentifiers()); } /** - * Serializes the <code>locators</code> using the <code>localName</code> as + * Serializes the <tt>locators</tt> using the <tt>localName</tt> as * element name. * - * If the set of <code>locators</code> is empty, this method does nothing. + * If the set of <tt>locators</tt> is empty, this method does nothing. * * @param localName The element's name. * @param locators The locators to serialize. * @throws IOException If an error occurs. */ - private void _writeLocatorSet(String localName, Set<Locator> locators) throws IOException { + private void _writeLocatorSet(final String localName, final Set<Locator> locators) throws IOException { if (locators.isEmpty()) { return; } @@ -596,13 +589,13 @@ * @param topic The topic to which the reference should point to. * @return Attributes with a topic reference. */ - private Attributes _topicRef(Topic topic) { + private Attributes _topicRef(final Topic topic) { if (topic == null) { _reportInvalid("The topic reference is null"); return CXTMWriter.EMPTY_ATTRS; } AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute("", "topicref", null, null, ""+_indexOf(topic)); + attrs.addAttribute("", "topicref", null, null, "" + _indexOf(topic)); return attrs; } @@ -611,10 +604,11 @@ * of the provided Topic Maps construct (not a topic). * * @param reifiable The Topic Maps construct. + * @param The position of the reifiable within the parent container. * @return Attributes which contain a reference to the reifier (if any) and * the number of the provided Topic Maps construct. */ - private Attributes _attributes(Reifiable reifiable, int i) { + private Attributes _attributes(final Reifiable reifiable, int i) { AttributesImpl attrs = new AttributesImpl(); _addReifier(attrs, reifiable); attrs.addAttribute("", "number", null, null, "" + i); @@ -629,7 +623,7 @@ * @param attrs The attributes. * @param reifiable The reifiable Topic Maps construct. */ - private void _addReifier(AttributesImpl attrs, Reifiable reifiable) { + private void _addReifier(final AttributesImpl attrs, final Reifiable reifiable) { Topic reifier = reifiable.getReifier(); if (reifier != null) { attrs.addAttribute("", "reifier", null, null, "" + _indexOf(reifier)); @@ -647,24 +641,22 @@ if (normLoc != null) { return normLoc; } - final String ref = locator.getReference(); - normLoc = ref; - if (ref.startsWith(_normBase)) { - normLoc = ref.substring(_normBase.length()); + normLoc = locator.getReference(); + if (normLoc.startsWith(_normBase)) { + normLoc = normLoc.substring(_normBase.length()); } else { int i = 0; int slashPos = -1; - final int max = _normBase.length() < ref.length() ? _normBase.length() - : ref.length(); - while(i < max && _normBase.charAt(i) == ref.charAt(i)) { + final int max = Math.min(_normBase.length(), normLoc.length()); + while(i < max && _normBase.charAt(i) == normLoc.charAt(i)) { if (_normBase.charAt(i) == '/') { slashPos = i; } i++; } if (slashPos > -1) { - normLoc = ref.substring(slashPos); + normLoc = normLoc.substring(slashPos); } } if (normLoc.startsWith("/")) { @@ -683,7 +675,7 @@ * @param baseLocator * @return */ - private static String _normalizeBaseLocator(String baseLocator) { + private static String _normalizeBaseLocator(final String baseLocator) { String loc = baseLocator; int i = loc.indexOf('#'); if (i > 0) { @@ -707,7 +699,7 @@ * * @param msg The warning message. */ - private static void _reportInvalid(String msg) { + private static void _reportInvalid(final String msg) { LOG.warning("Invalid CXTM: '" + msg + "'"); } @@ -1170,7 +1162,7 @@ _parent = parent; List<Role> roles = _topic2Roles.get(player); if (roles == null) { - roles = new ArrayList<Role>(); + roles = CollectionFactory.createList(); _topic2Roles.put(player, roles); } roles.add(this); Deleted: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java 2008-08-12 11:41:25 UTC (rev 120) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/LiteralCanonicalizer.java 2008-08-12 12:01:10 UTC (rev 121) @@ -1,57 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim.cxtm; - -import org.tinytim.core.ILiteral; -import org.tinytim.core.ILiteralAware; -import org.tinytim.voc.XSD; -import org.tmapi.core.Locator; - -/** - * - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ - */ -final class LiteralCanonicalizer { - - private LiteralCanonicalizer () { - // noop. - } - - public static String canonicalize(final ILiteralAware obj) { - final ILiteral lit = obj.getLiteral(); - final String value = lit.getValue(); - final Locator datatype = lit.getDatatype(); - if (datatype == XSD.ANY_URI || datatype == XSD.STRING) { - return lit.getValue(); - } - else if (datatype == XSD.DECIMAL || datatype == XSD.INT || datatype == XSD.INTEGER) { - if (value.charAt(0) == '+') { - return value.substring(1); - } - return value; - } - return lit.getValue(); - } - - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-12 11:41:16
|
Revision: 120 http://tinytim.svn.sourceforge.net/tinytim/?rev=120&view=rev Author: lheuer Date: 2008-08-12 11:41:25 +0000 (Tue, 12 Aug 2008) Log Message: ----------- - Use consequently CollectionFactory Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndexImpl.java Modified: tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java 2008-08-12 11:36:58 UTC (rev 119) +++ tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java 2008-08-12 11:41:25 UTC (rev 120) @@ -20,7 +20,6 @@ */ package org.tinytim.index; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -33,7 +32,7 @@ import org.tinytim.core.ILiteral; import org.tinytim.core.ILiteralAware; import org.tinytim.core.Literal; -import org.tinytim.utils.CollectionFactory; +import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Locator; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; @@ -81,7 +80,7 @@ } Collection<Name> names = _lit2Names.get(literal); return names == null ? Collections.<Name>emptySet() - : new ArrayList<Name>(names); + : CollectionFactory.createList(names); } /* (non-Javadoc) @@ -114,7 +113,7 @@ } Collection<Occurrence> occs = _lit2Occs.get(literal); return occs == null ? Collections.<Occurrence>emptySet() - : new ArrayList<Occurrence>(occs); + : CollectionFactory.createList(occs); } /* (non-Javadoc) @@ -147,7 +146,7 @@ } Collection<Variant> variants = _lit2Variants.get(literal); return variants == null ? Collections.<Variant>emptySet() - : new ArrayList<Variant>(variants); + : CollectionFactory.createList(variants); } public void clear() { @@ -159,7 +158,7 @@ private void _index(Map<ILiteral, List<ILiteralAware>> lit2LitAware, ILiteral lit, ILiteralAware litAware) { List<ILiteralAware> list = lit2LitAware.get(lit); if (list == null) { - list = new ArrayList<ILiteralAware>(); + list = CollectionFactory.createList(); lit2LitAware.put(lit, list); } list.add(litAware); Modified: tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java 2008-08-12 11:36:58 UTC (rev 119) +++ tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java 2008-08-12 11:41:25 UTC (rev 120) @@ -20,7 +20,6 @@ */ package org.tinytim.index; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -33,7 +32,7 @@ import org.tinytim.core.IEventPublisher; import org.tinytim.core.IScope; import org.tinytim.core.IScoped; -import org.tinytim.utils.CollectionFactory; +import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Association; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; @@ -80,7 +79,7 @@ public Collection<Association> getAssociations(Topic theme) { Collection<Association> assocs = _theme2Assocs.get(theme); return assocs == null ? Collections.<Association>emptySet() - : new ArrayList<Association>(assocs); + : CollectionFactory.createList(assocs); } /* (non-Javadoc) @@ -107,7 +106,7 @@ * @see org.tmapi.index.ScopedIndex#getAssociationThemes() */ public Collection<Topic> getAssociationThemes() { - List<Topic> themes = new ArrayList<Topic>(_theme2Assocs.keySet()); + List<Topic> themes = CollectionFactory.createList(_theme2Assocs.keySet()); themes.remove(null); return themes; } @@ -118,7 +117,7 @@ public Collection<Occurrence> getOccurrences(Topic theme) { Collection<Occurrence> occs = _theme2Occs.get(theme); return occs == null ? Collections.<Occurrence>emptySet() - : new ArrayList<Occurrence>(occs); + : CollectionFactory.createList(occs); } /* (non-Javadoc) @@ -145,7 +144,7 @@ * @see org.tmapi.index.ScopedIndex#getOccurrenceThemes() */ public Collection<Topic> getOccurrenceThemes() { - List<Topic> themes = new ArrayList<Topic>(_theme2Occs.keySet()); + List<Topic> themes = CollectionFactory.createList(_theme2Occs.keySet()); themes.remove(null); return themes; } @@ -156,7 +155,7 @@ public Collection<Name> getNames(Topic theme) { Collection<Name> names = _theme2Names.get(theme); return names == null ? Collections.<Name>emptySet() - : new ArrayList<Name>(names); + : CollectionFactory.createList(names); } /* (non-Javadoc) @@ -182,7 +181,7 @@ * @see org.tmapi.index.ScopedIndex#getNameThemes() */ public Collection<Topic> getNameThemes() { - List<Topic> themes = new ArrayList<Topic>(_theme2Names.keySet()); + List<Topic> themes = CollectionFactory.createList(_theme2Names.keySet()); themes.remove(null); return themes; } @@ -193,7 +192,7 @@ public Collection<Variant> getVariants(Topic theme) { Collection<Variant> vars = _theme2Variants.get(theme); return vars == null ? Collections.<Variant>emptySet() - : new ArrayList<Variant>(vars); + : CollectionFactory.createList(vars); } /* (non-Javadoc) @@ -219,7 +218,7 @@ * @see org.tmapi.index.ScopedIndex#getVariantThemes() */ public Collection<Topic> getVariantThemes() { - List<Topic> themes = new ArrayList<Topic>(_theme2Variants.keySet()); + List<Topic> themes = CollectionFactory.createList(_theme2Variants.keySet()); themes.remove(null); return themes; } Modified: tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndexImpl.java 2008-08-12 11:36:58 UTC (rev 119) +++ tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndexImpl.java 2008-08-12 11:41:25 UTC (rev 120) @@ -20,7 +20,6 @@ */ package org.tinytim.index; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -31,7 +30,7 @@ import org.tinytim.core.IConstruct; import org.tinytim.core.IEventHandler; import org.tinytim.core.IEventPublisher; -import org.tinytim.utils.CollectionFactory; +import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Association; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; @@ -86,7 +85,7 @@ * @see org.tinytim.index.ITypeInstanceIndex#getAssociationTypes() */ public Collection<Topic> getAssociationTypes() { - List<Topic> topics = new ArrayList<Topic>(_type2Assocs.keySet()); + List<Topic> topics = CollectionFactory.createList(_type2Assocs.keySet()); topics.remove(null); return topics; } @@ -97,14 +96,14 @@ public Collection<Association> getAssociations(Topic type) { List<Association> assocs = _type2Assocs.get(type); return assocs == null ? Collections.<Association>emptySet() - : new ArrayList<Association>(assocs); + : CollectionFactory.createList(assocs); } /* (non-Javadoc) * @see org.tinytim.index.ITypeInstanceIndex#getRoleTypes() */ public Collection<Topic> getRoleTypes() { - List<Topic> topics = new ArrayList<Topic>(_type2Roles.keySet()); + List<Topic> topics = CollectionFactory.createList(_type2Roles.keySet()); topics.remove(null); return topics; } @@ -115,14 +114,14 @@ public Collection<Role> getRoles(Topic type) { List<Role> roles = _type2Roles.get(type); return roles == null ? Collections.<Role>emptySet() - : new ArrayList<Role>(roles); + : CollectionFactory.createList(roles); } /* (non-Javadoc) * @see org.tinytim.index.ITypeInstanceIndex#getOccurrenceTypes() */ public Collection<Topic> getOccurrenceTypes() { - List<Topic> topics = new ArrayList<Topic>(_type2Occs.keySet()); + List<Topic> topics = CollectionFactory.createList(_type2Occs.keySet()); topics.remove(null); return topics; } @@ -133,14 +132,14 @@ public Collection<Occurrence> getOccurrences(Topic type) { List<Occurrence> occs = _type2Occs.get(type); return occs == null ? Collections.<Occurrence>emptySet() - : new ArrayList<Occurrence>(occs); + : CollectionFactory.createList(occs); } /* (non-Javadoc) * @see org.tinytim.index.ITypeInstanceIndex#getNameTypes() */ public Collection<Topic> getNameTypes() { - List<Topic> topics = new ArrayList<Topic>(_type2Names.keySet()); + List<Topic> topics = CollectionFactory.createList(_type2Names.keySet()); topics.remove(null); return topics; } @@ -151,14 +150,14 @@ public Collection<Name> getNames(Topic type) { List<Name> names = _type2Names.get(type); return names == null ? Collections.<Name>emptySet() - : new ArrayList<Name>(names); + : CollectionFactory.createList(names); } /* (non-Javadoc) * @see org.tinytim.index.ITypeInstanceIndex#getTopicTypes() */ public Collection<Topic> getTopicTypes() { - List<Topic> topics = new ArrayList<Topic>(_type2Topics.keySet()); + List<Topic> topics = CollectionFactory.createList(_type2Topics.keySet()); topics.remove(null); return topics; } @@ -169,7 +168,7 @@ public Collection<Topic> getTopics(Topic type) { Set<Topic> topics = _type2Topics.get(type); return topics == null ? Collections.<Topic>emptySet() - : new ArrayList<Topic>(topics); + : CollectionFactory.createList(topics); } /* (non-Javadoc) @@ -200,7 +199,7 @@ private void _index(Map<Topic, List<Typed>> type2Typed, Topic type, Typed typed) { List<Typed> list = type2Typed.get(type); if (list == null) { - list = new ArrayList<Typed>(); + list = CollectionFactory.createList(); type2Typed.put(type, list); } list.add(typed); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |