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