From: <lh...@us...> - 2008-11-12 14:48:06
|
Revision: 177 http://tinytim.svn.sourceforge.net/tinytim/?rev=177&view=rev Author: lheuer Date: 2008-11-12 14:48:00 +0000 (Wed, 12 Nov 2008) Log Message: ----------- - Fixed bug #2269551 -- Topic types are not considered as dependency - Fixed bug #2221024 -- Merging topic maps causes an autom. generated topic iid - Introduced ITopicMap - Renamed TopicMapImpl to MemoryTopicMap - Renamed TopicMapSystemImpl to MemoryTopicMapSystem Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/DecimalLiteral.java tinytim/trunk/src/main/java/org/tinytim/core/Event.java tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java tinytim/trunk/src/main/java/org/tinytim/core/IScope.java tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java tinytim/trunk/src/main/java/org/tinytim/core/IntegerLiteral.java tinytim/trunk/src/main/java/org/tinytim/core/Literal.java tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java tinytim/trunk/src/main/java/org/tinytim/index/AbstractIndex.java tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/CollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/ICollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/utils/Feature.java tinytim/trunk/src/main/java/org/tinytim/utils/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceConverter.java tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java tinytim/trunk/src/test/java/org/tinytim/core/AbstractTMAPITestSuite.java tinytim/trunk/src/test/java/org/tinytim/core/AllTests.java tinytim/trunk/src/test/java/org/tinytim/core/TinyTimTestCase.java tinytim/trunk/src/test/java/org/tinytim/utils/TestTopicUtils.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/Version.java tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java tinytim/trunk/src/main/java/org/tinytim/core/ITopicMap.java tinytim/trunk/src/main/java/org/tinytim/core/LocatorImpl.java tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMapSystem.java tinytim/trunk/src/main/java/org/tinytim/utils/Property.java tinytim/trunk/src/main/java/org/tinytim/voc/Namespace.java tinytim/trunk/src/test/java/org/tinytim/core/TestLocatorImpl.java Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/core/IRI.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemImpl.java tinytim/trunk/src/test/java/org/tinytim/core/TestIRI.java Added: tinytim/trunk/src/main/java/org/tinytim/Version.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Version.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/Version.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,37 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim; + +/** + * Provides the version information. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class Version { + + private static final String _MAJOR = "@MAJOR@"; + private static final String _MINOR = "@MINOR@"; + private static final String _MICRO = "@MICRO@"; + private static final String _STATE ="@STATE@"; + private static final String _DATE = "@DATE@"; + + /** + * The release information. + */ + public static final String RELEASE = _MAJOR + "." + _MINOR + "." + _MICRO + _STATE + _DATE; + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/Version.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,92 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +import java.util.Map; + +import org.tmapi.core.FeatureNotRecognizedException; +import org.tmapi.core.Locator; +import org.tmapi.core.TMAPIException; +import org.tmapi.core.TopicMap; +import org.tmapi.core.TopicMapExistsException; +import org.tmapi.core.TopicMapSystem; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +abstract class AbstractTopicMapSystem implements TopicMapSystem { + + protected final Map<String, Boolean> _features; + protected final Map<String, Object> _properties; + + AbstractTopicMapSystem(Map<String, Boolean> features, Map<String, Object> properties) throws TMAPIException { + _features = features; + _properties = properties; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#getFeature(java.lang.String) + */ + public boolean getFeature(String featureName) throws FeatureNotRecognizedException { + final Boolean supported = _features.get(featureName); + if (supported == null) { + TopicMapSystemFactoryImpl.reportFeatureNotRecognized(featureName); + } + return supported; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#getProperty(java.lang.String) + */ + public Object getProperty(String propertyName) { + return _properties.get(propertyName); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#createLocator(java.lang.String) + */ + public Locator createLocator(String reference) { + return Literal.createIRI(reference); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#getTopicMap(java.lang.String) + */ + public TopicMap getTopicMap(String reference) { + return getTopicMap(createLocator(reference)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#createTopicMap(java.lang.String) + */ + public TopicMap createTopicMap(String reference) throws TopicMapExistsException { + return createTopicMap(createLocator(reference)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#close() + */ + public void close() { + _features.clear(); + _properties.clear(); + } + + abstract void removeTopicMap(MemoryTopicMap tm); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-11-12 14:48:00 UTC (rev 177) @@ -35,12 +35,12 @@ private Set<Role> _roles; - AssociationImpl(TopicMapImpl tm) { + AssociationImpl(ITopicMap tm) { super(tm); _roles = CollectionFactory.createIdentitySet(IConstant.ASSOC_ROLE_SIZE); } - AssociationImpl(TopicMapImpl topicMap, Topic type, IScope scope) { + AssociationImpl(ITopicMap topicMap, Topic type, IScope scope) { super(topicMap, type, scope); _roles = CollectionFactory.createIdentitySet(IConstant.ASSOC_ROLE_SIZE); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-11-12 14:48:00 UTC (rev 177) @@ -33,11 +33,11 @@ abstract class ConstructImpl implements IConstruct { protected String _id; - protected TopicMapImpl _tm; + protected ITopicMap _tm; protected Construct _parent; private Set<Locator> _iids; - ConstructImpl(TopicMapImpl topicMap) { + ConstructImpl(ITopicMap topicMap) { _tm = topicMap; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-11-12 14:48:00 UTC (rev 177) @@ -54,13 +54,13 @@ * @param target The topic map which should receive the topics and associations. */ public static void copy(TopicMap source, TopicMap target) { - _copy(source, (TopicMapImpl) target); + _copy(source, (ITopicMap) target); } /** * @see #copy(TopicMap, TopicMap) */ - private static void _copy(TopicMap source, TopicMapImpl target) { + private static void _copy(TopicMap source, ITopicMap target) { if (source == null || target == null) { throw new IllegalArgumentException("Neither the source topic map nor the target topic map must be null"); } @@ -123,9 +123,9 @@ * @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, + private static Topic _copyTopic(Topic topic, ITopicMap target, Map<Topic, Topic> mergeMap) { - Topic targetTopic = target.createTopic(); + Topic targetTopic = target.createTopicWithoutIdentity(); _copyIdentities(topic, targetTopic); _copyTypes(topic, targetTopic, mergeMap); _copyCharacteristics(topic, (TopicImpl)targetTopic, mergeMap); @@ -161,7 +161,7 @@ for (Topic type: topic.getTypes()) { Topic targetType = mergeMap.get(type); if (targetType == null) { - targetType = _copyTopic(type, targetTopic.getTopicMap(), mergeMap); + targetType = _copyTopic(type, (ITopicMap) targetTopic.getTopicMap(), mergeMap); } targetTopic.addType(targetType); } @@ -261,7 +261,7 @@ return; } Topic reifier = mergeMap.containsKey(sourceReifier) ? mergeMap.get(sourceReifier) - : _copyTopic(sourceReifier, target.getTopicMap(), mergeMap); + : _copyTopic(sourceReifier, (ITopicMap) target.getTopicMap(), mergeMap); target.setReifier(reifier); } @@ -276,7 +276,7 @@ Map<Topic, Topic> mergeMap) { Topic sourceType = source.getType(); return mergeMap.containsKey(sourceType) ? mergeMap.get(sourceType) - : _copyTopic(sourceType, tm, mergeMap); + : _copyTopic(sourceType, (ITopicMap) tm, mergeMap); } /** @@ -293,7 +293,7 @@ Topic theme = null; for (Topic sourceTheme: source.getScope()) { theme = mergeMap.containsKey(sourceTheme) ? mergeMap.get(sourceTheme) - : _copyTopic(sourceTheme, tm, mergeMap); + : _copyTopic(sourceTheme, (ITopicMap) tm, mergeMap); themes.add(theme); } return themes; @@ -320,7 +320,7 @@ * @param mergeMap The map which holds the merge mappings. */ private static void _copyAssociations(TopicMap source, - TopicMapImpl target, Map<Topic, Topic> mergeMap) { + TopicMap target, Map<Topic, Topic> mergeMap) { Set<Association> assocs = target.getAssociations(); IIntObjectMap<Association> sigs = CollectionFactory.createIntObjectMap(assocs.size()); for (Association assoc: assocs) { Modified: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-11-12 14:48:00 UTC (rev 177) @@ -35,11 +35,11 @@ private ILiteral _literal; - DatatypeAwareConstruct(TopicMapImpl tm) { + DatatypeAwareConstruct(ITopicMap tm) { super(tm); } - DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, ILiteral literal, IScope scope) { + DatatypeAwareConstruct(ITopicMap topicMap, Topic type, ILiteral literal, IScope scope) { super(topicMap, type, scope); _literal = literal; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/DecimalLiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DecimalLiteral.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/DecimalLiteral.java 2008-11-12 14:48:00 UTC (rev 177) @@ -25,7 +25,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ + * @version $Rev:$ - $Date:$ */ final class DecimalLiteral implements ILiteral { Modified: tinytim/trunk/src/main/java/org/tinytim/core/Event.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-11-12 14:48:00 UTC (rev 177) @@ -17,11 +17,13 @@ /** * Event constants. - * + * <p> * All events are sent before a change happens. This allows to check * some constraints. - * + * </p> + * <p> * This class is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ @@ -76,6 +78,7 @@ * Notification that a variant should be removed. */ REMOVE_VARIANT, + /** * Notification that a subject identifier should be added. @@ -137,8 +140,19 @@ */ SET_LITERAL, - MOVE_OCCURRENCE, - MOVE_NAME, - MOVE_VARIANT + /** + * Notification that an occurrence should be moved from one topic to another. + */ + MOVED_OCCURRENCE, + /** + * Notification that a name should be moved from one topic to another. + */ + MOVED_NAME, + /** + * Notification that a variant should be moved from one name to another. + */ + MOVED_VARIANT, + + ATTACHED_NAME, DETACHED_NAME, ATTACHED_OCCURRENCE, DETACHED_OCCURRENCE, } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstant.java 2008-11-12 14:48:00 UTC (rev 177) @@ -25,11 +25,11 @@ */ interface IConstant { /** - * Initial size of the {@link TopicMapImpl} topic set + * Initial size of the {@link MemoryTopicMap} topic set */ public static final int TM_TOPIC_SIZE = 100; /** - * Initial size of the {@link TopicMapImpl} association set + * Initial size of the {@link MemoryTopicMap} association set */ public static final int TM_ASSOCIATION_SIZE = 100; /** @@ -101,7 +101,7 @@ */ public static final int SCOPE_SCOPES_SIZE = 10; /** - * Initial size of the {@link TopicMapSystemImpl} topic map map. + * Initial size of the {@link MemoryTopicMapSystem} topic map map. */ public static final int SYSTEM_TM_SIZE = 4; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-11-12 14:48:00 UTC (rev 177) @@ -19,20 +19,65 @@ /** * Enhancement of the {@link org.tmapi.core.Construct} interface. - * + * <p> + * Avoids <tt>foo instanceof Bar</tt> checks. Each construct knows its type. + * </p> + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ public interface IConstruct extends Construct { + /** + * Returns <tt>true</tt> if this is a topic map. + * + * @return <tt>true</tt> if this is a topic map, <tt>false</tt> otherwise. + */ public boolean isTopicMap(); + + /** + * Returns <tt>true</tt> if this is a topic. + * + * @return <tt>true</tt> if this is a topic, <tt>false</tt> otherwise. + */ public boolean isTopic(); + + /** + * Returns <tt>true</tt> if this is an association. + * + * @return <tt>true</tt> if this is an association, <tt>false</tt> otherwise. + */ public boolean isAssociation(); + + /** + * Returns <tt>true</tt> if this is a role. + * + * @return <tt>true</tt> if this is a role, <tt>false</tt> otherwise. + */ public boolean isRole(); + + /** + * Returns <tt>true</tt> if this is an occurrence. + * + * @return <tt>true</tt> if this is an occurrence, <tt>false</tt> otherwise. + */ public boolean isOccurrence(); + + /** + * Returns <tt>true</tt> if this is a name. + * + * @return <tt>true</tt> if this is a name, <tt>false</tt> otherwise. + */ public boolean isName(); + + /** + * Returns <tt>true</tt> if this is a variant. + * + * @return <tt>true</tt> if this is a variant, <tt>false</tt> otherwise. + */ public boolean isVariant(); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-11-12 14:48:00 UTC (rev 177) @@ -17,8 +17,9 @@ /** * Event handler that is able to handle Topic Maps events. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @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/core/IEventPublisher.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java 2008-11-12 14:48:00 UTC (rev 177) @@ -17,8 +17,9 @@ /** * Publisher for Topic Maps events. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ @@ -40,4 +41,5 @@ * @param handler The event handler. */ public void unsubscribe(Event event, IEventHandler handler); + } Added: tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,48 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +/** + * Something that subscribes and unsubscribes itself to an + * {org.tinytim.core.IEventPublisher}. + * <p> + * Implementations MUST have a default (public) constructor. + * </p> + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IEventPublisherAware { + + /** + * Subscribes this instance to the specified <tt>publisher</tt>. + * + * @param publisher An event publisher. + */ + public void subscribe(IEventPublisher publisher); + + /** + * Unsubscribes this instance from the specified <tt>publisher</tt>. + * <p> + * This method is only invoked if this instance has been subscribed to + * the <tt>publisher</tt>. + * </p> + * + * @param publisher The publisher to unsubscribe from. + */ + public void unsubscribe(IEventPublisher publisher); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisherAware.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,30 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +import org.tinytim.index.IIndexManager; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IIndexManagerAware { + + IIndexManager getIndexManager(); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IIndexManagerAware.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-11-12 14:48:00 UTC (rev 177) @@ -22,8 +22,9 @@ /** * Represents an immutable value with a datatype. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @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/core/ILiteralAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-11-12 14:48:00 UTC (rev 177) @@ -17,8 +17,9 @@ /** * Indicates that a literal can be attached to a construct. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @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/core/ILocator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-11-12 14:48:00 UTC (rev 177) @@ -20,8 +20,9 @@ /** * Marker interface which unifies the {@link org.tmapi.core.Locator} and * tinyTiM's {@link ILiteral}. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @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/core/IMovable.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java 2008-11-12 14:48:00 UTC (rev 177) @@ -20,8 +20,9 @@ /** * Indicates that a Topic Maps construct is able to be detached from the * current parent and attached to another parent. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IRI.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IRI.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IRI.java 2008-11-12 14:48:00 UTC (rev 177) @@ -1,138 +0,0 @@ -/* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.tinytim.core; - -import java.io.UnsupportedEncodingException; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.net.URI; -import java.net.URLDecoder; - -import org.tinytim.voc.XSD; -import org.tmapi.core.Locator; -import org.tmapi.core.TMAPIRuntimeException; - -/** - * Immutable representation of an IRI. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -final class IRI implements ILocator { - - private final URI _uri; - private final String _reference; - - IRI(String reference) { - try { - _reference = URLDecoder.decode(reference, "utf-8"); - } - catch (UnsupportedEncodingException ex) { - throw new TMAPIRuntimeException(ex); - } - _uri = URI.create(_reference.replace(" ", "%20")); - } - - private IRI(URI uri) { - try { - _reference = URLDecoder.decode(uri.toString(), "utf-8"); - } - catch (UnsupportedEncodingException ex) { - throw new TMAPIRuntimeException(ex); - } - _uri = uri; - } - - /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getDatatype() - */ - public Locator getDatatype() { - return XSD.ANY_URI; - } - - /* (non-Javadoc) - * @see org.tinytim.core.ILiteral#getValue() - */ - public String getValue() { - return _reference; - } - - public BigDecimal decimalValue() { - throw new NumberFormatException(); - } - - public float floatValue() { - throw new NumberFormatException(); - } - - public BigInteger integerValue() { - throw new NumberFormatException(); - } - - public int intValue() { - throw new NumberFormatException(); - } - - public long longValue() { - throw new NumberFormatException(); - } - - /* (non-Javadoc) - * @see org.tmapi.core.Locator#getReference() - */ - public String getReference() { - return _reference; - } - - /* (non-Javadoc) - * @see org.tmapi.core.Locator#resolve(java.lang.String) - */ - public Locator resolve(String reference) { - return new IRI(_uri.resolve(reference)); - } - - /* (non-Javadoc) - * @see org.tmapi.core.Locator#toExternalForm() - */ - public String toExternalForm() { - return _uri.toASCIIString(); - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - return this == obj || (obj instanceof IRI && _reference.equals(((IRI) obj)._reference)); - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - return _reference.hashCode(); - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return _uri.toString(); - } - -} Modified: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-11-12 14:48:00 UTC (rev 177) @@ -22,8 +22,9 @@ /** * Represents an immutable set of {@link org.tmapi.core.Topic}s. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @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/core/IScoped.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-11-12 14:48:00 UTC (rev 177) @@ -20,8 +20,9 @@ /** * Enhancement of the {@link org.tmapi.core.Scoped} interface which is * {@link IScope} aware. - * + * <p> * This interface is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ @@ -41,4 +42,5 @@ * @param scope The scope. */ public void setScopeObject(IScope scope); + } Added: tinytim/trunk/src/main/java/org/tinytim/core/ITopicMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ITopicMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/ITopicMap.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,54 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +import org.tmapi.core.Association; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +interface ITopicMap extends TopicMap, IEventHandler, IConstruct, IIndexManagerAware { + + /** + * + * + * @return + */ + Topic getDefaultTopicNameType(); + + void removeTopic(Topic topic); + + void removeAssociation(Association association); + + void addAssociation(Association assoc); + + /** + * Returns a topic without any identity. + * <p> + * The topic won't have an item identifier, subject identifier, or subject + * locator, just an internal identifier. + * </p> + * + * @return A topic without any identity. + */ + public Topic createTopicWithoutIdentity(); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/ITopicMap.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-11-12 14:48:00 UTC (rev 177) @@ -19,8 +19,9 @@ /** * Class used to generate identifiers. - * + * <p> * This class is not meant to be used outside of the tinyTiM package. + * </p> * * @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/core/IdentityManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-11-12 14:48:00 UTC (rev 177) @@ -28,34 +28,33 @@ /** * The identity manager takes care about the TMDM identity constraints and * provides an index to get Topic Maps constructs by their identity. - * + * <p> * This class is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -final class IdentityManager { +final class IdentityManager implements IEventPublisherAware { private Map<Locator, Topic> _sid2Topic; private Map<Locator, Topic> _slo2Topic; private Map<Locator, IConstruct> _iid2Construct; private Map<String, IConstruct> _id2Construct; - IdentityManager(TopicMapImpl tm) { + IdentityManager(MemoryTopicMap tm) { _id2Construct = CollectionFactory.createIdentityMap(IConstant.IDENTITY_ID2CONSTRUCT_SIZE); _sid2Topic = CollectionFactory.createIdentityMap(IConstant.IDENTITY_SID2TOPIC_SIZE); _slo2Topic = CollectionFactory.createIdentityMap(IConstant.IDENTITY_SLO2TOPIC_SIZE); _iid2Construct = CollectionFactory.createIdentityMap(IConstant.IDENTITY_IID2CONSTRUCT_SIZE); - _subscribe(tm); + subscribe(tm); _register(tm); } - /** - * Subscribes itself to the specified event publisher. - * - * @param publisher The publisher to subscribe to. + /* (non-Javadoc) + * @see org.tinytim.core.IEventPublisherAware#subscribe(org.tinytim.core.IEventPublisher) */ - private void _subscribe(IEventPublisher publisher) { + public void subscribe(IEventPublisher publisher) { IEventHandler handler = new TopicMapsConstructAddHandler(); publisher.subscribe(Event.ADD_TOPIC, handler); publisher.subscribe(Event.ADD_ASSOCIATION, handler); @@ -86,6 +85,13 @@ publisher.subscribe(Event.SET_REIFIER, handler); } + /* (non-Javadoc) + * @see org.tinytim.core.IEventPublisherAware#unsubscribe(org.tinytim.core.IEventPublisher) + */ + public void unsubscribe(IEventPublisher publisher) { + // noop. + } + /** * Registeres a Topic Maps construct and, if necessary, gives it an id. * Modified: tinytim/trunk/src/main/java/org/tinytim/core/IntegerLiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IntegerLiteral.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/IntegerLiteral.java 2008-11-12 14:48:00 UTC (rev 177) @@ -25,7 +25,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ + * @version $Rev:$ - $Date:$ */ final class IntegerLiteral implements ILiteral { Modified: tinytim/trunk/src/main/java/org/tinytim/core/Literal.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-11-12 14:48:00 UTC (rev 177) @@ -24,15 +24,16 @@ /** * - * + * <p> * This class is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ public final class Literal implements ILiteral { - private static final WeakObjectRegistry<IRI> _IRIS = new WeakObjectRegistry<IRI>(IConstant.LITERAL_IRI_SIZE); + private static final WeakObjectRegistry<LocatorImpl> _IRIS = new WeakObjectRegistry<LocatorImpl>(IConstant.LITERAL_IRI_SIZE); private static final WeakObjectRegistry<ILiteral> _STRINGS = new WeakObjectRegistry<ILiteral>(IConstant.LITERAL_STRING_SIZE); private static final WeakObjectRegistry<ILiteral> _OTHERS = new WeakObjectRegistry<ILiteral>(IConstant.LITERAL_OTHER_SIZE); @@ -69,7 +70,7 @@ if (value == null) { throw new IllegalArgumentException("The value must not be null"); } - return _IRIS.get(new IRI(value)); + return _IRIS.get(new LocatorImpl(value)); } public static synchronized ILiteral get(String value, Locator datatype) { @@ -155,7 +156,7 @@ if (value == null) { throw new IllegalArgumentException("The value must not be null"); } - return _registerIfAbsent(_IRIS, new IRI(value)); + return _registerIfAbsent(_IRIS, new LocatorImpl(value)); } public static synchronized ILiteral createDecimal(String value) { Modified: tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java 2008-11-12 14:23:22 UTC (rev 176) +++ tinytim/trunk/src/main/java/org/tinytim/core/LiteralNormalizer.java 2008-11-12 14:48:00 UTC (rev 177) @@ -20,8 +20,9 @@ /** * Normalizes literal values. - * + * <p> * This class is not meant to be used outside of the tinyTiM package. + * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ Added: tinytim/trunk/src/main/java/org/tinytim/core/LocatorImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/LocatorImpl.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/LocatorImpl.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,143 @@ +/* + * 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.core; + +import java.io.UnsupportedEncodingException; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.net.URI; +import java.net.URLDecoder; + +import org.tinytim.voc.XSD; +import org.tmapi.core.Locator; +import org.tmapi.core.TMAPIRuntimeException; + +/** + * Immutable representation of an IRI. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +final class LocatorImpl implements ILocator { + + private final URI _uri; + private final String _reference; + + LocatorImpl(String reference) { + try { + _reference = URLDecoder.decode(reference, "utf-8"); + } + catch (UnsupportedEncodingException ex) { + throw new TMAPIRuntimeException(ex); + } + _uri = URI.create(_reference.replace(" ", "%20")); + } + + private LocatorImpl(URI uri) { + try { + _reference = URLDecoder.decode(uri.toString(), "utf-8"); + } + catch (UnsupportedEncodingException ex) { + throw new TMAPIRuntimeException(ex); + } + _uri = uri; + } + + /* (non-Javadoc) + * @see org.tinytim.core.ILiteral#getDatatype() + */ + public Locator getDatatype() { + return XSD.ANY_URI; + } + + /* (non-Javadoc) + * @see org.tinytim.core.ILiteral#getValue() + */ + public String getValue() { + return _reference; + } + + public BigDecimal decimalValue() { + throw new NumberFormatException(); + } + + public float floatValue() { + throw new NumberFormatException(); + } + + public BigInteger integerValue() { + throw new NumberFormatException(); + } + + public int intValue() { + throw new NumberFormatException(); + } + + public long longValue() { + throw new NumberFormatException(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Locator#getReference() + */ + public String getReference() { + return _reference; + } + + /* (non-Javadoc) + * @see org.tmapi.core.Locator#resolve(java.lang.String) + */ + public Locator resolve(String reference) { + return new LocatorImpl(_uri.resolve(reference)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Locator#toExternalForm() + */ + public String toExternalForm() { + return _uri.toASCIIString(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return this == obj || (obj instanceof LocatorImpl && _reference.equals(((LocatorImpl) obj)._reference)); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return _reference.hashCode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return _uri.toString(); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/LocatorImpl.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2008-11-12 14:48:00 UTC (rev 177) @@ -0,0 +1,521 @@ +/* + * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.tinytim.core; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.tinytim.index.IndexManager; +import org.tinytim.index.IIndexManager; +import org.tinytim.internal.utils.Check; +import org.tinytim.internal.utils.CollectionFactory; +import org.tinytim.voc.TMDM; +import org.tmapi.core.Association; +import org.tmapi.core.IdentityConstraintException; +import org.tmapi.core.ModelConstraintException; +import org.tmapi.core.Role; +import org.tmapi.core.Locator; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.core.Construct; +import org.tmapi.core.Name; +import org.tmapi.core.Variant; +import org.tmapi.index.Index; + +/** + * {@link org.tmapi.core.TopicMap} implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +final class MemoryTopicMap extends ConstructImpl implements ITopicMap, + IEventHandler, IEventPublisher { + + private IdentityManager _identityManager; + private IIndexManager _indexManager; + private Locator _locator; + private Set<Topic> _topics; + private Set<Association> _assocs; + private AbstractTopicMapSystem _sys; + private Topic _reifier; + private Map<Event, List<IEventHandler>> _evtHandlers; + private EventMultiplier _eventMultiplier; + + MemoryTopicMap(AbstractTopicMapSystem sys, Locator locator) { + super(null); + super._tm = this; + _sys = sys; + _locator = locator; + _topics = CollectionFactory.createIdentitySet(IConstant.TM_TOPIC_SIZE); + _assocs = CollectionFactory.createIdentitySet(IConstant.TM_ASSOCIATION_SIZE); + _evtHandlers = CollectionFactory.createIdentityMap(); + _identityManager = new IdentityManager(this); + _indexManager = new IndexManager(); + _indexManager.subscribe(this); + _eventMultiplier = new EventMultiplier(this); + } + + Locator getLocator() { + return _locator; + } + + /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#getTopicMap() + */ + @Override + public TopicMap getTopicMap() { + return this; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createLocator(java.lang.String) + */ + public Locator createLocator(String reference) { + return Literal.createIRI(reference); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getTopics() + */ + public Set<Topic> getTopics() { + return Collections.unmodifiableSet(_topics); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ITopicMap#createTopicWithoutIdentity() + */ + public TopicImpl createTopicWithoutIdentity() { + TopicImpl topic = new TopicImpl(this); + addTopic(topic); + return topic; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createTopic() + */ + public Topic createTopic() { + Topic topic = createTopicWithoutIdentity(); + topic.addItemIdentifier(Literal.createIRI("urn:x-tinytim:" + IdGenerator.nextId())); + return topic; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createTopicByItemIdentifier(org.tmapi.core.Locator) + */ + public Topic createTopicByItemIdentifier(Locator iid) { + if (iid == null) { + throw new ModelConstraintException(null, "The item identifier must not be null"); + } + Construct construct = getConstructByItemIdentifier(iid); + if (construct != null) { + if (construct instanceof Topic) { + return (Topic) construct; + } + throw new IdentityConstraintException(null, construct, iid, "A construct with the item identifier '" + iid.getReference() + "' already exists"); + } + else { + Topic topic = getTopicBySubjectIdentifier(iid); + if (topic != null) { + topic.addItemIdentifier(iid); + return topic; + } + } + TopicImpl topic = createTopicWithoutIdentity(); + topic.addItemIdentifier(iid); + return topic; + } + + public Topic getDefaultTopicNameType() { + return createTopicBySubjectIdentifier(TMDM.TOPIC_NAME); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#createTopicBySubjectIdentifier(org.tmapi.core.Locator) + */ + public Topic createTopicBySubjectIdentifier(Locator sid) { + if (sid == null) { + throw new ModelConstraintException(null, "The subject identifier must not be null"); + } + Topic topic = getTopicBySubjectIdentifier(sid); + if (topic != null) { + return topic; + } + else { + Construct construct = getConstructByItemIdentifier(sid); + if (construct != null && construct instanceof Topic) { + topic = (Topic) construct; + topic.addSubjectIdentifier(sid); + return topic; + } + } + topic = createTopicWithoutIdentity(); + topic.addSubjectIdentifier(sid); + return topic; + } + + public Topic createTopicBySubjectLocator(Locator slo) { + if (slo == null) { + throw new ModelConstraintException(null, "The subject locator must not be null"); + } + Topic topic = getTopicBySubjectLocator(slo); + if (topic != null) { + return topic; + } + topic = createTopicWithoutIdentity(); + topic.addSubjectLocator(slo); + 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); + } + + public void removeTopic(Topic topic_) { + TopicImpl topic = (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); + } + + public Association createAssociation(Topic type, Topic... scope) { + Check.scopeNotNull(this, scope); + return createAssociation(type, Arrays.asList(scope)); + } + + public Association createAssociation(Topic type, Collection<Topic> scope) { + Check.typeNotNull(this, type); + Check.scopeNotNull(this, scope); + AssociationImpl assoc = new AssociationImpl(this, type, Scope.create(scope)); + addAssociation(assoc); + return assoc; + } + + public void addAssociation(Association assoc_) { + AssociationImpl assoc = (AssociationImpl) assoc_; + if (assoc._parent == this) { + return; + } + _fireEvent(Event.ADD_ASSOCIATION, null, assoc); + assoc._parent = this; + _assocs.add(assoc); + } + + public void removeAssociation(Association assoc_) { + AssociationImpl assoc = (AssociationImpl) assoc_; + if (assoc._parent != this) { + return; + } + _fireEvent(Event.REMOVE_ASSOCIATION, assoc, null); + for (Role role: assoc.getRoles()) { + TopicImpl player = (TopicImpl) role.getPlayer(); + if (player != null) { + player.removeRolePlayed(role); + } + } + _assocs.remove(assoc); + assoc._parent = null; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getConstructById(java.lang.String) + */ + public Construct getConstructById(String id) { + return _identityManager.getConstructById(id); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getTopicBySubjectIdentifier(org.tmapi.core.Locator) + */ + public Topic getTopicBySubjectIdentifier(Locator subjectIdentifier) { + return _identityManager.getTopicBySubjectIdentifier(subjectIdentifier); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getTopicBySubjectLocator(org.tmapi.core.Locator) + */ + public Topic getTopicBySubjectLocator(Locator subjectLocator) { + return _identityManager.getTopicBySubjectLocator(subjectLocator); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#getConstructByItemIdentifier(org.tmapi.core.Locator) + */ + public Construct getConstructByItemIdentifier(Locator itemIdentifier) { + return _identityManager.getConstructByItemIdentifier(itemIdentifier); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#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.tmapi.core.TopicMap#getIndex(java.lang.Class) + */ + @SuppressWarnings("unchecked") + public <I extends Index> I getIndex(Class<I> indexInterface) { + if (indexInterface.getName().equals("org.tmapi.index.TypeInstanceIndex")) { + return (I) _indexManager.getTypeInstanceIndex(); + } + if (indexInterface.getName().equals("org.tmapi.index.ScopedIndex")) { + return (I) _indexManager.getScopedIndex(); + } + if (indexInterface.getName().equals("org.tmapi.index.LiteralIndex")) { + return (I) _indexManager.getLiteralIndex(); + } + throw new UnsupportedOperationException("Index '" + indexInterface.getName() + "' is unknown"); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#mergeIn(org.tmapi.core.TopicMap) + */ + public void mergeIn(TopicMap other) { + MergeUtils.merge(other, this); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#close() + */ + public void close() { + remove(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#isTopicMap() + */ + @Override + public boolean isTopicMap() { + return true; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMap#remove() + */ + public void remove() { + _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.tinytim.core.ConstructImpl#_fireEvent(org.tinytim.core.Event, java.lang.Object, java.lang.Object) + */ + @Override + protected final void _fireEvent(Event evt, Object oldValue, Object newValue) { + handleEvent(evt, this, oldValue, newValue); + } + + /* (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; + ... [truncated message content] |