You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
(48) |
May
(21) |
Jun
(3) |
Jul
(10) |
Aug
(66) |
Sep
(11) |
Oct
(7) |
Nov
(73) |
Dec
(12) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(3) |
Feb
(17) |
Mar
(19) |
Apr
(1) |
May
(4) |
Jun
|
Jul
(43) |
Aug
(18) |
Sep
(1) |
Oct
(1) |
Nov
(2) |
Dec
|
2010 |
Jan
(3) |
Feb
(7) |
Mar
(21) |
Apr
(2) |
May
(1) |
Jun
(1) |
Jul
(6) |
Aug
(6) |
Sep
(7) |
Oct
|
Nov
(1) |
Dec
|
2011 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <lh...@us...> - 2008-05-24 15:29:38
|
Revision: 69 http://tinytim.svn.sourceforge.net/tinytim/?rev=69&view=rev Author: lheuer Date: 2008-05-24 08:29:21 -0700 (Sat, 24 May 2008) Log Message: ----------- Updated CHANGES.txt Modified Paths: -------------- tinytim-cxtm/trunk/CHANGES.txt Modified: tinytim-cxtm/trunk/CHANGES.txt =================================================================== --- tinytim-cxtm/trunk/CHANGES.txt 2008-05-24 15:27:43 UTC (rev 68) +++ tinytim-cxtm/trunk/CHANGES.txt 2008-05-24 15:29:21 UTC (rev 69) @@ -2,6 +2,11 @@ Changes Log =========== +1.0.0 alpha3 (xx.xx.2008) +------------------------- +* Fixed bug #1971341 (Item identifiers of roles are omitted) + + 1.0.0 alpha2 (16.05.2008) ------------------------- * Adapted the current CXTM draft dtd. 2008-05-15 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-24 15:28:37
|
Revision: 68 http://tinytim.svn.sourceforge.net/tinytim/?rev=68&view=rev Author: lheuer Date: 2008-05-24 08:27:43 -0700 (Sat, 24 May 2008) Log Message: ----------- Fixed bug #1971341 Modified Paths: -------------- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java Modified: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-05-24 15:24:58 UTC (rev 67) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-05-24 15:27:43 UTC (rev 68) @@ -436,6 +436,7 @@ _out.endElement("player"); _out.newline(); _writeType((ITyped) role); + _writeItemIdentifiers(role); _out.endElement("role"); _out.newline(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-24 15:25:13
|
Revision: 67 http://tinytim.svn.sourceforge.net/tinytim/?rev=67&view=rev Author: lheuer Date: 2008-05-24 08:24:58 -0700 (Sat, 24 May 2008) Log Message: ----------- - Replaced the fixed stateStack with a dynamic one to allow more states Modified Paths: -------------- tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java Modified: tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java =================================================================== --- tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java 2008-05-24 08:13:04 UTC (rev 66) +++ tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java 2008-05-24 15:24:58 UTC (rev 67) @@ -44,6 +44,7 @@ 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. @@ -58,14 +59,10 @@ SCOPE, THEME, REIFIER, PLAYER, ISA, TYPE; } - private static final String _XSD_STRING = "http://www.w3.org/2001/XMLSchema#string"; - private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; - private static final Logger LOG = Logger.getLogger(MapInputHandler.class.getName()); private TopicMapImpl _tm; - private State[] _stateStack; - private int _stackPointer; + private List<State> _stateStack; private List<TopicMapObject> _constructStack; public MapInputHandler() { @@ -93,8 +90,7 @@ */ public void startTopicMap() throws MIOException { _constructStack = new ArrayList<TopicMapObject>(); - _stateStack = new State[15]; - _stackPointer = -1; + _stateStack = new ArrayList<State>(); _enterState(State.INITIAL, _tm); } @@ -374,8 +370,8 @@ * @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)) { + 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) { @@ -405,7 +401,7 @@ * @param state The state to push ontop of the state stack. */ private void _enterState(State state) { - _stateStack[++_stackPointer] = state; + _stateStack.add(state); } /** @@ -427,10 +423,10 @@ * @throws MIOException If the state is not equals to the current state. */ private void _leaveState(State state) throws MIOException { - if (!(state == _stateStack[_stackPointer])) { - _reportError("Unexpected state: " + _stateStack[_stackPointer] + ", expected: " + state); + State current = _stateStack.remove(_stateStack.size()-1); + if (state != current) { + _reportError("Unexpected state: " + current + ", expected: " + state); } - --_stackPointer; } /** @@ -469,7 +465,7 @@ * @return The current state. */ private State _state() { - return _stateStack[_stackPointer]; + return _stateStack.get(_stateStack.size()-1); } /** Modified: tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java =================================================================== --- tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java 2008-05-24 08:13:04 UTC (rev 66) +++ tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java 2008-05-24 15:24:58 UTC (rev 67) @@ -75,6 +75,27 @@ } /** + * Tests reifying a topic map. + */ + public void testTMReifier() throws Exception { + String itemIdent = "http://sf.net/projects/tinytim/test#1"; + assertEquals(0, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + _handler.startTopicMap(); + _handler.startReifier(); + _handler.startTopic(Ref.createItemIdentifier(itemIdent)); + _handler.endTopic(); + _handler.endReifier(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + Topic topic = (Topic) _tm.getObjectByItemIdentifier(_tm.createLocator(itemIdent)); + assertNotNull(topic); + assertNotNull(_tm.getReifier()); + assertEquals(topic, _tm.getReifier()); + } + + /** * Tests topic creation with an item identifier. */ public void testTopicIdentityItemIdentifier() throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-24 08:13:03
|
Revision: 66 http://tinytim.svn.sourceforge.net/tinytim/?rev=66&view=rev Author: lheuer Date: 2008-05-24 01:13:04 -0700 (Sat, 24 May 2008) Log Message: ----------- - Updated JavaDoc (setting org.tinytim.Property#XTM10_REIFICATION is NO requirement anymore) Modified Paths: -------------- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java Modified: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-05-16 17:58:24 UTC (rev 65) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-05-24 08:13:04 UTC (rev 66) @@ -85,8 +85,7 @@ * <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 + * {@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> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-16 17:58:35
|
Revision: 65 http://tinytim.svn.sourceforge.net/tinytim/?rev=65&view=rev Author: lheuer Date: 2008-05-16 10:58:24 -0700 (Fri, 16 May 2008) Log Message: ----------- - Adapted Canonicalizer to the latest CXTM draft (15-05-2008) Modified Paths: -------------- tinytim-cxtm/trunk/CHANGES.txt tinytim-cxtm/trunk/build.properties tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java Modified: tinytim-cxtm/trunk/CHANGES.txt =================================================================== --- tinytim-cxtm/trunk/CHANGES.txt 2008-05-08 12:25:57 UTC (rev 64) +++ tinytim-cxtm/trunk/CHANGES.txt 2008-05-16 17:58:24 UTC (rev 65) @@ -2,6 +2,12 @@ Changes Log =========== +1.0.0 alpha2 (16.05.2008) +------------------------- +* Adapted the current CXTM draft dtd. 2008-05-15 + see <http://www.isotopicmaps.org/cxtm/> + + 1.0.0 alpha1 (07.05.2008) ------------------------- -- Initial release +* Initial release Modified: tinytim-cxtm/trunk/build.properties =================================================================== --- tinytim-cxtm/trunk/build.properties 2008-05-08 12:25:57 UTC (rev 64) +++ tinytim-cxtm/trunk/build.properties 2008-05-16 17:58:24 UTC (rev 65) @@ -1,4 +1,4 @@ version=1.0.0 -version_suffix=alpha1-2008-04-14 +version_suffix=alpha2-2008-05-15 debug=off optimize=on Modified: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-05-08 12:25:57 UTC (rev 64) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-05-16 17:58:24 UTC (rev 65) @@ -43,7 +43,6 @@ import org.tinytim.IDatatypeAwareConstruct; import org.tinytim.IReifiable; import org.tinytim.ITyped; -import org.tinytim.TopicImpl; import org.tinytim.TopicMapImpl; import org.tinytim.index.ITypeInstanceIndex; import org.tinytim.voc.TMDM; @@ -80,7 +79,7 @@ * </p> * <p> * <em>CAUTION</em>: This class implements the - * <a href="http://www.isotopicmaps.org/cxtm/2008-04-14/">CXTM draft dtd. 2008-04-14</a>, + * <a href="http://www.isotopicmaps.org/cxtm/">CXTM draft dtd. 2008-05-15</a>, * the output may change in the future. * </p> * <p> @@ -100,9 +99,6 @@ private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; private static final AssociationRole[] _EMPTY_ROLES = new AssociationRole[0]; - private static final Occurrence[] _EMPTY_OCCS = new Occurrence[0]; - private static final TopicName[] _EMPTY_NAMES = new TopicName[0]; - private static final Variant[] _EMPTY_VARIANTS = new Variant[0]; private Topic _type; private Topic _instance; @@ -124,9 +120,6 @@ private Comparator<Locator> _locComparator; private Comparator<Set<Topic>> _scopeComparator; - private Map<Topic, TopicName[]> _topic2Names; - private Map<Topic, Occurrence[]> _topic2Occs; - private Map<TopicName, Variant[]> _name2Variants; private Map<Association, AssociationRole[]> _assoc2Roles; /** @@ -173,9 +166,6 @@ _locator2Norm = new HashMap<String, String>(); _assoc2Roles = new IdentityHashMap<Association, AssociationRole[]>(); _topic2Roles = new IdentityHashMap<Topic, List<AssociationRole>>(); - _topic2Occs = new IdentityHashMap<Topic, Occurrence[]>(); - _topic2Names = new IdentityHashMap<Topic, TopicName[]>(); - _name2Variants = new IdentityHashMap<TopicName, Variant[]>(); ITypeInstanceIndex typeInstanceIndex = ((TopicMapImpl) topicMap).getIndexManager().getTypeInstanceIndex(); if (!typeInstanceIndex.isAutoUpdated()) { typeInstanceIndex.reindex(); @@ -204,9 +194,6 @@ _locator2Norm = null; _assoc2Roles = null; _topic2Roles = null; - _topic2Occs = null; - _topic2Names = null; - _name2Variants = null; } /** @@ -301,28 +288,6 @@ for (int i=0; i < topics.length; i++) { topic = topics[i]; _construct2Id.put(topic, new Integer(i+1)); - Set<Occurrence> occs_ = topic.getOccurrences(); - Occurrence[] occs = occs_.toArray(new Occurrence[occs_.size()]); - Arrays.sort(occs, _occComparator); - _topic2Occs.put(topic, occs); - for (int j=0; j < occs.length; j++) { - _construct2Id.put(occs[j], new Integer(j+1)); - } - Set<TopicName> names_ = topic.getTopicNames(); - TopicName[] names = names_.toArray(new TopicName[names_.size()]); - Arrays.sort(names, _nameComparator); - _topic2Names.put(topic, names); - for (int j=0; j < names.length; j++) { - TopicName name = names[j]; - _construct2Id.put(name, new Integer(j+1)); - Set<Variant> variants_ = name.getVariants(); - Variant[] variants = variants_.toArray(new Variant[variants_.size()]); - Arrays.sort(variants, _variantComparator); - _name2Variants.put(name, variants); - for (int k=0; k < variants.length; k++) { - _construct2Id.put(variants[k], new Integer(k+1)); - } - } } Arrays.sort(assocs, _assocComparator); Association assoc = null; @@ -356,9 +321,12 @@ * @param topic The topic to retrieve the names from. * @return A (maybe empty) sorted array of names. */ + @SuppressWarnings("unchecked") private TopicName[] _getNames(Topic topic) { - TopicName[] names = _topic2Names.get(topic); - return names != null ? names : _EMPTY_NAMES; + Set<TopicName> names_ = topic.getTopicNames(); + TopicName[] names = names_.toArray(new TopicName[names_.size()]); + Arrays.sort(names, _nameComparator); + return names; } /** @@ -367,9 +335,12 @@ * @param name The name to retrieve the variants from. * @return A (maybe empty) sorted array of variants. */ + @SuppressWarnings("unchecked") private Variant[] _getVariants(TopicName name) { - Variant[] variants = _name2Variants.get(name); - return variants != null ? variants : _EMPTY_VARIANTS; + Set<Variant> variants_ = name.getVariants(); + Variant[] variants = variants_.toArray(new Variant[variants_.size()]); + Arrays.sort(variants, _variantComparator); + return variants; } /** @@ -378,9 +349,12 @@ * @param topic The topic to retrieve the occurrences from. * @return A (maybe emtpy) sorted array of occurrences. */ + @SuppressWarnings("unchecked") private Occurrence[] _getOccurrences(Topic topic) { - Occurrence[] occs = _topic2Occs.get(topic); - return occs != null ? occs : _EMPTY_OCCS; + Set<Occurrence> occs_ = topic.getOccurrences(); + Occurrence[] occs = occs_.toArray(new Occurrence[occs_.size()]); + Arrays.sort(occs, _occComparator); + return occs; } /** @@ -393,8 +367,8 @@ * @param tmo The Topic Maps construct to return the index of. * @return The index of the Topic Maps construct. */ - private String _indexOf(TopicMapObject tmo) { - return _construct2Id.get(tmo).toString(); + private int _indexOf(TopicMapObject tmo) { + return _construct2Id.get(tmo).intValue(); } /** @@ -406,18 +380,19 @@ @SuppressWarnings("unchecked") private void _writeTopic(Topic topic) throws IOException { AttributesImpl attrs = new AttributesImpl(); - _addReified(attrs, topic); - attrs.addAttribute("", "number", null, null, _indexOf(topic)); + attrs.addAttribute("", "number", null, null, "" +_indexOf(topic)); _out.startElement("topic", attrs); _out.newline(); _writeLocatorSet("subjectIdentifiers", topic.getSubjectIdentifiers()); _writeLocatorSet("subjectLocators", topic.getSubjectLocators()); _writeItemIdentifiers(topic); - for (TopicName name: _getNames(topic)) { - _writeName(name); + TopicName[] names = _getNames(topic); + for (int i=0; i < names.length; i++) { + _writeName(names[i], i+1); } - for (Occurrence occ: _getOccurrences(topic)) { - _writeOccurrence(occ); + 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); @@ -452,11 +427,11 @@ */ @SuppressWarnings("unchecked") private void _writeAssociation(Association assoc) throws IOException { - _out.startElement("association", _attributes(assoc)); + _out.startElement("association", _attributes(assoc, _indexOf(assoc))); _out.newline(); _writeType((ITyped) assoc); for (AssociationRole role: _getRoles(assoc)) { - _out.startElement("role", _attributes(role)); + _out.startElement("role", _attributes(role, _indexOf(role))); _out.newline(); _out.startElement("player", _topicRef(role.getPlayer())); _out.endElement("player"); @@ -477,8 +452,8 @@ * @param occ The occurrence to serialize. * @throws IOException If an error occurs. */ - private void _writeOccurrence(Occurrence occ) throws IOException { - _out.startElement("occurrence", _attributes(occ)); + private void _writeOccurrence(Occurrence occ, int pos) throws IOException { + _out.startElement("occurrence", _attributes(occ, pos)); _out.newline(); _writeDatatyped((IDatatypeAwareConstruct) occ); _writeType((ITyped) occ); @@ -497,6 +472,7 @@ 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); } @@ -516,8 +492,8 @@ * @param name The name to serialize. * @throws IOException If an error occurs. */ - private void _writeName(TopicName name) throws IOException { - _out.startElement("topicName", _attributes(name)); + private void _writeName(TopicName name, int pos) throws IOException { + _out.startElement("name", _attributes(name, pos)); _out.newline(); _out.startElement("value"); _out.characters(name.getValue()); @@ -525,8 +501,11 @@ _out.newline(); _writeType((ITyped) name); _writeScope(name); - for (Variant variant: _getVariants(name)) { - _out.startElement("variant", _attributes(variant)); + 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); @@ -535,7 +514,7 @@ _out.newline(); } _writeItemIdentifiers(name); - _out.endElement("topicName"); + _out.endElement("name"); _out.newline(); } @@ -626,6 +605,7 @@ 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]); } @@ -645,7 +625,7 @@ return CXTMWriter.EMPTY_ATTRS; } AttributesImpl attrs = new AttributesImpl(); - attrs.addAttribute("", "topicref", null, null, _indexOf(topic)); + attrs.addAttribute("", "topicref", null, null, ""+_indexOf(topic)); return attrs; } @@ -657,10 +637,10 @@ * @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) { + private Attributes _attributes(TopicMapObject reifiable, int i) { AttributesImpl attrs = new AttributesImpl(); _addReifier(attrs, (IReifiable)reifiable); - attrs.addAttribute("", "number", null, null, _indexOf(reifiable)); + attrs.addAttribute("", "number", null, null, "" + i); return attrs; } @@ -675,65 +655,11 @@ private void _addReifier(AttributesImpl attrs, IReifiable reifiable) { Topic reifier = reifiable.getReifier(); if (reifier != null) { - attrs.addAttribute("", "reifier", null, null, _indexOf(reifier)); + attrs.addAttribute("", "reifier", null, null, "" + _indexOf(reifier)); } } /** - * Adds a reference to the Topic Maps construct which is reified by the - * provided topic. - * - * If the topic reifies no Topic Maps construct, the attributes are not - * modified. - * - * @param attrs The attributes to add the reference to. - * @param topic The topic. - */ - private void _addReified(AttributesImpl attrs, Topic topic) { - if (topic instanceof TypeInstanceTopic) { - return; - } - IReifiable reifiable = ((TopicImpl) topic).getReifiedConstruct(); - if (reifiable == null) { - return; - } - StringBuilder sb = new StringBuilder(); - if (reifiable instanceof TopicMap) { - sb.append("topicMap"); - } - else if (reifiable instanceof Association) { - sb.append("association.") - .append(_indexOf(reifiable)); - } - else if (reifiable instanceof AssociationRole) { - sb.append("association.") - .append(_indexOf(reifiable.getParent())) - .append(".role.") - .append(_indexOf(reifiable)); - } - else { - sb.append("topic."); - final IConstruct parent = reifiable.getParent(); - if (reifiable instanceof Occurrence) { - sb.append(_indexOf(parent)) - .append(".occurrence."); - } - else if (reifiable instanceof TopicName) { - sb.append(_indexOf(parent)) - .append(".name."); - } - else if (reifiable instanceof Variant) { - sb.append(_indexOf(parent.getParent())) - .append(".name.") - .append(_indexOf(parent)) - .append(".variant."); - } - sb.append(_indexOf(reifiable)); - } - attrs.addAttribute("", "reifier", null, null, sb.toString()); - } - - /** * Normalizes the locator according to CXTM 3.19. * * @param locator The locator to normalize. @@ -965,6 +891,9 @@ private final class RoleComparator extends RoleIgnoreParentComparator { public int compare(AssociationRole o1, AssociationRole o2) { + if (o1 == o2) { + return 0; + } int res = super.compare(o1, o2); if (res == 0) { res = _assocComparator.compare(o1.getAssociation(), o2.getAssociation()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-08 12:25:57
|
Revision: 64 http://tinytim.svn.sourceforge.net/tinytim/?rev=64&view=rev Author: lheuer Date: 2008-05-08 05:25:57 -0700 (Thu, 08 May 2008) Log Message: ----------- - Initial import of the build.xml & co Added Paths: ----------- tinytim-io/trunk/CHANGES.txt tinytim-io/trunk/LICENSE.txt tinytim-io/trunk/README.txt tinytim-io/trunk/build.properties tinytim-io/trunk/build.xml Added: tinytim-io/trunk/CHANGES.txt =================================================================== --- tinytim-io/trunk/CHANGES.txt (rev 0) +++ tinytim-io/trunk/CHANGES.txt 2008-05-08 12:25:57 UTC (rev 64) @@ -0,0 +1,8 @@ +=========== +Changes Log +=========== + + +1.0.0 alpha1 (08.05.2008) +------------------------- +- Initial tinyTiM I/O release Added: tinytim-io/trunk/LICENSE.txt =================================================================== --- tinytim-io/trunk/LICENSE.txt (rev 0) +++ tinytim-io/trunk/LICENSE.txt 2008-05-08 12:25:57 UTC (rev 64) @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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-io/trunk/README.txt =================================================================== --- tinytim-io/trunk/README.txt (rev 0) +++ tinytim-io/trunk/README.txt 2008-05-08 12:25:57 UTC (rev 64) @@ -0,0 +1,50 @@ +==================================== +tinyTiM - The tiny Topic Maps engine +==================================== + +What is tinyTiM I/O? +-------------------- +tinyTiM is a tiny Topic Maps engine which keeps topic maps in-memory. +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 +on Semagia MIO which provides a streaming Topic Maps API implementation. + +Note: Semagia MIO uses another license than tinyTiM, see +``LICENSE.semagia-mio.txt`` for details. + + + +Installation +------------ +Put the ``tinytim-io-<VERSION>.jar`` together with the ``tinytim-<VERSION>.jar``, +and ``tmapi-1_0SP1.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; +see <http://www.slf4j.org/> for details. The distribution comes with a logger +which uses the JDK 1.4 ``java.util.logging`` implementation. + + +Latest Version +-------------- +Visit tinyTiM's homepage <http://sourceforge.net/projects/tinytim> for the +latest version. + + +Mailing list +------------ +The mailing list for tinyTiM is located here +<http://sourceforge.net/mailarchive/forum.php?forum_name=tinytim-discuss>. +Feel free to ask any question about tinyTiM. :) + + +License +------- +tinyTiM is licensed under the GNU Lesser General Public License (LGPL) +Version 2.1, see LICENSE.txt for details. Added: tinytim-io/trunk/build.properties =================================================================== --- tinytim-io/trunk/build.properties (rev 0) +++ tinytim-io/trunk/build.properties 2008-05-08 12:25:57 UTC (rev 64) @@ -0,0 +1,4 @@ +version=1.0.0 +version_suffix=alpha1 +debug=off +optimize=on Added: tinytim-io/trunk/build.xml =================================================================== --- tinytim-io/trunk/build.xml (rev 0) +++ tinytim-io/trunk/build.xml 2008-05-08 12:25:57 UTC (rev 64) @@ -0,0 +1,214 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ==================================================================== + This is tinyTiM, a tiny Topic Maps engine. + + 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. + ==================================================================== + + $Rev:$ - $Date:$ +--> +<project name="tinyTiM" default="jar" basedir="."> + <property file="build.properties"/> + + <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.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"/> + + <target name="help"> + <echo message="------------------------"/> + <echo message="tinyTiM I/O - 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}"/> + <property name="dist.name" value="tinytim-io-${dist.version}"/> + + <property name="tinytim-io.jar" value="${dist.name}.jar"/> + <property name="tinytim-io.tar" value="${dist.name}.tar"/> + <property name="tinytim-io.tar.gz" value="${tinytim-io.tar}.gz"/> + <property name="tinytim-io.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="true" + use="true" + splitindex="true" + noindex="false" + windowtitle="tinyTiM I/O API v${dist.version}" + doctitle="tinyTiM API I/O v${dist.version}"> + <fileset dir="${dir.src}"> + <exclude name="**/MapInputHandler.*"/> + </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"> + <javac destdir="${dir.build.classes}" + debug="${debug}" + target="1.5"> + <classpath> + <pathelement location="${lib.tmapi}"/> + <pathelement location="${lib.tinytim}"/> + <pathelement location="${lib.mio}"/> + <pathelement location="${lib.log.api}"/> + <pathelement location="${lib.log}"/> + </classpath> + <src path="${dir.src}"/> + </javac> + </target> + + <!-- =================================================================== --> + <!-- Creates the jar --> + <!-- =================================================================== --> + <target name="jar" depends="compile"> + <jar destfile="${dir.build}/${tinytim-io.jar}"> + <fileset dir="${dir.build.classes}"> + <include name="**/*.*"/> + </fileset> + <manifest> + <attribute name="Implementation-Title" value="tinyTiM I/O"/> + <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-io.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="**/tinytim-*"/> + <exclude name="**/tmapi-*"/> + </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-io.tar}" + basedir="${dir.dist.root}"/> + <gzip src="${dir.dist.root}/${tinytim-io.tar}" + destfile="${dir.build}/${tinytim-io.tar.gz}" /> + <delete file="${dir.dist.root}/${tinytim-io.tar}" /> + <zip destfile="${dir.build}/${tinytim-io.zip}" basedir="${dir.dist.root}"/> + </target> +</project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-08 12:11:30
|
Revision: 63 http://tinytim.svn.sourceforge.net/tinytim/?rev=63&view=rev Author: lheuer Date: 2008-05-08 05:11:31 -0700 (Thu, 08 May 2008) Log Message: ----------- - Moved .mio into .io Added Paths: ----------- tinytim-io/trunk/src/main/java/org/tinytim/io/ tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java tinytim-io/trunk/src/main/java/org/tinytim/io/TopicMapImporter.java tinytim-io/trunk/src/test/java/org/tinytim/io/ tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java Removed Paths: ------------- tinytim-io/trunk/src/main/java/org/tinytim/mio/ tinytim-io/trunk/src/test/java/org/tinytim/mio/ Added: tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java =================================================================== --- tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java (rev 0) +++ tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java 2008-05-08 12:11:31 UTC (rev 63) @@ -0,0 +1,601 @@ +/* + * 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.io; + +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; + +/** + * {@link com.semagia.mio.IMapHandler} implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public class MapInputHandler implements IMapHandler { + + private enum State { + INITIAL, TOPIC, ASSOCIATION, ROLE, OCCURRENCE, NAME, VARIANT, + SCOPE, THEME, REIFIER, PLAYER, ISA, TYPE; + } + + private static final String _XSD_STRING = "http://www.w3.org/2001/XMLSchema#string"; + private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; + + private static final Logger LOG = Logger.getLogger(MapInputHandler.class.getName()); + + private TopicMapImpl _tm; + private State[] _stateStack; + private int _stackPointer; + private List<TopicMapObject> _constructStack; + + public MapInputHandler() { + } + + public MapInputHandler(TopicMap topicMap) { + this(); + setTopicMap(topicMap); + } + + /** + * Sets the topic map instance to operate on. + * + * @param topicMap The topic map. + */ + public void setTopicMap(TopicMap topicMap) { + if (topicMap == null) { + throw new IllegalArgumentException("The topic map must not be null"); + } + _tm = (TopicMapImpl) topicMap; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startTopicMap() + */ + public void startTopicMap() throws MIOException { + _constructStack = new ArrayList<TopicMapObject>(); + _stateStack = new State[15]; + _stackPointer = -1; + _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 = _peekTopic(); + _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) _peekConstruct(); + _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) _peekConstruct(); + _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[++_stackPointer] = 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 { + if (!(state == _stateStack[_stackPointer])) { + _reportError("Unexpected state: " + _stateStack[_stackPointer] + ", expected: " + state); + } + --_stackPointer; + } + + /** + * 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 void _leaveStatePopConstruct(State state) throws MIOException { + _leaveState(state); + _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[_stackPointer]; + } + + /** + * 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 <code>source</code> topic with the <code>target</code>. + * + * Further, this method ensures that the construct stack stays valid: If + * the <code>source</code> is part of the stack, it is replaced with + * <code>target</code>. + * + * @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); + } + +} Property changes on: tinytim-io/trunk/src/main/java/org/tinytim/io/MapInputHandler.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim-io/trunk/src/main/java/org/tinytim/io/TopicMapImporter.java =================================================================== --- tinytim-io/trunk/src/main/java/org/tinytim/io/TopicMapImporter.java (rev 0) +++ tinytim-io/trunk/src/main/java/org/tinytim/io/TopicMapImporter.java 2008-05-08 12:11:31 UTC (rev 63) @@ -0,0 +1,222 @@ +/* + * 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.io; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.tmapi.core.TMAPIRuntimeException; +import org.tmapi.core.TopicMap; + +import org.xml.sax.InputSource; + +import com.semagia.mio.DeserializerRegistry; +import com.semagia.mio.IDeserializer; +import com.semagia.mio.MIOException; +import com.semagia.mio.Syntax; + +/** + * Functions to import serialized topic maps. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class TopicMapImporter { + + private TopicMapImporter() { + // noop. + } + + /** + * Reads a XML topic map from <code>input</code> and adds the content to the + * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * resolve IRIs against. + * + * @param topicMap The topic map instance which receives the + * Topic Maps constructs. + * @param docIRI The IRI which is used to resolve IRIs against. + * @param input The stream to read the serialized topic map from. + * @throws IOException If an error occurs. + */ + public static void importInto(TopicMap topicMap, String docIRI, InputStream input) throws IOException { + _import(Syntax.XTM, topicMap, docIRI, input); + } + + /** + * Reads a XML topic map from <code>input</code> and adds the content to the + * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * resolve IRIs against. + * + * @param topicMap The topic map instance which receives the + * Topic Maps constructs. + * @param docIRI The IRI which is used to resolve IRIs against. + * @param input The source to read the serialized topic map from. + * @throws IOException If an error occurs. + */ + public static void importInto(TopicMap topicMap, String docIRI, InputSource input) throws IOException { + _import(Syntax.XTM, topicMap, docIRI, input); + } + + /** + * Reads a topic map from <code>file</code> and adds the content to the + * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * resolve IRIs against. + * + * The syntax of the serialized topic map is guessed by the file name. If + * the file extension gives no indication of the used syntax, XTM is + * assumed. + * + * @param topicMap The topic map instance which receives the + * Topic Maps constructs. + * @param docIRI The IRI which is used to resolve IRIs against. + * @param file The file to read the serialized topic map from. + * @throws IOException If an error occurs. + */ + public static void importInto(TopicMap topicMap, String docIRI, File file) throws IOException { + _import(_guessSyntax(file), topicMap, docIRI, new FileInputStream(file)); + } + + /** + * Reads a topic map from <code>file</code> and adds the content to the + * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * resolve IRIs against. + * + * The <code>syntax</code> is a string with the abbreviated Topic Maps syntax + * name; i.e. "xtm", "ltm", "ctm". The name is matched case-insensitve, that + * means "xtm" is the same as "xTm", "XTM" etc. + * + * @param topicMap The topic map instance which receives the + * Topic Maps constructs. + * @param docIRI The IRI which is used to resolve IRIs against. + * @param file The file to read the serialized topic map from. + * @param syntax The name of the syntax of the encoded topic map. I.e. "xtm". + * @throws IOException If an error occurs. + */ + public static void importInto(TopicMap topicMap, String docIRI, File file, String syntax) throws IOException { + importInto(topicMap, docIRI, new FileInputStream(file), syntax); + } + + /** + * Reads a topic map from <code>input</code> and adds the content to the + * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * resolve IRIs against. + * + * The <code>syntax</code> is a string with the abbreviated Topic Maps syntax + * name; i.e. "xtm", "ltm", "ctm". The name is matched case-insensitve, that + * means "xtm" is the same as "xTm", "XTM" etc. + * + * @param topicMap The topic map instance which receives the + * Topic Maps constructs. + * @param docIRI The IRI which is used to resolve IRIs against. + * @param input The stream to read the serialized topic map from. + * @param syntax The name of the syntax of the encoded topic map. I.e. "xtm". + * @throws IOException If an error occurs. + */ + public static void importInto(TopicMap topicMap, String docIRI, InputStream input, String syntax) throws IOException { + importInto(topicMap, docIRI, new InputSource(input), syntax); + } + + /** + * Reads a topic map from <code>input</code> and adds the content to the + * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * resolve IRIs against. + * + * The <code>syntax</code> is a string with the abbreviated Topic Maps syntax + * name; i.e. "xtm", "ltm", "ctm". The name is matched case-insensitve, that + * means "xtm" is the same as "xTm", "XTM" etc. + * + * @param topicMap The topic map instance which receives the + * Topic Maps constructs. + * @param docIRI The IRI which is used to resolve IRIs against. + * @param input The source to read the serialized topic map from. + * @param syntax The name of the syntax of the encoded topic map. I.e. "xtm". + * @throws IOException If an error occurs. + */ + public static void importInto(TopicMap topicMap, String docIRI, InputSource input, String syntax) throws IOException { + Syntax syntax_ = Syntax.valueOf(syntax); + if (syntax_ == null) { + throw new RuntimeException("The syntax '" + syntax + "' is unknown"); + } + _import(syntax_, topicMap, docIRI, input); + } + + /** + * Returns a {@link Syntax} instance. + * + * @param file The file to guess the syntax from. + * @return A syntax which matches the file extension or {@link Syntax#XTM} + * if the file extension is not available or gives no indication + * about the used syntax. + */ + private static Syntax _guessSyntax(File file) { + String name = file.getName(); + int i = name.lastIndexOf('.'); + return i == -1 ? Syntax.XTM + : Syntax.forFileExtension(name.substring(i+1), Syntax.XTM); + } + + /** + * Reads a topic map from <code>input</code> and adds the content to the + * <code>topicMap</code>. + * + * @param syntax A syntax instance. + * @param topicMap A topic map instance. + * @param docIRI The IRI which is used to resolve locators against. + * @param input The source to read the topic map from. + * @throws IOException If an error occurs. + */ + private static void _import(Syntax syntax, TopicMap topicMap, String docIRI, + InputStream input) throws IOException { + _import(syntax, topicMap, docIRI, new InputSource(input)); + } + + /** + * Reads a topic map from <code>input</code> and adds the content to the + * <code>topicMap</code>. + * + * @param syntax A syntax instance. + * @param topicMap A topic map instance. + * @param docIRI The IRI which is used to resolve locators against. + * @param input The source to read the topic map from. + * @throws IOException If an error occurs. + */ + private static void _import(Syntax syntax, TopicMap topicMap, String docIRI, + InputSource input) throws IOException { + IDeserializer deser = DeserializerRegistry.createDeserializer(syntax); + if (deser == null) { + throw new IOException("No deserializer found for the syntax '" + syntax.getName() + "'"); + } + deser.setMapHandler(new MapInputHandler(topicMap)); + try { + deser.parse(input, docIRI); + } + catch (MIOException ex) { + if (ex.getException() instanceof IOException) { + throw (IOException) ex.getException(); + } + else { + throw new TMAPIRuntimeException(ex); + } + } + } +} Property changes on: tinytim-io/trunk/src/main/java/org/tinytim/io/TopicMapImporter.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java =================================================================== --- tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java (rev 0) +++ tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java 2008-05-08 12:11:31 UTC (rev 63) @@ -0,0 +1,311 @@ +/* + * 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.io; + +import org.tinytim.Property; +import org.tinytim.TopicMapImpl; +import org.tinytim.voc.TMDM; +import org.tmapi.core.Locator; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMapSystem; +import org.tmapi.core.TopicMapSystemFactory; +import org.tmapi.core.TopicName; + +import com.semagia.mio.MIOException; +import com.semagia.mio.helpers.Ref; + +import junit.framework.TestCase; + +/** + * Tests against the {@link org.tinytim.io.MapInputHandler}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public class TestMapInputHandler extends TestCase { + + private static final String _XSD_STRING = "http://www.w3.org/2001/XMLSchema#string"; + private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; + + private TopicMapImpl _tm; + private MapInputHandler _handler; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + TopicMapSystemFactory tmSysFactory = TopicMapSystemFactory.newInstance(); + tmSysFactory.setProperty(Property.XTM10_REIFICATION, "false"); + TopicMapSystem tmSys = tmSysFactory.newTopicMapSystem(); + _tm = (TopicMapImpl) tmSys.createTopicMap("http://sf.net/projects/tinytim/test"); + _handler = new MapInputHandler(); + _handler.setTopicMap(_tm); + } + + /** + * Simple startTopicMap, followed by an endTopicMap event. + */ + public void testEmpty() throws Exception { + assertEquals(0, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + _handler.startTopicMap(); + _handler.endTopicMap(); + assertEquals(0, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + } + + /** + * Tests topic creation with an item identifier. + */ + public void testTopicIdentityItemIdentifier() throws Exception { + String itemIdent = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createItemIdentifier(itemIdent)); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = (Topic) _tm.getObjectByItemIdentifier(_tm.createLocator(itemIdent)); + assertNotNull(topic); + } + + /** + * Tests topic creation with a subject identifier. + */ + public void testTopicIdentitySubjectIdentifier() throws Exception { + String subjIdent = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(subjIdent)); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(subjIdent)); + assertNotNull(topic); + } + + /** + * Tests topic creation with a subject locator. + */ + public void testTopicIdentitySubjectLocator() throws Exception { + String subjLoc = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectLocator(subjLoc)); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = _tm.getTopicBySubjectLocator(_tm.createLocator(subjLoc)); + assertNotNull(topic); + } + + /** + * Tests transparent merging. + */ + public void testTopicMerging() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String itemIdent = "http://example.org/1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + // Topic in topic event + _handler.startTopic(Ref.createItemIdentifier(itemIdent)); + _handler.itemIdentifier(ref); + _handler.endTopic(); + _handler.startOccurrence(); + _handler.value("tinyTiM", _XSD_STRING); + _handler.endOccurrence(); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + assertEquals(topic, _tm.getObjectByItemIdentifier(_tm.createLocator(ref))); + assertEquals(topic, _tm.getObjectByItemIdentifier(_tm.createLocator(itemIdent))); + assertEquals(1, topic.getOccurrences().size()); + Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); + assertEquals("tinyTiM", occ.getValue()); + } + + /** + * Tests assigning identities to a topic. + */ + public void testTopicIdentities1() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.itemIdentifier(ref); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Locator loc = _tm.createLocator(ref); + Topic topic = _tm.getTopicBySubjectIdentifier(loc); + assertNotNull(topic); + assertEquals(topic, _tm.getObjectByItemIdentifier(loc)); + } + + /** + * Tests assigning identities to a topic. + */ + public void testTopicIdentities2() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createItemIdentifier(ref)); + _handler.subjectIdentifier(ref); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Locator loc = _tm.createLocator(ref); + Topic topic = _tm.getTopicBySubjectIdentifier(loc); + assertNotNull(topic); + assertEquals(topic, _tm.getObjectByItemIdentifier(loc)); + } + + /** + * Tests reifying the topic map. + */ + public void testTopicMapReifier() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startReifier(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.endTopic(); + _handler.endReifier(); + _handler.endTopicMap(); + assertNotNull(_tm.getReifier()); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + assertEquals(topic, _tm.getReifier()); + } + + /** + * Tests occurrence creation with a value of datatype xsd:string. + */ + public void testOccurrenceValueString() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startOccurrence(); + _handler.value(val, _XSD_STRING); + _handler.endOccurrence(); + _handler.endTopic(); + _handler.endTopicMap(); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); + assertEquals(val, occ.getValue()); + } + + /** + * Tests occurrence creation with a value of datatype xsd:anyURI. + */ + public void testOccurrenceValueURI() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "http://sf.net/projects/tinytim"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startOccurrence(); + _handler.value(val, _XSD_ANY_URI); + _handler.endOccurrence(); + _handler.endTopic(); + _handler.endTopicMap(); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); + assertNull(occ.getValue()); + assertEquals(val, occ.getResource().getReference()); + } + + /** + * Tests if the name type is automatically set. + */ + public void testDefaultNameType() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startName(); + _handler.value(val); + _handler.endName(); + _handler.endTopic(); + _handler.endTopicMap(); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + TopicName name = (TopicName) topic.getTopicNames().iterator().next(); + assertEquals(val, name.getValue()); + assertNotNull(name.getType()); + assertTrue(name.getType().getSubjectIdentifiers().contains(TMDM.TOPIC_NAME)); + } + + /** + * Tests if a variant with no scope is reported as error. + */ + public void testVariantNoScopeError() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startName(); + _handler.value(val); + _handler.startVariant(); + _handler.value(val, _XSD_STRING); + try { + _handler.endVariant(); + fail("A variant with no scope shouldn't be allowed"); + } + catch (MIOException ex) { + // noop. + } + } + + /** + * Tests if a variant with a scope equals to the parent's scope is rejected. + */ + public void testVariantNoScopeError2() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String theme = "http://sf.net/projects/tinytim/test#theme"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startName(); + _handler.startScope(); + _handler.startTheme(); + _handler.topicRef(Ref.createItemIdentifier(theme)); + _handler.endTheme(); + _handler.endScope(); + _handler.value(val); + + _handler.startVariant(); + _handler.value(val, _XSD_STRING); + _handler.startScope(); + _handler.startTheme(); + _handler.topicRef(Ref.createItemIdentifier(theme)); + _handler.endTheme(); + _handler.endScope(); + try { + _handler.endVariant(); + fail("A variant with a scope equals to the parent's scope shouldn't be allowed"); + } + catch (MIOException ex) { + // noop. + } + } + +} Property changes on: tinytim-io/trunk/src/test/java/org/tinytim/io/TestMapInputHandler.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-08 12:00:17
|
Revision: 62 http://tinytim.svn.sourceforge.net/tinytim/?rev=62&view=rev Author: lheuer Date: 2008-05-08 05:00:19 -0700 (Thu, 08 May 2008) Log Message: ----------- - Initial lib import Added Paths: ----------- tinytim-io/trunk/lib/ tinytim-io/trunk/lib/LICENSE.semagia-mio.txt tinytim-io/trunk/lib/LICENSE.slf4j.txt tinytim-io/trunk/lib/junit-4.4.jar tinytim-io/trunk/lib/semagia-mio-0.9.0.jar tinytim-io/trunk/lib/semagia-mio-xtm-0.9.0.jar tinytim-io/trunk/lib/slf4j-api-1.5.0.jar tinytim-io/trunk/lib/slf4j-jdk14-1.5.0.jar Added: tinytim-io/trunk/lib/LICENSE.semagia-mio.txt =================================================================== --- tinytim-io/trunk/lib/LICENSE.semagia-mio.txt (rev 0) +++ tinytim-io/trunk/lib/LICENSE.semagia-mio.txt 2008-05-08 12:00:19 UTC (rev 62) @@ -0,0 +1,33 @@ + + Copyright (c) 2007 - 2008 Semagia (http://www.semagia.com/). All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. 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. + 3. Redistributions in any form must be accompanied by information on + how to obtain complete source code for the software and any + accompanying software that uses the software. The source code + must either be included in the distribution or be available for no + more than the cost of distribution plus a nominal fee, and must be + freely redistributable under reasonable conditions. For an + executable file, complete source code means the source code for all + modules it contains. It does not include source code for modules or + files that typically accompany the major components of the operating + system on which the executable file runs. + + THIS SOFTWARE IS PROVIDED BY SEMAGIA ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR + NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL SEMAGIA + 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. Added: tinytim-io/trunk/lib/LICENSE.slf4j.txt =================================================================== --- tinytim-io/trunk/lib/LICENSE.slf4j.txt (rev 0) +++ tinytim-io/trunk/lib/LICENSE.slf4j.txt 2008-05-08 12:00:19 UTC (rev 62) @@ -0,0 +1,24 @@ +Copyright (c) 2004-2007 QOS.ch +All rights reserved. + +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 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. + + + Added: tinytim-io/trunk/lib/junit-4.4.jar =================================================================== (Binary files differ) Property changes on: tinytim-io/trunk/lib/junit-4.4.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: tinytim-io/trunk/lib/semagia-mio-0.9.0.jar =================================================================== (Binary files differ) Property changes on: tinytim-io/trunk/lib/semagia-mio-0.9.0.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: tinytim-io/trunk/lib/semagia-mio-xtm-0.9.0.jar =================================================================== (Binary files differ) Property changes on: tinytim-io/trunk/lib/semagia-mio-xtm-0.9.0.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: tinytim-io/trunk/lib/slf4j-api-1.5.0.jar =================================================================== (Binary files differ) Property changes on: tinytim-io/trunk/lib/slf4j-api-1.5.0.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: tinytim-io/trunk/lib/slf4j-jdk14-1.5.0.jar =================================================================== (Binary files differ) Property changes on: tinytim-io/trunk/lib/slf4j-jdk14-1.5.0.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-08 11:50:22
|
Revision: 61 http://tinytim.svn.sourceforge.net/tinytim/?rev=61&view=rev Author: lheuer Date: 2008-05-08 04:50:20 -0700 (Thu, 08 May 2008) Log Message: ----------- - Removed old I/O dir "mio" Removed Paths: ------------- tinytim-mio/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-08 11:36:06
|
Revision: 60 http://tinytim.svn.sourceforge.net/tinytim/?rev=60&view=rev Author: lheuer Date: 2008-05-08 04:36:02 -0700 (Thu, 08 May 2008) Log Message: ----------- - Moved MIO into IO Modified Paths: -------------- tinytim-io/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java Added Paths: ----------- tinytim-io/branches/ tinytim-io/tags/ tinytim-io/trunk/ tinytim-io/trunk/src/ Removed Paths: ------------- tinytim-io/trunk/src/ tinytim-mio/branches/ tinytim-mio/tags/ tinytim-mio/trunk/ Copied: tinytim-io/branches (from rev 54, tinytim-mio/branches) Copied: tinytim-io/tags (from rev 54, tinytim-mio/tags) Copied: tinytim-io/trunk (from rev 54, tinytim-mio/trunk) Copied: tinytim-io/trunk/src (from rev 59, tinytim-mio/trunk/src) Modified: tinytim-io/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java 2008-05-08 11:33:09 UTC (rev 59) +++ tinytim-io/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java 2008-05-08 11:36:02 UTC (rev 60) @@ -39,7 +39,7 @@ * Functions to import serialized topic maps. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class TopicMapImporter { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-08 11:33:09
|
Revision: 59 http://tinytim.svn.sourceforge.net/tinytim/?rev=59&view=rev Author: lheuer Date: 2008-05-08 04:33:09 -0700 (Thu, 08 May 2008) Log Message: ----------- - Added io, new home for mio :) Added Paths: ----------- tinytim-io/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-07 21:43:17
|
Revision: 58 http://tinytim.svn.sourceforge.net/tinytim/?rev=58&view=rev Author: lheuer Date: 2008-05-07 14:43:11 -0700 (Wed, 07 May 2008) Log Message: ----------- - Initial build import - Minor JavaDoc changes Modified Paths: -------------- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java Added Paths: ----------- tinytim-cxtm/trunk/CHANGES.txt tinytim-cxtm/trunk/LICENSE.txt tinytim-cxtm/trunk/README.txt tinytim-cxtm/trunk/build.properties tinytim-cxtm/trunk/build.xml Added: tinytim-cxtm/trunk/CHANGES.txt =================================================================== --- tinytim-cxtm/trunk/CHANGES.txt (rev 0) +++ tinytim-cxtm/trunk/CHANGES.txt 2008-05-07 21:43:11 UTC (rev 58) @@ -0,0 +1,7 @@ +=========== +Changes Log +=========== + +1.0.0 alpha1 (07.05.2008) +------------------------- +- Initial release Added: tinytim-cxtm/trunk/LICENSE.txt =================================================================== --- tinytim-cxtm/trunk/LICENSE.txt (rev 0) +++ tinytim-cxtm/trunk/LICENSE.txt 2008-05-07 21:43:11 UTC (rev 58) @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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-cxtm/trunk/README.txt =================================================================== --- tinytim-cxtm/trunk/README.txt (rev 0) +++ tinytim-cxtm/trunk/README.txt 2008-05-07 21:43:11 UTC (rev 58) @@ -0,0 +1,30 @@ +==================================== +tinyTiM - The tiny Topic Maps engine +==================================== + +What is tinyTiM CXTM? +--------------------- +tinyTiM is a tiny Topic Maps engine which keeps topic maps in-memory. +This Topic Maps engine is meant to be used together with the TMAPI interfaces, +see <http://www.tmapi.org/> for details. +The CXTM subpackage provides the serialization of topic maps into Canonical XTM +(CXTM) <http://www.isotopicmaps.org/cxtm/>. + + +Installation +------------ +No real installation needed, simply put the ``tinytim-cxtm-<VERSION>.jar`` +together with the ``tinytim-<VERSION>.jar`` and ``tmapi-1_0SP1.jar`` into your +classpath. + + +Latest Version +-------------- +Visit tinyTiM's homepage <http://sourceforge.net/projects/tinytim> for the +latest version. + + +License +------- +tinyTiM is licensed under the GNU Lesser General Public License (LGPL) +Version 2.1, see LICENSE.txt for details. Added: tinytim-cxtm/trunk/build.properties =================================================================== --- tinytim-cxtm/trunk/build.properties (rev 0) +++ tinytim-cxtm/trunk/build.properties 2008-05-07 21:43:11 UTC (rev 58) @@ -0,0 +1,4 @@ +version=1.0.0 +version_suffix=alpha1-2008-04-14 +debug=off +optimize=on Added: tinytim-cxtm/trunk/build.xml =================================================================== --- tinytim-cxtm/trunk/build.xml (rev 0) +++ tinytim-cxtm/trunk/build.xml 2008-05-07 21:43:11 UTC (rev 58) @@ -0,0 +1,158 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ==================================================================== + This is tinyTiM, a tiny Topic Maps engine. + + 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. + ==================================================================== + + $Rev:$ - $Date:$ +--> +<project name="tinyTiM CXTM" default="jar" basedir="."> + <property file="build.properties"/> + + <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.0alpha2.jar"/> + + <target name="help"> + <echo message="-------------------------"/> + <echo message="tinyTiM CXTM - Build file"/> + <echo message="-------------------------"/> + <echo message=""/> + <echo message="Available targets:"/> + <echo message=""/> + <echo message=" jar Creates the jar"/> + <echo message=" doc Creates the API documentation"/> + <echo message=" release Creates the jar and a distributable file"/> + </target> + + <target name="init"> + <property name="dist.version" value="${version}${version_suffix}"/> + <property name="dist.name" value="tinytim-cxtm-${dist.version}"/> + + <property name="tinytim-cxtm.jar" value="${dist.name}.jar"/> + <property name="tinytim-cxtm.tar" value="${dist.name}.tar"/> + <property name="tinytim-cxtm.tar.gz" value="${tinytim-cxtm.tar}.gz"/> + <property name="tinytim-cxtm.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> + + <!-- =================================================================== --> + <!-- Compile source files --> + <!-- =================================================================== --> + <target name="compile" depends="clean, prepare"> + <javac destdir="${dir.build.classes}" + debug="${debug}" + target="1.5"> + <classpath> + <pathelement location="${lib.tmapi}"/> + <pathelement location="${lib.tinytim}"/> + </classpath> + <src path="${dir.src}"/> + </javac> + </target> + + <!-- =================================================================== --> + <!-- Creates the Java Docs --> + <!-- =================================================================== --> + <target name="doc" depends="init"> + <mkdir dir="${dir.javadocs}"/> + <javadoc destdir="${dir.javadocs}" + packagenames="org.tinytim.*" + author="true" + version="true" + use="true" + splitindex="true" + noindex="false" + windowtitle="tinyTiM CXTM API v${dist.version}" + doctitle="tinyTiM CXTM API v${dist.version}"> + <fileset dir="${dir.src}"> + </fileset> + <link href="http://www.tmapi.org/apiDocs/"/> + </javadoc> + </target> + + <!-- =================================================================== --> + <!-- Creates the jar --> + <!-- =================================================================== --> + <target name="jar" depends="compile"> + <jar destfile="${dir.build}/${tinytim-cxtm.jar}"> + <fileset dir="${dir.build.classes}"> + <include name="**/*.*"/> + </fileset> + <manifest> + <attribute name="Implementation-Title" value="tinyTiM CXTM"/> + <attribute name="Implementation-Version" value="${dist.version}"/> + <attribute name="Implementation-URL" value="http://sourceforge.net/projects/tinytim"/> + </manifest> + </jar> + </target> + + <!-- =================================================================== --> + <!-- Prepares a distribution --> + <!-- =================================================================== --> + <target name="dist" depends="jar, doc"> + <mkdir dir="${dir.dist}"/> + + <copy todir="${dir.dist}" file="${dir.build}/${tinytim-cxtm.jar}"/> + + <copy todir="${dir.dist}/src"> + <fileset dir="${dir.src}"/> + </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) --> + <!-- =================================================================== --> + <target name="release" depends="jar, dist"> + <tar destfile="${dir.dist.root}/${tinytim-cxtm.tar}" + basedir="${dir.dist.root}"/> + <gzip src="${dir.dist.root}/${tinytim-cxtm.tar}" + destfile="${dir.build}/${tinytim-cxtm.tar.gz}" /> + <delete file="${dir.dist.root}/${tinytim-cxtm.tar}" /> + <zip destfile="${dir.build}/${tinytim-cxtm.zip}" basedir="${dir.dist.root}"/> + </target> +</project> Modified: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java 2008-05-07 12:44:47 UTC (rev 57) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java 2008-05-07 21:43:11 UTC (rev 58) @@ -35,7 +35,7 @@ * good enough to support CXTM. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class CXTMWriter { Modified: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-05-07 12:44:47 UTC (rev 57) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-05-07 21:43:11 UTC (rev 58) @@ -68,23 +68,28 @@ /** * 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. - * - * <em>CAUTION</em>: This class implements a CXTM draft (2008-04-14), the output - * may change in the future. - * - * The canonicalizer requires that the property + * </p> + * <p> + * <em>CAUTION</em>: This class implements the + * <a href="http://www.isotopicmaps.org/cxtm/2008-04-14/">CXTM draft dtd. 2008-04-14</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$ */ @@ -124,7 +129,17 @@ private Map<TopicName, Variant[]> _name2Variants; 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 Canonicalizer(OutputStream out, String baseLocator) throws IOException { + if (baseLocator == null) { + throw new IllegalArgumentException("The base locator must not be null"); + } _out = new CXTMWriter(out); _normBase = _normalizeBaseLocator(baseLocator); _topicComparator = new TopicComparator(); @@ -140,13 +155,15 @@ /** * 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. */ @@ -782,7 +799,7 @@ * Writes a warning msg to the log. * * This method is used to inform the user that the serialized topic map - * is not valid CXTM. + * is not valid acc. to CXTM. * * @param msg The warning message. */ @@ -922,7 +939,8 @@ /** * Role comparator which ignores the parent association. This comparator - * is meant to be used for roles where the parent is always equal. + * is meant to be used for roles where the parent is known to be equal or + * unequal. */ private class RoleIgnoreParentComparator extends AbstractComparator<AssociationRole> { @@ -1065,7 +1083,7 @@ private final class RoleSetComparator extends AbstractSetComparator<AssociationRole> { private RoleIgnoreParentComparator _roleCmp; - + RoleSetComparator() { _roleCmp = new RoleIgnoreParentComparator(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-07 12:44:47
|
Revision: 57 http://tinytim.svn.sourceforge.net/tinytim/?rev=57&view=rev Author: lheuer Date: 2008-05-07 05:44:47 -0700 (Wed, 07 May 2008) Log Message: ----------- Added link to TMAPI Modified Paths: -------------- tinytim/trunk/build.xml Modified: tinytim/trunk/build.xml =================================================================== --- tinytim/trunk/build.xml 2008-05-07 11:33:54 UTC (rev 56) +++ tinytim/trunk/build.xml 2008-05-07 12:44:47 UTC (rev 57) @@ -155,6 +155,7 @@ <exclude name="org/tinytim/IEvent*"/> <exclude name="org/tinytim/Event*"/> </fileset> + <link href="http://www.tmapi.org/apiDocs/"/> </javadoc> </target> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-07 11:33:48
|
Revision: 56 http://tinytim.svn.sourceforge.net/tinytim/?rev=56&view=rev Author: lheuer Date: 2008-05-07 04:33:54 -0700 (Wed, 07 May 2008) Log Message: ----------- - Initial TopicMapImporter import - Support for "untyped" names in the MapInputHandler - Check for scope constraints in the MapInputHandler - More tests Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java Added Paths: ----------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-05-07 11:31:20 UTC (rev 55) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-05-07 11:33:54 UTC (rev 56) @@ -21,6 +21,7 @@ package org.tinytim.mio; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.logging.Logger; @@ -28,6 +29,7 @@ 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; @@ -77,10 +79,13 @@ /** * Sets the topic map instance to operate on. * - * @param tm The topic map. + * @param topicMap The topic map. */ - public void setTopicMap(TopicMap tm) { - _tm = (TopicMapImpl) tm; + public void setTopicMap(TopicMap topicMap) { + if (topicMap == null) { + throw new IllegalArgumentException("The topic map must not be null"); + } + _tm = (TopicMapImpl) topicMap; } /* (non-Javadoc) @@ -189,7 +194,11 @@ * @see com.semagia.mio.IMapHandler#endName() */ public void endName() throws MIOException { + TopicName name = (TopicName) _peekConstruct(); _leaveStatePopConstruct(State.NAME); + if (name.getType() == null) { + name.setType(_topicBySubjectIdentifier(TMDM.TOPIC_NAME)); + } } /* (non-Javadoc) @@ -203,8 +212,14 @@ /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#endVariant() */ + @SuppressWarnings("unchecked") public void endVariant() throws MIOException { + Variant variant = (Variant) _peekConstruct(); _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) Added: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java (rev 0) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java 2008-05-07 11:33:54 UTC (rev 56) @@ -0,0 +1,222 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.mio; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.tmapi.core.TMAPIRuntimeException; +import org.tmapi.core.TopicMap; + +import org.xml.sax.InputSource; + +import com.semagia.mio.DeserializerRegistry; +import com.semagia.mio.IDeserializer; +import com.semagia.mio.MIOException; +import com.semagia.mio.Syntax; + +/** + * Functions to import serialized topic maps. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class TopicMapImporter { + + private TopicMapImporter() { + // noop. + } + + /** + * Reads a XML topic map from <code>input</code> and adds the content to the + * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * resolve IRIs against. + * + * @param topicMap The topic map instance which receives the + * Topic Maps constructs. + * @param docIRI The IRI which is used to resolve IRIs against. + * @param input The stream to read the serialized topic map from. + * @throws IOException If an error occurs. + */ + public static void importInto(TopicMap topicMap, String docIRI, InputStream input) throws IOException { + _import(Syntax.XTM, topicMap, docIRI, input); + } + + /** + * Reads a XML topic map from <code>input</code> and adds the content to the + * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * resolve IRIs against. + * + * @param topicMap The topic map instance which receives the + * Topic Maps constructs. + * @param docIRI The IRI which is used to resolve IRIs against. + * @param input The source to read the serialized topic map from. + * @throws IOException If an error occurs. + */ + public static void importInto(TopicMap topicMap, String docIRI, InputSource input) throws IOException { + _import(Syntax.XTM, topicMap, docIRI, input); + } + + /** + * Reads a topic map from <code>file</code> and adds the content to the + * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * resolve IRIs against. + * + * The syntax of the serialized topic map is guessed by the file name. If + * the file extension gives no indication of the used syntax, XTM is + * assumed. + * + * @param topicMap The topic map instance which receives the + * Topic Maps constructs. + * @param docIRI The IRI which is used to resolve IRIs against. + * @param file The file to read the serialized topic map from. + * @throws IOException If an error occurs. + */ + public static void importInto(TopicMap topicMap, String docIRI, File file) throws IOException { + _import(_guessSyntax(file), topicMap, docIRI, new FileInputStream(file)); + } + + /** + * Reads a topic map from <code>file</code> and adds the content to the + * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * resolve IRIs against. + * + * The <code>syntax</code> is a string with the abbreviated Topic Maps syntax + * name; i.e. "xtm", "ltm", "ctm". The name is matched case-insensitve, that + * means "xtm" is the same as "xTm", "XTM" etc. + * + * @param topicMap The topic map instance which receives the + * Topic Maps constructs. + * @param docIRI The IRI which is used to resolve IRIs against. + * @param file The file to read the serialized topic map from. + * @param syntax The name of the syntax of the encoded topic map. I.e. "xtm". + * @throws IOException If an error occurs. + */ + public static void importInto(TopicMap topicMap, String docIRI, File file, String syntax) throws IOException { + importInto(topicMap, docIRI, new FileInputStream(file), syntax); + } + + /** + * Reads a topic map from <code>input</code> and adds the content to the + * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * resolve IRIs against. + * + * The <code>syntax</code> is a string with the abbreviated Topic Maps syntax + * name; i.e. "xtm", "ltm", "ctm". The name is matched case-insensitve, that + * means "xtm" is the same as "xTm", "XTM" etc. + * + * @param topicMap The topic map instance which receives the + * Topic Maps constructs. + * @param docIRI The IRI which is used to resolve IRIs against. + * @param input The stream to read the serialized topic map from. + * @param syntax The name of the syntax of the encoded topic map. I.e. "xtm". + * @throws IOException If an error occurs. + */ + public static void importInto(TopicMap topicMap, String docIRI, InputStream input, String syntax) throws IOException { + importInto(topicMap, docIRI, new InputSource(input), syntax); + } + + /** + * Reads a topic map from <code>input</code> and adds the content to the + * specified <code>topicMap</code>. The <code>docIRI</code> is used to + * resolve IRIs against. + * + * The <code>syntax</code> is a string with the abbreviated Topic Maps syntax + * name; i.e. "xtm", "ltm", "ctm". The name is matched case-insensitve, that + * means "xtm" is the same as "xTm", "XTM" etc. + * + * @param topicMap The topic map instance which receives the + * Topic Maps constructs. + * @param docIRI The IRI which is used to resolve IRIs against. + * @param input The source to read the serialized topic map from. + * @param syntax The name of the syntax of the encoded topic map. I.e. "xtm". + * @throws IOException If an error occurs. + */ + public static void importInto(TopicMap topicMap, String docIRI, InputSource input, String syntax) throws IOException { + Syntax syntax_ = Syntax.valueOf(syntax); + if (syntax_ == null) { + throw new RuntimeException("The syntax '" + syntax + "' is unknown"); + } + _import(syntax_, topicMap, docIRI, input); + } + + /** + * Returns a {@link Syntax} instance. + * + * @param file The file to guess the syntax from. + * @return A syntax which matches the file extension or {@link Syntax#XTM} + * if the file extension is not available or gives no indication + * about the used syntax. + */ + private static Syntax _guessSyntax(File file) { + String name = file.getName(); + int i = name.lastIndexOf('.'); + return i == -1 ? Syntax.XTM + : Syntax.forFileExtension(name.substring(i+1), Syntax.XTM); + } + + /** + * Reads a topic map from <code>input</code> and adds the content to the + * <code>topicMap</code>. + * + * @param syntax A syntax instance. + * @param topicMap A topic map instance. + * @param docIRI The IRI which is used to resolve locators against. + * @param input The source to read the topic map from. + * @throws IOException If an error occurs. + */ + private static void _import(Syntax syntax, TopicMap topicMap, String docIRI, + InputStream input) throws IOException { + _import(syntax, topicMap, docIRI, new InputSource(input)); + } + + /** + * Reads a topic map from <code>input</code> and adds the content to the + * <code>topicMap</code>. + * + * @param syntax A syntax instance. + * @param topicMap A topic map instance. + * @param docIRI The IRI which is used to resolve locators against. + * @param input The source to read the topic map from. + * @throws IOException If an error occurs. + */ + private static void _import(Syntax syntax, TopicMap topicMap, String docIRI, + InputSource input) throws IOException { + IDeserializer deser = DeserializerRegistry.createDeserializer(syntax); + if (deser == null) { + throw new IOException("No deserializer found for the syntax '" + syntax.getName() + "'"); + } + deser.setMapHandler(new MapInputHandler(topicMap)); + try { + deser.parse(input, docIRI); + } + catch (MIOException ex) { + if (ex.getException() instanceof IOException) { + throw (IOException) ex.getException(); + } + else { + throw new TMAPIRuntimeException(ex); + } + } + } +} Property changes on: tinytim-mio/trunk/src/main/java/org/tinytim/mio/TopicMapImporter.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-05-07 11:31:20 UTC (rev 55) +++ tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-05-07 11:33:54 UTC (rev 56) @@ -22,6 +22,7 @@ import org.tinytim.Property; import org.tinytim.TopicMapImpl; +import org.tinytim.voc.TMDM; import org.tmapi.core.Locator; import org.tmapi.core.Occurrence; import org.tmapi.core.Topic; @@ -29,6 +30,7 @@ import org.tmapi.core.TopicMapSystemFactory; import org.tmapi.core.TopicName; +import com.semagia.mio.MIOException; import com.semagia.mio.helpers.Ref; import junit.framework.TestCase; @@ -126,9 +128,9 @@ _handler.startTopic(Ref.createItemIdentifier(itemIdent)); _handler.itemIdentifier(ref); _handler.endTopic(); - _handler.startName(); - _handler.value("tinyTiM"); - _handler.endName(); + _handler.startOccurrence(); + _handler.value("tinyTiM", _XSD_STRING); + _handler.endOccurrence(); _handler.endTopic(); _handler.endTopicMap(); assertEquals(1, _tm.getTopics().size()); @@ -136,9 +138,9 @@ assertNotNull(topic); assertEquals(topic, _tm.getObjectByItemIdentifier(_tm.createLocator(ref))); assertEquals(topic, _tm.getObjectByItemIdentifier(_tm.createLocator(itemIdent))); - assertEquals(1, topic.getTopicNames().size()); - TopicName name = (TopicName)topic.getTopicNames().iterator().next(); - assertEquals("tinyTiM", name.getValue()); + assertEquals(1, topic.getOccurrences().size()); + Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); + assertEquals("tinyTiM", occ.getValue()); } /** @@ -231,4 +233,79 @@ assertEquals(val, occ.getResource().getReference()); } + /** + * Tests if the name type is automatically set. + */ + public void testDefaultNameType() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startName(); + _handler.value(val); + _handler.endName(); + _handler.endTopic(); + _handler.endTopicMap(); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + TopicName name = (TopicName) topic.getTopicNames().iterator().next(); + assertEquals(val, name.getValue()); + assertNotNull(name.getType()); + assertTrue(name.getType().getSubjectIdentifiers().contains(TMDM.TOPIC_NAME)); + } + + /** + * Tests if a variant with no scope is reported as error. + */ + public void testVariantNoScopeError() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startName(); + _handler.value(val); + _handler.startVariant(); + _handler.value(val, _XSD_STRING); + try { + _handler.endVariant(); + fail("A variant with no scope shouldn't be allowed"); + } + catch (MIOException ex) { + // noop. + } + } + + /** + * Tests if a variant with a scope equals to the parent's scope is rejected. + */ + public void testVariantNoScopeError2() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String theme = "http://sf.net/projects/tinytim/test#theme"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startName(); + _handler.startScope(); + _handler.startTheme(); + _handler.topicRef(Ref.createItemIdentifier(theme)); + _handler.endTheme(); + _handler.endScope(); + _handler.value(val); + + _handler.startVariant(); + _handler.value(val, _XSD_STRING); + _handler.startScope(); + _handler.startTheme(); + _handler.topicRef(Ref.createItemIdentifier(theme)); + _handler.endTheme(); + _handler.endScope(); + try { + _handler.endVariant(); + fail("A variant with a scope equals to the parent's scope shouldn't be allowed"); + } + catch (MIOException ex) { + // noop. + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-07 11:31:14
|
Revision: 55 http://tinytim.svn.sourceforge.net/tinytim/?rev=55&view=rev Author: lheuer Date: 2008-05-07 04:31:20 -0700 (Wed, 07 May 2008) Log Message: ----------- - Added some identity comp. Modified Paths: -------------- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java Modified: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-05-05 14:53:21 UTC (rev 54) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-05-07 11:31:20 UTC (rev 55) @@ -86,7 +86,7 @@ * (set to <tt>true</tt>). * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class Canonicalizer { @@ -182,6 +182,7 @@ _out.endElement("topicMap"); _out.newline(); _out.endDocument(); + _out = null; _construct2Id = null; _locator2Norm = null; _assoc2Roles = null; @@ -821,7 +822,7 @@ } /** - * Abstract comparator that provides some utility method which handle common + * Abstract comparator that provides some utility methods which handle common * comparisons. */ private abstract class AbstractComparator<T> implements Comparator<T> { @@ -905,6 +906,9 @@ @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()); @@ -923,6 +927,9 @@ private class RoleIgnoreParentComparator extends AbstractComparator<AssociationRole> { public int compare(AssociationRole o1, AssociationRole o2) { + if (o1 == o2) { + return 0; + } int res = _topicComparator.compare(o1.getPlayer(), o2.getPlayer()); if (res == 0) { res = compareType((ITyped) o1, (ITyped) o2); @@ -959,6 +966,9 @@ private final class OccurrenceComparator extends AbstractDatatypeAwareComparator<Occurrence> { public int compare(Occurrence o1, Occurrence o2) { + if (o1 == o2) { + return 0; + } int res = _compareValueDatatype((IDatatypeAwareConstruct) o1, (IDatatypeAwareConstruct) o2); if (res == 0) { res = compareType((ITyped) o1, (ITyped) o2); @@ -981,6 +991,9 @@ private final class NameComparator extends AbstractComparator<TopicName> { public int compare(TopicName o1, TopicName o2) { + if (o1 == o2) { + return 0; + } int res = compareString(o1.getValue(), o2.getValue()); if (res == 0) { res = compareType((ITyped) o1, (ITyped) o2); @@ -1002,6 +1015,9 @@ private final class VariantComparator extends AbstractDatatypeAwareComparator<Variant> { public int compare(Variant o1, Variant o2) { + if (o1 == o2) { + return 0; + } int res = _compareValueDatatype((IDatatypeAwareConstruct) o1, (IDatatypeAwareConstruct) o2); if (res == 0) { res = compareScope(o1, o2); @@ -1115,6 +1131,9 @@ private final class LocatorComparator implements Comparator<Locator> { public int compare(Locator o1, Locator o2) { + if (o1 == o2) { + return 0; + } return _normalizeLocator(o1.getReference()).compareTo(_normalizeLocator(o2.getReference())); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-05 14:54:27
|
Revision: 54 http://tinytim.svn.sourceforge.net/tinytim/?rev=54&view=rev Author: lheuer Date: 2008-05-05 07:53:21 -0700 (Mon, 05 May 2008) Log Message: ----------- - Initial CXTM import Added Paths: ----------- tinytim-cxtm/trunk/src/main/java/org/ tinytim-cxtm/trunk/src/main/java/org/tinytim/ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java Added: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java (rev 0) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java 2008-05-05 14:53:21 UTC (rev 54) @@ -0,0 +1,207 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.cxtm; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.util.Arrays; + +import org.xml.sax.Attributes; +import org.xml.sax.helpers.AttributesImpl; + +/** + * Simple SAX-alike XML writer that respects canonical XML to some extend. + * + * This class is not meant to be a generic XML-C14N writer, but it should be + * good enough to support CXTM. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +final class CXTMWriter { + + public static final Attributes EMPTY_ATTRS = new AttributesImpl(); + + private static final char _NL = '\n'; + + private OutputStreamWriter _out; + + public CXTMWriter(OutputStream out) throws IOException { + _out = new OutputStreamWriter(out, "UTF-8"); + } + + /** + * Indicates the start of the serialization process. + * + * @throws IOException If an error occurs. + */ + public void startDocument() throws IOException { + // noop + } + + /** + * Indicates the end of the serialization process. + * + * @throws IOException If an error occurs. + */ + public void endDocument() throws IOException { + _out.flush(); + } + + /** + * Indicates the start of an element with the specified local name. + * + * @see #startElement(String, Attributes). + * + * @param localName The element's name. + * @throws IOException If an error occurs. + */ + public void startElement(String localName) throws IOException { + startElement(localName, EMPTY_ATTRS); + } + + /** + * Indicates the start of an element with the provided local name. + * + * The attributes written in canonical XML. + * + * @param localName The name of the element. + * @param attrs The element's attributes. + * @throws IOException If an error occurs. + */ + public void startElement(String localName, Attributes attrs) throws IOException { + String[] names = new String[attrs.getLength()]; + for (int i=0; i < names.length; i++) { + names[i] = attrs.getLocalName(i); + } + Arrays.sort(names); + _out.write('<'); + _out.write(localName); + for (int i=0; i < names.length; i++) { + _out.write(' '); + _out.write(names[i]); + _out.write("=\""); + _out.write(_escapeAttributeValue(attrs.getValue("", names[i]))); + _out.write('"'); + } + _out.write('>'); + } + + /** + * Indicates the end of an elemnt. + * + * @param localName The element's name. + * @throws IOException If an error occurs. + */ + public void endElement(String localName) throws IOException { + _out.write("</"); + _out.write(localName); + _out.write('>'); + } + + /** + * Writes a <tt>#x0A</tt> to the output. + * + * @throws IOException If an error occurs. + */ + public void newline() throws IOException { + _out.write(_NL); + } + + /** + * Writes the specified characters to the output. + * + * The data is written according to the rules of canonicalized XML. + * + * @param data The data to write. + * @throws IOException If an error occurs. + */ + public void characters(String data) throws IOException { + _out.write(_escapeTextContent(data)); + } + + /** + * Escapes the data according to the canonical XML rules. + * + * @param value The value. + * @return The escaped value. + */ + private String _escapeTextContent(String value) { + char[] data = value.toCharArray(); + StringBuilder sb = new StringBuilder(data.length); + for (int i=0; i < data.length; i++) { + char c = data[i]; + if (c == '\r') { + sb.append("
"); + } + else if (c == '&') { + sb.append("&"); + } + else if (c == '<') { + sb.append("<"); + } + else if (c == '>') { + sb.append(">"); + } + else { + sb.append(c); + } + } + return sb.toString(); + } + + /** + * Escapes the attribute's value according to canonical XML. + * + * @param value The value to escape. + * @return The escaped value. + */ + private String _escapeAttributeValue(String value) { + char[] data = value.toCharArray(); + StringBuilder sb = new StringBuilder(data.length); + for (int i=0; i<data.length; i++) { + char c = data[i]; + if (c == '\t') { + sb.append("	"); + } + else if (c == '\n') { + sb.append("
"); + } + else if (c == '\r') { + sb.append("
"); + } + else if (c == '\"') { + sb.append("""); + } + else if (c == '&') { + sb.append("&"); + } + else if (c == '<') { + sb.append("<"); + } + else { + sb.append(c); + } + } + return sb.toString(); + } +} Property changes on: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/CXTMWriter.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java =================================================================== --- tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java (rev 0) +++ tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java 2008-05-05 14:53:21 UTC (rev 54) @@ -0,0 +1,1299 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.cxtm; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.AbstractSet; +import java.util.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.TopicImpl; +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). + * + * 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. + * + * See <a href="http://www.isotopicmaps.org/cxtm/">http://www.isotopicmaps.org/cxtm/</a> + * for details. + * + * <em>CAUTION</em>: This class implements a CXTM draft (2008-04-14), the output + * may change in the future. + * + * 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>). + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class Canonicalizer { + + private static final Logger LOG = Logger.getLogger(Canonicalizer.class.getName()); + + private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; + + private static final AssociationRole[] _EMPTY_ROLES = new AssociationRole[0]; + private static final Occurrence[] _EMPTY_OCCS = new Occurrence[0]; + private static final TopicName[] _EMPTY_NAMES = new TopicName[0]; + private static final Variant[] _EMPTY_VARIANTS = new Variant[0]; + + private Topic _type; + private Topic _instance; + private Topic _typeInstance; + + private CXTMWriter _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<Topic, TopicName[]> _topic2Names; + private Map<Topic, Occurrence[]> _topic2Occs; + private Map<TopicName, Variant[]> _name2Variants; + private Map<Association, AssociationRole[]> _assoc2Roles; + + public Canonicalizer(OutputStream out, String baseLocator) throws IOException { + _out = new CXTMWriter(out); + _normBase = _normalizeBaseLocator(baseLocator); + _topicComparator = new TopicComparator(); + _assocComparator = new AssociationComparator(); + _roleComparator = new RoleComparator(); + _occComparator = new OccurrenceComparator(); + _nameComparator = new NameComparator(); + _variantComparator = new VariantComparator(); + _locSetComparator = new LocatorSetComparator(); + _locComparator = new LocatorComparator(); + _scopeComparator = new ScopeComparator(); + } + + /** + * Serializes the specified <code>topicMap</code> into the CXTM format. + * + * <em>CAUTION</em>: This method MAY modify the topic map since duplicate + * Topic Maps constructs (if any) are removed in advance. + * + * The topic map's base locator + * ({@link org.tmapi.core.TopicMap#getBaseLocator()}) is ignored. + * + * @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>>(); + _topic2Occs = new IdentityHashMap<Topic, Occurrence[]>(); + _topic2Names = new IdentityHashMap<Topic, TopicName[]>(); + _name2Variants = new IdentityHashMap<TopicName, Variant[]>(); + 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(); + _construct2Id = null; + _locator2Norm = null; + _assoc2Roles = null; + _topic2Roles = null; + _topic2Occs = null; + _topic2Names = null; + _name2Variants = 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, new Integer(i+1)); + Set<Occurrence> occs_ = topic.getOccurrences(); + Occurrence[] occs = occs_.toArray(new Occurrence[occs_.size()]); + Arrays.sort(occs, _occComparator); + _topic2Occs.put(topic, occs); + for (int j=0; j < occs.length; j++) { + _construct2Id.put(occs[j], new Integer(j+1)); + } + Set<TopicName> names_ = topic.getTopicNames(); + TopicName[] names = names_.toArray(new TopicName[names_.size()]); + Arrays.sort(names, _nameComparator); + _topic2Names.put(topic, names); + for (int j=0; j < names.length; j++) { + TopicName name = names[j]; + _construct2Id.put(name, new Integer(j+1)); + Set<Variant> variants_ = name.getVariants(); + Variant[] variants = variants_.toArray(new Variant[variants_.size()]); + Arrays.sort(variants, _variantComparator); + _name2Variants.put(name, variants); + for (int k=0; k < variants.length; k++) { + _construct2Id.put(variants[k], new Integer(k+1)); + } + } + } + Arrays.sort(assocs, _assocComparator); + Association assoc = null; + for (int i=0; i < assocs.length; i++) { + assoc = assocs[i]; + _construct2Id.put(assoc, new Integer(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], new Integer(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. + */ + private TopicName[] _getNames(Topic topic) { + TopicName[] names = _topic2Names.get(topic); + return names != null ? names : _EMPTY_NAMES; + } + + /** + * Returs a sorted array of variants of the provided name. + * + * @param name The name to retrieve the variants from. + * @return A (maybe empty) sorted array of variants. + */ + private Variant[] _getVariants(TopicName name) { + Variant[] variants = _name2Variants.get(name); + return variants != null ? variants : _EMPTY_VARIANTS; + } + + /** + * Returns a sorted array of occurrences of the provided topic. + * + * @param topic The topic to retrieve the occurrences from. + * @return A (maybe emtpy) sorted array of occurrences. + */ + private Occurrence[] _getOccurrences(Topic topic) { + Occurrence[] occs = _topic2Occs.get(topic); + return occs != null ? occs : _EMPTY_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 String _indexOf(TopicMapObject tmo) { + return _construct2Id.get(tmo).toString(); + } + + /** + * 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(); + _addReified(attrs, topic); + attrs.addAttribute("", "number", null, null, _indexOf(topic)); + _out.startElement("topic", attrs); + _out.newline(); + _writeLocatorSet("subjectIdentifiers", topic.getSubjectIdentifiers()); + _writeLocatorSet("subjectLocators", topic.getSubjectLocators()); + _writeItemIdentifiers(topic); + for (TopicName name: _getNames(topic)) { + _writeName(name); + } + for (Occurrence occ: _getOccurrences(topic)) { + _writeOccurrence(occ); + } + 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)); + _out.newline(); + _writeType((ITyped) assoc); + for (AssociationRole role: _getRoles(assoc)) { + _out.startElement("role", _attributes(role)); + _out.newline(); + _out.startElement("player", _topicRef(role.getPlayer())); + _out.endElement("player"); + _out.newline(); + _writeType((ITyped) 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) throws IOException { + _out.startElement("occurrence", _attributes(occ)); + _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(); + 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(_normalizeLocator(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) throws IOException { + _out.startElement("topicName", _attributes(name)); + _out.newline(); + _out.startElement("value"); + _out.characters(name.getValue()); + _out.endElement("value"); + _out.newline(); + _writeType((ITyped) name); + _writeScope(name); + for (Variant variant: _getVariants(name)) { + _out.startElement("variant", _attributes(variant)); + _out.newline(); + _writeDatatyped((IDatatypeAwareConstruct) variant); + _writeScope(variant); + _writeItemIdentifiers(variant); + _out.endElement("variant"); + _out.newline(); + } + _writeItemIdentifiers(name); + _out.endElement("topicName"); + _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); + 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 CXTMWriter.EMPTY_ATTRS; + } + AttributesImpl attrs = new AttributesImpl(); + attrs.addAttribute("", "topicref", null, null, _indexOf(topic)); + return attrs; + } + + /** + * Returns attributes which contain the reifier (if any) and the number + * of the provided Topic Maps construct (not a topic). + * + * @param reifiable The Topic Maps construct. + * @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) { + AttributesImpl attrs = new AttributesImpl(); + _addReifier(attrs, (IReifiable)reifiable); + attrs.addAttribute("", "number", null, null, _indexOf(reifiable)); + 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)); + } + } + + /** + * Adds a reference to the Topic Maps construct which is reified by the + * provided topic. + * + * If the topic reifies no Topic Maps construct, the attributes are not + * modified. + * + * @param attrs The attributes to add the reference to. + * @param topic The topic. + */ + private void _addReified(AttributesImpl attrs, Topic topic) { + if (topic instanceof TypeInstanceTopic) { + return; + } + IReifiable reifiable = ((TopicImpl) topic).getReifiedConstruct(); + if (reifiable == null) { + return; + } + StringBuilder sb = new StringBuilder(); + if (reifiable instanceof TopicMap) { + sb.append("topicMap"); + } + else if (reifiable instanceof Association) { + sb.append("association.") + .append(_indexOf(reifiable)); + } + else if (reifiable instanceof AssociationRole) { + sb.append("association.") + .append(_indexOf(reifiable.getParent())) + .append(".role.") + .append(_indexOf(reifiable)); + } + else { + sb.append("topic."); + final IConstruct parent = reifiable.getParent(); + if (reifiable instanceof Occurrence) { + sb.append(_indexOf(parent)) + .append(".occurrence."); + } + else if (reifiable instanceof TopicName) { + sb.append(_indexOf(parent)) + .append(".name."); + } + else if (reifiable instanceof Variant) { + sb.append(_indexOf(parent.getParent())) + .append(".name.") + .append(_indexOf(parent)) + .append(".variant."); + } + sb.append(_indexOf(reifiable)); + } + attrs.addAttribute("", "reifier", null, null, sb.toString()); + } + + /** + * 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 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 method 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) { + 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; + } + } + + /** + * Role comparator which ignores the parent association. This comparator + * is meant to be used for roles where the parent is always equal. + */ + private class RoleIgnoreParentComparator extends AbstractComparator<AssociationRole> { + + public int compare(AssociationRole o1, AssociationRole o2) { + int res = _topicComparator.compare(o1.getPlayer(), o2.getPlayer()); + if (res == 0) { + res = compareType((ITyped) o1, (ITyped) o2); + } + return res; + } + } + + /** + * Canonical sort order: + * 1. [player] + * 2. [type] + * 3. [parent] + */ + private final class RoleComparator extends RoleIgnoreParentComparator { + + public int compare(AssociationRole o1, AssociationRole o2) { + int res = super.compare(o1, o2); + if (res == 0) { + res = _assocComparator.compare(o1.getAssociation(), o2.getAssociation()); + } + return res; + } + } + + /** + * Canonical sort order: + * 1. [value] + * 2. [datatype] + * 3. [type] + * 4. [scope] + * 5. [parent] + */ + private final class OccurrenceComparator extends AbstractDatatypeAwareComparator<Occurrence> { + + public int compare(Occurrence o1, Occurrence o2) { + int res = _compareValueDatatype((IDatatypeAwareConstruct) o1, (IDatatypeAwareConstruct) o2); + if (res == 0) { + res = compareType((ITyped) o1, (ITyped) o2); + if (res == 0) { + res = compareScope(o1, o2); + } + } + return res; + } + + } + + /** + * Canonical sort order: + * 1. [value] + * 2. [type] + * 3. [scope] + * 4. [parent] + */ + private final class NameComparator extends AbstractComparator<TopicName> { + + public int compare(TopicName o1, TopicName o2) { + int res = compareString(o1.getValue(), o2.getValue()); + if (res == 0) { + res = compareType((ITyped) o1, (ITyped) o2); + if (res == 0) { + res = compareScope(o1, o2); + } + } + return res; + } + } + + /** + * Canonical sort order: + * 1. [value] + * 2. [datatype] + * 3. [scope] + * 4. [parent] + */ + private final class VariantComparator extends AbstractDatatypeAwareComparator<Variant> { + + public int compare(Variant o1, Variant o2) { + int res = _compareValueDatatype((IDatatypeAwareConstruct) o1, (IDatatypeAwareConstruct) o2); + if (res == 0) { + res = compareScope(o1, o2); + } + return res; + } + } + + /** + * Comparator which compares the size of the provided set. + * + * Iff the size of the sets are equal, another comparison method is used + * to compare the content of the sets. + */ + private abstract class AbstractSetComparator<T> implements Comparator<Set<T>> { + + public int compare(Set<T> o1, Set<T> o2) { + int s1 = o1.size(); + int s2 = o2.size(); + int res = s1 - s2; + if (res == 0) { + res = compareContent(o1, o2, s1); + } + return res; + } + + /** + * Called iff the size of the sets is equal. + * + * This method is used to compare the content of the sets. + * + * @param o1 The first set. + * @param o2 The second set. + * @param size The size of the set(s). + * @return A negative integer, zero, or a positive integer as the + * first argument is less than, equal to, or greater than the + * second. + */ + abstract int compareContent(Set<T> o1, Set<T> o2, int size); + } + + /** + * Compares role sets. The parent of the roles is ignored! + */ + private final class RoleSetComparator extends AbstractSetComparator<AssociationRole> { + + private RoleIgnoreParentComparator _roleCmp; + + RoleSetComparator() { + _roleCmp = new RoleIgnoreParentComparator(); + } + + @Override + int compareContent(Set<AssociationRole> o1, Set<AssociationRole> o2, + int size) { + int res = 0; + AssociationRole[] roles1 = o1.toArray(new AssociationRole[size]); + AssociationRole[] roles2 = o2.toArray(new AssociationRole[size]); + Arrays.sort(roles1, _roleCmp); + Arrays.sort(roles2, _roleCmp); + for (int i=0; i < size && res == 0; i++) { + res = _roleCmp.compare(roles1[i], roles2[i]); + } + return res; + } + + } + + /** + * Compares the scope of two scoped Topic Maps constructs. + */ + private final class ScopeComparator extends AbstractSetComparator<Topic> { + + @Override + int compareContent(Set<Topic> o1, Set<Topic> o2, int size) { + int res = 0 ; + Topic[] topics1 = o1.toArray(new Topic[size]); + Topic[] topics2 = o2.toArray(new Topic[size]); + Arrays.sort(topics1, _topicComparator); + Arrays.sort(topics2, _topicComparator); + for (int i=0; i < size && res == 0; i++) { + res = _topicComparator.compare(topics1[i], topics2[i]); + } + return res; + } + + } + + /** + * Comparator for sets of {@link org.tmapi.core.Locator}s. + */ + private final class LocatorSetComparator extends AbstractSetComparator<Locator> { + + @Override + int compareContent(Set<Locator> o1, Set<Locator> o2, int size) { + int res = 0; + Locator[] locs1 = o1.toArray(new Locator[size]); + Locator[] locs2 = o2.toArray(new Locator[size]); + Arrays.sort(locs1, _locComparator); + Arrays.sort(locs2, _locComparator); + for (int i=0; i < size && res == 0; i++) { + res = _locComparator.compare(locs1[i], locs2[i]); + } + return res; + } + } + + /** + * Compares {@link org.tmapi.core.Locator}s. + */ + private final class LocatorComparator implements Comparator<Locator> { + + public int compare(Locator o1, Locator o2) { + return _normalizeLocator(o1.getReference()).compareTo(_normalizeLocator(o2.getReference())); + } + + } + + + /* + * Helper classes to treat type-instance relationships, modelled as property + * of a topic, as associations. + */ + + @SuppressWarnings("unchecked") + private final class TypeInstanceTopic implements Topic { + + private final Set<Locator> _sids; + + TypeInstanceTopic(Locator sid) { + _sids = Collections.singleton(sid); + } + + public Set<Locator> getSubjectIdentifiers() { + return _sids; + } + + public void addSourceLocator(Locator arg0) throws DuplicateSourceLocatorException, MergeException { } + public void addSubjectIdentifier(Locator arg0) throws MergeException {} + public void addSubjectLocator(Locator arg0) throws MergeException, ModelConstraintException {} + public void addType(Topic arg0) {} + public Occurrence createOccurrence(String arg0, Topic arg1, Collection arg2) { return null; } + public Occurrence createOccurrence(Locator arg0, Topic arg1, Collection arg2) { return null; } + public TopicName createTopicName(String arg0, Collection arg1) throws MergeException { return null; } + public TopicName createTopicName(String arg0, Topic arg1, Collection arg2) throws UnsupportedOperationException, MergeException { return null; } + public Set getOccurrences() { return Collections.emptySet(); } + public Set getReified() { return null; } + public Set getRolesPlayed() { return Collections.emptySet(); } + public Set getSubjectLocators() { return Collections.emptySet(); } + public Set getTopicNames() { return Collections.emptySet(); } + public Set getTypes() { return null; } + public void mergeIn(Topic arg0) throws MergeException { } + public void remove() throws TopicInUseException { } + public void removeSubjectIdentifier(Locator arg0) { } + public void removeSubjectLocator(Locator arg0) { } + public void removeType(Topic arg0) { } + public String getObjectId() { return null; } + public Set getSourceLocators() { return Collections.emptySet(); } + public TopicMap getTopicMap() { return null; } + public void removeSourceLocator(Locator arg0) { } + } + + /** + * Used to represent type-instance relationships which are modelled as + * [type] property of topics. + */ + @SuppressWarnings("unchecked") + private final class TypeInstanceAssociation implements Association, IReifiable, ITyped { + + final Set<AssociationRole> _roles; + + TypeInstanceAssociation(Topic type, Topic instance) { + AssociationRole typeRole = new TypeInstanceRole(this, _type, type); + AssociationRole instanceRole = new TypeInstanceRole(this, _instance, instance); + _roles = new TypeInstanceRoleSet(typeRole, instanceRole); + } + + public Set<AssociationRole> getAssociationRoles() { + return _roles; + } + + public Topic getType() { + return _typeInstance; + } + + public void setReifier(Topic reifier) { } + public void addItemIdentifier(Locator itemIdentifier) { } + public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } + public IConstruct getParent() { return null; } + public void removeItemIdentifier(Locator itemIdentifier) { } + public AssociationRole createAssociationRole(Topic arg0, Topic arg1) { return null; } + public Topic getReifier() { return null; } + public void remove() throws TMAPIException {} + public void setType(Topic arg0) {} + public void addScopingTopic(Topic arg0) {} + public Set getScope() { return Collections.emptySet(); } + public void removeScopingTopic(Topic arg0) {} + public void addSourceLocator(Locator arg0) throws DuplicateSourceLocatorException {} + public String getObjectId() { return null; } + public Set getSourceLocators() { return Collections.emptySet(); } + public TopicMap getTopicMap() { return null; } + public void removeSourceLocator(Locator arg0) {} + } + + /** + * Immutable association role. + */ + @SuppressWarnings("unchecked") + private class TypeInstanceRole implements AssociationRole , IReifiable, ITyped { + private final Topic _type; + private final Topic _player; + private final Association _parent; + + TypeInstanceRole(Association parent, Topic type, Topic player) { + _type = type; + _player = player; + _parent = parent; + List<AssociationRole> roles = _topic2Roles.get(player); + if (roles == null) { + roles = new ArrayList<AssociationRole>(); + _topic2Roles.put(player, roles); + } + roles.add(this); + } + + public Topic getType() { + return _type; + } + + public Topic getPlayer() { + return _player; + } + + public void setReifier(Topic reifier) { } + public void addItemIdentifier(Locator itemIdentifier) { } + public Set<Locator> getItemIdentifiers() { return Collections.emptySet(); } + public IConstruct getParent() { return (IConstruct) _parent; } + public void removeItemIdentifier(Locator itemIdentifier) { } + public Association getAssociation() { return _parent; } + public Topic getReifier() { return null; } + public void remove() throws TMAPIException {} + public void setPlayer(Topic arg0) {} + public void setType(Topic arg0) {} + public void addSourceLocator(Locator arg0) throws DuplicateSourceLocatorException {} + public String getObjectId() { return null; } + public Set getSourceLocators() { return Collections.emptySet(); } + public TopicMap getTopicMap() { return null; } + public void removeSourceLocator(Locator arg0) {} + } + + /** + * Immutable 'set' of two roles. + */ + private static class TypeInstanceRoleSet extends AbstractSet<AssociationRole> { + + private final AssociationRole _role1; + private final AssociationRole _role2; + + TypeInstanceRoleSet(AssociationRole role1, AssociationRole role2) { + _role1 = role1; + _role2 = role2; + } + + @Override + public Iterator<AssociationRole> iterator() { + return new TypeInstanceRoleSetIterator(); + } + + @Override + public int size() { + return 2; + } + + private class TypeInstanceRoleSetIterator implements Iterator<AssociationRole> { + + private int _idx; + + public boolean hasNext() { + return _idx < 2; + } + + public AssociationRole next() { + if (_idx > 1) { + throw new NoSuchElementException(); + } + return 0 == _idx++ ? _role1 : _role2; + } + + public void remove() { + new UnsupportedOperationException(); + } + } + } + +} Property changes on: tinytim-cxtm/trunk/src/main/java/org/tinytim/cxtm/Canonicalizer.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-05-05 12:37:34
|
Revision: 53 http://tinytim.svn.sourceforge.net/tinytim/?rev=53&view=rev Author: lheuer Date: 2008-05-05 05:37:18 -0700 (Mon, 05 May 2008) Log Message: ----------- - Preparing alpha 2 - DuplicateRemovalUtils added - voc package added - TypeInstanceConverter added - More tests - IIndexManager added - Additional tinyTiM specific property added Modified Paths: -------------- tinytim/trunk/CHANGES.txt tinytim/trunk/build.properties tinytim/trunk/build.xml tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/Property.java tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ScopedObjectsIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java tinytim/trunk/src/test/java/org/tinytim/AllTests.java tinytim/trunk/src/test/java/org/tinytim/TestSignatureGenerator.java tinytim/trunk/src/test/java/org/tinytim/index/TestScopedIndex.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/TypeInstanceConverter.java tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java tinytim/trunk/src/main/java/org/tinytim/voc/ tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java tinytim/trunk/src/test/java/org/tinytim/TestDuplicateRemovalUtils.java Modified: tinytim/trunk/CHANGES.txt =================================================================== --- tinytim/trunk/CHANGES.txt 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/CHANGES.txt 2008-05-05 12:37:18 UTC (rev 53) @@ -2,7 +2,28 @@ Changes Log =========== +1.5.0 alpha2 (05.05.2008) +------------------------- +Features: +- ``voc`` package added which provides access to common PSIs. +- ``DuplicateRemovalUtils`` added. Used to remove + duplicate Topic Maps constructs from topic maps, topics, + associations, and names +- ``TypeInstanceConverter`` added. Used to convert + type-instance associations into the topic's [types] + property. +- ``tmapi.TopicNamesIndex``, ``tmapi.OccurrenceIndex`` + and ``tmapi.VarinatsIndex`` use an optimized reindex + algorithm. +- Property to let ``Variant`` instances return the union + of their 'own' scope and the parent's scope. +Bugfixes: +- ``DatatypeAwareConstruct`` sent wrong event. Fixed +- All indexes return copies of their collections to avoid + concurrent modification exceptions. + + 1.5.0 alpha1 (25.04.2008) ------------------------- - Initial 1.5.x release Modified: tinytim/trunk/build.properties =================================================================== --- tinytim/trunk/build.properties 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/build.properties 2008-05-05 12:37:18 UTC (rev 53) @@ -1,4 +1,4 @@ version=1.5.0 -version_suffix=alpha1 +version_suffix=alpha2 debug=off optimize=on Modified: tinytim/trunk/build.xml =================================================================== --- tinytim/trunk/build.xml 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/build.xml 2008-05-05 12:37:18 UTC (rev 53) @@ -41,6 +41,7 @@ <echo message="Available targets:"/> <echo message=""/> <echo message=" jar Creates the jar"/> + <echo message=" doc Creates the API documentation"/> <echo message=" release Creates the jar and a distributable file"/> </target> @@ -58,7 +59,7 @@ <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="${basedir}/javadocs"/> + <property name="dir.javadocs" value="${dir.dist}/docs/api"/> </target> <!-- =================================================================== --> @@ -132,6 +133,32 @@ </target> <!-- =================================================================== --> + <!-- Creates the Java Docs --> + <!-- =================================================================== --> + <target name="doc" depends="init"> + <mkdir dir="${dir.javadocs}"/> + <javadoc destdir="${dir.javadocs}" + packagenames="org.tinytim.*" + author="true" + version="true" + use="true" + splitindex="true" + noindex="false" + windowtitle="tinyTiM API v${dist.version}" + doctitle="tinyTiM API v${dist.version}"> + <fileset dir="${dir.src}"> + <exclude name="**/*Impl.*"/> + <exclude name="org/tinytim/index/**"/> + <exclude name="org/tinytim/IConstruct*"/> + <exclude name="org/tinytim/IDatatypeAware*"/> + <exclude name="org/tinytim/IRI*"/> + <exclude name="org/tinytim/IEvent*"/> + <exclude name="org/tinytim/Event*"/> + </fileset> + </javadoc> + </target> + + <!-- =================================================================== --> <!-- Creates the jar --> <!-- =================================================================== --> <target name="jar" depends="compile"> @@ -153,7 +180,7 @@ <!-- =================================================================== --> <!-- Prepares a distribution --> <!-- =================================================================== --> - <target name="dist" depends="jar"> + <target name="dist" depends="jar, doc"> <mkdir dir="${dir.dist}"/> <copy todir="${dir.dist}" file="${dir.build}/${tinytim.jar}"/> Added: tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java 2008-05-05 12:37:18 UTC (rev 53) @@ -0,0 +1,209 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.tinytim.index.ITypeInstanceIndex; +import org.tmapi.core.Association; +import org.tmapi.core.AssociationRole; +import org.tmapi.core.Occurrence; +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; + +/** + * Removes duplicates from Topic Maps constructs. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class DuplicateRemovalUtils { + + private DuplicateRemovalUtils() { + // noop. + } + + /** + * Removes duplicate Topic Maps constructs from a topic map. + * + * @param topicMap The topic map to remove the duplicates from. + */ + public static void removeDuplicates(TopicMap topicMap) { + TopicMapImpl tm = (TopicMapImpl) topicMap; + for (Topic topic: tm.getTopics()) { + removeDuplicates(topic); + } + Map<String, Association> sig2Assoc = tm.getCollectionFactory().createMap(); + ITypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + for (Topic type: typeInstanceIdx.getAssociationTypes()) { + _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(type)); + } + _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(null)); + } + + private static void _removeDuplicateAssociations(Map<String, Association> sig2Assoc, Collection<AssociationImpl> assocs) { + sig2Assoc.clear(); + Association existing = null; + String sig = null; + for (Association assoc: assocs) { + removeDuplicates(assoc); + sig = SignatureGenerator.generateSignature(assoc); + existing = sig2Assoc.get(sig); + if (existing != null) { + MergeUtils.moveRoleCharacteristics(assoc, existing); + _removeConstruct(assoc); + } + else { + sig2Assoc.put(sig, assoc); + } + } + } + + /** + * Removes duplicate occurrences and names from a topic. + * + * @param topic The topic from which duplicates should be removed from. + */ + @SuppressWarnings("unchecked") + public static void removeDuplicates(Topic topic) { + _removeDuplicateOccurrences(topic.getOccurrences()); + _removeDuplicateNames(topic.getTopicNames()); + } + + /** + * Removes duplicate variants from a name. + * + * @param name The name from which the duplicates should be removed. + */ + @SuppressWarnings("unchecked") + public static void removeDuplicates(TopicName name) { + Map<String, Variant> sigs = new HashMap<String, Variant>(); + for (Variant variant: new ArrayList<Variant>(name.getVariants())) { + String sig = SignatureGenerator.generateSignature(variant); + Variant existing = sigs.get(sig); + if (existing != null) { + _handleExistingConstruct(variant, existing); + _removeConstruct(variant); + } + else { + sigs.put(sig, variant); + } + } + } + + /** + * + * + * @param occs + */ + private static void _removeDuplicateOccurrences(Collection<Occurrence> occs) { + Map<String, Occurrence> sigs = new HashMap<String, Occurrence>(occs.size()); + Occurrence existing = null; + for (Occurrence occ: new ArrayList<Occurrence>(occs)) { + String sig = SignatureGenerator.generateSignature(occ); + existing = sigs.get(sig); + if (existing != null) { + _handleExistingConstruct(occ, existing); + _removeConstruct(occ); + } + else { + sigs.put(sig, occ); + } + } + } + + /** + * + * + * @param names + */ + private static void _removeDuplicateNames(Collection<TopicName> names) { + Map<String, TopicName> sigs = new HashMap<String, TopicName>(names.size()); + TopicName existing = null; + for (TopicName name: new ArrayList<TopicName>(names)) { + removeDuplicates(name); + String sig = SignatureGenerator.generateSignature(name); + existing = sigs.get(sig); + if (existing != null) { + _handleExistingConstruct(name, existing); + _moveVariants(name, existing); + _removeConstruct(name); + } + else { + sigs.put(sig, name); + } + } + } + + /** + * Removes duplicate roles from an association. + * + * @param assoc The association to remove duplicate roles from. + */ + @SuppressWarnings("unchecked") + public static void removeDuplicates(Association assoc) { + Map<String, AssociationRole> sig2Role = ((TopicMapImpl) assoc.getTopicMap()).getCollectionFactory().createMap(); + AssociationRole existing = null; + String sig = null; + for (AssociationRole role: new ArrayList<AssociationRole>(assoc.getAssociationRoles())) { + sig = SignatureGenerator.generateSignature(role); + existing = sig2Role.get(sig); + if (existing != null) { + _handleExistingConstruct(role, existing); + _removeConstruct(role); + } + else { + sig2Role.put(sig, role); + } + } + } + + /** + * @see {@link MergeUtils#moveVariants(TopicNameImpl, TopicNameImpl)} + */ + private static void _moveVariants(TopicName source, TopicName target) { + MergeUtils.moveVariants((TopicNameImpl)source, (TopicNameImpl)target); + } + + /** + * @see {@link MergeUtils#removeConstruct(IConstruct)} + */ + private static void _removeConstruct(TopicMapObject construct) { + MergeUtils.removeConstruct((IConstruct) construct); + } + + /** + * @see {@link MergeUtils#handleExistingConstruct(IReifiable, IReifiable)} + */ + private static void _handleExistingConstruct(TopicMapObject source, TopicMapObject target) { + MergeUtils.handleExistingConstruct((IReifiable) source, (IReifiable) target); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java 2008-05-05 12:37:18 UTC (rev 53) @@ -30,7 +30,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -interface IDatatypeAwareConstruct extends IConstruct { +public interface IDatatypeAwareConstruct extends IConstruct { /** * The value of this Topic Maps construct. Modified: tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-05-05 12:37:18 UTC (rev 53) @@ -25,9 +25,9 @@ import java.util.List; import java.util.Map; +import org.tinytim.index.IIndexManager; import org.tinytim.index.IScopedIndex; import org.tinytim.index.ITypeInstanceIndex; -import org.tinytim.index.IndexManager; import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.Locator; @@ -266,7 +266,7 @@ */ private static void _replaceTopics(Topic source, Topic replacement) { TopicMapImpl tm = (TopicMapImpl) replacement.getTopicMap(); - IndexManager idxMan = tm.getIndexManager(); + IIndexManager idxMan = tm.getIndexManager(); ITypeInstanceIndex typeInstanceIndex = idxMan.getTypeInstanceIndex(); if (!typeInstanceIndex.isAutoUpdated()) { typeInstanceIndex.reindex(); Modified: tinytim/trunk/src/main/java/org/tinytim/Property.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Property.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/Property.java 2008-05-05 12:37:18 UTC (rev 53) @@ -56,4 +56,14 @@ */ public static final String XTM10_REIFICATION = "org.tinytim.XTM10Reification"; + /** + * Property which indicates if the variant's parent scope is included + * in the {@link org.tmapi.core.Variant#getScope()} return value. + * + * This property is disabled by default. + * + * If enabled, the variants scope is the union of its own scope and + * the parent name's scope. + */ + public static final String INHERIT_NAME_SCOPE = "org.tinytim.InheritNameScope"; } Modified: tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java 2008-05-05 12:37:18 UTC (rev 53) @@ -20,6 +20,7 @@ */ package org.tinytim; +import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -44,7 +45,7 @@ */ public static Set<TopicMapObject> getReified(Topic reifier) { TopicMapImpl tm = (TopicMapImpl) reifier.getTopicMap(); - Set<TopicMapObject> reified = tm.getCollectionFactory().createSet(); + Set<TopicMapObject> reified = new HashSet<TopicMapObject>(); for (Locator sid: ((TopicImpl) reifier).getSubjectIdentifiers()) { TopicMapObject obj = tm.getObjectByItemIdentifier(sid); if (obj != null) { Modified: tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -29,6 +29,7 @@ import java.util.Set; import org.tinytim.index.IndexManager; +import org.tinytim.index.IIndexManager; import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.HelperObjectConfigurationException; @@ -88,6 +89,7 @@ private EventMultiplier _eventMultiplier; private Map<String, Object> _helperObjects; boolean _oldReification; + boolean _inheritNameScope; TopicMapImpl(TopicMapSystemImpl sys, Locator locator) { super(null); @@ -100,9 +102,11 @@ _evtHandlers = _collectionFactory.createMap(); _helperObjects = _collectionFactory.createMap(); _identityManager = new IdentityManager(this); + //TODO: Makes this configurable _indexManager = new IndexManager(this, _collectionFactory); _eventMultiplier = new EventMultiplier(this); _oldReification = "true".equalsIgnoreCase(sys.getProperty(Property.XTM10_REIFICATION)); + _inheritNameScope = "true".equalsIgnoreCase(sys.getProperty(Property.INHERIT_NAME_SCOPE)); } ICollectionFactory getCollectionFactory() { @@ -407,7 +411,7 @@ } } - public IndexManager getIndexManager() { + public IIndexManager getIndexManager() { return _indexManager; } Modified: tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -60,6 +60,7 @@ _features.put(feature.name, feature.defaultValue); } _properties.setProperty(Property.XTM10_REIFICATION, "true"); + _properties.setProperty(Property.INHERIT_NAME_SCOPE, "false"); _properties.setProperty(Property.COLLECTION_FACTORY, _COLL_FACTORY_JAVA); try { // Probe if Trove is available. Modified: tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-05-05 12:37:18 UTC (rev 53) @@ -20,9 +20,9 @@ */ package org.tinytim; +import org.tinytim.index.IIndexManager; import org.tinytim.index.IScopedIndex; import org.tinytim.index.ITypeInstanceIndex; -import org.tinytim.index.IndexManager; import org.tmapi.core.Topic; /** @@ -76,7 +76,7 @@ if (!topic.getRolesPlayed().isEmpty()) { return false; } - IndexManager idxMan = ((TopicMapImpl) topic.getTopicMap()).getIndexManager(); + IIndexManager idxMan = ((TopicMapImpl) topic.getTopicMap()).getIndexManager(); ITypeInstanceIndex typeInstanceIdx = idxMan.getTypeInstanceIndex(); if (!typeInstanceIdx.isAutoUpdated()) { typeInstanceIdx.reindex(); Added: tinytim/trunk/src/main/java/org/tinytim/TypeInstanceConverter.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TypeInstanceConverter.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/TypeInstanceConverter.java 2008-05-05 12:37:18 UTC (rev 53) @@ -0,0 +1,171 @@ +/* + * 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; + +import java.util.Collection; +import java.util.logging.Logger; + +import org.tinytim.index.ITypeInstanceIndex; +import org.tinytim.voc.TMDM; +import org.tinytim.voc.XTM10; +import org.tmapi.core.Association; +import org.tmapi.core.AssociationRole; +import org.tmapi.core.Locator; +import org.tmapi.core.TMAPIException; +import org.tmapi.core.TMAPIRuntimeException; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; + +/** + * This class provides functions that can be used to convert the type-instance + * relationships that are modelled as associations into the [types] property + * of {@link org.tmapi.core.Topic}s. + * + * Copied from the TMAPIX-project. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class TypeInstanceConverter { + + //TODO: Implement types -> associations + + private static final Logger LOG = Logger.getLogger(TypeInstanceConverter.class.getName()); + + private TypeInstanceConverter() { + // noop. + } + + /** + * Converts type-instance relationships (TMDM 1.0) and class-instance + * relationships into the [types] property of the {@link org.tmapi.core.Topic}. + * + * @see #convertTMDMAssociationsToTypes(TopicMap) + * @see #convertXTMAssociationsToTypes(TopicMap) + * + * @param topicMap The topic map to convert. + */ + public static void convertAssociationsToTypes(TopicMap topicMap) { + convertTMDMAssociationsToTypes(topicMap); + convertXTMAssociationsToTypes(topicMap); + } + + /** + * Converts class-instance relationships (XTM 1.0) into the [types] property + * of {@link org.tmapi.core.Topic}s. The associations are removed from the + * topic map. + * + * @param topicMap The topic map to convert. + */ + public static void convertXTMAssociationsToTypes(TopicMap topicMap) { + _associationsToTypes(topicMap, XTM10.CLASS_INSTANCE, + XTM10.CLASS, XTM10.INSTANCE); + } + + /** + * Converts type-instance relationships (TMDM 1.0) into the [types] property + * of {@link org.tmapi.core.Topic}s. The associations are removed from the + * topic map. + * + * @param topicMap The topic map to convert. + */ + public static void convertTMDMAssociationsToTypes(TopicMap topicMap) { + _associationsToTypes(topicMap, TMDM.TYPE_INSTANCE, + TMDM.TYPE, TMDM.INSTANCE); + } + + private static void _associationsToTypes(TopicMap topicMap, + Locator typeInstance_, Locator type_, Locator instance_) { + TopicMapImpl tm = (TopicMapImpl) topicMap; + Topic typeInstance = tm.getTopicBySubjectIdentifier(typeInstance_); + if (typeInstance == null) { + return; + } + Topic type = tm.getTopicBySubjectIdentifier(type_); + if (type == null) { + return; + } + Topic instance = tm.getTopicBySubjectIdentifier(instance_); + if (instance == null) { + return; + } + ITypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + for (Association assoc: typeInstanceIdx.getAssociations(typeInstance)) { + Topic[] pair = _getTypeInstancePair(assoc, type, instance); + if (pair == null) { + continue; + } + pair[1].addType(pair[0]); + try { + assoc.remove(); + } + catch (TMAPIException ex) { + throw new TMAPIRuntimeException(ex); + } + } + } + + private static void _info(Association assoc, String msg) { + LOG.info("The association (ID: '" + assoc.getObjectId() + "') cannot be converted into a type. Reason: " + msg); + } + + @SuppressWarnings("unchecked") + private static Topic[] _getTypeInstancePair(Association assoc, Topic type, Topic instance) { + Collection<AssociationRole> roles = assoc.getAssociationRoles(); + if (roles.size() != 2) { + _info(assoc, "Not a binary association."); + return null; + } + if (assoc.getReifier() != null) { + _info(assoc, "It is reified"); + return null; + } + if (!assoc.getSourceLocators().isEmpty()) { + _info(assoc, "It as item identifiers"); + return null; + } + if (!assoc.getScope().isEmpty()) { + _info(assoc, "The scope is not unconstrained"); + return null; + } + Topic[] pair = new Topic[2]; + for (AssociationRole role: roles) { + if (type.equals(role.getType())) { + pair[0] = role.getPlayer(); + } + else if (instance.equals(role.getType())) { + pair[1] = role.getPlayer(); + } + } + if (pair[0] == null) { + _info(assoc, "The type player is null."); + return null; + } + if (pair[1] == null) { + _info(assoc, "The instance player is null"); + return null; + } + return pair; + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/TypeInstanceConverter.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -21,6 +21,7 @@ package org.tinytim; import java.util.Collection; +import java.util.Set; import org.tmapi.core.Locator; import org.tmapi.core.TMAPIException; @@ -53,6 +54,22 @@ } /* (non-Javadoc) + * @see org.tinytim.Scoped#getScope() + */ + @Override + public Set<Topic> getScope() { + if (_tm == null || _parent == null || !_tm._inheritNameScope) { + return super.getScope(); + } + else { + Set<Topic> scope = _tm.getCollectionFactory().createSet(); + scope.addAll(super.getScope()); + scope.addAll(((IScoped) _parent).getScope()); + return scope; + } + } + + /* (non-Javadoc) * @see org.tinytim.IMovable#moveTo(java.lang.Object) */ public void moveTo(TopicName newParent) { Added: tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java 2008-05-05 12:37:18 UTC (rev 53) @@ -0,0 +1,44 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.index; + +/** + * The index manager provides access to the tinyTiM-specific indexes. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IIndexManager { + + /** + * Returns the {@link ITypeInstanceIndex}. + * + * @return A {@link ITypeInstanceIndex} instance. + */ + public ITypeInstanceIndex getTypeInstanceIndex(); + + /** + * Returns the {@link IScopedIndex}. + * + * @return A {@link IScopedIndex} instance. + */ + public IScopedIndex getScopedIndex(); +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java 2008-05-05 12:37:18 UTC (rev 53) @@ -24,12 +24,13 @@ import org.tinytim.IEventPublisher; /** + * {@link IIndexManager} implementation which provides autoupdated default + * indexes. * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -public final class IndexManager { +public final class IndexManager implements IIndexManager { private ITypeInstanceIndex _typeInstanceIndex; private IScopedIndex _scopedIndex; @@ -39,10 +40,16 @@ _scopedIndex = new ScopedIndex(publisher, collFactory); } + /* (non-Javadoc) + * @see org.tinytim.index.IIndexManager#getTypeInstanceIndex() + */ public ITypeInstanceIndex getTypeInstanceIndex() { return _typeInstanceIndex; } + /* (non-Javadoc) + * @see org.tinytim.index.IIndexManager#getScopedIndex() + */ public IScopedIndex getScopedIndex() { return _scopedIndex; } Modified: tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java 2008-05-05 12:37:18 UTC (rev 53) @@ -77,7 +77,7 @@ public Collection<AssociationImpl> getAssociationsByTheme(Topic theme) { List<AssociationImpl> assocs = _theme2Assocs.get(theme); return assocs == null ? Collections.<AssociationImpl>emptySet() - : Collections.unmodifiableCollection(assocs); + : new ArrayList<AssociationImpl>(assocs); } /* (non-Javadoc) @@ -95,7 +95,7 @@ public Collection<OccurrenceImpl> getOccurrencesByTheme(Topic theme) { List<OccurrenceImpl> occs = _theme2Occs.get(theme); return occs == null ? Collections.<OccurrenceImpl>emptySet() - : Collections.unmodifiableCollection(occs); + : new ArrayList<OccurrenceImpl>(occs); } /* (non-Javadoc) @@ -113,7 +113,7 @@ public Collection<TopicNameImpl> getNamesByTheme(Topic theme) { List<TopicNameImpl> names = _theme2Names.get(theme); return names == null ? Collections.<TopicNameImpl>emptySet() - : Collections.unmodifiableCollection(names); + : new ArrayList<TopicNameImpl>(names); } /* (non-Javadoc) @@ -131,7 +131,7 @@ public Collection<VariantImpl> getVariantsByTheme(Topic theme) { List<VariantImpl> vars = _theme2Variants.get(theme); return vars == null ? Collections.<VariantImpl>emptySet() - : Collections.unmodifiableCollection(vars); + : new ArrayList<VariantImpl>(vars); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -39,9 +39,13 @@ public class AssociationRolesIndexImpl extends AbstractTMAPIIndex implements AssociationRolesIndex { + private final IndexFlags _indexFlags; + public AssociationRolesIndexImpl(TopicMapImpl topicMap, ICollectionFactory collFactory) { super(topicMap, collFactory); + _indexFlags = topicMap.getIndexManager().getTypeInstanceIndex().isAutoUpdated() ? + IndexFlagsImpl.AUTOUPDATED : IndexFlagsImpl.NOT_AUTOUPDATED; } /* (non-Javadoc) @@ -62,14 +66,16 @@ * @see org.tmapi.index.Index#getFlags() */ public IndexFlags getFlags() throws TMAPIIndexException { - return IndexFlagsImpl.AUTOUPDATED; + return _indexFlags; } /* (non-Javadoc) * @see org.tmapi.index.Index#reindex() */ public void reindex() throws TMAPIIndexException { - // noop. + if (_indexFlags != IndexFlagsImpl.AUTOUPDATED) { + _weakTopicMap.get().getIndexManager().getTypeInstanceIndex().reindex(); + } } } Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -39,9 +39,13 @@ public class AssociationsIndexImpl extends AbstractTMAPIIndex implements AssociationsIndex { + private final IndexFlags _indexFlags; + public AssociationsIndexImpl(TopicMapImpl topicMap, ICollectionFactory collFactory) { super(topicMap, collFactory); + _indexFlags = topicMap.getIndexManager().getTypeInstanceIndex().isAutoUpdated() ? + IndexFlagsImpl.AUTOUPDATED : IndexFlagsImpl.NOT_AUTOUPDATED; } /* (non-Javadoc) @@ -62,14 +66,16 @@ * @see org.tmapi.index.Index#getFlags() */ public IndexFlags getFlags() throws TMAPIIndexException { - return IndexFlagsImpl.AUTOUPDATED; + return _indexFlags; } /* (non-Javadoc) * @see org.tmapi.index.Index#reindex() */ public void reindex() throws TMAPIIndexException { - // noop. + if (_indexFlags != IndexFlagsImpl.AUTOUPDATED) { + _weakTopicMap.get().getIndexManager().getTypeInstanceIndex().reindex(); + } } } Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -107,29 +106,39 @@ public void reindex() throws TMAPIIndexException { _value2Occs.clear(); _loc2Occs.clear(); - for (Topic topic: _weakTopicMap.get().getTopics()) { - for (Iterator<Occurrence> iter = topic.getOccurrences().iterator(); iter.hasNext();) { - Occurrence occ = iter.next(); - if (occ.getValue() != null) { - String value = occ.getValue(); - List<Occurrence> occs = _value2Occs.get(value); - if (occs == null) { - occs = new ArrayList<Occurrence>(); - _value2Occs.put(value, occs); - } - occs.add(occ); - } - else if (occ.getResource() != null) { - Locator loc = occ.getResource(); - List<Occurrence> occs = _loc2Occs.get(loc); - if (occs == null) { - occs = new ArrayList<Occurrence>(); - _loc2Occs.put(loc, occs); - } - occs.add(occ); - } + ITypeInstanceIndex typeInstanceIdx = _weakTopicMap.get().getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + for (Topic type: typeInstanceIdx.getOccurrenceTypes()) { + for (Occurrence occ: typeInstanceIdx.getOccurrences(type)) { + _index(occ); } } + for (Occurrence occ: typeInstanceIdx.getOccurrences(null)) { + _index(occ); + } } + private void _index(Occurrence occ) { + if (occ.getValue() != null) { + String value = occ.getValue(); + List<Occurrence> occs = _value2Occs.get(value); + if (occs == null) { + occs = new ArrayList<Occurrence>(); + _value2Occs.put(value, occs); + } + occs.add(occ); + } + else if (occ.getResource() != null) { + Locator loc = occ.getResource(); + List<Occurrence> occs = _loc2Occs.get(loc); + if (occs == null) { + occs = new ArrayList<Occurrence>(); + _loc2Occs.put(loc, occs); + } + occs.add(occ); + } + } + } Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ScopedObjectsIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ScopedObjectsIndexImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ScopedObjectsIndexImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -44,9 +44,13 @@ public class ScopedObjectsIndexImpl extends AbstractTMAPIIndex implements ScopedObjectsIndex { + private final IndexFlags _indexFlags; + public ScopedObjectsIndexImpl(TopicMapImpl topicMap, ICollectionFactory collFactory) { super(topicMap, collFactory); + _indexFlags = topicMap.getIndexManager().getScopedIndex().isAutoUpdated() ? + IndexFlagsImpl.AUTOUPDATED : IndexFlagsImpl.NOT_AUTOUPDATED; } private IScopedIndex _getScopedIndex() { @@ -102,14 +106,16 @@ * @see org.tmapi.index.Index#getFlags() */ public IndexFlags getFlags() throws TMAPIIndexException { - return IndexFlagsImpl.AUTOUPDATED; + return _indexFlags; } /* (non-Javadoc) * @see org.tmapi.index.Index#reindex() */ public void reindex() throws TMAPIIndexException { - // noop. + if (_indexFlags != IndexFlagsImpl.AUTOUPDATED) { + _weakTopicMap.get().getIndexManager().getScopedIndex().reindex(); + } } } Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -94,18 +93,28 @@ @SuppressWarnings("unchecked") public void reindex() throws TMAPIIndexException { _value2Names.clear(); - for (Topic topic: _weakTopicMap.get().getTopics()) { - for (Iterator<TopicName> iter = topic.getTopicNames().iterator(); iter.hasNext();) { - TopicName name = iter.next(); - String value = name.getValue(); - List<TopicName> names = _value2Names.get(value); - if (names == null) { - names = new ArrayList<TopicName>(); - _value2Names.put(value, names); - } - names.add(name); + ITypeInstanceIndex typeInstanceIdx = _weakTopicMap.get().getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + for (Topic type: typeInstanceIdx.getNameTypes()) { + for (TopicName name: typeInstanceIdx.getNames(type)) { + _index(name); } } + for (TopicName name: typeInstanceIdx.getNames(null)) { + _index(name); + } } + private void _index(TopicName name) { + String value = name.getValue(); + List<TopicName> names = _value2Names.get(value); + if (names == null) { + names = new ArrayList<TopicName>(); + _value2Names.put(value, names); + } + names.add(name); + } + } Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -29,6 +29,7 @@ import org.tinytim.ICollectionFactory; import org.tinytim.TopicMapImpl; +import org.tinytim.index.ITypeInstanceIndex; import org.tmapi.core.Locator; import org.tmapi.core.Topic; import org.tmapi.core.TopicName; @@ -88,31 +89,43 @@ public void reindex() throws TMAPIIndexException { _value2Variants.clear(); _loc2Variants.clear(); - for (Topic topic: _weakTopicMap.get().getTopics()) { - for (Iterator<TopicName> nameIter = topic.getTopicNames().iterator(); nameIter.hasNext();) { - for (Iterator<Variant> iter = nameIter.next().getVariants().iterator(); iter.hasNext();) { - Variant variant = iter.next(); - if (variant.getValue() != null) { - String value = variant.getValue(); - List<Variant> variants = _value2Variants.get(value); - if (variants == null) { - variants = new ArrayList<Variant>(); - _value2Variants.put(value, variants); - } - variants.add(variant); - } - else if (variant.getResource() != null) { - Locator loc = variant.getResource(); - List<Variant> variants = _loc2Variants.get(loc); - if (variants == null) { - variants = new ArrayList<Variant>(); - _loc2Variants.put(loc, variants); - } - variants.add(variant); - } + ITypeInstanceIndex typeInstanceIdx = _weakTopicMap.get().getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + for (Topic type: typeInstanceIdx.getNameTypes()) { + for (TopicName name: typeInstanceIdx.getNames(type)) { + for (Iterator<Variant> iter = name.getVariants().iterator(); iter.hasNext();) { + _index(iter.next()); } } } + for (TopicName name: typeInstanceIdx.getNames(null)) { + for (Iterator<Variant> iter = name.getVariants().iterator(); iter.hasNext();) { + _index(iter.next()); + } + } } + private void _index(Variant variant) { + if (variant.getValue() != null) { + String value = variant.getValue(); + List<Variant> variants = _value2Variants.get(value); + if (variants == null) { + variants = new ArrayList<Variant>(); + _value2Variants.put(value, variants); + } + variants.add(variant); + } + else if (variant.getResource() != null) { + Locator loc = variant.getResource(); + List<Variant> variants = _loc2Variants.get(loc); + if (variants == null) { + variants = new ArrayList<Variant>(); + _loc2Variants.put(loc, variants); + } + variants.add(variant); + } + } + } Added: tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java 2008-05-05 12:37:18 UTC (rev 53) @@ -0,0 +1,86 @@ +/* + * 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.voc; + +import org.tinytim.IRI; +import org.tmapi.core.Locator; + +/** + * Constants for TMDM 1.0 (model) PSIs. + * + * Copied from the Semagia MIO project. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class TMDM { + + private static final String _BASE = "http://psi.topicmaps.org/iso13250/model/"; + + /** + * Core concept of type-instance relationships. + * Used as association type. + */ + public static final Locator TYPE_INSTANCE = new IRI(_BASE + "type-instance"); + + /** + * Core concept of type within a type-instance relationship. + * Used as role type. + */ + public static final Locator TYPE = new IRI(_BASE + "type"); + + /** + * Core concept of instance within a type-instance relationship. + * Used as role type. + */ + public static final Locator INSTANCE = new IRI(_BASE + "instance"); + + /** + * Core concept of supertype-subtype relationship. + * Used as association type. + */ + public static final Locator SUPERTYPE_SUBTYPE = new IRI(_BASE + "supertype-subtype"); + + /** + * Core concept of supertype within a supertype-subtype relationship. + * Used as role type. + */ + public static final Locator SUPERTYPE = new IRI(_BASE + "supertype"); + + /** + * Core concept of subtype within a supertype-subtype relationship. + * Used as role type. + */ + public static final Locator SUBTYPE = new IRI(_BASE + "subtype"); + + /** + * Core concept of a topic name. + * Used as topic name type. + */ + public static final Locator TOPIC_NAME = new IRI(_BASE + "topic-name"); + + /** + * Used to indicate that a variant can be used for sorting purposes. + * Used as variant theme. + */ + public static final Locator SORT = new IRI(_BASE + "sort"); +} + Property changes on: tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java 2008-05-05 12:37:18 UTC (rev 53) @@ -0,0 +1,105 @@ +/* + * 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.voc; + +import org.tinytim.IRI; +import org.tmapi.core.Locator; + +/** + * Constants for XTM 1.0 PSIs. + * + * The XTM 1.0 PSIs are outdated and have no relevance for the + * Topic Maps Data Model. These constants are provided for (de-)serializing + * topic maps which depend on the XTM 1.0 "model" but they should not be + * used for new topic maps, use {@link TMDM}. + * + * Copied from the Semagia MIO project. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class XTM10 { + + private static final String _BASE = "http://www.topicmaps.org/xtm/1.0/core.xtm#"; + + /** + * The core concept of class-instance; the class of association that + * represents class-instance relationships between topics, and that is + * semantically equivalent to the use of <instanceOf> subelements. + */ + public static final Locator CLASS_INSTANCE = new IRI(_BASE + "class-instance"); + + /** + * The core concept of class; the role of class as played by one of the + * members of a class-instance association. + */ + public static final Locator CLASS = new IRI(_BASE + "class"); + + /** + * The core concept of instance; the role of instance as played by one of + * the members of a class-instance association. + */ + public static final Locator INSTANCE = new IRI(_BASE + "instance"); + + /** + * The core concept of superclass-subclass; the class of association that + * represents superclass-subclass relationships between topics. + */ + public static final Locator SUPERCLASS_SUBCLASS = new IRI(_BASE + "superclass-subclass"); + + /** + * The core concept of superclass; the role of superclass as played by one + * of the members of a superclass-subclass association. + */ + public static final Locator SUPERCLASS = new IRI(_BASE + "superclass"); + + /** + * The core concept of subclass; the role of subclass as played by one of + * the members of a superclass-subclass association. + */ + public static final Locator SUBCLASS = new IRI(_BASE + "subclass"); + + /** + * The core concept of association; the generic class to which all + * associations belong unless otherwise specified. + */ + public static final Locator ASSOCIATION = new IRI(_BASE + "association"); + + /** + * The core concept of occurrence; the generic class to which all + * occurrences belong unless otherwise specified. + */ + public static final Locator OCCURRENCE = new IRI(_BASE + "occurrence"); + + /** + * Used to indicate that a variant can be used for sorting purposes. + * Used as variant theme. + */ + public static final Locator SORT = new IRI(_BASE + "sort"); + + /** + * Used to indicate that a variant can be used for displaying purposes. + * Used as variant theme. + */ + public static final Locator DISPLAY = new IRI(_BASE + "display"); + +} + Property changes on: tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/test/java/org/tinytim/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/AllTests.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/test/java/org/tinytim/AllTests.java 2008-05-05 12:37:18 UTC (rev 53) @@ -41,6 +41,7 @@ public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(TestConstruct.class); + suite.addTestSuite(TestDuplicateRemovalUtils.class); suite.addTestSuite(TestItemIdentifierConstraint.class); suite.addTestSuite(TestReifiable.class); suite.addTestSuite(TestScoped.class); Added: tinytim/trunk/src/test/java/org/tinytim/TestDuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestDuplicateRemovalUtils.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/TestDuplicateRemovalUtils.java 2008-05-05 12:37:18 UTC (rev 53) @@ -0,0 +1,107 @@ +/* + * 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; + +import java.util.Arrays; +import java.util.Collection; + +import org.tmapi.core.Association; +import org.tmapi.core.Locator; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicName; + +/** + * Tests against the {@link DuplicateRemovalUtils}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestDuplicateRemovalUtils extends TinyTimTestCase { + + public void testTopicRemoveNames() { + Topic topic = _tm.createTopic(); + TopicName name1 = topic.createTopicName("tinyTiM", null); + TopicName name2 = topic.createTopicName("tinyTiM", null); + assertNull(name1.getType()); + assertTrue(name1.getScope().isEmpty()); + assertNull(name2.getType()); + assertTrue(name2.getScope().isEmpty()); + assertEquals(2, topic.getTopicNames().size()); + DuplicateRemovalUtils.removeDuplicates(topic); + assertEquals(1, topic.getTopicNames().size()); + TopicName name = (TopicName) topic.getTopicNames().iterator().next(); + assertEquals("tinyTiM", name.getValue()); + assertNull(name.getType()); + assertTrue(name.getScope().isEmpty()); + } + + public void testTopicRemoveNames2() { + Topic topic = _tm.createTopic(); + TopicName name1 = topic.createTopicName("tinyTiM", null); + TopicName name2 = topic.createTopicName("tinyTiM", null); + Locator iid1 = _tm.createLocator("http://example.org/iid-1"); + Locator iid2 = _tm.createLocator("http://example.org/iid-2"); + name1.addSourceLocator(iid1); + name2.addSourceLocator(iid2); + assertEquals(2, topic.getTopicNames().size()); + DuplicateRemovalUtils.removeDuplicates(topic); + assertEquals(1, topic.getTopicNames().size()); + TopicName name = (TopicName) topic.getTopicNames().iterator().next(); + assertEquals("tinyTiM", name.getValue()); + assertNull(name.getType()); + assertTrue(name.getScope().isEmpty()); + assertEquals(2, name.getSourceLocators().size()); + assertTrue(name.getSourceLocators().contains(iid1)); + assertTrue(name.getSourceLocators().contains(iid2)); + } + + public void testTopicRemoveNames3() { + Topic topic = _tm.createTopic(); + Topic theme1 = _tm.createTopic(); + Topic theme2 = _tm.createTopic(); + Collection<Topic> scope1 = Arrays.asList(new Topic[] {theme1, theme2}); + Collection<Topic> scope2 = Arrays.asList(new Topic[] {theme2, theme1}); + TopicName name1 = topic.createTopicName("tinyTiM", scope1); + TopicName name2 = topic.createTopicName("tinyTiM", scope2); + assertEquals(2, name1.getScope().size()); + assertEquals(2, name2.getScope().size()); + assertEquals(2, topic.getTopicNames().size()); + DuplicateRemovalUtils.removeDuplicates(topic); + assertEquals(1, topic.getTopicNames().size()); + TopicName name = (TopicNa... [truncated message content] |
From: <lh...@us...> - 2008-05-02 10:49:51
|
Revision: 52 http://tinytim.svn.sourceforge.net/tinytim/?rev=52&view=rev Author: lheuer Date: 2008-05-02 03:49:55 -0700 (Fri, 02 May 2008) Log Message: ----------- - Removed logging for the endTopicMap event Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-04-29 13:15:34 UTC (rev 51) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-05-02 10:49:55 UTC (rev 52) @@ -97,9 +97,6 @@ * @see com.semagia.mio.IMapHandler#endTopicMap() */ public void endTopicMap() throws MIOException { - if (_state() != State.INITIAL) { - LOG.warning("The topic map import seems to be unfinished due to errors"); - } TypeInstanceConverter.convertAssociationsToTypes(_tm); _constructStack = null; _stateStack = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-04-29 13:15:55
|
Revision: 51 http://tinytim.svn.sourceforge.net/tinytim/?rev=51&view=rev Author: lheuer Date: 2008-04-29 06:15:34 -0700 (Tue, 29 Apr 2008) Log Message: ----------- - Minor bug fixes - More tests Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-04-28 18:42:12 UTC (rev 50) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-04-29 13:15:34 UTC (rev 51) @@ -27,6 +27,7 @@ import org.tinytim.IReifiable; import org.tinytim.ITyped; import org.tinytim.TopicMapImpl; +import org.tinytim.TypeInstanceConverter; import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.Locator; @@ -65,6 +66,14 @@ private int _stackPointer; private List<TopicMapObject> _constructStack; + public MapInputHandler() { + } + + public MapInputHandler(TopicMap topicMap) { + this(); + setTopicMap(topicMap); + } + /** * Sets the topic map instance to operate on. * @@ -91,7 +100,7 @@ if (_state() != State.INITIAL) { LOG.warning("The topic map import seems to be unfinished due to errors"); } - //TODO: Convert type-instance assocs. + TypeInstanceConverter.convertAssociationsToTypes(_tm); _constructStack = null; _stateStack = null; _tm = null; @@ -354,7 +363,7 @@ */ public void value(String value, String datatype) throws MIOException { boolean isLocator = _XSD_ANY_URI.equals(datatype); - if (!isLocator && _XSD_STRING.equals(datatype)) { + if (!isLocator && !_XSD_STRING.equals(datatype)) { LOG.warning("The datatype '" + datatype + "' was converted into xsd:string"); } if (_state() == State.OCCURRENCE) { Modified: tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-04-28 18:42:12 UTC (rev 50) +++ tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-04-29 13:15:34 UTC (rev 51) @@ -22,6 +22,8 @@ import org.tinytim.Property; import org.tinytim.TopicMapImpl; +import org.tmapi.core.Locator; +import org.tmapi.core.Occurrence; import org.tmapi.core.Topic; import org.tmapi.core.TopicMapSystem; import org.tmapi.core.TopicMapSystemFactory; @@ -39,6 +41,9 @@ */ public class TestMapInputHandler extends TestCase { + private static final String _XSD_STRING = "http://www.w3.org/2001/XMLSchema#string"; + private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; + private TopicMapImpl _tm; private MapInputHandler _handler; @@ -55,6 +60,9 @@ _handler.setTopicMap(_tm); } + /** + * Simple startTopicMap, followed by an endTopicMap event. + */ public void testEmpty() throws Exception { assertEquals(0, _tm.getTopics().size()); assertEquals(0, _tm.getAssociations().size()); @@ -64,6 +72,9 @@ assertEquals(0, _tm.getAssociations().size()); } + /** + * Tests topic creation with an item identifier. + */ public void testTopicIdentityItemIdentifier() throws Exception { String itemIdent = "http://sf.net/projects/tinytim/test#1"; _handler.startTopicMap(); @@ -75,6 +86,9 @@ assertNotNull(topic); } + /** + * Tests topic creation with a subject identifier. + */ public void testTopicIdentitySubjectIdentifier() throws Exception { String subjIdent = "http://sf.net/projects/tinytim/test#1"; _handler.startTopicMap(); @@ -86,6 +100,9 @@ assertNotNull(topic); } + /** + * Tests topic creation with a subject locator. + */ public void testTopicIdentitySubjectLocator() throws Exception { String subjLoc = "http://sf.net/projects/tinytim/test#1"; _handler.startTopicMap(); @@ -97,11 +114,15 @@ assertNotNull(topic); } - public void testTopicMerging1() throws Exception { + /** + * Tests transparent merging. + */ + public void testTopicMerging() throws Exception { String ref = "http://sf.net/projects/tinytim/test#1"; String itemIdent = "http://example.org/1"; _handler.startTopicMap(); _handler.startTopic(Ref.createSubjectIdentifier(ref)); + // Topic in topic event _handler.startTopic(Ref.createItemIdentifier(itemIdent)); _handler.itemIdentifier(ref); _handler.endTopic(); @@ -120,6 +141,43 @@ assertEquals("tinyTiM", name.getValue()); } + /** + * Tests assigning identities to a topic. + */ + public void testTopicIdentities1() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.itemIdentifier(ref); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Locator loc = _tm.createLocator(ref); + Topic topic = _tm.getTopicBySubjectIdentifier(loc); + assertNotNull(topic); + assertEquals(topic, _tm.getObjectByItemIdentifier(loc)); + } + + /** + * Tests assigning identities to a topic. + */ + public void testTopicIdentities2() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createItemIdentifier(ref)); + _handler.subjectIdentifier(ref); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Locator loc = _tm.createLocator(ref); + Topic topic = _tm.getTopicBySubjectIdentifier(loc); + assertNotNull(topic); + assertEquals(topic, _tm.getObjectByItemIdentifier(loc)); + } + + /** + * Tests reifying the topic map. + */ public void testTopicMapReifier() throws Exception { String ref = "http://sf.net/projects/tinytim/test#1"; _handler.startTopicMap(); @@ -134,4 +192,43 @@ assertEquals(topic, _tm.getReifier()); } + /** + * Tests occurrence creation with a value of datatype xsd:string. + */ + public void testOccurrenceValueString() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "tinyTiM"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startOccurrence(); + _handler.value(val, _XSD_STRING); + _handler.endOccurrence(); + _handler.endTopic(); + _handler.endTopicMap(); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); + assertEquals(val, occ.getValue()); + } + + /** + * Tests occurrence creation with a value of datatype xsd:anyURI. + */ + public void testOccurrenceValueURI() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String val = "http://sf.net/projects/tinytim"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startOccurrence(); + _handler.value(val, _XSD_ANY_URI); + _handler.endOccurrence(); + _handler.endTopic(); + _handler.endTopicMap(); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + Occurrence occ = (Occurrence) topic.getOccurrences().iterator().next(); + assertNull(occ.getValue()); + assertEquals(val, occ.getResource().getReference()); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-04-28 18:42:35
|
Revision: 50 http://tinytim.svn.sourceforge.net/tinytim/?rev=50&view=rev Author: lheuer Date: 2008-04-28 11:42:12 -0700 (Mon, 28 Apr 2008) Log Message: ----------- - subjectIdentifier / itemIdentifier events: add subject identifier / item identifier even if a topic with the item identifier / subject identifier was found Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java =================================================================== --- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-04-28 13:19:37 UTC (rev 49) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-04-28 18:42:12 UTC (rev 50) @@ -517,6 +517,9 @@ 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(); @@ -538,6 +541,7 @@ TopicMapObject tmo = _tm.getObjectByItemIdentifier(sid); if (tmo instanceof Topic) { topic = (Topic) tmo; + topic.addSubjectIdentifier(sid); } } if (topic == null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-04-28 13:20:02
|
Revision: 49 http://tinytim.svn.sourceforge.net/tinytim/?rev=49&view=rev Author: lheuer Date: 2008-04-28 06:19:37 -0700 (Mon, 28 Apr 2008) Log Message: ----------- - Moved test / main into the right subdir Modified Paths: -------------- tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java Added Paths: ----------- tinytim-mio/trunk/src/main/ tinytim-mio/trunk/src/test/ Removed Paths: ------------- tinytim-mio/trunk/main/ tinytim-mio/trunk/test/ Copied: tinytim-mio/trunk/src/main (from rev 47, tinytim-mio/trunk/main) Modified: tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java =================================================================== --- tinytim-mio/trunk/main/java/org/tinytim/mio/MapInputHandler.java 2008-04-28 13:16:22 UTC (rev 47) +++ tinytim-mio/trunk/src/main/java/org/tinytim/mio/MapInputHandler.java 2008-04-28 13:19:37 UTC (rev 49) @@ -46,7 +46,7 @@ * {@link com.semagia.mio.IMapHandler} implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class MapInputHandler implements IMapHandler { Copied: tinytim-mio/trunk/src/test (from rev 47, tinytim-mio/trunk/test) Modified: tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java =================================================================== --- tinytim-mio/trunk/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-04-28 13:16:22 UTC (rev 47) +++ tinytim-mio/trunk/src/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-04-28 13:19:37 UTC (rev 49) @@ -35,7 +35,7 @@ * Tests against the {@link org.tinytim.mio.MapInputHandler}. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestMapInputHandler extends TestCase { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-04-28 13:18:26
|
Revision: 48 http://tinytim.svn.sourceforge.net/tinytim/?rev=48&view=rev Author: lheuer Date: 2008-04-28 06:18:24 -0700 (Mon, 28 Apr 2008) Log Message: ----------- Added Paths: ----------- tinytim-mio/trunk/src/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-04-28 13:16:19
|
Revision: 47 http://tinytim.svn.sourceforge.net/tinytim/?rev=47&view=rev Author: lheuer Date: 2008-04-28 06:16:22 -0700 (Mon, 28 Apr 2008) Log Message: ----------- - Initial tinyTiM MIO import Added Paths: ----------- tinytim-mio/ tinytim-mio/branches/ tinytim-mio/tags/ tinytim-mio/trunk/ tinytim-mio/trunk/main/ tinytim-mio/trunk/main/java/ tinytim-mio/trunk/main/java/org/ tinytim-mio/trunk/main/java/org/tinytim/ tinytim-mio/trunk/main/java/org/tinytim/mio/ tinytim-mio/trunk/main/java/org/tinytim/mio/MapInputHandler.java tinytim-mio/trunk/test/ tinytim-mio/trunk/test/java/ tinytim-mio/trunk/test/java/org/ tinytim-mio/trunk/test/java/org/tinytim/ tinytim-mio/trunk/test/java/org/tinytim/mio/ tinytim-mio/trunk/test/java/org/tinytim/mio/TestMapInputHandler.java Added: tinytim-mio/trunk/main/java/org/tinytim/mio/MapInputHandler.java =================================================================== --- tinytim-mio/trunk/main/java/org/tinytim/mio/MapInputHandler.java (rev 0) +++ tinytim-mio/trunk/main/java/org/tinytim/mio/MapInputHandler.java 2008-04-28 13:16:22 UTC (rev 47) @@ -0,0 +1,576 @@ +/* + * 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.List; +import java.util.logging.Logger; + +import org.tinytim.IReifiable; +import org.tinytim.ITyped; +import org.tinytim.TopicMapImpl; +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; + +/** + * {@link com.semagia.mio.IMapHandler} implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class MapInputHandler implements IMapHandler { + + private enum State { + INITIAL, TOPIC, ASSOCIATION, ROLE, OCCURRENCE, NAME, VARIANT, + SCOPE, THEME, REIFIER, PLAYER, ISA, TYPE; + } + + private static final String _XSD_STRING = "http://www.w3.org/2001/XMLSchema#string"; + private static final String _XSD_ANY_URI = "http://www.w3.org/2001/XMLSchema#anyURI"; + + private static final Logger LOG = Logger.getLogger(MapInputHandler.class.getName()); + + private TopicMapImpl _tm; + private State[] _stateStack; + private int _stackPointer; + private List<TopicMapObject> _constructStack; + + /** + * Sets the topic map instance to operate on. + * + * @param tm The topic map. + */ + public void setTopicMap(TopicMap tm) { + _tm = (TopicMapImpl) tm; + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#startTopicMap() + */ + public void startTopicMap() throws MIOException { + _constructStack = new ArrayList<TopicMapObject>(); + _stateStack = new State[15]; + _stackPointer = -1; + _enterState(State.INITIAL, _tm); + } + + /* (non-Javadoc) + * @see com.semagia.mio.IMapHandler#endTopicMap() + */ + public void endTopicMap() throws MIOException { + if (_state() != State.INITIAL) { + LOG.warning("The topic map import seems to be unfinished due to errors"); + } + //TODO: Convert type-instance assocs. + _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 = _peekTopic(); + _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 { + _leaveStatePopConstruct(State.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() + */ + public void endVariant() throws MIOException { + _leaveStatePopConstruct(State.VARIANT); + } + + /* (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[++_stackPointer] = 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 { + if (!(state == _stateStack[_stackPointer])) { + _reportError("Unexpected state: " + _stateStack[_stackPointer] + ", expected: " + state); + } + --_stackPointer; + } + + /** + * 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 void _leaveStatePopConstruct(State state) throws MIOException { + _leaveState(state); + _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[_stackPointer]; + } + + /** + * 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 <code>source</code> topic with the <code>target</code>. + * + * Further, this method ensures that the construct stack stays valid: If + * the <code>source</code> is part of the stack, it is replaced with + * <code>target</code>. + * + * @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 = _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; + } + } + 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); + } + +} Property changes on: tinytim-mio/trunk/main/java/org/tinytim/mio/MapInputHandler.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim-mio/trunk/test/java/org/tinytim/mio/TestMapInputHandler.java =================================================================== --- tinytim-mio/trunk/test/java/org/tinytim/mio/TestMapInputHandler.java (rev 0) +++ tinytim-mio/trunk/test/java/org/tinytim/mio/TestMapInputHandler.java 2008-04-28 13:16:22 UTC (rev 47) @@ -0,0 +1,137 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.mio; + +import org.tinytim.Property; +import org.tinytim.TopicMapImpl; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMapSystem; +import org.tmapi.core.TopicMapSystemFactory; +import org.tmapi.core.TopicName; + +import com.semagia.mio.helpers.Ref; + +import junit.framework.TestCase; + +/** + * Tests against the {@link org.tinytim.mio.MapInputHandler}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestMapInputHandler extends TestCase { + + private TopicMapImpl _tm; + private MapInputHandler _handler; + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + TopicMapSystemFactory tmSysFactory = TopicMapSystemFactory.newInstance(); + tmSysFactory.setProperty(Property.XTM10_REIFICATION, "false"); + TopicMapSystem tmSys = tmSysFactory.newTopicMapSystem(); + _tm = (TopicMapImpl) tmSys.createTopicMap("http://sf.net/projects/tinytim/test"); + _handler = new MapInputHandler(); + _handler.setTopicMap(_tm); + } + + public void testEmpty() throws Exception { + assertEquals(0, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + _handler.startTopicMap(); + _handler.endTopicMap(); + assertEquals(0, _tm.getTopics().size()); + assertEquals(0, _tm.getAssociations().size()); + } + + public void testTopicIdentityItemIdentifier() throws Exception { + String itemIdent = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createItemIdentifier(itemIdent)); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = (Topic) _tm.getObjectByItemIdentifier(_tm.createLocator(itemIdent)); + assertNotNull(topic); + } + + public void testTopicIdentitySubjectIdentifier() throws Exception { + String subjIdent = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(subjIdent)); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(subjIdent)); + assertNotNull(topic); + } + + public void testTopicIdentitySubjectLocator() throws Exception { + String subjLoc = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectLocator(subjLoc)); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = _tm.getTopicBySubjectLocator(_tm.createLocator(subjLoc)); + assertNotNull(topic); + } + + public void testTopicMerging1() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + String itemIdent = "http://example.org/1"; + _handler.startTopicMap(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.startTopic(Ref.createItemIdentifier(itemIdent)); + _handler.itemIdentifier(ref); + _handler.endTopic(); + _handler.startName(); + _handler.value("tinyTiM"); + _handler.endName(); + _handler.endTopic(); + _handler.endTopicMap(); + assertEquals(1, _tm.getTopics().size()); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + assertEquals(topic, _tm.getObjectByItemIdentifier(_tm.createLocator(ref))); + assertEquals(topic, _tm.getObjectByItemIdentifier(_tm.createLocator(itemIdent))); + assertEquals(1, topic.getTopicNames().size()); + TopicName name = (TopicName)topic.getTopicNames().iterator().next(); + assertEquals("tinyTiM", name.getValue()); + } + + public void testTopicMapReifier() throws Exception { + String ref = "http://sf.net/projects/tinytim/test#1"; + _handler.startTopicMap(); + _handler.startReifier(); + _handler.startTopic(Ref.createSubjectIdentifier(ref)); + _handler.endTopic(); + _handler.endReifier(); + _handler.endTopicMap(); + assertNotNull(_tm.getReifier()); + Topic topic = _tm.getTopicBySubjectIdentifier(_tm.createLocator(ref)); + assertNotNull(topic); + assertEquals(topic, _tm.getReifier()); + } + +} Property changes on: tinytim-mio/trunk/test/java/org/tinytim/mio/TestMapInputHandler.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-04-28 13:14:41
|
Revision: 46 http://tinytim.svn.sourceforge.net/tinytim/?rev=46&view=rev Author: lheuer Date: 2008-04-28 06:14:41 -0700 (Mon, 28 Apr 2008) Log Message: ----------- - Moved test dir into the right directory Added Paths: ----------- tinytim-cxtm/trunk/src/test/ Removed Paths: ------------- tinytim-cxtm/trunk/test/ Copied: tinytim-cxtm/trunk/src/test (from rev 45, tinytim-cxtm/trunk/test) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-04-27 13:24:48
|
Revision: 45 http://tinytim.svn.sourceforge.net/tinytim/?rev=45&view=rev Author: lheuer Date: 2008-04-27 06:24:06 -0700 (Sun, 27 Apr 2008) Log Message: ----------- Project layout for the CXTM subpackage Added Paths: ----------- tinytim-cxtm/trunk/src/ tinytim-cxtm/trunk/src/main/ tinytim-cxtm/trunk/src/main/java/ tinytim-cxtm/trunk/test/ tinytim-cxtm/trunk/test/java/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |