|
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.
|