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-11-12 15:09:25
|
Revision: 178 http://tinytim.svn.sourceforge.net/tinytim/?rev=178&view=rev Author: lheuer Date: 2008-11-12 15:09:23 +0000 (Wed, 12 Nov 2008) Log Message: ----------- Updated changes and readme Modified Paths: -------------- tinytim-mio/trunk/CHANGES.txt tinytim-mio/trunk/README.txt Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2008-11-12 14:48:00 UTC (rev 177) +++ tinytim-mio/trunk/CHANGES.txt 2008-11-12 15:09:23 UTC (rev 178) @@ -2,10 +2,16 @@ Changes Log =========== -2.0.0 a1 (xx.10.2008) +2.0.0 a3 (xx.11.2008) ------------------------- * Adapted MIO to tinyTiM 2.0.0 * Changed license to Apache License 2.0 +* Introduced TopicMapReader/TopicMapWriter interfaces +* Added dedicated, syntax-specific TopicMapReader implementations +* Moved CXTMWriter into .mio package, implements TopicMapWriter +* XTM 1.0/2.0 serializers +* Deprecated some TopicMapImporter methods which take a xml.InputSource + as argument 1.5.0 beta (13.08.2008) Modified: tinytim-mio/trunk/README.txt =================================================================== --- tinytim-mio/trunk/README.txt 2008-11-12 14:48:00 UTC (rev 177) +++ tinytim-mio/trunk/README.txt 2008-11-12 15:09:23 UTC (rev 178) @@ -2,13 +2,13 @@ tinyTiM - The tiny Topic Maps engine ==================================== -What is tinyTiM I/O? +What is tinyTiM MIO? -------------------- -tinyTiM is a tiny Topic Maps engine which keeps topic maps in-memory. +tinyTiM is a tiny Topic Maps engine with a small jar footprint. This Topic Maps engine is meant to be used together with the TMAPI interfaces, see <http://www.tmapi.org/> for details. -The I/O package provides an API to import serialized topic maps. It depends +The MIO package provides an API to import serialized topic maps. It depends on Semagia MIO which provides a streaming Topic Maps API implementation. Note: Semagia MIO uses another license than tinyTiM, see @@ -18,12 +18,10 @@ Installation ------------ -Put the ``tinytim-io-<VERSION>.jar`` together with the ``tinytim-<VERSION>.jar``, -and ``tmapi-1_0SP1.jar`` into the classpath. +Put the ``tinytim-mio-<VERSION>.jar`` together with the ``tinytim-<VERSION>.jar``, +and ``tmapi-2.0.0.jar`` into the classpath. Further, the ``semagia-mio-<VERSION>.jar`` and one or more ``semagia-mio-<SYNTAX-NAME>-<VERSION>.jar`` are needed in the classpath. -The standard tinyTiM I/O distribution offers the ``semagia-mio-xtm-<VERSION>.jar`` -which is used to import XML Topic Maps (XTM) version 1.0 and 2.0. Note, that ``Semagia MIO`` needs the ``Simple Logging Facade for Java`` (SLF4J), so ``slf4j-api-<VERSION>.jar`` and one of the ``slf4j-<TYPE>-<VERSION>.jar`` from the SLF4J project must be in the classpath; @@ -33,14 +31,14 @@ Latest Version -------------- -Visit tinyTiM's homepage <http://sourceforge.net/projects/tinytim> for the +Visit tinyTiM's homepage <http://tinytim.sourceforge.net/> for the latest version. Mailing list ------------ -The mailing list for tinyTiM is located here -<http://sourceforge.net/mailarchive/forum.php?forum_name=tinytim-discuss>. +The mailing list for tinyTiM is located at +<http://tinytim.sourceforge.net/mailinglist>. Feel free to ask any question about tinyTiM. :) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-18 16:05:29
|
Revision: 204 http://tinytim.svn.sourceforge.net/tinytim/?rev=204&view=rev Author: lheuer Date: 2008-11-18 16:05:24 +0000 (Tue, 18 Nov 2008) Log Message: ----------- - Updated build script - Removed BTM support from TopicMapImporter temporarily Modified Paths: -------------- tinytim-mio/trunk/build.properties tinytim-mio/trunk/build.xml tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java Modified: tinytim-mio/trunk/build.properties =================================================================== --- tinytim-mio/trunk/build.properties 2008-11-18 15:40:54 UTC (rev 203) +++ tinytim-mio/trunk/build.properties 2008-11-18 16:05:24 UTC (rev 204) @@ -1,4 +1,5 @@ version=2.0.0 -version_suffix=a1-snapshot +version_suffix=a3 +#release_type= debug=off optimize=on Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2008-11-18 15:40:54 UTC (rev 203) +++ tinytim-mio/trunk/build.xml 2008-11-18 16:05:24 UTC (rev 204) @@ -1,16 +1,18 @@ <?xml version="1.0" encoding="utf-8"?> <project name="tinyTiM" default="jar" basedir="."> <property file="build.properties"/> + <tstamp/> + <property name="release_type" value="-snapshot-${DSTAMP}${TSTAMP}"/> <property name="dir.src" value="${basedir}/src/main/java"/> <property name="dir.test" value="${basedir}/src/test/java"/> <property name="dir.lib" value="${basedir}/lib"/> - <property name="lib.junit" value="${dir.lib}/junit-4.4.jar"/> - <property name="lib.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0beta.jar"/> + <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> + <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a1.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a3.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"/> + <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.3.jar"/> <target name="help"> <echo message="------------------------"/> @@ -25,7 +27,7 @@ </target> <target name="init"> - <property name="dist.version" value="${version}${version_suffix}"/> + <property name="dist.version" value="${version}${version_suffix}${release_type}"/> <property name="dist.name" value="tinytim-mio-${dist.version}"/> <property name="tinytim-mio.jar" value="${dist.name}.jar"/> Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java 2008-11-18 15:40:54 UTC (rev 203) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java 2008-11-18 16:05:24 UTC (rev 204) @@ -191,9 +191,6 @@ else if (Syntax.SNELLO.equals(syntax)) { tmReader = new SnelloTopicMapReader(topicMap, input); } - else if (Syntax.BTM.equals(syntax)) { - tmReader = new BTMTopicMapReader(topicMap, input); - } if (tmReader == null) { throw new IOException("Unknown syntax " + syntax.getName()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-19 15:43:02
|
Revision: 211 http://tinytim.svn.sourceforge.net/tinytim/?rev=211&view=rev Author: lheuer Date: 2008-11-19 15:42:50 +0000 (Wed, 19 Nov 2008) Log Message: ----------- Added *experimental* support for tinyTiM 1.5 (TMAPI 1.0) Added Paths: ----------- tinytim-mio/trunk/build-15.properties tinytim-mio/trunk/build-15.xml tinytim-mio/trunk/lib/tinytim-1.5.0beta.jar tinytim-mio/trunk/lib/tmapi-1_0SP1.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler-15.txt Added: tinytim-mio/trunk/build-15.properties =================================================================== --- tinytim-mio/trunk/build-15.properties (rev 0) +++ tinytim-mio/trunk/build-15.properties 2008-11-19 15:42:50 UTC (rev 211) @@ -0,0 +1,5 @@ +version=1.5.0 +version_suffix=b +#release_type= +debug=off +optimize=on Added: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml (rev 0) +++ tinytim-mio/trunk/build-15.xml 2008-11-19 15:42:50 UTC (rev 211) @@ -0,0 +1,197 @@ +<?xml version="1.0" encoding="utf-8"?> +<project name="tinyTiM" default="jar" basedir="."> + <property file="build-15.properties"/> + <tstamp/> + <property name="release_type" value="-snapshot-${DSTAMP}${TSTAMP}"/> + + <property name="dir.src" value="${basedir}/src/main/java"/> + <property name="dir.test" value="${basedir}/src/test/java"/> + <property name="dir.lib" value="${basedir}/lib"/> + + <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> + <property name="lib.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.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.3.jar"/> + + <target name="help"> + <echo message="------------------------"/> + <echo message="tinyTiM MIO - Build file"/> + <echo message="------------------------"/> + <echo message=""/> + <echo message="Available targets:"/> + <echo message=""/> + <echo message=" jar Creates the jar"/> + <echo message=" doc Generates the Java Docs"/> + <echo message=" release Creates the jar and a distributable file"/> + </target> + + <target name="init"> + <property name="dist.version" value="${version}${version_suffix}${release_type}"/> + <property name="dist.name" value="tinytim-mio-${dist.version}"/> + + <property name="tinytim-mio.jar" value="${dist.name}.jar"/> + <property name="tinytim-mio.tar" value="${dist.name}.tar"/> + <property name="tinytim-mio.tar.gz" value="${tinytim-mio.tar}.gz"/> + <property name="tinytim-mio.zip" value="${dist.name}.zip"/> + + <property name="dir.build" value="${basedir}/build"/> + <property name="dir.dist.root" value="${dir.build}/dist"/> + <property name="dir.dist" value="${dir.dist.root}/${dist.name}"/> + <property name="dir.build.classes" value="${dir.build}/classes"/> + <property name="dir.build.tests" value="${dir.build}/tests"/> + <property name="dir.javadocs" value="${dir.dist}/docs/api"/> + </target> + + <!-- =================================================================== --> + <!-- Clean targets --> + <!-- =================================================================== --> + <target name="clean" depends="init"> + <delete dir="${dir.build}"/> + <delete dir="${dir.javadocs}"/> + </target> + + <!-- =================================================================== --> + <!-- Prepares the build directory --> + <!-- =================================================================== --> + <target name="prepare" depends="init"> + <mkdir dir="${dir.build}"/> + <mkdir dir="${dir.build.classes}"/> + </target> + + <!-- =================================================================== --> + <!-- Creates the Java Docs --> + <!-- =================================================================== --> + <target name="doc" depends="init"> + <mkdir dir="${dir.javadocs}"/> + <javadoc destdir="${dir.javadocs}" + packagenames="org.tinytim.*" + author="true" + version="false" + use="true" + splitindex="true" + noindex="false" + windowtitle="tinyTiM MIO API v${dist.version}" + doctitle="tinyTiM API MIO v${dist.version}"> + <fileset dir="${dir.src}"> + </fileset> + <link href="http://www.tmapi.org/apiDocs/"/> + </javadoc> + </target> + + <!-- =================================================================== --> + <!-- Tests --> + <!-- =================================================================== --> + <target name="test" depends="compile"> + <mkdir dir="${dir.build.tests}"/> + <javac destdir="${dir.build.tests}" + debug="${debug}" + optimize="${optimize}" + target="1.5"> + <classpath> + <pathelement location="${dir.build.classes}"/> + <pathelement location="${lib.junit}"/> + <pathelement location="${lib.tmapi}"/> + <pathelement location="${lib.tinytim}"/> + <pathelement location="${lib.mio}"/> + </classpath> + <src path="${dir.test}"/> + </javac> + <junit printsummary="true" showoutput="false" + errorProperty="test.failed" failureProperty="test.failed"> + <classpath> + <pathelement location="${dir.build.classes}"/> + <pathelement location="${dir.build.tests}"/> + <pathelement location="${lib.junit}"/> + <pathelement location="${lib.tmapi}"/> + <pathelement location="${lib.tinytim}"/> + <pathelement location="${lib.mio}"/> + </classpath> + <formatter type="brief" usefile="false"/> + <batchtest fork="no" todir="${dir.build}"> + <fileset dir="${dir.build.tests}/"> + <include name="**/Test**.class"/> + </fileset> + </batchtest> + </junit> + <fail message="Tests failed. Check test output." if="test.failed"/> + </target> + + <!-- =================================================================== --> + <!-- Compile source files --> + <!-- =================================================================== --> + <target name="compile" depends="clean, prepare"> + <copy file="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler.java" tofile="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler-20.txt"/> + <copy file="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler-15.txt" tofile="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler.java" overwrite="true"/> + <javac destdir="${dir.build.classes}" + debug="${debug}" + excludes="org/tinytim/mio/**Writer.*" + target="1.5"> + <classpath> + <pathelement location="${lib.tmapi}"/> + <pathelement location="${lib.tinytim}"/> + <pathelement location="${lib.mio}"/> + <pathelement location="${lib.logging}"/> + </classpath> + <src path="${dir.src}"/> + </javac> + <copy file="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler-20.txt" tofile="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler.java" overwrite="true"/> + <delete file="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler-20.txt"/> + </target> + + <!-- =================================================================== --> + <!-- Creates the jar --> + <!-- =================================================================== --> + <target name="jar" depends="compile"> + <jar destfile="${dir.build}/${tinytim-mio.jar}"> + <fileset dir="${dir.build.classes}"> + <include name="**/*.*"/> + </fileset> + <manifest> + <attribute name="Implementation-Title" value="tinyTiM MIO"/> + <attribute name="Implementation-Version" value="${dist.version}"/> + <attribute name="Implementation-URL" value="http://sourceforge.net/projects/tinytim"/> + </manifest> + </jar> + </target> + + <!-- =================================================================== --> + <!-- Prepares a distribution --> + <!-- =================================================================== --> + <target name="dist" depends="jar"> + <mkdir dir="${dir.dist}"/> + + <copy todir="${dir.dist}" file="${dir.build}/${tinytim-mio.jar}"/> + + <copy todir="${dir.dist}/src"> + <fileset dir="${dir.src}"/> + </copy> + <copy todir="${dir.dist}/test"> + <fileset dir="${dir.test}"/> + </copy> + <copy todir="${dir.dist}/lib"> + <fileset dir="${dir.lib}"> + <exclude name="**/tmapi*.jar"/> + <exclude name="**/tinytim*.jar"/> + </fileset> + </copy> + + <copy todir="${dir.dist}" file="CHANGES.txt"/> + <copy todir="${dir.dist}" file="LICENSE.txt"/> + <copy todir="${dir.dist}" file="README.txt"/> + </target> + + <!-- =================================================================== --> + <!-- Creates the distribution files (.zip and .tar.gz) --> + <!-- --> + <!-- Won't create the distribution files if a test fails --> + <!-- =================================================================== --> + <target name="release" depends="jar, test, doc, dist"> + <tar destfile="${dir.dist.root}/${tinytim-mio.tar}" + basedir="${dir.dist.root}"/> + <gzip src="${dir.dist.root}/${tinytim-mio.tar}" + destfile="${dir.build}/${tinytim-mio.tar.gz}" /> + <delete file="${dir.dist.root}/${tinytim-mio.tar}" /> + <zip destfile="${dir.build}/${tinytim-mio.zip}" basedir="${dir.dist.root}"/> + </target> +</project> Added: tinytim-mio/trunk/lib/tinytim-1.5.0beta.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-1.5.0beta.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: tinytim-mio/trunk/lib/tmapi-1_0SP1.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tmapi-1_0SP1.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler-15.txt =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler-15.txt (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler-15.txt 2008-11-19 15:42:50 UTC (rev 211) @@ -0,0 +1,595 @@ +/* + * 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: 123 $ - $Date: 2008-08-14 14:05:34 +0200 (Do, 14 Aug 2008) $ + */ +public class TinyTimMapInputHandler implements IMapHandler { + + private enum State { + INITIAL, TOPIC, ASSOCIATION, ROLE, OCCURRENCE, NAME, VARIANT, + SCOPE, THEME, REIFIER, PLAYER, ISA, TYPE; + } + + private static final Logger LOG = Logger.getLogger(TinyTimMapInputHandler.class.getName()); + + private TopicMapImpl _tm; + private List<State> _stateStack; + private List<TopicMapObject> _constructStack; + + public TinyTimMapInputHandler() { + } + + public TinyTimMapInputHandler(TopicMap topicMap) { + this(); + setTopicMap(topicMap); + } + + /** + * Sets the topic map instance to operate on. + * + * @param topicMap The topic map. + */ + public void setTopicMap(TopicMap topicMap) { + if (topicMap == null) { + throw new IllegalArgumentException("The topic map must not be null"); + } + _tm = (TopicMapImpl) topicMap; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startTopicMap() + */ + public void startTopicMap() throws MIOException { + _constructStack = new ArrayList<TopicMapObject>(); + _stateStack = new ArrayList<State>(); + _enterState(State.INITIAL, _tm); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTopicMap() + */ + public void endTopicMap() throws MIOException { + TypeInstanceConverter.convertAssociationsToTypes(_tm); + _constructStack = null; + _stateStack = null; + _tm = null; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startTopic(com.semagia.mio.IRef) + */ + public void startTopic(IRef identity) throws MIOException { + _enterState(State.TOPIC, _createTopic(identity)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTopic() + */ + public void endTopic() throws MIOException { + Topic topic = (Topic) _leaveStatePopConstruct(State.TOPIC); + _handleTopic(topic); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startAssociation() + */ + public void startAssociation() throws MIOException { + _enterState(State.ASSOCIATION, _tm.createAssociation()); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endAssociation() + */ + public void endAssociation() throws MIOException { + _leaveStatePopConstruct(State.ASSOCIATION); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startRole() + */ + public void startRole() throws MIOException { + assert _state() == State.ASSOCIATION; + _enterState(State.ROLE, ((Association) _peekConstruct()).createAssociationRole(null, null)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endRole() + */ + public void endRole() throws MIOException { + _leaveStatePopConstruct(State.ROLE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startPlayer() + */ + public void startPlayer() throws MIOException { + assert _state() == State.ROLE; + _enterState(State.PLAYER); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endPlayer() + */ + public void endPlayer() throws MIOException { + _leaveState(State.PLAYER); + assert _state() == State.ROLE; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startOccurrence() + */ + public void startOccurrence() throws MIOException { + _enterState(State.OCCURRENCE, _peekTopic().createOccurrence((Locator) null, null, null)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endOccurrence() + */ + public void endOccurrence() throws MIOException { + _leaveStatePopConstruct(State.OCCURRENCE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startName() + */ + public void startName() throws MIOException { + _enterState(State.NAME, _peekTopic().createTopicName(null, null)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endName() + */ + public void endName() throws MIOException { + TopicName name = (TopicName) _leaveStatePopConstruct(State.NAME); + if (name.getType() == null) { + name.setType(_topicBySubjectIdentifier(TMDM.TOPIC_NAME)); + } + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startVariant() + */ + public void startVariant() throws MIOException { + assert _state() == State.NAME; + _enterState(State.VARIANT, ((TopicName) _peekConstruct()).createVariant((Locator) null, null)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endVariant() + */ + @SuppressWarnings("unchecked") + public void endVariant() throws MIOException { + Variant variant = (Variant) _leaveStatePopConstruct(State.VARIANT); + Collection<Topic> scope = variant.getScope(); + if (scope.isEmpty() || variant.getTopicName().getScope().equals(scope)) { + throw new MIOException("The variant has no scope"); + } + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startType() + */ + public void startType() throws MIOException { + assert _peekConstruct() instanceof ITyped; + _enterState(State.TYPE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endType() + */ + public void endType() throws MIOException { + _leaveState(State.TYPE); + assert _peekConstruct() instanceof ITyped; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startScope() + */ + public void startScope() throws MIOException { + assert _peekConstruct() instanceof ScopedObject; + _enterState(State.SCOPE); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endScope() + */ + public void endScope() throws MIOException { + _leaveState(State.SCOPE); + assert _peekConstruct() instanceof ScopedObject; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startTheme() + */ + public void startTheme() throws MIOException { + assert _state() == State.SCOPE; + _enterState(State.THEME); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTheme() + */ + public void endTheme() throws MIOException { + _leaveState(State.THEME); + assert _state() == State.SCOPE; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#subjectIdentifier(java.lang.String) + */ + public void subjectIdentifier(String subjectIdentifier) throws MIOException { + Locator sid = _tm.createLocator(subjectIdentifier); + Topic topic = _peekTopic(); + Topic existing = _tm.getTopicBySubjectIdentifier(sid); + if (existing != null && !existing.equals(topic)) { + _merge(existing, topic); + } + else { + TopicMapObject tmo = _tm.getObjectByItemIdentifier(sid); + if (tmo != null && tmo instanceof Topic && !tmo.equals(topic)) { + _merge((Topic) tmo, topic); + } + } + topic.addSubjectIdentifier(sid); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#subjectLocator(java.lang.String) + */ + public void subjectLocator(String subjectLocator) throws MIOException { + Locator slo = _tm.createLocator(subjectLocator); + Topic topic = _peekTopic(); + Topic existing = _tm.getTopicBySubjectLocator(slo); + if (existing != null && !existing.equals(topic)) { + _merge(existing, topic); + } + topic.addSubjectLocator(slo); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#itemIdentifier(java.lang.String) + */ + public void itemIdentifier(String itemIdentifier) throws MIOException { + Locator iid = _tm.createLocator(itemIdentifier); + TopicMapObject tmo = _peekConstruct(); + if (_state() == State.TOPIC) { + TopicMapObject existing = _tm.getObjectByItemIdentifier(iid); + if (existing != null && existing instanceof Topic && !existing.equals(tmo)) { + _merge((Topic) existing, (Topic) tmo); + } + else { + Topic topic = _tm.getTopicBySubjectIdentifier(iid); + if (topic != null && !topic.equals(tmo)) { + _merge(topic, (Topic) tmo); + } + } + } + tmo.addSourceLocator(iid); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startIsa() + */ + public void startIsa() throws MIOException { + assert _state() == State.TOPIC; + _enterState(State.ISA); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endIsa() + */ + public void endIsa() throws MIOException { + _leaveState(State.ISA); + assert _state() == State.TOPIC; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startReifier() + */ + public void startReifier() throws MIOException { + assert _peekConstruct() instanceof IReifiable; + _enterState(State.REIFIER); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endReifier() + */ + public void endReifier() throws MIOException { + _leaveState(State.REIFIER); + assert _peekConstruct() instanceof IReifiable; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#topicRef(com.semagia.mio.IRef) + */ + public void topicRef(IRef identity) throws MIOException { + _handleTopic(_createTopic(identity)); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#value(java.lang.String) + */ + public void value(String value) throws MIOException { + assert _state() == State.NAME; + ((TopicName) _peekConstruct()).setValue(value); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#value(java.lang.String, java.lang.String) + */ + public void value(String value, String datatype) throws MIOException { + boolean isLocator = XSD.ANY_URI.equals(datatype); + if (!isLocator && !XSD.STRING.equals(datatype)) { + LOG.warning("The datatype '" + datatype + "' was converted into xsd:string"); + } + if (_state() == State.OCCURRENCE) { + Occurrence occ = (Occurrence) _peekConstruct(); + if (isLocator) { + occ.setResource(_tm.createLocator(value)); + } + else { + occ.setValue(value); + } + } + else { + assert _state() == State.VARIANT; + Variant variant = (Variant) _peekConstruct(); + if (isLocator) { + variant.setResource(_tm.createLocator(value)); + } + else { + variant.setValue(value); + } + } + } + + /** + * Enters a state. + * + * @param state The state to push ontop of the state stack. + */ + private void _enterState(State state) { + _stateStack.add(state); + } + + /** + * Enters a state and pushes the Topic Maps construct ontop of the construct + * stack. + * + * @param state The state to enter. + * @param tmo The Topic Maps construct which should be pushed to the stack. + */ + private void _enterState(State state, TopicMapObject tmo) { + _enterState(state); + _constructStack.add(tmo); + } + + /** + * Leaves a state. + * + * @param state The state to leave. + * @throws MIOException If the state is not equals to the current state. + */ + private void _leaveState(State state) throws MIOException { + State current = _stateStack.remove(_stateStack.size()-1); + if (state != current) { + _reportError("Unexpected state: " + current + ", expected: " + state); + } + } + + /** + * Leaves a state and removed the Topic Maps construct from the top of the + * construct stack. + * + * @param state The state to leave. + * @return The removed construct. + * @throws MIOException If the state is not equals to the current state. + */ + private TopicMapObject _leaveStatePopConstruct(State state) throws MIOException { + _leaveState(state); + return _constructStack.remove(_constructStack.size()-1); + } + + /** + * Returns the Topic Maps construct on top of the stack. + * + * @return The Topic Maps construct. + */ + private TopicMapObject _peekConstruct() { + return _constructStack.get(_constructStack.size()-1); + } + + /** + * Returns the topic on top of the stack. + * + * @return The topic. + */ + private Topic _peekTopic() { + return (Topic) _peekConstruct(); + } + + /** + * Returns the current state. + * + * @return The current state. + */ + private State _state() { + return _stateStack.get(_stateStack.size()-1); + } + + /** + * Handles the topic dependent on the current state. + * + * @param topic The topic to handle. + */ + private void _handleTopic(Topic topic) { + switch (_state()) { + case ISA: _peekTopic().addType(topic); break; + case TYPE: ((ITyped) _peekConstruct()).setType(topic); break; + case PLAYER: ((AssociationRole) _peekConstruct()).setPlayer(topic); break; + case THEME: ((ScopedObject) _peekConstruct()).addScopingTopic(topic); break; + case REIFIER: ((IReifiable) _peekConstruct()).setReifier(topic); break; + } + } + + /** + * Merges the <tt>source</tt> topic with the <tt>target</tt>. + * + * Further, this method ensures that the construct stack stays valid: If + * the <tt>source</tt> is part of the stack, it is replaced with + * <tt>target</tt>. + * + * @param source The source topic (will be removed). + * @param target The target topic. + */ + private void _merge(Topic source, Topic target) { + int i = _constructStack.indexOf(source); + while (i > -1) { + _constructStack.set(i, target); + i = _constructStack.indexOf(source); + } + target.mergeIn(source); + } + + /** + * Returns either an existing topic with the specified identity or creates + * a topic with the given identity. + * + * @param ref The identity of the topic. + * @return A topic instance. + * @throws MIOException + */ + private Topic _createTopic(IRef ref) throws MIOException { + Locator loc = _tm.createLocator(ref.getIRI()); + switch (ref.getType()) { + case IRef.ITEM_IDENTIFIER: return _topicByItemIdentifier(loc); + case IRef.SUBJECT_IDENTIFIER: return _topicBySubjectIdentifier(loc); + case IRef.SUBJECT_LOCATOR: return _topicBySubjectLocator(loc); + default: _reportError("Unknown reference type " + ref.getType()); + } + // Never returned, an exception was thrown + return null; + } + + /** + * Returns either an existing topic with the specified item identfier, + * or creates a topic with the given item identifier. + * + * @param iid The item identifier of the topic. + * @return A topic instance. + */ + private Topic _topicByItemIdentifier(Locator iid) { + TopicMapObject tmo = _tm.getObjectByItemIdentifier(iid); + Topic topic = (tmo instanceof Topic) ? (Topic) tmo : null; + if (topic == null) { + topic = _tm.getTopicBySubjectIdentifier(iid); + if (topic != null) { + topic.addSourceLocator(iid); + } + } + if (topic == null) { + topic = _tm.createTopic(); + topic.addSourceLocator(iid); + } + return topic; + } + + /** + * Returns either an existing topic with the specified subject identfier, + * or creates a topic with the given subject identifier. + * + * @param sid The subject identifier of the topic. + * @return A topic instance. + */ + private Topic _topicBySubjectIdentifier(Locator sid) { + Topic topic = _tm.getTopicBySubjectIdentifier(sid); + if (topic == null) { + TopicMapObject tmo = _tm.getObjectByItemIdentifier(sid); + if (tmo instanceof Topic) { + topic = (Topic) tmo; + topic.addSubjectIdentifier(sid); + } + } + if (topic == null) { + topic = _tm.createTopic(); + topic.addSubjectIdentifier(sid); + } + return topic; + } + + /** + * Returns either an existing topic with the specified subject locator, + * or creates a topic with the given subject locator. + * + * @param slo The subject locator of the topic. + * @return A topic instance. + */ + private Topic _topicBySubjectLocator(Locator slo) { + Topic topic = _tm.getTopicBySubjectLocator(slo); + if (topic == null) { + topic = _tm.createTopic(); + topic.addSubjectLocator(slo); + } + return topic; + } + + /** + * Reports an error. + * + * @param msg The error message. + * @throws MIOException Thrown in any case. + */ + private static void _reportError(String msg) throws MIOException { + throw new MIOException(msg); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-20 15:00:53
|
Revision: 219 http://tinytim.svn.sourceforge.net/tinytim/?rev=219&view=rev Author: lheuer Date: 2008-11-20 15:00:50 +0000 (Thu, 20 Nov 2008) Log Message: ----------- - Added license - Incremented version suffix (2.0 and 1.5) Modified Paths: -------------- tinytim-mio/trunk/CHANGES.txt tinytim-mio/trunk/build-15.properties tinytim-mio/trunk/build.properties Added Paths: ----------- tinytim-mio/trunk/lib/LICENSE.sesame.txt Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2008-11-20 14:30:14 UTC (rev 218) +++ tinytim-mio/trunk/CHANGES.txt 2008-11-20 15:00:50 UTC (rev 219) @@ -2,7 +2,7 @@ Changes Log =========== -2.0.0 a3 (xx.11.2008) +2.0.0 a4 (xx.11.2008) --------------------- * Initial .mio release for tinyTiM 2.x * Changed license to Apache License 2.0 Modified: tinytim-mio/trunk/build-15.properties =================================================================== --- tinytim-mio/trunk/build-15.properties 2008-11-20 14:30:14 UTC (rev 218) +++ tinytim-mio/trunk/build-15.properties 2008-11-20 15:00:50 UTC (rev 219) @@ -1,5 +1,5 @@ version=1.5.0 -version_suffix=b +version_suffix=b2 #release_type= debug=off optimize=on Modified: tinytim-mio/trunk/build.properties =================================================================== --- tinytim-mio/trunk/build.properties 2008-11-20 14:30:14 UTC (rev 218) +++ tinytim-mio/trunk/build.properties 2008-11-20 15:00:50 UTC (rev 219) @@ -1,5 +1,5 @@ version=2.0.0 -version_suffix=a3 +version_suffix=a4 #release_type= debug=off optimize=on Added: tinytim-mio/trunk/lib/LICENSE.sesame.txt =================================================================== --- tinytim-mio/trunk/lib/LICENSE.sesame.txt (rev 0) +++ tinytim-mio/trunk/lib/LICENSE.sesame.txt 2008-11-20 15:00:50 UTC (rev 219) @@ -0,0 +1,25 @@ +Copyright Aduna (http://www.aduna-software.com/) \xA9 2001-2007 +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-20 16:55:49
|
Revision: 222 http://tinytim.svn.sourceforge.net/tinytim/?rev=222&view=rev Author: lheuer Date: 2008-11-20 16:55:44 +0000 (Thu, 20 Nov 2008) Log Message: ----------- - Update to tinytim-1.5.0b2 - Added interface TopicMapWriter to the 1.5 build, implementation are still excluded Modified Paths: -------------- tinytim-mio/trunk/build-15.xml Added Paths: ----------- tinytim-mio/trunk/lib/tinytim-1.5.0b2.jar Removed Paths: ------------- tinytim-mio/trunk/lib/tinytim-1.5.0beta.jar Modified: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2008-11-20 16:08:28 UTC (rev 221) +++ tinytim-mio/trunk/build-15.xml 2008-11-20 16:55:44 UTC (rev 222) @@ -10,7 +10,7 @@ <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0beta.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0b2.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.3.jar"/> @@ -125,7 +125,7 @@ <copy file="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler-15.txt" tofile="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler.java" overwrite="true"/> <javac destdir="${dir.build.classes}" debug="${debug}" - excludes="org/tinytim/mio/**Writer.*" + excludes="org/tinytim/mio/XMLWriter* org/tinytim/mio/Abstract*Writer* org/tinytim/mio/CXTMTopicMapWriter* org/tinytim/mio/XTM*TopicMapWriter*" target="1.5"> <classpath> <pathelement location="${lib.tmapi}"/> Added: tinytim-mio/trunk/lib/tinytim-1.5.0b2.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-1.5.0b2.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/lib/tinytim-1.5.0beta.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-21 13:17:53
|
Revision: 223 http://tinytim.svn.sourceforge.net/tinytim/?rev=223&view=rev Author: lheuer Date: 2008-11-21 13:17:29 +0000 (Fri, 21 Nov 2008) Log Message: ----------- - Removed version info from XMLWriter - Added Sesame - Added backport of XTM(10|20)TopicMapWriter for 1.5 - Migrated 1.5 org.tinytim.cxtm.Canonicalizer to mio as CXTMTopicMapWriter (implements TopicMapWriter) for 1.5 - Removed datatype normalization from CXTMTopicMapWriter (1.5) Modified Paths: -------------- tinytim-mio/trunk/build-15.xml tinytim-mio/trunk/build.xml tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java Added Paths: ----------- tinytim-mio/trunk/lib/openrdf-sesame-2.2.1-onejar.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio15/ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/AbstractTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio15/CXTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio15/TinyTimMapInputHandler.java tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM20TopicMapWriter.java Removed Paths: ------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler-15.txt Modified: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2008-11-20 16:55:44 UTC (rev 222) +++ tinytim-mio/trunk/build-15.xml 2008-11-21 13:17:29 UTC (rev 223) @@ -121,11 +121,10 @@ <!-- Compile source files --> <!-- =================================================================== --> <target name="compile" depends="clean, prepare"> - <copy file="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler.java" tofile="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler-20.txt"/> - <copy file="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler-15.txt" tofile="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler.java" overwrite="true"/> <javac destdir="${dir.build.classes}" debug="${debug}" - excludes="org/tinytim/mio/XMLWriter* org/tinytim/mio/Abstract*Writer* org/tinytim/mio/CXTMTopicMapWriter* org/tinytim/mio/XTM*TopicMapWriter*" + excludes="org/tinytim/mio/AbstractTopicMapWriter* org/tinytim/mio/CXTMTopicMapWriter* org/tinytim/mio/XTM*TopicMapWriter*" + includes="org/tinytim/mio15/** org/tinytim/mio/*TopicMapReader* org/tinytim/mio/*TopicMapImporter*" target="1.5"> <classpath> <pathelement location="${lib.tmapi}"/> @@ -135,8 +134,6 @@ </classpath> <src path="${dir.src}"/> </javac> - <copy file="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler-20.txt" tofile="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler.java" overwrite="true"/> - <delete file="${dir.src}/org/tinytim/mio/TinyTimMapInputHandler-20.txt"/> </target> <!-- =================================================================== --> Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2008-11-20 16:55:44 UTC (rev 222) +++ tinytim-mio/trunk/build.xml 2008-11-21 13:17:29 UTC (rev 223) @@ -123,7 +123,8 @@ <target name="compile" depends="clean, prepare"> <javac destdir="${dir.build.classes}" debug="${debug}" - target="1.5"> + target="1.5" + excludes="org/tinytim/mio15/**"> <classpath> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tinytim}"/> Added: tinytim-mio/trunk/lib/openrdf-sesame-2.2.1-onejar.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/openrdf-sesame-2.2.1-onejar.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler-15.txt =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler-15.txt 2008-11-20 16:55:44 UTC (rev 222) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler-15.txt 2008-11-21 13:17:29 UTC (rev 223) @@ -1,590 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.mio; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.logging.Logger; - -import org.tinytim.IReifiable; -import org.tinytim.ITyped; -import org.tinytim.TopicMapImpl; -import org.tinytim.TypeInstanceConverter; -import org.tinytim.voc.TMDM; -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.Locator; -import org.tmapi.core.Occurrence; -import org.tmapi.core.ScopedObject; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.TopicMapObject; -import org.tmapi.core.TopicName; -import org.tmapi.core.Variant; - -import com.semagia.mio.IMapHandler; -import com.semagia.mio.IRef; -import com.semagia.mio.MIOException; -import com.semagia.mio.voc.XSD; - -/** - * {@link com.semagia.mio.IMapHandler} implementation. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev: 123 $ - $Date: 2008-08-14 14:05:34 +0200 (Do, 14 Aug 2008) $ - */ -public class TinyTimMapInputHandler implements IMapHandler { - - private enum State { - INITIAL, TOPIC, ASSOCIATION, ROLE, OCCURRENCE, NAME, VARIANT, - SCOPE, THEME, REIFIER, PLAYER, ISA, TYPE; - } - - private static final Logger LOG = Logger.getLogger(TinyTimMapInputHandler.class.getName()); - - private TopicMapImpl _tm; - private List<State> _stateStack; - private List<TopicMapObject> _constructStack; - - public TinyTimMapInputHandler() { - } - - public TinyTimMapInputHandler(TopicMap topicMap) { - this(); - setTopicMap(topicMap); - } - - /** - * Sets the topic map instance to operate on. - * - * @param topicMap The topic map. - */ - public void setTopicMap(TopicMap topicMap) { - if (topicMap == null) { - throw new IllegalArgumentException("The topic map must not be null"); - } - _tm = (TopicMapImpl) topicMap; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTopicMap() - */ - public void startTopicMap() throws MIOException { - _constructStack = new ArrayList<TopicMapObject>(); - _stateStack = new ArrayList<State>(); - _enterState(State.INITIAL, _tm); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTopicMap() - */ - public void endTopicMap() throws MIOException { - TypeInstanceConverter.convertAssociationsToTypes(_tm); - _constructStack = null; - _stateStack = null; - _tm = null; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTopic(com.semagia.mio.IRef) - */ - public void startTopic(IRef identity) throws MIOException { - _enterState(State.TOPIC, _createTopic(identity)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTopic() - */ - public void endTopic() throws MIOException { - Topic topic = (Topic) _leaveStatePopConstruct(State.TOPIC); - _handleTopic(topic); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startAssociation() - */ - public void startAssociation() throws MIOException { - _enterState(State.ASSOCIATION, _tm.createAssociation()); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endAssociation() - */ - public void endAssociation() throws MIOException { - _leaveStatePopConstruct(State.ASSOCIATION); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startRole() - */ - public void startRole() throws MIOException { - assert _state() == State.ASSOCIATION; - _enterState(State.ROLE, ((Association) _peekConstruct()).createAssociationRole(null, null)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endRole() - */ - public void endRole() throws MIOException { - _leaveStatePopConstruct(State.ROLE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startPlayer() - */ - public void startPlayer() throws MIOException { - assert _state() == State.ROLE; - _enterState(State.PLAYER); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endPlayer() - */ - public void endPlayer() throws MIOException { - _leaveState(State.PLAYER); - assert _state() == State.ROLE; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startOccurrence() - */ - public void startOccurrence() throws MIOException { - _enterState(State.OCCURRENCE, _peekTopic().createOccurrence((Locator) null, null, null)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endOccurrence() - */ - public void endOccurrence() throws MIOException { - _leaveStatePopConstruct(State.OCCURRENCE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startName() - */ - public void startName() throws MIOException { - _enterState(State.NAME, _peekTopic().createTopicName(null, null)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endName() - */ - public void endName() throws MIOException { - TopicName name = (TopicName) _leaveStatePopConstruct(State.NAME); - if (name.getType() == null) { - name.setType(_topicBySubjectIdentifier(TMDM.TOPIC_NAME)); - } - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startVariant() - */ - public void startVariant() throws MIOException { - assert _state() == State.NAME; - _enterState(State.VARIANT, ((TopicName) _peekConstruct()).createVariant((Locator) null, null)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endVariant() - */ - @SuppressWarnings("unchecked") - public void endVariant() throws MIOException { - Variant variant = (Variant) _leaveStatePopConstruct(State.VARIANT); - Collection<Topic> scope = variant.getScope(); - if (scope.isEmpty() || variant.getTopicName().getScope().equals(scope)) { - throw new MIOException("The variant has no scope"); - } - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startType() - */ - public void startType() throws MIOException { - assert _peekConstruct() instanceof ITyped; - _enterState(State.TYPE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endType() - */ - public void endType() throws MIOException { - _leaveState(State.TYPE); - assert _peekConstruct() instanceof ITyped; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startScope() - */ - public void startScope() throws MIOException { - assert _peekConstruct() instanceof ScopedObject; - _enterState(State.SCOPE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endScope() - */ - public void endScope() throws MIOException { - _leaveState(State.SCOPE); - assert _peekConstruct() instanceof ScopedObject; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTheme() - */ - public void startTheme() throws MIOException { - assert _state() == State.SCOPE; - _enterState(State.THEME); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTheme() - */ - public void endTheme() throws MIOException { - _leaveState(State.THEME); - assert _state() == State.SCOPE; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#subjectIdentifier(java.lang.String) - */ - public void subjectIdentifier(String subjectIdentifier) throws MIOException { - Locator sid = _tm.createLocator(subjectIdentifier); - Topic topic = _peekTopic(); - Topic existing = _tm.getTopicBySubjectIdentifier(sid); - if (existing != null && !existing.equals(topic)) { - _merge(existing, topic); - } - else { - TopicMapObject tmo = _tm.getObjectByItemIdentifier(sid); - if (tmo != null && tmo instanceof Topic && !tmo.equals(topic)) { - _merge((Topic) tmo, topic); - } - } - topic.addSubjectIdentifier(sid); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#subjectLocator(java.lang.String) - */ - public void subjectLocator(String subjectLocator) throws MIOException { - Locator slo = _tm.createLocator(subjectLocator); - Topic topic = _peekTopic(); - Topic existing = _tm.getTopicBySubjectLocator(slo); - if (existing != null && !existing.equals(topic)) { - _merge(existing, topic); - } - topic.addSubjectLocator(slo); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#itemIdentifier(java.lang.String) - */ - public void itemIdentifier(String itemIdentifier) throws MIOException { - Locator iid = _tm.createLocator(itemIdentifier); - TopicMapObject tmo = _peekConstruct(); - if (_state() == State.TOPIC) { - TopicMapObject existing = _tm.getObjectByItemIdentifier(iid); - if (existing != null && existing instanceof Topic && !existing.equals(tmo)) { - _merge((Topic) existing, (Topic) tmo); - } - else { - Topic topic = _tm.getTopicBySubjectIdentifier(iid); - if (topic != null && !topic.equals(tmo)) { - _merge(topic, (Topic) tmo); - } - } - } - tmo.addSourceLocator(iid); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startIsa() - */ - public void startIsa() throws MIOException { - assert _state() == State.TOPIC; - _enterState(State.ISA); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endIsa() - */ - public void endIsa() throws MIOException { - _leaveState(State.ISA); - assert _state() == State.TOPIC; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startReifier() - */ - public void startReifier() throws MIOException { - assert _peekConstruct() instanceof IReifiable; - _enterState(State.REIFIER); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endReifier() - */ - public void endReifier() throws MIOException { - _leaveState(State.REIFIER); - assert _peekConstruct() instanceof IReifiable; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#topicRef(com.semagia.mio.IRef) - */ - public void topicRef(IRef identity) throws MIOException { - _handleTopic(_createTopic(identity)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#value(java.lang.String) - */ - public void value(String value) throws MIOException { - assert _state() == State.NAME; - ((TopicName) _peekConstruct()).setValue(value); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#value(java.lang.String, java.lang.String) - */ - public void value(String value, String datatype) throws MIOException { - boolean isLocator = XSD.ANY_URI.equals(datatype); - if (!isLocator && !XSD.STRING.equals(datatype)) { - LOG.warning("The datatype '" + datatype + "' was converted into xsd:string"); - } - if (_state() == State.OCCURRENCE) { - Occurrence occ = (Occurrence) _peekConstruct(); - if (isLocator) { - occ.setResource(_tm.createLocator(value)); - } - else { - occ.setValue(value); - } - } - else { - assert _state() == State.VARIANT; - Variant variant = (Variant) _peekConstruct(); - if (isLocator) { - variant.setResource(_tm.createLocator(value)); - } - else { - variant.setValue(value); - } - } - } - - /** - * Enters a state. - * - * @param state The state to push ontop of the state stack. - */ - private void _enterState(State state) { - _stateStack.add(state); - } - - /** - * Enters a state and pushes the Topic Maps construct ontop of the construct - * stack. - * - * @param state The state to enter. - * @param tmo The Topic Maps construct which should be pushed to the stack. - */ - private void _enterState(State state, TopicMapObject tmo) { - _enterState(state); - _constructStack.add(tmo); - } - - /** - * Leaves a state. - * - * @param state The state to leave. - * @throws MIOException If the state is not equals to the current state. - */ - private void _leaveState(State state) throws MIOException { - State current = _stateStack.remove(_stateStack.size()-1); - if (state != current) { - _reportError("Unexpected state: " + current + ", expected: " + state); - } - } - - /** - * Leaves a state and removed the Topic Maps construct from the top of the - * construct stack. - * - * @param state The state to leave. - * @return The removed construct. - * @throws MIOException If the state is not equals to the current state. - */ - private TopicMapObject _leaveStatePopConstruct(State state) throws MIOException { - _leaveState(state); - return _constructStack.remove(_constructStack.size()-1); - } - - /** - * Returns the Topic Maps construct on top of the stack. - * - * @return The Topic Maps construct. - */ - private TopicMapObject _peekConstruct() { - return _constructStack.get(_constructStack.size()-1); - } - - /** - * Returns the topic on top of the stack. - * - * @return The topic. - */ - private Topic _peekTopic() { - return (Topic) _peekConstruct(); - } - - /** - * Returns the current state. - * - * @return The current state. - */ - private State _state() { - return _stateStack.get(_stateStack.size()-1); - } - - /** - * Handles the topic dependent on the current state. - * - * @param topic The topic to handle. - */ - private void _handleTopic(Topic topic) { - switch (_state()) { - case ISA: _peekTopic().addType(topic); break; - case TYPE: ((ITyped) _peekConstruct()).setType(topic); break; - case PLAYER: ((AssociationRole) _peekConstruct()).setPlayer(topic); break; - case THEME: ((ScopedObject) _peekConstruct()).addScopingTopic(topic); break; - case REIFIER: ((IReifiable) _peekConstruct()).setReifier(topic); break; - } - } - - /** - * Merges the <tt>source</tt> topic with the <tt>target</tt>. - * - * Further, this method ensures that the construct stack stays valid: If - * the <tt>source</tt> is part of the stack, it is replaced with - * <tt>target</tt>. - * - * @param source The source topic (will be removed). - * @param target The target topic. - */ - private void _merge(Topic source, Topic target) { - int i = _constructStack.indexOf(source); - while (i > -1) { - _constructStack.set(i, target); - i = _constructStack.indexOf(source); - } - target.mergeIn(source); - } - - /** - * Returns either an existing topic with the specified identity or creates - * a topic with the given identity. - * - * @param ref The identity of the topic. - * @return A topic instance. - * @throws MIOException - */ - private Topic _createTopic(IRef ref) throws MIOException { - Locator loc = _tm.createLocator(ref.getIRI()); - switch (ref.getType()) { - case IRef.ITEM_IDENTIFIER: return _topicByItemIdentifier(loc); - case IRef.SUBJECT_IDENTIFIER: return _topicBySubjectIdentifier(loc); - case IRef.SUBJECT_LOCATOR: return _topicBySubjectLocator(loc); - default: _reportError("Unknown reference type " + ref.getType()); - } - // Never returned, an exception was thrown - return null; - } - - /** - * Returns either an existing topic with the specified item identfier, - * or creates a topic with the given item identifier. - * - * @param iid The item identifier of the topic. - * @return A topic instance. - */ - private Topic _topicByItemIdentifier(Locator iid) { - TopicMapObject tmo = _tm.getObjectByItemIdentifier(iid); - Topic topic = (tmo instanceof Topic) ? (Topic) tmo : null; - if (topic == null) { - topic = _tm.getTopicBySubjectIdentifier(iid); - if (topic != null) { - topic.addSourceLocator(iid); - } - } - if (topic == null) { - topic = _tm.createTopic(); - topic.addSourceLocator(iid); - } - return topic; - } - - /** - * Returns either an existing topic with the specified subject identfier, - * or creates a topic with the given subject identifier. - * - * @param sid The subject identifier of the topic. - * @return A topic instance. - */ - private Topic _topicBySubjectIdentifier(Locator sid) { - Topic topic = _tm.getTopicBySubjectIdentifier(sid); - if (topic == null) { - TopicMapObject tmo = _tm.getObjectByItemIdentifier(sid); - if (tmo instanceof Topic) { - topic = (Topic) tmo; - topic.addSubjectIdentifier(sid); - } - } - if (topic == null) { - topic = _tm.createTopic(); - topic.addSubjectIdentifier(sid); - } - return topic; - } - - /** - * Returns either an existing topic with the specified subject locator, - * or creates a topic with the given subject locator. - * - * @param slo The subject locator of the topic. - * @return A topic instance. - */ - private Topic _topicBySubjectLocator(Locator slo) { - Topic topic = _tm.getTopicBySubjectLocator(slo); - if (topic == null) { - topic = _tm.createTopic(); - topic.addSubjectLocator(slo); - } - return topic; - } - - /** - * Reports an error. - * - * @param msg The error message. - * @throws MIOException Thrown in any case. - */ - private static void _reportError(String msg) throws MIOException { - throw new MIOException(msg); - } - -} Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2008-11-20 16:55:44 UTC (rev 222) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2008-11-21 13:17:29 UTC (rev 223) @@ -19,7 +19,6 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; -import org.tinytim.Version; import org.xml.sax.Attributes; import org.xml.sax.helpers.AttributesImpl; @@ -58,9 +57,7 @@ _out.write(_encoding); _out.write("\" standalone=\"yes\"?>"); _newline(); - _out.write("<!-- Generated by tinyTiM v"); - _out.write(Version.RELEASE); - _out.write(" - http://tinytim.sourceforge.net/ -->"); + _out.write("<!-- Generated by tinyTiM -- http://tinytim.sourceforge.net/ -->"); _newline(); _depth = 0; } Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/AbstractTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio15/AbstractTopicMapWriter.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/AbstractTopicMapWriter.java 2008-11-21 13:17:29 UTC (rev 223) @@ -0,0 +1,73 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.util.Set; + +import org.tmapi.core.Locator; +import org.tmapi.core.Topic; + +/** + * Common, abstract superclass for {@link TopicMapWriter} implementations. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +abstract class AbstractTopicMapWriter implements TopicMapWriter { + + protected final String _baseIRI; + + protected AbstractTopicMapWriter(final String baseIRI) { + _baseIRI = baseIRI; + } + + /** + * Returns an identifier for the topic. + * <p> + * The algorithm tries to avoid to use the internal identifier which may + * cause yet another item identifier. If the topic has an item identifier + * which starts with the specified IRI provided in the constructor, the + * algorithm tries to use the fragment identifier. + * </p> + * + * @param topic The topic to return an identifier for. + * @return An identifier, never <tt>null</tt>. + */ + protected String _getId(final Topic topic) { + String id = null; + @SuppressWarnings("unchecked") + Set<Locator> iids = topic.getSourceLocators(); + for (Locator loc: iids) { + String reference = loc.getReference(); + if (!reference.startsWith(_baseIRI)) { + continue; + } + int fragIdx = reference.indexOf('#'); + if (fragIdx < 0) { + continue; + } + id = reference.substring(fragIdx+1); + if (id.startsWith("id-")) { + id = null; + } + if (id != null) { + break; + } + } + return id != null ? id : "id-" + topic.getObjectId(); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/AbstractTopicMapWriter.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/CXTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio15/CXTMTopicMapWriter.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/CXTMTopicMapWriter.java 2008-11-21 13:17:29 UTC (rev 223) @@ -0,0 +1,1261 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.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; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.IdentityHashMap; +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.DuplicateRemovalUtils; +import org.tinytim.IConstruct; +import org.tinytim.IDatatypeAwareConstruct; +import org.tinytim.IReifiable; +import org.tinytim.ITyped; +import org.tinytim.TopicMapImpl; +import org.tinytim.index.ITypeInstanceIndex; +import org.tinytim.voc.TMDM; +import org.tmapi.core.Association; +import org.tmapi.core.AssociationRole; +import org.tmapi.core.DuplicateSourceLocatorException; +import org.tmapi.core.Locator; +import org.tmapi.core.MergeException; +import org.tmapi.core.ModelConstraintException; +import org.tmapi.core.Occurrence; +import org.tmapi.core.ScopedObject; +import org.tmapi.core.TMAPIException; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicInUseException; +import org.tmapi.core.TopicMap; +import org.tmapi.core.TopicMapObject; +import org.tmapi.core.TopicName; +import org.tmapi.core.Variant; + +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. The canonicalizer requires that the property + * {@link org.tinytim.Property#XTM10_REIFICATION} is set to <tt>false</tt> and + * that the property {@link org.tinytim.Property#INHERIT_NAME_SCOPE} is enabled + * (set to <tt>true</tt>). + * </p> + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class CXTMTopicMapWriter implements TopicMapWriter { + + private static final Logger LOG = Logger.getLogger(CXTMTopicMapWriter.class.getName()); + + private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; + + private static final AssociationRole[] _EMPTY_ROLES = new AssociationRole[0]; + + private Topic _type; + private Topic _instance; + private Topic _typeInstance; + + private XMLC14NWriter _out; + private final String _normBase; + private Map<TopicMapObject, Integer> _construct2Id; + private Map<Topic, List<AssociationRole>> _topic2Roles; + private Map<String, String> _locator2Norm; + + private Comparator<Topic> _topicComparator; + private Comparator<Association> _assocComparator; + private Comparator<AssociationRole> _roleComparator; + private Comparator<Occurrence> _occComparator; + private Comparator<TopicName> _nameComparator; + private Comparator<Variant> _variantComparator; + private Comparator<Set<Locator>> _locSetComparator; + private Comparator<Locator> _locComparator; + private Comparator<Set<Topic>> _scopeComparator; + + private Map<Association, AssociationRole[]> _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 CXTMTopicMapWriter(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 <code>topicMap</code> 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. + */ + public void write(TopicMap topicMap) throws IOException { + DuplicateRemovalUtils.removeDuplicates(topicMap); + _construct2Id = new IdentityHashMap<TopicMapObject, Integer>(); + _locator2Norm = new HashMap<String, String>(); + _assoc2Roles = new IdentityHashMap<Association, AssociationRole[]>(); + _topic2Roles = new IdentityHashMap<Topic, List<AssociationRole>>(); + ITypeInstanceIndex 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, (IReifiable)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. + */ + @SuppressWarnings("unchecked") + private Topic[] _fetchTopics(TopicMap topicMap, ITypeInstanceIndex 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()); + 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 <code>topics</code> + * 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(TopicMapImpl 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. + */ + @SuppressWarnings("unchecked") + private Association[] _fetchAssociations(TopicMap tm, ITypeInstanceIndex 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()); + 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. + */ + @SuppressWarnings("unchecked") + 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<AssociationRole> roles_ = assoc.getAssociationRoles(); + AssociationRole[] roles = roles_.toArray(new AssociationRole[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 AssociationRole[] _getRoles(Association assoc) { + AssociationRole[] 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. + */ + @SuppressWarnings("unchecked") + private TopicName[] _getNames(Topic topic) { + Set<TopicName> names_ = topic.getTopicNames(); + TopicName[] names = names_.toArray(new TopicName[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. + */ + @SuppressWarnings("unchecked") + private Variant[] _getVariants(TopicName 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. + */ + @SuppressWarnings("unchecked") + private Occurrence[] _getOccurrences(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(TopicMapObject tmo) { + return _construct2Id.get(tmo).intValue(); + } + + /** + * Serializes the <code>topic</code>. + * + * @param topic The topic to serialize. + * @throws IOException If an error occurs. + */ + @SuppressWarnings("unchecked") + private void _writeTopic(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); + TopicName[] 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); + } + Set<AssociationRole> roles_ = new HashSet<AssociationRole>(topic.getRolesPlayed()); + List<AssociationRole> alienRoles = _topic2Roles.get(topic); + if (alienRoles != null) { + roles_.addAll(alienRoles); + } + AssociationRole[] roles = roles_.toArray(new AssociationRole[roles_.size()]); + Arrays.sort(roles, _roleComparator); + AttributesImpl roleAttrs = new AttributesImpl(); + StringBuilder sb = new StringBuilder(); + for (int i=0; i < roles.length; i++) { + sb.append("association.") + .append(_indexOf(roles[i].getAssociation())) + .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. + */ + @SuppressWarnings("unchecked") + private void _writeAssociation(Association assoc) throws IOException { + _out.startElement("association", _attributes(assoc, _indexOf(assoc))); + _out.newline(); + _writeType((ITyped) assoc); + for (AssociationRole role: _getRoles(assoc)) { + _out.startElement("role", _attributes(role, _indexOf(role))); + _out.newline(); + _out.startElement("player", _topicRef(role.getPlayer())); + _out.endElement("player"); + _out.newline(); + _writeType((ITyped) 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. + * @throws IOException If an error occurs. + */ + private void _writeOccurrence(Occurrence occ, int pos) throws IOException { + _out.startElement("occurrence", _attributes(occ, pos)); + _out.newline(); + _writeDatatyped((IDatatypeAwareConstruct) occ); + _writeType((ITyped) 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(IDatatypeAwareConstruct obj) throws IOException { + String value = obj.getValue2(); + String datatype = obj.getDatatype().getReference(); + //TODO: Handle xsd:decimal, xsd:integer, xsd:date, xsd:dateTime xsd:anyType(?!?) + if (_XSD_ANY_URI.equals(datatype)) { + value = _normalizeLocator(value); + } + _out.startElement("value"); + _out.characters(value); + _out.endElement("value"); + _out.newline(); + _out.startElement("datatype"); + _out.characters(datatype); + _out.endElement("datatype"); + _out.newline(); + } + + /** + * Serializes a topic name. + * + * @param name The name to serialize. + * @throws IOException If an error occurs. + */ + private void _writeName(TopicName 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((ITyped) 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((IDatatypeAwareConstruct) 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(ITyped typed) throws IOException { + Topic type = typed.getType(); + if (type == null) { + _reportInvalid("The type of " + typed + " is null"); + } + _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. + */ + @SuppressWarnings("unchecked") + private void _writeScope(ScopedObject 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(Locator loc) throws IOException { + _out.startElement("locator"); + _out.characters(_normalizeLocator(loc.getReference())); + _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. + */ + @SuppressWarnings("unchecked") + private void _writeItemIdentifiers(TopicMapObject tmo) throws IOException { + _writeLocatorSet("itemIdentifiers", tmo.getSourceLocators()); + } + + /** + * Serializes the <code>locators</code> using the <code>localName</code> as + * element name. + * + * If the set of <code>locators</code> 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 { + 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(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. + * @return Attributes which contain a reference to the reifier (if any) and + * the number of the provided Topic Maps construct. + */ + private Attributes _attributes(TopicMapObject reifiable, int i) { + AttributesImpl attrs = new AttributesImpl(); + _addReifier(attrs, (IReifiable)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(AttributesImpl attrs, IReifiable 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(String locator) { + String normLoc = _locator2Norm.get(locator); + if (normLoc != null) { + return normLoc; + } + normLoc = locator; + if (locator.startsWith(_normBase)) { + normLoc = locator.substring(_normBase.length()); + } + else { + int i = 0; + int slashPos = -1; + final int max = _normBase.length() < locator.length() ? _normBase.length() + : locator.length(); + while(i < max && _normBase.charAt(i) == locator.charAt(i)) { + if (_normBase.charAt(i) == '/') { + slashPos = i; + } + i++; + } + if (slashPos > -1) { + normLoc = locator.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(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(String msg) { + LOG.warning("Invalid CXTM: '" + msg + "'"); + } + + + /* + * Comparators. + */ + + private final class TopicComparator implements Comparator<Topic> { + + @SuppressWarnings("unchecked") + 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.getSourceLocators(), o2.getSourceLocators()); + } + } + 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(ITyped o1, ITyped 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. + */ + @SuppressWarnings("unchecked") + int compareScope(ScopedObject o1, ScopedObject 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(IDatatypeAwareConstruct o1, IDatatypeAwareConstruct o2) { + int res = compareString(o1.getValue2(), o2.getValue2()); + 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<AssociationRole>> _roleSetComparator; + + AssociationComparator() { + _roleSetComparator = new RoleSetComparator(); + } + + @SuppressWarnings("unchecked") + public int compare(Association o1, Association o2) { + if (o1 == o2) { + return 0; + } + int res = compareType((ITyped) o1, (ITyped) o2); + if (res == 0) { + res = _roleSetComparator.compare(o1.getAssociationRoles(), o2.getAssociationRoles()); + if (res == 0) { + res = compareScope(o1, o2); + } + } + return res; + } ... [truncated message content] |
From: <lh...@us...> - 2008-11-21 14:12:54
|
Revision: 225 http://tinytim.svn.sourceforge.net/tinytim/?rev=225&view=rev Author: lheuer Date: 2008-11-21 14:12:50 +0000 (Fri, 21 Nov 2008) Log Message: ----------- Build scripts use SLF4J 1.5.6 now Modified Paths: -------------- tinytim-mio/trunk/build-15.xml tinytim-mio/trunk/build.xml Modified: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2008-11-21 14:09:38 UTC (rev 224) +++ tinytim-mio/trunk/build-15.xml 2008-11-21 14:12:50 UTC (rev 225) @@ -11,7 +11,7 @@ <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0b2.jar"/> - <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.2.jar"/> + <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.3.jar"/> <target name="help"> Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2008-11-21 14:09:38 UTC (rev 224) +++ tinytim-mio/trunk/build.xml 2008-11-21 14:12:50 UTC (rev 225) @@ -11,7 +11,7 @@ <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a1.jar"/> <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a3.jar"/> - <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.2.jar"/> + <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.3.jar"/> <target name="help"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-22 11:14:15
|
Revision: 227 http://tinytim.svn.sourceforge.net/tinytim/?rev=227&view=rev Author: lheuer Date: 2008-11-22 11:14:10 +0000 (Sat, 22 Nov 2008) Log Message: ----------- - Updated MIO libs, no effects on tinyTiM's API - Converted TinyTimMapInputHandler's state array from int[] to byte[] (even if Java makes no distinction) - Removed "--" from XMLWriter's comment Modified Paths: -------------- tinytim-mio/trunk/lib/semagia-mio-0.9.3.jar tinytim-mio/trunk/lib/semagia-mio-snello-0.9.3.jar tinytim-mio/trunk/lib/semagia-mio-xtm-0.9.3.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java Modified: tinytim-mio/trunk/lib/semagia-mio-0.9.3.jar =================================================================== (Binary files differ) Modified: tinytim-mio/trunk/lib/semagia-mio-snello-0.9.3.jar =================================================================== (Binary files differ) Modified: tinytim-mio/trunk/lib/semagia-mio-xtm-0.9.3.jar =================================================================== (Binary files differ) Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2008-11-21 15:16:07 UTC (rev 226) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2008-11-22 11:14:10 UTC (rev 227) @@ -47,18 +47,14 @@ import com.semagia.mio.MIOException; /** - * Abstract {@link com.semagia.mio.IMapHandler} implementation. - * <p> - * This class utilises the <tt>.core</tt> package since some <tt>...Impl</tt> - * classes have only package visibility. - * </p> + * Implementation of a {@link com.semagia.mio.IMapHandler} for tinyTiM. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ public final class TinyTimMapInputHandler implements IMapHandler { - private static final int + private static final byte INITIAL = 1, TOPIC = 2, ASSOCIATION = 3, @@ -80,7 +76,7 @@ private final IConstructFactory _factory; private final ITopicMap _tm; private final List<Topic> _scope; - private int[] _stateStack; + private byte[] _stateStack; private int _stateSize; private IConstruct[] _constructStack; private int _constructSize; @@ -99,7 +95,7 @@ */ public void startTopicMap() throws MIOException { _constructStack = new IConstruct[_CONSTRUCT_SIZE]; - _stateStack = new int[_STATE_SIZE]; + _stateStack = new byte[_STATE_SIZE]; _constructSize = 0; _stateSize = 0; _enterState(INITIAL, _tm); @@ -386,9 +382,9 @@ * * @param state The state to push ontop of the state stack. */ - private void _enterState(int state) { + private void _enterState(byte state) { if (_stateSize >= _stateStack.length) { - int[] states = new int[_stateStack.length*2]; + byte[] states = new byte[_stateStack.length*2]; System.arraycopy(_stateStack, 0, states, 0, _stateStack.length); _stateStack = states; } @@ -402,7 +398,7 @@ * @param state The state to enter. * @param tmo The Topic Maps construct which should be pushed to the stack. */ - private void _enterState(int state, Construct tmo) { + private void _enterState(byte state, Construct tmo) { _enterState(state); if (_constructSize >= _constructStack.length) { IConstruct[] constructs = new IConstruct[_constructStack.length*2]; @@ -418,7 +414,7 @@ * @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 { + private void _leaveState(byte state) throws MIOException { if (state != _state()) { _reportError("Unexpected state: " + _state() + ", expected: " + state); } @@ -432,7 +428,7 @@ * @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 { + private IConstruct _leaveStatePopConstruct(byte state) throws MIOException { _leaveState(state); final IConstruct construct = _peekConstruct(); _constructSize--; @@ -463,7 +459,7 @@ * * @return The current state. */ - private int _state() { + private byte _state() { return _stateStack[_stateSize-1]; } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2008-11-21 15:16:07 UTC (rev 226) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2008-11-22 11:14:10 UTC (rev 227) @@ -57,7 +57,7 @@ _out.write(_encoding); _out.write("\" standalone=\"yes\"?>"); _newline(); - _out.write("<!-- Generated by tinyTiM -- http://tinytim.sourceforge.net/ -->"); + _out.write("<!-- Generated by tinyTiM - http://tinytim.sourceforge.net/ -->"); _newline(); _depth = 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-23 14:50:31
|
Revision: 232 http://tinytim.svn.sourceforge.net/tinytim/?rev=232&view=rev Author: lheuer Date: 2008-11-23 14:50:27 +0000 (Sun, 23 Nov 2008) Log Message: ----------- - Added JSON Topic Maps (JTM) writer - Made prettifying XML configurable - Updated MIO XTM lib Modified Paths: -------------- tinytim-mio/trunk/CHANGES.txt tinytim-mio/trunk/build-15.xml tinytim-mio/trunk/lib/semagia-mio-xtm-0.9.3.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM20TopicMapWriter.java Added Paths: ----------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JSONWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/CHANGES.txt 2008-11-23 14:50:27 UTC (rev 232) @@ -17,8 +17,9 @@ - Snello - LTM 1.3 * Moved CXTMWriter into .mio package, implements TopicMapWriter -* XTM 1.0 writer -* XTM 2.0 writer +* JSON Topic Maps (JTM) writer +* XML Topic Maps (XTM) 1.0 writer +* XML Topic Maps (XTM) 2.0 writer * Deprecated some TopicMapImporter methods which take a sax.InputSource as argument * Added docs to TopicMapImporter that it may become deprecated Modified: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/build-15.xml 2008-11-23 14:50:27 UTC (rev 232) @@ -123,7 +123,7 @@ <target name="compile" depends="clean, prepare"> <javac destdir="${dir.build.classes}" debug="${debug}" - excludes="org/tinytim/mio/AbstractTopicMapWriter* org/tinytim/mio/CXTMTopicMapWriter* org/tinytim/mio/XTM*TopicMapWriter*" + excludes="org/tinytim/mio/AbstractTopicMapWriter* org/tinytim/mio/CXTMTopicMapWriter* org/tinytim/mio/XTM*TopicMapWriter* org/tinytim/mio/JTM* org/tinytim/mio/JSON*" includes="org/tinytim/mio15/** org/tinytim/mio/*TopicMapReader* org/tinytim/mio/*TopicMapImporter*" target="1.5"> <classpath> Modified: tinytim-mio/trunk/lib/semagia-mio-xtm-0.9.3.jar =================================================================== (Binary files differ) Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -29,7 +29,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -abstract class AbstractXTMWriter extends AbstractTopicMapWriter { +abstract class AbstractXTMTopicMapWriter extends AbstractTopicMapWriter { protected final AttributesImpl _attrs; @@ -42,7 +42,7 @@ * @param baseIRI The base IRI. * @throws IOException If an error occurs. */ - protected AbstractXTMWriter(final OutputStream out, final String baseIRI) + protected AbstractXTMTopicMapWriter(final OutputStream out, final String baseIRI) throws IOException { this(out, baseIRI, "utf-8"); } @@ -59,14 +59,34 @@ * @throws IOException * If an error occurs. */ - protected AbstractXTMWriter(final OutputStream out, final String baseIRI, + protected AbstractXTMTopicMapWriter(final OutputStream out, final String baseIRI, final String encoding) throws IOException { super(baseIRI); if (encoding == null) { throw new IOException("The encoding must not be null"); } _out = new XMLWriter(out, encoding); + _out.setPrettify(true); _attrs = new AttributesImpl(); } + /** + * Enables / disables newlines and indentation of XML elements. + * (newlines and indentation is enabled by default) + * + * @param prettify <tt>true</tt> to enable prettified XML, otherwise <tt>false</tt>. + */ + public void setPrettify(boolean prettify) { + _out.setPrettify(prettify); + } + + /** + * Returns if newlines and indentation are enabled. + * + * @return <tt>true</tt> if prettified XML is enabled, otherwise <tt>false</tt>. + */ + public boolean getPrettify() { + return _out.getPrettify(); + } + } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CXTMTopicMapWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -29,6 +29,7 @@ import java.util.Set; import java.util.logging.Logger; +import org.tinytim.internal.api.IIndexManagerAware; import org.tinytim.internal.utils.CollectionFactory; import org.tinytim.utils.DuplicateRemovalUtils; import org.tinytim.voc.TMDM; @@ -143,7 +144,7 @@ */ public void write(TopicMap topicMap) throws IOException { DuplicateRemovalUtils.removeDuplicates(topicMap); - TypeInstanceIndex typeInstanceIndex = topicMap.getIndex(TypeInstanceIndex.class); + TypeInstanceIndex typeInstanceIndex = ((IIndexManagerAware)topicMap).getIndexManager().getTypeInstanceIndex(); if (!typeInstanceIndex.isAutoUpdated()) { typeInstanceIndex.reindex(); } Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JSONWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JSONWriter.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JSONWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -0,0 +1,217 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +/** + * Simple JSON serializer. This class is not usable as a generic JSON writer + * since it is possible to create an invalid JSON representation, but + * it is good enough to support JTM. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +final class JSONWriter { + + private OutputStreamWriter _out; + private boolean _wantComma; + private int _depth; + private boolean _prettify; + + public JSONWriter(OutputStream out) throws IOException { + _out = new OutputStreamWriter(out, "utf-8"); + } + + public void setPrettify(boolean prettify) { + _prettify = prettify; + } + + public boolean getPrettify() { + return _prettify; + } + + public void startDocument() { + _depth = 0; + } + + public void endDocument() throws IOException { + _out.write('\n'); + _out.flush(); + } + + private void _indent() throws IOException { + if (!_prettify) { + return; + } + if (_depth > 0) { + _out.write('\n'); + } + int indent = _depth*2; + char[] chars = new char[indent]; + for (int i=0; i<indent; i++) { + chars[i] = ' '; + } + _out.write(chars); + } + + public void startObject() throws IOException { + if (_wantComma) { + _out.write(','); + } + _indent(); + _out.write('{'); + _depth++; + _wantComma = false; + } + + public void endObject() throws IOException { + _out.write('}'); + _depth--; + _wantComma = true; + } + + public void startArray() throws IOException { + _out.write('['); + _depth++; + _wantComma = false; + } + + public void endArray() throws IOException { + _out.write(']'); + _depth--; + _wantComma = true; + } + + /** + * Writes the key of a <tt>"key": value</tt> pair. + * The writer assumes that the key is a valid JSON string (ensured by + * by JTM) so the keys are not escaped! + * + * @param key + * @throws IOException + */ + public void key(String key) throws IOException { + if (_wantComma) { + _out.write(','); + _indent(); + } + _out.write('"'); + _out.write(key); + _out.write('"'); + _out.write(':'); + _wantComma = false; + } + + public void value(String value) throws IOException { + if (_wantComma) { + _out.write(','); + } + _out.write(escape(value)); + _wantComma = true; + } + + /** + * + * + * @param value + * @return + */ + public static String escape(String value) { + // Code adapted from JSON.org (JSONObject.quote(String)) + // Copyrighted by JSON.org licensed under a BSD-license, see + // complete copyright notice at the end of this file. + char b; + char c = 0; + char[] chars = value.toCharArray(); + StringBuilder sb = new StringBuilder(chars.length + 4); + String t; + sb.append('"'); + for (int i = 0; i < chars.length; i += 1) { + b = c; + c = chars[i]; + switch (chars[i]) { + case '\\': + case '"': + sb.append('\\'); + sb.append(c); + break; + case '/': + if (b == '<') { + sb.append('\\'); + } + sb.append(c); + break; + case '\b': + sb.append("\\b"); + break; + case '\t': + sb.append("\\t"); + break; + case '\n': + sb.append("\\n"); + break; + case '\f': + sb.append("\\f"); + break; + case '\r': + sb.append("\\r"); + break; + default: + if (c < ' ' || (c >= '\u0080' && c < '\u00a0') || + (c >= '\u2000' && c < '\u2100')) { + t = "000" + Integer.toHexString(c); + sb.append("\\u" + t.substring(t.length() - 4)); + } else { + sb.append(c); + } + } + } + sb.append('"'); + return sb.toString(); + } + + /* + =========================================================================== + Copyright of the JSONObject code which was used to implement the "escape" + function. + =========================================================================== + + Copyright (c) 2002 JSON.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + The Software shall be used for Good, not Evil. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JSONWriter.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -0,0 +1,347 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Set; + +import org.tinytim.internal.api.IIndexManagerAware; +import org.tinytim.internal.api.IScope; +import org.tinytim.internal.api.IScoped; +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.TopicMap; +import org.tmapi.core.Typed; +import org.tmapi.core.Variant; +import org.tmapi.index.TypeInstanceIndex; + +/** + * A {@link TopicMapWriter} implementation that serializes a topic map into + * a <a href="http://www.cerny-online.com/topincs/">JSON Topic Maps</a> + * representation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class JTMTopicMapWriter implements TopicMapWriter { + + private static final String _TMDM_TYPE_INSTANCE = TMDM.TYPE_INSTANCE.getReference(); + private static final String _TMDM_TYPE = TMDM.TYPE.getReference(); + private static final String _TMDM_INSTANCE = TMDM.INSTANCE.getReference(); + + private JSONWriter _out; + private String _baseIRI; + private Topic _defaultNameType; + + /** + * Creates a JTM writer. + * + * @param out The stream the JTM is written onto. + * @param baseIRI The base IRI which is used to resolve IRIs against. + * @throws IOException If an error occurs. + */ + public JTMTopicMapWriter(OutputStream out, String baseIRI) throws IOException { + _baseIRI = baseIRI; + _out = new JSONWriter(out); + _out.setPrettify(true); + } + + /** + * Enables / disables newlines and indentation of JSON elements. + * (newlines and indentation is enabled by default) + * + * @param prettify <tt>true</tt> to enable prettified JSON, otherwise <tt>false</tt>. + */ + public void setPrettify(boolean prettify) { + _out.setPrettify(prettify); + } + + /** + * Returns if newlines and indentation are enabled. + * + * @return <tt>true</tt> if prettified JSON is enabled, otherwise <tt>false</tt>. + */ + public boolean getPrettify() { + return _out.getPrettify(); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.TopicMapWriter#write(org.tmapi.core.TopicMap) + */ + public void write(TopicMap topicMap) throws IOException { + _defaultNameType = topicMap.getTopicBySubjectIdentifier(TMDM.TOPIC_NAME); + _out.startDocument(); + _out.startObject(); + _writeReifier(topicMap); + _writeItemIdentifiers(topicMap); + _out.key("topics"); + _out.startArray(); + for (Topic topic: topicMap.getTopics()) { + _writeTopic(topic); + } + _out.endArray(); + _out.key("associations"); + _out.startArray(); + for (Association assoc: topicMap.getAssociations()) { + _writeAssociation(assoc); + } + // Write type-instance relationships + TypeInstanceIndex tiIdx = ((IIndexManagerAware) topicMap).getIndexManager().getTypeInstanceIndex(); + if (!tiIdx.isAutoUpdated()) { + tiIdx.reindex(); + } + for (Topic type: tiIdx.getTopicTypes()) { + for (Topic instance: tiIdx.getTopics(type)) { + _writeTypeInstance(type, instance); + } + } + tiIdx.close(); + _out.endArray(); + _out.endObject(); + _out.endDocument(); + } + + private void _writeTopic(Topic topic) throws IOException { + // Ignore the topic if it is the default name type and it has no further + // characteristics + if (_isDefaultNameType(topic) + && topic.getReified() == null + && topic.getSubjectIdentifiers().size() == 1 + && topic.getSubjectLocators().isEmpty() + && topic.getItemIdentifiers().isEmpty() + && topic.getRolesPlayed().isEmpty() + && topic.getTypes().isEmpty() + && topic.getNames().isEmpty() + && topic.getOccurrences().isEmpty()) { + return; + } + _out.startObject(); + _writeItemIdentifiers(topic); + _writeLocators("subject_identifiers", topic.getSubjectIdentifiers()); + _writeLocators("subject_locators", topic.getSubjectLocators()); + Set<Name> names = topic.getNames(); + if (!names.isEmpty()) { + _out.key("names"); + _out.startArray(); + for (Name name: names) { + _writeName(name); + } + _out.endArray(); + } + Set<Occurrence> occs = topic.getOccurrences(); + if (!occs.isEmpty()) { + _out.key("occurrences"); + _out.startArray(); + for (Occurrence occ: occs) { + _writeOccurrence(occ); + } + _out.endArray(); + } + _out.endObject(); + } + + private void _writeName(Name name) throws IOException { + _out.startObject(); + _writeReifier(name); + _writeItemIdentifiers(name); + if (!_isDefaultNameType(name.getType())) { + _writeType(name); + } + _writeScope(name); + _writeKeyValue("value", name.getValue()); + Set<Variant> variants = name.getVariants(); + if (!variants.isEmpty()) { + _out.key("variants"); + _out.startArray(); + for (Variant variant: variants) { + _writeVariant(variant); + } + _out.endArray(); + } + _out.endObject(); + } + + private void _writeVariant(Variant variant) throws IOException { + _out.startObject(); + _writeReifier(variant); + _writeItemIdentifiers(variant); + _writeScope(variant); + _writeDatatypeAware(variant); + _out.endObject(); + } + + private void _writeOccurrence(Occurrence occ) throws IOException { + _out.startObject(); + _writeReifier(occ); + _writeItemIdentifiers(occ); + _writeType(occ); + _writeScope(occ); + _writeDatatypeAware(occ); + _out.endObject(); + } + + private void _writeDatatypeAware(DatatypeAware datatyped) throws IOException { + Locator datatype = datatyped.getDatatype(); + String value = XSD.ANY_URI.equals(datatype) ? datatyped.locatorValue().toExternalForm() + : datatyped.getValue(); + _writeKeyValue("value", value); + _writeKeyValue("datatype", datatype.toExternalForm()); + } + + private void _writeItemIdentifiers(Construct construct) throws IOException { + _writeLocators("item_identifiers", construct.getItemIdentifiers()); + } + + private void _writeLocators(String name, Set<Locator> locators) throws IOException { + if (locators.isEmpty()) { + return; + } + _out.key(name); + _out.startArray(); + for (Locator loc: locators) { + _out.value(loc.toExternalForm()); + } + _out.endArray(); + } + + private void _writeAssociation(Association assoc) throws IOException { + Set<Role> roles = assoc.getRoles(); + if (roles.isEmpty()) { + return; + } + _out.startObject(); + _writeReifier(assoc); + _writeItemIdentifiers(assoc); + _writeType(assoc); + _writeScope(assoc); + _out.key("roles"); + _out.startArray(); + for (Role role: roles) { + _writeRole(role); + } + _out.endArray(); + _out.endObject(); + } + + private void _writeRole(Role role) throws IOException { + _out.startObject(); + _writeReifier(role); + _writeItemIdentifiers(role); + _writeType(role); + _writeKeyValue("player", _topicRef(role.getPlayer())); + _out.endObject(); + } + + private void _writeType(Typed typed) throws IOException { + _writeKeyValue("type", _topicRef(typed.getType())); + } + + private void _writeScope(Scoped scoped) throws IOException { + IScope scope = ((IScoped) scoped).getScopeObject(); + if (scope.isUnconstrained()) { + return; + } + _out.key("scope"); + _out.startArray(); + for (Topic theme: scope) { + _out.value(_topicRef(theme)); + } + _out.endArray(); + } + + /** + * Writes a type-instance association. + * <p> + * JTM provides no shortcut like "instanceOf" at the topic level to indicate + * that a topic is an instance of another topic, all type-instance + * relationships must be encoded as associations. + * </p> + * + * @param type The topic which plays the <tt>tmdm:type</tt> role. + * @param instance The topic which plays the <tt>tmdm:instance</tt> role. + * @throws IOException If an error occurs. + */ + private void _writeTypeInstance(Topic type, Topic instance) throws IOException { + _out.startObject(); + _writeKeyValue("type", _TMDM_TYPE_INSTANCE); + _out.key("roles"); + _out.startArray(); + _out.startObject(); + _writeKeyValue("type", _TMDM_TYPE); + _writeKeyValue("player", _topicRef(type)); + _out.endObject(); + _out.startObject(); + _writeKeyValue("type", _TMDM_INSTANCE); + _writeKeyValue("player", _topicRef(instance)); + _out.endObject(); + _out.endArray(); + _out.endObject(); + } + + private void _writeReifier(Reifiable reifiable) throws IOException { + Topic reifier = reifiable.getReifier(); + if (reifier == null) { + return; + } + _writeKeyValue("reifier", _topicRef(reifier)); + } + + private void _writeKeyValue(String key, String value) throws IOException { + _out.key(key); + _out.value(value); + } + + /** + * Returns an IRI which is usable to as reference to the specified topic. + * + * @param topic The topic. + * @return An IRI. + */ + private String _topicRef(Topic topic) { + Set<Locator> locs = topic.getItemIdentifiers(); + if (!locs.isEmpty()) { + return locs.iterator().next().toExternalForm(); + } + locs = topic.getSubjectIdentifiers(); + if (!locs.isEmpty()) { + return locs.iterator().next().toExternalForm(); + } + return _baseIRI + "#" + topic.getId(); + } + + /** + * Checks if the specified <tt>topic</tt> is the default TMDM name type. + * + * @param topic The topic to check, not <tt>null</tt>. + * @return <tt>true</tt> if the topic is the default name type, otherwise <tt>false</tt>. + */ + private boolean _isDefaultNameType(final Topic topic) { + return topic.equals(_defaultNameType); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -39,6 +39,7 @@ private final String _encoding; private int _depth; + private boolean _prettify; public XMLWriter(OutputStream out) throws IOException { this(out, "utf-8"); @@ -49,6 +50,14 @@ _encoding = encoding; } + public void setPrettify(boolean prettify) { + _prettify = prettify; + } + + public boolean getPrettify() { + return _prettify; + } + /** * @see org.xml.sax.DocumentHandler#startDocument() */ @@ -83,9 +92,6 @@ * @see org.xml.sax.DocumentHandler#startElement(java.lang.String, org.xml.sax.AttributeList) */ public void startElement(String name, Attributes attrs) throws IOException { - if (_depth > 0) { - _newline(); - } _indent(); _out.write('<'); _out.write(name); @@ -106,8 +112,7 @@ */ public void _endElement(String name, boolean indent) throws IOException { _depth--; - if (indent && _depth >= 0) { - _newline(); + if (indent) { _indent(); } _out.write("</"); @@ -116,9 +121,6 @@ } public void emptyElement(String name, Attributes attrs) throws IOException { - if (_depth > 0) { - _newline(); - } _indent(); _out.write('<'); _out.write(name); @@ -158,6 +160,12 @@ } private void _indent() throws IOException { + if (!_prettify) { + return; + } + if (_depth > 0) { + _newline(); + } int indent = _depth*2; char[] chars = new char[indent]; for (int i=0; i<indent; i++) { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM10TopicMapWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -49,7 +49,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -public class XTM10TopicMapWriter extends AbstractXTMWriter { +public class XTM10TopicMapWriter extends AbstractXTMTopicMapWriter { private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM20TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM20TopicMapWriter.java 2008-11-23 14:42:02 UTC (rev 231) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/XTM20TopicMapWriter.java 2008-11-23 14:50:27 UTC (rev 232) @@ -58,7 +58,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -public class XTM20TopicMapWriter extends AbstractXTMWriter { +public class XTM20TopicMapWriter extends AbstractXTMTopicMapWriter { private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; private static final String _XSD_STRING = "http://www.w3.org/2001/XMLSchema#string"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-11-25 14:11:39
|
Revision: 235 http://tinytim.svn.sourceforge.net/tinytim/?rev=235&view=rev Author: lheuer Date: 2008-11-25 14:11:21 +0000 (Tue, 25 Nov 2008) Log Message: ----------- - Reduced visibility of constructors from abstract classes - Introduced RDFTopicMapReader (derived from TopicMapReader) - Added several RDFTopicMapReader implementations - Updated mio core - Added JTM reader (inefficient implementation, to be replaced by a specialized deserializer) - Updated TopicMapImporter for the new RDF topic map readers but *not* JTMTopicMapReader Modified Paths: -------------- tinytim-mio/trunk/lib/semagia-mio-0.9.3.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java Added Paths: ----------- tinytim-mio/trunk/lib/LICENSE.json_simple.txt tinytim-mio/trunk/lib/json_simple.jar tinytim-mio/trunk/lib/semagia-mio-rdf-0.9.3.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractRDFTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/N3TopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/NTriplesTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFXMLTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TrigTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TrixTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TurtleTopicMapReader.java Added: tinytim-mio/trunk/lib/LICENSE.json_simple.txt =================================================================== --- tinytim-mio/trunk/lib/LICENSE.json_simple.txt (rev 0) +++ tinytim-mio/trunk/lib/LICENSE.json_simple.txt 2008-11-25 14:11:21 UTC (rev 235) @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + <one line to give the library's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + <signature of Ty Coon>, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + Added: tinytim-mio/trunk/lib/json_simple.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/json_simple.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: tinytim-mio/trunk/lib/semagia-mio-0.9.3.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/semagia-mio-rdf-0.9.3.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/semagia-mio-rdf-0.9.3.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractRDFTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractRDFTopicMapReader.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractRDFTopicMapReader.java 2008-11-25 14:11:21 UTC (rev 235) @@ -0,0 +1,153 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; + +import org.tmapi.core.TopicMap; + +import com.semagia.mio.IMapHandler; +import com.semagia.mio.Property; +import com.semagia.mio.Source; +import com.semagia.mio.Syntax; + +/** + * Common superclass for {@link RDFTopicMapReader}s. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +abstract class AbstractRDFTopicMapReader extends AbstractTopicMapReader + implements RDFTopicMapReader { + + protected AbstractRDFTopicMapReader(IMapHandler handler, Syntax syntax, + Source source) { + super(handler, syntax, source); + } + + protected AbstractRDFTopicMapReader(TopicMap topicMap, Syntax syntax, + File source, String docIRI) throws IOException { + super(topicMap, syntax, source, docIRI); + } + + protected AbstractRDFTopicMapReader(TopicMap topicMap, Syntax syntax, + File source) throws IOException { + super(topicMap, syntax, source); + } + + protected AbstractRDFTopicMapReader(TopicMap topicMap, Syntax syntax, + InputStream source, String docIRI) { + super(topicMap, syntax, source, docIRI); + } + + protected AbstractRDFTopicMapReader(TopicMap topicMap, Syntax syntax, + Source source) { + super(topicMap, syntax, source); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.RDFTopicMapReader#setMappingSource(java.io.File) + */ + public void setMappingSource(File file) { + try { + setMappingSource(file.toURI().toURL()); + } + catch (MalformedURLException ex) { + throw new RuntimeException(ex); + } + } + + /* (non-Javadoc) + * @see org.tinytim.mio.RDFTopicMapReader#setMappingSource(java.net.URL) + */ + public void setMappingSource(URL url) { + setMappingSource(url.toExternalForm()); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.RDFTopicMapReader#setMappingSource(java.lang.String) + */ + public void setMappingSource(String iri) { + _deserializer.setProperty(Property.RDF2TM_MAPPING_IRI, iri); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.RDFTopicMapReader#getMappingSource() + */ + public String getMappingSource() { + return (String) _deserializer.getProperty(Property.RDF2TM_MAPPING_IRI); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.RDFTopicMapReader#getMappingSourceSyntax() + */ + public MappingSyntax getMappingSourceSyntax() { + Syntax syntax = (Syntax) _deserializer.getProperty(Property.RDF2TM_MAPPING_SYNTAX); + return _toMappingSyntax(syntax); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.RDFTopicMapReader#setMappingSourceSyntax(org.tinytim.mio.RDFTopicMapReader.MappingSyntax) + */ + public void setMappingSourceSyntax(MappingSyntax syntax) { + _deserializer.setProperty(Property.RDF2TM_MAPPING_SYNTAX, _fromMappingSyntax(syntax)); + } + + private static MappingSyntax _toMappingSyntax(Syntax syntax) { + if (syntax == null) { + return null; + } + if (Syntax.N3.equals(syntax)) { + return MappingSyntax.N3; + } + if (Syntax.NTRIPLES.equals(syntax)) { + return MappingSyntax.NTRIPLES; + } + if (Syntax.RDFXML.equals(syntax)) { + return MappingSyntax.RDFXML; + } + if (Syntax.TRIG.equals(syntax)) { + return MappingSyntax.TRIG; + } + if (Syntax.TRIX.equals(syntax)) { + return MappingSyntax.TRIX; + } + if (Syntax.TURTLE.equals(syntax)) { + return MappingSyntax.TURTLE; + } + throw new RuntimeException("Internal error, no MappingSyntax found for " + syntax.getName()); + } + + + private static Syntax _fromMappingSyntax(MappingSyntax syntax) { + if (syntax == null) { + return null; + } + switch (syntax) { + case N3: return Syntax.N3; + case NTRIPLES: return Syntax.NTRIPLES; + case RDFXML: return Syntax.RDFXML; + case TRIG: return Syntax.TRIG; + case TRIX: return Syntax.TRIX; + case TURTLE: return Syntax.TURTLE; + } + throw new RuntimeException("Internal error, no mio.Syntax found for " + syntax); + } +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractRDFTopicMapReader.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java 2008-11-24 15:35:42 UTC (rev 234) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java 2008-11-25 14:11:21 UTC (rev 235) @@ -33,29 +33,29 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -public abstract class AbstractXTMTopicMapReader extends AbstractTopicMapReader { +abstract class AbstractXTMTopicMapReader extends AbstractTopicMapReader { - public AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, + protected AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, File source) throws IOException { super(topicMap, syntax, source); } - public AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, + protected AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, File source, String docIRI) throws IOException { super(topicMap, syntax, source, docIRI); } - public AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, + protected AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, InputStream source, String docIRI) { super(topicMap, syntax, source, docIRI); } - public AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, + protected AbstractXTMTopicMapReader(TopicMap topicMap, Syntax syntax, Source source) { super(topicMap, syntax, source); } - public AbstractXTMTopicMapReader(IMapHandler handler, Syntax syntax, + protected AbstractXTMTopicMapReader(IMapHandler handler, Syntax syntax, Source source) { super(handler, syntax, source); } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java 2008-11-24 15:35:42 UTC (rev 234) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java 2008-11-25 14:11:21 UTC (rev 235) @@ -72,7 +72,7 @@ /** * Enables / disables newlines and indentation of XML elements. - * (newlines and indentation is enabled by default) + * (enabled by default) * * @param prettify <tt>true</tt> to enable prettified XML, otherwise <tt>false</tt>. */ Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java 2008-11-25 14:11:21 UTC (rev 235) @@ -0,0 +1,296 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.io.IOException; +import java.io.Reader; +import java.util.List; + +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.tmapi.core.TMAPIRuntimeException; +import org.tmapi.core.TopicMap; + +import com.semagia.mio.MIOException; +import com.semagia.mio.helpers.Ref; +import com.semagia.mio.helpers.SimpleMapHandler; + +/** + * {@link TopicMapReader} implementation that deserializes + * <a href="http://www.cerny-online.com/topincs/technical-whitepaper">JSON Topic Maps (JTM)</a>. + * <p> + * The reader does not accept fragments, i.e. only a topic in a JSON document; + * each JTM instance must start with a topic map container, i.e. + * <tt>{"topics":[...]"}</tt>. The TMDM constructs must provide all + * properties, i.e. it is not allowed to omit the type of an association. The + * only exception are topic names: If the "type" property is not provided, the + * default topic name type is automatically assigned. + * </p> + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +@SuppressWarnings("unchecked") +public class JTMTopicMapReader implements TopicMapReader { + + private TopicMap _tm; + private Reader _reader; + + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + * @param reader The reader to read the JSON encoded topic map from. + * @throws IOException If an error occurs. + */ + public JTMTopicMapReader(TopicMap topicMap, Reader reader) throws IOException { + _tm = topicMap; + _reader = reader; + } + + /* (non-Javadoc) + * @see org.tinytim.mio.TopicMapReader#read() + */ + public void read() throws IOException { + Object obj = JSONValue.parse(_reader); + if (!(obj instanceof JSONObject)) { + // Nothing to do. + return; + } + JSONObject map = (JSONObject) obj; + SimpleMapHandler mapHandler = SimpleMapHandler.create(new TinyTimMapInputHandler(_tm)); + try { + mapHandler.startTopicMap(); + _handleReifier(mapHandler, map); + _handleItemIdentifiers(mapHandler, map); + _handleTopics(mapHandler, (List<JSONObject>) map.get("topics")); + _handleAssociations(mapHandler, (List<JSONObject>) map.get("associations")); + mapHandler.endTopicMap(); + } + catch (MIOException ex) { + throw new TMAPIRuntimeException(ex); + } + } + + private void _handleTopics(SimpleMapHandler mapHandler, + List<JSONObject> jsonArray) throws MIOException { + if (jsonArray == null) { + return; + } + int length = jsonArray.size(); + for (int i=0; i<length; i++) { + _handleTopic(mapHandler, jsonArray.get(i)); + } + } + + private void _handleTopic(SimpleMapHandler mapHandler, + JSONObject jsonObject) throws MIOException { + boolean seenIdentity = false; + List<String> array = (List<String>) jsonObject.get("item_identifiers"); + if (array != null) { + seenIdentity = true; + mapHandler.startTopic(Ref.createItemIdentifier(array.get(0))); + int length = array.size(); + for (int i=1; i<length; i++) { + mapHandler.itemIdentifier(array.get(i)); + } + } + array = (List<String>) jsonObject.get("subject_identifiers"); + if (array != null) { + int start = 0; + if (!seenIdentity) { + seenIdentity = true; + start = 1; + mapHandler.startTopic(Ref.createSubjectIdentifier(array.get(0))); + } + int length = array.size(); + for (int i=start; i<length; i++) { + mapHandler.subjectIdentifier(array.get(i)); + } + } + array = (List<String>) jsonObject.get("subject_locators"); + if (array != null) { + int start = 0; + if (!seenIdentity) { + seenIdentity = true; + start = 1; + mapHandler.startTopic(Ref.createSubjectLocator(array.get(0))); + } + int length = array.size(); + for (int i=start; i<length; i++) { + mapHandler.subjectLocator(array.get(i)); + } + } + if (!seenIdentity) { + throw new MIOException("Topic without any identity: " + jsonObject); + } + List<JSONObject> objects = (List<JSONObject>) jsonObject.get("occurrences"); + if (objects != null) { + int length = objects.size(); + for (int i=0; i<length; i++) { + _handleOccurrence(mapHandler, objects.get(i)); + } + } + objects = (List<JSONObject>) jsonObject.get("names"); + if (objects != null) { + int length = objects.size(); + for (int i=0; i<length; i++) { + _handleName(mapHandler, objects.get(i)); + } + } + mapHandler.endTopic(); + } + + private void _handleOccurrence(SimpleMapHandler mapHandler, + JSONObject jsonObject) throws MIOException { + mapHandler.startOccurrence(); + _handleType(mapHandler, jsonObject, true); + _handleScope(mapHandler, jsonObject); + _handleReifier(mapHandler, jsonObject); + _handleItemIdentifiers(mapHandler, jsonObject); + _handleValueDatatype(mapHandler, jsonObject); + mapHandler.endOccurrence(); + } + + private void _handleValueDatatype(SimpleMapHandler mapHandler, + JSONObject jsonObject) throws MIOException { + String value = (String) jsonObject.get("value"); + if (value == null) { + throw new MIOException("The value must not be null: " + jsonObject); + } + String datatype = (String) jsonObject.get("datatype"); + if (datatype == null) { + throw new MIOException("The datatype must not be null: " + jsonObject); + } + mapHandler.value(value, datatype); + } + + private void _handleName(SimpleMapHandler mapHandler, + JSONObject jsonObject) throws MIOException { + mapHandler.startName(); + _handleType(mapHandler, jsonObject, false); + _handleScope(mapHandler, jsonObject); + _handleReifier(mapHandler, jsonObject); + _handleItemIdentifiers(mapHandler, jsonObject); + String value = (String) jsonObject.get("value"); + if (value == null) { + throw new MIOException("The value of a name must not be null: " + jsonObject); + } + mapHandler.value(value); + List<JSONObject> variants = (List<JSONObject>) jsonObject.get("variants"); + if (variants != null) { + int length = variants.size(); + for (int i=0; i<length; i++) { + _handleVariant(mapHandler, variants.get(i)); + } + } + mapHandler.endName(); + } + + private void _handleVariant(SimpleMapHandler mapHandler, + JSONObject jsonObject) throws MIOException { + mapHandler.startVariant(); + _handleScope(mapHandler, jsonObject); + _handleReifier(mapHandler, jsonObject); + _handleItemIdentifiers(mapHandler, jsonObject); + _handleValueDatatype(mapHandler, jsonObject); + mapHandler.endVariant(); + } + + private void _handleAssociations(SimpleMapHandler mapHandler, + List<JSONObject> jsonArray) throws MIOException { + if (jsonArray == null) { + return; + } + int length = jsonArray.size(); + for (int i=0; i<length; i++) { + _handleAssociation(mapHandler, jsonArray.get(i)); + } + } + + private void _handleAssociation(SimpleMapHandler mapHandler, + JSONObject jsonObject) throws MIOException { + List<JSONObject> roles = (List<JSONObject>) jsonObject.get("roles"); + if (roles == null) { + throw new MIOException("No roles specified: " + jsonObject); + } + mapHandler.startAssociation(); + _handleType(mapHandler, jsonObject, true); + _handleScope(mapHandler, jsonObject); + _handleReifier(mapHandler, jsonObject); + _handleItemIdentifiers(mapHandler, jsonObject); + int length = roles.size(); + for (int i=0; i<length; i++) { + _handleRole(mapHandler, roles.get(i)); + } + mapHandler.endAssociation(); + } + + private void _handleRole(SimpleMapHandler mapHandler, + JSONObject jsonObject) throws MIOException { + mapHandler.startRole(); + _handleType(mapHandler, jsonObject, true); + _handleReifier(mapHandler, jsonObject); + _handleItemIdentifiers(mapHandler, jsonObject); + String playerIRI = (String) jsonObject.get("player"); + if (playerIRI == null) { + throw new MIOException("No player defined: " + jsonObject); + } + mapHandler.player(Ref.createItemIdentifier(playerIRI)); + mapHandler.endRole(); + } + + private void _handleScope(SimpleMapHandler mapHandler, JSONObject jsonObject) throws MIOException { + List<String> array = (List<String>) jsonObject.get("scope"); + if (array == null) { + return; + } + int length = array.size(); + mapHandler.startScope(); + for (int i=0; i<length; i++) { + mapHandler.theme(Ref.createItemIdentifier(array.get(i))); + } + mapHandler.endScope(); + } + + private void _handleType(SimpleMapHandler mapHandler, JSONObject jsonObj, boolean notNull) throws MIOException { + String typeIRI = (String) jsonObj.get("type"); + if (typeIRI != null) { + mapHandler.type(Ref.createItemIdentifier(typeIRI)); + } + else if (notNull) { + throw new MIOException("The type must not be null: " + jsonObj); + } + } + + private void _handleReifier(SimpleMapHandler mapHandler, JSONObject jsonObj) throws MIOException { + String reifierIRI = (String) jsonObj.get("reifier"); + if (reifierIRI != null) { + mapHandler.reifier(Ref.createItemIdentifier(reifierIRI)); + } + } + + private void _handleItemIdentifiers(SimpleMapHandler mapHandler, JSONObject jsonObj) throws MIOException { + List<String> iids = (List<String>)jsonObj.get("item_identifiers"); + if (iids != null) { + int length = iids.size(); + for (int i=0; i<length; i++) { + mapHandler.itemIdentifier(iids.get(i)); + } + } + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/N3TopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/N3TopicMapReader.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/N3TopicMapReader.java 2008-11-25 14:11:21 UTC (rev 235) @@ -0,0 +1,83 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +import org.tmapi.core.TopicMap; + +import com.semagia.mio.Source; +import com.semagia.mio.Syntax; + +/** + * {@link RDFTopicMapReader} implementation that is able to deserialize RDF N3. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class N3TopicMapReader extends AbstractRDFTopicMapReader { + + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the topic map from. + * @param docIRI The document IRI which is used to resolve IRIs against. + * @throws IOException If an error occurs. + */ + public N3TopicMapReader(final TopicMap topicMap, final File source, final String docIRI) throws IOException { + super(topicMap, Syntax.N3, source, docIRI); + } + + /** + * Constructs a new instance. + * <p> + * The <tt>source</tt> is converted into an absolute IRI which will be + * utilised as document IRI + * </p> + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the topic map from. + * @throws IOException If an error occurs. + */ + public N3TopicMapReader(final TopicMap topicMap, final File source) throws IOException { + super(topicMap, Syntax.N3, source); + } + + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the topic map from. + * @param docIRI The document IRI which is used to resolve IRIs against. + */ + public N3TopicMapReader(final TopicMap topicMap, final InputStream source, final String docIRI) { + super(topicMap, Syntax.N3, source, docIRI); + } + + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the serialized topic map from. + */ + public N3TopicMapReader(final TopicMap topicMap, final Source source) { + super(topicMap, Syntax.N3, source); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/N3TopicMapReader.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/NTriplesTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/NTriplesTopicMapReader.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/NTriplesTopicMapReader.java 2008-11-25 14:11:21 UTC (rev 235) @@ -0,0 +1,84 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +import org.tmapi.core.TopicMap; + +import com.semagia.mio.Source; +import com.semagia.mio.Syntax; + +/** + * {@link RDFTopicMapReader} implementation that is able to deserialize RDF + * N-Triples. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class NTriplesTopicMapReader extends AbstractRDFTopicMapReader { + + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the topic map from. + * @param docIRI The document IRI which is used to resolve IRIs against. + * @throws IOException If an error occurs. + */ + public NTriplesTopicMapReader(final TopicMap topicMap, final File source, final String docIRI) throws IOException { + super(topicMap, Syntax.NTRIPLES, source, docIRI); + } + + /** + * Constructs a new instance. + * <p> + * The <tt>source</tt> is converted into an absolute IRI which will be + * utilised as document IRI + * </p> + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the topic map from. + * @throws IOException If an error occurs. + */ + public NTriplesTopicMapReader(final TopicMap topicMap, final File source) throws IOException { + super(topicMap, Syntax.NTRIPLES, source); + } + + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the topic map from. + * @param docIRI The document IRI which is used to resolve IRIs against. + */ + public NTriplesTopicMapReader(final TopicMap topicMap, final InputStream source, final String docIRI) { + super(topicMap, Syntax.NTRIPLES, source, docIRI); + } + + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the serialized topic map from. + */ + public NTriplesTopicMapReader(final TopicMap topicMap, final Source source) { + super(topicMap, Syntax.NTRIPLES, source); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/NTriplesTopicMapReader.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFTopicMapReader.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFTopicMapReader.java 2008-11-25 14:11:21 UTC (rev 235) @@ -0,0 +1,118 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio; + +import java.io.File; +import java.net.URL; + +/** + * Specialization of the {@link TopicMapReader} which provides methods to + * define an external RDF to Topic Maps (RTM) mapping source. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface RDFTopicMapReader extends TopicMapReader { + + /** + * Represents the syntax of a RTM mapping. + */ + public enum MappingSyntax { + /** + * N3 syntax. + */ + N3, + /** + * N-Triples syntax. + */ + NTRIPLES, + /** + * RDF/XML syntax. + */ + RDFXML, + /** + * TriG syntax. + */ + TRIG, + /** + * TriX syntax. + */ + TRIX, + /** + * Turtle syntax. + */ + TURTLE + }; + + /** + * Sets the file to read the RDF2TM mapping from. + * + * @see #setMappingSource(URL) + * @see #setMappingSource(String) + * + * @param file The file to read the RDF2TM mapping from. + */ + public void setMappingSource(File file); + + /** + * Sets the URL to read the RDF2TM mapping from. + * + * @see #setMappingSource(File) + * @see #setMappingSource(String) + * + * @param url The URL to read the RDF2TM mapping from. + */ + public void setMappingSource(URL url); + + /** + * Sets the URL to read the RDF2TM mapping from. + * + * @see #setMappingSource(File) + * @see #setMappingSource(URL) + * + * @param iri A string that represents an IRI / URL. + */ + public void setMappingSource(String iri); + + /** + * Returns the mapping source or <tt>null</tt> if no source is defined. + * + * @return A string representing an IRI or <tt>null</tt> if no source is defined. + */ + public String getMappingSource(); + + /** + * Sets the syntax of the mapping source. + * <p> + * By default, the reader tries to detect the syntax by the file + * extension. + * </p> + * + * @param syntax The syntax of the mapping source or <tt>null</tt> to + * let the reader autodetec... [truncated message content] |
From: <lh...@us...> - 2008-11-25 14:24:22
|
Revision: 237 http://tinytim.svn.sourceforge.net/tinytim/?rev=237&view=rev Author: lheuer Date: 2008-11-25 14:24:19 +0000 (Tue, 25 Nov 2008) Log Message: ----------- - Updated build files for 2.0 and 1.5 - 1.5 does not support JTMTopicMapWriter, but all readers are supported Modified Paths: -------------- tinytim-mio/trunk/build-15.xml tinytim-mio/trunk/build.xml Modified: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2008-11-25 14:18:12 UTC (rev 236) +++ tinytim-mio/trunk/build-15.xml 2008-11-25 14:24:19 UTC (rev 237) @@ -13,6 +13,7 @@ <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0b2.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.3.jar"/> + <property name="lib.json" value="${dir.lib}/json_simple.jar"/> <target name="help"> <echo message="------------------------"/> @@ -123,7 +124,7 @@ <target name="compile" depends="clean, prepare"> <javac destdir="${dir.build.classes}" debug="${debug}" - excludes="org/tinytim/mio/AbstractTopicMapWriter* org/tinytim/mio/CXTMTopicMapWriter* org/tinytim/mio/XTM*TopicMapWriter* org/tinytim/mio/JTM* org/tinytim/mio/JSON*" + excludes="org/tinytim/mio/AbstractTopicMapWriter* org/tinytim/mio/CXTMTopicMapWriter* org/tinytim/mio/XTM*TopicMapWriter* org/tinytim/mio/JTM*Writer* org/tinytim/mio/JSON*" includes="org/tinytim/mio15/** org/tinytim/mio/*TopicMapReader* org/tinytim/mio/*TopicMapImporter*" target="1.5"> <classpath> @@ -131,6 +132,7 @@ <pathelement location="${lib.tinytim}"/> <pathelement location="${lib.mio}"/> <pathelement location="${lib.logging}"/> + <pathelement location="${lib.json}"/> </classpath> <src path="${dir.src}"/> </javac> Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2008-11-25 14:18:12 UTC (rev 236) +++ tinytim-mio/trunk/build.xml 2008-11-25 14:24:19 UTC (rev 237) @@ -13,6 +13,7 @@ <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a3.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.3.jar"/> + <property name="lib.json" value="${dir.lib}/json_simple.jar"/> <target name="help"> <echo message="------------------------"/> @@ -130,6 +131,7 @@ <pathelement location="${lib.tinytim}"/> <pathelement location="${lib.mio}"/> <pathelement location="${lib.logging}"/> + <pathelement location="${lib.json}"/> </classpath> <src path="${dir.src}"/> </javac> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-12-06 16:55:05
|
Revision: 249 http://tinytim.svn.sourceforge.net/tinytim/?rev=249&view=rev Author: lheuer Date: 2008-12-06 16:55:00 +0000 (Sat, 06 Dec 2008) Log Message: ----------- Fixed doc, updated build.xml for 2.0 Modified Paths: -------------- tinytim-mio/trunk/build.xml tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapWriter.java Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2008-12-06 16:23:29 UTC (rev 248) +++ tinytim-mio/trunk/build.xml 2008-12-06 16:55:00 UTC (rev 249) @@ -10,7 +10,8 @@ <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a1.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a3.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a4.jar"/> + <property name="lib.tinytim.tests" value="${dir.lib}/tinytim-2.0.0a4-tests.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.3.jar"/> <property name="lib.json" value="${dir.lib}/json_simple.jar"/> @@ -68,15 +69,21 @@ <javadoc destdir="${dir.javadocs}" packagenames="org.tinytim.*" author="true" - version="false" + version="true" use="true" splitindex="true" noindex="false" windowtitle="tinyTiM MIO API v${dist.version}" doctitle="tinyTiM API MIO v${dist.version}"> <fileset dir="${dir.src}"> + <exclude name="org/tinytim/mio15/**"/> </fileset> - <link href="http://www.tmapi.org/apiDocs/"/> +<!-- + <doclet name="net.gleamynode.apiviz.APIviz" + path="${dir.lib}/apiviz-1.2.5.GA.jar"> + </doclet> +--> + <link href="http://www.tmapi.org/2.0/api/"/> </javadoc> </target> @@ -88,12 +95,15 @@ <javac destdir="${dir.build.tests}" debug="${debug}" optimize="${optimize}" - target="1.5"> + target="1.5" + excludes="org/tinytim/mio15/**" + > <classpath> <pathelement location="${dir.build.classes}"/> <pathelement location="${lib.junit}"/> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tinytim}"/> + <pathelement location="${lib.tinytim.tests}"/> <pathelement location="${lib.mio}"/> </classpath> <src path="${dir.test}"/> @@ -106,6 +116,7 @@ <pathelement location="${lib.junit}"/> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tinytim}"/> + <pathelement location="${lib.tinytim.tests}"/> <pathelement location="${lib.mio}"/> </classpath> <formatter type="brief" usefile="false"/> @@ -129,6 +140,7 @@ <classpath> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tinytim}"/> + <pathelement location="${lib.tinytim.tests}"/> <pathelement location="${lib.mio}"/> <pathelement location="${lib.logging}"/> <pathelement location="${lib.json}"/> @@ -148,7 +160,7 @@ <manifest> <attribute name="Implementation-Title" value="tinyTiM MIO"/> <attribute name="Implementation-Version" value="${dist.version}"/> - <attribute name="Implementation-URL" value="http://sourceforge.net/projects/tinytim"/> + <attribute name="Implementation-URL" value="http://tinytim.sourceforge.net/"/> </manifest> </jar> </target> Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapWriter.java 2008-12-06 16:23:29 UTC (rev 248) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapWriter.java 2008-12-06 16:55:00 UTC (rev 249) @@ -23,7 +23,7 @@ * This interface represents a writer to serialize a topic map. * <p> * The writer is not meant to be reused and should be thrown away once the - * {{@link #write(TopicMap)} method was invoked. + * {@link #write(TopicMap)} method was invoked. * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-12-06 17:20:52
|
Revision: 250 http://tinytim.svn.sourceforge.net/tinytim/?rev=250&view=rev Author: lheuer Date: 2008-12-06 17:20:48 +0000 (Sat, 06 Dec 2008) Log Message: ----------- - Updated build scripts - 1.5 release does not include the source code maybe this will be fixed for the next release (I love the TMAPI 1.0 legacy) - Updated CHANGES.txt (unified for 1.5 / 2.0) - Updated README (unified for 1.5 / 2.0) Modified Paths: -------------- tinytim-mio/trunk/CHANGES.txt tinytim-mio/trunk/README.txt tinytim-mio/trunk/build-15.properties tinytim-mio/trunk/build-15.xml tinytim-mio/trunk/build.properties tinytim-mio/trunk/build.xml Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2008-12-06 16:55:00 UTC (rev 249) +++ tinytim-mio/trunk/CHANGES.txt 2008-12-06 17:20:48 UTC (rev 250) @@ -2,8 +2,9 @@ Changes Log =========== -2.0.0 a4 (06.12.2008) ---------------------- +2.0.0 a4 / 1.5.0b2 (06.12.2008) +------------------------------- +* Note: The JTMWriter is not available in 1.5.0b2! * Initial .mio release for tinyTiM 2.x * Changed license to Apache License 2.0 * Introduced TopicMapReader / TopicMapWriter interfaces Modified: tinytim-mio/trunk/README.txt =================================================================== --- tinytim-mio/trunk/README.txt 2008-12-06 16:55:00 UTC (rev 249) +++ tinytim-mio/trunk/README.txt 2008-12-06 17:20:48 UTC (rev 250) @@ -19,7 +19,7 @@ Installation ------------ Put the ``tinytim-mio-<VERSION>.jar`` together with the ``tinytim-<VERSION>.jar``, -and ``tmapi-2.0.0.jar`` into the classpath. +and ``tmapi-<VERSION>.jar`` into the classpath. Further, the ``semagia-mio-<VERSION>.jar`` and one or more ``semagia-mio-<SYNTAX-NAME>-<VERSION>.jar`` are needed in the classpath. Note, that ``Semagia MIO`` needs the ``Simple Logging Facade for Java`` Modified: tinytim-mio/trunk/build-15.properties =================================================================== --- tinytim-mio/trunk/build-15.properties 2008-12-06 16:55:00 UTC (rev 249) +++ tinytim-mio/trunk/build-15.properties 2008-12-06 17:20:48 UTC (rev 250) @@ -1,5 +1,5 @@ version=1.5.0 version_suffix=b2 -#release_type= +release_type= debug=off optimize=on Modified: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2008-12-06 16:55:00 UTC (rev 249) +++ tinytim-mio/trunk/build-15.xml 2008-12-06 17:20:48 UTC (rev 250) @@ -75,6 +75,8 @@ windowtitle="tinyTiM MIO API v${dist.version}" doctitle="tinyTiM API MIO v${dist.version}"> <fileset dir="${dir.src}"> + <exclude name="org/tinytim/mio/JTM*Writer*"/> +<!-- <include name="org/tinytim/mio/** org/tinytim/mio/*TopicMapReader* org/tinytim/mio/*TopicMapImporter*"/> --> </fileset> <link href="http://www.tmapi.org/apiDocs/"/> </javadoc> @@ -88,7 +90,9 @@ <javac destdir="${dir.build.tests}" debug="${debug}" optimize="${optimize}" - target="1.5"> + target="1.5" + excludes="org/tinytim/mio/TinyTimMapInputHandler*" + > <classpath> <pathelement location="${dir.build.classes}"/> <pathelement location="${lib.junit}"/> @@ -149,7 +153,7 @@ <manifest> <attribute name="Implementation-Title" value="tinyTiM MIO"/> <attribute name="Implementation-Version" value="${dist.version}"/> - <attribute name="Implementation-URL" value="http://sourceforge.net/projects/tinytim"/> + <attribute name="Implementation-URL" value="http://tinytim.sourceforge.net/"/> </manifest> </jar> </target> @@ -161,13 +165,14 @@ <mkdir dir="${dir.dist}"/> <copy todir="${dir.dist}" file="${dir.build}/${tinytim-mio.jar}"/> - +<!-- <copy todir="${dir.dist}/src"> <fileset dir="${dir.src}"/> </copy> <copy todir="${dir.dist}/test"> <fileset dir="${dir.test}"/> </copy> +--> <copy todir="${dir.dist}/lib"> <fileset dir="${dir.lib}"> <exclude name="**/tmapi*.jar"/> @@ -185,7 +190,7 @@ <!-- --> <!-- Won't create the distribution files if a test fails --> <!-- =================================================================== --> - <target name="release" depends="jar, test, doc, dist"> + <target name="release" depends="jar, doc, dist"> <tar destfile="${dir.dist.root}/${tinytim-mio.tar}" basedir="${dir.dist.root}"/> <gzip src="${dir.dist.root}/${tinytim-mio.tar}" Modified: tinytim-mio/trunk/build.properties =================================================================== --- tinytim-mio/trunk/build.properties 2008-12-06 16:55:00 UTC (rev 249) +++ tinytim-mio/trunk/build.properties 2008-12-06 17:20:48 UTC (rev 250) @@ -1,5 +1,5 @@ version=2.0.0 version_suffix=a4 -#release_type= +release_type= debug=off optimize=on Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2008-12-06 16:55:00 UTC (rev 249) +++ tinytim-mio/trunk/build.xml 2008-12-06 17:20:48 UTC (rev 250) @@ -174,7 +174,9 @@ <copy todir="${dir.dist}" file="${dir.build}/${tinytim-mio.jar}"/> <copy todir="${dir.dist}/src"> - <fileset dir="${dir.src}"/> + <fileset dir="${dir.src}"> + <exclude name="**/mio15/**"/> + </fileset> </copy> <copy todir="${dir.dist}/test"> <fileset dir="${dir.test}"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-12-06 17:23:33
|
Revision: 252 http://tinytim.svn.sourceforge.net/tinytim/?rev=252&view=rev Author: lheuer Date: 2008-12-06 17:23:27 +0000 (Sat, 06 Dec 2008) Log Message: ----------- Snapshot a5 Modified Paths: -------------- tinytim-mio/trunk/build-15.properties tinytim-mio/trunk/build.properties Modified: tinytim-mio/trunk/build-15.properties =================================================================== --- tinytim-mio/trunk/build-15.properties 2008-12-06 17:22:07 UTC (rev 251) +++ tinytim-mio/trunk/build-15.properties 2008-12-06 17:23:27 UTC (rev 252) @@ -1,5 +1,5 @@ version=1.5.0 version_suffix=b2 -release_type= +#release_type= debug=off optimize=on Modified: tinytim-mio/trunk/build.properties =================================================================== --- tinytim-mio/trunk/build.properties 2008-12-06 17:22:07 UTC (rev 251) +++ tinytim-mio/trunk/build.properties 2008-12-06 17:23:27 UTC (rev 252) @@ -1,5 +1,5 @@ version=2.0.0 -version_suffix=a4 -release_type= +version_suffix=a5 +#release_type= debug=off optimize=on This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-02-24 13:56:56
|
Revision: 267 http://tinytim.svn.sourceforge.net/tinytim/?rev=267&view=rev Author: lheuer Date: 2009-02-24 13:56:47 +0000 (Tue, 24 Feb 2009) Log Message: ----------- - Added Override annotation (Java 6) - Switched to semagia-mio-jtm for the JTMTopicMapReader (json_simple.jar is not required anymore) - Adapted JTM 1.0 for JTMTopicMapWriter Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractRDFTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java Added Paths: ----------- tinytim-mio/trunk/lib/semagia-mio-jtm-0.9.3.jar Removed Paths: ------------- tinytim-mio/trunk/lib/json_simple.jar Deleted: tinytim-mio/trunk/lib/json_simple.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/semagia-mio-jtm-0.9.3.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/semagia-mio-jtm-0.9.3.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractRDFTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractRDFTopicMapReader.java 2009-02-20 13:05:54 UTC (rev 266) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractRDFTopicMapReader.java 2009-02-24 13:56:47 UTC (rev 267) @@ -32,7 +32,7 @@ * Common superclass for {@link RDFTopicMapReader}s. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ abstract class AbstractRDFTopicMapReader extends AbstractTopicMapReader implements RDFTopicMapReader { @@ -65,6 +65,7 @@ /* (non-Javadoc) * @see org.tinytim.mio.RDFTopicMapReader#setMappingSource(java.io.File) */ + @Override public void setMappingSource(File file) { try { setMappingSource(file.toURI().toURL()); @@ -77,6 +78,7 @@ /* (non-Javadoc) * @see org.tinytim.mio.RDFTopicMapReader#setMappingSource(java.net.URL) */ + @Override public void setMappingSource(URL url) { setMappingSource(url.toExternalForm()); } @@ -84,6 +86,7 @@ /* (non-Javadoc) * @see org.tinytim.mio.RDFTopicMapReader#setMappingSource(java.lang.String) */ + @Override public void setMappingSource(String iri) { _deserializer.setProperty(Property.RDF2TM_MAPPING_IRI, iri); } @@ -91,6 +94,7 @@ /* (non-Javadoc) * @see org.tinytim.mio.RDFTopicMapReader#getMappingSource() */ + @Override public String getMappingSource() { return (String) _deserializer.getProperty(Property.RDF2TM_MAPPING_IRI); } @@ -98,6 +102,7 @@ /* (non-Javadoc) * @see org.tinytim.mio.RDFTopicMapReader#getMappingSourceSyntax() */ + @Override public MappingSyntax getMappingSourceSyntax() { Syntax syntax = (Syntax) _deserializer.getProperty(Property.RDF2TM_MAPPING_SYNTAX); return _toMappingSyntax(syntax); @@ -106,10 +111,17 @@ /* (non-Javadoc) * @see org.tinytim.mio.RDFTopicMapReader#setMappingSourceSyntax(org.tinytim.mio.RDFTopicMapReader.MappingSyntax) */ + @Override public void setMappingSourceSyntax(MappingSyntax syntax) { _deserializer.setProperty(Property.RDF2TM_MAPPING_SYNTAX, _fromMappingSyntax(syntax)); } + /** + * Returns the {@link MappingSyntax} equivalent for the provided mio.Syntax. + * + * @param syntax The syntax to convert. + * @return The MappingSyntax instance. + */ private static MappingSyntax _toMappingSyntax(Syntax syntax) { if (syntax == null) { return null; @@ -136,6 +148,12 @@ } + /** + * Returns the mio.Syntax equivalent for the provided {@link MappingSyntax}. + * + * @param syntax The syntax to translate. + * @return The translated syntax. + */ private static Syntax _fromMappingSyntax(MappingSyntax syntax) { if (syntax == null) { return null; Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java 2009-02-20 13:05:54 UTC (rev 266) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java 2009-02-24 13:56:47 UTC (rev 267) @@ -125,6 +125,7 @@ /* (non-Javadoc) * @see org.tinytim.mio.ITopicMapReader#read() */ + @Override public void read() throws IOException { try { _deserializer.parse(_source); Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java 2009-02-20 13:05:54 UTC (rev 266) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapReader.java 2009-02-24 13:56:47 UTC (rev 267) @@ -70,7 +70,7 @@ * @param ignore <tt>true</tt> to ignore mergeMap elements, otherwise <tt>false</tt>. */ public void setIgnoreMergeMap(boolean ignore) { - _deserializer.setProperty(Property.IGNORE_MERGEMAP, ignore); + _deserializer.setProperty(Property.IGNORE_MERGEMAP, Boolean.valueOf(ignore)); } /** @@ -94,7 +94,7 @@ * disable validation. */ public void setValidation(boolean validate) { - _deserializer.setProperty(Property.VALIDATE, validate); + _deserializer.setProperty(Property.VALIDATE, Boolean.valueOf(validate)); } /** Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java 2009-02-20 13:05:54 UTC (rev 266) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractXTMTopicMapWriter.java 2009-02-24 13:56:47 UTC (rev 267) @@ -66,7 +66,7 @@ throw new IOException("The encoding must not be null"); } _out = new XMLWriter(out, encoding); - _out.setPrettify(true); + _out.setPrettify(false); _attrs = new AttributesImpl(); } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java 2009-02-20 13:05:54 UTC (rev 266) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java 2009-02-24 13:56:47 UTC (rev 267) @@ -1,5 +1,5 @@ /* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,282 +15,83 @@ */ package org.tinytim.mio; +import java.io.File; import java.io.IOException; -import java.io.Reader; -import java.util.List; +import java.io.InputStream; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; -import org.tmapi.core.TMAPIRuntimeException; import org.tmapi.core.TopicMap; -import com.semagia.mio.MIOException; -import com.semagia.mio.helpers.Ref; -import com.semagia.mio.helpers.SimpleMapHandler; +import com.semagia.mio.Source; +import com.semagia.mio.Syntax; /** * {@link TopicMapReader} implementation that deserializes * <a href="http://www.cerny-online.com/jtm/">JSON Topic Maps (JTM)</a>. * <p> - * The reader does not accept fragments, i.e. only a topic in a JSON document; - * each JTM instance must start with a topic map container, i.e. - * <tt>{"topics":[...]"}</tt>. The TMDM constructs must provide all - * properties, i.e. it is not allowed to omit the type of an association. The - * only exception are topic names: If the "type" property is not provided, the - * default topic name type is automatically assigned. + * This reader rejects JTM instances which contain just a single role or + * variant even if they are valid according to the JTM specification. * </p> + * <p> + * Further the reader expects that at least one identity of a topic + * (item identifier, subject identifier, subject locator) occurs before any + * occurrence / name. Fragments must start with a "version" property followed + * by the "item_type" property before any further properties are specified. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev:$ - $Date:$ */ -@SuppressWarnings("unchecked") -public class JTMTopicMapReader implements TopicMapReader { +public final class JTMTopicMapReader extends AbstractTopicMapReader { - private TopicMap _tm; - private Reader _reader; - /** * Constructs a new instance. * * @param topicMap The topic map to which the content is added to. - * @param reader The reader to read the JSON encoded topic map from. - * @throws IOException If an error occurs. + * @param source The source to read the topic map from. + * @param docIRI The document IRI which is used to resolve IRIs against. + * @throws IOException If an error occurs. */ - public JTMTopicMapReader(TopicMap topicMap, Reader reader) throws IOException { - _tm = topicMap; - _reader = reader; + public JTMTopicMapReader(final TopicMap topicMap, final File source, + final String docIRI) throws IOException { + super(topicMap, Syntax.JTM, source, docIRI); } - /* (non-Javadoc) - * @see org.tinytim.mio.TopicMapReader#read() + /** + * Constructs a new instance. + * <p> + * The <tt>source</tt> is converted into an absolute IRI which will be + * utilised as document IRI + * </p> + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the topic map from. + * @throws IOException If an error occurs. */ - public void read() throws IOException { - Object obj = JSONValue.parse(_reader); - if (!(obj instanceof JSONObject)) { - // Nothing to do. - return; - } - JSONObject map = (JSONObject) obj; - SimpleMapHandler mapHandler = SimpleMapHandler.create(new TinyTimMapInputHandler(_tm)); - try { - mapHandler.startTopicMap(); - _handleReifier(mapHandler, map); - _handleItemIdentifiers(mapHandler, map); - _handleTopics(mapHandler, (List<JSONObject>) map.get("topics")); - _handleAssociations(mapHandler, (List<JSONObject>) map.get("associations")); - mapHandler.endTopicMap(); - } - catch (MIOException ex) { - throw new TMAPIRuntimeException(ex); - } + public JTMTopicMapReader(final TopicMap topicMap, final File source) + throws IOException { + super(topicMap, Syntax.JTM, source); } - private void _handleTopics(SimpleMapHandler mapHandler, - List<JSONObject> jsonArray) throws MIOException { - if (jsonArray == null) { - return; - } - int length = jsonArray.size(); - for (int i=0; i<length; i++) { - _handleTopic(mapHandler, jsonArray.get(i)); - } + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the topic map from. + * @param docIRI The document IRI which is used to resolve IRIs against. + */ + public JTMTopicMapReader(final TopicMap topicMap, final InputStream source, + final String docIRI) { + super(topicMap, Syntax.JTM, source, docIRI); } - private void _handleTopic(SimpleMapHandler mapHandler, - JSONObject jsonObject) throws MIOException { - boolean seenIdentity = false; - List<String> array = (List<String>) jsonObject.get("item_identifiers"); - if (array != null) { - seenIdentity = true; - mapHandler.startTopic(Ref.createItemIdentifier(array.get(0))); - int length = array.size(); - for (int i=1; i<length; i++) { - mapHandler.itemIdentifier(array.get(i)); - } - } - array = (List<String>) jsonObject.get("subject_identifiers"); - if (array != null) { - int start = 0; - if (!seenIdentity) { - seenIdentity = true; - start = 1; - mapHandler.startTopic(Ref.createSubjectIdentifier(array.get(0))); - } - int length = array.size(); - for (int i=start; i<length; i++) { - mapHandler.subjectIdentifier(array.get(i)); - } - } - array = (List<String>) jsonObject.get("subject_locators"); - if (array != null) { - int start = 0; - if (!seenIdentity) { - seenIdentity = true; - start = 1; - mapHandler.startTopic(Ref.createSubjectLocator(array.get(0))); - } - int length = array.size(); - for (int i=start; i<length; i++) { - mapHandler.subjectLocator(array.get(i)); - } - } - if (!seenIdentity) { - throw new MIOException("Topic without any identity: " + jsonObject); - } - List<JSONObject> objects = (List<JSONObject>) jsonObject.get("occurrences"); - if (objects != null) { - int length = objects.size(); - for (int i=0; i<length; i++) { - _handleOccurrence(mapHandler, objects.get(i)); - } - } - objects = (List<JSONObject>) jsonObject.get("names"); - if (objects != null) { - int length = objects.size(); - for (int i=0; i<length; i++) { - _handleName(mapHandler, objects.get(i)); - } - } - mapHandler.endTopic(); + /** + * Constructs a new instance. + * + * @param topicMap The topic map to which the content is added to. + * @param source The source to read the serialized topic map from. + */ + public JTMTopicMapReader(final TopicMap topicMap, final Source source) { + super(topicMap, Syntax.JTM, source); } - private void _handleOccurrence(SimpleMapHandler mapHandler, - JSONObject jsonObject) throws MIOException { - mapHandler.startOccurrence(); - _handleType(mapHandler, jsonObject, true); - _handleScope(mapHandler, jsonObject); - _handleReifier(mapHandler, jsonObject); - _handleItemIdentifiers(mapHandler, jsonObject); - _handleValueDatatype(mapHandler, jsonObject); - mapHandler.endOccurrence(); - } - - private void _handleValueDatatype(SimpleMapHandler mapHandler, - JSONObject jsonObject) throws MIOException { - String value = (String) jsonObject.get("value"); - if (value == null) { - throw new MIOException("The value must not be null: " + jsonObject); - } - String datatype = (String) jsonObject.get("datatype"); - if (datatype == null) { - throw new MIOException("The datatype must not be null: " + jsonObject); - } - mapHandler.value(value, datatype); - } - - private void _handleName(SimpleMapHandler mapHandler, - JSONObject jsonObject) throws MIOException { - mapHandler.startName(); - _handleType(mapHandler, jsonObject, false); - _handleScope(mapHandler, jsonObject); - _handleReifier(mapHandler, jsonObject); - _handleItemIdentifiers(mapHandler, jsonObject); - String value = (String) jsonObject.get("value"); - if (value == null) { - throw new MIOException("The value of a name must not be null: " + jsonObject); - } - mapHandler.value(value); - List<JSONObject> variants = (List<JSONObject>) jsonObject.get("variants"); - if (variants != null) { - int length = variants.size(); - for (int i=0; i<length; i++) { - _handleVariant(mapHandler, variants.get(i)); - } - } - mapHandler.endName(); - } - - private void _handleVariant(SimpleMapHandler mapHandler, - JSONObject jsonObject) throws MIOException { - mapHandler.startVariant(); - _handleScope(mapHandler, jsonObject); - _handleReifier(mapHandler, jsonObject); - _handleItemIdentifiers(mapHandler, jsonObject); - _handleValueDatatype(mapHandler, jsonObject); - mapHandler.endVariant(); - } - - private void _handleAssociations(SimpleMapHandler mapHandler, - List<JSONObject> jsonArray) throws MIOException { - if (jsonArray == null) { - return; - } - int length = jsonArray.size(); - for (int i=0; i<length; i++) { - _handleAssociation(mapHandler, jsonArray.get(i)); - } - } - - private void _handleAssociation(SimpleMapHandler mapHandler, - JSONObject jsonObject) throws MIOException { - List<JSONObject> roles = (List<JSONObject>) jsonObject.get("roles"); - if (roles == null) { - throw new MIOException("No roles specified: " + jsonObject); - } - mapHandler.startAssociation(); - _handleType(mapHandler, jsonObject, true); - _handleScope(mapHandler, jsonObject); - _handleReifier(mapHandler, jsonObject); - _handleItemIdentifiers(mapHandler, jsonObject); - int length = roles.size(); - for (int i=0; i<length; i++) { - _handleRole(mapHandler, roles.get(i)); - } - mapHandler.endAssociation(); - } - - private void _handleRole(SimpleMapHandler mapHandler, - JSONObject jsonObject) throws MIOException { - mapHandler.startRole(); - _handleType(mapHandler, jsonObject, true); - _handleReifier(mapHandler, jsonObject); - _handleItemIdentifiers(mapHandler, jsonObject); - String playerIRI = (String) jsonObject.get("player"); - if (playerIRI == null) { - throw new MIOException("No player defined: " + jsonObject); - } - mapHandler.player(Ref.createItemIdentifier(playerIRI)); - mapHandler.endRole(); - } - - private void _handleScope(SimpleMapHandler mapHandler, JSONObject jsonObject) throws MIOException { - List<String> array = (List<String>) jsonObject.get("scope"); - if (array == null) { - return; - } - int length = array.size(); - mapHandler.startScope(); - for (int i=0; i<length; i++) { - mapHandler.theme(Ref.createItemIdentifier(array.get(i))); - } - mapHandler.endScope(); - } - - private void _handleType(SimpleMapHandler mapHandler, JSONObject jsonObj, boolean notNull) throws MIOException { - String typeIRI = (String) jsonObj.get("type"); - if (typeIRI != null) { - mapHandler.type(Ref.createItemIdentifier(typeIRI)); - } - else if (notNull) { - throw new MIOException("The type must not be null: " + jsonObj); - } - } - - private void _handleReifier(SimpleMapHandler mapHandler, JSONObject jsonObj) throws MIOException { - String reifierIRI = (String) jsonObj.get("reifier"); - if (reifierIRI != null) { - mapHandler.reifier(Ref.createItemIdentifier(reifierIRI)); - } - } - - private void _handleItemIdentifiers(SimpleMapHandler mapHandler, JSONObject jsonObj) throws MIOException { - List<String> iids = (List<String>)jsonObj.get("item_identifiers"); - if (iids != null) { - int length = iids.size(); - for (int i=0; i<length; i++) { - mapHandler.itemIdentifier(iids.get(i)); - } - } - } - } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java 2009-02-20 13:05:54 UTC (rev 266) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java 2009-02-24 13:56:47 UTC (rev 267) @@ -56,7 +56,6 @@ private JSONWriter _out; private String _baseIRI; - private Topic _defaultNameType; /** * Creates a JTM writer, using "utf-8" encoding. @@ -108,8 +107,8 @@ /* (non-Javadoc) * @see org.tinytim.mio.TopicMapWriter#write(org.tmapi.core.TopicMap) */ + @Override public void write(TopicMap topicMap) throws IOException { - _defaultNameType = topicMap.getTopicBySubjectIdentifier(TMDM.TOPIC_NAME); _out.startDocument(); _out.startObject(); _writeReifier(topicMap); @@ -152,19 +151,6 @@ * @throws IOException If an error occurs. */ private void _writeTopic(Topic topic) throws IOException { - // Ignore the topic if it is the default name type and it has no further - // characteristics - if (_isDefaultNameType(topic) - && topic.getReified() == null - && topic.getSubjectIdentifiers().size() == 1 - && topic.getSubjectLocators().isEmpty() - && topic.getItemIdentifiers().isEmpty() - && topic.getRolesPlayed().isEmpty() - && topic.getTypes().isEmpty() - && topic.getNames().isEmpty() - && topic.getOccurrences().isEmpty()) { - return; - } _out.startObject(); _writeItemIdentifiers(topic); _writeLocators("subject_identifiers", topic.getSubjectIdentifiers()); @@ -200,9 +186,7 @@ _out.startObject(); _writeReifier(name); _writeItemIdentifiers(name); - if (!_isDefaultNameType(name.getType())) { - _writeType(name); - } + _writeType(name); _writeScope(name); _writeKeyValue("value", name.getValue()); Set<Variant> variants = name.getVariants(); @@ -425,23 +409,17 @@ private String _topicRef(Topic topic) { Set<Locator> locs = topic.getItemIdentifiers(); if (!locs.isEmpty()) { - return locs.iterator().next().toExternalForm(); + return "ii:" + locs.iterator().next().toExternalForm(); } locs = topic.getSubjectIdentifiers(); if (!locs.isEmpty()) { - return locs.iterator().next().toExternalForm(); + return "si:" + locs.iterator().next().toExternalForm(); } - return _baseIRI + "#" + topic.getId(); + locs = topic.getSubjectLocators(); + if (!locs.isEmpty()) { + return "sl:" + locs.iterator().next().toExternalForm(); + } + return "ii:" + _baseIRI + "#" + topic.getId(); } - /** - * Checks if the specified <tt>topic</tt> is the default TMDM name type. - * - * @param topic The topic to check, not <tt>null</tt>. - * @return <tt>true</tt> if the topic is the default name type, otherwise <tt>false</tt>. - */ - private boolean _isDefaultNameType(final Topic topic) { - return topic.equals(_defaultNameType); - } - } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFTopicMapReader.java 2009-02-20 13:05:54 UTC (rev 266) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/RDFTopicMapReader.java 2009-02-24 13:56:47 UTC (rev 267) @@ -23,7 +23,7 @@ * define an external RDF to Topic Maps (RTM) mapping source. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface RDFTopicMapReader extends TopicMapReader { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLTopicMapReader.java 2009-02-20 13:05:54 UTC (rev 266) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TMXMLTopicMapReader.java 2009-02-24 13:56:47 UTC (rev 267) @@ -96,7 +96,7 @@ * disable validation. */ public void setValidation(boolean validate) { - _deserializer.setProperty(Property.VALIDATE, validate); + _deserializer.setProperty(Property.VALIDATE, Boolean.valueOf(validate)); } /** Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-02-20 13:05:54 UTC (rev 266) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-02-24 13:56:47 UTC (rev 267) @@ -216,7 +216,7 @@ IVariant variant = (IVariant) _leaveStatePopConstruct(VARIANT); IName name = (IName) _peekConstruct(); IScope scope = variant.getScopeObject(); - if (scope.isUnconstrained() || name.getScopeObject() == scope) { + if (scope.isUnconstrained() || name.getScopeObject().equals(scope)) { _reportError("The variant has no scope"); } } @@ -277,7 +277,7 @@ Locator sid = _tm.createLocator(subjectIdentifier); ITopic topic = _peekTopic(); Topic existing = _tm.getTopicBySubjectIdentifier(sid); - if (existing != null && !(existing == topic)) { + if (existing != null && !(existing.equals(topic))) { _merge(existing, topic); } else { @@ -296,7 +296,7 @@ Locator slo = _tm.createLocator(subjectLocator); ITopic topic = _peekTopic(); Topic existing = _tm.getTopicBySubjectLocator(slo); - if (existing != null && !(existing == topic)) { + if (existing != null && !(existing.equals(topic))) { _merge(existing, topic); } topic.addSubjectLocator(slo); Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2009-02-20 13:05:54 UTC (rev 266) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2009-02-24 13:56:47 UTC (rev 267) @@ -39,6 +39,7 @@ private final String _encoding; private int _depth; + private boolean _prettify; public XMLWriter(OutputStream out) throws IOException { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2009-02-20 13:05:54 UTC (rev 266) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XTM10TopicMapWriter.java 2009-02-24 13:56:47 UTC (rev 267) @@ -80,25 +80,11 @@ super(out, baseIRI, encoding); } - private String _getId(Reifiable reifiable) { - assert reifiable.getReifier() != null; - return "reifier-id-" + reifiable.getReifier().getId(); - } - - private void _addId(AttributesImpl attrs, final Reifiable reifiable) { - if (reifiable.getReifier() == null) { - return; - } - attrs.addAttribute("", "id", "", "CDATA", _getId(reifiable)); - } - - private void _addLocator(AttributesImpl attrs, Locator loc) { - attrs.addAttribute("", "xlink:href", "", "CDATA", loc.toExternalForm()); - } - + /* (non-Javadoc) * @see org.tinytim.mio.ITopicMapWriter#write(org.tmapi.core.TopicMap) */ + @Override public void write(final TopicMap topicMap) throws IOException { _out.startDocument(); _attrs.clear(); @@ -116,6 +102,22 @@ _out.endDocument(); } + private String _getId(Reifiable reifiable) { + assert reifiable.getReifier() != null; + return "reifier-id-" + reifiable.getReifier().getId(); + } + + private void _addId(AttributesImpl attrs, final Reifiable reifiable) { + if (reifiable.getReifier() == null) { + return; + } + attrs.addAttribute("", "id", "", "CDATA", _getId(reifiable)); + } + + private void _addLocator(AttributesImpl attrs, Locator loc) { + attrs.addAttribute("", "xlink:href", "", "CDATA", loc.toExternalForm()); + } + protected void _writeTopic(final Topic topic) throws IOException { _attrs.clear(); _attrs.addAttribute("", "id", "", "CDATA", _getId(topic)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-02-25 15:16:10
|
Revision: 271 http://tinytim.svn.sourceforge.net/tinytim/?rev=271&view=rev Author: lheuer Date: 2009-02-25 15:16:05 +0000 (Wed, 25 Feb 2009) Log Message: ----------- Updated build scripts Modified Paths: -------------- tinytim-mio/trunk/build-15.xml tinytim-mio/trunk/build.xml Modified: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2009-02-25 14:15:13 UTC (rev 270) +++ tinytim-mio/trunk/build-15.xml 2009-02-25 15:16:05 UTC (rev 271) @@ -13,7 +13,6 @@ <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0b2.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.3.jar"/> - <property name="lib.json" value="${dir.lib}/json_simple.jar"/> <target name="help"> <echo message="------------------------"/> @@ -136,7 +135,6 @@ <pathelement location="${lib.tinytim}"/> <pathelement location="${lib.mio}"/> <pathelement location="${lib.logging}"/> - <pathelement location="${lib.json}"/> </classpath> <src path="${dir.src}"/> </javac> Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-02-25 14:15:13 UTC (rev 270) +++ tinytim-mio/trunk/build.xml 2009-02-25 15:16:05 UTC (rev 271) @@ -14,7 +14,6 @@ <property name="lib.tinytim.tests" value="${dir.lib}/tinytim-2.0.0a4-tests.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.3.jar"/> - <property name="lib.json" value="${dir.lib}/json_simple.jar"/> <target name="help"> <echo message="------------------------"/> @@ -143,7 +142,6 @@ <pathelement location="${lib.tinytim.tests}"/> <pathelement location="${lib.mio}"/> <pathelement location="${lib.logging}"/> - <pathelement location="${lib.json}"/> </classpath> <src path="${dir.src}"/> </javac> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-03-03 15:00:26
|
Revision: 276 http://tinytim.svn.sourceforge.net/tinytim/?rev=276&view=rev Author: lheuer Date: 2009-03-03 15:00:25 +0000 (Tue, 03 Mar 2009) Log Message: ----------- - Updated JTM 1.0 reader to the latest spec. - Writer checks first the subject identifiers and then iids and slos for a topic reference Modified Paths: -------------- tinytim-mio/trunk/lib/semagia-mio-jtm-0.9.3.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java Modified: tinytim-mio/trunk/lib/semagia-mio-jtm-0.9.3.jar =================================================================== (Binary files differ) Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java 2009-03-02 17:25:00 UTC (rev 275) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapReader.java 2009-03-03 15:00:25 UTC (rev 276) @@ -28,18 +28,21 @@ * {@link TopicMapReader} implementation that deserializes * <a href="http://www.cerny-online.com/jtm/">JSON Topic Maps (JTM)</a>. * <p> - * This reader rejects JTM instances which contain just a single role or - * variant even if they are valid according to the JTM specification. + * This reader rejects JTM instances where the "item_type" is either + * "role" or "variant" even if they are valid according to the JTM specification. * </p> * <p> * Further the reader expects that at least one identity of a topic * (item identifier, subject identifier, subject locator) occurs before any - * occurrence / name. Fragments must start with a "version" property followed - * by the "item_type" property before any further properties are specified. + * occurrence / name. * </p> + * <p> + * The JTM instance must start with a "version" property followed by the + * "item_type" property before any further properties are specified. + * </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 JTMTopicMapReader extends AbstractTopicMapReader { Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java 2009-03-02 17:25:00 UTC (rev 275) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/JTMTopicMapWriter.java 2009-03-03 15:00:25 UTC (rev 276) @@ -245,7 +245,9 @@ String value = XSD.ANY_URI.equals(datatype) ? datatyped.locatorValue().toExternalForm() : datatyped.getValue(); _writeKeyValue("value", value); - _writeKeyValue("datatype", datatype.toExternalForm()); + if (!XSD.STRING.equals(datatype)) { + _writeKeyValue("datatype", datatype.toExternalForm()); + } } /** @@ -409,18 +411,18 @@ * @return An IRI. */ private String _topicRef(Topic topic) { - Set<Locator> locs = topic.getItemIdentifiers(); + Set<Locator> locs = topic.getSubjectIdentifiers(); if (!locs.isEmpty()) { - return "ii:" + locs.iterator().next().toExternalForm(); - } - locs = topic.getSubjectIdentifiers(); - if (!locs.isEmpty()) { return "si:" + locs.iterator().next().toExternalForm(); } locs = topic.getSubjectLocators(); if (!locs.isEmpty()) { return "sl:" + locs.iterator().next().toExternalForm(); } + locs = topic.getItemIdentifiers(); + if (!locs.isEmpty()) { + return "ii:" + locs.iterator().next().toExternalForm(); + } return "ii:" + _baseIRI + "#" + topic.getId(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-03-10 14:27:17
|
Revision: 284 http://tinytim.svn.sourceforge.net/tinytim/?rev=284&view=rev Author: lheuer Date: 2009-03-10 14:27:07 +0000 (Tue, 10 Mar 2009) Log Message: ----------- - XMLWriter adds newline even even if depth == 0 if prettify is enabled - AbstractTopicMapReader: added method which gets called if parsing was successful - LTMTopicMapReader: Added configurable reifier handling, added docs - LTM lib: Added configurable reifier handling - XTM lib: Fixed XTM 1.0 mergeMap bug (mergeMap works now) - MIO lib: Changed some internals but it is binary compatible to 0.9.3 Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMTopicMapReader.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java Added Paths: ----------- tinytim-mio/trunk/lib/semagia-mio-0.9.4.jar tinytim-mio/trunk/lib/semagia-mio-ltm-0.9.4.jar tinytim-mio/trunk/lib/semagia-mio-xtm-0.9.4.jar Removed Paths: ------------- tinytim-mio/trunk/lib/semagia-mio-0.9.3.jar tinytim-mio/trunk/lib/semagia-mio-ltm-0.9.3.jar tinytim-mio/trunk/lib/semagia-mio-xtm-0.9.3-sp1.jar Deleted: tinytim-mio/trunk/lib/semagia-mio-0.9.3.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/semagia-mio-0.9.4.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/semagia-mio-0.9.4.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/lib/semagia-mio-ltm-0.9.3.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/semagia-mio-ltm-0.9.4.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/semagia-mio-ltm-0.9.4.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/lib/semagia-mio-xtm-0.9.3-sp1.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/semagia-mio-xtm-0.9.4.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/semagia-mio-xtm-0.9.4.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java 2009-03-09 13:59:35 UTC (rev 283) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/AbstractTopicMapReader.java 2009-03-10 14:27:07 UTC (rev 284) @@ -1,5 +1,5 @@ /* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -129,6 +129,7 @@ public void read() throws IOException { try { _deserializer.parse(_source); + postProcess(); } catch (MIOException ex) { if (ex.getException() instanceof IOException) { @@ -142,4 +143,14 @@ _deserializer = null; } } + + /** + * Called if parsing has been finished without errors, does nothing by default. + * <p> + * The {@link #_deserializer} is still available. + * </p> + */ + protected void postProcess() { + // noop. + } } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMTopicMapReader.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMTopicMapReader.java 2009-03-09 13:59:35 UTC (rev 283) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/LTMTopicMapReader.java 2009-03-10 14:27:07 UTC (rev 284) @@ -1,5 +1,5 @@ /* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import org.tmapi.core.TopicMap; +import com.semagia.mio.Property; import com.semagia.mio.Source; import com.semagia.mio.Syntax; @@ -41,6 +42,10 @@ * specified after an subject locator (if given); this implementation * does not mandate any order; a subject locator may be followed by an * subject identifier etc.</li> + * <li>Reification is handled directly without adding an additional item + * identifier to the reified construct and without adding an additional + * subject identifier to the reifier (unless this "feature" is enabled + * explicitely; c.f. {@link #setLegacyReifierHandling(boolean)}</li> * </ul> * </p> * @@ -100,49 +105,31 @@ super(topicMap, Syntax.LTM, source); } -// /** -// * Enables / disables processing of the "#MERGEMAP" directive. -// * <p> -// * The reader won't deserialize topic maps referenced by mergeMap if -// * this feature is enabled (disabled by default). -// * </p> -// * -// * @param ignore <tt>true</tt> to ignore "#MERGEMAP" directives, -// * otherwise <tt>false</tt>. -// */ -// public void setIgnoreMergeMap(boolean ignore) { -// _deserializer.setProperty(Property.IGNORE_MERGEMAP, ignore); -// } -// -// /** -// * Returns if this reader ignores "#MERGEMAP" directives. -// * -// * @return <tt>true</tt> if "#MERGEMAP" is ignored, otherwise <tt>false</tt>. -// */ -// public boolean isIgnoringMergeMap() { -// return Boolean.TRUE.equals(_deserializer.getProperty(Property.IGNORE_MERGEMAP)); -// } + /** + * Indicates if reified construct should receive an item identifier of the + * form <tt>uri-of-file#--reified--id</tt> and the reifying topic should + * receive a subject identifier of the same form. + * <p> + * By default this "feature" is disabled; the parser sets [reifier] property + * of the reified construct and does not add any additional IRIs. To be + * conform to the LTM specification, this feature has to be enabled even if + * it adds no value. + * </p> + * + * @param enable <tt>true</tt> to enable the legacy mode, otherwise <tt>false</tt>. + */ + public void setLegacyReifierHandling(boolean enable) { + _deserializer.setProperty(Property.XTM_10_LEGACY, Boolean.valueOf(enable)); + } -// /** -// * Enables / disables processing of the "#INCLUDE" directive. -// * <p> -// * The reader won't deserialize topic maps referenced by "#INCLUDE" if -// * this feature is enabled (disabled by default). -// * </p> -// * -// * @param ignore <tt>true</tt> to ignore "#INCLUDE" directives, -// * otherwise <tt>false</tt>. -// */ -// public void setIgnoreInclude(boolean ignore) { -// _deserializer.setProperty(Property.IGNORE_INCLUDE, ignore); -// } -// -// /** -// * Returns if this reader ignores "#INCLUDE" directives. -// * -// * @return <tt>true</tt> if "#INCLUDE" is ignored, otherwise <tt>false</tt>. -// */ -// public boolean isIgnoringInclude() { -// return Boolean.TRUE.equals(_deserializer.getProperty(Property.IGNORE_INCLUDE)); -// } + /** + * Indicates if the parser handles the reification of constructs in a legacy + * way. + * + * @return <tt>true</tt> if the parser is in legacy mode, otherwise <tt>false</tt>. + */ + public boolean getLegacyReifierHandling() { + return Boolean.TRUE.equals(_deserializer.getProperty(Property.XTM_10_LEGACY)); + } + } Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2009-03-09 13:59:35 UTC (rev 283) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/XMLWriter.java 2009-03-10 14:27:07 UTC (rev 284) @@ -1,5 +1,5 @@ /* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,7 +68,9 @@ _out.write("\" standalone=\"yes\"?>"); _newline(); _out.write("<!-- Generated by tinyTiM - http://tinytim.sourceforge.net/ -->"); - _newline(); + if (!_prettify) { + _newline(); + } _depth = 0; } @@ -85,6 +87,9 @@ } } + /** + * Writes an element start with no attributes. + */ public void startElement(String name) throws IOException { startElement(name, EMPTY_ATTRS); } @@ -108,10 +113,7 @@ _endElement(name, true); } - /** - * @see org.xml.sax.DocumentHandler#endElement(java.lang.String) - */ - public void _endElement(String name, boolean indent) throws IOException { + private void _endElement(String name, boolean indent) throws IOException { _depth--; if (indent) { _indent(); @@ -139,7 +141,7 @@ _endElement(name, false); } - public void _writeAttributes(Attributes attrs) throws IOException { + private void _writeAttributes(Attributes attrs) throws IOException { char[] chars; for (int i=0; i < attrs.getLength(); i++) { _out.write(' '); @@ -164,9 +166,7 @@ if (!_prettify) { return; } - if (_depth > 0) { - _newline(); - } + _newline(); int indent = _depth*2; char[] chars = new char[indent]; for (int i=0; i<indent; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-03-10 14:33:09
|
Revision: 286 http://tinytim.svn.sourceforge.net/tinytim/?rev=286&view=rev Author: lheuer Date: 2009-03-10 14:32:55 +0000 (Tue, 10 Mar 2009) Log Message: ----------- Updated CHANGES.txt and build scripts Modified Paths: -------------- tinytim-mio/trunk/CHANGES.txt tinytim-mio/trunk/build-15.xml tinytim-mio/trunk/build.xml Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2009-03-10 14:28:29 UTC (rev 285) +++ tinytim-mio/trunk/CHANGES.txt 2009-03-10 14:32:55 UTC (rev 286) @@ -2,15 +2,17 @@ Changes Log =========== -2.0.0 a4 SP1 (xx.02.2008) -------------------------- +2.0.0 a5 (xx.03.2009) +--------------------- * JTMTopicMapReader / JTMTopicMapWriter implement the new JSON Topic Maps specification (<http://www.cerny-online.com/jtm/1.0/> +* LTMTopicMapReader: Configurable reification handling Bugfixes: --------- * Validation of XTM 1.0 and 2.0 sources against a RELAX-NG schema - did not work in all cases, fixed in "semagia-mio-xtm-0.9.3-sp1.jar" + did not work in all cases, fixed in "semagia-mio-xtm-0.9.4.jar" +* XTM 1.0 <mergeMap/> didn't work, fixed * Bug #2560821 -- XTM 1.0 serializer uses wrong element for type reported by Jens Rummler * Bug #2540490 -- Using QName in isa/ako throws syntax error Modified: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2009-03-10 14:28:29 UTC (rev 285) +++ tinytim-mio/trunk/build-15.xml 2009-03-10 14:32:55 UTC (rev 286) @@ -12,7 +12,7 @@ <property name="lib.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0b2.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> - <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.3.jar"/> + <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> <target name="help"> <echo message="------------------------"/> Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-03-10 14:28:29 UTC (rev 285) +++ tinytim-mio/trunk/build.xml 2009-03-10 14:32:55 UTC (rev 286) @@ -13,7 +13,7 @@ <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a4.jar"/> <property name="lib.tinytim.tests" value="${dir.lib}/tinytim-2.0.0a4-tests.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> - <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.3.jar"/> + <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> <target name="help"> <echo message="------------------------"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 11:34:55
|
Revision: 302 http://tinytim.svn.sourceforge.net/tinytim/?rev=302&view=rev Author: lheuer Date: 2009-07-02 11:34:33 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Removed TinyTimMapInputHandler from 2.0 mio, updated build script, updated TMAPI Modified Paths: -------------- tinytim-mio/trunk/build.xml Added Paths: ----------- tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-20090702.jar tinytim-mio/trunk/lib/tmapi-2.0a2.jar Removed Paths: ------------- tinytim-mio/trunk/lib/tinytim-2.0.0a4.jar tinytim-mio/trunk/lib/tmapi-2.0a1.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/mio/ Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-07-02 11:27:40 UTC (rev 301) +++ tinytim-mio/trunk/build.xml 2009-07-02 11:34:33 UTC (rev 302) @@ -9,8 +9,8 @@ <property name="dir.lib" value="${basedir}/lib"/> <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> - <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a1.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a4.jar"/> + <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a2.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a5-snapshot-20090702.jar"/> <property name="lib.tinytim.tests" value="${dir.lib}/tinytim-2.0.0a4-tests.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> Deleted: tinytim-mio/trunk/lib/tinytim-2.0.0a4.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-20090702.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-2.0.0a5-snapshot-20090702.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/lib/tmapi-2.0a1.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/tmapi-2.0a2.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tmapi-2.0a2.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-02 11:27:40 UTC (rev 301) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-07-02 11:34:33 UTC (rev 302) @@ -1,530 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.mio; - -import java.util.List; - -import org.tinytim.core.Scope; -import org.tinytim.core.value.Literal; -import org.tinytim.internal.api.IConstruct; -import org.tinytim.internal.api.IConstructFactory; -import org.tinytim.internal.api.ILiteralAware; -import org.tinytim.internal.api.IName; -import org.tinytim.internal.api.IScope; -import org.tinytim.internal.api.IScoped; -import org.tinytim.internal.api.ITopic; -import org.tinytim.internal.api.ITopicMap; -import org.tinytim.internal.api.IVariant; -import org.tinytim.internal.utils.CollectionFactory; -import org.tinytim.utils.TypeInstanceConverter; -import org.tinytim.voc.TMDM; - -import org.tmapi.core.Association; -import org.tmapi.core.Construct; -import org.tmapi.core.Locator; -import org.tmapi.core.Reifiable; -import org.tmapi.core.Role; -import org.tmapi.core.Scoped; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.Typed; - -import com.semagia.mio.IMapHandler; -import com.semagia.mio.IRef; -import com.semagia.mio.MIOException; - -/** - * Implementation of a {@link com.semagia.mio.IMapHandler} for tinyTiM. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public final class TinyTimMapInputHandler implements IMapHandler { - - private static final byte - INITIAL = 1, - TOPIC = 2, - ASSOCIATION = 3, - ROLE = 4, - OCCURRENCE = 5, - NAME = 6, - VARIANT = 7, - SCOPE = 8, - THEME = 9, - REIFIER = 10, - PLAYER = 11, - ISA = 12, - TYPE = 13; - - private static final int _CONSTRUCT_SIZE = 6; - private static final int _STATE_SIZE = 10; - private static final int _SCOPE_SIZE = 6; - - private final IConstructFactory _factory; - private final ITopicMap _tm; - private final List<Topic> _scope; - private byte[] _stateStack; - private int _stateSize; - private IConstruct[] _constructStack; - private int _constructSize; - - public TinyTimMapInputHandler(TopicMap topicMap) { - if (topicMap == null) { - throw new IllegalArgumentException("The topic map must not be null"); - } - _tm = (ITopicMap) topicMap; - _factory = _tm.getConstructFactory(); - _scope = CollectionFactory.createList(_SCOPE_SIZE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTopicMap() - */ - public void startTopicMap() throws MIOException { - _constructStack = new IConstruct[_CONSTRUCT_SIZE]; - _stateStack = new byte[_STATE_SIZE]; - _constructSize = 0; - _stateSize = 0; - _enterState(INITIAL, _tm); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTopicMap() - */ - public void endTopicMap() throws MIOException { - TypeInstanceConverter.convertAssociationsToTypes(_tm); - _constructStack = null; - _stateStack = null; - _scope.clear(); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTopic(com.semagia.mio.IRef) - */ - public void startTopic(IRef identity) throws MIOException { - _enterState(TOPIC, _createTopic(identity)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTopic() - */ - public void endTopic() throws MIOException { - _handleTopic((Topic) _leaveStatePopConstruct(TOPIC)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startAssociation() - */ - public void startAssociation() throws MIOException { - _enterState(ASSOCIATION, _factory.createAssociation()); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endAssociation() - */ - public void endAssociation() throws MIOException { - _leaveStatePopConstruct(ASSOCIATION); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startRole() - */ - public void startRole() throws MIOException { - assert _state() == ASSOCIATION; - _enterState(ROLE, _factory.createRole((Association) _peekConstruct())); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endRole() - */ - public void endRole() throws MIOException { - _leaveStatePopConstruct(ROLE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startPlayer() - */ - public void startPlayer() throws MIOException { - assert _state() == ROLE; - _enterState(PLAYER); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endPlayer() - */ - public void endPlayer() throws MIOException { - _leaveState(PLAYER); - assert _state() == ROLE; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startOccurrence() - */ - public void startOccurrence() throws MIOException { - _enterState(OCCURRENCE, _factory.createOccurrence(_peekTopic())); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endOccurrence() - */ - public void endOccurrence() throws MIOException { - _leaveStatePopConstruct(OCCURRENCE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startName() - */ - public void startName() throws MIOException { - _enterState(NAME, _factory.createName(_peekTopic())); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endName() - */ - public void endName() throws MIOException { - IName name = (IName) _leaveStatePopConstruct(NAME); - if (name.getType() == null) { - name.setType(_tm.createTopicBySubjectIdentifier(TMDM.TOPIC_NAME)); - } - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startVariant() - */ - public void startVariant() throws MIOException { - assert _state() == NAME; - _enterState(VARIANT, _factory.createVariant((IName) _peekConstruct())); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endVariant() - */ - public void endVariant() throws MIOException { - IVariant variant = (IVariant) _leaveStatePopConstruct(VARIANT); - IName name = (IName) _peekConstruct(); - IScope scope = variant.getScopeObject(); - if (scope.isUnconstrained() || name.getScopeObject().equals(scope)) { - _reportError("The variant has no scope"); - } - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startType() - */ - public void startType() throws MIOException { - assert _peekConstruct() instanceof Typed; - _enterState(TYPE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endType() - */ - public void endType() throws MIOException { - _leaveState(TYPE); - assert _peekConstruct() instanceof Typed; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startScope() - */ - public void startScope() throws MIOException { - assert _peekConstruct() instanceof Scoped; - _enterState(SCOPE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endScope() - */ - public void endScope() throws MIOException { - _leaveState(SCOPE); - ((IScoped) _peekConstruct()).setScopeObject(Scope.create(_scope)); - _scope.clear(); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTheme() - */ - public void startTheme() throws MIOException { - assert _state() == SCOPE; - _enterState(THEME); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTheme() - */ - public void endTheme() throws MIOException { - _leaveState(THEME); - assert _state() == SCOPE; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#subjectIdentifier(java.lang.String) - */ - public void subjectIdentifier(String subjectIdentifier) throws MIOException { - Locator sid = _tm.createLocator(subjectIdentifier); - ITopic topic = _peekTopic(); - Topic existing = _tm.getTopicBySubjectIdentifier(sid); - if (existing != null && !(existing.equals(topic))) { - _merge(existing, topic); - } - else { - IConstruct tmo = (IConstruct) _tm.getConstructByItemIdentifier(sid); - if (tmo != null && tmo.isTopic() && !tmo.equals(topic)) { - _merge((Topic) tmo, topic); - } - } - topic.addSubjectIdentifier(sid); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#subjectLocator(java.lang.String) - */ - public void subjectLocator(String subjectLocator) throws MIOException { - Locator slo = _tm.createLocator(subjectLocator); - ITopic topic = _peekTopic(); - Topic existing = _tm.getTopicBySubjectLocator(slo); - if (existing != null && !(existing.equals(topic))) { - _merge(existing, topic); - } - topic.addSubjectLocator(slo); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#itemIdentifier(java.lang.String) - */ - public void itemIdentifier(String itemIdentifier) throws MIOException { - Locator iid = _tm.createLocator(itemIdentifier); - IConstruct tmo = _peekConstruct(); - if (_state() == TOPIC) { - IConstruct existing = (IConstruct) _tm.getConstructByItemIdentifier(iid); - if (existing != null && existing.isTopic() && !existing.equals(tmo)) { - _merge((Topic) existing, (ITopic) tmo); - } - else { - Topic topic = _tm.getTopicBySubjectIdentifier(iid); - if (topic != null && !topic.equals(tmo)) { - _merge(topic, (ITopic) tmo); - } - } - } - tmo.addItemIdentifier(iid); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startIsa() - */ - public void startIsa() throws MIOException { - assert _state() == TOPIC; - _enterState(ISA); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endIsa() - */ - public void endIsa() throws MIOException { - _leaveState(ISA); - assert _state() == TOPIC; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startReifier() - */ - public void startReifier() throws MIOException { - assert _peekConstruct() instanceof Reifiable; - _enterState(REIFIER); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endReifier() - */ - public void endReifier() throws MIOException { - _leaveState(REIFIER); - assert _peekConstruct() instanceof Reifiable; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#topicRef(com.semagia.mio.IRef) - */ - public void topicRef(IRef identity) throws MIOException { - _handleTopic(_createTopic(identity)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#value(java.lang.String) - */ - public void value(String value) throws MIOException { - assert _state() == NAME; - ((IName) _peekConstruct()).setValue(value); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#value(java.lang.String, java.lang.String) - */ - public void value(String value, String datatype) throws MIOException { - ((ILiteralAware) _peekConstruct()).setLiteral(Literal.create(value, datatype)); - } - - /** - * Enters a state. - * - * @param state The state to push ontop of the state stack. - */ - private void _enterState(byte state) { - if (_stateSize >= _stateStack.length) { - byte[] states = new byte[_stateStack.length*2]; - System.arraycopy(_stateStack, 0, states, 0, _stateStack.length); - _stateStack = states; - } - _stateStack[_stateSize++] = state; - } - - /** - * Enters a state and pushes the Topic Maps construct ontop of the construct - * stack. - * - * @param state The state to enter. - * @param tmo The Topic Maps construct which should be pushed to the stack. - */ - private void _enterState(byte state, Construct tmo) { - _enterState(state); - if (_constructSize >= _constructStack.length) { - IConstruct[] constructs = new IConstruct[_constructStack.length*2]; - System.arraycopy(_constructStack, 0, constructs, 0, _constructStack.length); - _constructStack = constructs; - } - _constructStack[_constructSize++] = (IConstruct) tmo; - } - - /** - * Leaves a state. - * - * @param state The state to leave. - * @throws MIOException If the state is not equals to the current state. - */ - private void _leaveState(byte state) throws MIOException { - if (state != _state()) { - _reportError("Unexpected state: " + _state() + ", expected: " + state); - } - _stateSize--; - } - - /** - * Leaves a state and removed the Topic Maps construct from the top of the - * construct stack. - * - * @param state The state to leave. - * @throws MIOException If the state is not equals to the current state. - */ - private IConstruct _leaveStatePopConstruct(byte state) throws MIOException { - _leaveState(state); - final IConstruct construct = _peekConstruct(); - _constructSize--; - _constructStack[_constructSize] = null; - return construct; - } - - /** - * Returns the Topic Maps construct on top of the stack. - * - * @return The Topic Maps construct. - */ - private IConstruct _peekConstruct() { - return _constructStack[_constructSize-1]; - } - - /** - * Returns the topic on top of the stack. - * - * @return The topic. - */ - private ITopic _peekTopic() { - return (ITopic) _peekConstruct(); - } - - /** - * Returns the current state. - * - * @return The current state. - */ - private byte _state() { - return _stateStack[_stateSize-1]; - } - - /** - * Handles the topic dependent on the current state. - * - * @param topic The topic to handle. - */ - private void _handleTopic(Topic topic) { - switch (_state()) { - case ISA: _peekTopic().addType(topic); break; - case TYPE: ((Typed) _peekConstruct()).setType(topic); break; - case PLAYER: ((Role) _peekConstruct()).setPlayer(topic); break; - case THEME: _scope.add(topic); break; - case REIFIER: ((Reifiable) _peekConstruct()).setReifier(topic); break; - } - } - - /** - * Merges the <tt>source</tt> topic with the <tt>target</tt>. - * - * Further, this method ensures that the construct stack stays valid: If - * the <tt>source</tt> is part of the stack, it is replaced with - * <tt>target</tt>. - * - * @param source The source topic (will be removed). - * @param target The target topic. - */ - private void _merge(Topic source, ITopic target) { - for (int i=0; i <_constructSize; i++) { - if (_constructStack[i].equals(source)) { - _constructStack[i] = target; - } - } - target.mergeIn(source); - } - - /** - * Returns either an existing topic with the specified identity or creates - * a topic with the given identity. - * - * @param ref The identity of the topic. - * @return A topic instance. - * @throws MIOException - */ - private ITopic _createTopic(IRef ref) throws MIOException { - Locator loc = _tm.createLocator(ref.getIRI()); - switch (ref.getType()) { - case IRef.ITEM_IDENTIFIER: return (ITopic) _tm.createTopicByItemIdentifier(loc); - case IRef.SUBJECT_IDENTIFIER: return (ITopic) _tm.createTopicBySubjectIdentifier(loc); - case IRef.SUBJECT_LOCATOR: return (ITopic) _tm.createTopicBySubjectLocator(loc); - default: _reportError("Unknown reference type " + ref.getType()); - } - // Never returned, an exception was thrown - return null; - } - - /** - * Reports an error. - * - * @param msg The error message. - * @throws MIOException Thrown in any case. - */ - private static void _reportError(String msg) throws MIOException { - throw new MIOException(msg); - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 13:17:08
|
Revision: 305 http://tinytim.svn.sourceforge.net/tinytim/?rev=305&view=rev Author: lheuer Date: 2009-07-02 12:44:13 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Preparation for 1.5.0 mio release Modified Paths: -------------- tinytim-mio/trunk/CHANGES.txt tinytim-mio/trunk/build-15.properties tinytim-mio/trunk/build-15.xml Added Paths: ----------- tinytim-mio/trunk/lib/tinytim-1.5.0.jar Removed Paths: ------------- tinytim-mio/trunk/lib/tinytim-1.5.0b2.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio15/TinyTimMapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/mio15/ Modified: tinytim-mio/trunk/CHANGES.txt =================================================================== --- tinytim-mio/trunk/CHANGES.txt 2009-07-02 12:24:57 UTC (rev 304) +++ tinytim-mio/trunk/CHANGES.txt 2009-07-02 12:44:13 UTC (rev 305) @@ -2,10 +2,8 @@ Changes Log =========== -2.0.0 a5 (xx.05.2009) +1.5.0 (02.07.2009) --------------------- -* JTMTopicMapReader / JTMTopicMapWriter implement the new JSON Topic Maps - specification (<http://www.cerny-online.com/jtm/1.0/> * LTMTopicMapReader: Configurable reification handling Bugfixes: Modified: tinytim-mio/trunk/build-15.properties =================================================================== --- tinytim-mio/trunk/build-15.properties 2009-07-02 12:24:57 UTC (rev 304) +++ tinytim-mio/trunk/build-15.properties 2009-07-02 12:44:13 UTC (rev 305) @@ -1,5 +1,5 @@ version=1.5.0 -version_suffix=b2 -#release_type= +version_suffix= +release_type= debug=off optimize=on Modified: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2009-07-02 12:24:57 UTC (rev 304) +++ tinytim-mio/trunk/build-15.xml 2009-07-02 12:44:13 UTC (rev 305) @@ -10,7 +10,7 @@ <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> <property name="lib.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0b2.jar"/> + <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0.jar"/> <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> Added: tinytim-mio/trunk/lib/tinytim-1.5.0.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/tinytim-1.5.0.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/lib/tinytim-1.5.0b2.jar =================================================================== (Binary files differ) Deleted: tinytim-mio/trunk/src/main/java/org/tinytim/mio15/TinyTimMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio15/TinyTimMapInputHandler.java 2009-07-02 12:24:57 UTC (rev 304) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio15/TinyTimMapInputHandler.java 2009-07-02 12:44:13 UTC (rev 305) @@ -1,590 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.mio; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.logging.Logger; - -import org.tinytim.IReifiable; -import org.tinytim.ITyped; -import org.tinytim.TopicMapImpl; -import org.tinytim.TypeInstanceConverter; -import org.tinytim.voc.TMDM; -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.Locator; -import org.tmapi.core.Occurrence; -import org.tmapi.core.ScopedObject; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.TopicMapObject; -import org.tmapi.core.TopicName; -import org.tmapi.core.Variant; - -import com.semagia.mio.IMapHandler; -import com.semagia.mio.IRef; -import com.semagia.mio.MIOException; -import com.semagia.mio.voc.XSD; - -/** - * {@link com.semagia.mio.IMapHandler} implementation. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public class TinyTimMapInputHandler implements IMapHandler { - - private enum State { - INITIAL, TOPIC, ASSOCIATION, ROLE, OCCURRENCE, NAME, VARIANT, - SCOPE, THEME, REIFIER, PLAYER, ISA, TYPE; - } - - private static final Logger LOG = Logger.getLogger(TinyTimMapInputHandler.class.getName()); - - private TopicMapImpl _tm; - private List<State> _stateStack; - private List<TopicMapObject> _constructStack; - - public TinyTimMapInputHandler() { - } - - public TinyTimMapInputHandler(TopicMap topicMap) { - this(); - setTopicMap(topicMap); - } - - /** - * Sets the topic map instance to operate on. - * - * @param topicMap The topic map. - */ - public void setTopicMap(TopicMap topicMap) { - if (topicMap == null) { - throw new IllegalArgumentException("The topic map must not be null"); - } - _tm = (TopicMapImpl) topicMap; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTopicMap() - */ - public void startTopicMap() throws MIOException { - _constructStack = new ArrayList<TopicMapObject>(); - _stateStack = new ArrayList<State>(); - _enterState(State.INITIAL, _tm); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTopicMap() - */ - public void endTopicMap() throws MIOException { - TypeInstanceConverter.convertAssociationsToTypes(_tm); - _constructStack = null; - _stateStack = null; - _tm = null; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTopic(com.semagia.mio.IRef) - */ - public void startTopic(IRef identity) throws MIOException { - _enterState(State.TOPIC, _createTopic(identity)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTopic() - */ - public void endTopic() throws MIOException { - Topic topic = (Topic) _leaveStatePopConstruct(State.TOPIC); - _handleTopic(topic); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startAssociation() - */ - public void startAssociation() throws MIOException { - _enterState(State.ASSOCIATION, _tm.createAssociation()); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endAssociation() - */ - public void endAssociation() throws MIOException { - _leaveStatePopConstruct(State.ASSOCIATION); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startRole() - */ - public void startRole() throws MIOException { - assert _state() == State.ASSOCIATION; - _enterState(State.ROLE, ((Association) _peekConstruct()).createAssociationRole(null, null)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endRole() - */ - public void endRole() throws MIOException { - _leaveStatePopConstruct(State.ROLE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startPlayer() - */ - public void startPlayer() throws MIOException { - assert _state() == State.ROLE; - _enterState(State.PLAYER); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endPlayer() - */ - public void endPlayer() throws MIOException { - _leaveState(State.PLAYER); - assert _state() == State.ROLE; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startOccurrence() - */ - public void startOccurrence() throws MIOException { - _enterState(State.OCCURRENCE, _peekTopic().createOccurrence((Locator) null, null, null)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endOccurrence() - */ - public void endOccurrence() throws MIOException { - _leaveStatePopConstruct(State.OCCURRENCE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startName() - */ - public void startName() throws MIOException { - _enterState(State.NAME, _peekTopic().createTopicName(null, null)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endName() - */ - public void endName() throws MIOException { - TopicName name = (TopicName) _leaveStatePopConstruct(State.NAME); - if (name.getType() == null) { - name.setType(_topicBySubjectIdentifier(TMDM.TOPIC_NAME)); - } - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startVariant() - */ - public void startVariant() throws MIOException { - assert _state() == State.NAME; - _enterState(State.VARIANT, ((TopicName) _peekConstruct()).createVariant((Locator) null, null)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endVariant() - */ - @SuppressWarnings("unchecked") - public void endVariant() throws MIOException { - Variant variant = (Variant) _leaveStatePopConstruct(State.VARIANT); - Collection<Topic> scope = variant.getScope(); - if (scope.isEmpty() || variant.getTopicName().getScope().equals(scope)) { - throw new MIOException("The variant has no scope"); - } - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startType() - */ - public void startType() throws MIOException { - assert _peekConstruct() instanceof ITyped; - _enterState(State.TYPE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endType() - */ - public void endType() throws MIOException { - _leaveState(State.TYPE); - assert _peekConstruct() instanceof ITyped; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startScope() - */ - public void startScope() throws MIOException { - assert _peekConstruct() instanceof ScopedObject; - _enterState(State.SCOPE); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endScope() - */ - public void endScope() throws MIOException { - _leaveState(State.SCOPE); - assert _peekConstruct() instanceof ScopedObject; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startTheme() - */ - public void startTheme() throws MIOException { - assert _state() == State.SCOPE; - _enterState(State.THEME); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endTheme() - */ - public void endTheme() throws MIOException { - _leaveState(State.THEME); - assert _state() == State.SCOPE; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#subjectIdentifier(java.lang.String) - */ - public void subjectIdentifier(String subjectIdentifier) throws MIOException { - Locator sid = _tm.createLocator(subjectIdentifier); - Topic topic = _peekTopic(); - Topic existing = _tm.getTopicBySubjectIdentifier(sid); - if (existing != null && !existing.equals(topic)) { - _merge(existing, topic); - } - else { - TopicMapObject tmo = _tm.getObjectByItemIdentifier(sid); - if (tmo != null && tmo instanceof Topic && !tmo.equals(topic)) { - _merge((Topic) tmo, topic); - } - } - topic.addSubjectIdentifier(sid); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#subjectLocator(java.lang.String) - */ - public void subjectLocator(String subjectLocator) throws MIOException { - Locator slo = _tm.createLocator(subjectLocator); - Topic topic = _peekTopic(); - Topic existing = _tm.getTopicBySubjectLocator(slo); - if (existing != null && !existing.equals(topic)) { - _merge(existing, topic); - } - topic.addSubjectLocator(slo); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#itemIdentifier(java.lang.String) - */ - public void itemIdentifier(String itemIdentifier) throws MIOException { - Locator iid = _tm.createLocator(itemIdentifier); - TopicMapObject tmo = _peekConstruct(); - if (_state() == State.TOPIC) { - TopicMapObject existing = _tm.getObjectByItemIdentifier(iid); - if (existing != null && existing instanceof Topic && !existing.equals(tmo)) { - _merge((Topic) existing, (Topic) tmo); - } - else { - Topic topic = _tm.getTopicBySubjectIdentifier(iid); - if (topic != null && !topic.equals(tmo)) { - _merge(topic, (Topic) tmo); - } - } - } - tmo.addSourceLocator(iid); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startIsa() - */ - public void startIsa() throws MIOException { - assert _state() == State.TOPIC; - _enterState(State.ISA); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endIsa() - */ - public void endIsa() throws MIOException { - _leaveState(State.ISA); - assert _state() == State.TOPIC; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#startReifier() - */ - public void startReifier() throws MIOException { - assert _peekConstruct() instanceof IReifiable; - _enterState(State.REIFIER); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#endReifier() - */ - public void endReifier() throws MIOException { - _leaveState(State.REIFIER); - assert _peekConstruct() instanceof IReifiable; - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#topicRef(com.semagia.mio.IRef) - */ - public void topicRef(IRef identity) throws MIOException { - _handleTopic(_createTopic(identity)); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#value(java.lang.String) - */ - public void value(String value) throws MIOException { - assert _state() == State.NAME; - ((TopicName) _peekConstruct()).setValue(value); - } - - /* (non-Javadoc) - * @see com.semagia.mio.IMapHandler#value(java.lang.String, java.lang.String) - */ - public void value(String value, String datatype) throws MIOException { - boolean isLocator = XSD.ANY_URI.equals(datatype); - if (!isLocator && !XSD.STRING.equals(datatype)) { - LOG.warning("The datatype '" + datatype + "' was converted into xsd:string"); - } - if (_state() == State.OCCURRENCE) { - Occurrence occ = (Occurrence) _peekConstruct(); - if (isLocator) { - occ.setResource(_tm.createLocator(value)); - } - else { - occ.setValue(value); - } - } - else { - assert _state() == State.VARIANT; - Variant variant = (Variant) _peekConstruct(); - if (isLocator) { - variant.setResource(_tm.createLocator(value)); - } - else { - variant.setValue(value); - } - } - } - - /** - * Enters a state. - * - * @param state The state to push ontop of the state stack. - */ - private void _enterState(State state) { - _stateStack.add(state); - } - - /** - * Enters a state and pushes the Topic Maps construct ontop of the construct - * stack. - * - * @param state The state to enter. - * @param tmo The Topic Maps construct which should be pushed to the stack. - */ - private void _enterState(State state, TopicMapObject tmo) { - _enterState(state); - _constructStack.add(tmo); - } - - /** - * Leaves a state. - * - * @param state The state to leave. - * @throws MIOException If the state is not equals to the current state. - */ - private void _leaveState(State state) throws MIOException { - State current = _stateStack.remove(_stateStack.size()-1); - if (state != current) { - _reportError("Unexpected state: " + current + ", expected: " + state); - } - } - - /** - * Leaves a state and removed the Topic Maps construct from the top of the - * construct stack. - * - * @param state The state to leave. - * @return The removed construct. - * @throws MIOException If the state is not equals to the current state. - */ - private TopicMapObject _leaveStatePopConstruct(State state) throws MIOException { - _leaveState(state); - return _constructStack.remove(_constructStack.size()-1); - } - - /** - * Returns the Topic Maps construct on top of the stack. - * - * @return The Topic Maps construct. - */ - private TopicMapObject _peekConstruct() { - return _constructStack.get(_constructStack.size()-1); - } - - /** - * Returns the topic on top of the stack. - * - * @return The topic. - */ - private Topic _peekTopic() { - return (Topic) _peekConstruct(); - } - - /** - * Returns the current state. - * - * @return The current state. - */ - private State _state() { - return _stateStack.get(_stateStack.size()-1); - } - - /** - * Handles the topic dependent on the current state. - * - * @param topic The topic to handle. - */ - private void _handleTopic(Topic topic) { - switch (_state()) { - case ISA: _peekTopic().addType(topic); break; - case TYPE: ((ITyped) _peekConstruct()).setType(topic); break; - case PLAYER: ((AssociationRole) _peekConstruct()).setPlayer(topic); break; - case THEME: ((ScopedObject) _peekConstruct()).addScopingTopic(topic); break; - case REIFIER: ((IReifiable) _peekConstruct()).setReifier(topic); break; - } - } - - /** - * Merges the <tt>source</tt> topic with the <tt>target</tt>. - * - * Further, this method ensures that the construct stack stays valid: If - * the <tt>source</tt> is part of the stack, it is replaced with - * <tt>target</tt>. - * - * @param source The source topic (will be removed). - * @param target The target topic. - */ - private void _merge(Topic source, Topic target) { - int i = _constructStack.indexOf(source); - while (i > -1) { - _constructStack.set(i, target); - i = _constructStack.indexOf(source); - } - target.mergeIn(source); - } - - /** - * Returns either an existing topic with the specified identity or creates - * a topic with the given identity. - * - * @param ref The identity of the topic. - * @return A topic instance. - * @throws MIOException - */ - private Topic _createTopic(IRef ref) throws MIOException { - Locator loc = _tm.createLocator(ref.getIRI()); - switch (ref.getType()) { - case IRef.ITEM_IDENTIFIER: return _topicByItemIdentifier(loc); - case IRef.SUBJECT_IDENTIFIER: return _topicBySubjectIdentifier(loc); - case IRef.SUBJECT_LOCATOR: return _topicBySubjectLocator(loc); - default: _reportError("Unknown reference type " + ref.getType()); - } - // Never returned, an exception was thrown - return null; - } - - /** - * Returns either an existing topic with the specified item identfier, - * or creates a topic with the given item identifier. - * - * @param iid The item identifier of the topic. - * @return A topic instance. - */ - private Topic _topicByItemIdentifier(Locator iid) { - TopicMapObject tmo = _tm.getObjectByItemIdentifier(iid); - Topic topic = (tmo instanceof Topic) ? (Topic) tmo : null; - if (topic == null) { - topic = _tm.getTopicBySubjectIdentifier(iid); - if (topic != null) { - topic.addSourceLocator(iid); - } - } - if (topic == null) { - topic = _tm.createTopic(); - topic.addSourceLocator(iid); - } - return topic; - } - - /** - * Returns either an existing topic with the specified subject identfier, - * or creates a topic with the given subject identifier. - * - * @param sid The subject identifier of the topic. - * @return A topic instance. - */ - private Topic _topicBySubjectIdentifier(Locator sid) { - Topic topic = _tm.getTopicBySubjectIdentifier(sid); - if (topic == null) { - TopicMapObject tmo = _tm.getObjectByItemIdentifier(sid); - if (tmo instanceof Topic) { - topic = (Topic) tmo; - topic.addSubjectIdentifier(sid); - } - } - if (topic == null) { - topic = _tm.createTopic(); - topic.addSubjectIdentifier(sid); - } - return topic; - } - - /** - * Returns either an existing topic with the specified subject locator, - * or creates a topic with the given subject locator. - * - * @param slo The subject locator of the topic. - * @return A topic instance. - */ - private Topic _topicBySubjectLocator(Locator slo) { - Topic topic = _tm.getTopicBySubjectLocator(slo); - if (topic == null) { - topic = _tm.createTopic(); - topic.addSubjectLocator(slo); - } - return topic; - } - - /** - * Reports an error. - * - * @param msg The error message. - * @throws MIOException Thrown in any case. - */ - private static void _reportError(String msg) throws MIOException { - throw new MIOException(msg); - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 13:17:09
|
Revision: 307 http://tinytim.svn.sourceforge.net/tinytim/?rev=307&view=rev Author: lheuer Date: 2009-07-02 12:47:54 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Removed references to tinyTiM 1.5 Removed Paths: ------------- tinytim-mio/trunk/build-15.properties tinytim-mio/trunk/build-15.xml tinytim-mio/trunk/lib/tinytim-1.5.0.jar tinytim-mio/trunk/lib/tmapi-1_0SP1.jar tinytim-mio/trunk/src/main/java/org/tinytim/mio15/ Deleted: tinytim-mio/trunk/build-15.properties =================================================================== --- tinytim-mio/trunk/build-15.properties 2009-07-02 12:45:44 UTC (rev 306) +++ tinytim-mio/trunk/build-15.properties 2009-07-02 12:47:54 UTC (rev 307) @@ -1,5 +0,0 @@ -version=1.5.0 -version_suffix= -release_type= -debug=off -optimize=on Deleted: tinytim-mio/trunk/build-15.xml =================================================================== --- tinytim-mio/trunk/build-15.xml 2009-07-02 12:45:44 UTC (rev 306) +++ tinytim-mio/trunk/build-15.xml 2009-07-02 12:47:54 UTC (rev 307) @@ -1,199 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<project name="tinyTiM" default="jar" basedir="."> - <property file="build-15.properties"/> - <tstamp/> - <property name="release_type" value="-snapshot-${DSTAMP}${TSTAMP}"/> - - <property name="dir.src" value="${basedir}/src/main/java"/> - <property name="dir.test" value="${basedir}/src/test/java"/> - <property name="dir.lib" value="${basedir}/lib"/> - - <property name="lib.junit" value="${dir.lib}/junit-4.5.jar"/> - <property name="lib.tmapi" value="${dir.lib}/tmapi-1_0SP1.jar"/> - <property name="lib.tinytim" value="${dir.lib}/tinytim-1.5.0.jar"/> - <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> - <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> - - <target name="help"> - <echo message="------------------------"/> - <echo message="tinyTiM MIO - Build file"/> - <echo message="------------------------"/> - <echo message=""/> - <echo message="Available targets:"/> - <echo message=""/> - <echo message=" jar Creates the jar"/> - <echo message=" doc Generates the Java Docs"/> - <echo message=" release Creates the jar and a distributable file"/> - </target> - - <target name="init"> - <property name="dist.version" value="${version}${version_suffix}${release_type}"/> - <property name="dist.name" value="tinytim-mio-${dist.version}"/> - - <property name="tinytim-mio.jar" value="${dist.name}.jar"/> - <property name="tinytim-mio.tar" value="${dist.name}.tar"/> - <property name="tinytim-mio.tar.gz" value="${tinytim-mio.tar}.gz"/> - <property name="tinytim-mio.zip" value="${dist.name}.zip"/> - - <property name="dir.build" value="${basedir}/build"/> - <property name="dir.dist.root" value="${dir.build}/dist"/> - <property name="dir.dist" value="${dir.dist.root}/${dist.name}"/> - <property name="dir.build.classes" value="${dir.build}/classes"/> - <property name="dir.build.tests" value="${dir.build}/tests"/> - <property name="dir.javadocs" value="${dir.dist}/docs/api"/> - </target> - - <!-- =================================================================== --> - <!-- Clean targets --> - <!-- =================================================================== --> - <target name="clean" depends="init"> - <delete dir="${dir.build}"/> - <delete dir="${dir.javadocs}"/> - </target> - - <!-- =================================================================== --> - <!-- Prepares the build directory --> - <!-- =================================================================== --> - <target name="prepare" depends="init"> - <mkdir dir="${dir.build}"/> - <mkdir dir="${dir.build.classes}"/> - </target> - - <!-- =================================================================== --> - <!-- Creates the Java Docs --> - <!-- =================================================================== --> - <target name="doc" depends="init"> - <mkdir dir="${dir.javadocs}"/> - <javadoc destdir="${dir.javadocs}" - packagenames="org.tinytim.*" - author="true" - version="false" - use="true" - splitindex="true" - noindex="false" - windowtitle="tinyTiM MIO API v${dist.version}" - doctitle="tinyTiM API MIO v${dist.version}"> - <fileset dir="${dir.src}"> - <exclude name="org/tinytim/mio/JTM*Writer*"/> -<!-- <include name="org/tinytim/mio/** org/tinytim/mio/*TopicMapReader* org/tinytim/mio/*TopicMapImporter*"/> --> - </fileset> - <link href="http://www.tmapi.org/apiDocs/"/> - </javadoc> - </target> - - <!-- =================================================================== --> - <!-- Tests --> - <!-- =================================================================== --> - <target name="test" depends="compile"> - <mkdir dir="${dir.build.tests}"/> - <javac destdir="${dir.build.tests}" - debug="${debug}" - optimize="${optimize}" - target="1.5" - excludes="org/tinytim/mio/TinyTimMapInputHandler*" - > - <classpath> - <pathelement location="${dir.build.classes}"/> - <pathelement location="${lib.junit}"/> - <pathelement location="${lib.tmapi}"/> - <pathelement location="${lib.tinytim}"/> - <pathelement location="${lib.mio}"/> - </classpath> - <src path="${dir.test}"/> - </javac> - <junit printsummary="true" showoutput="false" - errorProperty="test.failed" failureProperty="test.failed"> - <classpath> - <pathelement location="${dir.build.classes}"/> - <pathelement location="${dir.build.tests}"/> - <pathelement location="${lib.junit}"/> - <pathelement location="${lib.tmapi}"/> - <pathelement location="${lib.tinytim}"/> - <pathelement location="${lib.mio}"/> - </classpath> - <formatter type="brief" usefile="false"/> - <batchtest fork="no" todir="${dir.build}"> - <fileset dir="${dir.build.tests}/"> - <include name="**/Test**.class"/> - </fileset> - </batchtest> - </junit> - <fail message="Tests failed. Check test output." if="test.failed"/> - </target> - - <!-- =================================================================== --> - <!-- Compile source files --> - <!-- =================================================================== --> - <target name="compile" depends="clean, prepare"> - <javac destdir="${dir.build.classes}" - debug="${debug}" - excludes="org/tinytim/mio/AbstractTopicMapWriter* org/tinytim/mio/CXTMTopicMapWriter* org/tinytim/mio/XTM*TopicMapWriter* org/tinytim/mio/JTM*Writer* org/tinytim/mio/JSON*" - includes="org/tinytim/mio15/** org/tinytim/mio/*TopicMapReader* org/tinytim/mio/*TopicMapImporter*" - target="1.5"> - <classpath> - <pathelement location="${lib.tmapi}"/> - <pathelement location="${lib.tinytim}"/> - <pathelement location="${lib.mio}"/> - <pathelement location="${lib.logging}"/> - </classpath> - <src path="${dir.src}"/> - </javac> - </target> - - <!-- =================================================================== --> - <!-- Creates the jar --> - <!-- =================================================================== --> - <target name="jar" depends="compile"> - <jar destfile="${dir.build}/${tinytim-mio.jar}"> - <fileset dir="${dir.build.classes}"> - <include name="**/*.*"/> - </fileset> - <manifest> - <attribute name="Implementation-Title" value="tinyTiM MIO"/> - <attribute name="Implementation-Version" value="${dist.version}"/> - <attribute name="Implementation-URL" value="http://tinytim.sourceforge.net/"/> - </manifest> - </jar> - </target> - - <!-- =================================================================== --> - <!-- Prepares a distribution --> - <!-- =================================================================== --> - <target name="dist" depends="jar"> - <mkdir dir="${dir.dist}"/> - - <copy todir="${dir.dist}" file="${dir.build}/${tinytim-mio.jar}"/> -<!-- - <copy todir="${dir.dist}/src"> - <fileset dir="${dir.src}"/> - </copy> - <copy todir="${dir.dist}/test"> - <fileset dir="${dir.test}"/> - </copy> ---> - <copy todir="${dir.dist}/lib"> - <fileset dir="${dir.lib}"> - <exclude name="**/tmapi*.jar"/> - <exclude name="**/tinytim*.jar"/> - </fileset> - </copy> - - <copy todir="${dir.dist}" file="CHANGES.txt"/> - <copy todir="${dir.dist}" file="LICENSE.txt"/> - <copy todir="${dir.dist}" file="README.txt"/> - </target> - - <!-- =================================================================== --> - <!-- Creates the distribution files (.zip and .tar.gz) --> - <!-- --> - <!-- Won't create the distribution files if a test fails --> - <!-- =================================================================== --> - <target name="release" depends="jar, doc, dist"> - <tar destfile="${dir.dist.root}/${tinytim-mio.tar}" - basedir="${dir.dist.root}"/> - <gzip src="${dir.dist.root}/${tinytim-mio.tar}" - destfile="${dir.build}/${tinytim-mio.tar.gz}" /> - <delete file="${dir.dist.root}/${tinytim-mio.tar}" /> - <zip destfile="${dir.build}/${tinytim-mio.zip}" basedir="${dir.dist.root}"/> - </target> -</project> Deleted: tinytim-mio/trunk/lib/tinytim-1.5.0.jar =================================================================== (Binary files differ) Deleted: tinytim-mio/trunk/lib/tmapi-1_0SP1.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 14:51:47
|
Revision: 310 http://tinytim.svn.sourceforge.net/tinytim/?rev=310&view=rev Author: lheuer Date: 2009-07-02 14:51:22 +0000 (Thu, 02 Jul 2009) Log Message: ----------- Added newer CTMWriter version which does not work Excluded CTMWriter & co from build process Modified Paths: -------------- tinytim-mio/trunk/build.xml tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java Added Paths: ----------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITMCLPreprocessor.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITemplate.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-07-02 14:27:30 UTC (rev 309) +++ tinytim-mio/trunk/build.xml 2009-07-02 14:51:22 UTC (rev 310) @@ -130,7 +130,9 @@ <target name="compile" depends="clean, prepare"> <javac destdir="${dir.build.classes}" debug="${debug}" - target="1.5"> + target="1.5" + excludes="**/CTMTopicMapWriter.java, **/internal/**" + > <classpath> <pathelement location="${lib.tmapi}"/> <pathelement location="${lib.tinytim}"/> Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-07-02 14:27:30 UTC (rev 309) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/CTMTopicMapWriter.java 2009-07-02 14:51:22 UTC (rev 310) @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.logging.Logger; @@ -37,6 +38,11 @@ import org.tinytim.internal.api.IScope; import org.tinytim.internal.api.IScoped; import org.tinytim.internal.api.IVariant; +import org.tinytim.mio.internal.ctm.ITMCLPreprocessor; +import org.tinytim.mio.internal.ctm.ITemplate; +import org.tinytim.mio.internal.ctm.impl.DefaultTMCLPreprocessor; +import org.tinytim.voc.Namespace; +import org.tinytim.voc.TMCL; import org.tinytim.voc.TMDM; import org.tinytim.voc.XSD; @@ -68,12 +74,38 @@ private static final Logger LOG = Logger.getLogger(CTMTopicMapWriter.class.getName()); - //TODO: Unicode ranges in patterns - private static final Pattern _ID_PATTERN = Pattern.compile("[A-Za-z_](\\.*[\\-A-Za-z_0-9])*"); + private static final String _ID_START = "[a-zA-Z_]" + + "|[\\u00C0-\\u00D6]" + + "|[\\u00D8-\\u00F6]" + + "|[\\u00F8-\\u02FF]" + + "|[\\u0370-\\u037D]" + + "|[\\u037F-\\u1FFF]" + + "|[\\u200C-\\u200D]" + + "|[\\u2070-\\u218F]" + + "|[\\u2C00-\\u2FEF]" + + "|[\\u3001-\\uD7FF]" + + "|[\\uF900-\\uFDCF]" + + "|[\\uFDF0-\\uFFFD]" + + "|[\\u10000-\\uEFFFF]"; + private static final String _ID_PART = _ID_START + + "|[\\-\\.0-9]" + + "|\\u00B7" + + "|[\\u0300-\\u036F]" + + "|[\\u203F-\\u2040]"; + private static final String _ID_END = _ID_START + + "|[\\-0-9]" + + "|\\u00B7" + + "|[\\u0300-\\u036F]" + + "|[\\u203F-\\u2040]"; + private static final Pattern _ID_PATTERN = Pattern.compile(String.format("%s(%s*%s)*", _ID_START, _ID_PART, _ID_END)); private static final Pattern _LOCAL_PATTERN = Pattern.compile("([0-9]*\\.*[\\-A-Za-z_0-9])*"); + private static final Pattern _IRI_PATTERN = Pattern.compile("[^<>\"\\{\\}\\`\\\\ ]+"); private static final char[] _TRIPLE_QUOTES = new char[] { '"', '"', '"' }; private static final Reference[] _EMPTY_REFERENCE_ARRAY = new Reference[0]; + private static final ITemplate[] _EMPTY_TEMPLATE_ARRAY = new ITemplate[0]; + private static final Topic[] _EMPTY_TOPIC_ARRAY = new Topic[0]; private static final Reference _UNTYPED_REFERENCE = Reference.createId("[untyped]"); + private static final String _TMCL_TEMPLATE = "http://www.topicmaps.org/tmcl/templates.ctm"; private final Writer _out; private final String _baseIRI; @@ -96,8 +128,20 @@ private final Comparator<Variant> _variantComparator; private final Map<Topic, Reference> _topic2Reference; //TODO: LRU? private final Map<String, String> _prefixes; + private final Set<String> _imports; + private final Map<Topic, Collection<ITemplate>> _topic2Templates; + private final Map<Topic, Collection<Topic>> _topic2Supertypes; private Reference _lastReference; + private boolean _tmcl; + private static enum TypeFilter { + TOPIC, + ASSOCIATION, + ROLE, + OCCURRENCE, + NAME + } + /** * Constructs a new instance using "utf-8" encoding. * <p> @@ -158,8 +202,12 @@ _roleComparator = new RoleComparator(); _variantComparator = new VariantComparator(); _prefixes = new HashMap<String, String>(); + _imports = new HashSet<String>(); + _topic2Templates = new HashMap<Topic, Collection<ITemplate>>(); + _topic2Supertypes = new HashMap<Topic, Collection<Topic>>(); setIdentation(4); setExportItemIdentifiers(false); + setTMCL(true); } /** @@ -243,6 +291,13 @@ return _comment; } + public void setTMCL(boolean enable) { + _imports.add(_TMCL_TEMPLATE); + addPrefix("tmcl", Namespace.TMCL); + addPrefix("tmdm", Namespace.TMDM_MODEL); + _tmcl = true; + } + /** * Adds a prefix to the writer. * <p> @@ -261,6 +316,18 @@ * @param reference The IRI to which the prefix should be assigned to. */ public void addPrefix(String prefix, String reference) { + if (prefix == null) { + throw new IllegalArgumentException("The prefix must not be null"); + } + if (!_isValidId(prefix)) { + throw new IllegalArgumentException("The prefix is an invalid CTM identifier: " + prefix); + } + if (reference == null) { + throw new IllegalArgumentException("The reference must not be null"); + } + if (!_IRI_PATTERN.matcher(reference).matches()) { + throw new IllegalArgumentException("The reference is an invalid CTM IRI: " + reference); + } _prefixes.put(prefix, reference); } @@ -275,7 +342,7 @@ /** * Sets the identation level, by default the identation level is set to 4 - * which means four whitespace characters are written. + * which means that four whitespace characters are written. * <p> * If the size is set to <tt>0</tt>, no identation will be done. * </p> @@ -352,9 +419,19 @@ _newline(); _out.write("%version 1.0"); _writeFileHeader(); + _writeImports(); _writePrefixes(); _newline(); Collection<Topic> topics = new ArrayList<Topic>(topicMap.getTopics()); + Collection<Association> assocs = new ArrayList<Association>(topicMap.getAssociations()); + TypeInstanceIndex tiIdx = ((IIndexManagerAware) topicMap).getIndexManager().getTypeInstanceIndex(); + if (!tiIdx.isAutoUpdated()) { + tiIdx.reindex(); + } + _createSupertypeSubtypeRelationships(tiIdx, topicMap, assocs); + if (_tmcl) { + _createTMCLTemplates(topicMap, topics, assocs); + } if (topicMap.getReifier() != null) { // Special handling of the tm reifier to avoid an additional // whitespace character in front of the ~ @@ -366,37 +443,16 @@ _writeTopic(reifier, false); topics.remove(reifier); } - TypeInstanceIndex tiIdx = ((IIndexManagerAware) topicMap).getIndexManager().getTypeInstanceIndex(); - if (!tiIdx.isAutoUpdated()) { - tiIdx.reindex(); - } _writeSection("ONTOLOGY"); - _writeOntologySection(tiIdx.getTopicTypes(), topics, "Topic Types"); - Collection<Topic> types = tiIdx.getAssociationTypes(); - final Topic typeInstance = topicMap.getTopicBySubjectIdentifier(TMDM.TYPE_INSTANCE); - if (_omitTopic(typeInstance)) { - types.remove(typeInstance); - topics.remove(typeInstance); - } + Collection<Topic> types = _filter(topicMap, tiIdx.getTopicTypes(), topics, TypeFilter.TOPIC); + _writeOntologySection(types, topics, "Topic Types"); + types = _filter(topicMap, tiIdx.getAssociationTypes(), topics, TypeFilter.ASSOCIATION); _writeOntologySection(types, topics, "Association Types"); - types = tiIdx.getRoleTypes(); - final Topic type = topicMap.getTopicBySubjectIdentifier(TMDM.TYPE); - final Topic instance = topicMap.getTopicBySubjectIdentifier(TMDM.INSTANCE); - if (_omitTopic(type)) { - types.remove(type); - topics.remove(type); - } - if (_omitTopic(instance)) { - types.remove(instance); - topics.remove(instance); - } + types = _filter(topicMap, tiIdx.getRoleTypes(), topics, TypeFilter.ROLE); _writeOntologySection(types, topics, "Role Types"); - _writeOntologySection(tiIdx.getOccurrenceTypes(), topics, "Occurrence Types"); - types = new ArrayList<Topic>(tiIdx.getNameTypes()); - if (_omitTopic(_defaultNameType)) { - types.remove(_defaultNameType); - topics.remove(_defaultNameType); - } + types = _filter(topicMap, tiIdx.getOccurrenceTypes(), topics, TypeFilter.OCCURRENCE); + _writeOntologySection(types, topics, "Occurrence Types"); + types = _filter(topicMap, tiIdx.getNameTypes(), topics, TypeFilter.NAME); _writeOntologySection(types, topics, "Name Types"); tiIdx.close(); ScopedIndex scopeIdx = ((IIndexManagerAware) topicMap).getIndexManager().getScopedIndex(); @@ -412,7 +468,6 @@ _writeSection("INSTANCES"); _writeSection("Topics"); _writeTopics(topics); - Collection<Association> assocs = new ArrayList<Association>(topicMap.getAssociations()); if (!assocs.isEmpty()) { Association[] assocArray = assocs.toArray(new Association[assocs.size()]); _writeSection("Associations"); @@ -426,8 +481,160 @@ _newline(); _out.flush(); _topic2Reference.clear(); + _topic2Supertypes.clear(); + _topic2Templates.clear(); } + private void _createSupertypeSubtypeRelationships(TypeInstanceIndex tiIdx, + TopicMap tm, Collection<Association> assocs) { + final Topic supertypeSubtype = tm.getTopicBySubjectIdentifier(TMDM.SUPERTYPE_SUBTYPE); + final Topic supertype = tm.getTopicBySubjectIdentifier(TMDM.SUPERTYPE); + final Topic subtype = tm.getTopicBySubjectIdentifier(TMDM.SUBTYPE); + if (supertypeSubtype == null || supertype == null || subtype == null) { + return; + } + for (Association assoc: tiIdx.getAssociations(supertypeSubtype)) { + if (!assoc.getScope().isEmpty()) { + continue; + } + if (assoc.getReifier() != null) { + continue; + } + Collection<Role> roles = assoc.getRoles(); + if (roles.size() != 2) { + continue; + } + Topic supertypePlayer = null; + Topic subtypePlayer = null; + for (Role role: roles) { + if (role.getType().equals(supertype)) { + supertypePlayer = role.getPlayer(); + } + else if (role.getType().equals(subtype)) { + subtypePlayer = role.getPlayer(); + } + } + if (supertypePlayer == null || subtypePlayer == null) { + continue; + } + Collection<Topic> supertypes = _topic2Supertypes.get(subtypePlayer); + if (supertypes == null) { + supertypes = new HashSet<Topic>(); + _topic2Supertypes.put(subtypePlayer, supertypes); + } + supertypes.add(supertypePlayer); + assocs.remove(assoc); + } + } + + private void _createTMCLTemplates(TopicMap topicMap, + Collection<Topic> topics, + Collection<Association> assocs) { + ITMCLPreprocessor tmclProcessor = new DefaultTMCLPreprocessor(); + tmclProcessor.process(topicMap, topics, assocs); + _topic2Templates.putAll(tmclProcessor.getTopicToTemplatesMapping()); + } + + private Locator[] _getSubjectIdentifiersToFilter(TypeFilter mode) { + Locator[] toFilter = new Locator[0]; + switch (mode) { + case TOPIC: { + if (_tmcl) { + toFilter = new Locator[] { + TMCL.TOPIC_TYPE, + TMCL.OCCURRENCE_TYPE, + TMCL.ASSOCIATION_TYPE, + TMCL.ROLE_TYPE, + TMCL.NAME_TYPE, + TMCL.SCOPE_TYPE, + TMCL.CONSTRAINT, + // Constraint types + TMCL.TOPIC_TYPE_CONSTRAINT, + TMCL.ASSOCIATION_TYPE_CONSTRAINT, + TMCL.ASSOCIATION_ROLE_TYPE, + TMCL.OCCURRENCE_TYPE_CONSTRAINT, + TMCL.NAME_TYPE_CONSTRAINT, + TMCL.ABSTRACT_TOPIC_TYPE_CONSTRAINT, + TMCL.EXCLUSIVE_INSTANCE, + TMCL.SUBJECT_IDENTIFIER_CONSTRAINT, + TMCL.SUBJECT_LOCATOR_CONSTRAINT, + TMCL.NAME_TYPE, + TMCL.NAME_TYPE_SCOPE_CONSTRAINT, + TMCL.TOPIC_OCCURRENCE_TYPE, + TMCL.ASSOCIATION_TYPE_SCOPE_CONSTRAINT, + TMCL.OCCURRENCE_DATATYPE_CONSTRAINT, + TMCL.TOPIC_OCCURRENCE_CONSTRAINT, + TMCL.ASSOCIATION_ROLE_CONSTRAINT, + TMCL.ASSOCIATION_ROLE_PLAYER, + TMCL.OTHERROLE_CONSTRAINT, + TMCL.UNIQUE_OCCURRENCE_CONSTRAINT, + }; + } + break; + } + case ASSOCIATION: { + toFilter = new Locator[] {TMDM.TYPE_INSTANCE, TMDM.SUPERTYPE_SUBTYPE}; + if (_tmcl) { + toFilter = new Locator[] { + toFilter[0], + toFilter[1], + TMCL.APPLIES_TO + }; + } + break; + } + case ROLE: { + toFilter = new Locator[] {TMDM.TYPE, TMDM.INSTANCE, TMDM.SUPERTYPE, TMDM.SUBTYPE}; + if (_tmcl) { + toFilter = new Locator[] {toFilter[0], toFilter[1], toFilter[2], toFilter[3], + TMCL.TOPIC_TYPE_ROLE, + TMCL.OCCURRENCE_TYPE_ROLE, + TMCL.ASSOCIATION_TYPE_ROLE, + TMCL.ROLE_TYPE_ROLE, + TMCL.OTHERROLE_TYPE_ROLE, + TMCL.NAME_TYPE_ROLE, + TMCL.SCOPE_TYPE_ROLE, + TMCL.CONSTRAINT_ROLE + }; + } + break; + } + case OCCURRENCE: { + if (_tmcl) { + toFilter = new Locator[] { + TMCL.CARD_MIN, + TMCL.CARD_MAX, + TMCL.DATATYPE, + TMCL.REGEXP, + TMCL.VALIDATION_EXPRESSION, + }; + } + break; + } + case NAME: { + toFilter = new Locator[] {TMDM.TOPIC_NAME}; + break; + } + } + return toFilter; + } + + private Collection<Topic> _filter(TopicMap topicMap, Collection<Topic> types, + Collection<Topic> allTopics, TypeFilter mode) { + return _filter(topicMap, types, allTopics, _getSubjectIdentifiersToFilter(mode)); + } + + private Collection<Topic> _filter(TopicMap topicMap, Collection<Topic> topics, Collection<Topic> allTopics, Locator...subjectIdentifiers) { + for (Locator loc: subjectIdentifiers) { + Topic topic = topicMap.getTopicBySubjectIdentifier(loc); + if (_omitTopic(topic)) { + topics.remove(topic); + allTopics.remove(topic); + } + } + return topics; + } + /** * Indicates if the provided <tt>topic</tt> has just one subject identifier * and provides no further properties. @@ -437,14 +644,14 @@ */ private boolean _omitTopic(Topic topic) { return topic != null - && topic.getSubjectIdentifiers().size() == 1 - && topic.getSubjectLocators().isEmpty() - && (!_exportIIDs || topic.getItemIdentifiers().isEmpty()) - && topic.getTypes().isEmpty() - && topic.getNames().isEmpty() - && topic.getOccurrences().isEmpty() - && topic.getRolesPlayed().isEmpty() - && topic.getReified() == null; + && topic.getSubjectIdentifiers().size() == 1 + && topic.getSubjectLocators().isEmpty() + && (!_exportIIDs || topic.getItemIdentifiers().isEmpty()) + && topic.getTypes().isEmpty() + && topic.getNames().isEmpty() + && topic.getOccurrences().isEmpty() + && topic.getRolesPlayed().isEmpty() + && topic.getReified() == null; } /** @@ -501,6 +708,25 @@ } /** + * Writes the registered imports. + * + * @throws IOException In case of an error. + */ + private void _writeImports() throws IOException { + if (_imports.isEmpty()) { + return; + } + _writeSection("Included Topic Maps"); + String[] imports = _imports.toArray(new String[_imports.size()]); + Arrays.sort(imports); + for (String imp: imports) { + _out.write("%include "); + _writeLocator(imp); + _newline(); + } + } + + /** * If <tt>topics</tt> is not empty, the topics will be removed from * <tt>allTopics</tt> and written out under the specified section <tt>title</tt>. * @@ -564,9 +790,13 @@ wantSemicolon = true; } for (Topic supertype: _getSupertypes(topic)) { - this._writeSupertypeSubtype(supertype, wantSemicolon); + _writeSupertypeSubtype(supertype, wantSemicolon); wantSemicolon = true; } + for (ITemplate tpl: _getTemplates(topic)) { + _writeTemplate(tpl, wantSemicolon); + wantSemicolon = true; + } for (Name name: _getNames(topic)) { _writeName((IName) name, wantSemicolon); wantSemicolon = true; @@ -636,7 +866,7 @@ if (iids.isEmpty()) { return _EMPTY_REFERENCE_ARRAY; } - Collection<Reference> refs = new ArrayList<Reference>(); + Collection<Reference> refs = new ArrayList<Reference>(iids.size()); for (Locator iid: iids) { refs.add(Reference.createItemIdentifier(iid)); } @@ -703,25 +933,42 @@ * @return A sorted array of supertypes. */ private Topic[] _getSupertypes(Topic topic) { - //FIXME - return new Topic[0]; -// Set<Topic> supertypes_ = TypeInstanceUtils.getSupertypes(topic); -// Topic[] supertypes = supertypes_.toArray(new Topic[supertypes_.size()]); -// Arrays.sort(supertypes, _topicIdComparator); -// return supertypes; + Collection<Topic> supertypes_ = _topic2Supertypes.get(topic); + if (supertypes_ == null) { + return _EMPTY_TOPIC_ARRAY; + } + Topic[] supertypes = supertypes_.toArray(new Topic[supertypes_.size()]); + Arrays.sort(supertypes, _topicIdComparator); + return supertypes; } /** + * Returns a sorted array of templates for the specified topic. + * + * @param topic The topic to retrieve the templates from. + * @return A sorted array of templates. + */ + private ITemplate[] _getTemplates(Topic topic) { + Collection<ITemplate> templates = _topic2Templates.get(topic); + if (templates == null) { + return _EMPTY_TEMPLATE_ARRAY; + } + ITemplate[] tplArray = templates.toArray(new ITemplate[templates.size()]); + Arrays.sort(tplArray); + return tplArray; + } + + /** * Returns a sorted array of names for the specified topic. * * @param topic The topic to retrieve the names from. * @return A sorted array of names. */ private Name[] _getNames(Topic topic) { - Set<Name> names_ = topic.getNames(); - Name[] names = names_.toArray(new Name[names_.size()]); - Arrays.sort(names, _nameComparator); - return names; + Collection<Name> names = topic.getNames(); + Name[] nameArray = names.toArray(new Name[names.size()]); + Arrays.sort(nameArray, _nameComparator); + return nameArray; } /** @@ -731,10 +978,10 @@ * @return A sorted array of occurrences. */ private Occurrence[] _getOccurrences(Topic topic) { - Set<Occurrence> occs_ = topic.getOccurrences(); - Occurrence[] occs = occs_.toArray(new Occurrence[occs_.size()]); - Arrays.sort(occs, _occComparator); - return occs; + Collection<Occurrence> occs = topic.getOccurrences(); + Occurrence[] occArray = occs.toArray(new Occurrence[occs.size()]); + Arrays.sort(occArray, _occComparator); + return occArray; } /** @@ -764,6 +1011,36 @@ } /** + * Writes a template invocation. + * + * @param tpl The template invocation to write. + * @param wantSemicolon Indicates if a semicolon should be written. + * @throws IOException In case of an error. + */ + private void _writeTemplate(ITemplate tpl, boolean wantSemicolon) throws IOException { + _writeSemicolon(wantSemicolon); + _out.write(tpl.getName()); + _out.write('('); + boolean wantComma = false; + for (Object param: tpl.getParameters()) { + if (wantComma) { + _out.write(", "); + } + if (param instanceof ILiteral) { + _writeLiteral((ILiteral) param); + } + else if (param instanceof Topic) { + _writeTopicRef((Topic) param); + } + else { + _writeTopicRef((Reference) param); + } + wantComma = true; + } + _out.write(')'); + } + + /** * Serializes the specified occurrence. * * @param occ The occurrence to serialize @@ -1111,7 +1388,7 @@ int idx = addr.indexOf('#'); if (idx > 0) { String id = addr.substring(idx+1); - if (_isValidId(id)) { + if (_isValidId(id) && !_isKeyword(id)) { if (_keepAbsoluteIIDs && !addr.startsWith(_baseIRI)) { refs.add(Reference.createItemIdentifier(iid)); } @@ -1146,6 +1423,20 @@ } /** + * Returns if the provided identifier is a CTM keyword. + * + * @param id The id to check. + * @return <tt>true</tt> if <tt>id</tt> is a keyword, otherwise <tt>false</tt>. + */ + private boolean _isKeyword(String id) { + return id.length() == 3 + && ("def".equals(id) + || "end".equals(id) + || "isa".equals(id) + || "ako".equals(id)); + } + + /** * Returns if the provided <tt>id</tt> is a valid CTM topic identifier. * * @param id The id to check. @@ -1179,9 +1470,7 @@ || XSD.INTEGER.equals(datatype) || XSD.DATE.equals(datatype) || XSD.DATE_TIME.equals(datatype) - || (XSD.DOUBLE.equals(datatype) - && ("INF".equals(literal.getValue())) - || "-INF".equals(literal.getValue())); + || XSD.DOUBLE.equals(datatype); } /** @@ -1218,10 +1507,27 @@ LOG.warning("Invalid CTM: '" + msg + "'"); } + static final class Template implements Comparable<Template> { + private final String name; + private final Collection<Object> params; + private Template(String name) { + this.name = name; + this.params = new ArrayList<Object>(); + } + @Override + public int compareTo(Template o) { + int res = name.compareTo(o.name); + if (res == 0) { + res = params.size() - o.params.size(); + } + return res; + } + } + /** * Represents a reference to a topic. */ - static final class Reference implements Comparable<Reference> { + private static final class Reference implements Comparable<Reference> { static final int ID = 0, SID = 1, Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITMCLPreprocessor.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITMCLPreprocessor.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITMCLPreprocessor.java 2009-07-02 14:51:22 UTC (rev 310) @@ -0,0 +1,41 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio.internal.ctm; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +import org.tmapi.core.Association; +import org.tmapi.core.Locator; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface ITMCLPreprocessor { + + public void process(TopicMap topicMap, Collection<Topic> topics, Collection<Association> assocs); + + public Set<Locator> getSuppressableSubjectIdentifiers(); + + public Map<Topic, Collection<ITemplate>> getTopicToTemplatesMapping(); + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITMCLPreprocessor.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITemplate.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITemplate.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITemplate.java 2009-07-02 14:51:22 UTC (rev 310) @@ -0,0 +1,32 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio.internal.ctm; + +import java.util.List; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface ITemplate extends Comparable<ITemplate> { + + public String getName(); + + public List<Object> getParameters(); + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/ITemplate.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java 2009-07-02 14:51:22 UTC (rev 310) @@ -0,0 +1,436 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio.internal.ctm.impl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.logging.Logger; + +import org.tinytim.mio.internal.ctm.ITMCLPreprocessor; +import org.tinytim.mio.internal.ctm.ITemplate; +import org.tinytim.internal.api.IIndexManagerAware; +import org.tinytim.internal.api.ILiteral; +import org.tinytim.internal.api.IOccurrence; +import org.tinytim.voc.TMCL; + +import org.tmapi.core.Association; +import org.tmapi.core.Locator; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.index.TypeInstanceIndex; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class DefaultTMCLPreprocessor implements ITMCLPreprocessor { + + private static final Logger LOG = Logger.getLogger(DefaultTMCLPreprocessor.class.getName()); + + private final Map<Topic, Collection<ITemplate>> _topic2Templates; + + private Topic _topicType; + + private Topic _appliesTo; + + private Topic _constraintRole; + + private Topic _cardMin; + + private Topic _cardMax; + + private Topic _datatype; + + private Topic _regEx; + + private Topic _topicTypeRole; + + private Topic _scopeTypeRole; + + private Topic _assocTypeRole; + + + public DefaultTMCLPreprocessor() { + _topic2Templates = new HashMap<Topic, Collection<ITemplate>>(); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.internal.ctm.ITMCLPreprocessor#getSuppressableSubjectIdentifiers() + */ + @Override + public Set<Locator> getSuppressableSubjectIdentifiers() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.tinytim.mio.internal.ctm.ITMCLPreprocessor#getTopicToTemplatesMapping() + */ + @Override + public Map<Topic, Collection<ITemplate>> getTopicToTemplatesMapping() { + return _topic2Templates; + } + + /* (non-Javadoc) + * @see org.tinytim.mio.internal.ctm.ITMCLPreprocessor#process(org.tmapi.core.TopicMap, java.util.Collection, java.util.Collection) + */ + @Override + public void process(TopicMap topicMap, Collection<Topic> topics, + Collection<Association> assocs) { + _init(topicMap); + TypeInstanceIndex tiIdx = ((IIndexManagerAware) topicMap).getIndexManager().getTypeInstanceIndex(); + if (!tiIdx.isAutoUpdated()) { + tiIdx.reindex(); + } + _processAbstractTopicConstraints(topicMap, tiIdx, topics, assocs); + _processSubjectIdentifierConstraints(topicMap, tiIdx, topics, assocs); + _processSubjectLocatorConstraints(topicMap, tiIdx, topics, assocs); + _processAssociationTypeScopeConstraints(topicMap, tiIdx, topics, assocs); + _processRoleConstraints(topicMap, tiIdx, topics, assocs); + _processPlayerConstraints(topicMap, tiIdx, topics, assocs); + _processOccurrenceConstraints(topicMap, tiIdx, topics, assocs); + _processOccurrenceTypeScopeConstraints(topicMap, tiIdx, topics, assocs); + _processNameConstraints(topicMap, tiIdx, topics, assocs); + _processNameTypeScopeConstraints(topicMap, tiIdx, topics, assocs); + } + + private Collection<Topic> _getConstraintInstances(TopicMap topicMap, TypeInstanceIndex tiIdx, Locator subjectIdentifier) { + final Topic constraintType = topicMap.getTopicBySubjectIdentifier(subjectIdentifier); + if (constraintType == null) { + return Collections.emptySet(); + } + return tiIdx.getTopics(constraintType); + } + + private Collection<Topic> _getTopicTypeRolePlayers(Topic constraint, Collection<Association> assocs) { + return _getPlayers(constraint, _constraintRole, _topicTypeRole, assocs); + } + + private Collection<Topic> _getPlayers(Topic constraint, Topic constraintRoleType, Topic otherRoleType, Collection<Association> assocs) { + Collection<Topic> result = new ArrayList<Topic>(); + for (Role role: constraint.getRolesPlayed(constraintRoleType, _appliesTo)) { + Association assoc = role.getParent(); + if (!_isBinary(assoc)) { + continue; + } + for (Role otherRole: assoc.getRoles(otherRoleType)) { + assocs.remove(assoc); + result.add(otherRole.getPlayer()); + } + } + return result; + } + + private void _processAbstractTopicConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ABSTRACT_TOPIC_TYPE_CONSTRAINT)) { + _processAbstractTopicConstraint(constraint, topics, assocs); + } + } + + private void _processAbstractTopicConstraint(Topic constraint, + Collection<Topic> topics, Collection<Association> assocs) { + ITemplate tpl = new DefaultTemplate("isAbstract"); + Collection<Topic> players = _getTopicTypeRolePlayers(constraint, assocs); + for (Topic player: players) { + _registerTemplate(player, tpl); + } + if (players.size() == constraint.getRolesPlayed().size() + && constraint.getOccurrences().isEmpty() + && constraint.getNames().isEmpty() + && constraint.getTypes().size() == 1 + && constraint.getSubjectLocators().isEmpty() + && constraint.getSubjectIdentifiers().isEmpty()) { + topics.remove(constraint); + } + } + + private void _processSubjectIdentifierConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + _processLocatorConstraints(topicMap, tiIdx, "has-subjectidentifier", TMCL.SUBJECT_IDENTIFIER_CONSTRAINT, topics, assocs); + } + + private void _processSubjectLocatorConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + _processLocatorConstraints(topicMap, tiIdx, "has-subjectlocator", TMCL.SUBJECT_LOCATOR_CONSTRAINT, topics, assocs); + } + + private void _processLocatorConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, String templateName, Locator constraintSID, Collection<Topic> topics, + Collection<Association> assocs) { + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, constraintSID)) { + _processLocatorConstraint(constraint, templateName, constraintSID, topics, assocs); + } + } + + private void _processLocatorConstraint(Topic constraint, + String templateName, Locator constraintSID, Collection<Topic> topics, + Collection<Association> assocs) { + ILiteral cardMin = _getCardMin(constraint); + ILiteral cardMax = _getCardMax(constraint); + ILiteral regEx = _getRegEx(constraint); + //TODO: Default values? + if (cardMin == null || cardMax == null || regEx == null) { + return; + } + DefaultTemplate tpl = new DefaultTemplate(templateName); + tpl.addParameter(cardMin); + tpl.addParameter(cardMax); + tpl.addParameter(regEx); + Collection<Topic> players = _getTopicTypeRolePlayers(constraint, assocs); + for (Topic player: players) { + _registerTemplate(player, tpl); + } + if (players.size() == constraint.getRolesPlayed().size() + && constraint.getOccurrences().size() == 3 + && constraint.getNames().isEmpty() + && constraint.getTypes().size() == 1 + && constraint.getSubjectLocators().isEmpty() + && constraint.getSubjectIdentifiers().isEmpty()) { + topics.remove(constraint); + } + } + + private void _processAssociationTypeScopeConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.ASSOCIATION_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ASSOCIATION_TYPE_SCOPE_CONSTRAINT)) { + _processTypeScopeConstraint(constraint, "has-association-scope", type, topics, assocs); + } + } + + private void _processRoleConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.ROLE_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ASSOCIATION_ROLE_CONSTRAINT)) { + _processRoleConstraint(constraint, type, topics, assocs); + } + } + + //TODO: Merge with {@link #_processTypeScopeConstraint} + private void _processRoleConstraint(Topic constraint, Topic type, Collection<Topic> topics, + Collection<Association> assocs) { + Topic topic = _getRolePlayer(constraint, type, assocs); + ILiteral cardMin = _getCardMin(constraint); + ILiteral cardMax = _getCardMax(constraint); + if (topic == null || cardMin == null || cardMax == null) { + return; + } + DefaultTemplate tpl = new DefaultTemplate("has-role"); + tpl.addParameter(topic); + tpl.addParameter(cardMin); + tpl.addParameter(cardMax); + Collection<Topic> players = _getPlayers(constraint, _constraintRole, _assocTypeRole, assocs); + for (Topic player: players) { + _registerTemplate(player, tpl); + } + if (players.size() * 2 == constraint.getRolesPlayed().size() + && constraint.getOccurrences().size() == 2 + && constraint.getNames().isEmpty() + && constraint.getTypes().size() == 1 + && constraint.getSubjectLocators().isEmpty() + && constraint.getSubjectIdentifiers().isEmpty()) { + topics.remove(constraint); + } + } + + private void _processPlayerConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.ROLE_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.ASSOCIATION_ROLE_CONSTRAINT)) { + _processRoleConstraint(constraint, type, topics, assocs); + } + } + + private void _processOccurrenceConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.OCCURRENCE_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.TOPIC_OCCURRENCE_CONSTRAINT)) { + _processHasTopicChildConstraint(constraint, "has-occurrence", type, topics, assocs); + } + } + + private void _processOccurrenceTypeScopeConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.OCCURRENCE_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.TOPIC_OCCURRENCE_TYPE)) { + _processTypeScopeConstraint(constraint, "has-occurrence-scope", type, topics, assocs); + } + } + + private void _processTypeScopeConstraint(Topic constraint, String templateName, Topic type, + Collection<Topic> topics, Collection<Association> assocs) { + Topic topic = _getRolePlayer(constraint, type, assocs); + ILiteral cardMin = _getCardMin(constraint); + ILiteral cardMax = _getCardMax(constraint); + if (topic == null || cardMin == null || cardMax == null) { + return; + } + DefaultTemplate tpl = new DefaultTemplate(templateName); + tpl.addParameter(topic); + tpl.addParameter(cardMin); + tpl.addParameter(cardMax); + Collection<Topic> players = _getPlayers(constraint, _constraintRole, _scopeTypeRole, assocs); + for (Topic player: players) { + _registerTemplate(player, tpl); + } + if (players.size() * 2 == constraint.getRolesPlayed().size() + && constraint.getOccurrences().size() == 2 + && constraint.getNames().isEmpty() + && constraint.getTypes().size() == 1 + && constraint.getSubjectLocators().isEmpty() + && constraint.getSubjectIdentifiers().isEmpty()) { + topics.remove(constraint); + } + } + + private void _processNameConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.NAME_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.NAME_TYPE)) { + _processHasTopicChildConstraint(constraint, "has-name", type, topics, assocs); + } + } + + private void _processHasTopicChildConstraint(Topic constraint, String templateName, + Topic type, Collection<Topic> topics, Collection<Association> assocs) { + Topic topic = _getRolePlayer(constraint, type, assocs); + ILiteral cardMin = _getCardMin(constraint); + ILiteral cardMax = _getCardMax(constraint); + ILiteral regEx = _getRegEx(constraint); + if (topic == null || cardMin == null || cardMax == null || regEx == null) { + return; + } + DefaultTemplate tpl = new DefaultTemplate(templateName); + tpl.addParameter(topic); + tpl.addParameter(cardMin); + tpl.addParameter(cardMax); + tpl.addParameter(regEx); + Collection<Topic> players = _getTopicTypeRolePlayers(constraint, assocs); + for (Topic player: players) { + _registerTemplate(player, tpl); + } + if (players.size() * 2 == constraint.getRolesPlayed().size() + && constraint.getOccurrences().size() == 3 + && constraint.getNames().isEmpty() + && constraint.getTypes().size() == 1 + && constraint.getSubjectLocators().isEmpty() + && constraint.getSubjectIdentifiers().isEmpty()) { + topics.remove(constraint); + } + } + + private void _processNameTypeScopeConstraints(TopicMap topicMap, + TypeInstanceIndex tiIdx, Collection<Topic> topics, + Collection<Association> assocs) { + final Topic type = topicMap.getTopicBySubjectIdentifier(TMCL.NAME_TYPE_ROLE); + if (type == null) { + return; + } + for (Topic constraint: _getConstraintInstances(topicMap, tiIdx, TMCL.NAME_TYPE_SCOPE_CONSTRAINT)) { + _processTypeScopeConstraint(constraint, "has-name-scope", type, topics, assocs); + } + } + + private Topic _getRolePlayer(Topic constraint, Topic roleType, Collection<Association> assocs) { + Collection<Topic> players = _getPlayers(constraint, _constraintRole, roleType, assocs); + return players.isEmpty() ? null : players.iterator().next(); + } + + private ILiteral _getValue(Topic topic, Topic type) { + if (type == null) { + return null; + } + Collection<Occurrence> occs = topic.getOccurrences(type); + if (occs.size() != 1) { + return null; + } + return ((IOccurrence) occs.iterator().next()).getLiteral(); + } + + private ILiteral _getCardMin(Topic constraint) { + return _getValue(constraint, _cardMin); + } + + private ILiteral _getCardMax(Topic constraint) { + return _getValue(constraint, _cardMax); + } + + private ILiteral _getRegEx(Topic constraint) { + return _getValue(constraint, _regEx); + } + + private boolean _isBinary(Association assoc) { + return assoc.getRoles().size() == 2; + } + + private void _init(TopicMap topicMap) { + _appliesTo = topicMap.getTopicBySubjectIdentifier(TMCL.APPLIES_TO); + _constraintRole = topicMap.getTopicBySubjectIdentifier(TMCL.CONSTRAINT_ROLE); + _cardMin = topicMap.getTopicBySubjectIdentifier(TMCL.CARD_MIN); + _cardMax = topicMap.getTopicBySubjectIdentifier(TMCL.CARD_MAX); + _datatype = topicMap.getTopicBySubjectIdentifier(TMCL.DATATYPE); + _regEx = topicMap.getTopicBySubjectIdentifier(TMCL.REGEXP); + _topicTypeRole = topicMap.getTopicBySubjectIdentifier(TMCL.TOPIC_TYPE_ROLE); + _scopeTypeRole = topicMap.getTopicBySubjectIdentifier(TMCL.SCOPE_TYPE_ROLE); + _assocTypeRole = topicMap.getTopicBySubjectIdentifier(TMCL.ASSOCIATION_TYPE_ROLE); + } + + private void _registerTemplate(Topic topic, ITemplate tpl) { + Collection<ITemplate> templates = _topic2Templates.get(topic); + if (templates == null) { + templates = new ArrayList<ITemplate>(); + _topic2Templates.put(topic, templates); + } + templates.add(tpl); + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTMCLPreprocessor.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java 2009-07-02 14:51:22 UTC (rev 310) @@ -0,0 +1,68 @@ +/* + * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.mio.internal.ctm.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.tinytim.mio.internal.ctm.ITemplate; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class DefaultTemplate implements ITemplate { + + private final String _name; + private List<Object> _params; + + public DefaultTemplate(String name) { + _name = name; + _params = new ArrayList<Object>(); + } + + /* (non-Javadoc) + * @see org.tinytim.mio.internal.ctm.ITemplate#getName() + */ + @Override + public String getName() { + return _name; + } + + /* (non-Javadoc) + * @see org.tinytim.mio.internal.ctm.ITemplate#getParameters() + */ + @Override + public List<Object> getParameters() { + return _params; + } + + public void addParameter(Object param) { + if (param == null) { + throw new IllegalArgumentException("The paramater must not be null"); + } + _params.add(param); + } + + @Override + public int compareTo(ITemplate o) { + // TODO Auto-generated method stub + return 0; + } + +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/internal/ctm/impl/DefaultTemplate.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-02 15:21:03
|
Revision: 312 http://tinytim.svn.sourceforge.net/tinytim/?rev=312&view=rev Author: lheuer Date: 2009-07-02 15:21:01 +0000 (Thu, 02 Jul 2009) Log Message: ----------- SLF4J 1.5.6 -> 1.5.8 Modified Paths: -------------- tinytim-mio/trunk/build.xml Added Paths: ----------- tinytim-mio/trunk/lib/slf4j-api-1.5.8.jar tinytim-mio/trunk/lib/slf4j-jdk14-1.5.8.jar Removed Paths: ------------- tinytim-mio/trunk/lib/slf4j-api-1.5.6.jar tinytim-mio/trunk/lib/slf4j-jdk14-1.5.6.jar Modified: tinytim-mio/trunk/build.xml =================================================================== --- tinytim-mio/trunk/build.xml 2009-07-02 15:07:25 UTC (rev 311) +++ tinytim-mio/trunk/build.xml 2009-07-02 15:21:01 UTC (rev 312) @@ -12,7 +12,7 @@ <property name="lib.tmapi" value="${dir.lib}/tmapi-2.0a2.jar"/> <property name="lib.tinytim" value="${dir.lib}/tinytim-2.0.0a5-snapshot-20090702.jar"/> <property name="lib.tinytim.tests" value="${dir.lib}/tinytim-2.0.0a4-tests.jar"/> - <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.6.jar"/> + <property name="lib.logging" value="${dir.lib}/slf4j-api-1.5.8.jar"/> <property name="lib.mio" value="${dir.lib}/semagia-mio-0.9.4.jar"/> <target name="help"> Deleted: tinytim-mio/trunk/lib/slf4j-api-1.5.6.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/slf4j-api-1.5.8.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/slf4j-api-1.5.8.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: tinytim-mio/trunk/lib/slf4j-jdk14-1.5.6.jar =================================================================== (Binary files differ) Added: tinytim-mio/trunk/lib/slf4j-jdk14-1.5.8.jar =================================================================== (Binary files differ) Property changes on: tinytim-mio/trunk/lib/slf4j-jdk14-1.5.8.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |