From: <lh...@us...> - 2008-04-21 14:03:13
|
Revision: 23 http://tinytim.svn.sourceforge.net/tinytim/?rev=23&view=rev Author: lheuer Date: 2008-04-21 07:02:48 -0700 (Mon, 21 Apr 2008) Log Message: ----------- Added TopicUtils, updated TopicMerge test Modified Paths: -------------- tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java Added: tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-04-21 14:02:48 UTC (rev 23) @@ -0,0 +1,81 @@ +/* + * 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 org.tinytim.index.IScopedIndex; +import org.tinytim.index.ITypeInstanceIndex; +import org.tinytim.index.IndexManager; +import org.tmapi.core.Topic; + +/** + * This class provides utility functions for {@link org.tmapi.core.Topic}s. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class TopicUtils { + + private TopicUtils() { + // noop. + } + + /** + * Returns if the <code>topic</code> is removable. + * + * A topic is removable iff it plays no role, is not used as type of + * a typed Topic Maps construct, is not not used as theme of a scoped + * Topic Maps construct and iff it is not used reifier. + * + * @param topic The topic to check. + * @return <code>true</code> if the topic has no dependencies, + * otherwise <code>false</code>. + */ + public static boolean isRemovable(Topic topic) { + if (((TopicImpl) topic)._reified != null) { + return false; + } + if (!topic.getRolesPlayed().isEmpty()) { + return false; + } + IndexManager idxMan = ((TopicMapImpl) topic.getTopicMap()).getIndexManager(); + ITypeInstanceIndex typeInstanceIdx = idxMan.getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + if (!typeInstanceIdx.getAssociations(topic).isEmpty() + || !typeInstanceIdx.getRoles(topic).isEmpty() + || !typeInstanceIdx.getOccurrences(topic).isEmpty() + || !typeInstanceIdx.getNames(topic).isEmpty()) { + return false; + } + IScopedIndex scopedIdx = idxMan.getScopedIndex(); + if (!scopedIdx.isAutoUpdated()) { + scopedIdx.reindex(); + } + if (!scopedIdx.getAssociationsByTheme(topic).isEmpty() + || !scopedIdx.getOccurrencesByTheme(topic).isEmpty() + || !scopedIdx.getNamesByTheme(topic).isEmpty() + || !scopedIdx.getVariantsByTheme(topic).isEmpty()) { + return false; + } + return true; + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-04-21 13:55:44 UTC (rev 22) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-04-21 14:02:48 UTC (rev 23) @@ -26,6 +26,7 @@ import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Topic; import org.tmapi.core.TopicName; +import org.tmapi.core.Variant; /** * Tests merging of topics. @@ -156,4 +157,28 @@ topic1.mergeIn(topic2); assertEquals(2, topic1.getTopicNames().size()); } + + /** + * Tests if merging detects duplicate names and moves the variants. + */ + public void testDuplicateSuppressionName2() { + Topic topic1 = _tm.createTopic(); + Topic topic2 = _tm.createTopic(); + TopicName name1 = topic1.createTopicName("tinyTiM", null, null); + TopicName name2 = topic2.createTopicName("tinyTiM", null, null); + Variant var = name2.createVariant("tiny", null); + assertEquals(1, topic1.getTopicNames().size()); + assertTrue(topic1.getTopicNames().contains(name1)); + assertEquals(0, name1.getVariants().size()); + assertEquals(1, topic2.getTopicNames().size()); + assertTrue(topic2.getTopicNames().contains(name2)); + assertEquals(1, name2.getVariants().size()); + assertTrue(name2.getVariants().contains(var)); + topic1.mergeIn(topic2); + assertEquals(1, topic1.getTopicNames().size()); + TopicName tmpName = (TopicName) topic1.getTopicNames().iterator().next(); + assertEquals(1, tmpName.getVariants().size()); + Variant tmpVar = (Variant) tmpName.getVariants().iterator().next(); + assertEquals("tiny", tmpVar.getValue()); + } } Added: tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java 2008-04-21 14:02:48 UTC (rev 23) @@ -0,0 +1,63 @@ +/* + * 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 org.tmapi.core.Association; +import org.tmapi.core.AssociationRole; +import org.tmapi.core.Topic; + +/** + * Tests against the {@link TopicUtils}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestTopicUtils extends TinyTimTestCase { + + /** + * Tests if a topic is considered as 'removable'. + */ + public void testRemovable() { + Topic topic = _tm.createTopic(); + assertTrue(TopicUtils.isRemovable(topic)); + Association assoc = _tm.createAssociation(); + // Type + assoc.setType(topic); + assertFalse(TopicUtils.isRemovable(topic)); + assoc.setType(null); + assertTrue(TopicUtils.isRemovable(topic)); + // Role played + AssociationRole role = assoc.createAssociationRole(topic, _tm.createTopic()); + assertFalse(TopicUtils.isRemovable(topic)); + role.setPlayer(null); + assertTrue(TopicUtils.isRemovable(topic)); + // Theme + assoc.addScopingTopic(topic); + assertFalse(TopicUtils.isRemovable(topic)); + assoc.removeScopingTopic(topic); + assertTrue(TopicUtils.isRemovable(topic)); + // Reifier + ((IReifiable) assoc).setReifier(topic); + assertFalse(TopicUtils.isRemovable(topic)); + ((IReifiable) assoc).setReifier(null); + assertTrue(TopicUtils.isRemovable(topic)); + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.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-22 13:13:20
|
Revision: 27 http://tinytim.svn.sourceforge.net/tinytim/?rev=27&view=rev Author: lheuer Date: 2008-04-22 06:13:08 -0700 (Tue, 22 Apr 2008) Log Message: ----------- - Refactored Scoped and Typed: Scoped does not implement IReifiable, Typed does - All instances return copies of theirs list - Added ReificationUtils to support XTM 1.0 reification Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/AssociationImpl.java tinytim/trunk/src/main/java/org/tinytim/AssociationRoleImpl.java tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/IdentityManager.java tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java tinytim/trunk/src/main/java/org/tinytim/Property.java tinytim/trunk/src/main/java/org/tinytim/Scoped.java tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/Typed.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/TypeInstanceIndex.java tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java tinytim/trunk/src/test/java/org/tinytim/TinyTimTestCase.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java Modified: tinytim/trunk/src/main/java/org/tinytim/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/AssociationImpl.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/AssociationImpl.java 2008-04-22 13:13:08 UTC (rev 27) @@ -33,7 +33,7 @@ * {@link org.tmapi.core.Association} implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class AssociationImpl extends Scoped implements Association, IReifiable, ITyped, IScoped { @@ -42,7 +42,7 @@ private Topic _type; AssociationImpl(TopicMapImpl topicMap) { - super(topicMap, null); + super(topicMap, null, null); _roles = topicMap.getCollectionFactory().createSet(2); } Modified: tinytim/trunk/src/main/java/org/tinytim/AssociationRoleImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/AssociationRoleImpl.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/AssociationRoleImpl.java 2008-04-22 13:13:08 UTC (rev 27) @@ -29,7 +29,7 @@ * {@link org.tmapi.core.AssociationRole} implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class AssociationRoleImpl extends Typed implements AssociationRole, ITyped { @@ -37,7 +37,7 @@ private Topic _player; AssociationRoleImpl(TopicMapImpl tm, Topic type, Topic player) { - super(tm, type, null); + super(tm, type); _player = player; } Modified: tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java 2008-04-22 13:13:08 UTC (rev 27) @@ -34,7 +34,7 @@ * topic map to another without creating duplicates. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class CopyUtils { Modified: tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java 2008-04-22 13:13:08 UTC (rev 27) @@ -29,10 +29,10 @@ * Implementation of {@link org.tinytim.IDatatypeAwareConstruct}. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ -abstract class DatatypeAwareConstruct extends Typed implements - IDatatypeAwareConstruct, IScoped { +abstract class DatatypeAwareConstruct extends Scoped implements + IDatatypeAwareConstruct { private String _value; private Locator _resource; @@ -58,9 +58,11 @@ } /** + * Sets the value (xsd:string) of this construct. * + * Sideeffect: The resource is set to null. * - * @param value + * @param value Sets the value of this construct. */ public void setValue(String value) { _fireEvent(Event.SET_VALUE, _value, value); @@ -69,25 +71,29 @@ } /** - * + * Returns the value of this construct. * - * @return + * @return The value or <code>null</code>. */ public String getValue() { return _value; } /** - * + * Returns the locator (xsd:anyURI value) of this construct. * - * @return + * @return The locator or <code>null</code>. */ public Locator getResource() { return _resource; } - /* (non-Javadoc) - * @see org.tmapi.core.Occurrence#setResource(org.tmapi.core.Locator) + /** + * Sets the value (xsd:anyURI) of this construct. + * + * Side effect: The string value (if any) is set to <code>null</code>. + * + * @param value The locator. */ public void setResource(Locator value) { _fireEvent(Event.SET_VALUE, _value, value); Modified: tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java 2008-04-22 13:13:08 UTC (rev 27) @@ -26,7 +26,7 @@ * Indicates that a Topic Maps construct has a value and a datatype. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ interface IDatatypeAwareConstruct extends IConstruct { Modified: tinytim/trunk/src/main/java/org/tinytim/IdentityManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IdentityManager.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/IdentityManager.java 2008-04-22 13:13:08 UTC (rev 27) @@ -33,7 +33,7 @@ * provides an index to get Topic Maps constructs by their identity. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class IdentityManager { Modified: tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-04-22 13:13:08 UTC (rev 27) @@ -47,7 +47,7 @@ * changes, check the <code>==</code> comparisons. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class MergeUtils { @@ -272,32 +272,23 @@ if (!typeInstanceIndex.isAutoUpdated()) { typeInstanceIndex.reindex(); } - List<Topic> topics = new ArrayList<Topic>(typeInstanceIndex.getTopics(source)); - for (Topic topic: topics) { + for (Topic topic: typeInstanceIndex.getTopics(source)) { topic.removeType(source); topic.addType(replacement); } - Collection<ITyped> typed = new ArrayList<ITyped>(typeInstanceIndex.getAssociations(source)); - _replaceTopicAsType(typed, replacement); - typed = new ArrayList<ITyped>(typeInstanceIndex.getRoles(source)); - _replaceTopicAsType(typed, replacement); - typed = new ArrayList<ITyped>(typeInstanceIndex.getOccurrences(source)); - _replaceTopicAsType(typed, replacement); - typed = new ArrayList<ITyped>(typeInstanceIndex.getNames(source)); - _replaceTopicAsType(typed, replacement); + _replaceTopicAsType(typeInstanceIndex.getAssociations(source), replacement); + _replaceTopicAsType(typeInstanceIndex.getRoles(source), replacement); + _replaceTopicAsType(typeInstanceIndex.getOccurrences(source), replacement); + _replaceTopicAsType(typeInstanceIndex.getNames(source), replacement); typeInstanceIndex.close(); IScopedIndex scopedIndex = idxMan.getScopedIndex(); if (!scopedIndex.isAutoUpdated()) { scopedIndex.reindex(); } - Collection<IScoped> scoped = new ArrayList<IScoped>(scopedIndex.getAssociationsByTheme(source)); - _replaceTopicAsTheme(scoped, source, replacement); - scoped = new ArrayList<IScoped>(scopedIndex.getOccurrencesByTheme(source)); - _replaceTopicAsTheme(scoped, source, replacement); - scoped = new ArrayList<IScoped>(scopedIndex.getNamesByTheme(source)); - _replaceTopicAsTheme(scoped, source, replacement); - scoped = new ArrayList<IScoped>(scopedIndex.getVariantsByTheme(source)); - _replaceTopicAsTheme(scoped, source, replacement); + _replaceTopicAsTheme(scopedIndex.getAssociationsByTheme(source), source, replacement); + _replaceTopicAsTheme(scopedIndex.getOccurrencesByTheme(source), source, replacement); + _replaceTopicAsTheme(scopedIndex.getNamesByTheme(source), source, replacement); + _replaceTopicAsTheme(scopedIndex.getVariantsByTheme(source), source, replacement); scopedIndex.close(); } @@ -307,14 +298,14 @@ * @param typedConstructs A collection of typed constructs. * @param replacement The type. */ - private static void _replaceTopicAsType(Collection<ITyped> typedConstructs, + private static void _replaceTopicAsType(Collection<? extends ITyped> typedConstructs, Topic replacement) { for (ITyped typed: typedConstructs) { typed.setType(replacement); } } - private static void _replaceTopicAsTheme(Collection<IScoped> scopedCollection, + private static void _replaceTopicAsTheme(Collection<? extends IScoped> scopedCollection, Topic oldTheme, Topic newTheme) { for (IScoped scoped: scopedCollection) { scoped.removeTheme(oldTheme); Modified: tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java 2008-04-22 13:13:08 UTC (rev 27) @@ -31,10 +31,10 @@ * {@link org.tmapi.core.Occurrence} implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class OccurrenceImpl extends DatatypeAwareConstruct implements - Occurrence, ITyped { + Occurrence, ITyped, IScoped { OccurrenceImpl(TopicMapImpl topicMap, Topic type, String value, Collection<Topic> scope) { super(topicMap, type, value, scope); Modified: tinytim/trunk/src/main/java/org/tinytim/Property.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Property.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/Property.java 2008-04-22 13:13:08 UTC (rev 27) @@ -41,4 +41,14 @@ * default Java collections. */ public static final String COLLECTION_FACTORY = "org.tinytim.CollectionFactory"; + + /** + * Property which indicates if the "old" XTM 1.0 reification mechansm should + * be used. + * + * For backwards compatibilty and to support TMAPI 1.0 this property is + * set to "true" by default. + */ + public static final String XTM10_REIFICATION = "org.tinytim.XTM10Reification"; + } Added: tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java 2008-04-22 13:13:08 UTC (rev 27) @@ -0,0 +1,80 @@ +/* + * 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.Iterator; +import java.util.Set; + +import org.tmapi.core.Locator; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMapObject; + +/** + * Functions to support the XTM 1.0 reification mechanism. + * + * This class is not meant to be used outside of the tinyTiM package. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +final class ReificationUtils { + + /** + * Returns all Topic Maps constructs which have an item identifier + * equals to a subject identifier of the specified <code>reifier</code>. + * + * @param reifier A topic. + * @return A (maybe empty) collection of Topic Maps constructs. + */ + public static Set<TopicMapObject> getReified(Topic reifier) { + TopicMapImpl tm = (TopicMapImpl) reifier.getTopicMap(); + Set<TopicMapObject> reified = tm.getCollectionFactory().createSet(); + for (Locator sid: ((TopicImpl) reifier).getSubjectIdentifiers()) { + TopicMapObject obj = tm.getObjectByItemIdentifier(sid); + if (obj != null) { + reified.add(obj); + } + } + return reified; + } + + /** + * Returns a topic that has a subject identifier equals to one of the + * item identifiers of the <code>reifiable</code>. + * + * @param reifiable The reifiable Topic Maps construct. + * @return A topic or <code>null</code>. + */ + @SuppressWarnings("unchecked") + public static Topic getReifier(TopicMapObject reifiable) { + if (reifiable instanceof Topic) { + throw new IllegalArgumentException("Topics are not reifiable"); + } + TopicMapImpl tm = (TopicMapImpl) reifiable.getTopicMap(); + for (Iterator<Locator> iter = reifiable.getSourceLocators().iterator(); iter.hasNext();) { + Topic reifier = tm.getTopicBySubjectIdentifier(iter.next()); + if (reifier != null) { + return reifier; + } + } + return null; + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/Scoped.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Scoped.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/Scoped.java 2008-04-22 13:13:08 UTC (rev 27) @@ -28,25 +28,23 @@ /** * Class that provides a "scope" property and sends events if that - * scope property changes. Additionally, this class provides - * a {@link IReifiable} implementation. + * scope property changes. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -abstract class Scoped extends Construct implements IReifiable { +abstract class Scoped extends Typed { //NOTE: This class does NOT implement IScoped by intention! - // Typed extends this class and roles are not IScoped! private Set<Topic> _scope; - private Topic _reifier; - Scoped(TopicMapImpl topicMap, Collection<Topic> scope) { - super(topicMap); + Scoped(TopicMapImpl topicMap, Topic type, Collection<Topic> scope) { + super(topicMap, type); if (scope != null) { - for(Topic theme: scope) { - addTheme(theme); + _scope = topicMap.getCollectionFactory().createSet(scope.size()); + for (Topic theme: scope) { + _scope.add(theme); } } } @@ -99,36 +97,11 @@ } /* (non-Javadoc) - * @see org.tmapi.core.Association#getReifier() - */ - public Topic getReifier() { - return _reifier; - } - - /* (non-Javadoc) - * @see org.tinytim.IReifiable#setReifier(org.tmapi.core.Topic) - */ - public void setReifier(Topic reifier) { - if (_reifier == reifier) { - return; - } - _fireEvent(Event.SET_REIFIER, _reifier, reifier); - if (_reifier != null) { - ((TopicImpl) _reifier)._reified = null; - } - _reifier = reifier; - if (reifier != null) { - ((TopicImpl) reifier)._reified = this; - } - } - - /* (non-Javadoc) * @see org.tinytim.Construct#dispose() */ @Override protected void dispose() { _scope = null; - _reifier = null; super.dispose(); } Modified: tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java 2008-04-22 13:13:08 UTC (rev 27) @@ -38,7 +38,7 @@ * {@link org.tmapi.core.Topic} implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class TopicImpl extends Construct implements Topic { @@ -230,6 +230,9 @@ * @see org.tmapi.core.Topic#getReified() */ public Set<TopicMapObject> getReified() { + if (_tm._oldReification) { + return ReificationUtils.getReified(this); + } return _reified != null ? Collections.<TopicMapObject>singleton(_reified) : Collections.<TopicMapObject>emptySet(); } Modified: tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java 2008-04-22 13:13:08 UTC (rev 27) @@ -59,6 +59,7 @@ for (FeatureInfo feature: _FEATURES) { _features.put(feature.name, feature.defaultValue); } + _properties.setProperty(Property.XTM10_REIFICATION, "true"); _properties.setProperty(Property.COLLECTION_FACTORY, _COLL_FACTORY_JAVA); try { // Probe if Trove is available. Modified: tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java 2008-04-22 13:13:08 UTC (rev 27) @@ -35,9 +35,9 @@ * {@link org.tmapi.core.TopicName} implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ -public final class TopicNameImpl extends Typed implements TopicName, ITyped, IScoped { +public final class TopicNameImpl extends Scoped implements TopicName, ITyped, IScoped { private String _value; private Set<Variant> _variants; Modified: tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-04-22 13:13:08 UTC (rev 27) @@ -45,8 +45,8 @@ * Topic Maps construct and iff it is not used reifier. * * @param topic The topic to check. - * @return <code>true</code> if the topic has no dependencies, - * otherwise <code>false</code>. + * @return <code>true</code> if the topic is removable, <code>false</code> + * otherwise. */ public static boolean isRemovable(Topic topic) { if (((TopicImpl) topic)._reified != null) { @@ -60,22 +60,22 @@ if (!typeInstanceIdx.isAutoUpdated()) { typeInstanceIdx.reindex(); } - if (!typeInstanceIdx.getAssociations(topic).isEmpty() - || !typeInstanceIdx.getRoles(topic).isEmpty() - || !typeInstanceIdx.getOccurrences(topic).isEmpty() - || !typeInstanceIdx.getNames(topic).isEmpty()) { - return false; + boolean removable = typeInstanceIdx.getAssociations(topic).isEmpty() + && typeInstanceIdx.getRoles(topic).isEmpty() + && typeInstanceIdx.getOccurrences(topic).isEmpty() + && typeInstanceIdx.getNames(topic).isEmpty(); + typeInstanceIdx.close(); + if (removable) { + IScopedIndex scopedIdx = idxMan.getScopedIndex(); + if (!scopedIdx.isAutoUpdated()) { + scopedIdx.reindex(); + } + removable = scopedIdx.getAssociationsByTheme(topic).isEmpty() + && scopedIdx.getOccurrencesByTheme(topic).isEmpty() + && scopedIdx.getNamesByTheme(topic).isEmpty() + && scopedIdx.getVariantsByTheme(topic).isEmpty(); + scopedIdx.close(); } - IScopedIndex scopedIdx = idxMan.getScopedIndex(); - if (!scopedIdx.isAutoUpdated()) { - scopedIdx.reindex(); - } - if (!scopedIdx.getAssociationsByTheme(topic).isEmpty() - || !scopedIdx.getOccurrencesByTheme(topic).isEmpty() - || !scopedIdx.getNamesByTheme(topic).isEmpty() - || !scopedIdx.getVariantsByTheme(topic).isEmpty()) { - return false; - } - return true; + return removable; } } Modified: tinytim/trunk/src/main/java/org/tinytim/Typed.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Typed.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/Typed.java 2008-04-22 13:13:08 UTC (rev 27) @@ -20,26 +20,26 @@ */ package org.tinytim; -import java.util.Collection; - import org.tmapi.core.Topic; /** - * Class that provides a "type" property and fires and event if that type - * property changes. + * Class that provides a "type" property and fires an event if that type + * property changes. Additionally, this class provides + * a {@link IReifiable} implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -abstract class Typed extends Scoped { +abstract class Typed extends Construct implements IReifiable { //NOTE: This class does NOT implement ITyped by intention! // DatatypeAwareConstruct extends this class and variants are not ITyped! private Topic _type; + private Topic _reifier; - Typed(TopicMapImpl topicMap, Topic type, Collection<Topic> scope) { - super(topicMap, scope); + Typed(TopicMapImpl topicMap, Topic type) { + super(topicMap); _type = type; } @@ -62,11 +62,39 @@ } /* (non-Javadoc) + * @see org.tmapi.core.IReifiable#getReifier() + */ + public Topic getReifier() { + if (_tm._oldReification) { + return ReificationUtils.getReifier(this); + } + return _reifier; + } + + /* (non-Javadoc) + * @see org.tinytim.IReifiable#setReifier(org.tmapi.core.Topic) + */ + public void setReifier(Topic reifier) { + if (_reifier == reifier) { + return; + } + _fireEvent(Event.SET_REIFIER, _reifier, reifier); + if (_reifier != null) { + ((TopicImpl) _reifier)._reified = null; + } + _reifier = reifier; + if (reifier != null) { + ((TopicImpl) reifier)._reified = this; + } + } + + /* (non-Javadoc) * @see org.tinytim.Scoped#dispose() */ @Override protected void dispose() { _type = null; + _reifier = null; super.dispose(); } Modified: tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java 2008-04-22 13:13:08 UTC (rev 27) @@ -32,9 +32,10 @@ * {@link org.tmapi.core.Variant} implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ -public final class VariantImpl extends DatatypeAwareConstruct implements Variant { +public final class VariantImpl extends DatatypeAwareConstruct implements + Variant, IScoped { VariantImpl(TopicMapImpl topicMap, String value, Collection<Topic> scope) { super(topicMap, null, value, scope); Modified: tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java 2008-04-22 13:13:08 UTC (rev 27) @@ -27,7 +27,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class IndexManager { Modified: tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java 2008-04-22 13:13:08 UTC (rev 27) @@ -42,7 +42,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class ScopedIndex implements IScopedIndex { Modified: tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java 2008-04-22 13:13:08 UTC (rev 27) @@ -23,8 +23,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.tinytim.AssociationImpl; import org.tinytim.AssociationRoleImpl; @@ -39,10 +41,10 @@ import org.tmapi.core.Topic; /** + * {@link ITypeInstanceIndex} implementation. * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TypeInstanceIndex implements ITypeInstanceIndex { @@ -78,7 +80,7 @@ public Collection<AssociationImpl> getAssociations(Topic type) { List<AssociationImpl> assocs = _type2Assocs.get(type); return assocs == null ? Collections.<AssociationImpl>emptySet() - : Collections.unmodifiableCollection(assocs); + : new ArrayList<AssociationImpl>(assocs); } /* (non-Javadoc) @@ -94,7 +96,7 @@ public Collection<AssociationRoleImpl> getRoles(Topic type) { List<AssociationRoleImpl> roles = _type2Roles.get(type); return roles == null ? Collections.<AssociationRoleImpl>emptySet() - : Collections.unmodifiableCollection(roles); + : new ArrayList<AssociationRoleImpl>(roles); } /* (non-Javadoc) @@ -110,7 +112,7 @@ public Collection<OccurrenceImpl> getOccurrences(Topic type) { List<OccurrenceImpl> occs = _type2Occs.get(type); return occs == null ? Collections.<OccurrenceImpl>emptySet() - : Collections.unmodifiableCollection(occs); + : new ArrayList<OccurrenceImpl>(occs); } /* (non-Javadoc) @@ -126,7 +128,7 @@ public Collection<TopicNameImpl> getNames(Topic type) { List<TopicNameImpl> names = _type2Names.get(type); return names == null ? Collections.<TopicNameImpl>emptySet() - : Collections.unmodifiableCollection(names); + : new ArrayList<TopicNameImpl>(names); } /* (non-Javadoc) @@ -139,13 +141,20 @@ /* (non-Javadoc) * @see org.tinytim.index.ITypeInstanceIndex#getTopics(org.tmapi.core.Topic[]) */ - public Collection<Topic> getTopics(Topic... type) { - if (type == null || type.length == 1) { - List<Topic> topics = _type2Topics.get(type); + public Collection<Topic> getTopics(Topic... types) { + if (types == null || types.length == 1) { + List<Topic> topics = _type2Topics.get(types[0]); return topics == null ? Collections.<Topic>emptySet() - : Collections.unmodifiableCollection(topics); + : new ArrayList<Topic>(topics); } - return null; + Set<Topic> topics = new HashSet<Topic>(10); + for (Topic type: types) { + List<Topic> matches = _type2Topics.get(type); + if (matches != null) { + topics.addAll(matches); + } + } + return topics; } /* (non-Javadoc) Modified: tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java 2008-04-22 13:13:08 UTC (rev 27) @@ -20,6 +20,8 @@ */ package org.tinytim; +import java.util.Properties; + import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.ModelConstraintException; @@ -37,6 +39,16 @@ */ public class TestReifiable extends TinyTimTestCase { + /* (non-Javadoc) + * @see org.tinytim.TinyTimTestCase#getAdditionalProperties() + */ + @Override + protected Properties getAdditionalProperties() { + Properties props = new Properties(); + props.setProperty(Property.XTM10_REIFICATION, "false"); + return props; + } + /** * Tests if a Topic Maps construct is an instance of IReifiable. */ Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-04-22 13:13:08 UTC (rev 27) @@ -20,6 +20,8 @@ */ package org.tinytim; +import java.util.Properties; + import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.Locator; @@ -36,6 +38,16 @@ */ public class TestTopicMerge extends TinyTimTestCase { + /* (non-Javadoc) + * @see org.tinytim.TinyTimTestCase#getAdditionalProperties() + */ + @Override + protected Properties getAdditionalProperties() { + Properties props = new Properties(); + props.setProperty(Property.XTM10_REIFICATION, "false"); + return props; + } + /** * If topics reify different Topic Maps constructs they cannot be merged. */ Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java 2008-04-22 13:13:08 UTC (rev 27) @@ -28,7 +28,7 @@ * Tests against the {@link TopicUtils}. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestTopicUtils extends TinyTimTestCase { @@ -60,4 +60,5 @@ ((IReifiable) assoc).setReifier(null); assertTrue(TopicUtils.isRemovable(topic)); } + } Modified: tinytim/trunk/src/test/java/org/tinytim/TinyTimTestCase.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TinyTimTestCase.java 2008-04-21 14:59:01 UTC (rev 26) +++ tinytim/trunk/src/test/java/org/tinytim/TinyTimTestCase.java 2008-04-22 13:13:08 UTC (rev 27) @@ -20,6 +20,9 @@ */ package org.tinytim; +import java.util.Enumeration; +import java.util.Properties; + import org.tinytim.TopicMapImpl; import org.tinytim.TopicMapSystemFactoryImpl; import org.tinytim.TopicMapSystemImpl; @@ -45,6 +48,17 @@ protected TopicMapSystemImpl _sys; protected TopicMapSystemFactoryImpl _sysFactory; + /** + * Returns additional / non-default properties which should be set + * to configure the {@link org.tmapi.core.TopicMapSystemFactory}. + * + * @return Properties instance or <code>null</code> if no properties != + * default properties should be set. + */ + protected Properties getAdditionalProperties() { + return null; + } + /* (non-Javadoc) * @see junit.framework.TestCase#setUp() */ @@ -52,6 +66,13 @@ protected void setUp() throws Exception { super.setUp(); _sysFactory = new TopicMapSystemFactoryImpl(); + Properties properties = getAdditionalProperties(); + if (properties != null) { + for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) { + String name = (String) e.nextElement(); + _sysFactory.setProperty(name, properties.getProperty(name)); + } + } _sys = (TopicMapSystemImpl) _sysFactory.newTopicMapSystem(); _tm = (TopicMapImpl) _sys.createTopicMap(_IRI); _base = _tm.getBaseLocator(); @@ -66,6 +87,7 @@ _sysFactory = null; _sys = null; _tm = null; + _base = null; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-04-23 12:16:13
|
Revision: 29 http://tinytim.svn.sourceforge.net/tinytim/?rev=29&view=rev Author: lheuer Date: 2008-04-23 05:16:08 -0700 (Wed, 23 Apr 2008) Log Message: ----------- - Added moveable to move a Topic Maps construct to another - Tests for item identifier constraints - Enhanced TopicUtils Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/Construct.java tinytim/trunk/src/main/java/org/tinytim/Event.java tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java tinytim/trunk/src/main/java/org/tinytim/Scoped.java tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/Typed.java tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java tinytim/trunk/src/test/java/org/tinytim/TestReificationUtils.java tinytim/trunk/src/test/java/org/tinytim/TestTopicMergeDetection.java tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/IMovable.java tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java Modified: tinytim/trunk/src/main/java/org/tinytim/Construct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Construct.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/main/java/org/tinytim/Construct.java 2008-04-23 12:16:08 UTC (rev 29) @@ -167,4 +167,18 @@ _iids = null; } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(super.toString()); + sb.append(" iids=["); + for (Locator sid: getItemIdentifiers()) { + sb.append(sid); + sb.append(','); + } + sb.append("]"); + return sb.toString(); + } } Modified: tinytim/trunk/src/main/java/org/tinytim/Event.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Event.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/main/java/org/tinytim/Event.java 2008-04-23 12:16:08 UTC (rev 29) @@ -151,6 +151,10 @@ * Notification that the "resource" of an occurrence or variant should be * set. */ - SET_LOCATOR; //TODO: Remove this once we have a TMDM-compatible version + SET_LOCATOR, //TODO: Remove this once we have a TMDM-compatible version + MOVE_OCCURRENCE, + MOVE_NAME, + MOVE_VARIANT + } Added: tinytim/trunk/src/main/java/org/tinytim/IMovable.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IMovable.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/IMovable.java 2008-04-23 12:16:08 UTC (rev 29) @@ -0,0 +1,41 @@ +/* + * 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; + +/** + * Indicates that a Topic Maps construct is able to be detached from the + * current parent and attached to another parent. + * + * This interface is not meant to be used outside of the tinyTiM package. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +interface IMovable<T /* extends IConstruct */> { + + /** + * Moves this Topic Maps construct to the new parent. + * + * @param newParent The parent to move this construct to. + */ + public void moveTo(T newParent); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/IMovable.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-04-23 12:16:08 UTC (rev 29) @@ -84,6 +84,7 @@ /** * @see #merge(Topic, Topic) */ + @SuppressWarnings("unchecked") private static void _merge(TopicImpl source, TopicImpl target) { if (source == null || target == null) { throw new IllegalArgumentException("Neither the source topic nor the target topic must be null"); @@ -130,8 +131,7 @@ removeConstruct((IConstruct)occ); } else { - source.removeOccurrence(occ); - target.addOccurrence(occ); + ((IMovable<Topic>) occ).moveTo(target); } } sigs.clear(); @@ -146,8 +146,7 @@ removeConstruct((IConstruct) name); } else { - source.removeName(name); - target.addName(name); + ((IMovable<Topic>) name).moveTo(target); } } sigs.clear(); @@ -210,6 +209,7 @@ * @param source The name to take the variants from. * @param target The target to add the variants to. */ + @SuppressWarnings("unchecked") static void moveVariants(TopicNameImpl source, TopicNameImpl target) { Map<String, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().<String, Variant>createMap(); for (Variant var: target.getVariants()) { @@ -223,8 +223,7 @@ removeConstruct((IConstruct)var); } else { - source.removeVariant(var); - target.addVariant(var); + ((IMovable<TopicName>) var).moveTo(target); } } } Modified: tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java 2008-04-23 12:16:08 UTC (rev 29) @@ -34,7 +34,7 @@ * @version $Rev$ - $Date$ */ public final class OccurrenceImpl extends DatatypeAwareConstruct implements - Occurrence, ITyped, IScoped { + Occurrence, ITyped, IScoped, IMovable<Topic> { OccurrenceImpl(TopicMapImpl topicMap, Topic type, String value, Collection<Topic> scope) { super(topicMap, type, value, scope); @@ -52,6 +52,15 @@ } /* (non-Javadoc) + * @see org.tinytim.IMovable#moveTo(java.lang.Object) + */ + public void moveTo(Topic newParent) { + _fireEvent(Event.MOVE_OCCURRENCE, _parent, newParent); + ((TopicImpl) _parent).detachOccurrence(this); + ((TopicImpl) newParent).attachOccurrence(this); + } + + /* (non-Javadoc) * @see org.tmapi.core.TopicMapObject#remove() */ public void remove() throws TMAPIException { Modified: tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java 2008-04-23 12:16:08 UTC (rev 29) @@ -30,12 +30,10 @@ /** * Functions to support the XTM 1.0 reification mechanism. * - * This class is not meant to be used outside of the tinyTiM package. - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ -final class ReificationUtils { +public final class ReificationUtils { /** * Returns all Topic Maps constructs which have an item identifier Modified: tinytim/trunk/src/main/java/org/tinytim/Scoped.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Scoped.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/main/java/org/tinytim/Scoped.java 2008-04-23 12:16:08 UTC (rev 29) @@ -97,7 +97,7 @@ } /* (non-Javadoc) - * @see org.tinytim.Construct#dispose() + * @see org.tinytim.Typed#dispose() */ @Override protected void dispose() { Modified: tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java 2008-04-23 12:16:08 UTC (rev 29) @@ -159,8 +159,7 @@ return; } _fireEvent(Event.ADD_OCCURRENCE, null, o); - o._parent = this; - _occs.add(o); + attachOccurrence(o); } /** @@ -174,10 +173,19 @@ return; } _fireEvent(Event.REMOVE_OCCURRENCE, o, null); - _occs.remove(o); - o._parent = null; + detachOccurrence(o); } + void attachOccurrence(OccurrenceImpl occ) { + occ._parent = this; + _occs.add(occ); + } + + void detachOccurrence(OccurrenceImpl occ) { + _occs.remove(occ); + occ._parent = null; + } + /* (non-Javadoc) * @see org.tmapi.core.Topic#getTopicNames() */ @@ -212,8 +220,7 @@ } assert n._parent == null; _fireEvent(Event.ADD_NAME, null, n); - n._parent = this; - _names.add(n); + attachName(n); } void removeName(TopicName name) { @@ -222,10 +229,19 @@ return; } _fireEvent(Event.REMOVE_NAME, n, null); - _names.remove(n); - n._parent = null; + detachName(n); } + void attachName(TopicNameImpl name) { + name._parent = this; + _names.add(name); + } + + void detachName(TopicNameImpl name) { + _names.remove(name); + name._parent = null; + } + /* (non-Javadoc) * @see org.tmapi.core.Topic#getReified() */ @@ -303,9 +319,12 @@ * @see org.tmapi.core.TopicMapObject#remove() */ public void remove() throws TopicInUseException { - if (!TopicUtils.isRemovable(this)) { - throw new TopicInUseException("The topic is used as type, player, reifier or theme"); + if (!TopicUtils.isRemovable(this, false)) { + throw new TopicInUseException("The topic is used as type, player, or theme"); } + if (_reified != null) { + _reified.setReifier(null); + } _tm.removeTopic(this); _sids = null; _slos = null; @@ -317,4 +336,24 @@ super.dispose(); } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(super.toString()); + sb.append(", sids=["); + for (Locator sid: getSubjectIdentifiers()) { + sb.append(sid); + sb.append(','); + } + sb.append("], slos=["); + for (Locator slo: getSubjectLocators()) { + sb.append(slo); + sb.append(','); + } + sb.append("]"); + return sb.toString(); + } + } Modified: tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java 2008-04-23 12:16:08 UTC (rev 29) @@ -37,7 +37,8 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -public final class TopicNameImpl extends Scoped implements TopicName, ITyped, IScoped { +public final class TopicNameImpl extends Scoped implements TopicName, ITyped, + IScoped, IMovable<Topic> { private String _value; private Set<Variant> _variants; @@ -104,11 +105,7 @@ } assert v._parent == null; _fireEvent(Event.ADD_VARIANT, null, v); - if (_variants == null) { - _variants = _tm.getCollectionFactory().createSet(); - } - v._parent = this; - _variants.add(v); + attachVariant(v); } void removeVariant(Variant variant) { @@ -117,10 +114,31 @@ return; } _fireEvent(Event.REMOVE_VARIANT, v, null); - _variants.remove(v); - v._parent = null; + detachVariant(v); } + void attachVariant(VariantImpl variant) { + if (_variants == null) { + _variants = _tm.getCollectionFactory().createSet(); + } + variant._parent = this; + _variants.add(variant); + } + + void detachVariant(VariantImpl variant) { + _variants.remove(variant); + variant._parent = null; + } + + /* (non-Javadoc) + * @see org.tinytim.IMovable#moveTo(java.lang.Object) + */ + public void moveTo(Topic newParent) { + _fireEvent(Event.MOVE_NAME, _parent, newParent); + ((TopicImpl) _parent).detachName(this); + ((TopicImpl) newParent).attachName(this); + } + /* (non-Javadoc) * @see org.tmapi.core.TopicMapObject#remove() */ Modified: tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-04-23 12:16:08 UTC (rev 29) @@ -41,15 +41,36 @@ * Returns if the <code>topic</code> is removable. * * A topic is removable iff it plays no role, is not used as type of + * a typed Topic Maps construct, and is not not used as theme of a scoped + * Topic Maps construct. + * + * This functions returns the same result as + * <code>isRemovable(topic, false)</code>. + * + * @param topic The topic to check. + * @return <code>true</code> if the topic is removable, <code>false</code> + * otherwise. + */ + public static boolean isRemovable(Topic topic) { + return isRemovable(topic, false); + } + + /** + * Returns if the <code>topic</code> is removable. + * + * A topic is removable iff it plays no role, is not used as type of * a typed Topic Maps construct, is not not used as theme of a scoped - * Topic Maps construct and iff it is not used reifier. + * Topic Maps construct and iff it is not used reifier + * (if <code>includeReified</code> is <code>true</code>). * * @param topic The topic to check. + * @param includeReified Indicates if a reified Topic Maps construct (if any) + * is considered as dependency. * @return <code>true</code> if the topic is removable, <code>false</code> * otherwise. */ - public static boolean isRemovable(Topic topic) { - if (((TopicImpl) topic)._reified != null) { + public static boolean isRemovable(Topic topic, boolean includeReified) { + if (includeReified && ((TopicImpl) topic)._reified != null) { return false; } if (!topic.getRolesPlayed().isEmpty()) { @@ -78,4 +99,5 @@ } return removable; } + } Modified: tinytim/trunk/src/main/java/org/tinytim/Typed.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Typed.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/main/java/org/tinytim/Typed.java 2008-04-23 12:16:08 UTC (rev 29) @@ -89,7 +89,7 @@ } /* (non-Javadoc) - * @see org.tinytim.Scoped#dispose() + * @see org.tinytim.Construct#dispose() */ @Override protected void dispose() { Modified: tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java 2008-04-23 12:16:08 UTC (rev 29) @@ -35,7 +35,7 @@ * @version $Rev$ - $Date$ */ public final class VariantImpl extends DatatypeAwareConstruct implements - Variant, IScoped { + Variant, IScoped, IMovable<TopicName> { VariantImpl(TopicMapImpl topicMap, String value, Collection<Topic> scope) { super(topicMap, null, value, scope); @@ -53,6 +53,15 @@ } /* (non-Javadoc) + * @see org.tinytim.IMovable#moveTo(java.lang.Object) + */ + public void moveTo(TopicName newParent) { + _fireEvent(Event.MOVE_VARIANT, _parent, newParent); + ((TopicNameImpl) _parent).detachVariant(this); + ((TopicNameImpl) newParent).attachVariant(this); + } + + /* (non-Javadoc) * @see org.tmapi.core.Variant#remove() */ public void remove() throws TMAPIException { Added: tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java 2008-04-23 12:16:08 UTC (rev 29) @@ -0,0 +1,155 @@ +/* + * 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 org.tmapi.core.Association; +import org.tmapi.core.AssociationRole; +import org.tmapi.core.DuplicateSourceLocatorException; +import org.tmapi.core.Locator; +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.TopicsMustMergeException; +import org.tmapi.core.Variant; + +/** + * Tests if the TMDM item identifier constraint is respected. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestItemIdentifierConstraint extends TinyTimTestCase { + + /** + * Tests against a topic map. + */ + public void testTopicMap() throws Exception { + _testConstraint(_tm); + } + + /** + * Tests againts a topic. + */ + public void testTopic() throws Exception { + Topic topic = _tm.createTopic(); + Locator iid = _tm.createLocator("http://sf.net/projects/tinytim"); + topic.addSourceLocator(iid); + assertTrue(topic.getSourceLocators().contains(iid)); + Topic topic2 = _tm.createTopic(); + try { + topic2.addSourceLocator(iid); + } + catch (TopicsMustMergeException ex) { + // noop. + } + topic.removeSourceLocator(iid); + assertFalse(topic.getSourceLocators().contains(iid)); + topic2.addSourceLocator(iid); + assertTrue(topic2.getSourceLocators().contains(iid)); + topic2.removeSourceLocator(iid); + topic.addSourceLocator(iid); + assertTrue(topic.getSourceLocators().contains(iid)); + assertFalse(topic2.getSourceLocators().contains(iid)); + topic.remove(); + topic2.addSourceLocator(iid); + assertTrue(topic2.getSourceLocators().contains(iid)); + } + + /** + * Tests against an association. + */ + public void testAssociation() throws Exception { + _testConstraint(_tm.createAssociation()); + } + + /** + * Tests against a role. + */ + public void testRole() throws Exception { + Association assoc = _tm.createAssociation(); + AssociationRole role = assoc.createAssociationRole(_tm.createTopic(), _tm.createTopic()); + _testConstraint(role); + } + + /** + * Tests against an occurrence. + */ + public void testOccurrence() throws Exception { + Topic topic = _tm.createTopic(); + Occurrence occ = topic.createOccurrence("tinyTiM", null, null); + _testConstraint(occ); + } + + /** + * Tests against a name. + */ + public void testName() throws Exception { + Topic topic = _tm.createTopic(); + TopicName name = topic.createTopicName("tinyTiM", null, null); + _testConstraint(name); + } + + /** + * Tests against a variant. + */ + public void testVariant() throws Exception { + Topic topic = _tm.createTopic(); + TopicName name = topic.createTopicName("tinyTiM", null, null); + Variant variant = name.createVariant("tinyTiM", null); + _testConstraint(variant); + } + + /** + * The item identifier constraint test. + * + * @param tmo The Topic Maps construct to test. + */ + private void _testConstraint(TopicMapObject tmo) throws Exception { + assertTrue(tmo.getSourceLocators().isEmpty()); + Locator iid = _tm.createLocator("http://sf.net/projects/tinytim"); + tmo.addSourceLocator(iid); + assertTrue(tmo.getSourceLocators().contains(iid)); + Association assoc = _tm.createAssociation(); + try { + assoc.addSourceLocator(iid); + fail("Topic Maps constructs with the same item identifier are not allowed"); + } + catch (DuplicateSourceLocatorException ex) { + // noop + } + tmo.removeSourceLocator(iid); + assertFalse(tmo.getSourceLocators().contains(iid)); + assoc.addSourceLocator(iid); + assertTrue(assoc.getSourceLocators().contains(iid)); + assoc.removeSourceLocator(iid); + assertFalse(assoc.getSourceLocators().contains(iid)); + tmo.addSourceLocator(iid); + assertTrue(tmo.getSourceLocators().contains(iid)); + if (!(tmo instanceof TopicMap)) { + // Removal should 'free' the item identifier + tmo.remove(); + assoc.addSourceLocator(iid); + assertTrue(assoc.getSourceLocators().contains(iid)); + } + } +} Property changes on: tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/test/java/org/tinytim/TestReificationUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestReificationUtils.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/test/java/org/tinytim/TestReificationUtils.java 2008-04-23 12:16:08 UTC (rev 29) @@ -34,7 +34,7 @@ * Tests against the {@link ReificationUtils}. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestReificationUtils extends TinyTimTestCase { Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicMergeDetection.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicMergeDetection.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMergeDetection.java 2008-04-23 12:16:08 UTC (rev 29) @@ -99,9 +99,9 @@ } /** - * Tests if adding a subject identifier equals to an item identifier is detected. + * Tests if adding an item identifier equals to a subject identifier is detected. */ - public void testExistingSubjectIdentifierItemIdentifier() { + public void testExistingSubjectIdentifierAddItemIdentifier() { Topic topic1 = _tm.createTopic(); Topic topic2 = _tm.createTopic(); Locator loc = _tm.createLocator("http://sf.net/projects/tinytim"); @@ -118,10 +118,10 @@ } /** - * Tests if adding a subject identifier equals to an item identifier + * Tests if adding an item identifier equals to a subject identifier * on the SAME topic is accepted */ - public void testExistingSubjectIdentifierItemIdentifierLegal() { + public void testExistingSubjectIdentifierAddItemIdentifierLegal() { Topic topic1 = _tm.createTopic(); Locator loc = _tm.createLocator("http://sf.net/projects/tinytim"); topic1.addSubjectIdentifier(loc); @@ -138,4 +138,45 @@ assertEquals(topic1, _tm.getTopicBySubjectIdentifier(loc)); assertEquals(topic1, _tm.getObjectByItemIdentifier(loc)); } + + /** + * Tests if adding a subject identifier equals to an item identifier is detected. + */ + public void testExistingItemIdentifierAddSubjectIdentifier() { + Topic topic1 = _tm.createTopic(); + Topic topic2 = _tm.createTopic(); + Locator loc = _tm.createLocator("http://sf.net/projects/tinytim"); + topic1.addSourceLocator(loc); + assertTrue(topic1.getSourceLocators().contains(loc)); + assertEquals(topic1, _tm.getObjectByItemIdentifier(loc)); + try { + topic2.addSubjectIdentifier(loc); + fail("A topic with an item identifier equals to the subject identifier '" + loc + "' exists."); + } + catch (TopicsMustMergeException ex) { + // noop. + } + } + + /** + * Tests if adding a subject identifier equals to an item identifier + * on the SAME topic is accepted + */ + public void testExistingItemIdentifierAddSubjectIdentifierLegal() { + Topic topic1 = _tm.createTopic(); + Locator loc = _tm.createLocator("http://sf.net/projects/tinytim"); + topic1.addSourceLocator(loc); + assertEquals(1, topic1.getSourceLocators().size()); + assertEquals(0, topic1.getSubjectIdentifiers().size()); + assertTrue(topic1.getSourceLocators().contains(loc)); + assertEquals(topic1, _tm.getObjectByItemIdentifier(loc)); + assertNull(_tm.getTopicBySubjectIdentifier(loc)); + topic1.addSubjectIdentifier(loc); + assertEquals(1, topic1.getSubjectIdentifiers().size()); + assertEquals(1, topic1.getSourceLocators().size()); + assertTrue(topic1.getSubjectIdentifiers().contains(loc)); + assertTrue(topic1.getSourceLocators().contains(loc)); + assertEquals(topic1, _tm.getTopicBySubjectIdentifier(loc)); + assertEquals(topic1, _tm.getObjectByItemIdentifier(loc)); + } } Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java 2008-04-22 15:12:58 UTC (rev 28) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java 2008-04-23 12:16:08 UTC (rev 29) @@ -56,7 +56,8 @@ assertTrue(TopicUtils.isRemovable(topic)); // Reifier ((IReifiable) assoc).setReifier(topic); - assertFalse(TopicUtils.isRemovable(topic)); + assertTrue(TopicUtils.isRemovable(topic)); + assertFalse(TopicUtils.isRemovable(topic, true)); ((IReifiable) assoc).setReifier(null); assertTrue(TopicUtils.isRemovable(topic)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-04-23 16:15:43
|
Revision: 32 http://tinytim.svn.sourceforge.net/tinytim/?rev=32&view=rev Author: lheuer Date: 2008-04-23 09:15:39 -0700 (Wed, 23 Apr 2008) Log Message: ----------- - Added missing TopcMapImpl - Added all TMAPI indexes Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/Construct.java tinytim/trunk/src/main/java/org/tinytim/Property.java tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/index/IScopedIndex.java tinytim/trunk/src/main/java/org/tinytim/index/ITypeInstanceIndex.java tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java tinytim/trunk/src/test/java/org/tinytim/index/TestTypeInstanceIndex.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AbstractTMAPIIndex.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/IndexFlagsImpl.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/TopicMapObjectsIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicsIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java Modified: tinytim/trunk/src/main/java/org/tinytim/Construct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Construct.java 2008-04-23 14:35:03 UTC (rev 31) +++ tinytim/trunk/src/main/java/org/tinytim/Construct.java 2008-04-23 16:15:39 UTC (rev 32) @@ -173,9 +173,10 @@ @Override public String toString() { StringBuilder sb = new StringBuilder(super.toString()); + sb.append(" ").append(_id); sb.append(" iids=["); - for (Locator sid: getItemIdentifiers()) { - sb.append(sid); + for (Locator iid: getItemIdentifiers()) { + sb.append(iid); sb.append(','); } sb.append("]"); Modified: tinytim/trunk/src/main/java/org/tinytim/Property.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Property.java 2008-04-23 14:35:03 UTC (rev 31) +++ tinytim/trunk/src/main/java/org/tinytim/Property.java 2008-04-23 16:15:39 UTC (rev 32) @@ -48,6 +48,11 @@ * * For backwards compatibilty and to support TMAPI 1.0 this property is * set to "true" by default. + * + * Note, that this property is likely to be removed in a future version and + * that only the TMDM way of reification will be supported. + * Maybe you'll be able to use {@link org.tinytim.ReificationUtils} to support + * the XTM 1.0 reification mechanism. */ public static final String XTM10_REIFICATION = "org.tinytim.XTM10Reification"; Added: tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-04-23 16:15:39 UTC (rev 32) @@ -0,0 +1,572 @@ +/* + * 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.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.tinytim.index.IndexManager; +import org.tmapi.core.Association; +import org.tmapi.core.AssociationRole; +import org.tmapi.core.HelperObjectConfigurationException; +import org.tmapi.core.HelperObjectInstantiationException; +import org.tmapi.core.Locator; +import org.tmapi.core.MergeException; +import org.tmapi.core.Occurrence; +import org.tmapi.core.TMAPIException; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.core.TopicMapObject; +import org.tmapi.core.TopicMapSystem; +import org.tmapi.core.TopicName; +import org.tmapi.core.UnsupportedHelperObjectException; +import org.tmapi.core.Variant; + +/** + * {@link org.tmapi.core.TopicMap} implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class TopicMapImpl extends Construct implements TopicMap, + IReifiable, IEventHandler, IEventPublisher { + + // Fixed set of helper objects, against the TMAPI 1.0 spec., though + private static final Map<String, String> _SUPPORTED_HELPER_OBJECTS = new HashMap<String, String>(); + + static { + _SUPPORTED_HELPER_OBJECTS.put(org.tmapi.index.core.TopicMapObjectsIndex.class.getName(), + org.tinytim.index.tmapi.TopicMapObjectsIndexImpl.class.getName()); + _SUPPORTED_HELPER_OBJECTS.put(org.tmapi.index.core.ScopedObjectsIndex.class.getName(), + org.tinytim.index.tmapi.ScopedObjectsIndexImpl.class.getName()); + _SUPPORTED_HELPER_OBJECTS.put(org.tmapi.index.core.TopicsIndex.class.getName(), + org.tinytim.index.tmapi.TopicsIndexImpl.class.getName()); + _SUPPORTED_HELPER_OBJECTS.put(org.tmapi.index.core.AssociationsIndex.class.getName(), + org.tinytim.index.tmapi.AssociationsIndexImpl.class.getName()); + _SUPPORTED_HELPER_OBJECTS.put(org.tmapi.index.core.AssociationRolesIndex.class.getName(), + org.tinytim.index.tmapi.AssociationRolesIndexImpl.class.getName()); + _SUPPORTED_HELPER_OBJECTS.put(org.tmapi.index.core.OccurrencesIndex.class.getName(), + org.tinytim.index.tmapi.OccurrencesIndexImpl.class.getName()); + _SUPPORTED_HELPER_OBJECTS.put(org.tmapi.index.core.TopicNamesIndex.class.getName(), + org.tinytim.index.tmapi.TopicNamesIndexImpl.class.getName()); + _SUPPORTED_HELPER_OBJECTS.put(org.tmapi.index.core.VariantsIndex.class.getName(), + org.tinytim.index.tmapi.VariantsIndexImpl.class.getName()); + }; + + private IdentityManager _identityManager; + private IndexManager _indexManager; + private ICollectionFactory _collectionFactory; + private Locator _locator; + private Set<Topic> _topics; + private Set<Association> _assocs; + private TopicMapSystemImpl _sys; + private Topic _reifier; + private Map<Event, List<IEventHandler>> _evtHandlers; + private EventMultiplier _eventMultiplier; + private Map<String, Object> _helperObjects; + boolean _oldReification; + + TopicMapImpl(TopicMapSystemImpl sys, Locator locator) { + super(null); + super._tm = this; + _sys = sys; + _locator = locator; + _collectionFactory = _sys.getCollectionFactory(); + _topics = _collectionFactory.createSet(100); + _assocs = _collectionFactory.createSet(100); + _evtHandlers = _collectionFactory.createMap(); + _helperObjects = _collectionFactory.createMap(); + _identityManager = new IdentityManager(this); + _indexManager = new IndexManager(this, _collectionFactory); + _eventMultiplier = new EventMultiplier(this); + _oldReification = "true".equalsIgnoreCase(sys.getProperty(Property.XTM10_REIFICATION)); + } + + ICollectionFactory getCollectionFactory() { + return _collectionFactory; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getTopicMapSystem() + */ + public TopicMapSystem getTopicMapSystem() { + return _sys; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getBaseLocator() + */ + public Locator getBaseLocator() { + return _locator; + } + + /* (non-Javadoc) + * @see org.tinytim.Construct#getTopicMap() + */ + @Override + public TopicMap getTopicMap() { + return this; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createLocator(java.lang.String) + */ + public Locator createLocator(String reference) { + return new IRI(reference); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createLocator(java.lang.String, java.lang.String) + */ + public Locator createLocator(String reference, String notation) { + assert "URI".equals(notation); + return createLocator(reference); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getTopics() + */ + public Set<Topic> getTopics() { + return Collections.unmodifiableSet(_topics); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createTopic() + */ + public Topic createTopic() { + TopicImpl topic = new TopicImpl(this); + addTopic(topic); + return topic; + } + + /** + * Adds a topic to the topics property. + * + * @param topic The topic to add. + */ + void addTopic(TopicImpl topic) { + if (topic._parent == this) { + return; + } + _fireEvent(Event.ADD_TOPIC, null, topic); + topic._parent = this; + _topics.add(topic); + } + + /** + * Removes a topic from the topics property. + * + * Caution: This method does not check if a topic has any dependencies; + * this method never reports that a topic is not removable. This + * method should only be used if a topic should be detached. + * + * @param topic The topic to remove. + */ + void removeTopic(TopicImpl topic) { + if (topic._parent != this) { + return; + } + assert topic._parent == null; + _fireEvent(Event.REMOVE_TOPIC, topic, null); + _topics.remove(topic); + topic._parent = null; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getAssociations() + */ + public Set<Association> getAssociations() { + return Collections.unmodifiableSet(_assocs); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createAssociation() + */ + public Association createAssociation() { + AssociationImpl assoc = new AssociationImpl(this); + addAssociation(assoc); + return assoc; + } + + void addAssociation(AssociationImpl assoc) { + if (assoc._parent == this) { + return; + } + _fireEvent(Event.ADD_ASSOCIATION, null, assoc); + assoc._parent = this; + _assocs.add(assoc); + } + + void removeAssociation(AssociationImpl assoc) { + if (assoc._parent != this) { + return; + } + _fireEvent(Event.REMOVE_ASSOCIATION, assoc, null); + for (AssociationRole role: assoc.getAssociationRoles()) { + TopicImpl player = (TopicImpl) role.getPlayer(); + if (player != null) { + player.removeRolePlayed(role); + } + } + _assocs.remove(assoc); + assoc._parent = null; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getObjectById(java.lang.String) + */ + public TopicMapObject getObjectById(String id) { + return _identityManager.getConstructById(id); + } + + /** + * Returns a toic by its subject identifier. + * + * @param subjectIdentifier The subject identifier. + * @return A topic or <code>null</code> if no topic with the specified + * subject identifier exists. + */ + public Topic getTopicBySubjectIdentifier(Locator subjectIdentifier) { + return _identityManager.getTopicBySubjectIdentifier(subjectIdentifier); + } + + /** + * Returns a toic by its subject locator. + * + * @param subjectLocator The subject locator. + * @return A topic or <code>null</code> if no topic with the specified + * subject locator exists. + */ + public Topic getTopicBySubjectLocator(Locator subjectLocator) { + return _identityManager.getTopicBySubjectLocator(subjectLocator); + } + + /** + * Returns a Topic Maps construct by its item identifier. + * + * @param itemIdentifier The item identifier. + * @return A Topic Maps construct or <code>null</code> if no topic with + * the specified item identifier exists. + */ + public TopicMapObject getObjectByItemIdentifier(Locator itemIdentifier) { + return _identityManager.getConstructByItemIdentifier(itemIdentifier); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getReifier() + */ + public Topic getReifier() { + if (_oldReification) { + return ReificationUtils.getReifier(this); + } + return _reifier; + } + + /* (non-Javadoc) + * @see org.tinytim.IReifiable#setReifier(org.tmapi.core.Topic) + */ + public void setReifier(Topic reifier) { + if (_reifier == reifier) { + return; + } + _fireEvent(Event.SET_REIFIER, _reifier, reifier); + if (_reifier != null) { + ((TopicImpl) _reifier)._reified = null; + } + _reifier = reifier; + if (reifier != null) { + ((TopicImpl) reifier)._reified = this; + } + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#mergeIn(org.tmapi.core.TopicMap) + */ + public void mergeIn(TopicMap other) throws MergeException { + MergeUtils.merge(other, this); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#close() + */ + public void close() { + try { + remove(); + } + catch (TMAPIException ex) { + // noop. + } + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#remove() + */ + public void remove() throws TMAPIException { + _sys.removeTopicMap(this); + _sys = null; + _locator = null; + _topics = null; + _assocs = null; + _indexManager.close(); + _indexManager = null; + _identityManager.close(); + _identityManager = null; + _eventMultiplier = null; + super.dispose(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getHelperObject(java.lang.Class) + */ + @SuppressWarnings("unchecked") + public Object getHelperObject(Class implInterface) + throws UnsupportedHelperObjectException, + HelperObjectInstantiationException, + HelperObjectConfigurationException { + String interfaceName = implInterface.getName(); + Object instance = _helperObjects.get(interfaceName); + if (instance == null) { + String className = _SUPPORTED_HELPER_OBJECTS.get(interfaceName); + if (className == null) { + throw new UnsupportedHelperObjectException("A helper object of class " + implInterface.getName() + " is not supported"); + } + try { + Class klass = Class.forName(className); + // Caution: Bypassing the configure step etc since we know + // that this constructor exists. + Constructor constr = klass.getConstructor(TopicMapImpl.class, ICollectionFactory.class); + instance = constr.newInstance(this, this._collectionFactory); + _helperObjects.put(interfaceName, instance); + } + catch (Exception ex) { + throw new HelperObjectInstantiationException(""); + } + } + return instance; + } + + /* (non-Javadoc) + * @see org.tinytim.IEventHandler#handleEvent(org.tinytim.Event, org.tinytim.IConstruct, java.lang.Object, java.lang.Object) + */ + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { + if (!_evtHandlers.containsKey(evt)) { + _eventMultiplier.handleEvent(evt, sender, oldValue, newValue); + return; + } + List<IEventHandler> handlers = _evtHandlers.get(evt); + for (IEventHandler handler: handlers) { + handler.handleEvent(evt, sender, oldValue, newValue); + } + _eventMultiplier.handleEvent(evt, sender, oldValue, newValue); + } + + /* (non-Javadoc) + * @see org.tinytim.IEventPublisher#subscribe(org.tinytim.Event, org.tinytim.IEventHandler) + */ + public void subscribe(Event event, IEventHandler handler) { + List<IEventHandler> handlers = _evtHandlers.get(event); + if (handlers == null) { + handlers = new ArrayList<IEventHandler>(); + _evtHandlers.put(event, handlers); + } + handlers.add(handler); + } + + /* (non-Javadoc) + * @see org.tinytim.IEventPublisher#unsubscribe(org.tinytim.Event, org.tinytim.IEventHandler) + */ + public void unsubscribe(Event event, IEventHandler handler) { + List<IEventHandler> handlers = _evtHandlers.get(event); + if (handlers != null) { + handlers.remove(handler); + } + } + + public IndexManager getIndexManager() { + return _indexManager; + } + + private static class EventMultiplier implements IEventHandler { + + private TopicMapImpl _handler; + + EventMultiplier(TopicMapImpl handler) { + _handler = handler; + } + + public void handleEvent(Event evt, IConstruct sender, Object oldValue, + Object newValue) { + switch (evt) { + case ADD_TOPIC: _topicAdd((TopicImpl)newValue); break; + case ADD_ASSOCIATION: _associationAdd((AssociationImpl)newValue); break; + case ADD_ROLE: _roleAdd((AssociationRoleImpl)newValue); break; + case ADD_OCCURRENCE: _occurrenceAdd((OccurrenceImpl)newValue); break; + case ADD_NAME: _nameAdd((TopicNameImpl)newValue); break; + case ADD_VARIANT: _variantAdd((VariantImpl)newValue); break; + case REMOVE_TOPIC: _topicRemove((TopicImpl) oldValue); break; + case REMOVE_ASSOCIATION: _associationRemove((AssociationImpl) oldValue); break; + case REMOVE_ROLE: _roleRemove((AssociationRoleImpl) oldValue); break; + case REMOVE_OCCURRENCE: _occurrenceRemove((OccurrenceImpl) oldValue); break; + case REMOVE_NAME: _nameRemove((TopicNameImpl) oldValue); break; + case REMOVE_VARIANT: _variantRemove((VariantImpl) oldValue); break; + } + } + + private void _topicAdd(TopicImpl sender) { + _constructAdd(sender); + for (Locator sid: sender.getSubjectIdentifiers()) { + _handler.handleEvent(Event.ADD_SID, sender, null, sid); + } + for (Locator slo: sender.getSubjectLocators()) { + _handler.handleEvent(Event.ADD_SLO, sender, null, slo); + } + for (Topic type: sender.getTypes()) { + _handler.handleEvent(Event.ADD_TYPE, sender, null, type); + } + for (Occurrence occ: sender.getOccurrences()) { + _handler.handleEvent(Event.ADD_OCCURRENCE, sender, null, occ); + } + for (TopicName name: sender.getTopicNames()) { + _handler.handleEvent(Event.ADD_NAME, sender, null, name); + } + } + + private void _associationAdd(AssociationImpl sender) { + _constructAdd(sender); + _typedAdd(sender); + _scopedAdd(sender); + for (AssociationRole role: sender.getAssociationRoles()) { + _handler.handleEvent(Event.ADD_ROLE, sender, null, role); + } + } + + private void _roleAdd(AssociationRoleImpl sender) { + _constructAdd(sender); + _typedAdd(sender); + _handler.handleEvent(Event.SET_PLAYER, sender, null, sender.getPlayer()); + } + + private void _occurrenceAdd(OccurrenceImpl sender) { + _constructAdd(sender); + _typedAdd(sender); + _scopedAdd(sender); + if (sender.getValue() != null) { + _handler.handleEvent(Event.SET_VALUE, sender, null, sender.getValue()); + } + else if (sender.getResource() != null) { + _handler.handleEvent(Event.SET_LOCATOR, sender, null, sender.getResource()); + } + } + + private void _nameAdd(TopicNameImpl sender) { + _constructAdd(sender); + _typedAdd(sender); + _scopedAdd(sender); + _handler.handleEvent(Event.SET_VALUE, sender, null, sender.getValue()); + for (Variant variant: sender.getVariants()) { + _handler.handleEvent(Event.ADD_VARIANT, sender, null, variant); + } + } + + private void _variantAdd(VariantImpl sender) { + _constructAdd(sender); + _scopedAdd(sender); + if (sender.getValue() != null) { + _handler.handleEvent(Event.SET_VALUE, sender, null, sender.getValue()); + } + else if (sender.getResource() != null) { + _handler.handleEvent(Event.SET_LOCATOR, sender, null, sender.getResource()); + } + } + + private void _typedAdd(ITyped typed) { + _handler.handleEvent(Event.SET_TYPE, typed, null, typed.getType()); + } + + private void _scopedAdd(IScoped scoped) { + for (Topic theme: scoped.getScope()) { + _handler.handleEvent(Event.ADD_THEME, scoped, null, theme); + } + } + + private void _constructAdd(IConstruct construct) { + for (Locator iid: construct.getItemIdentifiers()) { + _handler.handleEvent(Event.ADD_IID, construct, null, iid); + } + } + + private void _constructRemove(IConstruct sender) { + for (Locator iid: sender.getItemIdentifiers()) { + _handler.handleEvent(Event.REMOVE_IID, sender, iid, null); + } + } + + private void _topicRemove(TopicImpl sender) { + _constructRemove(sender); + for (Locator sid: sender.getSubjectIdentifiers()) { + _handler.handleEvent(Event.REMOVE_SID, sender, sid, null); + } + for (Locator slo: sender.getSubjectLocators()) { + _handler.handleEvent(Event.REMOVE_SLO, sender, slo, null); + } + for (Topic type: sender.getTypes()) { + _handler.handleEvent(Event.REMOVE_TYPE, sender, type, null); + } + for (Occurrence occ: sender.getOccurrences()) { + _handler.handleEvent(Event.REMOVE_OCCURRENCE, sender, occ, null); + } + for (TopicName name: sender.getTopicNames()) { + _handler.handleEvent(Event.REMOVE_NAME, sender, name, null); + } + } + + private void _associationRemove(AssociationImpl sender) { + _constructRemove(sender); + for (AssociationRole role: sender.getAssociationRoles()) { + _handler.handleEvent(Event.REMOVE_ROLE, sender, role, null); + } + } + + private void _roleRemove(AssociationRoleImpl sender) { + _constructRemove(sender); + } + + private void _occurrenceRemove(OccurrenceImpl sender) { + _constructRemove(sender); + } + + private void _nameRemove(TopicNameImpl sender) { + _constructRemove(sender); + for (Variant variant: sender.getVariants()) { + _handler.handleEvent(Event.REMOVE_VARIANT, sender, variant, null); + } + } + + private void _variantRemove(VariantImpl sender) { + _constructRemove(sender); + } + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-04-23 14:35:03 UTC (rev 31) +++ tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-04-23 16:15:39 UTC (rev 32) @@ -44,7 +44,7 @@ * a typed Topic Maps construct, and is not not used as theme of a scoped * Topic Maps construct. * - * This functions returns the same result as + * This function returns the same result as * <code>isRemovable(topic, false)</code>. * * @param topic The topic to check. Modified: tinytim/trunk/src/main/java/org/tinytim/index/IScopedIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/IScopedIndex.java 2008-04-23 14:35:03 UTC (rev 31) +++ tinytim/trunk/src/main/java/org/tinytim/index/IScopedIndex.java 2008-04-23 16:15:39 UTC (rev 32) @@ -50,6 +50,8 @@ */ public Collection<AssociationImpl> getAssociationsByTheme(Topic theme); + public Collection<Topic> getAssociationThemes(); + /** * Returns all occurrences which use the specified topic as theme. * @@ -59,6 +61,8 @@ */ public Collection<OccurrenceImpl> getOccurrencesByTheme(Topic theme); + public Collection<Topic> getOccurrenceThemes(); + /** * Returns all names which use the specified topic as theme. * @@ -68,6 +72,8 @@ */ public Collection<TopicNameImpl> getNamesByTheme(Topic theme); + public Collection<Topic> getNameThemes(); + /** * Returns all variants which use the specified topic as theme. * @@ -76,4 +82,6 @@ * in their [scope] property. */ public Collection<VariantImpl> getVariantsByTheme(Topic theme); + + public Collection<Topic> getVariantThemes(); } Modified: tinytim/trunk/src/main/java/org/tinytim/index/ITypeInstanceIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/ITypeInstanceIndex.java 2008-04-23 14:35:03 UTC (rev 31) +++ tinytim/trunk/src/main/java/org/tinytim/index/ITypeInstanceIndex.java 2008-04-23 16:15:39 UTC (rev 32) @@ -50,9 +50,21 @@ * <code>null</code> all untyped topics will be returned. * @return A (maybe empty) collection of topic instances. */ - public Collection<Topic> getTopics(Topic... type); + public Collection<Topic> getTopics(Topic type); /** + * Returns these topics which have the one of the specified + * <code>types</code> iff <code>matchAll</code> is false. Iff + * <code>matchAll</code> is <code>true</code>, these topics will be returned + * which have all the specified <code>types</code>. + * + * @param types The types to match + * @param matchAll Indicates if a topic must have all types to be part of the result. + * @return A (maybe empty) collection of topic instances. + */ + public Collection<Topic> getTopics(Topic[] types, boolean matchAll); + + /** * Returns the associations that are typed by the {@link org.tmapi.core.Topic} * <code>type</code>. * Modified: tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java 2008-04-23 14:35:03 UTC (rev 31) +++ tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java 2008-04-23 16:15:39 UTC (rev 32) @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -39,8 +40,8 @@ import org.tmapi.core.Topic; /** + * {@link IScopedIndex} implementation. * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ @@ -58,6 +59,16 @@ _theme2Variants = collFactory.createMap(); publisher.subscribe(Event.ADD_THEME, new AddThemeHandler()); publisher.subscribe(Event.REMOVE_THEME, new RemoveThemeHandler()); + IEventHandler handler = new AddScopedHandler(); + publisher.subscribe(Event.ADD_ASSOCIATION, handler); + publisher.subscribe(Event.ADD_OCCURRENCE, handler); + publisher.subscribe(Event.ADD_NAME, handler); + publisher.subscribe(Event.ADD_VARIANT, handler); + handler = new RemoveScopedHandler(); + publisher.subscribe(Event.REMOVE_ASSOCIATION, handler); + publisher.subscribe(Event.REMOVE_OCCURRENCE, handler); + publisher.subscribe(Event.REMOVE_NAME, handler); + publisher.subscribe(Event.REMOVE_VARIANT, handler); } /* (non-Javadoc) @@ -70,6 +81,15 @@ } /* (non-Javadoc) + * @see org.tinytim.index.IScopedIndex#getAssociationThemes() + */ + public Collection<Topic> getAssociationThemes() { + List<Topic> themes = new ArrayList<Topic>(_theme2Assocs.keySet()); + themes.remove(null); + return themes; + } + + /* (non-Javadoc) * @see org.tinytim.index.IScopedIndex#getOccurrencesByTheme(org.tmapi.core.Topic) */ public Collection<OccurrenceImpl> getOccurrencesByTheme(Topic theme) { @@ -79,6 +99,15 @@ } /* (non-Javadoc) + * @see org.tinytim.index.IScopedIndex#getOccurrenceThemes() + */ + public Collection<Topic> getOccurrenceThemes() { + List<Topic> themes = new ArrayList<Topic>(_theme2Occs.keySet()); + themes.remove(null); + return themes; + } + + /* (non-Javadoc) * @see org.tinytim.index.IScopedIndex#getNamesByTheme(org.tmapi.core.Topic) */ public Collection<TopicNameImpl> getNamesByTheme(Topic theme) { @@ -88,6 +117,15 @@ } /* (non-Javadoc) + * @see org.tinytim.index.IScopedIndex#getNameThemes() + */ + public Collection<Topic> getNameThemes() { + List<Topic> themes = new ArrayList<Topic>(_theme2Names.keySet()); + themes.remove(null); + return themes; + } + + /* (non-Javadoc) * @see org.tinytim.index.IScopedIndex#getVariantsByTheme(org.tmapi.core.Topic) */ public Collection<VariantImpl> getVariantsByTheme(Topic theme) { @@ -97,6 +135,15 @@ } /* (non-Javadoc) + * @see org.tinytim.index.IScopedIndex#getVariantThemes() + */ + public Collection<Topic> getVariantThemes() { + List<Topic> themes = new ArrayList<Topic>(_theme2Variants.keySet()); + themes.remove(null); + return themes; + } + + /* (non-Javadoc) * @see org.tinytim.index.IIndex#close() */ public void close() { @@ -128,56 +175,126 @@ _theme2Variants = null; } - private final class AddThemeHandler implements IEventHandler { + private abstract class _EvtHandler implements IEventHandler { @SuppressWarnings("unchecked") - public void handleEvent(Event evt, IConstruct sender, Object oldValue, - Object newValue) { + Map<Topic, List<ScopedObject>> getMap(ScopedObject scoped) { Map<Topic, ?> theme2Scoped = null; - if (sender instanceof AssociationImpl) { + if (scoped instanceof AssociationImpl) { theme2Scoped = _theme2Assocs; } - else if (sender instanceof OccurrenceImpl) { + else if (scoped instanceof OccurrenceImpl) { theme2Scoped = _theme2Occs; } - else if (sender instanceof TopicNameImpl) { + else if (scoped instanceof TopicNameImpl) { theme2Scoped = _theme2Names; } - else if (sender instanceof VariantImpl) { + else if (scoped instanceof VariantImpl) { theme2Scoped = _theme2Variants; } - _index((Map<Topic, List<ScopedObject>>) theme2Scoped, (Topic) newValue, (ScopedObject) sender); + return (Map<Topic, List<ScopedObject>>) theme2Scoped; } + } - private void _index(Map<Topic, List<ScopedObject>> theme2Scoped, - Topic newValue, ScopedObject sender) { - List<ScopedObject> scopedConstructs = theme2Scoped.get(newValue); - if (scopedConstructs == null) { - scopedConstructs = new ArrayList<ScopedObject>(); - theme2Scoped.put(newValue, scopedConstructs); + private final class AddScopedHandler extends _EvtHandler { + @SuppressWarnings("unchecked") + @Override + public void handleEvent(Event evt, IConstruct sender, Object oldValue, + Object newValue) { + ScopedObject scoped = (ScopedObject) newValue; + Map<Topic, List<ScopedObject>> map = getMap(scoped); + List<ScopedObject> list = null; + if (scoped.getScope().isEmpty()) { + list = map.get(null); + if (list == null) { + list = new ArrayList<ScopedObject>(); + map.put(null, list); + } + list.add(scoped); } - scopedConstructs.add(sender); + else { + for (Iterator<Topic> iter = scoped.getScope().iterator(); iter.hasNext();) { + Topic theme = iter.next(); + list = map.get(theme); + if (list == null) { + list = new ArrayList<ScopedObject>(); + map.put(theme, list); + } + list.add(scoped); + } + } } + } - private final class RemoveThemeHandler implements IEventHandler { + private final class RemoveScopedHandler extends _EvtHandler { + @SuppressWarnings("unchecked") + @Override public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { - List<?> scoped = null; - if (sender instanceof AssociationImpl) { - scoped = _theme2Assocs.get(oldValue); + ScopedObject scoped = (ScopedObject) oldValue; + Map<Topic, List<ScopedObject>> map = getMap(scoped); + List<ScopedObject> list = null; + if (scoped.getScope().isEmpty()) { + list = map.get(null); + if (list != null) { + list.remove(scoped); + } } - else if (sender instanceof OccurrenceImpl) { - scoped = _theme2Occs.get(oldValue); + else { + for (Iterator<Topic> iter = scoped.getScope().iterator(); iter.hasNext();) { + Topic theme = iter.next(); + list = map.get(theme); + if (list != null) { + list.remove(scoped); + if (list.isEmpty()) { + map.remove(theme); + } + } + } } - else if (sender instanceof TopicNameImpl) { - scoped = _theme2Names.get(oldValue); + } + + } + + private final class AddThemeHandler extends _EvtHandler { + @SuppressWarnings("unchecked") + public void handleEvent(Event evt, IConstruct sender, Object oldValue, + Object newValue) { + ScopedObject scoped = (ScopedObject) sender; + Map<Topic, List<ScopedObject>> map = getMap(scoped); + List<ScopedObject> list = map.get(newValue); + if (list == null) { + list = new ArrayList<ScopedObject>(); + map.put((Topic)newValue, list); } - else if (sender instanceof VariantImpl) { - scoped = _theme2Variants.get(oldValue); + list.add(scoped); + list = map.get(null); + if (list != null) { + list.remove(scoped); } - if (scoped != null) { - scoped.remove(sender); + } + } + + private final class RemoveThemeHandler extends _EvtHandler { + public void handleEvent(Event evt, IConstruct sender, Object oldValue, + Object newValue) { + ScopedObject scoped = (ScopedObject) sender; + Map<Topic, List<ScopedObject>> map = getMap(scoped); + List<ScopedObject> list = map.get(oldValue); + if (list != null) { + list.remove(scoped); + if (list.isEmpty()) { + map.remove(oldValue); + } } + if (scoped.getScope().size() == 1) { + list = map.get(null); + if (list == null) { + list = new ArrayList<ScopedObject>(); + map.put(null, list); + } + list.add(scoped); + } } } Modified: tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java 2008-04-23 14:35:03 UTC (rev 31) +++ tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java 2008-04-23 16:15:39 UTC (rev 32) @@ -48,7 +48,7 @@ */ public class TypeInstanceIndex implements ITypeInstanceIndex { - private Map<Topic, List<Topic>> _type2Topics; + private Map<Topic, Set<Topic>> _type2Topics; private Map<Topic, List<AssociationImpl>> _type2Assocs; private Map<Topic, List<AssociationRoleImpl>> _type2Roles; private Map<Topic, List<OccurrenceImpl>> _type2Occs; @@ -63,15 +63,26 @@ IEventHandler handler = new TopicTypeHandler(); publisher.subscribe(Event.ADD_TYPE, handler); publisher.subscribe(Event.REMOVE_TYPE, handler); + handler = new AddTopicHandler(); + publisher.subscribe(Event.ADD_TOPIC, handler); + handler = new RemoveTopicHandler(); + publisher.subscribe(Event.REMOVE_TOPIC, handler); handler = new TypeHandler(); publisher.subscribe(Event.SET_TYPE, handler); + handler = new RemoveTypedHandler(); + publisher.subscribe(Event.REMOVE_ASSOCIATION, handler); + publisher.subscribe(Event.REMOVE_ROLE, handler); + publisher.subscribe(Event.REMOVE_OCCURRENCE, handler); + publisher.subscribe(Event.REMOVE_NAME, handler); } /* (non-Javadoc) * @see org.tinytim.index.ITypeInstanceIndex#getAssociationTypes() */ public Collection<Topic> getAssociationTypes() { - return Collections.unmodifiableSet(_type2Assocs.keySet()); + List<Topic> topics = new ArrayList<Topic>(_type2Assocs.keySet()); + topics.remove(null); + return topics; } /* (non-Javadoc) @@ -87,7 +98,9 @@ * @see org.tinytim.index.ITypeInstanceIndex#getRoleTypes() */ public Collection<Topic> getRoleTypes() { - return Collections.unmodifiableSet(_type2Roles.keySet()); + List<Topic> topics = new ArrayList<Topic>(_type2Roles.keySet()); + topics.remove(null); + return topics; } /* (non-Javadoc) @@ -103,7 +116,9 @@ * @see org.tinytim.index.ITypeInstanceIndex#getOccurrenceTypes() */ public Collection<Topic> getOccurrenceTypes() { - return Collections.unmodifiableSet(_type2Occs.keySet()); + List<Topic> topics = new ArrayList<Topic>(_type2Occs.keySet()); + topics.remove(null); + return topics; } /* (non-Javadoc) @@ -119,7 +134,9 @@ * @see org.tinytim.index.ITypeInstanceIndex#getNameTypes() */ public Collection<Topic> getNameTypes() { - return Collections.unmodifiableSet(_type2Names.keySet()); + List<Topic> topics = new ArrayList<Topic>(_type2Names.keySet()); + topics.remove(null); + return topics; } /* (non-Javadoc) @@ -135,28 +152,54 @@ * @see org.tinytim.index.ITypeInstanceIndex#getTopicTypes() */ public Collection<Topic> getTopicTypes() { - return Collections.unmodifiableSet(_type2Topics.keySet()); + List<Topic> topics = new ArrayList<Topic>(_type2Topics.keySet()); + topics.remove(null); + return topics; } /* (non-Javadoc) * @see org.tinytim.index.ITypeInstanceIndex#getTopics(org.tmapi.core.Topic[]) */ - public Collection<Topic> getTopics(Topic... types) { - if (types == null || types.length == 1) { - List<Topic> topics = _type2Topics.get(types[0]); - return topics == null ? Collections.<Topic>emptySet() - : new ArrayList<Topic>(topics); + public Collection<Topic> getTopics(Topic type) { + Set<Topic> topics = _type2Topics.get(type); + return topics == null ? Collections.<Topic>emptySet() + : new ArrayList<Topic>(topics); + } + + /* (non-Javadoc) + * @see org.tinytim.index.ITypeInstanceIndex#getTopics(org.tmapi.core.Topic[], boolean) + */ + public Collection<Topic> getTopics(Topic[] types, boolean matchAll) { + if (types.length == 1) { + return getTopics(types[0]); } - Set<Topic> topics = new HashSet<Topic>(10); - for (Topic type: types) { - List<Topic> matches = _type2Topics.get(type); - if (matches != null) { - topics.addAll(matches); + if (!matchAll) { + Set<Topic> topics = new HashSet<Topic>(); + for (Topic type: types) { + Set<Topic> matches = _type2Topics.get(type); + if (matches != null) { + topics.addAll(matches); + } } + return topics; } - return topics; + else { + Set<Topic> topics = new HashSet<Topic>(getTopics(types[0])); + for (int i=1; i < types.length; i++) { + topics.retainAll(getTopics(types[i])); + } + return topics; + } } + private boolean _unindex(List<ITyped> objects, Object obj) { + if (objects == null) { + return false; + } + objects.remove(obj); + return objects.isEmpty(); + } + /* (non-Javadoc) * @see org.tinytim.index.IIndex#close() */ @@ -178,6 +221,52 @@ // noop. } + private final class AddTopicHandler implements IEventHandler { + @SuppressWarnings("unchecked") + public void handleEvent(Event evt, IConstruct sender, Object oldValue, + Object newValue) { + Topic topic = (Topic) newValue; + Collection<Topic> types = topic.getTypes(); + if (types.isEmpty()) { + Set<Topic> topics = _type2Topics.get(null); + if (topics == null) { + topics = new HashSet<Topic>(); + _type2Topics.put(null, topics); + } + topics.add(topic); + } + else { + for (Topic type: types) { + Set<Topic> topics = _type2Topics.get(type); + if (topics == null) { + topics = new HashSet<Topic>(); + _type2Topics.put(type, topics); + } + topics.add(topic); + } + } + } + } + + private final class RemoveTopicHandler implements IEventHandler { + @SuppressWarnings("unchecked") + public void handleEvent(Event evt, IConstruct sender, Object oldValue, + Object newValue) { + Topic topic = (Topic) oldValue; + Set<Topic> topics = _type2Topics.get(null); + if (topics != null) { + topics.remove(topic); + } + Collection<Topic> types = topic.getTypes(); + for (Topic type: types) { + topics = _type2Topics.get(type); + if (topics != null) { + topics.remove(topic); + } + } + } + } + /** * Handler that (un-)indexes topics by their type. */ @@ -186,19 +275,35 @@ Object newValue) { Topic topic = (Topic) sender; if (oldValue == null) { - List<Topic> topics = _type2Topics.get(newValue); + // Adding a type + Set<Topic> topics = _type2Topics.get(newValue); if (topics == null) { - topics = new ArrayList<Topic>(); + topics = new HashSet<Topic>(); _type2Topics.put((Topic) newValue, topics); } topics.add(topic); + topics = _type2Topics.get(null); + if (topics != null) { + topics.remove(topic); + } } else { - List<Topic> topics = _type2Topics.get(oldValue); + Set<Topic> topics = _type2Topics.get(oldValue); if (topics == null) { return; } topics.remove(topic); + if (topics.isEmpty()) { + _type2Topics.remove(oldValue); + } + if (topic.getTypes().size() == 1) { + topics = _type2Topics.get(null); + if (topics == null) { + topics = new HashSet<Topic>(); + _type2Topics.put(null, topics); + } + topics.add(topic); + } } } } @@ -220,7 +325,9 @@ else if (sender instanceof TopicNameImpl) { type2Typed = _type2Names; } - _unindex((List<ITyped>)type2Typed.get(oldValue), sender); + if (_unindex((List<ITyped>)type2Typed.get((Topic)oldValue), sender)) { + type2Typed.remove(oldValue); + } _index((Map<Topic, List<ITyped>>) type2Typed, (Topic) newValue, (ITyped) sender); } @@ -233,12 +340,29 @@ } typedConstructs.add(sender); } + } - private void _unindex(List<ITyped> objects, Object obj) { - if (objects == null) { - return; + private final class RemoveTypedHandler implements IEventHandler { + @SuppressWarnings("unchecked") + public void handleEvent(Event evt, IConstruct sender, Object oldValue, + Object newValue) { + Map<Topic, ?> type2Typed = null; + if (oldValue instanceof AssociationImpl) { + type2Typed = _type2Assocs; } - objects.remove(obj); + else if (oldValue instanceof AssociationRoleImpl) { + type2Typed = _type2Roles; + } + else if (oldValue instanceof OccurrenceImpl) { + type2Typed = _type2Occs; + } + else if (oldValue instanceof TopicNameImpl) { + type2Typed = _type2Names; + } + Topic type = ((ITyped) oldValue).getType(); + if (_unindex((List<ITyped>)type2Typed.get(type), oldValue)) { + type2Typed.remove(type); + } } } Added: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AbstractTMAPIIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AbstractTMAPIIndex.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AbstractTMAPIIndex.java 2008-04-23 16:15:39 UTC (rev 32) @@ -0,0 +1,75 @@ +/* + * 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.tmapi; + +import java.lang.ref.WeakReference; + +import org.tinytim.ICollectionFactory; +import org.tinytim.TopicMapImpl; +import org.tmapi.core.HelperObjectConfigurationException; +import org.tmapi.core.TopicMap; +import org.tmapi.index.Index; +import org.tmapi.index.TMAPIIndexException; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +abstract class AbstractTMAPIIndex implements Index { + + protected WeakReference<TopicMapImpl> _weakTopicMap; + + public AbstractTMAPIIndex(TopicMapImpl topicMap, ICollectionFactory collFactory) { + _weakTopicMap = new WeakReference<TopicMapImpl>(topicMap); + } + + /* (non-Javadoc) + * @see org.tmapi.index.Index#close() + */ + public void close() throws TMAPIIndexException { + // noop. + } + + /* (non-Javadoc) + * @see org.tmapi.index.Index#isOpen() + */ + public boolean isOpen() throws TMAPIIndexException { + return true; + } + + /* (non-Javadoc) + * @see org.tmapi.index.Index#open() + */ + public void open() throws TMAPIIndexException { + // noop. + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem.ConfigurableHelperObject#configure(org.tmapi.core.TopicMap) + */ + public void configure(TopicMap tm) + throws HelperObjectConfigurationException { + // noop. + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AbstractTMAPIIndex.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java 2008-04-23 16:15:39 UTC (rev 32) @@ -0,0 +1,75 @@ +/* + * 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.tmapi; + +import java.util.Collection; + +import org.tinytim.AssociationRoleImpl; +import org.tinytim.ICollectionFactory; +import org.tinytim.TopicMapImpl; +import org.tmapi.core.Topic; +import org.tmapi.index.IndexFlags; +import org.tmapi.index.TMAPIIndexException; +import org.tmapi.index.core.AssociationRolesIndex; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class AssociationRolesIndexImpl extends AbstractTMAPIIndex implements + AssociationRolesIndex { + + public AssociationRolesIndexImpl(TopicMapImpl topicMap, + ICollectionFactory collFactory) { + super(topicMap, collFactory); + } + + /* (non-Javadoc) + * @see org.tmapi.index.core.AssociationRolesIndex#getAssociationRoleTypes() + */ + public Collection<Topic> getAssociationRoleTypes() { + return _weakTopicMap.get().getIndexManager().getTypeInstanceIndex().getRoleTypes(); + } + + /* (non-Javadoc) + * @see org.tmapi.index.core.AssociationRolesIndex#getAssociationRolesByType(org.tmapi.core.Topic) + */ + public Collection<AssociationRoleImpl> getAssociationRolesByType(Topic type) { + return _weakTopicMap.get().getIndexManager().getTypeInstanceIndex().getRoles(type); + } + + /* (non-Javadoc) + * @see org.tmapi.index.Index#getFlags() + */ + public IndexFlags getFlags() throws TMAPIIndexException { + return IndexFlagsImpl.AUTOUPDATED; + } + + /* (non-Javadoc) + * @see org.tmapi.index.Index#reindex() + */ + public void reindex() throws TMAPIIndexException { + // noop. + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java 2008-04-23 16:15:39 UTC (rev 32) @@ -0,0 +1,75 @@ +/* + * 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.tmapi; + +import java.util.Collection; + +import org.tinytim.AssociationImpl; +import org.tinytim.ICollectionFactory; +import org.tinytim.TopicMapImpl; +import org.tmapi.core.Topic; +import org.tmapi.index.IndexFlags; +import org.tmapi.index.TMAPIIndexException; +import org.tmapi.index.core.AssociationsIndex; + +/** + * Implementation of the {@link org.tmapi.index.core.AssociationsIndex}; + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class AssociationsIndexImpl extends AbstractTMAPIIndex implements + AssociationsIndex { + + public AssociationsIndexImpl(TopicMapImpl topicMap, + ICollectionFactory collFactory) { + super(topicMap, collFactory); + } + + /* (non-Javadoc) + * @see org.tmapi.index.core.AssociationsIndex#getAssociationTypes() + */ + public Collection<Topic> getAssociationTypes() { + return _weakTopicMap.get().getIndexManager().getTypeInstanceIndex().getAssociationTypes(); + } + + /* (non-Javadoc) + * @see org.tmapi.index.core.AssociationsIndex#getAssociationsByType(org.tmapi.core.Topic) + */ + public Collection<AssociationImpl> getAssociationsByType(Topic type) { + return _weakTopicMap.get().getIndexManager().getTypeInstanceIndex().getAssociations(type); + } + + /* (non-Javadoc) + * @see org.tmapi.index.Index#getFlags() + */ + public IndexFlags getFlags() throws TMAPIIndexException { + return IndexFlagsImpl.AUTOUPDATED; + } + + /* (non-Javadoc) + * @see org.tmapi.index.Index#reindex() + */ + public void reindex() throws TMAPIIndexException { + // noop. + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/IndexFlagsImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/IndexFlagsImpl.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/IndexFlagsImpl.java 2008-04-23 16:15:39 UTC (rev 32) @@ -0,0 +1,58 @@ +/* + * 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.tmapi; + +import org.tmapi.index.IndexFlags; + +/** + * Immutable {@link org.tmapi.index.IndexFlags} implementation. + * + * Use {@link #AUTOUPDATED} or {@link #NOT_AUTOUPDATED} + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +final class IndexFlagsImpl implements IndexFlags { + + /** + * Indicates that the index is auto updated. + */ + public static IndexFlags AUTOUPDATED = new IndexFlagsImpl(true); + + /** + * Indicates that the index is NOT auto updated. + */ + public static IndexFlags NOT_AUTOUPDATED = new IndexFlagsImpl(false); + + private final boolean _autoUpdated; + + private IndexFlagsImpl(boolean autoUpdated) { + _autoUpdated = autoUpdated; + } + + /* (non-Javadoc) + * @see org.tmapi.index.IndexFlags#isAutoUpdated() + */ + public boolean isAutoUpdated() { + return _autoUpdated; + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/IndexFlagsImpl.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-sty... [truncated message content] |
From: <lh...@us...> - 2008-04-23 17:55:59
|
Revision: 34 http://tinytim.svn.sourceforge.net/tinytim/?rev=34&view=rev Author: lheuer Date: 2008-04-23 10:55:30 -0700 (Wed, 23 Apr 2008) Log Message: ----------- - JavaDocs - More topic merge tests Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AbstractTMAPIIndex.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/TopicMapObjectsIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicsIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AbstractTMAPIIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AbstractTMAPIIndex.java 2008-04-23 16:24:46 UTC (rev 33) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AbstractTMAPIIndex.java 2008-04-23 17:55:30 UTC (rev 34) @@ -33,7 +33,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ abstract class AbstractTMAPIIndex implements Index { Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java 2008-04-23 16:24:46 UTC (rev 33) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java 2008-04-23 17:55:30 UTC (rev 34) @@ -31,10 +31,10 @@ import org.tmapi.index.core.AssociationRolesIndex; /** + * Implementation of the {@link org.tmapi.index.core.AssociationRolesIndex}; * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class AssociationRolesIndexImpl extends AbstractTMAPIIndex implements AssociationRolesIndex { Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java 2008-04-23 16:24:46 UTC (rev 33) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java 2008-04-23 17:55:30 UTC (rev 34) @@ -34,7 +34,7 @@ * Implementation of the {@link org.tmapi.index.core.AssociationsIndex}; * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class AssociationsIndexImpl extends AbstractTMAPIIndex implements AssociationsIndex { Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java 2008-04-23 16:24:46 UTC (rev 33) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java 2008-04-23 17:55:30 UTC (rev 34) @@ -42,7 +42,7 @@ * Implementation of the {@link org.tmapi.index.core.OccurrencesIndex}. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class OccurrencesIndexImpl extends AbstractTMAPIIndex implements OccurrencesIndex { Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ScopedObjectsIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ScopedObjectsIndexImpl.java 2008-04-23 16:24:46 UTC (rev 33) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ScopedObjectsIndexImpl.java 2008-04-23 17:55:30 UTC (rev 34) @@ -39,7 +39,7 @@ * {@link org.tmapi.index.core.ScopedObjectsIndex} implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class ScopedObjectsIndexImpl extends AbstractTMAPIIndex implements ScopedObjectsIndex { Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicMapObjectsIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicMapObjectsIndexImpl.java 2008-04-23 16:24:46 UTC (rev 33) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicMapObjectsIndexImpl.java 2008-04-23 17:55:30 UTC (rev 34) @@ -29,10 +29,10 @@ import org.tmapi.index.core.TopicMapObjectsIndex; /** + * Implementation of the {@link org.tmapi.index.core.TopicMapObjectsIndex}; * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TopicMapObjectsIndexImpl extends AbstractTMAPIIndex implements TopicMapObjectsIndex { Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java 2008-04-23 16:24:46 UTC (rev 33) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java 2008-04-23 17:55:30 UTC (rev 34) @@ -38,10 +38,10 @@ import org.tmapi.index.core.TopicNamesIndex; /** + * Implementation of the {@link org.tmapi.index.core.TopicNamesIndex}; * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TopicNamesIndexImpl extends AbstractTMAPIIndex implements TopicNamesIndex { Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicsIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicsIndexImpl.java 2008-04-23 16:24:46 UTC (rev 33) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicsIndexImpl.java 2008-04-23 17:55:30 UTC (rev 34) @@ -35,7 +35,7 @@ * {@link org.tmapi.index.core.TopicsIndex} implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TopicsIndexImpl extends AbstractTMAPIIndex implements TopicsIndex { Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java 2008-04-23 16:24:46 UTC (rev 33) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java 2008-04-23 17:55:30 UTC (rev 34) @@ -41,7 +41,7 @@ * Implementation of the {@link org.tmapi.index.core.VariantsIndex}. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class VariantsIndexImpl extends AbstractTMAPIIndex implements VariantsIndex { Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-04-23 16:24:46 UTC (rev 33) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-04-23 17:55:30 UTC (rev 34) @@ -26,6 +26,7 @@ import org.tmapi.core.AssociationRole; import org.tmapi.core.Locator; import org.tmapi.core.ModelConstraintException; +import org.tmapi.core.Occurrence; import org.tmapi.core.Topic; import org.tmapi.core.TopicName; import org.tmapi.core.Variant; @@ -193,4 +194,51 @@ Variant tmpVar = (Variant) tmpName.getVariants().iterator().next(); assertEquals("tiny", tmpVar.getValue()); } + + /** + * Tests if merging detects duplicate occurrences. + */ + public void testDuplicateSuppressionOccurrence() { + Topic topic1 = _tm.createTopic(); + Topic topic2 = _tm.createTopic(); + Occurrence occ1 = topic1.createOccurrence("tinyTiM", null, null); + Occurrence occ2 = topic2.createOccurrence("tinyTiM", null, null); + Occurrence occ3 = topic2.createOccurrence("tiny Topic Maps engine", null, null); + assertEquals(1, topic1.getOccurrences().size()); + assertTrue(topic1.getOccurrences().contains(occ1)); + assertEquals(2, topic2.getOccurrences().size()); + assertTrue(topic2.getOccurrences().contains(occ2)); + assertTrue(topic2.getOccurrences().contains(occ3)); + topic1.mergeIn(topic2); + assertEquals(2, topic1.getOccurrences().size()); + } + + /** + * Tests if merging detects duplicate occurrences and moves the + * item identifiers. + */ + public void testDuplicateSuppressionOccurrenceItemIdentifiers() { + Topic topic1 = _tm.createTopic(); + Topic topic2 = _tm.createTopic(); + Locator iid1 = _tm.createLocator("http://example.org/iid-1"); + Locator iid2 = _tm.createLocator("http://example.org/iid-2"); + Occurrence occ1 = topic1.createOccurrence("tinyTiM", null, null); + occ1.addSourceLocator(iid1); + assertTrue(occ1.getSourceLocators().contains(iid1)); + Occurrence occ2 = topic2.createOccurrence("tinyTiM", null, null); + occ2.addSourceLocator(iid2); + assertTrue(occ2.getSourceLocators().contains(iid2)); + assertEquals(1, topic1.getOccurrences().size()); + assertTrue(topic1.getOccurrences().contains(occ1)); + assertEquals(1, topic2.getOccurrences().size()); + assertTrue(topic2.getOccurrences().contains(occ2)); + topic1.mergeIn(topic2); + assertEquals(1, topic1.getOccurrences().size()); + Occurrence occ = (Occurrence) topic1.getOccurrences().iterator().next(); + assertEquals(2, occ.getSourceLocators().size()); + assertTrue(occ.getSourceLocators().contains(iid1)); + assertTrue(occ.getSourceLocators().contains(iid2)); + assertEquals("tinyTiM", occ.getValue()); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-04-24 12:13:25
|
Revision: 35 http://tinytim.svn.sourceforge.net/tinytim/?rev=35&view=rev Author: lheuer Date: 2008-04-24 05:04:37 -0700 (Thu, 24 Apr 2008) Log Message: ----------- - More tests - CopyUtils finished (needs testing, though) - Added getReifiedConstruct() to the TopicImpl to avoid direct access to that field in most cases Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/IMovable.java tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java tinytim/trunk/src/main/resources/META-INF/services/org.tmapi.core.TopicMapSystemFactory tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java Modified: tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java 2008-04-23 17:55:30 UTC (rev 34) +++ tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java 2008-04-24 12:04:37 UTC (rev 35) @@ -22,12 +22,17 @@ import java.util.Iterator; import java.util.Map; +import java.util.Set; +import org.tmapi.core.Association; +import org.tmapi.core.AssociationRole; import org.tmapi.core.Locator; 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; /** * This class provides methods to copy Topic Maps constructs from one @@ -107,8 +112,17 @@ _copyTypes(topic, targetTopic, mergeMap); _copyCharacteristics(topic, (TopicImpl)targetTopic, mergeMap); } + _copyAssociations(source, target, mergeMap); } + /** + * Copies the <code>topic</code> to the <code>target</code> topic map. + * + * @param topic The topic to copy. + * @param target The target topic map. + * @param mergeMap The map which holds the merge mappings. + * @return The newly created topic in the target topic map. + */ private static Topic _copyTopic(Topic topic, TopicMap target, Map<Topic, Topic> mergeMap) { Topic targetTopic = target.createTopic(); @@ -118,6 +132,13 @@ return targetTopic; } + /** + * Copies the identities (item identifiers, subject identifiers and subject + * locators) from the <code>source/code> to the <code>targetTopic</code>. + * + * @param topic The topic to take the identities from. + * @param targetTopic The topic which gets the identities. + */ @SuppressWarnings("unchecked") private static void _copyIdentities(Topic topic, Topic targetTopic) { for(Iterator<Locator> iter = topic.getSubjectIdentifiers().iterator(); iter.hasNext();) { @@ -129,6 +150,13 @@ _copyItemIdentifiers((IConstruct)topic, (IConstruct)targetTopic); } + /** + * Copies the types from the <code>topic</code> to the <code>targetTopic</code>. + * + * @param topic The topic to take the types from. + * @param targetTopic The topic which receives the types. + * @param mergeMap The map which holds the merge mappings. + */ @SuppressWarnings("unchecked") private static void _copyTypes(Topic topic, Topic targetTopic, Map<Topic, Topic> mergeMap) { @@ -142,20 +170,206 @@ } } + /** + * Copies the occurrences and names from <code>topic</code> to the + * <code>targetTopic</code>. + * + * @param topic The topic to take the characteristics from. + * @param targetTopic The target topic which gets the charateristics. + * @param mergeMap The map which holds the merge mappings. + */ private static void _copyCharacteristics(Topic topic, TopicImpl targetTopic, Map<Topic, Topic> mergeMap) { Map<String, IReifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().<String, IReifiable>createMap(); for (Occurrence occ: targetTopic.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), (IReifiable)occ); } + IReifiable existing = null; + for (Occurrence occ: ((TopicImpl) topic).getOccurrences()) { + Occurrence targetOcc = targetTopic.createOccurrence((String)null, null, null); + _copyType((ITyped)occ, (ITyped)targetOcc, mergeMap); + _copyScope((IScoped)occ, (IScoped)targetOcc, mergeMap); + if (occ.getValue() != null) { + targetOcc.setValue(occ.getValue()); + } + else if (occ.getResource() != null) { + targetOcc.setResource(occ.getResource()); + } + existing = sigs.get(SignatureGenerator.generateSignature(targetOcc)); + if (existing != null) { + MergeUtils.removeConstruct((IConstruct) targetOcc); + targetOcc = (Occurrence)existing; + } + _copyReifier((IReifiable) occ, (IReifiable) targetOcc, mergeMap); + _copyItemIdentifiers((IConstruct) occ, (IConstruct) targetOcc); + } + sigs.clear(); + for (TopicName name: targetTopic.getTopicNames()) { + sigs.put(SignatureGenerator.generateSignature(name), (IReifiable)name); + } + for (TopicName name: ((TopicImpl) topic).getTopicNames()) { + TopicName targetName = targetTopic.createTopicName(name.getValue(), null); + _copyType((ITyped) name, (ITyped) targetName, mergeMap); + _copyScope((IScoped) name, (IScoped) targetName, mergeMap); + existing = sigs.get(SignatureGenerator.generateSignature(targetName)); + if (existing != null) { + MergeUtils.removeConstruct((IConstruct)targetName); + targetName = (TopicName) existing; + } + _copyReifier((IReifiable) name, (IReifiable) targetName, mergeMap); + _copyItemIdentifiers((IConstruct) name, (IConstruct) targetName); + _copyVariants(name, targetName, mergeMap); + } } + /** + * Copies the variants from <code>source</code> to the <code>target</code>. + * + * @param source The name to take the variants from. + * @param target The target name which receives the variants. + * @param mergeMap The map which holds the merge mappings. + */ + private static void _copyVariants(TopicName source, TopicName target, + Map<Topic, Topic> mergeMap) { + Map<String, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); + for (Variant variant: ((TopicNameImpl) target).getVariants()) { + sigs.put(SignatureGenerator.generateSignature(variant), variant); + } + Variant existing = null; + for (Variant variant: ((TopicNameImpl) source).getVariants()) { + Variant targetVar = target.createVariant((String) null, null); + _copyScope((IScoped) variant, (IScoped) targetVar, mergeMap); + if (variant.getValue() != null) { + targetVar.setValue(variant.getValue()); + } + else if (variant.getResource() != null) { + targetVar.setResource(variant.getResource()); + } + existing = sigs.get(SignatureGenerator.generateSignature(targetVar)); + if (existing != null) { + MergeUtils.removeConstruct((IConstruct) targetVar); + targetVar = existing; + } + _copyReifier((IReifiable) variant, (IReifiable) targetVar, mergeMap); + _copyItemIdentifiers((IConstruct) variant, (IConstruct) targetVar); + } + } + + /** + * Copies the reifier of <code>source</code> (if any) to the <code>target</code>. + * + * @param source The reifiable Topic Maps construct to take the reifier from. + * @param target The target Topic Maps construct. + * @param mergeMap The map which holds the merge mappings. + */ + private static void _copyReifier(IReifiable source, IReifiable target, + Map<Topic, Topic> mergeMap) { + Topic sourceReifier = source.getReifier(); + if (sourceReifier == null) { + return; + } + Topic reifier = mergeMap.containsKey(sourceReifier) ? mergeMap.get(sourceReifier) + : _copyTopic(sourceReifier, target.getTopicMap(), mergeMap); + target.setReifier(reifier); + } + + /** + * Copies the type of the <code>source</code> (if any) to the <code>target</code>. + * + * @param source The Topic Maps construct to take the type from. + * @param target The Topic Maps construct which receives the type. + * @param mergeMap The map which holds the merge mappings. + */ + private static void _copyType(ITyped source, ITyped target, + Map<Topic, Topic> mergeMap) { + Topic sourceType = source.getType(); + if (sourceType == null) { + return; + } + Topic type = mergeMap.containsKey(sourceType) ? mergeMap.get(sourceType) + : _copyTopic(sourceType, target.getTopicMap(), mergeMap); + target.setType(type); + } + + /** + * Copies all themes from the <code>source</code> scoped Topic Maps construct + * to the <code>target</code>. + * + * @param source The source to take the scope from. + * @param target The target which receives the scope. + * @param mergeMap The map which holds the merge mappings. + */ + private static void _copyScope(IScoped source, IScoped target, + Map<Topic, Topic> mergeMap) { + Topic theme = null; + for (Topic sourceTheme: source.getScope()) { + theme = mergeMap.containsKey(sourceTheme) ? mergeMap.get(sourceTheme) + : _copyTopic(sourceTheme, target.getTopicMap(), mergeMap); + target.addTheme(theme); + } + } + + /** + * Copies the item identifiers from <code>source</code> to <code>target</code>. + * + * @param source The source Topic Maps construct. + * @param target The target Topic Maps construct. + */ private static void _copyItemIdentifiers(IConstruct source, IConstruct target) { for(Locator iid: source.getItemIdentifiers()) { target.addSourceLocator(iid); } } + /** + * Copies the associations from the <code>source</code> topic map to the + * <code>target</code> topic map. + * + * @param source The topic map to take the associations from. + * @param target The topic map which receives the associations. + * @param mergeMap The map which holds the merge mappings. + */ + @SuppressWarnings("unchecked") + private static void _copyAssociations(TopicMapImpl source, + TopicMapImpl target, Map<Topic, Topic> mergeMap) { + Set<Association> assocs = target.getAssociations(); + Map<String, Association> sigs = target.getCollectionFactory().createMap(assocs.size()); + for (Association assoc: assocs) { + sigs.put(SignatureGenerator.generateSignature(assoc), assoc); + } + Association existing = null; + for (Association assoc: source.getAssociations()) { + Association targetAssoc = target.createAssociation(); + _copyType((ITyped) assoc, (ITyped) targetAssoc, mergeMap); + _copyScope((IScoped) assoc, (IScoped) targetAssoc, mergeMap); + for (Iterator<AssociationRole> iter = assoc.getAssociationRoles().iterator(); iter.hasNext();) { + AssociationRole role = iter.next(); + AssociationRole targetRole = targetAssoc.createAssociationRole(role.getPlayer(), role.getType()); + _copyItemIdentifiers((IConstruct)role, (IConstruct)targetRole); + _copyReifier((IReifiable) role, (IReifiable) targetRole, mergeMap); + } + existing = sigs.get(SignatureGenerator.generateSignature(targetAssoc)); + if (existing != null) { + MergeUtils.moveRoleCharacteristics(targetAssoc, existing); + MergeUtils.removeConstruct((IConstruct) targetAssoc); + targetAssoc = existing; + } + _copyReifier((IReifiable) assoc, (IReifiable) targetAssoc, mergeMap); + _copyItemIdentifiers((IConstruct) assoc, (IConstruct) targetAssoc); + } + } + + /** + * Adds a mapping from <code>source</code> to <code>target</code> into the + * <code>mergeMap</code>. + * + * If <code>source</code> has already a mapping to another target topic, + * <code>target</code> is merged with the existing target topic. + * + * @param source The source topic. + * @param target The target topic. + * @param mergeMap The map which holds the merge mappings. + */ private static void _addMerge(Topic source, Topic target, Map<Topic, Topic> mergeMap) { Topic prevTarget = mergeMap.get(source); if (prevTarget != null) { Modified: tinytim/trunk/src/main/java/org/tinytim/IMovable.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IMovable.java 2008-04-23 17:55:30 UTC (rev 34) +++ tinytim/trunk/src/main/java/org/tinytim/IMovable.java 2008-04-24 12:04:37 UTC (rev 35) @@ -27,7 +27,7 @@ * This interface is not meant to be used outside of the tinyTiM package. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ interface IMovable<T /* extends IConstruct */> { Modified: tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-04-23 17:55:30 UTC (rev 34) +++ tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-04-24 12:04:37 UTC (rev 35) @@ -95,10 +95,10 @@ if (source.getTopicMap() != target.getTopicMap()) { throw new IllegalArgumentException("The topics must belong to the same topic map"); } - IReifiable sourceReifiable = source._reified; - if (sourceReifiable != null && target._reified != null) { + IReifiable sourceReifiable = source.getReifiedConstruct(); + if (sourceReifiable != null && target.getReifiedConstruct() != null) { // This should be enforced by the model - assert sourceReifiable != target._reified; + assert sourceReifiable != target.getReifiedConstruct(); throw new ModelConstraintException(target, "The topics cannot be merged. They reify different Topic Maps constructs"); } _moveItemIdentifiers((IConstruct)source, (IConstruct)target); @@ -160,7 +160,7 @@ existing = sigs.get(SignatureGenerator.generateSignature(parent)); if (existing != null) { handleExistingConstruct((IReifiable)parent, existing); - _moveRoleCharacteristics(parent, (Association)existing); + moveRoleCharacteristics(parent, (Association)existing); removeConstruct((IConstruct)parent); } } @@ -191,7 +191,7 @@ * @param target The association which takes the role characteristics. */ @SuppressWarnings("unchecked") - private static void _moveRoleCharacteristics(Association source, Association target) { + static void moveRoleCharacteristics(Association source, Association target) { Map<String, AssociationRole> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().<String, AssociationRole>createMap(); for (AssociationRole role: ((AssociationImpl)target).getAssociationRoles()) { sigs.put(SignatureGenerator.generateSignature(role), role); @@ -304,6 +304,14 @@ } } + /** + * Replaces the <code>oldTheme</code> with the <code>newTheme</code> in each + * scoped Topic Maps construct. + * + * @param scopedCollection A collection of scoped Topic Maps constructs. + * @param oldTheme The old theme. + * @param newTheme The theme that is used as replacement for <code>oldTheme</code>. + */ private static void _replaceTopicAsTheme(Collection<? extends IScoped> scopedCollection, Topic oldTheme, Topic newTheme) { for (IScoped scoped: scopedCollection) { Modified: tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java 2008-04-23 17:55:30 UTC (rev 34) +++ tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java 2008-04-24 12:04:37 UTC (rev 35) @@ -242,6 +242,17 @@ name._parent = null; } + /** + * Returns the Topic Maps construct that is reified by + * this topic. + * + * @return The reified construct or <code>null</code> if this + * topic reifies nothing. + */ + public IReifiable getReifiedConstruct() { + return _reified; + } + /* (non-Javadoc) * @see org.tmapi.core.Topic#getReified() */ Modified: tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-04-23 17:55:30 UTC (rev 34) +++ tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-04-24 12:04:37 UTC (rev 35) @@ -49,7 +49,7 @@ * {@link org.tmapi.core.TopicMap} implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class TopicMapImpl extends Construct implements TopicMap, IReifiable, IEventHandler, IEventPublisher { Modified: tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java 2008-04-23 17:55:30 UTC (rev 34) +++ tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java 2008-04-24 12:04:37 UTC (rev 35) @@ -197,7 +197,6 @@ private final class AddScopedHandler extends _EvtHandler { @SuppressWarnings("unchecked") - @Override public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { ScopedObject scoped = (ScopedObject) newValue; @@ -228,7 +227,6 @@ private final class RemoveScopedHandler extends _EvtHandler { @SuppressWarnings("unchecked") - @Override public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { ScopedObject scoped = (ScopedObject) oldValue; Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java 2008-04-23 17:55:30 UTC (rev 34) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java 2008-04-24 12:04:37 UTC (rev 35) @@ -64,7 +64,6 @@ /* (non-Javadoc) * @see org.tmapi.index.core.OccurrencesIndex#getOccurrenceTypes() */ - @Override public Collection<Topic> getOccurrenceTypes() { return _getTypeInstanceIndex().getOccurrenceTypes(); } @@ -72,7 +71,6 @@ /* (non-Javadoc) * @see org.tmapi.index.core.OccurrencesIndex#getOccurrencesByType(org.tmapi.core.Topic) */ - @Override public Collection<OccurrenceImpl> getOccurrencesByType(Topic type) { return _getTypeInstanceIndex().getOccurrences(type); } @@ -80,7 +78,6 @@ /* (non-Javadoc) * @see org.tmapi.index.core.OccurrencesIndex#getOccurrencesByResource(org.tmapi.core.Locator) */ - @Override public Collection<Occurrence> getOccurrencesByResource(Locator value) { List<Occurrence> occs = _loc2Occs.get(value); return occs == null ? Collections.<Occurrence>emptySet() @@ -90,7 +87,6 @@ /* (non-Javadoc) * @see org.tmapi.index.core.OccurrencesIndex#getOccurrencesByValue(java.lang.String) */ - @Override public Collection<Occurrence> getOccurrencesByValue(String value) { List<Occurrence> occs = _value2Occs.get(value); return occs == null ? Collections.<Occurrence>emptySet() @@ -100,7 +96,6 @@ /* (non-Javadoc) * @see org.tmapi.index.Index#getFlags() */ - @Override public IndexFlags getFlags() throws TMAPIIndexException { return IndexFlagsImpl.NOT_AUTOUPDATED; } @@ -109,7 +104,6 @@ * @see org.tmapi.index.Index#reindex() */ @SuppressWarnings("unchecked") - @Override public void reindex() throws TMAPIIndexException { _value2Occs.clear(); _loc2Occs.clear(); Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java 2008-04-23 17:55:30 UTC (rev 34) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java 2008-04-24 12:04:37 UTC (rev 35) @@ -61,7 +61,6 @@ /* (non-Javadoc) * @see org.tmapi.index.core.TopicNamesIndex#getTopicNameTypes() */ - @Override public Collection<Topic> getTopicNameTypes() { return _getTypeInstanceIndex().getNameTypes(); } @@ -69,7 +68,6 @@ /* (non-Javadoc) * @see org.tmapi.index.core.TopicNamesIndex#getTopicNamesByType(org.tmapi.core.Topic) */ - @Override public Collection<TopicNameImpl> getTopicNamesByType(Topic type) { return _getTypeInstanceIndex().getNames(type); } @@ -77,7 +75,6 @@ /* (non-Javadoc) * @see org.tmapi.index.core.TopicNamesIndex#getTopicNamesByValue(java.lang.String) */ - @Override public Collection<TopicName> getTopicNamesByValue(String value) { List<TopicName> names = _value2Names.get(value); return names == null ? Collections.<TopicName>emptySet() @@ -87,7 +84,6 @@ /* (non-Javadoc) * @see org.tmapi.index.Index#getFlags() */ - @Override public IndexFlags getFlags() throws TMAPIIndexException { return IndexFlagsImpl.NOT_AUTOUPDATED; } @@ -96,7 +92,6 @@ * @see org.tmapi.index.Index#reindex() */ @SuppressWarnings("unchecked") - @Override public void reindex() throws TMAPIIndexException { _value2Names.clear(); for (Topic topic: _weakTopicMap.get().getTopics()) { Modified: tinytim/trunk/src/main/resources/META-INF/services/org.tmapi.core.TopicMapSystemFactory =================================================================== --- tinytim/trunk/src/main/resources/META-INF/services/org.tmapi.core.TopicMapSystemFactory 2008-04-23 17:55:30 UTC (rev 34) +++ tinytim/trunk/src/main/resources/META-INF/services/org.tmapi.core.TopicMapSystemFactory 2008-04-24 12:04:37 UTC (rev 35) @@ -1 +1 @@ -org.tinytim.TopicMapSystemFactoryImpl \ No newline at end of file +org.tinytim.TopicMapSystemFactoryImpl Modified: tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java 2008-04-23 17:55:30 UTC (rev 34) +++ tinytim/trunk/src/test/java/org/tinytim/TestItemIdentifierConstraint.java 2008-04-24 12:04:37 UTC (rev 35) @@ -36,7 +36,7 @@ * Tests if the TMDM item identifier constraint is respected. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestItemIdentifierConstraint extends TinyTimTestCase { Modified: tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java 2008-04-23 17:55:30 UTC (rev 34) +++ tinytim/trunk/src/test/java/org/tinytim/TestReifiable.java 2008-04-24 12:04:37 UTC (rev 35) @@ -130,19 +130,19 @@ assertEquals(0, reifier.getReified().size()); reifiable.setReifier(reifier); assertEquals(reifier, reifiable.getReifier()); - assertEquals(reifiable, reifier._reified); + assertEquals(reifiable, reifier.getReifiedConstruct()); assertEquals(1, reifier.getReified().size()); assertTrue(reifier.getReified().contains(reifiable)); reifiable.setReifier(null); assertNull(reifiable.getReifier()); - assertNull(reifier._reified); + assertNull(reifier.getReifiedConstruct()); assertEquals(0, reifier.getReified().size()); TopicImpl reifier2 = (TopicImpl) _tm.createTopic(); IReifiable assoc = (IReifiable) _tm.createAssociation(); assoc.setReifier(reifier2); assertEquals(reifier2, assoc.getReifier()); - assertEquals(assoc, reifier2._reified); + assertEquals(assoc, reifier2.getReifiedConstruct()); try { reifiable.setReifier(reifier2); fail("Expected an exception. The reifier reifies another Topic Maps construct"); @@ -152,12 +152,12 @@ } assoc.setReifier(null); assertNull(assoc.getReifier()); - assertNull(reifier2._reified); + assertNull(reifier2.getReifiedConstruct()); reifiable.setReifier(reifier); assertEquals(reifier, reifiable.getReifier()); - assertEquals(reifiable, reifier._reified); + assertEquals(reifiable, reifier.getReifiedConstruct()); reifiable.setReifier(reifier2); assertEquals(reifier2, reifiable.getReifier()); - assertEquals(reifiable, reifier2._reified); + assertEquals(reifiable, reifier2.getReifiedConstruct()); } } Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-04-23 17:55:30 UTC (rev 34) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMerge.java 2008-04-24 12:04:37 UTC (rev 35) @@ -154,6 +154,86 @@ } /** + * Tests if merging detects duplicates and that the reifier is kept. + */ + public void testDuplicateDetectionReifier() { + Topic topic1 = _tm.createTopic(); + Topic topic2 = _tm.createTopic(); + Topic reifier = _tm.createTopic(); + TopicName name1 = topic1.createTopicName("tinyTiM", null, null); + TopicName name2 = topic2.createTopicName("tinyTiM", null, null); + assertEquals(3, _tm.getTopics().size()); + ((IReifiable) name1).setReifier(reifier); + assertEquals(reifier, name1.getReifier()); + assertEquals(1, topic1.getTopicNames().size()); + assertTrue(topic1.getTopicNames().contains(name1)); + assertEquals(1, topic2.getTopicNames().size()); + assertTrue(topic2.getTopicNames().contains(name2)); + topic1.mergeIn(topic2); + assertEquals(2, _tm.getTopics().size()); + assertEquals(1, topic1.getTopicNames().size()); + TopicName name = (TopicName) topic1.getTopicNames().iterator().next(); + assertEquals(reifier, name.getReifier()); + } + + /** + * Tests if merging detects duplicates and merges the reifiers of the + * duplicates. + */ + public void testDuplicateDetectionReifierMerge() { + Topic topic1 = _tm.createTopic(); + Topic topic2 = _tm.createTopic(); + Topic reifier1 = _tm.createTopic(); + Topic reifier2 = _tm.createTopic(); + TopicName name1 = topic1.createTopicName("tinyTiM", null, null); + TopicName name2 = topic2.createTopicName("tinyTiM", null, null); + assertEquals(4, _tm.getTopics().size()); + ((IReifiable) name1).setReifier(reifier1); + ((IReifiable) name2).setReifier(reifier2); + assertEquals(reifier1, name1.getReifier()); + assertEquals(reifier2, name2.getReifier()); + assertEquals(1, topic1.getTopicNames().size()); + assertTrue(topic1.getTopicNames().contains(name1)); + assertEquals(1, topic2.getTopicNames().size()); + assertTrue(topic2.getTopicNames().contains(name2)); + topic1.mergeIn(topic2); + assertEquals(2, _tm.getTopics().size()); + assertEquals(1, topic1.getTopicNames().size()); + TopicName name = (TopicName) topic1.getTopicNames().iterator().next(); + Topic reifier = null; + for (Topic topic: _tm.getTopics()) { + if (!topic.equals(topic1)) { + reifier = topic; + } + } + assertEquals(reifier, name.getReifier()); + } + + /** + * Tests if merging detects duplicate associations. + */ + public void testDuplicateSuppressionAssociation() { + Topic topic1 = _tm.createTopic(); + Topic topic2 = _tm.createTopic(); + Topic roleType = _tm.createTopic(); + Association assoc1 = _tm.createAssociation(); + Association assoc2 = _tm.createAssociation(); + AssociationRole role1 = assoc1.createAssociationRole(topic1, roleType); + AssociationRole role2 = assoc2.createAssociationRole(topic2, roleType); + assertEquals(3, _tm.getTopics().size()); + assertEquals(2, _tm.getAssociations().size()); + assertTrue(topic1.getRolesPlayed().contains(role1)); + assertTrue(topic2.getRolesPlayed().contains(role2)); + assertEquals(1, topic1.getRolesPlayed().size()); + assertEquals(1, topic2.getRolesPlayed().size()); + topic1.mergeIn(topic2); + assertEquals(2, _tm.getTopics().size()); + assertEquals(1, _tm.getAssociations().size()); + AssociationRole role = (AssociationRole) topic1.getRolesPlayed().iterator().next(); + assertEquals(roleType, role.getType()); + } + + /** * Tests if merging detects duplicate names. */ public void testDuplicateSuppressionName() { @@ -196,6 +276,34 @@ } /** + * Tests if merging detects duplicate names and sets the item + * identifier to the union of both names. + */ + public void testDuplicateSuppressionNameMoveItemIdentifiers() { + Topic topic1 = _tm.createTopic(); + Topic topic2 = _tm.createTopic(); + Locator iid1 = _tm.createLocator("http://example.org/iid-1"); + Locator iid2 = _tm.createLocator("http://example.org/iid-2"); + TopicName name1 = topic1.createTopicName("tinyTiM", null, null); + TopicName name2 = topic2.createTopicName("tinyTiM", null, null); + name1.addSourceLocator(iid1); + name2.addSourceLocator(iid2); + assertTrue(name1.getSourceLocators().contains(iid1)); + assertTrue(name2.getSourceLocators().contains(iid2)); + assertEquals(1, topic1.getTopicNames().size()); + assertTrue(topic1.getTopicNames().contains(name1)); + assertEquals(1, topic2.getTopicNames().size()); + assertTrue(topic2.getTopicNames().contains(name2)); + topic1.mergeIn(topic2); + assertEquals(1, topic1.getTopicNames().size()); + TopicName name = (TopicName) topic1.getTopicNames().iterator().next(); + assertEquals(2, name.getSourceLocators().size()); + assertTrue(name.getSourceLocators().contains(iid1)); + assertTrue(name.getSourceLocators().contains(iid2)); + assertEquals("tinyTiM", name.getValue()); + } + + /** * Tests if merging detects duplicate occurrences. */ public void testDuplicateSuppressionOccurrence() { @@ -214,10 +322,10 @@ } /** - * Tests if merging detects duplicate occurrences and moves the - * item identifiers. + * Tests if merging detects duplicate occurrences and sets the item + * identifier to the union of both occurrences. */ - public void testDuplicateSuppressionOccurrenceItemIdentifiers() { + public void testDuplicateSuppressionOccurrenceMoveItemIdentifiers() { Topic topic1 = _tm.createTopic(); Topic topic2 = _tm.createTopic(); Locator iid1 = _tm.createLocator("http://example.org/iid-1"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-04-25 20:11:44
|
Revision: 37 http://tinytim.svn.sourceforge.net/tinytim/?rev=37&view=rev Author: lheuer Date: 2008-04-25 13:09:10 -0700 (Fri, 25 Apr 2008) Log Message: ----------- - Small modifications - Event system simplified - Bugs in ScopedIndex fixed Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/Construct.java tinytim/trunk/src/main/java/org/tinytim/IdentityManager.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/Scoped.java tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java tinytim/trunk/src/test/java/org/tinytim/TestTMAPICore.java tinytim/trunk/src/test/java/org/tinytim/TestTMAPIIndex.java tinytim/trunk/src/test/java/org/tinytim/TestTopicMapMerge.java Modified: tinytim/trunk/src/main/java/org/tinytim/Construct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Construct.java 2008-04-24 13:43:47 UTC (rev 36) +++ tinytim/trunk/src/main/java/org/tinytim/Construct.java 2008-04-25 20:09:10 UTC (rev 37) @@ -125,18 +125,18 @@ * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(Object obj) { + public final boolean equals(Object obj) { if (this == obj) { return true; } - return (obj instanceof Construct) && _id.equals(((Construct) obj)._id); + return (obj instanceof Construct) && _id.equals(((Construct) obj).getObjectId()); } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ @Override - public int hashCode() { + public final int hashCode() { return _id.hashCode(); } Modified: tinytim/trunk/src/main/java/org/tinytim/IdentityManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IdentityManager.java 2008-04-24 13:43:47 UTC (rev 36) +++ tinytim/trunk/src/main/java/org/tinytim/IdentityManager.java 2008-04-25 20:09:10 UTC (rev 37) @@ -53,6 +53,11 @@ _register(tm); } + /** + * Subscribes itself to the specified event publisher. + * + * @param publisher The publisher to subscribe to. + */ private void _subscribe(IEventPublisher publisher) { IEventHandler handler = new TopicMapsConstructAddHandler(); publisher.subscribe(Event.ADD_TOPIC, handler); @@ -84,32 +89,66 @@ publisher.subscribe(Event.SET_REIFIER, handler); } + /** + * Registeres a Topic Maps construct and, if necessary, gives it an id. + * + * @param construct The construct to register. + */ private void _register(IConstruct construct) { Construct c = (Construct) construct; if (c._id == null) { c._id = "" + _nextId++; } - if (!_id2Construct.containsKey(c)) { + if (!_id2Construct.containsKey(c._id)) { _id2Construct.put(c._id, c); } } + /** + * Unregisteres the specified <code>construct</code>. + * + * @param construct The Topic Maps construct to unregister. + */ private void _unregister(IConstruct construct) { _id2Construct.remove(((Construct) construct)._id); } + /** + * Returns a Topic Maps construct by its identifier. + * + * @param id The identifier. + * @return A Topic Maps construct with the <code>id</code> or <code>null</code>. + */ public IConstruct getConstructById(String id) { return _id2Construct.get(id); } + /** + * Returns a topic by its subject identifier. + * + * @param sid The subject identifier. + * @return A topic with the <code>sid</code> or <code>null</code>. + */ public Topic getTopicBySubjectIdentifier(Locator sid) { return _sid2Topic.get(sid); } + /** + * Returns a topic by its subject locator. + * + * @param slo The subject locator. + * @return A topic with the <code>slo</code> or <code>null</code>. + */ public Topic getTopicBySubjectLocator(Locator slo) { return _slo2Topic.get(slo); } + /** + * Returns a Topic Maps construct by its item identifier. + * + * @param iid The item identifier. + * @return A Topic Maps construct with the <code>iid</code> or <code>null</code>. + */ public IConstruct getConstructByItemIdentifier(Locator iid) { return _iid2Construct.get(iid); } @@ -199,8 +238,7 @@ private class RemoveSubjectIdentifierHandler implements IEventHandler { public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { - Locator slo = (Locator) oldValue; - _sid2Topic.remove(slo); + _sid2Topic.remove(oldValue); } } @@ -227,8 +265,7 @@ private class RemoveSubjectLocatorHandler implements IEventHandler { public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { - Locator slo = (Locator) oldValue; - _slo2Topic.remove(slo); + _slo2Topic.remove(oldValue); } } Modified: tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-04-24 13:43:47 UTC (rev 36) +++ tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-04-25 20:09:10 UTC (rev 37) @@ -41,7 +41,7 @@ import org.tmapi.core.Variant; /** - * This class does provides functions to merge topic maps and topics. + * This class provides functions to merge topic maps and topics. * * This class relies on the implementation of tinyTiM, if the implementation * changes, check the <code>==</code> comparisons. Modified: tinytim/trunk/src/main/java/org/tinytim/Property.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Property.java 2008-04-24 13:43:47 UTC (rev 36) +++ tinytim/trunk/src/main/java/org/tinytim/Property.java 2008-04-25 20:09:10 UTC (rev 37) @@ -43,16 +43,16 @@ public static final String COLLECTION_FACTORY = "org.tinytim.CollectionFactory"; /** - * Property which indicates if the "old" XTM 1.0 reification mechansm should - * be used. + * Property which indicates if the "old" XTM 1.0 reification mechanism + * should be used. * * For backwards compatibilty and to support TMAPI 1.0 this property is * set to "true" by default. * * Note, that this property is likely to be removed in a future version and * that only the TMDM way of reification will be supported. - * Maybe you'll be able to use {@link org.tinytim.ReificationUtils} to support - * the XTM 1.0 reification mechanism. + * Maybe you'll be able to use {@link org.tinytim.ReificationUtils} to + * support the XTM 1.0 reification mechanism. */ public static final String XTM10_REIFICATION = "org.tinytim.XTM10Reification"; Modified: tinytim/trunk/src/main/java/org/tinytim/Scoped.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Scoped.java 2008-04-24 13:43:47 UTC (rev 36) +++ tinytim/trunk/src/main/java/org/tinytim/Scoped.java 2008-04-25 20:09:10 UTC (rev 37) @@ -27,8 +27,8 @@ import org.tmapi.core.Topic; /** - * Class that provides a "scope" property and sends events if that - * scope property changes. + * Class that provides a "scope" property and sends events if that property + * changes. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ Modified: tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-04-24 13:43:47 UTC (rev 36) +++ tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-04-25 20:09:10 UTC (rev 37) @@ -422,16 +422,16 @@ switch (evt) { case ADD_TOPIC: _topicAdd((TopicImpl)newValue); break; case ADD_ASSOCIATION: _associationAdd((AssociationImpl)newValue); break; - case ADD_ROLE: _roleAdd((AssociationRoleImpl)newValue); break; - case ADD_OCCURRENCE: _occurrenceAdd((OccurrenceImpl)newValue); break; case ADD_NAME: _nameAdd((TopicNameImpl)newValue); break; - case ADD_VARIANT: _variantAdd((VariantImpl)newValue); break; + case ADD_ROLE: + case ADD_OCCURRENCE: + case ADD_VARIANT: _constructAdd((IConstruct)newValue); break; case REMOVE_TOPIC: _topicRemove((TopicImpl) oldValue); break; case REMOVE_ASSOCIATION: _associationRemove((AssociationImpl) oldValue); break; - case REMOVE_ROLE: _roleRemove((AssociationRoleImpl) oldValue); break; - case REMOVE_OCCURRENCE: _occurrenceRemove((OccurrenceImpl) oldValue); break; - case REMOVE_NAME: _nameRemove((TopicNameImpl) oldValue); break; - case REMOVE_VARIANT: _variantRemove((VariantImpl) oldValue); break; + case REMOVE_NAME: _nameRemove((TopicNameImpl)oldValue); break; + case REMOVE_ROLE: + case REMOVE_OCCURRENCE: + case REMOVE_VARIANT: _constructRemove((IConstruct) oldValue); break; } } @@ -456,62 +456,18 @@ private void _associationAdd(AssociationImpl sender) { _constructAdd(sender); - _typedAdd(sender); - _scopedAdd(sender); for (AssociationRole role: sender.getAssociationRoles()) { _handler.handleEvent(Event.ADD_ROLE, sender, null, role); } } - private void _roleAdd(AssociationRoleImpl sender) { - _constructAdd(sender); - _typedAdd(sender); - _handler.handleEvent(Event.SET_PLAYER, sender, null, sender.getPlayer()); - } - - private void _occurrenceAdd(OccurrenceImpl sender) { - _constructAdd(sender); - _typedAdd(sender); - _scopedAdd(sender); - if (sender.getValue() != null) { - _handler.handleEvent(Event.SET_VALUE, sender, null, sender.getValue()); - } - else if (sender.getResource() != null) { - _handler.handleEvent(Event.SET_LOCATOR, sender, null, sender.getResource()); - } - } - private void _nameAdd(TopicNameImpl sender) { _constructAdd(sender); - _typedAdd(sender); - _scopedAdd(sender); - _handler.handleEvent(Event.SET_VALUE, sender, null, sender.getValue()); for (Variant variant: sender.getVariants()) { _handler.handleEvent(Event.ADD_VARIANT, sender, null, variant); } } - private void _variantAdd(VariantImpl sender) { - _constructAdd(sender); - _scopedAdd(sender); - if (sender.getValue() != null) { - _handler.handleEvent(Event.SET_VALUE, sender, null, sender.getValue()); - } - else if (sender.getResource() != null) { - _handler.handleEvent(Event.SET_LOCATOR, sender, null, sender.getResource()); - } - } - - private void _typedAdd(ITyped typed) { - _handler.handleEvent(Event.SET_TYPE, typed, null, typed.getType()); - } - - private void _scopedAdd(IScoped scoped) { - for (Topic theme: scoped.getScope()) { - _handler.handleEvent(Event.ADD_THEME, scoped, null, theme); - } - } - private void _constructAdd(IConstruct construct) { for (Locator iid: construct.getItemIdentifiers()) { _handler.handleEvent(Event.ADD_IID, construct, null, iid); @@ -550,14 +506,6 @@ } } - private void _roleRemove(AssociationRoleImpl sender) { - _constructRemove(sender); - } - - private void _occurrenceRemove(OccurrenceImpl sender) { - _constructRemove(sender); - } - private void _nameRemove(TopicNameImpl sender) { _constructRemove(sender); for (Variant variant: sender.getVariants()) { @@ -565,8 +513,5 @@ } } - private void _variantRemove(VariantImpl sender) { - _constructRemove(sender); - } } } Modified: tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-04-24 13:43:47 UTC (rev 36) +++ tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-04-25 20:09:10 UTC (rev 37) @@ -70,7 +70,7 @@ * otherwise. */ public static boolean isRemovable(Topic topic, boolean includeReified) { - if (includeReified && ((TopicImpl) topic)._reified != null) { + if (includeReified && ((TopicImpl) topic).getReifiedConstruct() != null) { return false; } if (!topic.getRolesPlayed().isEmpty()) { Modified: tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java 2008-04-24 13:43:47 UTC (rev 36) +++ tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java 2008-04-25 20:09:10 UTC (rev 37) @@ -69,6 +69,11 @@ publisher.subscribe(Event.REMOVE_TOPIC, handler); handler = new TypeHandler(); publisher.subscribe(Event.SET_TYPE, handler); + handler = new AddTypedHandler(); + publisher.subscribe(Event.ADD_ASSOCIATION, handler); + publisher.subscribe(Event.ADD_ROLE, handler); + publisher.subscribe(Event.ADD_OCCURRENCE, handler); + publisher.subscribe(Event.ADD_NAME, handler); handler = new RemoveTypedHandler(); publisher.subscribe(Event.REMOVE_ASSOCIATION, handler); publisher.subscribe(Event.REMOVE_ROLE, handler); @@ -192,14 +197,26 @@ } } - private boolean _unindex(List<ITyped> objects, Object obj) { - if (objects == null) { - return false; + private void _index(Map<Topic, List<ITyped>> type2Typed, Topic type, ITyped typed) { + List<ITyped> list = type2Typed.get(type); + if (list == null) { + list = new ArrayList<ITyped>(); + type2Typed.put(type, list); } - objects.remove(obj); - return objects.isEmpty(); + list.add(typed); } + private void _unindex(Map<Topic, List<ITyped>> type2Typed, Topic type, ITyped typed) { + List<ITyped> list = type2Typed.get(type); + if (list == null) { + return; + } + list.remove(typed); + if (list.isEmpty()) { + type2Typed.remove(type); + } + } + /* (non-Javadoc) * @see org.tinytim.index.IIndex#close() */ @@ -308,64 +325,57 @@ } } - private final class TypeHandler implements IEventHandler { + private abstract class _EvtHandler implements IEventHandler { @SuppressWarnings("unchecked") - public void handleEvent(Event evt, IConstruct sender, Object oldValue, - Object newValue) { + Map<Topic, List<ITyped>> getMap(ITyped typed) { Map<Topic, ?> type2Typed = null; - if (sender instanceof AssociationImpl) { + if (typed instanceof AssociationImpl) { type2Typed = _type2Assocs; } - else if (sender instanceof AssociationRoleImpl) { + else if (typed instanceof AssociationRoleImpl) { type2Typed = _type2Roles; } - else if (sender instanceof OccurrenceImpl) { + else if (typed instanceof OccurrenceImpl) { type2Typed = _type2Occs; } - else if (sender instanceof TopicNameImpl) { + else if (typed instanceof TopicNameImpl) { type2Typed = _type2Names; } - if (_unindex((List<ITyped>)type2Typed.get((Topic)oldValue), sender)) { - type2Typed.remove(oldValue); - } - _index((Map<Topic, List<ITyped>>) type2Typed, (Topic) newValue, (ITyped) sender); + return (Map<Topic, List<ITyped>>) type2Typed; } + } - private void _index(Map<Topic, List<ITyped>> type2Typed, - Topic newValue, ITyped sender) { - List<ITyped> typedConstructs = type2Typed.get(newValue); - if (typedConstructs == null) { - typedConstructs = new ArrayList<ITyped>(); - type2Typed.put(newValue, typedConstructs); - } - typedConstructs.add(sender); + private final class TypeHandler extends _EvtHandler { + @SuppressWarnings("unchecked") + public void handleEvent(Event evt, IConstruct sender, Object oldValue, + Object newValue) { + ITyped typed = (ITyped) sender; + Map<Topic, List<ITyped>> map = getMap(typed); + _unindex(map, (Topic) oldValue, typed); + _index(map, (Topic) newValue, typed); } } - private final class RemoveTypedHandler implements IEventHandler { + private final class AddTypedHandler extends _EvtHandler { @SuppressWarnings("unchecked") public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { - Map<Topic, ?> type2Typed = null; - if (oldValue instanceof AssociationImpl) { - type2Typed = _type2Assocs; - } - else if (oldValue instanceof AssociationRoleImpl) { - type2Typed = _type2Roles; - } - else if (oldValue instanceof OccurrenceImpl) { - type2Typed = _type2Occs; - } - else if (oldValue instanceof TopicNameImpl) { - type2Typed = _type2Names; - } - Topic type = ((ITyped) oldValue).getType(); - if (_unindex((List<ITyped>)type2Typed.get(type), oldValue)) { - type2Typed.remove(type); - } + ITyped typed = (ITyped) newValue; + Map<Topic, List<ITyped>> map = getMap(typed); + _index(map, typed.getType(), typed); } } + private final class RemoveTypedHandler extends _EvtHandler { + @SuppressWarnings("unchecked") + public void handleEvent(Event evt, IConstruct sender, Object oldValue, + Object newValue) { + ITyped typed = (ITyped) oldValue; + Map<Topic, List<ITyped>> map = getMap(typed); + _unindex(map, typed.getType(), typed); + } + } + void clear() { _type2Topics.clear(); _type2Topics = null; Modified: tinytim/trunk/src/test/java/org/tinytim/TestTMAPICore.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTMAPICore.java 2008-04-24 13:43:47 UTC (rev 36) +++ tinytim/trunk/src/test/java/org/tinytim/TestTMAPICore.java 2008-04-25 20:09:10 UTC (rev 37) @@ -23,7 +23,6 @@ import org.tmapi.core.test.AllTMAPITests; import junit.framework.Test; -import junit.framework.TestSuite; /** * Runs the TMAPI core test suite against tinyTiM. @@ -31,15 +30,13 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -public class TestTMAPICore extends TMAPITestCase { +public class TestTMAPICore extends AbstractTMAPITestSuite { public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public static Test suite() { - TestSuite suite = new TestSuite(); - suite.addTest(AllTMAPITests.suite()); - return suite; + return AllTMAPITests.suite(); } } Modified: tinytim/trunk/src/test/java/org/tinytim/TestTMAPIIndex.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTMAPIIndex.java 2008-04-24 13:43:47 UTC (rev 36) +++ tinytim/trunk/src/test/java/org/tinytim/TestTMAPIIndex.java 2008-04-25 20:09:10 UTC (rev 37) @@ -23,7 +23,6 @@ import org.tmapi.index.core.test.AllTMAPIIndexTests; import junit.framework.Test; -import junit.framework.TestSuite; /** * Runs the TMAPI index test suite against tinyTiM. @@ -31,15 +30,13 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -public class TestTMAPIIndex extends TMAPITestCase { +public class TestTMAPIIndex extends AbstractTMAPITestSuite { public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public static Test suite() { - TestSuite suite = new TestSuite(); - suite.addTest(AllTMAPIIndexTests.suite()); - return suite; + return AllTMAPIIndexTests.suite(); } } Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicMapMerge.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicMapMerge.java 2008-04-24 13:43:47 UTC (rev 36) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicMapMerge.java 2008-04-25 20:09:10 UTC (rev 37) @@ -28,7 +28,7 @@ * Tests merging of topic maps. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class TestTopicMapMerge extends TinyTimTestCase { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-04-26 09:51:35
|
Revision: 42 http://tinytim.svn.sourceforge.net/tinytim/?rev=42&view=rev Author: lheuer Date: 2008-04-26 02:51:39 -0700 (Sat, 26 Apr 2008) Log Message: ----------- - Moved the IDatatypeAwareConstruct constants to the abstract class - DatatypeAwareConstruct sends now the correct SET_LOCATOR event if the resource is set - Minor Java Doc tweaks - TopicMapImpl cleans up the cached HelperObjects Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/SignatureGenerator.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/Typed.java tinytim/trunk/src/test/java/org/tinytim/AllTests.java tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java Modified: tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java 2008-04-25 20:24:19 UTC (rev 41) +++ tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java 2008-04-26 09:51:39 UTC (rev 42) @@ -34,6 +34,10 @@ abstract class DatatypeAwareConstruct extends Scoped implements IDatatypeAwareConstruct { + private static final String _XSD_BASE = "http://www.w3.org/2001/XMLSchema#"; + private static final Locator STRING = new IRI(_XSD_BASE + "string"); + private static final Locator ANY_URI = new IRI(_XSD_BASE + "anyURI"); + private String _value; private Locator _resource; @@ -96,7 +100,7 @@ * @param value The locator. */ public void setResource(Locator value) { - _fireEvent(Event.SET_VALUE, _value, value); + _fireEvent(Event.SET_LOCATOR, _resource, value); _value = null; _resource = value; } Modified: tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java 2008-04-25 20:24:19 UTC (rev 41) +++ tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java 2008-04-26 09:51:39 UTC (rev 42) @@ -25,15 +25,13 @@ /** * Indicates that a Topic Maps construct has a value and a datatype. * + * This interface is not meant to be used outside of the tinyTiM package. + * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ interface IDatatypeAwareConstruct extends IConstruct { - static final String _XSD_BASE = "http://www.w3.org/2001/XMLSchema#"; - static final Locator STRING = new IRI(_XSD_BASE + "string"); - static final Locator ANY_URI = new IRI(_XSD_BASE + "anyURI"); - /** * The value of this Topic Maps construct. * Modified: tinytim/trunk/src/main/java/org/tinytim/SignatureGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/SignatureGenerator.java 2008-04-25 20:24:19 UTC (rev 41) +++ tinytim/trunk/src/main/java/org/tinytim/SignatureGenerator.java 2008-04-26 09:51:39 UTC (rev 42) @@ -34,7 +34,7 @@ * Generates signatures for Topic Maps constructs. * * This class can be used to detect duplicates: If two Topic Maps constructs - * have the same signature, they should be merged (if they belong to the same + * have the same signature, they should be merged (if they belong to the same * parent). * * Neither the topic map, the parent, the reifier, nor item identifiers Modified: tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-04-25 20:24:19 UTC (rev 41) +++ tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-04-26 09:51:39 UTC (rev 42) @@ -243,7 +243,7 @@ } /** - * Returns a toic by its subject identifier. + * Returns a topic by its subject identifier. * * @param subjectIdentifier The subject identifier. * @return A topic or <code>null</code> if no topic with the specified @@ -254,7 +254,7 @@ } /** - * Returns a toic by its subject locator. + * Returns a topic by its subject locator. * * @param subjectLocator The subject locator. * @return A topic or <code>null</code> if no topic with the specified @@ -335,6 +335,8 @@ _identityManager.close(); _identityManager = null; _eventMultiplier = null; + _helperObjects.clear(); + _helperObjects = null; super.dispose(); } @@ -362,7 +364,7 @@ _helperObjects.put(interfaceName, instance); } catch (Exception ex) { - throw new HelperObjectInstantiationException(""); + throw new HelperObjectInstantiationException("Failed to initialize the helper object"); } } return instance; Modified: tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java 2008-04-25 20:24:19 UTC (rev 41) +++ tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java 2008-04-26 09:51:39 UTC (rev 42) @@ -80,7 +80,7 @@ } /** - * Creates a collection factory based according to the + * Creates a collection factory according to the * {@link Property#COLLECTION_FACTORY} value. If the collection factory * is not available, a default collection factory implementation is returned. * Modified: tinytim/trunk/src/main/java/org/tinytim/Typed.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Typed.java 2008-04-25 20:24:19 UTC (rev 41) +++ tinytim/trunk/src/main/java/org/tinytim/Typed.java 2008-04-26 09:51:39 UTC (rev 42) @@ -23,9 +23,9 @@ import org.tmapi.core.Topic; /** - * Class that provides a "type" property and fires an event if that type - * property changes. Additionally, this class provides - * a {@link IReifiable} implementation. + * Class that provides a "type" property and fires an event if that property + * changes. Additionally, this class provides a {@link IReifiable} + * implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ Modified: tinytim/trunk/src/test/java/org/tinytim/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/AllTests.java 2008-04-25 20:24:19 UTC (rev 41) +++ tinytim/trunk/src/test/java/org/tinytim/AllTests.java 2008-04-26 09:51:39 UTC (rev 42) @@ -30,7 +30,7 @@ * Runs all tests. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class AllTests extends TestSuite { Modified: tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java 2008-04-25 20:24:19 UTC (rev 41) +++ tinytim/trunk/src/test/java/org/tinytim/TestTopicUtils.java 2008-04-26 09:51:39 UTC (rev 42) @@ -60,6 +60,7 @@ assertFalse(TopicUtils.isRemovable(topic, true)); ((IReifiable) assoc).setReifier(null); assertTrue(TopicUtils.isRemovable(topic)); + assertTrue(TopicUtils.isRemovable(topic, true)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |