From: <lh...@us...> - 2008-05-05 12:37:34
|
Revision: 53 http://tinytim.svn.sourceforge.net/tinytim/?rev=53&view=rev Author: lheuer Date: 2008-05-05 05:37:18 -0700 (Mon, 05 May 2008) Log Message: ----------- - Preparing alpha 2 - DuplicateRemovalUtils added - voc package added - TypeInstanceConverter added - More tests - IIndexManager added - Additional tinyTiM specific property added Modified Paths: -------------- tinytim/trunk/CHANGES.txt tinytim/trunk/build.properties tinytim/trunk/build.xml tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/Property.java tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ScopedObjectsIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java tinytim/trunk/src/test/java/org/tinytim/AllTests.java tinytim/trunk/src/test/java/org/tinytim/TestSignatureGenerator.java tinytim/trunk/src/test/java/org/tinytim/index/TestScopedIndex.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/TypeInstanceConverter.java tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java tinytim/trunk/src/main/java/org/tinytim/voc/ tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java tinytim/trunk/src/test/java/org/tinytim/TestDuplicateRemovalUtils.java Modified: tinytim/trunk/CHANGES.txt =================================================================== --- tinytim/trunk/CHANGES.txt 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/CHANGES.txt 2008-05-05 12:37:18 UTC (rev 53) @@ -2,7 +2,28 @@ Changes Log =========== +1.5.0 alpha2 (05.05.2008) +------------------------- +Features: +- ``voc`` package added which provides access to common PSIs. +- ``DuplicateRemovalUtils`` added. Used to remove + duplicate Topic Maps constructs from topic maps, topics, + associations, and names +- ``TypeInstanceConverter`` added. Used to convert + type-instance associations into the topic's [types] + property. +- ``tmapi.TopicNamesIndex``, ``tmapi.OccurrenceIndex`` + and ``tmapi.VarinatsIndex`` use an optimized reindex + algorithm. +- Property to let ``Variant`` instances return the union + of their 'own' scope and the parent's scope. +Bugfixes: +- ``DatatypeAwareConstruct`` sent wrong event. Fixed +- All indexes return copies of their collections to avoid + concurrent modification exceptions. + + 1.5.0 alpha1 (25.04.2008) ------------------------- - Initial 1.5.x release Modified: tinytim/trunk/build.properties =================================================================== --- tinytim/trunk/build.properties 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/build.properties 2008-05-05 12:37:18 UTC (rev 53) @@ -1,4 +1,4 @@ version=1.5.0 -version_suffix=alpha1 +version_suffix=alpha2 debug=off optimize=on Modified: tinytim/trunk/build.xml =================================================================== --- tinytim/trunk/build.xml 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/build.xml 2008-05-05 12:37:18 UTC (rev 53) @@ -41,6 +41,7 @@ <echo message="Available targets:"/> <echo message=""/> <echo message=" jar Creates the jar"/> + <echo message=" doc Creates the API documentation"/> <echo message=" release Creates the jar and a distributable file"/> </target> @@ -58,7 +59,7 @@ <property name="dir.dist" value="${dir.dist.root}/${dist.name}"/> <property name="dir.build.classes" value="${dir.build}/classes"/> <property name="dir.build.tests" value="${dir.build}/tests"/> - <property name="dir.javadocs" value="${basedir}/javadocs"/> + <property name="dir.javadocs" value="${dir.dist}/docs/api"/> </target> <!-- =================================================================== --> @@ -132,6 +133,32 @@ </target> <!-- =================================================================== --> + <!-- Creates the Java Docs --> + <!-- =================================================================== --> + <target name="doc" depends="init"> + <mkdir dir="${dir.javadocs}"/> + <javadoc destdir="${dir.javadocs}" + packagenames="org.tinytim.*" + author="true" + version="true" + use="true" + splitindex="true" + noindex="false" + windowtitle="tinyTiM API v${dist.version}" + doctitle="tinyTiM API v${dist.version}"> + <fileset dir="${dir.src}"> + <exclude name="**/*Impl.*"/> + <exclude name="org/tinytim/index/**"/> + <exclude name="org/tinytim/IConstruct*"/> + <exclude name="org/tinytim/IDatatypeAware*"/> + <exclude name="org/tinytim/IRI*"/> + <exclude name="org/tinytim/IEvent*"/> + <exclude name="org/tinytim/Event*"/> + </fileset> + </javadoc> + </target> + + <!-- =================================================================== --> <!-- Creates the jar --> <!-- =================================================================== --> <target name="jar" depends="compile"> @@ -153,7 +180,7 @@ <!-- =================================================================== --> <!-- Prepares a distribution --> <!-- =================================================================== --> - <target name="dist" depends="jar"> + <target name="dist" depends="jar, doc"> <mkdir dir="${dir.dist}"/> <copy todir="${dir.dist}" file="${dir.build}/${tinytim.jar}"/> Added: tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java 2008-05-05 12:37:18 UTC (rev 53) @@ -0,0 +1,209 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.tinytim.index.ITypeInstanceIndex; +import org.tmapi.core.Association; +import org.tmapi.core.AssociationRole; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.core.TopicMapObject; +import org.tmapi.core.TopicName; +import org.tmapi.core.Variant; + +/** + * Removes duplicates from Topic Maps constructs. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class DuplicateRemovalUtils { + + private DuplicateRemovalUtils() { + // noop. + } + + /** + * Removes duplicate Topic Maps constructs from a topic map. + * + * @param topicMap The topic map to remove the duplicates from. + */ + public static void removeDuplicates(TopicMap topicMap) { + TopicMapImpl tm = (TopicMapImpl) topicMap; + for (Topic topic: tm.getTopics()) { + removeDuplicates(topic); + } + Map<String, Association> sig2Assoc = tm.getCollectionFactory().createMap(); + ITypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + for (Topic type: typeInstanceIdx.getAssociationTypes()) { + _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(type)); + } + _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(null)); + } + + private static void _removeDuplicateAssociations(Map<String, Association> sig2Assoc, Collection<AssociationImpl> assocs) { + sig2Assoc.clear(); + Association existing = null; + String sig = null; + for (Association assoc: assocs) { + removeDuplicates(assoc); + sig = SignatureGenerator.generateSignature(assoc); + existing = sig2Assoc.get(sig); + if (existing != null) { + MergeUtils.moveRoleCharacteristics(assoc, existing); + _removeConstruct(assoc); + } + else { + sig2Assoc.put(sig, assoc); + } + } + } + + /** + * Removes duplicate occurrences and names from a topic. + * + * @param topic The topic from which duplicates should be removed from. + */ + @SuppressWarnings("unchecked") + public static void removeDuplicates(Topic topic) { + _removeDuplicateOccurrences(topic.getOccurrences()); + _removeDuplicateNames(topic.getTopicNames()); + } + + /** + * Removes duplicate variants from a name. + * + * @param name The name from which the duplicates should be removed. + */ + @SuppressWarnings("unchecked") + public static void removeDuplicates(TopicName name) { + Map<String, Variant> sigs = new HashMap<String, Variant>(); + for (Variant variant: new ArrayList<Variant>(name.getVariants())) { + String sig = SignatureGenerator.generateSignature(variant); + Variant existing = sigs.get(sig); + if (existing != null) { + _handleExistingConstruct(variant, existing); + _removeConstruct(variant); + } + else { + sigs.put(sig, variant); + } + } + } + + /** + * + * + * @param occs + */ + private static void _removeDuplicateOccurrences(Collection<Occurrence> occs) { + Map<String, Occurrence> sigs = new HashMap<String, Occurrence>(occs.size()); + Occurrence existing = null; + for (Occurrence occ: new ArrayList<Occurrence>(occs)) { + String sig = SignatureGenerator.generateSignature(occ); + existing = sigs.get(sig); + if (existing != null) { + _handleExistingConstruct(occ, existing); + _removeConstruct(occ); + } + else { + sigs.put(sig, occ); + } + } + } + + /** + * + * + * @param names + */ + private static void _removeDuplicateNames(Collection<TopicName> names) { + Map<String, TopicName> sigs = new HashMap<String, TopicName>(names.size()); + TopicName existing = null; + for (TopicName name: new ArrayList<TopicName>(names)) { + removeDuplicates(name); + String sig = SignatureGenerator.generateSignature(name); + existing = sigs.get(sig); + if (existing != null) { + _handleExistingConstruct(name, existing); + _moveVariants(name, existing); + _removeConstruct(name); + } + else { + sigs.put(sig, name); + } + } + } + + /** + * Removes duplicate roles from an association. + * + * @param assoc The association to remove duplicate roles from. + */ + @SuppressWarnings("unchecked") + public static void removeDuplicates(Association assoc) { + Map<String, AssociationRole> sig2Role = ((TopicMapImpl) assoc.getTopicMap()).getCollectionFactory().createMap(); + AssociationRole existing = null; + String sig = null; + for (AssociationRole role: new ArrayList<AssociationRole>(assoc.getAssociationRoles())) { + sig = SignatureGenerator.generateSignature(role); + existing = sig2Role.get(sig); + if (existing != null) { + _handleExistingConstruct(role, existing); + _removeConstruct(role); + } + else { + sig2Role.put(sig, role); + } + } + } + + /** + * @see {@link MergeUtils#moveVariants(TopicNameImpl, TopicNameImpl)} + */ + private static void _moveVariants(TopicName source, TopicName target) { + MergeUtils.moveVariants((TopicNameImpl)source, (TopicNameImpl)target); + } + + /** + * @see {@link MergeUtils#removeConstruct(IConstruct)} + */ + private static void _removeConstruct(TopicMapObject construct) { + MergeUtils.removeConstruct((IConstruct) construct); + } + + /** + * @see {@link MergeUtils#handleExistingConstruct(IReifiable, IReifiable)} + */ + private static void _handleExistingConstruct(TopicMapObject source, TopicMapObject target) { + MergeUtils.handleExistingConstruct((IReifiable) source, (IReifiable) target); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java 2008-05-05 12:37:18 UTC (rev 53) @@ -30,7 +30,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -interface IDatatypeAwareConstruct extends IConstruct { +public interface IDatatypeAwareConstruct extends IConstruct { /** * The value of this Topic Maps construct. Modified: tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java 2008-05-05 12:37:18 UTC (rev 53) @@ -25,9 +25,9 @@ import java.util.List; import java.util.Map; +import org.tinytim.index.IIndexManager; import org.tinytim.index.IScopedIndex; import org.tinytim.index.ITypeInstanceIndex; -import org.tinytim.index.IndexManager; import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.Locator; @@ -266,7 +266,7 @@ */ private static void _replaceTopics(Topic source, Topic replacement) { TopicMapImpl tm = (TopicMapImpl) replacement.getTopicMap(); - IndexManager idxMan = tm.getIndexManager(); + IIndexManager idxMan = tm.getIndexManager(); ITypeInstanceIndex typeInstanceIndex = idxMan.getTypeInstanceIndex(); if (!typeInstanceIndex.isAutoUpdated()) { typeInstanceIndex.reindex(); Modified: tinytim/trunk/src/main/java/org/tinytim/Property.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Property.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/Property.java 2008-05-05 12:37:18 UTC (rev 53) @@ -56,4 +56,14 @@ */ public static final String XTM10_REIFICATION = "org.tinytim.XTM10Reification"; + /** + * Property which indicates if the variant's parent scope is included + * in the {@link org.tmapi.core.Variant#getScope()} return value. + * + * This property is disabled by default. + * + * If enabled, the variants scope is the union of its own scope and + * the parent name's scope. + */ + public static final String INHERIT_NAME_SCOPE = "org.tinytim.InheritNameScope"; } Modified: tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java 2008-05-05 12:37:18 UTC (rev 53) @@ -20,6 +20,7 @@ */ package org.tinytim; +import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -44,7 +45,7 @@ */ public static Set<TopicMapObject> getReified(Topic reifier) { TopicMapImpl tm = (TopicMapImpl) reifier.getTopicMap(); - Set<TopicMapObject> reified = tm.getCollectionFactory().createSet(); + Set<TopicMapObject> reified = new HashSet<TopicMapObject>(); for (Locator sid: ((TopicImpl) reifier).getSubjectIdentifiers()) { TopicMapObject obj = tm.getObjectByItemIdentifier(sid); if (obj != null) { Modified: tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -29,6 +29,7 @@ import java.util.Set; import org.tinytim.index.IndexManager; +import org.tinytim.index.IIndexManager; import org.tmapi.core.Association; import org.tmapi.core.AssociationRole; import org.tmapi.core.HelperObjectConfigurationException; @@ -88,6 +89,7 @@ private EventMultiplier _eventMultiplier; private Map<String, Object> _helperObjects; boolean _oldReification; + boolean _inheritNameScope; TopicMapImpl(TopicMapSystemImpl sys, Locator locator) { super(null); @@ -100,9 +102,11 @@ _evtHandlers = _collectionFactory.createMap(); _helperObjects = _collectionFactory.createMap(); _identityManager = new IdentityManager(this); + //TODO: Makes this configurable _indexManager = new IndexManager(this, _collectionFactory); _eventMultiplier = new EventMultiplier(this); _oldReification = "true".equalsIgnoreCase(sys.getProperty(Property.XTM10_REIFICATION)); + _inheritNameScope = "true".equalsIgnoreCase(sys.getProperty(Property.INHERIT_NAME_SCOPE)); } ICollectionFactory getCollectionFactory() { @@ -407,7 +411,7 @@ } } - public IndexManager getIndexManager() { + public IIndexManager getIndexManager() { return _indexManager; } Modified: tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -60,6 +60,7 @@ _features.put(feature.name, feature.defaultValue); } _properties.setProperty(Property.XTM10_REIFICATION, "true"); + _properties.setProperty(Property.INHERIT_NAME_SCOPE, "false"); _properties.setProperty(Property.COLLECTION_FACTORY, _COLL_FACTORY_JAVA); try { // Probe if Trove is available. Modified: tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java 2008-05-05 12:37:18 UTC (rev 53) @@ -20,9 +20,9 @@ */ package org.tinytim; +import org.tinytim.index.IIndexManager; import org.tinytim.index.IScopedIndex; import org.tinytim.index.ITypeInstanceIndex; -import org.tinytim.index.IndexManager; import org.tmapi.core.Topic; /** @@ -76,7 +76,7 @@ if (!topic.getRolesPlayed().isEmpty()) { return false; } - IndexManager idxMan = ((TopicMapImpl) topic.getTopicMap()).getIndexManager(); + IIndexManager idxMan = ((TopicMapImpl) topic.getTopicMap()).getIndexManager(); ITypeInstanceIndex typeInstanceIdx = idxMan.getTypeInstanceIndex(); if (!typeInstanceIdx.isAutoUpdated()) { typeInstanceIdx.reindex(); Added: tinytim/trunk/src/main/java/org/tinytim/TypeInstanceConverter.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/TypeInstanceConverter.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/TypeInstanceConverter.java 2008-05-05 12:37:18 UTC (rev 53) @@ -0,0 +1,171 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim; + +import java.util.Collection; +import java.util.logging.Logger; + +import org.tinytim.index.ITypeInstanceIndex; +import org.tinytim.voc.TMDM; +import org.tinytim.voc.XTM10; +import org.tmapi.core.Association; +import org.tmapi.core.AssociationRole; +import org.tmapi.core.Locator; +import org.tmapi.core.TMAPIException; +import org.tmapi.core.TMAPIRuntimeException; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; + +/** + * This class provides functions that can be used to convert the type-instance + * relationships that are modelled as associations into the [types] property + * of {@link org.tmapi.core.Topic}s. + * + * Copied from the TMAPIX-project. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class TypeInstanceConverter { + + //TODO: Implement types -> associations + + private static final Logger LOG = Logger.getLogger(TypeInstanceConverter.class.getName()); + + private TypeInstanceConverter() { + // noop. + } + + /** + * Converts type-instance relationships (TMDM 1.0) and class-instance + * relationships into the [types] property of the {@link org.tmapi.core.Topic}. + * + * @see #convertTMDMAssociationsToTypes(TopicMap) + * @see #convertXTMAssociationsToTypes(TopicMap) + * + * @param topicMap The topic map to convert. + */ + public static void convertAssociationsToTypes(TopicMap topicMap) { + convertTMDMAssociationsToTypes(topicMap); + convertXTMAssociationsToTypes(topicMap); + } + + /** + * Converts class-instance relationships (XTM 1.0) into the [types] property + * of {@link org.tmapi.core.Topic}s. The associations are removed from the + * topic map. + * + * @param topicMap The topic map to convert. + */ + public static void convertXTMAssociationsToTypes(TopicMap topicMap) { + _associationsToTypes(topicMap, XTM10.CLASS_INSTANCE, + XTM10.CLASS, XTM10.INSTANCE); + } + + /** + * Converts type-instance relationships (TMDM 1.0) into the [types] property + * of {@link org.tmapi.core.Topic}s. The associations are removed from the + * topic map. + * + * @param topicMap The topic map to convert. + */ + public static void convertTMDMAssociationsToTypes(TopicMap topicMap) { + _associationsToTypes(topicMap, TMDM.TYPE_INSTANCE, + TMDM.TYPE, TMDM.INSTANCE); + } + + private static void _associationsToTypes(TopicMap topicMap, + Locator typeInstance_, Locator type_, Locator instance_) { + TopicMapImpl tm = (TopicMapImpl) topicMap; + Topic typeInstance = tm.getTopicBySubjectIdentifier(typeInstance_); + if (typeInstance == null) { + return; + } + Topic type = tm.getTopicBySubjectIdentifier(type_); + if (type == null) { + return; + } + Topic instance = tm.getTopicBySubjectIdentifier(instance_); + if (instance == null) { + return; + } + ITypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + for (Association assoc: typeInstanceIdx.getAssociations(typeInstance)) { + Topic[] pair = _getTypeInstancePair(assoc, type, instance); + if (pair == null) { + continue; + } + pair[1].addType(pair[0]); + try { + assoc.remove(); + } + catch (TMAPIException ex) { + throw new TMAPIRuntimeException(ex); + } + } + } + + private static void _info(Association assoc, String msg) { + LOG.info("The association (ID: '" + assoc.getObjectId() + "') cannot be converted into a type. Reason: " + msg); + } + + @SuppressWarnings("unchecked") + private static Topic[] _getTypeInstancePair(Association assoc, Topic type, Topic instance) { + Collection<AssociationRole> roles = assoc.getAssociationRoles(); + if (roles.size() != 2) { + _info(assoc, "Not a binary association."); + return null; + } + if (assoc.getReifier() != null) { + _info(assoc, "It is reified"); + return null; + } + if (!assoc.getSourceLocators().isEmpty()) { + _info(assoc, "It as item identifiers"); + return null; + } + if (!assoc.getScope().isEmpty()) { + _info(assoc, "The scope is not unconstrained"); + return null; + } + Topic[] pair = new Topic[2]; + for (AssociationRole role: roles) { + if (type.equals(role.getType())) { + pair[0] = role.getPlayer(); + } + else if (instance.equals(role.getType())) { + pair[1] = role.getPlayer(); + } + } + if (pair[0] == null) { + _info(assoc, "The type player is null."); + return null; + } + if (pair[1] == null) { + _info(assoc, "The instance player is null"); + return null; + } + return pair; + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/TypeInstanceConverter.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -21,6 +21,7 @@ package org.tinytim; import java.util.Collection; +import java.util.Set; import org.tmapi.core.Locator; import org.tmapi.core.TMAPIException; @@ -53,6 +54,22 @@ } /* (non-Javadoc) + * @see org.tinytim.Scoped#getScope() + */ + @Override + public Set<Topic> getScope() { + if (_tm == null || _parent == null || !_tm._inheritNameScope) { + return super.getScope(); + } + else { + Set<Topic> scope = _tm.getCollectionFactory().createSet(); + scope.addAll(super.getScope()); + scope.addAll(((IScoped) _parent).getScope()); + return scope; + } + } + + /* (non-Javadoc) * @see org.tinytim.IMovable#moveTo(java.lang.Object) */ public void moveTo(TopicName newParent) { Added: tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java 2008-05-05 12:37:18 UTC (rev 53) @@ -0,0 +1,44 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.index; + +/** + * The index manager provides access to the tinyTiM-specific indexes. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IIndexManager { + + /** + * Returns the {@link ITypeInstanceIndex}. + * + * @return A {@link ITypeInstanceIndex} instance. + */ + public ITypeInstanceIndex getTypeInstanceIndex(); + + /** + * Returns the {@link IScopedIndex}. + * + * @return A {@link IScopedIndex} instance. + */ + public IScopedIndex getScopedIndex(); +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java 2008-05-05 12:37:18 UTC (rev 53) @@ -24,12 +24,13 @@ import org.tinytim.IEventPublisher; /** + * {@link IIndexManager} implementation which provides autoupdated default + * indexes. * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -public final class IndexManager { +public final class IndexManager implements IIndexManager { private ITypeInstanceIndex _typeInstanceIndex; private IScopedIndex _scopedIndex; @@ -39,10 +40,16 @@ _scopedIndex = new ScopedIndex(publisher, collFactory); } + /* (non-Javadoc) + * @see org.tinytim.index.IIndexManager#getTypeInstanceIndex() + */ public ITypeInstanceIndex getTypeInstanceIndex() { return _typeInstanceIndex; } + /* (non-Javadoc) + * @see org.tinytim.index.IIndexManager#getScopedIndex() + */ public IScopedIndex getScopedIndex() { return _scopedIndex; } Modified: tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java 2008-05-05 12:37:18 UTC (rev 53) @@ -77,7 +77,7 @@ public Collection<AssociationImpl> getAssociationsByTheme(Topic theme) { List<AssociationImpl> assocs = _theme2Assocs.get(theme); return assocs == null ? Collections.<AssociationImpl>emptySet() - : Collections.unmodifiableCollection(assocs); + : new ArrayList<AssociationImpl>(assocs); } /* (non-Javadoc) @@ -95,7 +95,7 @@ public Collection<OccurrenceImpl> getOccurrencesByTheme(Topic theme) { List<OccurrenceImpl> occs = _theme2Occs.get(theme); return occs == null ? Collections.<OccurrenceImpl>emptySet() - : Collections.unmodifiableCollection(occs); + : new ArrayList<OccurrenceImpl>(occs); } /* (non-Javadoc) @@ -113,7 +113,7 @@ public Collection<TopicNameImpl> getNamesByTheme(Topic theme) { List<TopicNameImpl> names = _theme2Names.get(theme); return names == null ? Collections.<TopicNameImpl>emptySet() - : Collections.unmodifiableCollection(names); + : new ArrayList<TopicNameImpl>(names); } /* (non-Javadoc) @@ -131,7 +131,7 @@ public Collection<VariantImpl> getVariantsByTheme(Topic theme) { List<VariantImpl> vars = _theme2Variants.get(theme); return vars == null ? Collections.<VariantImpl>emptySet() - : Collections.unmodifiableCollection(vars); + : new ArrayList<VariantImpl>(vars); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationRolesIndexImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -39,9 +39,13 @@ public class AssociationRolesIndexImpl extends AbstractTMAPIIndex implements AssociationRolesIndex { + private final IndexFlags _indexFlags; + public AssociationRolesIndexImpl(TopicMapImpl topicMap, ICollectionFactory collFactory) { super(topicMap, collFactory); + _indexFlags = topicMap.getIndexManager().getTypeInstanceIndex().isAutoUpdated() ? + IndexFlagsImpl.AUTOUPDATED : IndexFlagsImpl.NOT_AUTOUPDATED; } /* (non-Javadoc) @@ -62,14 +66,16 @@ * @see org.tmapi.index.Index#getFlags() */ public IndexFlags getFlags() throws TMAPIIndexException { - return IndexFlagsImpl.AUTOUPDATED; + return _indexFlags; } /* (non-Javadoc) * @see org.tmapi.index.Index#reindex() */ public void reindex() throws TMAPIIndexException { - // noop. + if (_indexFlags != IndexFlagsImpl.AUTOUPDATED) { + _weakTopicMap.get().getIndexManager().getTypeInstanceIndex().reindex(); + } } } Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/AssociationsIndexImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -39,9 +39,13 @@ public class AssociationsIndexImpl extends AbstractTMAPIIndex implements AssociationsIndex { + private final IndexFlags _indexFlags; + public AssociationsIndexImpl(TopicMapImpl topicMap, ICollectionFactory collFactory) { super(topicMap, collFactory); + _indexFlags = topicMap.getIndexManager().getTypeInstanceIndex().isAutoUpdated() ? + IndexFlagsImpl.AUTOUPDATED : IndexFlagsImpl.NOT_AUTOUPDATED; } /* (non-Javadoc) @@ -62,14 +66,16 @@ * @see org.tmapi.index.Index#getFlags() */ public IndexFlags getFlags() throws TMAPIIndexException { - return IndexFlagsImpl.AUTOUPDATED; + return _indexFlags; } /* (non-Javadoc) * @see org.tmapi.index.Index#reindex() */ public void reindex() throws TMAPIIndexException { - // noop. + if (_indexFlags != IndexFlagsImpl.AUTOUPDATED) { + _weakTopicMap.get().getIndexManager().getTypeInstanceIndex().reindex(); + } } } Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/OccurrencesIndexImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -107,29 +106,39 @@ public void reindex() throws TMAPIIndexException { _value2Occs.clear(); _loc2Occs.clear(); - for (Topic topic: _weakTopicMap.get().getTopics()) { - for (Iterator<Occurrence> iter = topic.getOccurrences().iterator(); iter.hasNext();) { - Occurrence occ = iter.next(); - if (occ.getValue() != null) { - String value = occ.getValue(); - List<Occurrence> occs = _value2Occs.get(value); - if (occs == null) { - occs = new ArrayList<Occurrence>(); - _value2Occs.put(value, occs); - } - occs.add(occ); - } - else if (occ.getResource() != null) { - Locator loc = occ.getResource(); - List<Occurrence> occs = _loc2Occs.get(loc); - if (occs == null) { - occs = new ArrayList<Occurrence>(); - _loc2Occs.put(loc, occs); - } - occs.add(occ); - } + ITypeInstanceIndex typeInstanceIdx = _weakTopicMap.get().getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + for (Topic type: typeInstanceIdx.getOccurrenceTypes()) { + for (Occurrence occ: typeInstanceIdx.getOccurrences(type)) { + _index(occ); } } + for (Occurrence occ: typeInstanceIdx.getOccurrences(null)) { + _index(occ); + } } + private void _index(Occurrence occ) { + if (occ.getValue() != null) { + String value = occ.getValue(); + List<Occurrence> occs = _value2Occs.get(value); + if (occs == null) { + occs = new ArrayList<Occurrence>(); + _value2Occs.put(value, occs); + } + occs.add(occ); + } + else if (occ.getResource() != null) { + Locator loc = occ.getResource(); + List<Occurrence> occs = _loc2Occs.get(loc); + if (occs == null) { + occs = new ArrayList<Occurrence>(); + _loc2Occs.put(loc, occs); + } + occs.add(occ); + } + } + } Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ScopedObjectsIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ScopedObjectsIndexImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ScopedObjectsIndexImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -44,9 +44,13 @@ public class ScopedObjectsIndexImpl extends AbstractTMAPIIndex implements ScopedObjectsIndex { + private final IndexFlags _indexFlags; + public ScopedObjectsIndexImpl(TopicMapImpl topicMap, ICollectionFactory collFactory) { super(topicMap, collFactory); + _indexFlags = topicMap.getIndexManager().getScopedIndex().isAutoUpdated() ? + IndexFlagsImpl.AUTOUPDATED : IndexFlagsImpl.NOT_AUTOUPDATED; } private IScopedIndex _getScopedIndex() { @@ -102,14 +106,16 @@ * @see org.tmapi.index.Index#getFlags() */ public IndexFlags getFlags() throws TMAPIIndexException { - return IndexFlagsImpl.AUTOUPDATED; + return _indexFlags; } /* (non-Javadoc) * @see org.tmapi.index.Index#reindex() */ public void reindex() throws TMAPIIndexException { - // noop. + if (_indexFlags != IndexFlagsImpl.AUTOUPDATED) { + _weakTopicMap.get().getIndexManager().getScopedIndex().reindex(); + } } } Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/TopicNamesIndexImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -94,18 +93,28 @@ @SuppressWarnings("unchecked") public void reindex() throws TMAPIIndexException { _value2Names.clear(); - for (Topic topic: _weakTopicMap.get().getTopics()) { - for (Iterator<TopicName> iter = topic.getTopicNames().iterator(); iter.hasNext();) { - TopicName name = iter.next(); - String value = name.getValue(); - List<TopicName> names = _value2Names.get(value); - if (names == null) { - names = new ArrayList<TopicName>(); - _value2Names.put(value, names); - } - names.add(name); + ITypeInstanceIndex typeInstanceIdx = _weakTopicMap.get().getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + for (Topic type: typeInstanceIdx.getNameTypes()) { + for (TopicName name: typeInstanceIdx.getNames(type)) { + _index(name); } } + for (TopicName name: typeInstanceIdx.getNames(null)) { + _index(name); + } } + private void _index(TopicName name) { + String value = name.getValue(); + List<TopicName> names = _value2Names.get(value); + if (names == null) { + names = new ArrayList<TopicName>(); + _value2Names.put(value, names); + } + names.add(name); + } + } Modified: tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/main/java/org/tinytim/index/tmapi/VariantsIndexImpl.java 2008-05-05 12:37:18 UTC (rev 53) @@ -29,6 +29,7 @@ import org.tinytim.ICollectionFactory; import org.tinytim.TopicMapImpl; +import org.tinytim.index.ITypeInstanceIndex; import org.tmapi.core.Locator; import org.tmapi.core.Topic; import org.tmapi.core.TopicName; @@ -88,31 +89,43 @@ public void reindex() throws TMAPIIndexException { _value2Variants.clear(); _loc2Variants.clear(); - for (Topic topic: _weakTopicMap.get().getTopics()) { - for (Iterator<TopicName> nameIter = topic.getTopicNames().iterator(); nameIter.hasNext();) { - for (Iterator<Variant> iter = nameIter.next().getVariants().iterator(); iter.hasNext();) { - Variant variant = iter.next(); - if (variant.getValue() != null) { - String value = variant.getValue(); - List<Variant> variants = _value2Variants.get(value); - if (variants == null) { - variants = new ArrayList<Variant>(); - _value2Variants.put(value, variants); - } - variants.add(variant); - } - else if (variant.getResource() != null) { - Locator loc = variant.getResource(); - List<Variant> variants = _loc2Variants.get(loc); - if (variants == null) { - variants = new ArrayList<Variant>(); - _loc2Variants.put(loc, variants); - } - variants.add(variant); - } + ITypeInstanceIndex typeInstanceIdx = _weakTopicMap.get().getIndexManager().getTypeInstanceIndex(); + if (!typeInstanceIdx.isAutoUpdated()) { + typeInstanceIdx.reindex(); + } + for (Topic type: typeInstanceIdx.getNameTypes()) { + for (TopicName name: typeInstanceIdx.getNames(type)) { + for (Iterator<Variant> iter = name.getVariants().iterator(); iter.hasNext();) { + _index(iter.next()); } } } + for (TopicName name: typeInstanceIdx.getNames(null)) { + for (Iterator<Variant> iter = name.getVariants().iterator(); iter.hasNext();) { + _index(iter.next()); + } + } } + private void _index(Variant variant) { + if (variant.getValue() != null) { + String value = variant.getValue(); + List<Variant> variants = _value2Variants.get(value); + if (variants == null) { + variants = new ArrayList<Variant>(); + _value2Variants.put(value, variants); + } + variants.add(variant); + } + else if (variant.getResource() != null) { + Locator loc = variant.getResource(); + List<Variant> variants = _loc2Variants.get(loc); + if (variants == null) { + variants = new ArrayList<Variant>(); + _loc2Variants.put(loc, variants); + } + variants.add(variant); + } + } + } Added: tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java 2008-05-05 12:37:18 UTC (rev 53) @@ -0,0 +1,86 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.voc; + +import org.tinytim.IRI; +import org.tmapi.core.Locator; + +/** + * Constants for TMDM 1.0 (model) PSIs. + * + * Copied from the Semagia MIO project. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class TMDM { + + private static final String _BASE = "http://psi.topicmaps.org/iso13250/model/"; + + /** + * Core concept of type-instance relationships. + * Used as association type. + */ + public static final Locator TYPE_INSTANCE = new IRI(_BASE + "type-instance"); + + /** + * Core concept of type within a type-instance relationship. + * Used as role type. + */ + public static final Locator TYPE = new IRI(_BASE + "type"); + + /** + * Core concept of instance within a type-instance relationship. + * Used as role type. + */ + public static final Locator INSTANCE = new IRI(_BASE + "instance"); + + /** + * Core concept of supertype-subtype relationship. + * Used as association type. + */ + public static final Locator SUPERTYPE_SUBTYPE = new IRI(_BASE + "supertype-subtype"); + + /** + * Core concept of supertype within a supertype-subtype relationship. + * Used as role type. + */ + public static final Locator SUPERTYPE = new IRI(_BASE + "supertype"); + + /** + * Core concept of subtype within a supertype-subtype relationship. + * Used as role type. + */ + public static final Locator SUBTYPE = new IRI(_BASE + "subtype"); + + /** + * Core concept of a topic name. + * Used as topic name type. + */ + public static final Locator TOPIC_NAME = new IRI(_BASE + "topic-name"); + + /** + * Used to indicate that a variant can be used for sorting purposes. + * Used as variant theme. + */ + public static final Locator SORT = new IRI(_BASE + "sort"); +} + Property changes on: tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java 2008-05-05 12:37:18 UTC (rev 53) @@ -0,0 +1,105 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.voc; + +import org.tinytim.IRI; +import org.tmapi.core.Locator; + +/** + * Constants for XTM 1.0 PSIs. + * + * The XTM 1.0 PSIs are outdated and have no relevance for the + * Topic Maps Data Model. These constants are provided for (de-)serializing + * topic maps which depend on the XTM 1.0 "model" but they should not be + * used for new topic maps, use {@link TMDM}. + * + * Copied from the Semagia MIO project. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class XTM10 { + + private static final String _BASE = "http://www.topicmaps.org/xtm/1.0/core.xtm#"; + + /** + * The core concept of class-instance; the class of association that + * represents class-instance relationships between topics, and that is + * semantically equivalent to the use of <instanceOf> subelements. + */ + public static final Locator CLASS_INSTANCE = new IRI(_BASE + "class-instance"); + + /** + * The core concept of class; the role of class as played by one of the + * members of a class-instance association. + */ + public static final Locator CLASS = new IRI(_BASE + "class"); + + /** + * The core concept of instance; the role of instance as played by one of + * the members of a class-instance association. + */ + public static final Locator INSTANCE = new IRI(_BASE + "instance"); + + /** + * The core concept of superclass-subclass; the class of association that + * represents superclass-subclass relationships between topics. + */ + public static final Locator SUPERCLASS_SUBCLASS = new IRI(_BASE + "superclass-subclass"); + + /** + * The core concept of superclass; the role of superclass as played by one + * of the members of a superclass-subclass association. + */ + public static final Locator SUPERCLASS = new IRI(_BASE + "superclass"); + + /** + * The core concept of subclass; the role of subclass as played by one of + * the members of a superclass-subclass association. + */ + public static final Locator SUBCLASS = new IRI(_BASE + "subclass"); + + /** + * The core concept of association; the generic class to which all + * associations belong unless otherwise specified. + */ + public static final Locator ASSOCIATION = new IRI(_BASE + "association"); + + /** + * The core concept of occurrence; the generic class to which all + * occurrences belong unless otherwise specified. + */ + public static final Locator OCCURRENCE = new IRI(_BASE + "occurrence"); + + /** + * Used to indicate that a variant can be used for sorting purposes. + * Used as variant theme. + */ + public static final Locator SORT = new IRI(_BASE + "sort"); + + /** + * Used to indicate that a variant can be used for displaying purposes. + * Used as variant theme. + */ + public static final Locator DISPLAY = new IRI(_BASE + "display"); + +} + Property changes on: tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/src/test/java/org/tinytim/AllTests.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/AllTests.java 2008-05-02 10:49:55 UTC (rev 52) +++ tinytim/trunk/src/test/java/org/tinytim/AllTests.java 2008-05-05 12:37:18 UTC (rev 53) @@ -41,6 +41,7 @@ public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(TestConstruct.class); + suite.addTestSuite(TestDuplicateRemovalUtils.class); suite.addTestSuite(TestItemIdentifierConstraint.class); suite.addTestSuite(TestReifiable.class); suite.addTestSuite(TestScoped.class); Added: tinytim/trunk/src/test/java/org/tinytim/TestDuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/test/java/org/tinytim/TestDuplicateRemovalUtils.java (rev 0) +++ tinytim/trunk/src/test/java/org/tinytim/TestDuplicateRemovalUtils.java 2008-05-05 12:37:18 UTC (rev 53) @@ -0,0 +1,107 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim; + +import java.util.Arrays; +import java.util.Collection; + +import org.tmapi.core.Association; +import org.tmapi.core.Locator; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicName; + +/** + * Tests against the {@link DuplicateRemovalUtils}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class TestDuplicateRemovalUtils extends TinyTimTestCase { + + public void testTopicRemoveNames() { + Topic topic = _tm.createTopic(); + TopicName name1 = topic.createTopicName("tinyTiM", null); + TopicName name2 = topic.createTopicName("tinyTiM", null); + assertNull(name1.getType()); + assertTrue(name1.getScope().isEmpty()); + assertNull(name2.getType()); + assertTrue(name2.getScope().isEmpty()); + assertEquals(2, topic.getTopicNames().size()); + DuplicateRemovalUtils.removeDuplicates(topic); + assertEquals(1, topic.getTopicNames().size()); + TopicName name = (TopicName) topic.getTopicNames().iterator().next(); + assertEquals("tinyTiM", name.getValue()); + assertNull(name.getType()); + assertTrue(name.getScope().isEmpty()); + } + + public void testTopicRemoveNames2() { + Topic topic = _tm.createTopic(); + TopicName name1 = topic.createTopicName("tinyTiM", null); + TopicName name2 = topic.createTopicName("tinyTiM", null); + Locator iid1 = _tm.createLocator("http://example.org/iid-1"); + Locator iid2 = _tm.createLocator("http://example.org/iid-2"); + name1.addSourceLocator(iid1); + name2.addSourceLocator(iid2); + assertEquals(2, topic.getTopicNames().size()); + DuplicateRemovalUtils.removeDuplicates(topic); + assertEquals(1, topic.getTopicNames().size()); + TopicName name = (TopicName) topic.getTopicNames().iterator().next(); + assertEquals("tinyTiM", name.getValue()); + assertNull(name.getType()); + assertTrue(name.getScope().isEmpty()); + assertEquals(2, name.getSourceLocators().size()); + assertTrue(name.getSourceLocators().contains(iid1)); + assertTrue(name.getSourceLocators().contains(iid2)); + } + + public void testTopicRemoveNames3() { + Topic topic = _tm.createTopic(); + Topic theme1 = _tm.createTopic(); + Topic theme2 = _tm.createTopic(); + Collection<Topic> scope1 = Arrays.asList(new Topic[] {theme1, theme2}); + Collection<Topic> scope2 = Arrays.asList(new Topic[] {theme2, theme1}); + TopicName name1 = topic.createTopicName("tinyTiM", scope1); + TopicName name2 = topic.createTopicName("tinyTiM", scope2); + assertEquals(2, name1.getScope().size()); + assertEquals(2, name2.getScope().size()); + assertEquals(2, topic.getTopicNames().size()); + DuplicateRemovalUtils.removeDuplicates(topic); + assertEquals(1, topic.getTopicNames().size()); + TopicName name = (TopicNa... [truncated message content] |