From: <lh...@us...> - 2008-08-07 14:26:12
|
Revision: 101 http://tinytim.svn.sourceforge.net/tinytim/?rev=101&view=rev Author: lheuer Date: 2008-08-07 14:26:19 +0000 (Thu, 07 Aug 2008) Log Message: ----------- Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/core/ 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/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/core/Event.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/IFactory.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/IRI.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/JavaCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/core/Literal.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/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/core/TroveCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java tinytim/trunk/src/main/java/org/tinytim/core/VariantImpl.java Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/index/IIndex.java tinytim/trunk/src/main/java/org/tinytim/index/IIndexManager.java tinytim/trunk/src/main/java/org/tinytim/index/IScopedIndex.java tinytim/trunk/src/main/java/org/tinytim/index/ITypeInstanceIndex.java tinytim/trunk/src/main/java/org/tinytim/index/IndexManager.java tinytim/trunk/src/main/java/org/tinytim/index/ScopedIndex.java tinytim/trunk/src/main/java/org/tinytim/index/TypeInstanceIndex.java tinytim/trunk/src/main/java/org/tinytim/index/tmapi/ Added: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,155 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +import org.tmapi.core.Association; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; + +/** + * {@link org.tmapi.core.Association} implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +final class AssociationImpl extends ScopedImpl implements Association { + + private Set<Role> _roles; + + AssociationImpl(TopicMapImpl topicMap, Topic type, Collection<Topic> scope) { + super(topicMap, type, scope); + _roles = _makeSet(2); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#getParent() + */ + @Override + public TopicMap getParent() { + return _tm; + } + + /** + * Adds a role to this association. + * + * @param role The role to add. + */ + void addRole(Role role) { + RoleImpl r = (RoleImpl) role; + if (r._parent == this) { + return; + } + assert r._parent == null; + _fireEvent(Event.ADD_ROLE, null, r); + _roles.add(r); + r._parent = this; + TopicImpl player = (TopicImpl) r.getPlayer(); + if (player != null) { + player.addRolePlayed(r); + } + } + + /** + * Removes a role from this association. + * + * @param role The role to remove. + */ + void removeRole(Role role) { + RoleImpl r = (RoleImpl) role; + if (r._parent != this) { + return; + } + _fireEvent(Event.REMOVE_ROLE, r, null); + _roles.remove(role); + r._parent = null; + TopicImpl player = (TopicImpl) r.getPlayer(); + if (player != null) { + player.removeRolePlayed(r); + } + } + + /* (non-Javadoc) + * @see org.tmapi.core.Association#createRole(org.tmapi.core.Topic, org.tmapi.core.Topic) + */ + public Role createRole(Topic type, Topic player) { + if (type == null) { + throw new IllegalArgumentException("The type must not be null"); + } + if (player == null) { + throw new IllegalArgumentException("The player must not be null"); + } + RoleImpl role = new RoleImpl(_tm, type, player); + addRole(role); + return role; + } + + /* (non-Javadoc) + * @see org.tmapi.core.Association#getRoles() + */ + public Set<Role> getRoles() { + return Collections.unmodifiableSet(_roles); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Association#getRoleTypes() + */ + public Set<Topic> getRoleTypes() { + Set<Topic> roleTypes = _makeSet(_roles.size()); + for (Role role: _roles) { + roleTypes.add(role.getType()); + } + return roleTypes; + } + + /* (non-Javadoc) + * @see org.tmapi.core.Association#getRoles(org.tmapi.core.Topic) + */ + public Set<Role> getRoles(Topic type) { + if (type == null) { + throw new IllegalArgumentException("The type must not be null"); + } + Set<Role> roles = _makeSet(_roles.size()); + for (Role role: _roles) { + if (type == role.getType()) { + roles.add(role); + } + } + return roles; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapObject#remove() + */ + public void remove() { + _tm.removeAssociation(this); + for (Role role: new ArrayList<Role>(_roles)) { + role.remove(); + } + _roles = null; + super.dispose(); + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,170 @@ +/* + * 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.util.Collections; +import java.util.Set; + +import org.tmapi.core.Construct; +import org.tmapi.core.Locator; +import org.tmapi.core.TopicMap; + +/** + * Base class for all Topic Maps constructs. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +abstract class ConstructImpl implements Construct { + + protected String _id; + protected TopicMapImpl _tm; + protected Construct _parent; + private Set<Locator> _iids; + + ConstructImpl(TopicMapImpl topicMap) { + _tm = topicMap; + } + + protected <E> Set<E> _makeSet() { + return _tm.getCollectionFactory().createIdentitySet(); + } + + protected <E> Set<E> _makeSet(int size) { + return _tm.getCollectionFactory().createIdentitySet(size); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Construct#getParent() + */ + public Construct getParent() { + return _parent; + } + + /* (non-Javadoc) + * @see org.tmapi.core.Construct#getId() + */ + public String getId() { + return _id; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapObject#getTopicMap() + */ + public TopicMap getTopicMap() { + return _tm; + } + + /* (non-Javadoc) + * @see org.tmapi.core.Construct#getItemIdentifiers() + */ + public Set<Locator> getItemIdentifiers() { + return _iids == null ? Collections.<Locator>emptySet() + : Collections.unmodifiableSet(_iids); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Construct#addItemIdentifier(org.tmapi.core.Locator) + */ + public void addItemIdentifier(Locator itemIdentifier) { + if (itemIdentifier == null) { + throw new IllegalArgumentException("The item identifier must not be null"); + } + if (_iids != null && _iids.contains(itemIdentifier)) { + return; + } + _fireEvent(Event.ADD_IID, null, itemIdentifier); + if (_iids == null) { + _iids = _makeSet(); + } + _iids.add(itemIdentifier); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Construct#removeItemIdentifier(org.tmapi.core.Locator) + */ + public void removeItemIdentifier(Locator itemIdentifier) { + if (_iids == null || !_iids.contains(itemIdentifier)) { + return; + } + _fireEvent(Event.REMOVE_IID, itemIdentifier, null); + _iids.remove(itemIdentifier); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public final boolean equals(Object obj) { + return this == obj; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public final int hashCode() { + return _id.hashCode(); + } + + /** + * Notifies the topic map about an event. + * + * If the topic map is <code>null</code>, no event is sent. + * + * @param evt The event. + * @param oldValue The old value. + * @param newValue The new value. + */ + protected void _fireEvent(Event evt, Object oldValue, Object newValue) { + if (_tm != null) { + _tm.handleEvent(evt, this, oldValue, newValue); + } + } + + /** + * Releases used resources. + * + * Should be called in the {@link org.tmapi.core.TopicMapObject#remove()} + * method. + */ + protected void dispose() { + _tm = null; + _parent = null; + _iids = null; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(super.toString()); + sb.append(" ").append(_id); + sb.append(" iids=["); + for (Locator iid: getItemIdentifiers()) { + sb.append(iid); + sb.append(','); + } + sb.append("]"); + return sb.toString(); + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,374 @@ +/* + * 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.util.Map; +import java.util.Set; + +import org.tmapi.core.Association; +import org.tmapi.core.Construct; +import org.tmapi.core.Locator; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Reifiable; +import org.tmapi.core.Role; +import org.tmapi.core.Scoped; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.core.Typed; +import org.tmapi.core.Variant; + +/** + * This class provides methods to copy Topic Maps constructs from one + * topic map to another without creating duplicates. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +final class CopyUtils { + + /** + * Copies the topics and associations from the <tt>source</tt> to the + * <tt>target</tt> topic map. + * + * @param source The topic map to take the topics and associations from. + * @param target The topic map which should receive the topics and associations. + */ + public static void copy(TopicMap source, TopicMap target) { + _copy(source, (TopicMapImpl) target); + } + + /** + * @see #copy(TopicMap, TopicMap) + */ + private static void _copy(TopicMap source, TopicMapImpl target) { + if (source == null || target == null) { + throw new IllegalArgumentException("Neither the source topic map nor the target topic map must be null"); + } + if (source == target) { + return; + } + Map<Topic, Topic> mergeMap = target.getCollectionFactory().createIdentityMap(); + Topic existing = null; + Construct existingConstruct = null; + for (Topic topic: source.getTopics()) { + for (Locator slo: topic.getSubjectLocators()) { + existing = target.getTopicBySubjectLocator(slo); + if (existing != null) { + _addMerge(topic, existing, mergeMap); + } + } + for (Locator sid: topic.getSubjectIdentifiers()) { + existing = target.getTopicBySubjectIdentifier(sid); + if (existing != null) { + _addMerge(topic, existing, mergeMap); + } + existingConstruct = target.getConstructByItemIdentifier(sid); + if (existingConstruct instanceof Topic) { + _addMerge(topic, (Topic) existingConstruct, mergeMap); + } + } + for (Locator iid: topic.getItemIdentifiers()) { + existingConstruct = target.getConstructByItemIdentifier(iid); + if (existingConstruct instanceof Topic) { + _addMerge(topic, (Topic) existingConstruct, mergeMap); + } + existing = target.getTopicBySubjectIdentifier(iid); + if (existing != null) { + _addMerge(topic, existing, mergeMap); + } + } + } + if (source.getReifier() != null && target.getReifier() != null) { + _addMerge(source.getReifier(), target.getReifier(), mergeMap); + } + for (Topic topic: source.getTopics()) { + if (!mergeMap.containsKey(topic)) { + _copyTopic(topic, target, mergeMap); + } + } + for (Topic topic: mergeMap.keySet()) { + Topic targetTopic = mergeMap.get(topic); + _copyIdentities(topic, targetTopic); + _copyTypes(topic, targetTopic, mergeMap); + _copyCharacteristics(topic, (TopicImpl)targetTopic, mergeMap); + } + _copyAssociations(source, target, mergeMap); + } + + /** + * Copies the <tt>topic</tt> to the <tt>target</tt> topic map. + * + * @param topic The topic to copy. + * @param target The target topic map. + * @param mergeMap The map which holds the merge mappings. + * @return The newly created topic in the target topic map. + */ + private static Topic _copyTopic(Topic topic, TopicMap target, + Map<Topic, Topic> mergeMap) { + Topic targetTopic = target.createTopic(); + _copyIdentities(topic, targetTopic); + _copyTypes(topic, targetTopic, mergeMap); + _copyCharacteristics(topic, (TopicImpl)targetTopic, mergeMap); + return targetTopic; + } + + /** + * Copies the identities (item identifiers, subject identifiers and subject + * locators) from the <tt>source/tt> to the <tt>targetTopic</tt>. + * + * @param topic The topic to take the identities from. + * @param targetTopic The topic which gets the identities. + */ + private static void _copyIdentities(Topic topic, Topic targetTopic) { + for(Locator sid: topic.getSubjectIdentifiers()) { + targetTopic.addSubjectIdentifier(sid); + } + for(Locator slo: topic.getSubjectLocators()) { + targetTopic.addSubjectLocator(slo); + } + _copyItemIdentifiers(topic, targetTopic); + } + + /** + * Copies the types from the <tt>topic</tt> to the <tt>targetTopic</tt>. + * + * @param topic The topic to take the types from. + * @param targetTopic The topic which receives the types. + * @param mergeMap The map which holds the merge mappings. + */ + private static void _copyTypes(Topic topic, Topic targetTopic, + Map<Topic, Topic> mergeMap) { + for (Topic type: topic.getTypes()) { + Topic targetType = mergeMap.get(type); + if (targetType == null) { + targetType = _copyTopic(type, targetTopic.getTopicMap(), mergeMap); + } + targetTopic.addType(targetType); + } + } + + /** + * Copies the occurrences and names from <tt>topic</tt> to the + * <tt>targetTopic</tt>. + * + * @param topic The topic to take the characteristics from. + * @param targetTopic The target topic which gets the charateristics. + * @param mergeMap The map which holds the merge mappings. + */ + private static void _copyCharacteristics(Topic topic, TopicImpl targetTopic, + Map<Topic, Topic> mergeMap) { + Map<String, Reifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().createMap(); + for (Occurrence occ: targetTopic.getOccurrences()) { + sigs.put(SignatureGenerator.generateSignature(occ), occ); + } + Reifiable existing = null; + final TopicMap tm = targetTopic.getTopicMap(); + Topic type = null; + Set<Topic> scope = null; + Occurrence targetOcc = null; + for (Occurrence occ: topic.getOccurrences()) { + type = _copyType(occ, tm, mergeMap); + scope = _copyScope(occ, tm, mergeMap); + targetOcc = targetTopic._createOccurrence(type, ((ILiteralAware) occ).getLiteral(), scope); + existing = sigs.get(SignatureGenerator.generateSignature(targetOcc)); + if (existing != null) { + targetOcc.remove(); + targetOcc = (Occurrence)existing; + } + _copyReifier(occ, targetOcc, mergeMap); + _copyItemIdentifiers(occ, targetOcc); + } + sigs.clear(); + for (Name name: targetTopic.getNames()) { + sigs.put(SignatureGenerator.generateSignature(name), name); + } + + for (Name name: topic.getNames()) { + type = _copyType(name, tm, mergeMap); + scope = _copyScope(name, tm, mergeMap); + Name targetName = targetTopic._createName(type, ((ILiteralAware) name).getLiteral(), scope); + existing = sigs.get(SignatureGenerator.generateSignature(targetName)); + if (existing != null) { + targetName.remove(); + targetName = (Name) existing; + } + _copyReifier(name, targetName, mergeMap); + _copyItemIdentifiers(name, targetName); + _copyVariants(name, (NameImpl)targetName, mergeMap); + } + } + + /** + * Copies the variants from <tt>source</tt> to the <tt>target</tt>. + * + * @param source The name to take the variants from. + * @param target The target name which receives the variants. + * @param mergeMap The map which holds the merge mappings. + */ + private static void _copyVariants(Name source, NameImpl target, + Map<Topic, Topic> mergeMap) { + Map<String, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); + for (Variant variant: target.getVariants()) { + sigs.put(SignatureGenerator.generateSignature(variant), variant); + } + final TopicMap tm = target.getTopicMap(); + Variant existing = null; + Set<Topic> scope = null; + for (Variant variant: source.getVariants()) { + scope = _copyScope( variant, tm, mergeMap); + Variant targetVar = target._createVariant(((ILiteralAware) variant).getLiteral(), scope); + existing = sigs.get(SignatureGenerator.generateSignature(targetVar)); + if (existing != null) { + targetVar.remove(); + targetVar = existing; + } + _copyReifier(variant, targetVar, mergeMap); + _copyItemIdentifiers(variant, targetVar); + } + } + + /** + * Copies the reifier of <tt>source</tt> (if any) to the <tt>target</tt>. + * + * @param source The reifiable Topic Maps construct to take the reifier from. + * @param target The target Topic Maps construct. + * @param mergeMap The map which holds the merge mappings. + */ + private static void _copyReifier(Reifiable source, Reifiable target, + Map<Topic, Topic> mergeMap) { + Topic sourceReifier = source.getReifier(); + if (sourceReifier == null) { + return; + } + Topic reifier = mergeMap.containsKey(sourceReifier) ? mergeMap.get(sourceReifier) + : _copyTopic(sourceReifier, target.getTopicMap(), mergeMap); + target.setReifier(reifier); + } + + /** + * Copies the type of the <tt>source</tt> (if any) to the <tt>target</tt>. + * + * @param source The Topic Maps construct to take the type from. + * @param target The Topic Maps construct which receives the type. + * @param mergeMap The map which holds the merge mappings. + */ + private static Topic _copyType(Typed source, TopicMap tm, + Map<Topic, Topic> mergeMap) { + Topic sourceType = source.getType(); + return mergeMap.containsKey(sourceType) ? mergeMap.get(sourceType) + : _copyTopic(sourceType, tm, mergeMap); + } + + /** + * Copies all themes from the <tt>source</tt> scoped Topic Maps construct + * to the <tt>target</tt>. + * + * @param source The source to take the scope from. + * @param target The target which receives the scope. + * @param mergeMap The map which holds the merge mappings. + */ + private static Set<Topic>_copyScope(Scoped source, TopicMap tm, + Map<Topic, Topic> mergeMap) { + Set<Topic> themes = ((TopicMapImpl) tm).getCollectionFactory().createIdentitySet(source.getScope().size()); + Topic theme = null; + for (Topic sourceTheme: source.getScope()) { + theme = mergeMap.containsKey(sourceTheme) ? mergeMap.get(sourceTheme) + : _copyTopic(sourceTheme, tm, mergeMap); + themes.add(theme); + } + return themes; + } + + /** + * Copies the item identifiers from <tt>source</tt> to <tt>target</tt>. + * + * @param source The source Topic Maps construct. + * @param target The target Topic Maps construct. + */ + private static void _copyItemIdentifiers(Construct source, Construct target) { + for(Locator iid: source.getItemIdentifiers()) { + target.addItemIdentifier(iid); + } + } + + /** + * Copies the associations from the <tt>source</tt> topic map to the + * <tt>target</tt> topic map. + * + * @param source The topic map to take the associations from. + * @param target The topic map which receives the associations. + * @param mergeMap The map which holds the merge mappings. + */ + private static void _copyAssociations(TopicMap source, + TopicMapImpl target, Map<Topic, Topic> mergeMap) { + Set<Association> assocs = target.getAssociations(); + Map<String, Association> sigs = target.getCollectionFactory().createMap(assocs.size()); + for (Association assoc: assocs) { + sigs.put(SignatureGenerator.generateSignature(assoc), assoc); + } + Association existing = null; + Topic type = null; + Set<Topic> scope = null; + for (Association assoc: source.getAssociations()) { + type = _copyType(assoc, target, mergeMap); + scope = _copyScope(assoc, target, mergeMap); + Association targetAssoc = target.createAssociation(type, scope); + for (Role role: assoc.getRoles()) { + Role targetRole = targetAssoc.createRole(role.getType(), role.getPlayer()); + _copyItemIdentifiers(role, targetRole); + _copyReifier(role, targetRole, mergeMap); + } + existing = sigs.get(SignatureGenerator.generateSignature(targetAssoc)); + if (existing != null) { + MergeUtils.moveRoleCharacteristics(targetAssoc, existing); + targetAssoc.remove(); + targetAssoc = existing; + } + _copyReifier(assoc, targetAssoc, mergeMap); + _copyItemIdentifiers(assoc, targetAssoc); + } + } + + /** + * Adds a mapping from <tt>source</tt> to <tt>target</tt> into the + * <tt>mergeMap</tt>. + * + * If <tt>source</tt> has already a mapping to another target topic, + * <tt>target</tt> is merged with the existing target topic. + * + * @param source The source topic. + * @param target The target topic. + * @param mergeMap The map which holds the merge mappings. + */ + private static void _addMerge(Topic source, Topic target, Map<Topic, Topic> mergeMap) { + Topic prevTarget = mergeMap.get(source); + if (prevTarget != null) { + if (!prevTarget.equals(target)) { + MergeUtils.merge(target, prevTarget); + } + } + else { + mergeMap.put(source, target); + } + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,185 @@ +/* + * 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.math.BigDecimal; +import java.math.BigInteger; +import java.util.Collection; + +import org.tinytim.voc.XSD; +import org.tmapi.core.DatatypeAware; +import org.tmapi.core.Locator; +import org.tmapi.core.Topic; + +/** + * Implementation of {@link org.tinytim.IDatatypeAwareConstruct}. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +abstract class DatatypeAwareConstruct extends ScopedImpl implements + DatatypeAware, ILiteralAware { + + private ILiteral _literal; + + DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, ILiteral literal, Collection<Topic> scope) { + super(topicMap, type, scope); + _literal = literal; + } + + /* (non-Javadoc) + * @see org.tinytim.core.ILiteralAware#getLiteral() + */ + public ILiteral getLiteral() { + return _literal; + } + + /* (non-Javadoc) + * @see org.tinytim.core.ILiteralAware#setLiteral(org.tinytim.core.ILiteral) + */ + public void setLiteral(ILiteral literal) { + assert literal != null; + _fireEvent(Event.SET_LITERAL, _literal, literal); + _literal = literal; + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#getValue() + */ + public String getValue() { + return _literal.getValue(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#getDatatype() + */ + public Locator getDatatype() { + return _literal.getDatatype(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(java.lang.String) + */ + public void setValue(String value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(java.math.BigDecimal) + */ + public void setValue(BigDecimal value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(java.math.BigInteger) + */ + public void setValue(BigInteger value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(float) + */ + public void setValue(float value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(int) + */ + public void setValue(int value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(org.tmapi.core.Locator) + */ + public void setValue(Locator value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(long) + */ + public void setValue(long value) { + setLiteral(Literal.create(value)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#setValue(java.lang.String, org.tmapi.core.Locator) + */ + public void setValue(String value, Locator datatype) { + setLiteral(Literal.create(value, datatype)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#decimalValue() + */ + public BigDecimal decimalValue() { + return _literal.decimalValue(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#floatValue() + */ + public float floatValue() { + return _literal.floatValue(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#integerValue() + */ + public BigInteger integerValue() { + return _literal.integerValue(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#intValue() + */ + public int intValue() { + return _literal.intValue(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#locatorValue() + */ + public Locator locatorValue() { + return XSD.ANY_URI.equals(_literal.getDatatype()) ? (Locator) _literal + : Literal.createIRI(_literal.getValue()); + } + + /* (non-Javadoc) + * @see org.tmapi.core.DatatypeAware#longValue() + */ + public long longValue() { + return _literal.longValue(); + } + + /* (non-Javadoc) + * @see org.tinytim.Construct#dispose() + */ + @Override + protected void dispose() { + _literal = null; + super.dispose(); + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,184 @@ +/* + * 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.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.tmapi.core.Association; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.core.Variant; +import org.tmapi.index.TypeInstanceIndex; + +/** + * 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(); + TypeInstanceIndex 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<Association> 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); + assoc.remove(); + } + else { + sig2Assoc.put(sig, assoc); + } + } + } + + /** + * Removes duplicate occurrences and names from a topic. + * + * @param topic The topic from which duplicates should be removed from. + */ + public static void removeDuplicates(Topic topic) { + _removeDuplicateOccurrences(topic.getOccurrences()); + _removeDuplicateNames(topic.getNames()); + } + + /** + * Removes duplicate variants from a name. + * + * @param name The name from which the duplicates should be removed. + */ + public static void removeDuplicates(Name 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) { + MergeUtils.handleExistingConstruct(variant, existing); + variant.remove(); + } + 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) { + MergeUtils.handleExistingConstruct(occ, existing); + occ.remove(); + } + else { + sigs.put(sig, occ); + } + } + } + + /** + * + * + * @param names + */ + private static void _removeDuplicateNames(Collection<Name> names) { + Map<String, Name> sigs = new HashMap<String, Name>(names.size()); + Name existing = null; + for (Name name: new ArrayList<Name>(names)) { + removeDuplicates(name); + String sig = SignatureGenerator.generateSignature(name); + existing = sigs.get(sig); + if (existing != null) { + MergeUtils.handleExistingConstruct(name, existing); + MergeUtils.moveVariants(name, existing); + name.remove(); + } + else { + sigs.put(sig, name); + } + } + } + + /** + * Removes duplicate roles from an association. + * + * @param assoc The association to remove duplicate roles from. + */ + public static void removeDuplicates(Association assoc) { + Map<String, Role> sig2Role = ((TopicMapImpl) assoc.getTopicMap()).getCollectionFactory().createMap(); + Role existing = null; + String sig = null; + for (Role role: new ArrayList<Role>(assoc.getRoles())) { + sig = SignatureGenerator.generateSignature(role); + existing = sig2Role.get(sig); + if (existing != null) { + MergeUtils.handleExistingConstruct(role, existing); + role.remove(); + } + else { + sig2Role.put(sig, role); + } + } + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/Event.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Event.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,154 @@ +/* + * 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; + +/** + * Event constants. + * + * All events are sent before a change happens. This allows to check + * some constraints. + * + * This class is not meant to be used outside of the tinyTiM package. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public enum Event { + + /** + * Notification that a topic should be added. + */ + ADD_TOPIC, + /** + * Notification that a topic should be removed. + */ + REMOVE_TOPIC, + /** + * Notification that an association should be added. + */ + ADD_ASSOCIATION, + /** + * Notification that an association should be removed. + */ + REMOVE_ASSOCIATION, + /** + * Notification that a role should be added. + */ + ADD_ROLE, + /** + * Notification that a role should be removed. + */ + REMOVE_ROLE, + /** + * Notification that an occurrence should be added. + */ + ADD_OCCURRENCE, + /** + * Notification that an occurrence should be removed. + */ + REMOVE_OCCURRENCE, + /** + * Notification that a name should be added. + */ + ADD_NAME, + /** + * Notification that a name should be removed. + */ + REMOVE_NAME, + /** + * Notification that a variant should be added. + */ + ADD_VARIANT, + /** + * Notification that a variant should be removed. + */ + REMOVE_VARIANT, + + /** + * Notification that a subject identifier should be added. + */ + ADD_SID, + /** + * Notification that a subject identifier should be removed. + */ + REMOVE_SID, + /** + * Notification that a subject locator should be added. + */ + ADD_SLO, + /** + * Notification that a subject locator should be removed. + */ + REMOVE_SLO, + /** + * Notification that an item identifier should be added. + */ + ADD_IID, + /** + * Notification that an item identifier should be removed. + */ + REMOVE_IID, + + /** + * Notification that a type should be added to a topic. + */ + ADD_TYPE, + /** + * Notification that a type should be removed from a topic. + */ + REMOVE_TYPE, + /** + * Notification that the type of a {@link ITyped} construct should be set. + */ + SET_TYPE, + + /** + * Notification that a theme should be added to a {@link IScoped} construct. + */ + ADD_THEME, + /** + * Notification that a theme should be removed from a + * {@link IScoped} construct. + */ + REMOVE_THEME, + + /** + * Notification that the player of a role should be set. + */ + SET_PLAYER, + + /** + * Notification that the reifier of a {@link IReifiable} construct + * should be set. + */ + SET_REIFIER, + + /** + * Notification that the literal value of a name, an occurrence or variant + * should be set. + */ + SET_LITERAL, + + MOVE_OCCURRENCE, + MOVE_NAME, + MOVE_VARIANT + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/Event.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,49 @@ +/* + * 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 org.tmapi.core.Construct; + +/** + * Event handler that is able to handle Topic Maps events. + * + * This interface is not meant to be used outside of the tinyTiM package. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public interface IEventHandler { + + /** + * Callback method if a {@link IEventPublisher} sends an event to which + * this handler is subscribed to. + * + * @param evt The event. + * @param sender The sender of the event (this is not necessarily the + * publisher). + * @param oldValue The old value or <code>null</code> if the old value + * is not available or was <code>null</code>. + * @param newValue The new value or <code>null</code> if the new value + * is not available or should become <code>null</code>. + */ + public void handleEvent(Event evt, Construct sender, Object oldValue, Object newValue); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,48 @@ +/* + * 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; + +/** + * Publisher for Topic Maps events. + * + * This interface is not meant to be used outside of the tinyTiM package. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public interface IEventPublisher { + + /** + * Subscribes the handler for the specified event. + * + * @param event The event of interesst. + * @param handler The event handler. + */ + public void subscribe(Event event, IEventHandler handler); + + /** + * Removes the handler from the publisher. + * + * @param event The event. + * @param handler The event handler. + */ + public void unsubscribe(Event event, IEventHandler handler); +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IEventPublisher.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,48 @@ +/* + * 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 org.tmapi.core.Association; +import org.tmapi.core.Name; +import org.tmapi.core.Occurrence; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.Variant; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IFactory { + + public Association createAssociation(); + + public Role createRole(Association parent); + + public Occurrence createOccurrence(Topic parent); + + public Name createName(Topic parent); + + public Variant createVariant(Name parent); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,52 @@ +/* + * 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.math.BigDecimal; +import java.math.BigInteger; + +import org.tmapi.core.Locator; + +/** + * + * + * This interface is not meant to be used outside of the tinyTiM package. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface ILiteral { + + public String getValue(); + + public Locator getDatatype(); + + public BigDecimal decimalValue(); + + public float floatValue(); + + public BigInteger integerValue(); + + public int intValue(); + + public long longValue(); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,37 @@ +/* + * 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; + +/** + * + * + * This interface is not meant to be used outside of the tinyTiM package. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface ILiteralAware { + + public ILiteral getLiteral(); + + public void setLiteral(ILiteral literal); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,35 @@ +/* + * 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 org.tmapi.core.Locator; + +/** + * + * + * This interface is not meant to be used outside of the tinyTiM package. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface ILocator extends ILiteral, Locator { + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IMovable.java 2008-08-07 14:26:19 UTC (rev 101) @@ -0,0 +1,43 @@ +/* + * 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 ... [truncated message content] |
From: <lh...@us...> - 2008-08-07 14:28:46
|
Revision: 102 http://tinytim.svn.sourceforge.net/tinytim/?rev=102&view=rev Author: lheuer Date: 2008-08-07 14:28:52 +0000 (Thu, 07 Aug 2008) Log Message: ----------- - Imported current dev.status of tinyTiM 2. Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/utils/ tinytim/trunk/src/main/java/org/tinytim/utils/Feature.java tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/Property.java tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceConverter.java tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java Added: tinytim/trunk/src/main/java/org/tinytim/utils/Feature.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/Feature.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/Feature.java 2008-08-07 14:28:52 UTC (rev 102) @@ -0,0 +1,92 @@ +/* + * 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.utils; + +/** + * This class provides access to the feature strings that TMAPI-compatible + * Topic Maps processors must recognize (but not necessarily support). + * + * 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 Feature { + + private Feature() { + // noop. + } + + private static final String _FEATURE_BASE = "http://tmapi.org/features/"; + + /** + * An implementation which supports this feature can process locator + * addresses in URI notation as defined by RFC 2396. + * + * An implementation that supports URI notation locators MUST support + * the expansion of relative URIs that use a hierarchical URI scheme to + * fully specified URIs against a specified base URI, and MAY support + * the expansion of relative URIs that use other scheme-specific mechansims + * for relative URI expansion. + */ + public static final String NOTATION_URI= _FEATURE_BASE + "notation/URI"; + + /** + * An implementation which supports this feature supports the Topic Maps + * data model defined by the XTM 1.0 specification. + */ + public static final String XTM_1_0 = _FEATURE_BASE + "model/xtm1.0"; + + /** + * An implementation which supports this feature supports the + * <a href="http://www.isotopicmaps.org/sam/sam-model/">Topic Maps + * Data Model (TMDM) ISO/IEC 13250-2</a>. + */ + public static final String XTM_1_1 = _FEATURE_BASE + "model/xtm1.1"; + + /** + * An implementation which supports this feature MUST detect when two + * topic instances have topic names which match both in the scope of the + * name and the value of the name string, and, if XTM 1.1 is supported, + * the types are equal. Topics which have matching names must either be + * merged or a {@link org.tmapi.core.TopicsMustMergeException} must be + * raised, depending on the value of the + * <a href="http://tmapi.org/features/automerge">http://tmapi.org/features/automerge</a> + * feature. + */ + public static final String TNC = _FEATURE_BASE + "merge/byTopicName"; + + /** + * This feature indicates that the underlying + * {@link org.tmapi.core.TopicMapSystem} cannot be modified. + */ + public static final String READ_ONLY = _FEATURE_BASE + "readOnly"; + + /** + * If an implementation supports this feature, then whenever the + * implementation detects that two Topics should be merged (by one or more + * of the merge features defined under + * <a href="http://tmapi.org/features/merge/">http://tmapi.org/features/merge/</a>), + * then the implementation MUST merge the properties of these two Topics + * automatically and transparently to the API client. + */ + public static final String AUTOMERGE = _FEATURE_BASE + "automerge"; +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/Feature.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java 2008-08-07 14:28:52 UTC (rev 102) @@ -0,0 +1,120 @@ +/* + * 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.utils; + +import java.util.Map; +import java.util.Set; + +/** + * Factory for collections. + * + * Implementations of this interface must provide a default constructor. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public interface ICollectionFactory { + + /** + * Creates a {@link java.util.Set} with the specified initial <code>size</code>. + * + * @param <E> + * @param size The initial capacity. + * @return + */ + <E> Set<E> createSet(int size); + + /** + * Creates a {@link java.util.Set}. + * + * @param <E> + * @return + */ + <E> Set<E> createSet(); + + /** + * Creates a {@link java.util.Set} with the specified initial <tt>size</tt>. + * + * This is almost equal to {@link #createSet(int)} but the implementation is + * allowed (but not required) to compare the elements by identity. + * + * @param <E> + * @param size The initial capacity. + * @return + */ + <E> Set<E> createIdentitySet(int size); + + /** + * Creates a {@link java.util.Set}. + * + * This is almost equal to {@link #createSet()} but the implementation is + * allowed (but not required) to compare the elements by identity. + * + * @param <E> + * @return + */ + <E> Set<E> createIdentitySet(); + + /** + * Creates a {@link java.util.Map}. + * + * @param <K> + * @param <V> + * @return + */ + <K, V> Map<K, V> createMap(); + + /** + * Creates a {@link java.util.Map} with the specified initial <tt>size</tt>. + * + * @param <K> + * @param <V> + * @param size The initial capacity. + * @return + */ + <K, V> Map<K, V> createMap(int size); + + /** + * Creates a {@link java.util.Map}. + * + * This is almost equal to {@link #createMap()} but the implementation is + * allowed (but not required) to compare the key elements by identity. + * + * @param <K> + * @param <V> + * @return + */ + <K, V> Map<K, V> createIdentityMap(); + + /** + * Creates a {@link java.util.Map} with the specified initial <tt>size</tt>. + * + * This is almost equal to {@link #createMap(int)} but the implementation is + * allowed (but not required) to compare the key elements by identity. + * + * @param <K> + * @param <V> + * @param size The initial capacity. + * @return + */ + <K, V> Map<K, V> createIdentityMap(int size); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/Property.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/Property.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/Property.java 2008-08-07 14:28:52 UTC (rev 102) @@ -0,0 +1,45 @@ +/* + * 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.utils; + +/** + * Provides constants for all tinyTiM-specific TMAPI properties. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +public final class Property { + + private Property() { + // noop. + } + + /** + * Property which indicates the {@link org.tinytim.ICollectionFactory} to use. + * + * The default value of this property depends on the environment: If + * the <a href="http://trove4j.sourceforge.net/">Trove4J</a> lib is found, + * that lib used, otherwise a collection factory which depends on the + * default Java collections. + */ + public static final String COLLECTION_FACTORY = "org.tinytim.util.ICollectionFactory"; + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/Property.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceConverter.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceConverter.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/TypeInstanceConverter.java 2008-08-07 14:28:52 UTC (rev 102) @@ -0,0 +1,164 @@ +/* + * 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.utils; + +import java.util.Collection; +import java.util.logging.Logger; + +import org.tinytim.core.TopicMapImpl; +import org.tinytim.voc.TMDM; +import org.tinytim.voc.XTM10; +import org.tmapi.core.Association; +import org.tmapi.core.Locator; +import org.tmapi.core.Role; +import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; +import org.tmapi.index.TypeInstanceIndex; + +/** + * 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; + } + TypeInstanceIndex 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]); + assoc.remove(); + } + } + + private static void _info(Association assoc, String msg) { + LOG.info("The association (ID: '" + assoc.getId() + "') cannot be converted into a type property. Reason: " + msg); + } + + private static Topic[] _getTypeInstancePair(Association assoc, Topic type, Topic instance) { + Collection<Role> roles = assoc.getRoles(); + 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.getItemIdentifiers().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 (Role 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/utils/TypeInstanceConverter.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java 2008-08-07 14:26:19 UTC (rev 101) +++ tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java 2008-08-07 14:28:52 UTC (rev 102) @@ -20,67 +20,71 @@ */ 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. + * Copied with permission from the Semagia MIO project. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ -public final class TMDM { +public final class TMDM extends Vocabulary { + private TMDM() { + // noop. + } + 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"); + public static final Locator TYPE_INSTANCE = _createLocator(_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"); + public static final Locator TYPE = _createLocator(_BASE + "type"); /** * Core concept of instance within a type-instance relationship. * Used as role type. */ - public static final Locator INSTANCE = new IRI(_BASE + "instance"); + public static final Locator INSTANCE = _createLocator(_BASE + "instance"); /** * Core concept of supertype-subtype relationship. * Used as association type. */ - public static final Locator SUPERTYPE_SUBTYPE = new IRI(_BASE + "supertype-subtype"); + public static final Locator SUPERTYPE_SUBTYPE = _createLocator(_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"); + public static final Locator SUPERTYPE = _createLocator(_BASE + "supertype"); /** * Core concept of subtype within a supertype-subtype relationship. * Used as role type. */ - public static final Locator SUBTYPE = new IRI(_BASE + "subtype"); + public static final Locator SUBTYPE = _createLocator(_BASE + "subtype"); /** * Core concept of a topic name. * Used as topic name type. */ - public static final Locator TOPIC_NAME = new IRI(_BASE + "topic-name"); + public static final Locator TOPIC_NAME = _createLocator(_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"); + public static final Locator SORT = _createLocator(_BASE + "sort"); + } Added: tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java 2008-08-07 14:28:52 UTC (rev 102) @@ -0,0 +1,37 @@ +/* + * 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.core.Literal; +import org.tmapi.core.Locator; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +abstract class Vocabulary { + + protected static Locator _createLocator(String reference) { + return Literal.createIRI(reference); + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java 2008-08-07 14:28:52 UTC (rev 102) @@ -0,0 +1,53 @@ +/* + * 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.tmapi.core.Locator; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class XSD extends Vocabulary { + + private XSD() { + // noop. + } + + private static final String _BASE = "http://www.w3.org/2001/XMLSchema#"; + + public final static Locator STRING = _createLocator(_BASE + "string"); + + public final static Locator ANY_URI = _createLocator(_BASE + "anyURI"); + + public final static Locator DECIMAL = _createLocator(_BASE + "decimal"); + + public final static Locator INTEGER = _createLocator(_BASE + "integer"); + + public final static Locator INT = _createLocator(_BASE + "int"); + + public final static Locator FLOAT = _createLocator(_BASE + "float"); + + public final static Locator LONG = _createLocator(_BASE + "long"); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java 2008-08-07 14:26:19 UTC (rev 101) +++ tinytim/trunk/src/main/java/org/tinytim/voc/XTM10.java 2008-08-07 14:28:52 UTC (rev 102) @@ -20,7 +20,6 @@ */ package org.tinytim.voc; -import org.tinytim.IRI; import org.tmapi.core.Locator; /** @@ -34,9 +33,9 @@ * Copied from the Semagia MIO project. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ -public final class XTM10 { +public final class XTM10 extends Vocabulary { private static final String _BASE = "http://www.topicmaps.org/xtm/1.0/core.xtm#"; @@ -45,61 +44,61 @@ * 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"); + public static final Locator CLASS_INSTANCE = _createLocator(_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"); + public static final Locator CLASS = _createLocator(_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"); + public static final Locator INSTANCE = _createLocator(_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"); + public static final Locator SUPERCLASS_SUBCLASS = _createLocator(_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"); + public static final Locator SUPERCLASS = _createLocator(_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"); + public static final Locator SUBCLASS = _createLocator(_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"); + public static final Locator ASSOCIATION = _createLocator(_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"); + public static final Locator OCCURRENCE = _createLocator(_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"); + public static final Locator SORT = _createLocator(_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"); + public static final Locator DISPLAY = _createLocator(_BASE + "display"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-07 14:36:47
|
Revision: 103 http://tinytim.svn.sourceforge.net/tinytim/?rev=103&view=rev Author: lheuer Date: 2008-08-07 14:36:54 +0000 (Thu, 07 Aug 2008) Log Message: ----------- Added Paths: ----------- 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 Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/AssociationImpl.java tinytim/trunk/src/main/java/org/tinytim/AssociationRoleImpl.java tinytim/trunk/src/main/java/org/tinytim/Construct.java tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/Event.java tinytim/trunk/src/main/java/org/tinytim/ICollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/IConstruct.java tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java tinytim/trunk/src/main/java/org/tinytim/IEventHandler.java tinytim/trunk/src/main/java/org/tinytim/IEventPublisher.java tinytim/trunk/src/main/java/org/tinytim/IMovable.java tinytim/trunk/src/main/java/org/tinytim/IRI.java tinytim/trunk/src/main/java/org/tinytim/IReifiable.java tinytim/trunk/src/main/java/org/tinytim/IScoped.java tinytim/trunk/src/main/java/org/tinytim/ITyped.java tinytim/trunk/src/main/java/org/tinytim/IdentityManager.java tinytim/trunk/src/main/java/org/tinytim/JavaCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/OccurrenceImpl.java tinytim/trunk/src/main/java/org/tinytim/Property.java tinytim/trunk/src/main/java/org/tinytim/ReificationUtils.java tinytim/trunk/src/main/java/org/tinytim/Scoped.java tinytim/trunk/src/main/java/org/tinytim/SignatureGenerator.java tinytim/trunk/src/main/java/org/tinytim/TMAPIFeature.java tinytim/trunk/src/main/java/org/tinytim/TopicImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemFactoryImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicMapSystemImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicNameImpl.java tinytim/trunk/src/main/java/org/tinytim/TopicUtils.java tinytim/trunk/src/main/java/org/tinytim/TroveCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/TypeInstanceConverter.java tinytim/trunk/src/main/java/org/tinytim/Typed.java tinytim/trunk/src/main/java/org/tinytim/VariantImpl.java Deleted: tinytim/trunk/src/main/java/org/tinytim/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/AssociationImpl.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/AssociationImpl.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,114 +0,0 @@ -/* - * 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.Collections; -import java.util.Set; - -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.TMAPIException; -import org.tmapi.core.Topic; - -/** - * {@link org.tmapi.core.Association} implementation. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public final class AssociationImpl extends Scoped implements Association, - IReifiable, ITyped, IScoped { - - private Set<AssociationRole> _roles; - - AssociationImpl(TopicMapImpl topicMap) { - super(topicMap, null, null); - _roles = topicMap.getCollectionFactory().createSet(2); - } - - /** - * Adds a role to this association. - * - * @param role The role to add. - */ - void addRole(AssociationRole role) { - AssociationRoleImpl r = (AssociationRoleImpl) role; - if (r._parent == this) { - return; - } - assert r._parent == null; - _fireEvent(Event.ADD_ROLE, null, r); - _roles.add(r); - r._parent = this; - TopicImpl player = (TopicImpl) r.getPlayer(); - if (player != null) { - player.addRolePlayed(r); - } - } - - /** - * Removes a role from this association. - * - * @param role The role to remove. - */ - void removeRole(AssociationRole role) { - AssociationRoleImpl r = (AssociationRoleImpl) role; - if (r._parent != this) { - return; - } - _fireEvent(Event.REMOVE_ROLE, r, null); - _roles.remove(role); - r._parent = null; - TopicImpl player = (TopicImpl) r.getPlayer(); - if (player != null) { - player.removeRolePlayed(r); - } - } - - /* (non-Javadoc) - * @see org.tmapi.core.Association#createAssociationRole(org.tmapi.core.Topic, org.tmapi.core.Topic) - */ - public AssociationRole createAssociationRole(Topic player, Topic type) { - AssociationRoleImpl role = new AssociationRoleImpl(_tm, type, player); - addRole(role); - return role; - } - - /* (non-Javadoc) - * @see org.tmapi.core.Association#getAssociationRoles() - */ - public Set<AssociationRole> getAssociationRoles() { - return Collections.unmodifiableSet(_roles); - } - - /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#remove() - */ - public void remove() throws TMAPIException { - _tm.removeAssociation(this); - for (AssociationRole role: new ArrayList<AssociationRole>(_roles)) { - role.remove(); - } - _roles = null; - super.dispose(); - } -} Deleted: tinytim/trunk/src/main/java/org/tinytim/AssociationRoleImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/AssociationRoleImpl.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/AssociationRoleImpl.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,83 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim; - -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.TMAPIException; -import org.tmapi.core.Topic; - -/** - * {@link org.tmapi.core.AssociationRole} implementation. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public final class AssociationRoleImpl extends Typed implements AssociationRole, - ITyped { - - private Topic _player; - - AssociationRoleImpl(TopicMapImpl tm, Topic type, Topic player) { - super(tm, type); - _player = player; - } - - /* (non-Javadoc) - * @see org.tmapi.core.AssociationRole#getAssociation() - */ - public Association getAssociation() { - return (Association) _parent; - } - - /* (non-Javadoc) - * @see org.tmapi.core.AssociationRole#getPlayer() - */ - public Topic getPlayer() { - return _player; - } - - /* (non-Javadoc) - * @see org.tmapi.core.AssociationRole#setPlayer(org.tmapi.core.Topic) - */ - public void setPlayer(Topic player) { - if (_player == player) { - return; - } - _fireEvent(Event.SET_PLAYER, _player, player); - if (_player != null) { - ((TopicImpl)_player).removeRolePlayed(this); - } - _player = player; - if (player != null) { - ((TopicImpl) player).addRolePlayed(this); - } - } - - /* (non-Javadoc) - * @see org.tinytim.TopicMapObjectImpl#remove() - */ - public void remove() throws TMAPIException { - ((AssociationImpl) _parent).removeRole(this); - super.dispose(); - } - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/Construct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Construct.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/Construct.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,184 +0,0 @@ -/* - * 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.Collections; -import java.util.Set; - -import org.tmapi.core.DuplicateSourceLocatorException; -import org.tmapi.core.Locator; -import org.tmapi.core.TopicMap; - -/** - * Base class for all Topic Maps constructs. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -abstract class Construct implements IConstruct { - - protected String _id; - protected TopicMapImpl _tm; - protected IConstruct _parent; - private Set<Locator> _iids; - - Construct(TopicMapImpl topicMap) { - _tm = topicMap; - } - - /* (non-Javadoc) - * @see org.tinytim.IConstruct#getParent() - */ - public IConstruct getParent() { - return _parent; - } - - /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#getObjectId() - */ - public String getObjectId() { - return _id; - } - - /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#getSourceLocators() - */ - public Set<Locator> getSourceLocators() { - return getItemIdentifiers(); - } - - /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#addSourceLocator(org.tmapi.core.Locator) - */ - public void addSourceLocator(Locator loc) - throws DuplicateSourceLocatorException { - addItemIdentifier(loc); - } - - /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#removeSourceLocator(org.tmapi.core.Locator) - */ - public void removeSourceLocator(Locator loc) { - removeItemIdentifier(loc); - } - - /* (non-Javadoc) - * @see org.tmapi.core.TopicMapObject#getTopicMap() - */ - public TopicMap getTopicMap() { - return _tm; - } - - /* (non-Javadoc) - * @see org.tinytim.IConstruct#getItemIdentifiers() - */ - public Set<Locator> getItemIdentifiers() { - return _iids == null ? Collections.<Locator>emptySet() - : Collections.unmodifiableSet(_iids); - } - - /* (non-Javadoc) - * @see org.tinytim.IConstruct#addItemIdentifier(org.tmapi.core.Locator) - */ - public void addItemIdentifier(Locator itemIdentifier) { - if (_iids != null && _iids.contains(itemIdentifier)) { - return; - } - _fireEvent(Event.ADD_IID, null, itemIdentifier); - if (_iids == null) { - _iids = _tm.getCollectionFactory().createSet(); - } - _iids.add(itemIdentifier); - } - - /* (non-Javadoc) - * @see org.tinytim.IConstruct#removeItemIdentifier(org.tmapi.core.Locator) - */ - public void removeItemIdentifier(Locator itemIdentifier) { - if (_iids == null || !_iids.contains(itemIdentifier)) { - return; - } - _fireEvent(Event.REMOVE_IID, itemIdentifier, null); - _iids.remove(itemIdentifier); - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public final boolean equals(Object obj) { - if (this == obj) { - return true; - } - return (obj instanceof Construct) && _id.equals(((Construct) obj)._id); - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public final int hashCode() { - return _id.hashCode(); - } - - /** - * Notifies the topic map about an event. - * - * If the topic map is <code>null</code>, no event is sent. - * - * @param evt The event. - * @param oldValue The old value. - * @param newValue The new value. - */ - protected void _fireEvent(Event evt, Object oldValue, Object newValue) { - if (_tm != null) { - _tm.handleEvent(evt, this, oldValue, newValue); - } - } - - /** - * Releases used resources. - * - * Should be called in the {@link org.tmapi.core.TopicMapObject#remove()} - * method. - */ - protected void dispose() { - _tm = null; - _parent = null; - _iids = null; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(super.toString()); - sb.append(" ").append(_id); - sb.append(" iids=["); - for (Locator iid: getItemIdentifiers()) { - sb.append(iid); - sb.append(','); - } - sb.append("]"); - return sb.toString(); - } -} Deleted: tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/CopyUtils.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,385 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim; - -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.tmapi.core.Association; -import org.tmapi.core.AssociationRole; -import org.tmapi.core.Locator; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Topic; -import org.tmapi.core.TopicMap; -import org.tmapi.core.TopicMapObject; -import org.tmapi.core.TopicName; -import org.tmapi.core.Variant; - -/** - * This class provides methods to copy Topic Maps constructs from one - * topic map to another without creating duplicates. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -final class CopyUtils { - - /** - * Copies the topics and associations from the <code>source</code> to the - * <code>target</code> topic map. - * - * @param source The topic map to take the topics and associations from. - * @param target The topic map which should receive the topics and associations. - */ - public static void copy(TopicMap source, TopicMap target) { - _copy((TopicMapImpl) source, (TopicMapImpl) target); - } - - /** - * @see #copy(TopicMap, TopicMap) - */ - @SuppressWarnings("unchecked") - private static void _copy(TopicMapImpl source, TopicMapImpl target) { - if (source == null || target == null) { - throw new IllegalArgumentException("Neither the source topic map nor the target topic map must be null"); - } - if (source == target) { - return; - } - Map<Topic, Topic> mergeMap = target.getCollectionFactory().createMap(); - Topic existing = null; - TopicMapObject existingConstruct = null; - for (Topic topic: source.getTopics()) { - for (Iterator<Locator> iter = topic.getSubjectLocators().iterator(); iter.hasNext();) { - existing = target.getTopicBySubjectLocator(iter.next()); - if (existing != null) { - _addMerge(topic, existing, mergeMap); - } - } - for (Iterator<Locator> iter = topic.getSubjectIdentifiers().iterator(); iter.hasNext();) { - Locator sid = iter.next(); - existing = target.getTopicBySubjectIdentifier(sid); - if (existing != null) { - _addMerge(topic, existing, mergeMap); - } - existingConstruct = target.getObjectByItemIdentifier(sid); - if (existingConstruct instanceof Topic) { - _addMerge(topic, (Topic) existingConstruct, mergeMap); - } - } - for (Iterator<Locator> iter = topic.getSourceLocators().iterator(); iter.hasNext();) { - Locator iid = iter.next(); - existingConstruct = target.getObjectByItemIdentifier(iid); - if (existingConstruct instanceof Topic) { - _addMerge(topic, (Topic) existingConstruct, mergeMap); - } - existing = target.getTopicBySubjectIdentifier(iid); - if (existing != null) { - _addMerge(topic, existing, mergeMap); - } - } - } - if (source.getReifier() != null && target.getReifier() != null) { - _addMerge(source.getReifier(), target.getReifier(), mergeMap); - } - for (Topic topic: source.getTopics()) { - if (!mergeMap.containsKey(topic)) { - _copyTopic(topic, target, mergeMap); - } - } - for (Topic topic: mergeMap.keySet()) { - Topic targetTopic = mergeMap.get(topic); - _copyIdentities(topic, targetTopic); - _copyTypes(topic, targetTopic, mergeMap); - _copyCharacteristics(topic, (TopicImpl)targetTopic, mergeMap); - } - _copyAssociations(source, target, mergeMap); - } - - /** - * Copies the <code>topic</code> to the <code>target</code> topic map. - * - * @param topic The topic to copy. - * @param target The target topic map. - * @param mergeMap The map which holds the merge mappings. - * @return The newly created topic in the target topic map. - */ - private static Topic _copyTopic(Topic topic, TopicMap target, - Map<Topic, Topic> mergeMap) { - Topic targetTopic = target.createTopic(); - _copyIdentities(topic, targetTopic); - _copyTypes(topic, targetTopic, mergeMap); - _copyCharacteristics(topic, (TopicImpl)targetTopic, mergeMap); - return targetTopic; - } - - /** - * Copies the identities (item identifiers, subject identifiers and subject - * locators) from the <code>source/code> to the <code>targetTopic</code>. - * - * @param topic The topic to take the identities from. - * @param targetTopic The topic which gets the identities. - */ - @SuppressWarnings("unchecked") - private static void _copyIdentities(Topic topic, Topic targetTopic) { - for(Iterator<Locator> iter = topic.getSubjectIdentifiers().iterator(); iter.hasNext();) { - targetTopic.addSubjectIdentifier(iter.next()); - } - for(Iterator<Locator> iter = topic.getSubjectLocators().iterator(); iter.hasNext();) { - targetTopic.addSubjectLocator(iter.next()); - } - _copyItemIdentifiers((IConstruct)topic, (IConstruct)targetTopic); - } - - /** - * Copies the types from the <code>topic</code> to the <code>targetTopic</code>. - * - * @param topic The topic to take the types from. - * @param targetTopic The topic which receives the types. - * @param mergeMap The map which holds the merge mappings. - */ - @SuppressWarnings("unchecked") - private static void _copyTypes(Topic topic, Topic targetTopic, - Map<Topic, Topic> mergeMap) { - for (Iterator<Topic> iter = topic.getTypes().iterator(); iter.hasNext();) { - Topic type = iter.next(); - Topic targetType = mergeMap.get(type); - if (targetType == null) { - targetType = _copyTopic(type, targetTopic.getTopicMap(), mergeMap); - } - targetTopic.addType(targetType); - } - } - - /** - * Copies the occurrences and names from <code>topic</code> to the - * <code>targetTopic</code>. - * - * @param topic The topic to take the characteristics from. - * @param targetTopic The target topic which gets the charateristics. - * @param mergeMap The map which holds the merge mappings. - */ - private static void _copyCharacteristics(Topic topic, TopicImpl targetTopic, - Map<Topic, Topic> mergeMap) { - Map<String, IReifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().<String, IReifiable>createMap(); - for (Occurrence occ: targetTopic.getOccurrences()) { - sigs.put(SignatureGenerator.generateSignature(occ), (IReifiable)occ); - } - IReifiable existing = null; - for (Occurrence occ: ((TopicImpl) topic).getOccurrences()) { - Occurrence targetOcc = targetTopic.createOccurrence((String)null, null, null); - _copyType((ITyped)occ, (ITyped)targetOcc, mergeMap); - _copyScope((IScoped)occ, (IScoped)targetOcc, mergeMap); - if (occ.getValue() != null) { - targetOcc.setValue(occ.getValue()); - } - else if (occ.getResource() != null) { - targetOcc.setResource(occ.getResource()); - } - existing = sigs.get(SignatureGenerator.generateSignature(targetOcc)); - if (existing != null) { - MergeUtils.removeConstruct((IConstruct) targetOcc); - targetOcc = (Occurrence)existing; - } - _copyReifier((IReifiable) occ, (IReifiable) targetOcc, mergeMap); - _copyItemIdentifiers((IConstruct) occ, (IConstruct) targetOcc); - } - sigs.clear(); - for (TopicName name: targetTopic.getTopicNames()) { - sigs.put(SignatureGenerator.generateSignature(name), (IReifiable)name); - } - for (TopicName name: ((TopicImpl) topic).getTopicNames()) { - TopicName targetName = targetTopic.createTopicName(name.getValue(), null); - _copyType((ITyped) name, (ITyped) targetName, mergeMap); - _copyScope((IScoped) name, (IScoped) targetName, mergeMap); - existing = sigs.get(SignatureGenerator.generateSignature(targetName)); - if (existing != null) { - MergeUtils.removeConstruct((IConstruct)targetName); - targetName = (TopicName) existing; - } - _copyReifier((IReifiable) name, (IReifiable) targetName, mergeMap); - _copyItemIdentifiers((IConstruct) name, (IConstruct) targetName); - _copyVariants(name, targetName, mergeMap); - } - } - - /** - * Copies the variants from <code>source</code> to the <code>target</code>. - * - * @param source The name to take the variants from. - * @param target The target name which receives the variants. - * @param mergeMap The map which holds the merge mappings. - */ - private static void _copyVariants(TopicName source, TopicName target, - Map<Topic, Topic> mergeMap) { - Map<String, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); - for (Variant variant: ((TopicNameImpl) target).getVariants()) { - sigs.put(SignatureGenerator.generateSignature(variant), variant); - } - Variant existing = null; - for (Variant variant: ((TopicNameImpl) source).getVariants()) { - Variant targetVar = target.createVariant((String) null, null); - _copyScope((IScoped) variant, (IScoped) targetVar, mergeMap); - if (variant.getValue() != null) { - targetVar.setValue(variant.getValue()); - } - else if (variant.getResource() != null) { - targetVar.setResource(variant.getResource()); - } - existing = sigs.get(SignatureGenerator.generateSignature(targetVar)); - if (existing != null) { - MergeUtils.removeConstruct((IConstruct) targetVar); - targetVar = existing; - } - _copyReifier((IReifiable) variant, (IReifiable) targetVar, mergeMap); - _copyItemIdentifiers((IConstruct) variant, (IConstruct) targetVar); - } - } - - /** - * Copies the reifier of <code>source</code> (if any) to the <code>target</code>. - * - * @param source The reifiable Topic Maps construct to take the reifier from. - * @param target The target Topic Maps construct. - * @param mergeMap The map which holds the merge mappings. - */ - private static void _copyReifier(IReifiable source, IReifiable target, - Map<Topic, Topic> mergeMap) { - Topic sourceReifier = source.getReifier(); - if (sourceReifier == null) { - return; - } - Topic reifier = mergeMap.containsKey(sourceReifier) ? mergeMap.get(sourceReifier) - : _copyTopic(sourceReifier, target.getTopicMap(), mergeMap); - target.setReifier(reifier); - } - - /** - * Copies the type of the <code>source</code> (if any) to the <code>target</code>. - * - * @param source The Topic Maps construct to take the type from. - * @param target The Topic Maps construct which receives the type. - * @param mergeMap The map which holds the merge mappings. - */ - private static void _copyType(ITyped source, ITyped target, - Map<Topic, Topic> mergeMap) { - Topic sourceType = source.getType(); - if (sourceType == null) { - return; - } - Topic type = mergeMap.containsKey(sourceType) ? mergeMap.get(sourceType) - : _copyTopic(sourceType, target.getTopicMap(), mergeMap); - target.setType(type); - } - - /** - * Copies all themes from the <code>source</code> scoped Topic Maps construct - * to the <code>target</code>. - * - * @param source The source to take the scope from. - * @param target The target which receives the scope. - * @param mergeMap The map which holds the merge mappings. - */ - private static void _copyScope(IScoped source, IScoped target, - Map<Topic, Topic> mergeMap) { - Topic theme = null; - for (Topic sourceTheme: source.getScope()) { - theme = mergeMap.containsKey(sourceTheme) ? mergeMap.get(sourceTheme) - : _copyTopic(sourceTheme, target.getTopicMap(), mergeMap); - target.addTheme(theme); - } - } - - /** - * Copies the item identifiers from <code>source</code> to <code>target</code>. - * - * @param source The source Topic Maps construct. - * @param target The target Topic Maps construct. - */ - private static void _copyItemIdentifiers(IConstruct source, IConstruct target) { - for(Locator iid: source.getItemIdentifiers()) { - target.addSourceLocator(iid); - } - } - - /** - * Copies the associations from the <code>source</code> topic map to the - * <code>target</code> topic map. - * - * @param source The topic map to take the associations from. - * @param target The topic map which receives the associations. - * @param mergeMap The map which holds the merge mappings. - */ - @SuppressWarnings("unchecked") - private static void _copyAssociations(TopicMapImpl source, - TopicMapImpl target, Map<Topic, Topic> mergeMap) { - Set<Association> assocs = target.getAssociations(); - Map<String, Association> sigs = target.getCollectionFactory().createMap(assocs.size()); - for (Association assoc: assocs) { - sigs.put(SignatureGenerator.generateSignature(assoc), assoc); - } - Association existing = null; - for (Association assoc: source.getAssociations()) { - Association targetAssoc = target.createAssociation(); - _copyType((ITyped) assoc, (ITyped) targetAssoc, mergeMap); - _copyScope((IScoped) assoc, (IScoped) targetAssoc, mergeMap); - for (Iterator<AssociationRole> iter = assoc.getAssociationRoles().iterator(); iter.hasNext();) { - AssociationRole role = iter.next(); - AssociationRole targetRole = targetAssoc.createAssociationRole(role.getPlayer(), role.getType()); - _copyItemIdentifiers((IConstruct)role, (IConstruct)targetRole); - _copyReifier((IReifiable) role, (IReifiable) targetRole, mergeMap); - } - existing = sigs.get(SignatureGenerator.generateSignature(targetAssoc)); - if (existing != null) { - MergeUtils.moveRoleCharacteristics(targetAssoc, existing); - MergeUtils.removeConstruct((IConstruct) targetAssoc); - targetAssoc = existing; - } - _copyReifier((IReifiable) assoc, (IReifiable) targetAssoc, mergeMap); - _copyItemIdentifiers((IConstruct) assoc, (IConstruct) targetAssoc); - } - } - - /** - * Adds a mapping from <code>source</code> to <code>target</code> into the - * <code>mergeMap</code>. - * - * If <code>source</code> has already a mapping to another target topic, - * <code>target</code> is merged with the existing target topic. - * - * @param source The source topic. - * @param target The target topic. - * @param mergeMap The map which holds the merge mappings. - */ - private static void _addMerge(Topic source, Topic target, Map<Topic, Topic> mergeMap) { - Topic prevTarget = mergeMap.get(source); - if (prevTarget != null) { - if (!prevTarget.equals(target)) { - MergeUtils.merge(target, prevTarget); - } - } - else { - mergeMap.put(source, target); - } - } - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/DatatypeAwareConstruct.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,127 +0,0 @@ -/* - * 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 org.tmapi.core.Locator; -import org.tmapi.core.Topic; - -/** - * Implementation of {@link org.tinytim.IDatatypeAwareConstruct}. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -abstract class DatatypeAwareConstruct extends Scoped implements - IDatatypeAwareConstruct { - - private static final String _XSD_BASE = "http://www.w3.org/2001/XMLSchema#"; - private static final Locator STRING = new IRI(_XSD_BASE + "string"); - private static final Locator ANY_URI = new IRI(_XSD_BASE + "anyURI"); - - private String _value; - private Locator _resource; - - DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, String value, Collection<Topic> scope) { - super(topicMap, type, scope); - _value = value; - } - - DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, Locator value, Collection<Topic> scope) { - super(topicMap, type, scope); - _resource = value; - } - - /* (non-Javadoc) - * @see org.tinytim.IDatatypeAwareConstruct#getValue2() - */ - public String getValue2() { - if (_value != null) { - return _value; - } - return _resource != null ? _resource.getReference() : ""; - } - - /** - * Sets the value (xsd:string) of this construct. - * - * Sideeffect: The resource is set to null. - * - * @param value Sets the value of this construct. - */ - public void setValue(String value) { - _fireEvent(Event.SET_VALUE, _value, value); - _resource = null; - _value = value; - } - - /** - * Returns the value of this construct. - * - * @return The value or <code>null</code>. - */ - public String getValue() { - return _value; - } - - /** - * Returns the locator (xsd:anyURI value) of this construct. - * - * @return The locator or <code>null</code>. - */ - public Locator getResource() { - return _resource; - } - - /** - * Sets the value (xsd:anyURI) of this construct. - * - * Side effect: The string value (if any) is set to <code>null</code>. - * - * @param value The locator. - */ - public void setResource(Locator value) { - _fireEvent(Event.SET_LOCATOR, _resource, value); - _value = null; - _resource = value; - } - - /* (non-Javadoc) - * @see org.tinytim.IDatatypeAwareConstruct#getDatatype() - */ - public Locator getDatatype() { - if (_value != null || _resource == null) { - return STRING; - } - return ANY_URI; - } - - /* (non-Javadoc) - * @see org.tinytim.Construct#dispose() - */ - @Override - protected void dispose() { - _value = null; - _resource = null; - super.dispose(); - } -} Deleted: tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/DuplicateRemovalUtils.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,209 +0,0 @@ -/* - * 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); - } - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/Event.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/Event.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/Event.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,160 +0,0 @@ -/* - * 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; - -/** - * Event constants. - * - * All events are sent before a change happens. This allows to check - * some constraints. - * - * This class is not meant to be used outside of the tinyTiM package. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public enum Event { - - /** - * Notification that a topic should be added. - */ - ADD_TOPIC, - /** - * Notification that a topic should be removed. - */ - REMOVE_TOPIC, - /** - * Notification that an association should be added. - */ - ADD_ASSOCIATION, - /** - * Notification that an association should be removed. - */ - REMOVE_ASSOCIATION, - /** - * Notification that a role should be added. - */ - ADD_ROLE, - /** - * Notification that a role should be removed. - */ - REMOVE_ROLE, - /** - * Notification that an occurrence should be added. - */ - ADD_OCCURRENCE, - /** - * Notification that an occurrence should be removed. - */ - REMOVE_OCCURRENCE, - /** - * Notification that a name should be added. - */ - ADD_NAME, - /** - * Notification that a name should be removed. - */ - REMOVE_NAME, - /** - * Notification that a variant should be added. - */ - ADD_VARIANT, - /** - * Notification that a variant should be removed. - */ - REMOVE_VARIANT, - - /** - * Notification that a subject identifier should be added. - */ - ADD_SID, - /** - * Notification that a subject identifier should be removed. - */ - REMOVE_SID, - /** - * Notification that a subject locator should be added. - */ - ADD_SLO, - /** - * Notification that a subject locator should be removed. - */ - REMOVE_SLO, - /** - * Notification that an item identifier should be added. - */ - ADD_IID, - /** - * Notification that an item identifier should be removed. - */ - REMOVE_IID, - - /** - * Notification that a type should be added to a topic. - */ - ADD_TYPE, - /** - * Notification that a type should be removed from a topic. - */ - REMOVE_TYPE, - /** - * Notification that the type of a {@link ITyped} construct should be set. - */ - SET_TYPE, - - /** - * Notification that a theme should be added to a {@link IScoped} construct. - */ - ADD_THEME, - /** - * Notification that a theme should be removed from a - * {@link IScoped} construct. - */ - REMOVE_THEME, - - /** - * Notification that the value of a name, an occurrence or variant - * should be set. - */ - SET_VALUE, - - /** - * Notification that the player of a role should be set. - */ - SET_PLAYER, - - /** - * Notification that the reifier of a {@link IReifiable} construct - * should be set. - */ - SET_REIFIER, - - /** - * Notification that the "resource" of an occurrence or variant should be - * set. - */ - SET_LOCATOR, //TODO: Remove this once we have a TMDM-compatible version - - MOVE_OCCURRENCE, - MOVE_NAME, - MOVE_VARIANT - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/ICollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/ICollectionFactory.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/ICollectionFactory.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,72 +0,0 @@ -/* - * 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.Map; -import java.util.Set; - -/** - * Factory for collections. - * - * Implementations of this interface must provide a default constructor. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface ICollectionFactory { - - /** - * Creates a Set with the specified initial <code>size</code>. - * - * @param <E> - * @param size The initial capacity. - * @return - */ - <E> Set<E> createSet(int size); - - /** - * Creates a Set. - * - * @param <E> - * @return - */ - <E> Set<E> createSet(); - - /** - * Creates a Map. - * - * @param <K> - * @param <V> - * @return - */ - <K, V> Map<K, V> createMap(); - - /** - * Creates a Map with the specified initial <code>size</code>. - * - * @param <K> - * @param <V> - * @param size The initial capacity. - * @return - */ - <K, V> Map<K, V> createMap(int size); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/IConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IConstruct.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/IConstruct.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,66 +0,0 @@ -/* - * 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.Set; - -import org.tmapi.core.Locator; -import org.tmapi.core.TopicMapObject; - -/** - * The Topic Maps construct. - * - * This interface is not meant to be used outside of the tinyTiM package. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface IConstruct extends TopicMapObject { - - /** - * Returns the parent of the Topic Maps construct. - * - * @return The parent of a Topic Maps construct or <code>null</code>. - */ - public IConstruct getParent(); - - /** - * Returns the item identifiers of the Topic Maps construct. - * - * @return A (maybe empty) immutable Set of item identifiers. - */ - public Set<Locator> getItemIdentifiers(); - - /** - * Adds an item identifier to the Topic Maps construct. - * - * @param itemIdentifier The item identifier to add. - */ - public void addItemIdentifier(Locator itemIdentifier); - - /** - * Removes an item identifier from the Topic Maps construct. - * - * @param itemIdentifier The item identifier to remove. - */ - public void removeItemIdentifier(Locator itemIdentifier); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/IDatatypeAwareConstruct.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,54 +0,0 @@ -/* - * This is tinyTiM, a tiny Topic Maps engine. - * - * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ -package org.tinytim; - -import org.tmapi.core.Locator; - -/** - * Indicates that a Topic Maps construct has a value and a datatype. - * - * This interface is not meant to be used outside of the tinyTiM package. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface IDatatypeAwareConstruct extends IConstruct { - - /** - * The value of this Topic Maps construct. - * - * This method differs from TMAPI: This method MUST return the value OR the - * locator as string. This method should be removed if we have TMAPI 2.0 - * (maybe the whole interface should be removed). - * Currently, the {@link SignatureGenerator} needs it. - * - * @return The value. - */ - public String getValue2(); - - /** - * Returns the datatype of this Topic Maps construct. - * - * @return The datatype. - */ - public Locator getDatatype(); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/IEventHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IEventHandler.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/IEventHandler.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,47 +0,0 @@ -/* - * 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; - -/** - * Event handler that is able to handle Topic Maps events. - * - * This interface is not meant to be used outside of the tinyTiM package. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface IEventHandler { - - /** - * Callback method if a {@link IEventPublisher} sends an event to which - * this handler is subscribed to. - * - * @param evt The event. - * @param sender The sender of the event (this is not necessarily the - * publisher). - * @param oldValue The old value or <code>null</code> if the old value - * is not available or was <code>null</code>. - * @param newValue The new value or <code>null</code> if the new value - * is not available or should become <code>null</code>. - */ - public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue); - -} Deleted: tinytim/trunk/src/main/java/org/tinytim/IEventPublisher.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/IEventPublisher.java 2008-08-07 14:28:52 UTC (rev 102) +++ tinytim/trunk/src/main/java/org/tinytim/IEventPublisher.java 2008-08-07 14:36:54 UTC (rev 103) @@ -1,48 +0,0 @@ -/* - * 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; - -/** - * Publisher for Topic Maps events. - * - * This interface is not meant to be used outside of the tinyTiM package. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface IEventPublisher { - - /** - * Subscribes the handler for the specified event. - * - * @param event The event of interesst. - * @param handler The event handler. - */ - public void subscribe(Event event, IEventHandler handler); - - /** - * Removes the handler from the publisher. - * - * @param event The event. - * @param handler The event handler. - */ - public void unsubscribe(Event event, IEventHandler handler); -} Deleted: tinytim/trunk/src/main/java/org/tinytim/IMovable.java =================================================================== --- tinytim/trunk/src/main/java/org/t... [truncated message content] |
From: <lh...@us...> - 2008-08-08 12:10:39
|
Revision: 108 http://tinytim.svn.sourceforge.net/tinytim/?rev=108&view=rev Author: lheuer Date: 2008-08-08 12:10:45 +0000 (Fri, 08 Aug 2008) Log Message: ----------- - Signatures are Integers now (previously Strings) - Added Literal.get(..) to retrieve either an existing Lit. or null Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/core/IFactory.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/IdGenerator.java tinytim/trunk/src/main/java/org/tinytim/core/Literal.java tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-08 12:10:45 UTC (rev 108) @@ -176,7 +176,7 @@ */ private static void _copyCharacteristics(Topic topic, TopicImpl targetTopic, Map<Topic, Topic> mergeMap) { - Map<String, Reifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().createMap(); + Map<Integer, Reifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().createMap(); for (Occurrence occ: targetTopic.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), occ); } @@ -226,7 +226,7 @@ */ private static void _copyVariants(Name source, NameImpl target, Map<Topic, Topic> mergeMap) { - Map<String, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); + Map<Integer, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); for (Variant variant: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(variant), variant); } @@ -321,7 +321,7 @@ private static void _copyAssociations(TopicMap source, TopicMapImpl target, Map<Topic, Topic> mergeMap) { Set<Association> assocs = target.getAssociations(); - Map<String, Association> sigs = target.getCollectionFactory().createMap(assocs.size()); + Map<Integer, Association> sigs = target.getCollectionFactory().createMap(assocs.size()); for (Association assoc: assocs) { sigs.put(SignatureGenerator.generateSignature(assoc), assoc); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-08 12:10:45 UTC (rev 108) @@ -22,9 +22,9 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.Map; +import org.tinytim.utils.ICollectionFactory; import org.tmapi.core.Association; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; @@ -56,7 +56,7 @@ for (Topic topic: tm.getTopics()) { removeDuplicates(topic); } - Map<String, Association> sig2Assoc = tm.getCollectionFactory().createMap(); + Map<Integer, Association> sig2Assoc = tm.getCollectionFactory().createMap(); TypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); if (!typeInstanceIdx.isAutoUpdated()) { typeInstanceIdx.reindex(); @@ -64,13 +64,12 @@ for (Topic type: typeInstanceIdx.getAssociationTypes()) { _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(type)); } - _removeDuplicateAssociations(sig2Assoc, typeInstanceIdx.getAssociations(null)); } - private static void _removeDuplicateAssociations(Map<String, Association> sig2Assoc, Collection<Association> assocs) { + private static void _removeDuplicateAssociations(Map<Integer, Association> sig2Assoc, Collection<Association> assocs) { sig2Assoc.clear(); Association existing = null; - String sig = null; + Integer sig = null; for (Association assoc: assocs) { removeDuplicates(assoc); sig = SignatureGenerator.generateSignature(assoc); @@ -91,8 +90,9 @@ * @param topic The topic from which duplicates should be removed from. */ public static void removeDuplicates(Topic topic) { - _removeDuplicateOccurrences(topic.getOccurrences()); - _removeDuplicateNames(topic.getNames()); + ICollectionFactory collFactory = ((TopicMapImpl) topic.getTopicMap()).getCollectionFactory(); + _removeDuplicateOccurrences(topic.getOccurrences(), collFactory); + _removeDuplicateNames(topic.getNames(), collFactory); } /** @@ -101,9 +101,10 @@ * @param name The name from which the duplicates should be removed. */ public static void removeDuplicates(Name name) { - Map<String, Variant> sigs = new HashMap<String, Variant>(); + Map<Integer, Variant> sigs = ((TopicMapImpl) name.getTopicMap()).getCollectionFactory().createMap(); + Integer sig = null; for (Variant variant: new ArrayList<Variant>(name.getVariants())) { - String sig = SignatureGenerator.generateSignature(variant); + sig = SignatureGenerator.generateSignature(variant); Variant existing = sigs.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(variant, existing); @@ -120,11 +121,12 @@ * * @param occs */ - private static void _removeDuplicateOccurrences(Collection<Occurrence> occs) { - Map<String, Occurrence> sigs = new HashMap<String, Occurrence>(occs.size()); + private static void _removeDuplicateOccurrences(Collection<Occurrence> occs, ICollectionFactory collFactory) { + Map<Integer, Occurrence> sigs = collFactory.createMap(occs.size()); Occurrence existing = null; + Integer sig = null; for (Occurrence occ: new ArrayList<Occurrence>(occs)) { - String sig = SignatureGenerator.generateSignature(occ); + sig = SignatureGenerator.generateSignature(occ); existing = sigs.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(occ, existing); @@ -141,12 +143,13 @@ * * @param names */ - private static void _removeDuplicateNames(Collection<Name> names) { - Map<String, Name> sigs = new HashMap<String, Name>(names.size()); + private static void _removeDuplicateNames(Collection<Name> names, ICollectionFactory collFactory) { + Map<Integer, Name> sigs = collFactory.createMap(names.size()); Name existing = null; + Integer sig = null; for (Name name: new ArrayList<Name>(names)) { removeDuplicates(name); - String sig = SignatureGenerator.generateSignature(name); + sig = SignatureGenerator.generateSignature(name); existing = sigs.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(name, existing); @@ -165,9 +168,9 @@ * @param assoc The association to remove duplicate roles from. */ public static void removeDuplicates(Association assoc) { - Map<String, Role> sig2Role = ((TopicMapImpl) assoc.getTopicMap()).getCollectionFactory().createMap(); + Map<Integer, Role> sig2Role = ((TopicMapImpl) assoc.getTopicMap()).getCollectionFactory().createMap(); Role existing = null; - String sig = null; + Integer sig = null; for (Role role: new ArrayList<Role>(assoc.getRoles())) { sig = SignatureGenerator.generateSignature(role); existing = sig2Role.get(sig); Modified: tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java 2008-08-08 12:10:45 UTC (rev 108) @@ -31,7 +31,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface IFactory { Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteral.java 2008-08-08 12:10:45 UTC (rev 108) @@ -31,7 +31,7 @@ * This interface is not meant to be used outside of the tinyTiM package. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface ILiteral { Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILiteralAware.java 2008-08-08 12:10:45 UTC (rev 108) @@ -26,7 +26,7 @@ * This interface is not meant to be used outside of the tinyTiM package. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface ILiteralAware { Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-08-08 12:10:45 UTC (rev 108) @@ -28,7 +28,7 @@ * This interface is not meant to be used outside of the tinyTiM package. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface ILocator extends ILiteral, Locator { Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-08 12:10:45 UTC (rev 108) @@ -26,7 +26,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class IdGenerator { Modified: tinytim/trunk/src/main/java/org/tinytim/core/Literal.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-08 12:10:45 UTC (rev 108) @@ -37,7 +37,7 @@ * This class is not meant to be used outside of the tinyTiM package. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class Literal implements ILiteral { @@ -49,6 +49,9 @@ private final Locator _datatype; private Literal(final String value, final Locator datatype) { + if (value == null) { + throw new IllegalArgumentException("The value must not be null"); + } _value = value; _datatype = datatype; } @@ -61,6 +64,34 @@ return _value; } + public static synchronized ILiteral get(String value) { + return _STRINGS.get(new Literal(value, XSD.STRING)); + } + + public static synchronized ILiteral getIRI(String value) { + if (value == null) { + throw new IllegalArgumentException("The value must not be null"); + } + return _IRIS.get(new IRI(value)); + } + + public static synchronized ILiteral get(String value, Locator datatype) { + if (value == null) { + throw new IllegalArgumentException("The value must not be null"); + } + if (datatype == null) { + throw new IllegalArgumentException("The datatype must not be null"); + } + if (XSD.ANY_URI.equals(datatype)) { + return getIRI(value); + } + if (XSD.STRING.equals(datatype)) { + return get(value); + } + return _LITERALS.get(new Literal(value, datatype)); + + } + public static synchronized ILiteral create(final String value, final Locator datatype) { if (value == null) { throw new IllegalArgumentException("The value must not be null"); @@ -84,9 +115,6 @@ } public static synchronized ILiteral create(String value) { - if (value == null) { - throw new IllegalArgumentException("The value must not be null"); - } ILiteral literal = new Literal(value, XSD.STRING); ILiteral existing = _STRINGS.get(literal); if (existing != null) { Modified: tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-08 12:10:45 UTC (rev 108) @@ -121,7 +121,7 @@ for(Topic type: source.getTypes()) { target.addType(type); } - Map<String, Reifiable> sigs = ((TopicMapImpl) source.getTopicMap()).getCollectionFactory().createMap(); + Map<Integer, Reifiable> sigs = ((TopicMapImpl) source.getTopicMap()).getCollectionFactory().createMap(); for (Occurrence occ: target.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), occ); } @@ -177,7 +177,7 @@ * @param target The association which takes the role characteristics. */ static void moveRoleCharacteristics(Association source, Association target) { - Map<String, Role> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().<String, Role>createMap(); + Map<Integer, Role> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); for (Role role: target.getRoles()) { sigs.put(SignatureGenerator.generateSignature(role), role); } @@ -196,7 +196,7 @@ */ @SuppressWarnings("unchecked") static void moveVariants(Name source, Name target) { - Map<String, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().<String, Variant>createMap(); + Map<Integer, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); for (Variant var: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(var), var); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java 2008-08-08 12:10:45 UTC (rev 108) @@ -21,6 +21,7 @@ package org.tinytim.core; import java.util.Arrays; +import java.util.Collection; import java.util.Set; import org.tmapi.core.Association; @@ -61,24 +62,23 @@ * @param assoc The association to generate the signature for. * @return The association's signature. */ - public static String generateSignature(Association assoc) { - StringBuilder sb = new StringBuilder(); - sb.append(_generateTypeSignature(assoc)) - .append('s') - .append(_generateScopeSignature(assoc)) - .append('.'); - Set<Role> roles = assoc.getRoles(); - String[] roleSigs = new String[roles.size()]; + public static int generateSignature(Association assoc) { + return Arrays.hashCode(new int[] {_generateTypeSignature(assoc), + _generateScopeSignature(assoc), + _generateRolesSignature(assoc.getRoles())}); + } + + private static int _generateRolesSignature(final Collection<Role> roles) { + if (roles.isEmpty()) { + return 0; + } + int[] ids = new int[roles.size()]; int i = 0; for (Role role : roles) { - roleSigs[i++] = generateSignature(role); + ids[i++] = generateSignature(role); } - Arrays.sort(roleSigs); - for (String sig : roleSigs) { - sb.append(sig) - .append('.'); - } - return sb.toString(); + Arrays.sort(ids); + return Arrays.hashCode(ids); } /** @@ -87,12 +87,10 @@ * @param role The role to generate the signature for. * @return The role's signature. */ - public static String generateSignature(Role role) { - StringBuilder sb = new StringBuilder(); - sb.append(_generateTypeSignature(role)) - .append('p') - .append(role.getPlayer() == null ? "" : role.getPlayer().getId()); - return sb.toString(); + public static int generateSignature(final Role role) { + return Arrays.hashCode(new int[] { + _signature(role.getType()), _signature(role.getPlayer()) + }); } /** @@ -101,14 +99,12 @@ * @param occ The occurrence to create the signature for. * @return The signature of the occurrence. */ - public static String generateSignature(Occurrence occ) { - StringBuilder sb = new StringBuilder(); - sb.append(_generateTypeSignature(occ)) - .append('s') - .append(_generateScopeSignature(occ)) - .append('v') - .append(_generateDataSignature((ILiteralAware) occ)); - return sb.toString(); + public static int generateSignature(final Occurrence occ) { + return Arrays.hashCode(new int[] { + _generateTypeSignature(occ), + _generateScopeSignature(occ), + _generateDataSignature((ILiteralAware)occ) + }); } /** @@ -119,14 +115,12 @@ * @param name The name to generate the signature for. * @return A signature for the name. */ - public static String generateSignature(Name name) { - StringBuilder sb = new StringBuilder(); - sb.append(_generateTypeSignature(name)) - .append('s') - .append(_generateScopeSignature(name)) - .append('v') - .append(_generateDataSignature((ILiteralAware) name)); - return sb.toString(); + public static int generateSignature(final Name name) { + return Arrays.hashCode(new int[] { + _generateTypeSignature(name), + _generateScopeSignature(name), + _generateDataSignature((ILiteralAware)name) + }); } /** @@ -135,12 +129,11 @@ * @param variant The variant to generate the signature for. * @return A signature for the variant. */ - public static String generateSignature(Variant variant) { - StringBuilder sb = new StringBuilder(); - sb.append(_generateScopeSignature(variant)) - .append('v') - .append(_generateDataSignature((ILiteralAware)variant)); - return sb.toString(); + public static int generateSignature(final Variant variant) { + return Arrays.hashCode(new int[] { + _generateScopeSignature(variant), + _generateDataSignature((ILiteralAware)variant) + }); } /** @@ -149,7 +142,7 @@ * @param construct An occurrence or variant. * @return The signature. */ - private static int _generateDataSignature(ILiteralAware construct) { + private static int _generateDataSignature(final ILiteralAware construct) { return System.identityHashCode(construct.getLiteral()); } @@ -159,9 +152,8 @@ * @param typed The typed Topic Maps construct. * @return The signature. */ - private static String _generateTypeSignature(Typed typed) { - Topic type = typed.getType(); - return type == null ? "" : type.getId(); + private static int _generateTypeSignature(final Typed typed) { + return _signature(typed.getType()); } /** @@ -173,23 +165,22 @@ * @param scoped The scoped Topic Maps construct. * @return The signature. */ - private static String _generateScopeSignature(Scoped scoped) { + private static int _generateScopeSignature(final Scoped scoped) { Set<Topic> scope = scoped.getScope(); if (scope.isEmpty()) { - return ""; + return 0; } - String[] ids = new String[scope.size()]; + int[] ids = new int[scope.size()]; int i = 0; for (Topic topic : scope) { - ids[i++] = topic.getId(); + ids[i++] = _signature(topic); } Arrays.sort(ids); - StringBuilder sb = new StringBuilder(); - for (String id : ids) { - sb.append(id) - .append('.'); - } - return sb.toString(); + return Arrays.hashCode(ids); } + private static int _signature(Topic topic) { + return System.identityHashCode(topic); + } + } Modified: tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/index/LiteralIndexImpl.java 2008-08-08 12:10:45 UTC (rev 108) @@ -45,7 +45,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public class LiteralIndexImpl extends AbstractIndex implements LiteralIndex { @@ -73,10 +73,13 @@ * @see org.tmapi.index.LiteralIndex#getNames(java.lang.String) */ public Collection<Name> getNames(String value) { - return _getNames(Literal.create(value)); + return _getNames(Literal.get(value)); } private Collection<Name> _getNames(ILiteral literal) { + if (literal == null) { + return Collections.<Name>emptySet(); + } Collection<Name> names = _lit2Names.get(literal); return names == null ? Collections.<Name>emptySet() : new ArrayList<Name>(names); @@ -86,24 +89,30 @@ * @see org.tmapi.index.LiteralIndex#getOccurrences(java.lang.String) */ public Collection<Occurrence> getOccurrences(String value) { - return _getOccurrences(Literal.create(value)); + return _getOccurrences(Literal.get(value)); } /* (non-Javadoc) * @see org.tmapi.index.LiteralIndex#getOccurrences(org.tmapi.core.Locator) */ public Collection<Occurrence> getOccurrences(Locator value) { - return _getOccurrences(Literal.create(value)); + if (value == null) { + throw new IllegalArgumentException("The value must not be null"); + } + return _getOccurrences((ILiteral) value); } /* (non-Javadoc) * @see org.tmapi.index.LiteralIndex#getOccurrences(java.lang.String, org.tmapi.core.Locator) */ public Collection<Occurrence> getOccurrences(String value, Locator datatype) { - return _getOccurrences(Literal.create(value, datatype)); + return _getOccurrences(Literal.get(value, datatype)); } private Collection<Occurrence> _getOccurrences(ILiteral literal) { + if (literal == null) { + return Collections.<Occurrence>emptySet(); + } Collection<Occurrence> occs = _lit2Occs.get(literal); return occs == null ? Collections.<Occurrence>emptySet() : new ArrayList<Occurrence>(occs); @@ -113,24 +122,30 @@ * @see org.tmapi.index.LiteralIndex#getVariants(java.lang.String) */ public Collection<Variant> getVariants(String value) { - return _getVariants(Literal.create(value)); + return _getVariants(Literal.get(value)); } /* (non-Javadoc) * @see org.tmapi.index.LiteralIndex#getVariants(org.tmapi.core.Locator) */ public Collection<Variant> getVariants(Locator value) { - return _getVariants(Literal.create(value)); + if (value == null) { + throw new IllegalArgumentException("The value must not be null"); + } + return _getVariants((ILiteral) value); } /* (non-Javadoc) * @see org.tmapi.index.LiteralIndex#getVariants(java.lang.String, org.tmapi.core.Locator) */ public Collection<Variant> getVariants(String value, Locator datatype) { - return _getVariants(Literal.create(value, datatype)); + return _getVariants(Literal.get(value, datatype)); } private Collection<Variant> _getVariants(ILiteral literal) { + if (literal == null) { + return Collections.<Variant>emptySet(); + } Collection<Variant> variants = _lit2Variants.get(literal); return variants == null ? Collections.<Variant>emptySet() : new ArrayList<Variant>(variants); Modified: tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/voc/Vocabulary.java 2008-08-08 12:10:45 UTC (rev 108) @@ -27,7 +27,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ abstract class Vocabulary { Modified: tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java 2008-08-07 15:08:28 UTC (rev 107) +++ tinytim/trunk/src/main/java/org/tinytim/voc/XSD.java 2008-08-08 12:10:45 UTC (rev 108) @@ -26,7 +26,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class XSD extends Vocabulary { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-11 12:19:04
|
Revision: 111 http://tinytim.svn.sourceforge.net/tinytim/?rev=111&view=rev Author: lheuer Date: 2008-08-11 12:18:58 +0000 (Mon, 11 Aug 2008) Log Message: ----------- - Introduced Scope as first class object - Introduced a constructor which takes a TopicMapImpl for association, role etc. - Removed CollectionFactory from the TopicMapImpl and TopicMapSystemFactoryImpl - Added a static CollectionFactory - Various modifications 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/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/core/Event.java tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java tinytim/trunk/src/main/java/org/tinytim/core/ILocator.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/Literal.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/TopicMapImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemImpl.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/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/utils/ICollectionFactory.java Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java tinytim/trunk/src/main/java/org/tinytim/core/IScope.java tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java tinytim/trunk/src/main/java/org/tinytim/core/JavaCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/core/TroveCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/Property.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -21,7 +21,6 @@ package org.tinytim.core; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Set; @@ -40,7 +39,12 @@ private Set<Role> _roles; - AssociationImpl(TopicMapImpl topicMap, Topic type, Collection<Topic> scope) { + AssociationImpl(TopicMapImpl tm) { + super(tm); + _roles = _makeSet(2); + } + + AssociationImpl(TopicMapImpl topicMap, Topic type, IScope scope) { super(topicMap, type, scope); _roles = _makeSet(2); } @@ -142,6 +146,14 @@ } /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#isAssociation() + */ + @Override + public final boolean isAssociation() { + return true; + } + + /* (non-Javadoc) * @see org.tmapi.core.TopicMapObject#remove() */ public void remove() { Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.Set; +import org.tinytim.utils.CollectionFactory; import org.tmapi.core.Construct; import org.tmapi.core.Locator; import org.tmapi.core.TopicMap; @@ -33,7 +34,7 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -abstract class ConstructImpl implements Construct { +abstract class ConstructImpl implements IConstruct { protected String _id; protected TopicMapImpl _tm; @@ -45,11 +46,11 @@ } protected <E> Set<E> _makeSet() { - return _tm.getCollectionFactory().createIdentitySet(); + return CollectionFactory.createIdentitySet(); } protected <E> Set<E> _makeSet(int size) { - return _tm.getCollectionFactory().createIdentitySet(size); + return CollectionFactory.createIdentitySet(size); } /* (non-Javadoc) @@ -135,7 +136,7 @@ * @param newValue The new value. */ protected void _fireEvent(Event evt, Object oldValue, Object newValue) { - if (_tm != null) { + if (_tm != null && _parent != null) { _tm.handleEvent(evt, this, oldValue, newValue); } } @@ -153,6 +154,55 @@ } /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isAssociation() + */ + public boolean isAssociation() { + return false; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isName() + */ + public boolean isName() { + return false; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isOccurrence() + */ + public boolean isOccurrence() { + return false; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isRole() + */ + public boolean isRole() { + return false; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isTopic() + */ + public boolean isTopic() { + return false; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isTopicMap() + */ + public boolean isTopicMap() { + return false; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IConstruct#isVariant() + */ + public boolean isVariant() { + return false; + } + + /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-11 12:18:58 UTC (rev 111) @@ -23,6 +23,9 @@ import java.util.Map; import java.util.Set; +import org.tinytim.utils.CollectionFactory; +import org.tinytim.utils.IIntObjectMap; +import org.tinytim.utils.IntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Construct; import org.tmapi.core.Locator; @@ -66,7 +69,7 @@ if (source == target) { return; } - Map<Topic, Topic> mergeMap = target.getCollectionFactory().createIdentityMap(); + Map<Topic, Topic> mergeMap = CollectionFactory.createIdentityMap(); Topic existing = null; Construct existingConstruct = null; for (Topic topic: source.getTopics()) { @@ -176,7 +179,7 @@ */ private static void _copyCharacteristics(Topic topic, TopicImpl targetTopic, Map<Topic, Topic> mergeMap) { - Map<Integer, Reifiable> sigs = ((TopicMapImpl) targetTopic.getTopicMap()).getCollectionFactory().createMap(); + IIntObjectMap<Reifiable> sigs = IntObjectMap.create(); for (Occurrence occ: targetTopic.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), occ); } @@ -226,7 +229,7 @@ */ private static void _copyVariants(Name source, NameImpl target, Map<Topic, Topic> mergeMap) { - Map<Integer, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); + IIntObjectMap<Variant> sigs = IntObjectMap.create(); for (Variant variant: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(variant), variant); } @@ -288,7 +291,7 @@ */ private static Set<Topic>_copyScope(Scoped source, TopicMap tm, Map<Topic, Topic> mergeMap) { - Set<Topic> themes = ((TopicMapImpl) tm).getCollectionFactory().createIdentitySet(source.getScope().size()); + Set<Topic> themes = CollectionFactory.createIdentitySet(source.getScope().size()); Topic theme = null; for (Topic sourceTheme: source.getScope()) { theme = mergeMap.containsKey(sourceTheme) ? mergeMap.get(sourceTheme) @@ -321,7 +324,7 @@ private static void _copyAssociations(TopicMap source, TopicMapImpl target, Map<Topic, Topic> mergeMap) { Set<Association> assocs = target.getAssociations(); - Map<Integer, Association> sigs = target.getCollectionFactory().createMap(assocs.size()); + IIntObjectMap<Association> sigs = IntObjectMap.create(assocs.size()); for (Association assoc: assocs) { sigs.put(SignatureGenerator.generateSignature(assoc), assoc); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/DatatypeAwareConstruct.java 2008-08-11 12:18:58 UTC (rev 111) @@ -22,7 +22,6 @@ import java.math.BigDecimal; import java.math.BigInteger; -import java.util.Collection; import org.tinytim.voc.XSD; import org.tmapi.core.DatatypeAware; @@ -40,7 +39,11 @@ private ILiteral _literal; - DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, ILiteral literal, Collection<Topic> scope) { + DatatypeAwareConstruct(TopicMapImpl tm) { + super(tm); + } + + DatatypeAwareConstruct(TopicMapImpl topicMap, Topic type, ILiteral literal, IScope scope) { super(topicMap, type, scope); _literal = literal; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-11 12:18:58 UTC (rev 111) @@ -22,9 +22,9 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Map; -import org.tinytim.utils.ICollectionFactory; +import org.tinytim.utils.IIntObjectMap; +import org.tinytim.utils.IntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; @@ -56,7 +56,7 @@ for (Topic topic: tm.getTopics()) { removeDuplicates(topic); } - Map<Integer, Association> sig2Assoc = tm.getCollectionFactory().createMap(); + IIntObjectMap<Association> sig2Assoc = IntObjectMap.create(); TypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); if (!typeInstanceIdx.isAutoUpdated()) { typeInstanceIdx.reindex(); @@ -66,13 +66,12 @@ } } - private static void _removeDuplicateAssociations(Map<Integer, Association> sig2Assoc, Collection<Association> assocs) { + private static void _removeDuplicateAssociations(IIntObjectMap<Association> sig2Assoc, Collection<Association> assocs) { sig2Assoc.clear(); Association existing = null; - Integer sig = null; for (Association assoc: assocs) { removeDuplicates(assoc); - sig = SignatureGenerator.generateSignature(assoc); + int sig = SignatureGenerator.generateSignature(assoc); existing = sig2Assoc.get(sig); if (existing != null) { MergeUtils.moveRoleCharacteristics(assoc, existing); @@ -90,9 +89,8 @@ * @param topic The topic from which duplicates should be removed from. */ public static void removeDuplicates(Topic topic) { - ICollectionFactory collFactory = ((TopicMapImpl) topic.getTopicMap()).getCollectionFactory(); - _removeDuplicateOccurrences(topic.getOccurrences(), collFactory); - _removeDuplicateNames(topic.getNames(), collFactory); + _removeDuplicateOccurrences(topic.getOccurrences()); + _removeDuplicateNames(topic.getNames()); } /** @@ -101,10 +99,9 @@ * @param name The name from which the duplicates should be removed. */ public static void removeDuplicates(Name name) { - Map<Integer, Variant> sigs = ((TopicMapImpl) name.getTopicMap()).getCollectionFactory().createMap(); - Integer sig = null; + IIntObjectMap<Variant> sigs = IntObjectMap.create(); for (Variant variant: new ArrayList<Variant>(name.getVariants())) { - sig = SignatureGenerator.generateSignature(variant); + int sig = SignatureGenerator.generateSignature(variant); Variant existing = sigs.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(variant, existing); @@ -121,12 +118,11 @@ * * @param occs */ - private static void _removeDuplicateOccurrences(Collection<Occurrence> occs, ICollectionFactory collFactory) { - Map<Integer, Occurrence> sigs = collFactory.createMap(occs.size()); + private static void _removeDuplicateOccurrences(Collection<Occurrence> occs) { + IIntObjectMap<Occurrence> sigs = IntObjectMap.create(occs.size()); Occurrence existing = null; - Integer sig = null; for (Occurrence occ: new ArrayList<Occurrence>(occs)) { - sig = SignatureGenerator.generateSignature(occ); + int sig = SignatureGenerator.generateSignature(occ); existing = sigs.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(occ, existing); @@ -143,13 +139,12 @@ * * @param names */ - private static void _removeDuplicateNames(Collection<Name> names, ICollectionFactory collFactory) { - Map<Integer, Name> sigs = collFactory.createMap(names.size()); + private static void _removeDuplicateNames(Collection<Name> names) { + IIntObjectMap<Name> sigs = IntObjectMap.create(names.size()); Name existing = null; - Integer sig = null; for (Name name: new ArrayList<Name>(names)) { removeDuplicates(name); - sig = SignatureGenerator.generateSignature(name); + int sig = SignatureGenerator.generateSignature(name); existing = sigs.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(name, existing); @@ -168,11 +163,10 @@ * @param assoc The association to remove duplicate roles from. */ public static void removeDuplicates(Association assoc) { - Map<Integer, Role> sig2Role = ((TopicMapImpl) assoc.getTopicMap()).getCollectionFactory().createMap(); + IIntObjectMap<Role> sig2Role = IntObjectMap.create(); Role existing = null; - Integer sig = null; for (Role role: new ArrayList<Role>(assoc.getRoles())) { - sig = SignatureGenerator.generateSignature(role); + int sig = SignatureGenerator.generateSignature(role); existing = sig2Role.get(sig); if (existing != null) { MergeUtils.handleExistingConstruct(role, existing); Modified: tinytim/trunk/src/main/java/org/tinytim/core/Event.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/Event.java 2008-08-11 12:18:58 UTC (rev 111) @@ -121,14 +121,9 @@ SET_TYPE, /** - * Notification that a theme should be added to a {@link IScoped} construct. + * Notification that the scope is changed. */ - ADD_THEME, - /** - * Notification that a theme should be removed from a - * {@link IScoped} construct. - */ - REMOVE_THEME, + SET_SCOPE, /** * Notification that the player of a role should be set. Added: tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-08-11 12:18:58 UTC (rev 111) @@ -0,0 +1,41 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.core; + +import org.tmapi.core.Construct; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IConstruct extends Construct { + + public boolean isTopicMap(); + public boolean isTopic(); + public boolean isAssociation(); + public boolean isRole(); + public boolean isOccurrence(); + public boolean isName(); + public boolean isVariant(); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Modified: tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/IEventHandler.java 2008-08-11 12:18:58 UTC (rev 111) @@ -20,8 +20,6 @@ */ package org.tinytim.core; -import org.tmapi.core.Construct; - /** * Event handler that is able to handle Topic Maps events. * @@ -44,6 +42,6 @@ * @param newValue The new value or <code>null</code> if the new value * is not available or should become <code>null</code>. */ - public void handleEvent(Event evt, Construct sender, Object oldValue, Object newValue); + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue); } Deleted: tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/IFactory.java 2008-08-11 12:18:58 UTC (rev 111) @@ -1,48 +0,0 @@ -/* - * 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 org.tmapi.core.Association; -import org.tmapi.core.Name; -import org.tmapi.core.Occurrence; -import org.tmapi.core.Role; -import org.tmapi.core.Topic; -import org.tmapi.core.Variant; - -/** - * - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -public interface IFactory { - - public Association createAssociation(); - - public Role createRole(Association parent); - - public Occurrence createOccurrence(Topic parent); - - public Name createName(Topic parent); - - public Variant createVariant(Name parent); - -} Modified: tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/ILocator.java 2008-08-11 12:18:58 UTC (rev 111) @@ -23,8 +23,9 @@ import org.tmapi.core.Locator; /** + * Marker interface which unifies the {@link org.tmapi.core.Locator} and + * tinyTiM's {@link ILiteral}. * - * * This interface is not meant to be used outside of the tinyTiM package. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> Added: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScope.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-08-11 12:18:58 UTC (rev 111) @@ -0,0 +1,49 @@ +/* + * 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.util.Set; + +import org.tmapi.core.Topic; + +/** + * Represents an immutable set of {@link org.tmapi.core.Topic}s. + * + * This interface is not meant to be used outside of the tinyTiM package. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IScope extends Iterable<Topic> { + + public Set<Topic> asSet(); + + public boolean contains(Topic theme); + + public IScope add(Topic theme); + + public IScope remove(Topic theme); + + public boolean isUnconstrained(); + + public int size(); + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-08-11 12:18:58 UTC (rev 111) @@ -0,0 +1,36 @@ +/* + * 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 org.tmapi.core.Scoped; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IScoped extends Scoped, IConstruct { + + public IScope getScopeObject(); + + public void setScopeObject(IScope scope); +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/IScoped.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-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-11 12:18:58 UTC (rev 111) @@ -31,13 +31,8 @@ final class IdGenerator { private static final AtomicLong _COUNTER = new AtomicLong(); - private static final IdGenerator _INSTANCE = new IdGenerator(); - public static IdGenerator getInstance() { - return _INSTANCE; - } - - public long nextId() { + public static long nextId() { return _COUNTER.getAndIncrement(); } } Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdentityManager.java 2008-08-11 12:18:58 UTC (rev 111) @@ -22,7 +22,7 @@ import java.util.Map; -import org.tinytim.utils.ICollectionFactory; +import org.tinytim.utils.CollectionFactory; import org.tmapi.core.Construct; import org.tmapi.core.IdentityConstraintException; import org.tmapi.core.Locator; @@ -41,15 +41,14 @@ private Map<Locator, Topic> _sid2Topic; private Map<Locator, Topic> _slo2Topic; - private Map<Locator, Construct> _iid2Construct; - private Map<String, Construct> _id2Construct; + private Map<Locator, IConstruct> _iid2Construct; + private Map<String, IConstruct> _id2Construct; IdentityManager(TopicMapImpl tm) { - ICollectionFactory collFactory = tm.getCollectionFactory(); - _id2Construct = collFactory.createIdentityMap(); - _sid2Topic = collFactory.createIdentityMap(); - _slo2Topic = collFactory.createIdentityMap(); - _iid2Construct = collFactory.createIdentityMap(); + _id2Construct = CollectionFactory.createIdentityMap(); + _sid2Topic = CollectionFactory.createIdentityMap(); + _slo2Topic = CollectionFactory.createIdentityMap(); + _iid2Construct = CollectionFactory.createIdentityMap(); _subscribe(tm); _register(tm); } @@ -95,10 +94,10 @@ * * @param construct The construct to register. */ - private void _register(Construct construct) { + private void _register(IConstruct construct) { ConstructImpl c = (ConstructImpl) construct; if (c._id == null) { - String id = "" + IdGenerator.getInstance().nextId(); + String id = "" + IdGenerator.nextId(); c._id = id.intern(); } if (!_id2Construct.containsKey(c._id)) { @@ -163,16 +162,16 @@ } private class TopicMapsConstructAddHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { - _register((ConstructImpl)newValue); + _register((IConstruct)newValue); } } private class TopicMapsConstructRemoveHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { - _unregister((ConstructImpl)oldValue); + _unregister((IConstruct)oldValue); } } @@ -181,19 +180,19 @@ * item identifier to the index. */ private class AddItemIdentifierHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { Locator iid = (Locator) newValue; - Construct existing = _iid2Construct.get(iid); + IConstruct existing = _iid2Construct.get(iid); if (existing != null) { if (existing != sender) { - if (sender instanceof Topic && existing instanceof Topic) { + if (sender.isTopic() && existing.isTopic()) { throw new IdentityConstraintException((Topic) sender, (Topic) existing, iid, "A topic with the same item identifier '" + iid.getReference() + "' exists"); } throw new IdentityConstraintException(sender, existing, iid, "A Topic Maps construct with the same item identifier '" + iid.getReference() + "' exists"); } } - if (sender instanceof Topic) { + if (sender.isTopic()) { Topic existingTopic = _sid2Topic.get(iid); if (existingTopic != null && existingTopic != sender) { throw new IdentityConstraintException((Topic) sender, existingTopic, iid, "A topic with a subject identifier equals to the item identifier '" + iid.getReference() + "' exists"); @@ -207,7 +206,7 @@ * Removes an item identifier and its Topic Maps constructs from the index. */ private class RemoveItemIdentifierHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { _iid2Construct.remove(oldValue); } @@ -218,16 +217,16 @@ * subject identifier to the index. */ private class AddSubjectIdentifierHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { Topic topic = (Topic) sender; Locator sid = (Locator) newValue; - Construct existing = _sid2Topic.get(sid); + IConstruct existing = (IConstruct) _sid2Topic.get(sid); if (existing != null && existing != topic) { throw new IdentityConstraintException(topic, (Topic) existing, sid, "A topic with the same subject identifier '" + sid.getReference() + "' exists"); } existing = _iid2Construct.get(sid); - if (existing != null && existing instanceof Topic && existing != topic) { + if (existing != null && existing.isTopic() && existing != topic) { throw new IdentityConstraintException(topic, (Topic) existing, sid, "A topic with an item identifier equals to the subject identifier '" + sid.getReference() + "' exists"); } _sid2Topic.put(sid, topic); @@ -238,7 +237,7 @@ * Removes a subject identifier and its topic from the index. */ private class RemoveSubjectIdentifierHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { _sid2Topic.remove(oldValue); } @@ -249,7 +248,7 @@ * subject locator to the index. */ private class AddSubjectLocatorHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { Topic topic = (Topic) sender; Locator slo = (Locator) newValue; @@ -265,7 +264,7 @@ * Removes a subject locator and its topic from the index. */ private class RemoveSubjectLocatorHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { _slo2Topic.remove(oldValue); } @@ -275,7 +274,7 @@ * Checks if setting the reifier is allowed. */ private static class ReifierConstraintHandler implements IEventHandler { - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { if (newValue == null) { return; Deleted: tinytim/trunk/src/main/java/org/tinytim/core/JavaCollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/JavaCollectionFactory.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/JavaCollectionFactory.java 2008-08-11 12:18:58 UTC (rev 111) @@ -1,161 +0,0 @@ -/* - * 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.util.AbstractSet; -import java.util.HashMap; -import java.util.HashSet; -import java.util.IdentityHashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.tinytim.utils.ICollectionFactory; - -/** - * {@link ICollectionFactory} which uses the standard Java collections. - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev$ - $Date$ - */ -final class JavaCollectionFactory implements ICollectionFactory { - - /* (non-Javadoc) - * @see org.tinytim.ICollectionFactory#createMap(int) - */ - public <K, V> Map<K, V> createMap(int size) { - return new HashMap<K, V>(size); - } - - /* (non-Javadoc) - * @see org.tinytim.ICollectionFactory#createMap() - */ - public <K, V> Map<K, V> createMap() { - return new HashMap<K, V>(); - } - - /* (non-Javadoc) - * @see org.tinytim.core.ICollectionFactory#createIdentityMap() - */ - public <K, V> Map<K, V> createIdentityMap() { - return new IdentityHashMap<K,V>(); - } - - /* (non-Javadoc) - * @see org.tinytim.core.ICollectionFactory#createIdentityMap(int) - */ - public <K, V> Map<K, V> createIdentityMap(int size) { - return new IdentityHashMap<K,V>(size); - } - - /* (non-Javadoc) - * @see org.tinytim.ICollectionFactory#createSet(int) - */ - public <E> Set<E> createSet(int size) { - return new HashSet<E>(size); - } - - /* (non-Javadoc) - * @see org.tinytim.ICollectionFactory#createSet() - */ - public <E> Set<E> createSet() { - return new HashSet<E>(); - } - - /* (non-Javadoc) - * @see org.tinytim.core.ICollectionFactory#createIdentitySet() - */ - public <E> Set<E> createIdentitySet() { - return new IdentityHashSet<E>(); - } - - /* (non-Javadoc) - * @see org.tinytim.core.ICollectionFactory#createIdentitySet(int) - */ - public <E> Set<E> createIdentitySet(int size) { - return new IdentityHashSet<E>(size); - } - - /** - * {@link java.util.Set} implementation that compares its elements by - * identity. - */ - private static class IdentityHashSet<E> extends AbstractSet<E> { - - private final Map<E, Boolean> _map; - - public IdentityHashSet() { - _map = new IdentityHashMap<E, Boolean>(); - } - - public IdentityHashSet(int size) { - _map = new IdentityHashMap<E, Boolean>(size); - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#add(java.lang.Object) - */ - @Override - public boolean add(E obj) { - return _map.put(obj, Boolean.TRUE) == null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#remove(java.lang.Object) - */ - @Override - public boolean remove(Object obj) { - return _map.remove(obj) != null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#contains(java.lang.Object) - */ - @Override - public boolean contains(Object obj) { - return _map.containsKey(obj); - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#iterator() - */ - @Override - public Iterator<E> iterator() { - return _map.keySet().iterator(); - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#size() - */ - @Override - public int size() { - return _map.size(); - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#clear() - */ - @Override - public void clear() { - _map.clear(); - } - } -} Modified: tinytim/trunk/src/main/java/org/tinytim/core/Literal.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/Literal.java 2008-08-11 12:18:58 UTC (rev 111) @@ -20,14 +20,10 @@ */ package org.tinytim.core; -import java.lang.ref.WeakReference; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.AbstractSet; -import java.util.Iterator; -import java.util.Map; -import java.util.WeakHashMap; +import org.tinytim.utils.WeakObjectRegistry; import org.tinytim.voc.XSD; import org.tmapi.core.Locator; @@ -210,77 +206,4 @@ && this._datatype.equals(other._datatype); } - - private static class WeakObjectRegistry<E> extends AbstractSet<E> { - - private final Map<E, WeakReference<E>> _obj2Ref; - - public WeakObjectRegistry() { - super(); - _obj2Ref = new WeakHashMap<E, WeakReference<E>>(); - } - - /** - * - * - * @param key - * @return - */ - public E get(Object key) { - WeakReference<E> weakRef = _obj2Ref.get(key); - return weakRef != null ? weakRef.get() : null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#add(java.lang.Object) - */ - @Override - public boolean add(E obj) { - WeakReference<E> ref = new WeakReference<E>(obj); - ref = _obj2Ref.put(obj, ref); - return ref != null && ref.get() != null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#remove(java.lang.Object) - */ - @Override - public boolean remove(Object obj) { - WeakReference<E> ref = _obj2Ref.remove(obj); - return ref != null && ref.get() != null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#clear() - */ - @Override - public void clear() { - _obj2Ref.clear(); - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#contains(java.lang.Object) - */ - @Override - public boolean contains(Object obj) { - return get(obj) != null; - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#iterator() - */ - @Override - public Iterator<E> iterator() { - return _obj2Ref.keySet().iterator(); - } - - /* (non-Javadoc) - * @see java.util.AbstractCollection#size() - */ - @Override - public int size() { - return _obj2Ref.size(); - } - } - } Modified: tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-11 12:18:58 UTC (rev 111) @@ -23,9 +23,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Map; import org.tinytim.index.IIndexManager; +import org.tinytim.utils.IIntObjectMap; +import org.tinytim.utils.IntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Construct; import org.tmapi.core.Locator; @@ -86,8 +87,7 @@ /** * @see #merge(Topic, Topic) */ - @SuppressWarnings("unchecked") - private static void _merge(TopicImpl source, TopicImpl target) { + private static void _merge(TopicImpl source, Topic target) { if (source == null || target == null) { throw new IllegalArgumentException("Neither the source topic nor the target topic must be null"); } @@ -121,7 +121,7 @@ for(Topic type: source.getTypes()) { target.addType(type); } - Map<Integer, Reifiable> sigs = ((TopicMapImpl) source.getTopicMap()).getCollectionFactory().createMap(); + IIntObjectMap<Reifiable> sigs = IntObjectMap.create(); for (Occurrence occ: target.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), occ); } @@ -133,7 +133,7 @@ occ.remove(); } else { - ((IMovable<Topic>) occ).moveTo(target); + ((OccurrenceImpl) occ).moveTo(target); } } sigs.clear(); @@ -148,7 +148,7 @@ name.remove(); } else { - ((IMovable<Topic>) name).moveTo(target); + ((NameImpl) name).moveTo(target); } } sigs.clear(); @@ -177,7 +177,7 @@ * @param target The association which takes the role characteristics. */ static void moveRoleCharacteristics(Association source, Association target) { - Map<Integer, Role> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); + IIntObjectMap<Role> sigs = IntObjectMap.create(); for (Role role: target.getRoles()) { sigs.put(SignatureGenerator.generateSignature(role), role); } @@ -194,9 +194,8 @@ * @param source The name to take the variants from. * @param target The target to add the variants to. */ - @SuppressWarnings("unchecked") static void moveVariants(Name source, Name target) { - Map<Integer, Variant> sigs = ((TopicMapImpl) target.getTopicMap()).getCollectionFactory().createMap(); + IIntObjectMap<Variant> sigs = IntObjectMap.create(); for (Variant var: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(var), var); } @@ -208,7 +207,7 @@ var.remove(); } else { - ((IMovable<Name>) var).moveTo(target); + ((VariantImpl) var).moveTo(target); } } } Modified: tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -44,7 +44,11 @@ private Set<Variant> _variants; - NameImpl(TopicMapImpl topicMap, Topic type, ILiteral literal, Collection<Topic> scope) { + NameImpl(TopicMapImpl tm) { + super(tm); + } + + NameImpl(TopicMapImpl topicMap, Topic type, ILiteral literal, IScope scope) { super(topicMap, type, scope); _literal = literal; } @@ -151,7 +155,7 @@ if (scope_.isEmpty()) { throw new ModelConstraintException(this, "The variant's scope is not a true superset of the parent's scope"); } - Variant variant = new VariantImpl(_tm, literal, scope_); + Variant variant = new VariantImpl(_tm, literal, Scope.create(scope_)); addVariant(variant); return variant; } @@ -198,6 +202,14 @@ } /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#isName() + */ + @Override + public final boolean isName() { + return true; + } + + /* (non-Javadoc) * @see org.tmapi.core.Construct#remove() */ public void remove() { Modified: tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/OccurrenceImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -20,8 +20,6 @@ */ package org.tinytim.core; -import java.util.Collection; - import org.tmapi.core.Occurrence; import org.tmapi.core.Topic; @@ -34,7 +32,11 @@ final class OccurrenceImpl extends DatatypeAwareConstruct implements Occurrence, IMovable<Topic> { - OccurrenceImpl(TopicMapImpl topicMap, Topic type, ILiteral literal, Collection<Topic> scope) { + OccurrenceImpl(TopicMapImpl tm) { + super(tm); + } + + OccurrenceImpl(TopicMapImpl topicMap, Topic type, ILiteral literal, IScope scope) { super(topicMap, type, literal, scope); } @@ -55,6 +57,14 @@ } /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#isOccurrence() + */ + @Override + public final boolean isOccurrence() { + return true; + } + + /* (non-Javadoc) * @see org.tmapi.core.Construct#remove() */ public void remove() { Modified: tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -34,6 +34,10 @@ private Topic _player; + RoleImpl(TopicMapImpl tm) { + super(tm); + } + RoleImpl(TopicMapImpl tm, Topic type, Topic player) { super(tm, type); _player = player; @@ -74,6 +78,14 @@ } /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#isRole() + */ + @Override + public final boolean isRole() { + return true; + } + + /* (non-Javadoc) * @see org.tmapi.core.Construct#remove() */ public void remove() { Modified: tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -20,8 +20,6 @@ */ package org.tinytim.core; -import java.util.Collection; -import java.util.Collections; import java.util.Set; import org.tmapi.core.Topic; @@ -33,28 +31,45 @@ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ -abstract class ScopedImpl extends TypedImpl { +abstract class ScopedImpl extends TypedImpl implements IScoped { //NOTE: This class does NOT implement IScoped by intention! - private Set<Topic> _scope; + private IScope _scope; - ScopedImpl(TopicMapImpl topicMap, Topic type, Collection<Topic> scope) { + ScopedImpl(TopicMapImpl tm) { + super(tm); + _scope = Scope.UCS; + } + + ScopedImpl(TopicMapImpl topicMap, Topic type, IScope scope) { super(topicMap, type); - if (scope != null && !scope.isEmpty()) { - _scope = _makeSet(scope.size()); - for (Topic theme: scope) { - _scope.add(theme); - } + _scope = scope; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScoped#getScopeObject() + */ + public IScope getScopeObject() { + return _scope; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScoped#setScopeObject(org.tinytim.core.IScope) + */ + public void setScopeObject(IScope scope) { + if (_scope == scope) { + return; } + _fireEvent(Event.SET_SCOPE, _scope, scope); + _scope = scope; } /* (non-Javadoc) * @see org.tmapi.core.ScopedObject#getScope() */ public Set<Topic> getScope() { - return _scope == null ? Collections.<Topic>emptySet() - : Collections.unmodifiableSet(_scope); + return _scope.asSet(); } /* (non-Javadoc) @@ -64,25 +79,14 @@ if (theme == null) { throw new IllegalArgumentException("The theme must not be null"); } - if (_scope != null && _scope.contains(theme)) { - return; - } - _fireEvent(Event.ADD_THEME, null, theme); - if (_scope == null) { - _scope = _makeSet(); - } - _scope.add(theme); + setScopeObject(_scope.add(theme)); } /* (non-Javadoc) * @see org.tmapi.Scoped#removeTheme(org.tmapi.core.Topic) */ public void removeTheme(Topic theme) { - if (_scope == null || _scope.isEmpty()) { - return; - } - _fireEvent(Event.REMOVE_THEME, theme, null); - _scope.remove(theme); + setScopeObject(_scope.remove(theme)); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/SignatureGenerator.java 2008-08-11 12:18:58 UTC (rev 111) @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.Collection; -import java.util.Set; import org.tmapi.core.Association; import org.tmapi.core.Name; @@ -166,17 +165,7 @@ * @return The signature. */ private static int _generateScopeSignature(final Scoped scoped) { - Set<Topic> scope = scoped.getScope(); - if (scope.isEmpty()) { - return 0; - } - int[] ids = new int[scope.size()]; - int i = 0; - for (Topic topic : scope) { - ids[i++] = _signature(topic); - } - Arrays.sort(ids); - return Arrays.hashCode(ids); + return System.identityHashCode(((IScoped) scoped).getScopeObject()); } private static int _signature(Topic topic) { Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -193,7 +193,7 @@ if (scope == null) { throw new IllegalArgumentException("The scope must not be null"); } - Occurrence occ = new OccurrenceImpl(_tm, type, literal, scope); + Occurrence occ = new OccurrenceImpl(_tm, type, literal, Scope.create(scope)); addOccurrence(occ); return occ; } @@ -313,7 +313,7 @@ if (scope == null) { throw new IllegalArgumentException("The scope must not be null"); } - NameImpl name = new NameImpl(_tm, type, literal, scope); + NameImpl name = new NameImpl(_tm, type, literal, Scope.create(scope)); addName(name); return name; } @@ -461,6 +461,14 @@ } /* (non-Javadoc) + * @see org.tinytim.core.ConstructImpl#isTopic() + */ + @Override + public final boolean isTopic() { + return true; + } + + /* (non-Javadoc) * @see org.tmapi.core.TopicMapObject#remove() */ public void remove() throws TopicInUseException { Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-08 14:10:59 UTC (rev 110) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicMapImpl.java 2008-08-11 12:18:58 UTC (rev 111) @@ -30,7 +30,7 @@ import org.tinytim.index.IndexManager; import org.tinytim.index.IIndexManager; -import org.tinytim.utils.ICollectionFactory; +import org.tinytim.utils.CollectionFactory; import org.tinytim.voc.TMDM; import org.tmapi.core.Association; import org.tmapi.core.IdentityConstraintException; @@ -55,8 +55,6 @@ private IdentityManager _identityManager; private IndexManager _indexManager; - private ICollectionFactory _collectionFactory; - private IFactory _factory; private Locator _locator; private Set<Topic> _topics; private Set<Association> _assocs; @@ -70,23 +68,14 @@ super._tm = this; _sys = sys; _locator = locator; - _collectionFactory = _sys.getCollectionFactory(); - _topics = _collectionFactory.createIdentitySet(100); - _assocs = _collectionFactory.createIdentitySet(100); - _evtHandlers = _collectionFactory.createIdentityMap(); + _topics = CollectionFactory.createIdentitySet(100); + _assocs = CollectionFactory.createIdentitySet(100); + _evtHandlers = CollectionFactory.createIdentityMap(); _identityManager = new IdentityManager(this); - _indexManager = new IndexManager(this, _collectionFactory); + _indexManager = new IndexManager(this); _eventMultiplier = new EventMultiplier(this); } - ICollectionFactory getCollectionFactory() { - return _collectionFactory; - } - - public IFactory getFactory() { - return _factory; - } - Locator getLocator() { return _locator; } @@ -119,7 +108,7 @@ public Topic createTopic() { TopicImpl topic = new TopicImpl(this); addTopic(topic); - topic.addItemIdentifier(Literal.createIRI("urn:x-tinytim:" + IdGenerator.getInstance().nextId())); + topic.addItemIdentifier(Literal.createIRI("urn:x-tinytim:" + IdGenerator.nextId())); return topic; } @@ -244,7 +233,7 @@ if (scope == null) { throw new IllegalArgumentException("The scope must not be null"); } - AssociationImpl assoc = new AssociationImpl(this, type, scope); + AssociationImpl assoc = new AssociationImpl(this, type, Scope.create(scope)); addAssociation(assoc); return assoc; } @@ -328,15 +317,16 @@ /* (non-Javadoc) * @see org.tmapi.core.TopicMap#getIndex(java.lang.Class) */ - public Index getIndex(Class<? extends Index> indexInterface) { + @SuppressWarnings("unchecked") + public <I extends Index> I getIndex(Class<I> indexInterface) { if (indexInterface.getName().equals("org.tmapi.index.TypeInstanceIndex")) { - return _indexManager.getTypeInstanceIndex(); + return (I) _indexManager.getTypeInstanceIndex(); } if (indexInterface.getName().equals("org.tmapi.index.ScopedIndex")) { - return _indexManager.getScopedIndex(); + return (I) _indexManager.getScopedIndex(); } if (indexInterface.getName().equals("org.tmapi.index.LiteralIndex")) { - return _indexManager.getLiteralIndex(); + return (I) _indexManager.getLiteralIndex(); } throw new UnsupportedOperationException("Index '" + indexInterface.getName() + "' is unknown"); } @@ -356,6 +346,14 @@ } /* (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() { @@ -373,9 +371,17 @@ } /* (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, Construct sender, Object oldValue, Object newValue) { + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { if (!_evtHandlers.containsKey(evt)) { _eventMultiplier.handleEvent(evt, sender, oldValue, newValue); return; @@ -421,25 +427,25 @@ _handler = handler; } - public void handleEvent(Event evt, Construct sender, Object oldValue, + public void handleEvent(Event evt, IConstruct sender, Object oldValue, Object newValue) { switch (evt) { - case ADD_TOPIC: _topicAdd((Topic)newValue); break; - case ADD_ASSOCIATION: _associationAdd((Association)newValue); break; - case ADD_NAME: _nameAdd((Name)newValue); break; + case ADD_TOPIC: _topicAdd((TopicImpl)newValue); break; + case ADD_ASSOCIATION: _associationAdd((AssociationImpl)newValue); break; + case ADD_NAME: _nameAdd((NameImpl)newValue); break; case ADD_ROLE: case ADD_OCCURRENCE: - ... [truncated message content] |
From: <lh...@us...> - 2008-08-11 12:21:37
|
Revision: 112 http://tinytim.svn.sourceforge.net/tinytim/?rev=112&view=rev Author: lheuer Date: 2008-08-11 12:21:38 +0000 (Mon, 11 Aug 2008) Log Message: ----------- - Committed missing classes (Scope and the new CollectionFactory) Added Paths: ----------- tinytim/trunk/src/main/java/org/tinytim/core/Scope.java tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java Added: tinytim/trunk/src/main/java/org/tinytim/core/Scope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Scope.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,154 @@ +/* + * 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.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.Set; + +import org.tinytim.utils.CollectionFactory; +import org.tinytim.utils.WeakObjectRegistry; +import org.tmapi.core.Topic; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +final class Scope implements IScope { + + public static final IScope UCS = new Scope(); + + private static final WeakObjectRegistry<IScope> _SCOPES = new WeakObjectRegistry<IScope>(); + + private final Set<Topic> _set; + + private Scope() { + _set = Collections.emptySet(); + } + + private Scope(Collection<Topic> themes) { + _set = CollectionFactory.createIdentitySet(themes.size()); + _set.addAll(themes); + } + + private Scope(Set<Topic> themes) { + _set = themes; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + return (obj instanceof Scope) && _set.equals(((Scope)obj)._set); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return _set.hashCode(); + } + + public static synchronized IScope create(Collection<Topic> scope) { + if (scope.isEmpty()) { + return UCS; + } + Set<Topic> themes = CollectionFactory.createIdentitySet(scope.size()); + themes.addAll(scope); + IScope scope_ = new Scope(themes); + IScope existing = _SCOPES.get(scope_); + if (existing != null) { + return existing; + } + _SCOPES.add(scope_); + return scope_; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScope#asSet() + */ + public Set<Topic> asSet() { + return Collections.unmodifiableSet(_set); + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScope#contains(org.tmapi.core.Topic) + */ + public boolean contains(Topic theme) { + return _set.contains(theme); + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScope#add(org.tmapi.core.Topic) + */ + public IScope add(Topic theme) { + if (_set.contains(theme)) { + return this; + } + Collection<Topic> themes = CollectionFactory.createIdentitySet(_set.size()); + themes.addAll(_set); + themes.add(theme); + return create(themes); + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScope#remove(org.tmapi.core.Topic) + */ + public IScope remove(Topic theme) { + if (!_set.contains(theme)) { + return this; + } + Collection<Topic> themes = CollectionFactory.createIdentitySet(_set.size()); + themes.addAll(_set); + themes.remove(theme); + return create(themes); + } + + /* (non-Javadoc) + * @see java.lang.Iterable#iterator() + */ + public Iterator<Topic> iterator(){ + return _set.iterator(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScope#isUnconstrained() + */ + public boolean isUnconstrained() { + return this == UCS; + } + + /* (non-Javadoc) + * @see org.tinytim.core.IScope#size() + */ + public int size() { + return _set.size(); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/core/Scope.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,108 @@ +/* + * 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.utils; + +import java.util.Map; +import java.util.Set; + + + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class CollectionFactory { + + private static final String _COLL_FACTORY_TROVE = "org.tinytim.utils.TroveCollectionFactory"; + + private static final ICollectionFactory _COLL_FACTORY; + + static { + ICollectionFactory collFactory; + try { + Class.forName("gnu.trove.THashSet"); + collFactory = (ICollectionFactory) Class.forName(_COLL_FACTORY_TROVE).newInstance(); + } + catch (Exception ex) { + collFactory = new JavaCollectionFactory(); + } + _COLL_FACTORY = collFactory; + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createIdentityMap() + */ + public static <K, V> Map<K, V> createIdentityMap() { + return _COLL_FACTORY.createIdentityMap(); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createIdentityMap(int) + */ + public static <K, V> Map<K, V> createIdentityMap(int size) { + return _COLL_FACTORY.createIdentityMap(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createIdentitySet(int) + */ + public static <E> Set<E> createIdentitySet(int size) { + return _COLL_FACTORY.createIdentitySet(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createIdentitySet() + */ + public static <E> Set<E> createIdentitySet() { + return _COLL_FACTORY.createIdentitySet(); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createMap() + */ + public static <K, V> Map<K, V> createMap() { + return _COLL_FACTORY.createMap(); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createMap(int) + */ + public static <K, V> Map<K, V> createMap(int size) { + return _COLL_FACTORY.createMap(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createSet(int) + */ + public static <E> Set<E> createSet(int size) { + return _COLL_FACTORY.createSet(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createSet() + */ + public static <E> Set<E> createSet() { + return _COLL_FACTORY.createSet(); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,36 @@ +/* + * 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.utils; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IIntObjectMap<V> { + + public V put(int key, V value); + + public V get(int key); + + public void clear(); +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,57 @@ +/* + * 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.utils; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class IntObjectMap { + + private static final boolean _TROVE_AVAILABLE; + + static { + boolean available = false; + try { + // Probe if Trove is available. + Class.forName("gnu.trove.THashSet"); + available = true; + } + catch (Exception ex) { + + } + _TROVE_AVAILABLE = available; + } + + private IntObjectMap() { + // noop. + } + + public static <V> IIntObjectMap<V> create() { + return _TROVE_AVAILABLE ? new TroveIntObjectMap<V>() : new JavaIntObjectMap<V>(); + } + + public static <V> IIntObjectMap<V> create(int size) { + return _TROVE_AVAILABLE ? new TroveIntObjectMap<V>(size) : new JavaIntObjectMap<V>(size); + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,160 @@ +/* + * 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.utils; + +import java.util.AbstractSet; +import java.util.HashMap; +import java.util.HashSet; +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + + +/** + * {@link ICollectionFactory} which uses the standard Java collections. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +final class JavaCollectionFactory implements ICollectionFactory { + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createMap(int) + */ + public <K, V> Map<K, V> createMap(int size) { + return new HashMap<K, V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createMap() + */ + public <K, V> Map<K, V> createMap() { + return new HashMap<K, V>(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentityMap() + */ + public <K, V> Map<K, V> createIdentityMap() { + return new IdentityHashMap<K,V>(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentityMap(int) + */ + public <K, V> Map<K, V> createIdentityMap(int size) { + return new IdentityHashMap<K,V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createSet(int) + */ + public <E> Set<E> createSet(int size) { + return new HashSet<E>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createSet() + */ + public <E> Set<E> createSet() { + return new HashSet<E>(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentitySet() + */ + public <E> Set<E> createIdentitySet() { + return new IdentityHashSet<E>(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentitySet(int) + */ + public <E> Set<E> createIdentitySet(int size) { + return new IdentityHashSet<E>(size); + } + + /** + * {@link java.util.Set} implementation that compares its elements by + * identity. + */ + private static class IdentityHashSet<E> extends AbstractSet<E> { + + private final Map<E, Boolean> _map; + + public IdentityHashSet() { + _map = new IdentityHashMap<E, Boolean>(); + } + + public IdentityHashSet(int size) { + _map = new IdentityHashMap<E, Boolean>(size); + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#add(java.lang.Object) + */ + @Override + public boolean add(E obj) { + return _map.put(obj, Boolean.TRUE) == null; + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#remove(java.lang.Object) + */ + @Override + public boolean remove(Object obj) { + return _map.remove(obj) != null; + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#contains(java.lang.Object) + */ + @Override + public boolean contains(Object obj) { + return _map.containsKey(obj); + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#iterator() + */ + @Override + public Iterator<E> iterator() { + return _map.keySet().iterator(); + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#size() + */ + @Override + public int size() { + return _map.size(); + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#clear() + */ + @Override + public void clear() { + _map.clear(); + } + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,62 @@ +/* + * 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.utils; + +import java.util.HashMap; +import java.util.Map; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +final class JavaIntObjectMap<V> implements IIntObjectMap<V> { + + private final Map<Integer, V> _map; + + JavaIntObjectMap() { + _map = new HashMap<Integer, V>(); + } + + JavaIntObjectMap(int size) { + _map = new HashMap<Integer, V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#get(int) + */ + public V get(int key) { + return _map.get(key); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object) + */ + public V put(int key, V value) { + return _map.put(Integer.valueOf(key), value); + } + + public void clear() { + _map.clear(); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,97 @@ +/* + * 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.utils; + +import gnu.trove.THashMap; +import gnu.trove.THashSet; +import gnu.trove.TObjectIdentityHashingStrategy; + +import java.util.Map; +import java.util.Set; + + +/** + * {@link ICollectionFactory} which uses the + * <a href="http://sourceforge.net/projects/trove4j/">Trove library </a>. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev$ - $Date$ + */ +final class TroveCollectionFactory implements ICollectionFactory { + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createMap(int) + */ + public <K, V> Map<K, V> createMap(int size) { + return new THashMap<K,V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createMap() + */ + public <K, V> Map<K, V> createMap() { + return new THashMap<K, V>(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentityMap() + */ + public <K, V> Map<K, V> createIdentityMap() { + return new THashMap<K, V>(new TObjectIdentityHashingStrategy<K>()); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentityMap(int) + */ + public <K, V> Map<K, V> createIdentityMap(int size) { + return new THashMap<K, V>(size, new TObjectIdentityHashingStrategy<K>()); + } + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createSet(int) + */ + public <E> Set<E> createSet(int size) { + return new THashSet<E>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.ICollectionFactory#createSet() + */ + public <E> Set<E> createSet() { + return new THashSet<E>(); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentitySet() + */ + public <E> Set<E> createIdentitySet() { + return new THashSet<E>(new TObjectIdentityHashingStrategy<E>()); + } + + /* (non-Javadoc) + * @see org.tinytim.core.ICollectionFactory#createIdentitySet(int) + */ + public <E> Set<E> createIdentitySet(int size) { + return new THashSet<E>(size, new TObjectIdentityHashingStrategy<E>()); + } + + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java 2008-08-11 12:21:38 UTC (rev 112) @@ -0,0 +1,61 @@ +/* + * 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.utils; + +import gnu.trove.TIntObjectHashMap; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +final class TroveIntObjectMap<V> implements IIntObjectMap<V> { + + private final TIntObjectHashMap<V> _map; + + TroveIntObjectMap() { + _map = new TIntObjectHashMap<V>(); + } + + TroveIntObjectMap(int size) { + _map = new TIntObjectHashMap<V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#get(int) + */ + public V get(int key) { + return _map.get(key); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object) + */ + public V put(int key, V value) { + return _map.put(key, value); + } + + public void clear() { + _map.clear(); + } + +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native Added: tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java (rev 0) +++ tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java 2008-08-11 12:21:38 UTC (rev 112) @@ -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.utils; + +import java.lang.ref.WeakReference; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Map; +import java.util.WeakHashMap; + +/** + * + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class WeakObjectRegistry<E> extends AbstractSet<E> { + + private final Map<E, WeakReference<E>> _obj2Ref; + + public WeakObjectRegistry() { + super(); + _obj2Ref = new WeakHashMap<E, WeakReference<E>>(); + } + + /** + * + * + * @param key + * @return + */ + public E get(Object key) { + WeakReference<E> weakRef = _obj2Ref.get(key); + return weakRef != null ? weakRef.get() : null; + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#add(java.lang.Object) + */ + @Override + public boolean add(E obj) { + WeakReference<E> ref = new WeakReference<E>(obj); + ref = _obj2Ref.put(obj, ref); + return ref != null && ref.get() != null; + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#remove(java.lang.Object) + */ + @Override + public boolean remove(Object obj) { + WeakReference<E> ref = _obj2Ref.remove(obj); + return ref != null && ref.get() != null; + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#clear() + */ + @Override + public void clear() { + _obj2Ref.clear(); + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#contains(java.lang.Object) + */ + @Override + public boolean contains(Object obj) { + return get(obj) != null; + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#iterator() + */ + @Override + public Iterator<E> iterator() { + return _obj2Ref.keySet().iterator(); + } + + /* (non-Javadoc) + * @see java.util.AbstractCollection#size() + */ + @Override + public int size() { + return _obj2Ref.size(); + } +} Property changes on: tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-11 16:45:28
|
Revision: 118 http://tinytim.svn.sourceforge.net/tinytim/?rev=118&view=rev Author: lheuer Date: 2008-08-11 16:45:18 +0000 (Mon, 11 Aug 2008) Log Message: ----------- - Added IIntObjectMap factory methods to the CollectionFactory - Inlined implementations of IIntObjectMap Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.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/MergeUtils.java tinytim/trunk/src/main/java/org/tinytim/core/Scope.java tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java Removed Paths: ------------- tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-11 16:45:18 UTC (rev 118) @@ -25,7 +25,6 @@ import org.tinytim.utils.CollectionFactory; import org.tinytim.utils.IIntObjectMap; -import org.tinytim.utils.IntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Construct; import org.tmapi.core.Locator; @@ -179,7 +178,7 @@ */ private static void _copyCharacteristics(Topic topic, TopicImpl targetTopic, Map<Topic, Topic> mergeMap) { - IIntObjectMap<Reifiable> sigs = IntObjectMap.create(); + IIntObjectMap<Reifiable> sigs = CollectionFactory.createIntObjectMap(); for (Occurrence occ: targetTopic.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), occ); } @@ -229,7 +228,7 @@ */ private static void _copyVariants(Name source, NameImpl target, Map<Topic, Topic> mergeMap) { - IIntObjectMap<Variant> sigs = IntObjectMap.create(); + IIntObjectMap<Variant> sigs = CollectionFactory.createIntObjectMap(); for (Variant variant: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(variant), variant); } @@ -324,7 +323,7 @@ private static void _copyAssociations(TopicMap source, TopicMapImpl target, Map<Topic, Topic> mergeMap) { Set<Association> assocs = target.getAssociations(); - IIntObjectMap<Association> sigs = IntObjectMap.create(assocs.size()); + IIntObjectMap<Association> sigs = CollectionFactory.createIntObjectMap(assocs.size()); for (Association assoc: assocs) { sigs.put(SignatureGenerator.generateSignature(assoc), assoc); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/DuplicateRemovalUtils.java 2008-08-11 16:45:18 UTC (rev 118) @@ -23,8 +23,8 @@ import java.util.ArrayList; import java.util.Collection; +import org.tinytim.utils.CollectionFactory; import org.tinytim.utils.IIntObjectMap; -import org.tinytim.utils.IntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; @@ -56,7 +56,7 @@ for (Topic topic: tm.getTopics()) { removeDuplicates(topic); } - IIntObjectMap<Association> sig2Assoc = IntObjectMap.create(); + IIntObjectMap<Association> sig2Assoc = CollectionFactory.createIntObjectMap(); TypeInstanceIndex typeInstanceIdx = tm.getIndexManager().getTypeInstanceIndex(); if (!typeInstanceIdx.isAutoUpdated()) { typeInstanceIdx.reindex(); @@ -99,7 +99,7 @@ * @param name The name from which the duplicates should be removed. */ public static void removeDuplicates(Name name) { - IIntObjectMap<Variant> sigs = IntObjectMap.create(); + IIntObjectMap<Variant> sigs = CollectionFactory.createIntObjectMap(); for (Variant variant: new ArrayList<Variant>(name.getVariants())) { int sig = SignatureGenerator.generateSignature(variant); Variant existing = sigs.get(sig); @@ -119,7 +119,7 @@ * @param occs */ private static void _removeDuplicateOccurrences(Collection<Occurrence> occs) { - IIntObjectMap<Occurrence> sigs = IntObjectMap.create(occs.size()); + IIntObjectMap<Occurrence> sigs = CollectionFactory.createIntObjectMap(occs.size()); Occurrence existing = null; for (Occurrence occ: new ArrayList<Occurrence>(occs)) { int sig = SignatureGenerator.generateSignature(occ); @@ -140,7 +140,7 @@ * @param names */ private static void _removeDuplicateNames(Collection<Name> names) { - IIntObjectMap<Name> sigs = IntObjectMap.create(names.size()); + IIntObjectMap<Name> sigs = CollectionFactory.createIntObjectMap(names.size()); Name existing = null; for (Name name: new ArrayList<Name>(names)) { removeDuplicates(name); @@ -163,7 +163,7 @@ * @param assoc The association to remove duplicate roles from. */ public static void removeDuplicates(Association assoc) { - IIntObjectMap<Role> sig2Role = IntObjectMap.create(); + IIntObjectMap<Role> sig2Role = CollectionFactory.createIntObjectMap(); Role existing = null; for (Role role: new ArrayList<Role>(assoc.getRoles())) { int sig = SignatureGenerator.generateSignature(role); Modified: tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/IConstruct.java 2008-08-11 16:45:18 UTC (rev 118) @@ -26,7 +26,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface IConstruct extends Construct { Modified: tinytim/trunk/src/main/java/org/tinytim/core/IScope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScope.java 2008-08-11 16:45:18 UTC (rev 118) @@ -30,7 +30,7 @@ * This interface is not meant to be used outside of the tinyTiM package. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface IScope extends Iterable<Topic> { Modified: tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/IScoped.java 2008-08-11 16:45:18 UTC (rev 118) @@ -26,7 +26,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface IScoped extends Scoped, IConstruct { Modified: tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/MergeUtils.java 2008-08-11 16:45:18 UTC (rev 118) @@ -25,8 +25,8 @@ import java.util.List; import org.tinytim.index.IIndexManager; +import org.tinytim.utils.CollectionFactory; import org.tinytim.utils.IIntObjectMap; -import org.tinytim.utils.IntObjectMap; import org.tmapi.core.Association; import org.tmapi.core.Construct; import org.tmapi.core.Locator; @@ -121,7 +121,7 @@ for(Topic type: source.getTypes()) { target.addType(type); } - IIntObjectMap<Reifiable> sigs = IntObjectMap.create(); + IIntObjectMap<Reifiable> sigs = CollectionFactory.createIntObjectMap(); for (Occurrence occ: target.getOccurrences()) { sigs.put(SignatureGenerator.generateSignature(occ), occ); } @@ -177,7 +177,7 @@ * @param target The association which takes the role characteristics. */ static void moveRoleCharacteristics(Association source, Association target) { - IIntObjectMap<Role> sigs = IntObjectMap.create(); + IIntObjectMap<Role> sigs = CollectionFactory.createIntObjectMap(); for (Role role: target.getRoles()) { sigs.put(SignatureGenerator.generateSignature(role), role); } @@ -195,7 +195,7 @@ * @param target The target to add the variants to. */ static void moveVariants(Name source, Name target) { - IIntObjectMap<Variant> sigs = IntObjectMap.create(); + IIntObjectMap<Variant> sigs = CollectionFactory.createIntObjectMap(); for (Variant var: target.getVariants()) { sigs.put(SignatureGenerator.generateSignature(var), var); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/Scope.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/core/Scope.java 2008-08-11 16:45:18 UTC (rev 118) @@ -33,7 +33,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class Scope implements IScope { Modified: tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/CollectionFactory.java 2008-08-11 16:45:18 UTC (rev 118) @@ -24,12 +24,11 @@ import java.util.Set; - /** * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class CollectionFactory { @@ -105,4 +104,12 @@ return _COLL_FACTORY.createSet(); } + public static <E> IIntObjectMap<E> createIntObjectMap() { + return _COLL_FACTORY.createIntObjectMap(); + } + + public static <E> IIntObjectMap<E> createIntObjectMap(int size) { + return _COLL_FACTORY.createIntObjectMap(size); + } + } Modified: tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/ICollectionFactory.java 2008-08-11 16:45:18 UTC (rev 118) @@ -33,6 +33,10 @@ */ interface ICollectionFactory { + <E> IIntObjectMap<E> createIntObjectMap(); + + <E> IIntObjectMap<E> createIntObjectMap(int size); + /** * Creates a {@link java.util.Set} with the specified initial <code>size</code>. * Modified: tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/IIntObjectMap.java 2008-08-11 16:45:18 UTC (rev 118) @@ -24,7 +24,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public interface IIntObjectMap<V> { Deleted: tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/IntObjectMap.java 2008-08-11 16:45:18 UTC (rev 118) @@ -1,57 +0,0 @@ -/* - * 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.utils; - -/** - * - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ - */ -public class IntObjectMap { - - private static final boolean _TROVE_AVAILABLE; - - static { - boolean available = false; - try { - // Probe if Trove is available. - Class.forName("gnu.trove.THashSet"); - available = true; - } - catch (Exception ex) { - - } - _TROVE_AVAILABLE = available; - } - - private IntObjectMap() { - // noop. - } - - public static <V> IIntObjectMap<V> create() { - return _TROVE_AVAILABLE ? new TroveIntObjectMap<V>() : new JavaIntObjectMap<V>(); - } - - public static <V> IIntObjectMap<V> create(int size) { - return _TROVE_AVAILABLE ? new TroveIntObjectMap<V>(size) : new JavaIntObjectMap<V>(size); - } -} Modified: tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/JavaCollectionFactory.java 2008-08-11 16:45:18 UTC (rev 118) @@ -38,6 +38,22 @@ final class JavaCollectionFactory implements ICollectionFactory { /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createIntObjectMap() + */ + @Override + public <E> IIntObjectMap<E> createIntObjectMap() { + return new JavaIntObjectMap<E>(); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.ICollectionFactory#createIntObjectMap(int) + */ + @Override + public <E> IIntObjectMap<E> createIntObjectMap(int size) { + return new JavaIntObjectMap<E>(size); + } + + /* (non-Javadoc) * @see org.tinytim.ICollectionFactory#createMap(int) */ public <K, V> Map<K, V> createMap(int size) { @@ -157,4 +173,36 @@ _map.clear(); } } + + private static final class JavaIntObjectMap<V> implements IIntObjectMap<V> { + + private final Map<Integer, V> _map; + + JavaIntObjectMap() { + _map = new HashMap<Integer, V>(); + } + + JavaIntObjectMap(int size) { + _map = new HashMap<Integer, V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#get(int) + */ + public V get(int key) { + return _map.get(key); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object) + */ + public V put(int key, V value) { + return _map.put(Integer.valueOf(key), value); + } + + public void clear() { + _map.clear(); + } + + } } Deleted: tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/JavaIntObjectMap.java 2008-08-11 16:45:18 UTC (rev 118) @@ -1,62 +0,0 @@ -/* - * 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.utils; - -import java.util.HashMap; -import java.util.Map; - -/** - * - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ - */ -final class JavaIntObjectMap<V> implements IIntObjectMap<V> { - - private final Map<Integer, V> _map; - - JavaIntObjectMap() { - _map = new HashMap<Integer, V>(); - } - - JavaIntObjectMap(int size) { - _map = new HashMap<Integer, V>(size); - } - - /* (non-Javadoc) - * @see org.tinytim.utils.IIntObjectMap#get(int) - */ - public V get(int key) { - return _map.get(key); - } - - /* (non-Javadoc) - * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object) - */ - public V put(int key, V value) { - return _map.put(Integer.valueOf(key), value); - } - - public void clear() { - _map.clear(); - } - -} Modified: tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/TroveCollectionFactory.java 2008-08-11 16:45:18 UTC (rev 118) @@ -22,6 +22,7 @@ import gnu.trove.THashMap; import gnu.trove.THashSet; +import gnu.trove.TIntObjectHashMap; import gnu.trove.TObjectIdentityHashingStrategy; import java.util.Map; @@ -37,6 +38,16 @@ */ final class TroveCollectionFactory implements ICollectionFactory { + @Override + public <E> IIntObjectMap<E> createIntObjectMap() { + return new TroveIntObjectMap<E>(); + } + + @Override + public <E> IIntObjectMap<E> createIntObjectMap(int size) { + return new TroveIntObjectMap<E>(size); + } + /* (non-Javadoc) * @see org.tinytim.ICollectionFactory#createMap(int) */ @@ -94,4 +105,35 @@ } + private static final class TroveIntObjectMap<V> implements IIntObjectMap<V> { + + private final TIntObjectHashMap<V> _map; + + TroveIntObjectMap() { + _map = new TIntObjectHashMap<V>(); + } + + TroveIntObjectMap(int size) { + _map = new TIntObjectHashMap<V>(size); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#get(int) + */ + public V get(int key) { + return _map.get(key); + } + + /* (non-Javadoc) + * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object) + */ + public V put(int key, V value) { + return _map.put(key, value); + } + + public void clear() { + _map.clear(); + } + + } } Deleted: tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/TroveIntObjectMap.java 2008-08-11 16:45:18 UTC (rev 118) @@ -1,61 +0,0 @@ -/* - * 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.utils; - -import gnu.trove.TIntObjectHashMap; - -/** - * - * - * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ - */ -final class TroveIntObjectMap<V> implements IIntObjectMap<V> { - - private final TIntObjectHashMap<V> _map; - - TroveIntObjectMap() { - _map = new TIntObjectHashMap<V>(); - } - - TroveIntObjectMap(int size) { - _map = new TIntObjectHashMap<V>(size); - } - - /* (non-Javadoc) - * @see org.tinytim.utils.IIntObjectMap#get(int) - */ - public V get(int key) { - return _map.get(key); - } - - /* (non-Javadoc) - * @see org.tinytim.utils.IIntObjectMap#put(int, java.lang.Object) - */ - public V put(int key, V value) { - return _map.put(key, value); - } - - public void clear() { - _map.clear(); - } - -} Modified: tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java 2008-08-11 13:42:49 UTC (rev 117) +++ tinytim/trunk/src/main/java/org/tinytim/utils/WeakObjectRegistry.java 2008-08-11 16:45:18 UTC (rev 118) @@ -30,7 +30,7 @@ * * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ public final class WeakObjectRegistry<E> extends AbstractSet<E> { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-08-21 14:35:35
|
Revision: 141 http://tinytim.svn.sourceforge.net/tinytim/?rev=141&view=rev Author: lheuer Date: 2008-08-21 14:35:44 +0000 (Thu, 21 Aug 2008) Log Message: ----------- - Added a few private constructors - Some Check docs Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-21 12:08:07 UTC (rev 140) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-08-21 14:35:44 UTC (rev 141) @@ -47,6 +47,10 @@ */ final class CopyUtils { + private CopyUtils() { + // noop. + } + /** * Copies the topics and associations from the <tt>source</tt> to the * <tt>target</tt> topic map. Modified: tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-21 12:08:07 UTC (rev 140) +++ tinytim/trunk/src/main/java/org/tinytim/core/IdGenerator.java 2008-08-21 14:35:44 UTC (rev 141) @@ -34,6 +34,10 @@ private static final AtomicLong _COUNTER = new AtomicLong(); + private IdGenerator() { + // noop. + } + /** * Returns the next identifier. * Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-08-21 12:08:07 UTC (rev 140) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-08-21 14:35:44 UTC (rev 141) @@ -28,8 +28,10 @@ import org.tmapi.core.Topic; /** + * Utility class to check arguments and to throw + * {@link org.tmapi.core.ModelConstraintException}s if the arg violates a + * constraint. * - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2008-09-04 11:46:43
|
Revision: 154 http://tinytim.svn.sourceforge.net/tinytim/?rev=154&view=rev Author: lheuer Date: 2008-09-04 11:46:52 +0000 (Thu, 04 Sep 2008) Log Message: ----------- - Added private constructors (again) :( Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-09-04 11:43:42 UTC (rev 153) +++ tinytim/trunk/src/main/java/org/tinytim/core/CopyUtils.java 2008-09-04 11:46:52 UTC (rev 154) @@ -47,6 +47,10 @@ */ final class CopyUtils { + private CopyUtils() { + // noop. + } + /** * Copies the topics and associations from the <tt>source</tt> to the * <tt>target</tt> topic map. Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-09-04 11:43:42 UTC (rev 153) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2008-09-04 11:46:52 UTC (rev 154) @@ -35,6 +35,17 @@ */ public final class Check { + private Check() { + // noop. + } + + /** + * Throws a {@link ModelConstraintException} with the specified <tt>sender</tt> + * and <tt>msg</tt> + * + * @param sender The sender + * @param msg The error message + */ private static void _reportError(Construct sender, String msg) { throw new ModelConstraintException(sender, msg); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-07-03 06:54:10
|
Revision: 299 http://tinytim.svn.sourceforge.net/tinytim/?rev=299&view=rev Author: lheuer Date: 2009-07-02 11:07:24 +0000 (Thu, 02 Jul 2009) Log Message: ----------- - Applied patch from Hannes Niederhausen (TMCL voc) - Internal change: All constructs are now checked if they belong to the same topic map - Fixes issue #2812460 Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java 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/MemoryTopicMap.java tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.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/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/internal/utils/Check.java tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java Modified: tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/AbstractTopicMapSystem.java 2009-07-02 11:07:24 UTC (rev 299) @@ -50,7 +50,7 @@ if (supported == null) { TopicMapSystemFactoryImpl.reportFeatureNotRecognized(featureName); } - return supported; + return supported.booleanValue(); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/AssociationImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -103,6 +103,7 @@ public Role createRole(Topic type, Topic player) { Check.typeNotNull(this, type); Check.playerNotNull(this, player); + Check.sameTopicMap(this, type, player); RoleImpl role = new RoleImpl(_tm, type, player); addRole(role); return role; @@ -130,9 +131,7 @@ * @see org.tmapi.core.Association#getRoles(org.tmapi.core.Topic) */ public Set<Role> getRoles(Topic type) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(type); Set<Role> roles = CollectionFactory.createIdentitySet(_roles.size()); for (Role role: _roles) { if (type == role.getType()) { Modified: tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/ConstructImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -22,11 +22,11 @@ import org.tinytim.internal.api.IConstant; import org.tinytim.internal.api.IConstruct; import org.tinytim.internal.api.ITopicMap; +import org.tinytim.internal.utils.Check; import org.tinytim.internal.utils.CollectionFactory; import org.tmapi.core.Construct; import org.tmapi.core.Locator; -import org.tmapi.core.ModelConstraintException; import org.tmapi.core.TopicMap; /** @@ -78,18 +78,16 @@ /* (non-Javadoc) * @see org.tmapi.core.Construct#addItemIdentifier(org.tmapi.core.Locator) */ - public void addItemIdentifier(Locator itemIdentifier) { - if (itemIdentifier == null) { - throw new ModelConstraintException(this, "The item identifier must not be null"); - } - if (_iids != null && _iids.contains(itemIdentifier)) { + public void addItemIdentifier(Locator iid) { + Check.itemIdentifierNotNull(this, iid); + if (_iids != null && _iids.contains(iid)) { return; } - _fireEvent(Event.ADD_IID, null, itemIdentifier); + _fireEvent(Event.ADD_IID, null, iid); if (_iids == null) { _iids = CollectionFactory.createIdentitySet(IConstant.CONSTRUCT_IID_SIZE); } - _iids.add(itemIdentifier); + _iids.add(iid); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/MemoryTopicMap.java 2009-07-02 11:07:24 UTC (rev 299) @@ -36,7 +36,6 @@ 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; @@ -127,9 +126,7 @@ * @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"); - } + Check.itemIdentifierNotNull(this, iid); Construct construct = getConstructByItemIdentifier(iid); if (construct != null) { if (construct instanceof Topic) { @@ -153,9 +150,7 @@ * @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"); - } + Check.subjectIdentifierNotNull(this, sid); Topic topic = getTopicBySubjectIdentifier(sid); if (topic != null) { return topic; @@ -177,9 +172,7 @@ * @see org.tmapi.core.TopicMap#createTopicBySubjectLocator(org.tmapi.core.Locator) */ public Topic createTopicBySubjectLocator(Locator slo) { - if (slo == null) { - throw new ModelConstraintException(null, "The subject locator must not be null"); - } + Check.subjectLocatorNotNull(this, slo); Topic topic = getTopicBySubjectLocator(slo); if (topic != null) { return topic; @@ -229,6 +222,8 @@ public Association createAssociation(Topic type, Collection<Topic> scope) { Check.typeNotNull(this, type); Check.scopeNotNull(this, scope); + Check.sameTopicMap(this, type); + Check.sameTopicMap(this, scope); AssociationImpl assoc = new AssociationImpl(this, type, Scope.create(scope)); addAssociation(assoc); return assoc; @@ -270,22 +265,25 @@ /* (non-Javadoc) * @see org.tmapi.core.TopicMap#getTopicBySubjectIdentifier(org.tmapi.core.Locator) */ - public Topic getTopicBySubjectIdentifier(Locator subjectIdentifier) { - return _identityManager.getTopicBySubjectIdentifier(subjectIdentifier); + public Topic getTopicBySubjectIdentifier(Locator sid) { + Check.subjectIdentifierNotNull(sid); + return _identityManager.getTopicBySubjectIdentifier(sid); } /* (non-Javadoc) * @see org.tmapi.core.TopicMap#getTopicBySubjectLocator(org.tmapi.core.Locator) */ - public Topic getTopicBySubjectLocator(Locator subjectLocator) { - return _identityManager.getTopicBySubjectLocator(subjectLocator); + public Topic getTopicBySubjectLocator(Locator slo) { + Check.subjectLocatorNotNull(slo); + return _identityManager.getTopicBySubjectLocator(slo); } /* (non-Javadoc) * @see org.tmapi.core.TopicMap#getConstructByItemIdentifier(org.tmapi.core.Locator) */ - public Construct getConstructByItemIdentifier(Locator itemIdentifier) { - return _identityManager.getConstructByItemIdentifier(itemIdentifier); + public Construct getConstructByItemIdentifier(Locator iid) { + Check.itemIdentifierNotNull(iid); + return _identityManager.getConstructByItemIdentifier(iid); } /* (non-Javadoc) @@ -299,6 +297,7 @@ * @see org.tmapi.core.Reifiable#setReifier(org.tmapi.core.Topic) */ public void setReifier(Topic reifier) { + Check.sameTopicMap(this, reifier); if (_reifier == reifier) { return; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/NameImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -186,6 +186,7 @@ } public IVariant createVariant(ILiteral literal, Collection<Topic> scope) { + Check.sameTopicMap(this, scope); if (scope.isEmpty()) { throw new ModelConstraintException(this, "The scope of the variant must not be unconstrained"); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/RoleImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -61,6 +61,7 @@ */ public void setPlayer(Topic player) { Check.playerNotNull(this, player); + Check.sameTopicMap(this, player); if (_player == player) { return; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/ScopedImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -21,8 +21,8 @@ import org.tinytim.internal.api.IScope; import org.tinytim.internal.api.IScoped; import org.tinytim.internal.api.ITopicMap; +import org.tinytim.internal.utils.Check; -import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Topic; /** @@ -77,9 +77,8 @@ * @see org.tmapi.core.Scoped#addTheme(org.tmapi.core.Topic) */ public void addTheme(Topic theme) { - if (theme == null) { - throw new ModelConstraintException(this, "The theme must not be null"); - } + Check.themeNotNull(this, theme); + Check.sameTopicMap(this, theme); setScopeObject(_scope.add(theme)); } @@ -87,6 +86,9 @@ * @see org.tmapi.core.Scoped#removeTheme(org.tmapi.core.Topic) */ public void removeTheme(Topic theme) { + if (theme == null) { + return; + } setScopeObject(_scope.remove(theme)); } Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -35,7 +35,6 @@ import org.tinytim.voc.TMDM; import org.tmapi.core.Locator; -import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Name; import org.tmapi.core.Occurrence; import org.tmapi.core.Reifiable; @@ -86,9 +85,7 @@ * @see org.tmapi.core.Topic#addSubjectIdentifier(org.tmapi.core.Locator) */ public void addSubjectIdentifier(Locator sid) { - if (sid == null) { - throw new ModelConstraintException(this, "The subject identifier must not be null"); - } + Check.subjectIdentifierNotNull(this, sid); if (_sids.contains(sid)) { return; } @@ -119,9 +116,7 @@ * @see org.tmapi.core.Topic#addSubjectLocator(org.tmapi.core.Locator) */ public void addSubjectLocator(Locator slo) { - if (slo == null) { - throw new ModelConstraintException(this, "The subject locator must not be null"); - } + Check.subjectLocatorNotNull(this, slo); if (_slos != null && _sids.contains(slo)) { return; } @@ -201,6 +196,8 @@ public IOccurrence createOccurrence(Topic type, ILiteral literal, Collection<Topic> scope) { Check.typeNotNull(this, type); Check.scopeNotNull(this, scope); + Check.sameTopicMap(this, type); + Check.sameTopicMap(this, scope); IOccurrence occ = new OccurrenceImpl(_tm, type, literal, Scope.create(scope)); addOccurrence(occ); return occ; @@ -261,9 +258,7 @@ * @see org.tmapi.core.Topic#getNames(org.tmapi.core.Topic) */ public Set<Name> getNames(Topic type) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(type); Set<Name> names = CollectionFactory.createIdentitySet(); for (Name name: _names) { if (type == name.getType()) { @@ -293,9 +288,7 @@ * @see org.tmapi.core.Topic#getOccurrences(org.tmapi.core.Topic) */ public Set<Occurrence> getOccurrences(Topic type) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(type); Set<Occurrence> occs = CollectionFactory.createIdentitySet(); for (Occurrence occ: _occs) { if (type == occ.getType()) { @@ -323,6 +316,8 @@ public IName createName(Topic type, ILiteral literal, Collection<Topic> scope) { Check.typeNotNull(this, type); Check.scopeNotNull(this, scope); + Check.sameTopicMap(this, type); + Check.sameTopicMap(this, scope); NameImpl name = new NameImpl(_tm, type, literal, Scope.create(scope)); addName(name); return name; @@ -382,9 +377,7 @@ * @see org.tmapi.core.Topic#getRolesPlayed(org.tmapi.core.Topic) */ public Set<Role> getRolesPlayed(Topic type) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(type); if (_rolesPlayed == null) { return Collections.emptySet(); } @@ -401,9 +394,7 @@ * @see org.tmapi.core.Topic#getRolesPlayed(org.tmapi.core.Topic, org.tmapi.core.Topic) */ public Set<Role> getRolesPlayed(Topic type, Topic assoc) { - if (type == null) { - throw new IllegalArgumentException("The type must not be null"); - } + Check.typeNotNull(type); if (assoc == null) { throw new IllegalArgumentException("The association type must not be null"); } @@ -446,6 +437,7 @@ */ public void addType(Topic type) { Check.typeNotNull(this, type); + Check.sameTopicMap(this, type); if (_types != null && _types.contains(type)) { return; } Modified: tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/TopicMapSystemFactoryImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -40,11 +40,7 @@ private static final FeatureInfo[] _FEATURES = new FeatureInfo[] { // Feature IRI, default value, fixed? - new FeatureInfo(Feature.NOTATION_URI, true, true), - new FeatureInfo(Feature.XTM_1_0, false, true), - new FeatureInfo(Feature.XTM_1_1, true, true), new FeatureInfo(Feature.AUTOMERGE, false, true), - new FeatureInfo(Feature.TNC, false, true), new FeatureInfo(Feature.READ_ONLY, false, true) }; @@ -114,7 +110,7 @@ if (supported == null) { reportFeatureNotRecognized(featureName); } - return supported; + return supported.booleanValue(); } /* (non-Javadoc) Modified: tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/core/TypedImpl.java 2009-07-02 11:07:24 UTC (rev 299) @@ -59,6 +59,7 @@ */ public void setType(Topic type) { Check.typeNotNull(this, type); + Check.sameTopicMap(this, type); if (_type == type) { return; } @@ -77,6 +78,7 @@ * @see org.tmapi.core.Reifiable#setReifier(org.tmapi.core.Topic) */ public void setReifier(Topic reifier) { + Check.sameTopicMap(this, reifier); if (_reifier == reifier) { return; } Modified: tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/internal/utils/Check.java 2009-07-02 11:07:24 UTC (rev 299) @@ -21,6 +21,7 @@ import org.tmapi.core.Locator; import org.tmapi.core.ModelConstraintException; import org.tmapi.core.Topic; +import org.tmapi.core.TopicMap; /** * Provides various argument constraint checks. @@ -41,11 +42,20 @@ * @param sender The sender * @param msg The error message */ - private static void _reportError(Construct sender, String msg) { + private static void _reportModelConstraintViolation(Construct sender, String msg) { throw new ModelConstraintException(sender, msg); } /** + * + * + * @param msg + */ + private static void _reportIllegalArgument(String msg) { + throw new IllegalArgumentException(msg); + } + + /** * Throws a {@link ModelConstraintException} iff the <tt>scope</tt> is * <tt>null</tt>. * @@ -54,7 +64,7 @@ */ public static void scopeNotNull(Construct sender, Topic[] scope) { if (scope == null) { - _reportError(sender, "The scope must not be null"); + _reportModelConstraintViolation(sender, "The scope must not be null"); } } @@ -67,7 +77,7 @@ */ public static void scopeNotNull(Construct sender, Collection<Topic> scope) { if (scope == null) { - _reportError(sender, "The scope must not be null"); + _reportModelConstraintViolation(sender, "The scope must not be null"); } } @@ -80,7 +90,7 @@ */ public static void typeNotNull(Construct sender, Topic type) { if (type == null) { - _reportError(sender, "The type must not be null"); + _reportModelConstraintViolation(sender, "The type must not be null"); } } @@ -93,7 +103,7 @@ */ public static void valueNotNull(Construct sender, Object value) { if (value == null) { - _reportError(sender, "The value must not be null"); + _reportModelConstraintViolation(sender, "The value must not be null"); } } @@ -108,7 +118,7 @@ public static void valueNotNull(Construct sender, Object value, Locator datatype) { valueNotNull(sender, value); if (datatype == null) { - _reportError(sender, "The datatype must not be null"); + _reportModelConstraintViolation(sender, "The datatype must not be null"); } } @@ -121,8 +131,147 @@ */ public static void playerNotNull(Construct sender, Topic player) { if (player == null) { - _reportError(sender, "The role player must not be null"); + _reportModelConstraintViolation(sender, "The role player must not be null"); } } + /** + * Throws a {@link ModelConstraintException} iff the <tt>iid</tt> is + * <tt>null</tt>. + * + * @param sender The sender + * @param iid The item identifier. + */ + public static void itemIdentifierNotNull(Construct sender, Locator iid) { + if (iid == null) { + _reportModelConstraintViolation(sender, "The item identifier must not be null"); + } + } + + /** + * Throws a {@link ModelConstraintException} iff the <tt>sid</tt> is + * <tt>null</tt>. + * + * @param sender The sender + * @param sid The subject identifier. + */ + public static void subjectIdentifierNotNull(Construct sender, Locator sid) { + if (sid == null) { + _reportModelConstraintViolation(sender, "The subject identifier must not be null"); + } + } + + /** + * Throws a {@link ModelConstraintException} iff the <tt>slo</tt> is + * <tt>null</tt>. + * + * @param sender The sender + * @param slo The subject locator. + */ + public static void subjectLocatorNotNull(Construct sender, Locator slo) { + if (slo == null) { + _reportModelConstraintViolation(sender, "The subject locator must not be null"); + } + } + + /** + * Throws an {@link ModelConstraintException} iff the <tt>theme</tt> is + * <tt>null</tt>. + * + * @param theme The theme. + */ + public static void themeNotNull(Construct sender, Topic theme) { + if (theme == null) { + _reportModelConstraintViolation(sender, "The theme must not be null"); + } + } + + /** + * Reports a {@link ModelConstraintException} iff the <tt>sender<tt> and + * the <tt>construct</tt> do not belong to the same topic map. + * + * @param sender The sender. + * @param construct The construct. + */ + public static void sameTopicMap(Construct sender, Construct construct) { + if (construct == null) { + return; + } + _sameTopicMap(sender, sender.getTopicMap(), construct); + } + + public static void sameTopicMap(Construct sender, Construct...constructs) { + if (constructs == null || constructs.length == 0) { + return; + } + TopicMap tm = sender.getTopicMap(); + for (Construct construct: constructs) { + _sameTopicMap(sender, tm, construct); + } + } + + public static void sameTopicMap(Construct sender, Collection<? extends Construct> constructs) { + if (constructs == null) { + return; + } + TopicMap tm = sender.getTopicMap(); + for (Construct construct: constructs) { + _sameTopicMap(sender, tm, construct); + } + } + + private static void _sameTopicMap(Construct sender, TopicMap tm, Construct other) { + if (!tm.equals(other.getTopicMap())) { + _reportModelConstraintViolation(sender, "All constructs must belong to the same topic map"); + } + } + + /** + * Throws an {@link IllegalArgumentException} iff the <tt>type</tt> is + * <tt>null</tt>. + * + * @param type The type. + */ + public static void typeNotNull(Topic type) { + if (type == null) { + _reportIllegalArgument("The type must not be null"); + } + } + + /** + * Reports an {@link IllegalArgumentException} iff the <tt>sid</tt> is + * <tt>null</tt>. + * + * @param sid The subject identifier. + */ + public static void subjectIdentifierNotNull(Locator sid) { + if (sid == null) { + _reportIllegalArgument("The subject identifier must not be null"); + } + } + + /** + * Reports an {@link IllegalArgumentException} iff the <tt>slo</tt> is + * <tt>null</tt>. + * + * @param slo The subject locator. + */ + public static void subjectLocatorNotNull(Locator slo) { + if (slo == null) { + _reportIllegalArgument("The subject locator must not be null"); + } + } + + /** + * Reports an {@link IllegalArgumentException} iff the <tt>iid</tt> is + * <tt>null</tt>. + * + * @param iid The item identifier. + */ + public static void itemIdentifierNotNull(Locator iid) { + if (iid == null) { + _reportIllegalArgument("The item identifier must not be null"); + } + } + } Modified: tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java 2009-05-13 15:02:57 UTC (rev 298) +++ tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java 2009-07-02 11:07:24 UTC (rev 299) @@ -36,92 +36,98 @@ // Topic types - public static final Locator TOPIC_TYPE = _createLocator(_BASE + "topictype"); + public static final Locator TOPIC_TYPE = _createLocator(_BASE + "topic-type"); - public static final Locator ASSOCIATION_TYPE = _createLocator(_BASE + "associationtype"); + public static final Locator ASSOCIATION_TYPE = _createLocator(_BASE + "association-type"); - public static final Locator ROLE_TYPE = _createLocator(_BASE + "roletype"); + public static final Locator ROLE_TYPE = _createLocator(_BASE + "role-type"); - public static final Locator OCCURRENCE_TYPE = _createLocator(_BASE + "occurrencetype"); + public static final Locator OCCURRENCE_TYPE = _createLocator(_BASE + "occurrence-type"); - public static final Locator NAME_TYPE = _createLocator(_BASE + "nametype"); + public static final Locator NAME_TYPE = _createLocator(_BASE + "name-type"); - public static final Locator SCOPE_TYPE = _createLocator(_BASE + "scopetype"); + public static final Locator SCOPE_TYPE = _createLocator(_BASE + "scope-type"); // Role types + public static final Locator ALLOWS = _createLocator(_BASE + "allows"); + + public static final Locator ALLOWED = _createLocator(_BASE + "allowed"); + + public static final Locator CONSTRAINS = _createLocator(_BASE + "constrains"); + + public static final Locator CONSTRAINED = _createLocator(_BASE + "constrained"); - public static final Locator TOPIC_TYPE_ROLE = _createLocator(_BASE + "topictype-role"); - - public static final Locator ASSOCIATION_TYPE_ROLE = _createLocator(_BASE + "associationtype-role"); - - public static final Locator ROLE_TYPE_ROLE = _createLocator(_BASE + "roletype-role"); - - public static final Locator OTHERROLE_TYPE_ROLE = _createLocator(_BASE + "roletype-role"); - - public static final Locator OCCURRENCE_TYPE_ROLE = _createLocator(_BASE + "occurrencetype-role"); - - public static final Locator NAME_TYPE_ROLE = _createLocator(_BASE + "nametype-role"); - - public static final Locator SCOPE_TYPE_ROLE = _createLocator(_BASE + "scopetype-role"); - - public static final Locator CONSTRAINT_ROLE = _createLocator(_BASE + "constraint-role"); - - + // Association types - applies-to is no more + public static final Locator CONSTRAINED_TOPIC_TYPE = _createLocator(_BASE + "constrained-topic-type"); + + public static final Locator CONSTRAINED_STATEMENT = _createLocator(_BASE + "constrained-statement"); + + public static final Locator CONSTRAINED_ROLE = _createLocator(_BASE + "constrained-role"); + + public static final Locator OVERLAPS = _createLocator(_BASE + "overlaps"); + + public static final Locator ALLOWED_SCOPE = _createLocator(_BASE + "allowed-scope"); + + public static final Locator ALLOWED_REIFIER = _createLocator(_BASE + "allowed-reifier"); + + public static final Locator OTHER_CONSTRAINED_TOPIC_TYPE = _createLocator(_BASE + "other-constrained-topic-type"); + + public static final Locator OTHER_CONSTRAINED_ROLE = _createLocator(_BASE + "other-constrained-role"); + + public static final Locator BELONGS_TO_SCHEMA = _createLocator(_BASE + "belongs-to-schema"); + // Model topics + + public static final Locator SCHEMA = _createLocator(_BASE + "schema"); + public static final Locator CONSTRAINT = _createLocator(_BASE + "constraint"); public static final Locator VALIDATION_EXPRESSION = _createLocator(_BASE + "validation-expression"); - public static final Locator APPLIES_TO = _createLocator(_BASE + "applies-to"); - public static final Locator CARD_MIN = _createLocator(_BASE + "card-min"); public static final Locator CARD_MAX = _createLocator(_BASE + "card-max"); - //TODO: TMCL uses sometimes "regexp" and sometimes "reg-exp" - public static final Locator REGEXP = _createLocator(_BASE + "reg-exp"); + public static final Locator REGEXP = _createLocator(_BASE + "regexp"); public static final Locator DATATYPE = _createLocator(_BASE + "datatype"); + + public static final Locator VERSION = _createLocator(_BASE + "version"); + public static final Locator DESCRIPTION = _createLocator(_BASE + "description"); + + public static final Locator COMMENT = _createLocator(_BASE + "comment"); + + public static final Locator SEE_ALSO = _createLocator(_BASE + "see-also"); // Constraint types - public static final Locator TOPIC_TYPE_CONSTRAINT = _createLocator(_BASE + "topictype-constraint"); + + public static final Locator ABSTRACT_TOPIC_TYPE_CONSTRAINT = _createLocator(_BASE + "abstract-constraint"); + + public static final Locator OVERLAP_DECLARATION = _createLocator(_BASE + "overlap-declaration"); + + public static final Locator SUBJECT_IDENTIFIER_CONSTRAINT = _createLocator(_BASE + "subject-identifier-constraint"); - public static final Locator ASSOCIATION_TYPE_CONSTRAINT = _createLocator(_BASE + "associationtype-constraint"); + public static final Locator SUBJECT_LOCATOR_CONSTRAINT = _createLocator(_BASE + "subject-locator-constraint"); + + public static final Locator TOPIC_NAME_CONSTRAINT = _createLocator(_BASE + "topic-name-constraint"); + + public static final Locator TOPIC_OCCURRENCE_CONSTRAINT = _createLocator(_BASE + "topic-occurrence-constraint"); + + public static final Locator ROLE_PLAYER_CONSTRAINT = _createLocator(_BASE + "role-player-constraint"); + + public static final Locator SCOPE_CONSTRAINT = _createLocator(_BASE + "scope-constraint"); + + public static final Locator REIFIER_CONSTRAINT = _createLocator(_BASE + "reifier-constraint"); - public static final Locator ROLE_TYPE_CONSTRAINT = _createLocator(_BASE + "roletype-constraint"); + public static final Locator ASSOCIATION_ROLE_CONSTRAINT = _createLocator(_BASE + "association-role-constraint"); + + public static final Locator OTHER_ROLE_CONSTRAINT = _createLocator(_BASE + "other-role-constraint"); + + public static final Locator OCCURRENCE_DATATYPE_CONSTRAINT = _createLocator(_BASE + "occurrence-datatype-constraint"); - public static final Locator OCCURRENCE_TYPE_CONSTRAINT = _createLocator(_BASE + "occurrencetype-constraint"); - - public static final Locator NAME_TYPE_CONSTRAINT = _createLocator(_BASE + "nametype-constraint"); - - public static final Locator ABSTRACT_TOPIC_TYPE_CONSTRAINT = _createLocator(_BASE + "abstract-topictype-constraint"); + public static final Locator UNIQUE_VALUE_CONSTRAINT = _createLocator(_BASE + "unique-value-constraint"); - public static final Locator EXCLUSIVE_INSTANCE = _createLocator(_BASE + "exclusive-instance"); - - public static final Locator SUBJECT_IDENTIFIER_CONSTRAINT = _createLocator(_BASE + "subjectidentifier-constraint"); - - public static final Locator SUBJECT_LOCATOR_CONSTRAINT = _createLocator(_BASE + "subjectlocator-constraint"); - - public static final Locator NAME_CONSTRAINT = _createLocator(_BASE + "topicname-constraint"); - - public static final Locator NAME_TYPE_SCOPE_CONSTRAINT = _createLocator(_BASE + "nametypescope-constraint"); - - public static final Locator OCCURRENCE_TYPE_SCOPE_CONSTRAINT = _createLocator(_BASE + "occurrencetypescope-constraint"); - - public static final Locator OCCURRENCE_DATATYPE_CONSTRAINT = _createLocator(_BASE + "occurrencedatatype-constraint"); - - public static final Locator ASSOCIATION_TYPE_SCOPE_CONSTRAINT = _createLocator(_BASE + "associationtypescope-constraint"); - - public static final Locator ASSOCIATION_ROLE_CONSTRAINT = _createLocator(_BASE + "associationrole-constraint"); - - public static final Locator ROLE_PLAYER_CONSTRAINT = _createLocator(_BASE + "roleplayer-constraint"); - - public static final Locator OTHERROLE_CONSTRAINT = _createLocator(_BASE + "otherrole-constraint"); - - public static final Locator TOPIC_OCCURRENCE_CONSTRAINT = _createLocator(_BASE + "topicoccurrence-constraint"); - - public static final Locator UNIQUE_OCCURRENCE_CONSTRAINT = _createLocator(_BASE + "uniqueoccurrence-constraint"); - + public static final Locator REGULAR_EXPRESSION_CONSTRAINT = _createLocator(_BASE + "regular-expression-constraint"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lh...@us...> - 2009-08-14 11:43:37
|
Revision: 347 http://tinytim.svn.sourceforge.net/tinytim/?rev=347&view=rev Author: lheuer Date: 2009-08-14 11:43:24 +0000 (Fri, 14 Aug 2009) Log Message: ----------- - Added package visible getter to tinytim/mio/TinyTimMapInputHandler to retrieve the topic map - Added tmdm:subject - Added docs to TMCL and deprecated some constants Modified Paths: -------------- tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java Modified: tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-08-13 12:40:55 UTC (rev 346) +++ tinytim/trunk/src/main/java/org/tinytim/mio/TinyTimMapInputHandler.java 2009-08-14 11:43:24 UTC (rev 347) @@ -100,6 +100,15 @@ _delayedItemIdentifiers = CollectionFactory.createIdentityMap(_DELAYED_ITEM_IDENTIFIER_SIZE); } + /** + * Returns the underlying topic map. + * + * @return The topic map this handler operates upon. + */ + TopicMap getTopicMap() { + return _tm; + } + /* (non-Javadoc) * @see com.semagia.mio.IMapHandler#startTopicMap() */ Modified: tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java 2009-08-13 12:40:55 UTC (rev 346) +++ tinytim/trunk/src/main/java/org/tinytim/voc/TMCL.java 2009-08-14 11:43:24 UTC (rev 347) @@ -20,7 +20,7 @@ /** * Constants for TMCL PSIs. * <p> - * These PSIs are not stable yet. + * CAUTION: These PSIs are not stable yet. * </p> * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> @@ -35,107 +35,417 @@ private static final String _BASE = Namespace.TMCL; - // Topic types + /** + * Core concept of a constraint. + * + * Used as constraint (topic) type. + */ + public static final Locator CONSTRAINT = _createLocator(_BASE + "constraint"); + + /* + * Topic types + * + * c.f. 6. TMCL Declarations + */ + /** + * Indicates that a topic may be used as a topic type. + * + * Used as topic type. + */ public static final Locator TOPIC_TYPE = _createLocator(_BASE + "topic-type"); + /** + * Indicates that a topic may be used as association type. + * + * Used as topic type. + */ public static final Locator ASSOCIATION_TYPE = _createLocator(_BASE + "association-type"); + /** + * Indicates that a topic may be used as role type. + * + * Used as topic type. + */ public static final Locator ROLE_TYPE = _createLocator(_BASE + "role-type"); + /** + * Indicates that a topic may be used as occurrence type. + * + * Used as topic type. + */ public static final Locator OCCURRENCE_TYPE = _createLocator(_BASE + "occurrence-type"); + /** + * Indicates that a topic may be used as name type. + * + * Used as topic type. + */ public static final Locator NAME_TYPE = _createLocator(_BASE + "name-type"); + /** + * The tmcl:overlap-declaration is used to declare that the sets of + * instances of two or more topic types are non-disjoint (that is, that + * they may overlap). + * The default is that the instance sets of different topic types are + * disjoint. + * + * Used as topic type. + */ + public static final Locator OVERLAP_DECLARATION = _createLocator(_BASE + "overlap-declaration"); + + @Deprecated + //FIXME: What's the replacement for this PSI? public static final Locator SCOPE_TYPE = _createLocator(_BASE + "scope-type"); + + /* + * Constraint types + * c.f. 7 TMCL Constraint Types + */ + + /** + * The tmcl:abstract-constraint provides a way to express that a given topic + * type must not have any direct instances + * + * Used as constraint (topic) type. + * + * See 7.2 Abstract Topic Type Constraint + */ + public static final Locator ABSTRACT_CONSTRAINT = _createLocator(_BASE + "abstract-constraint"); + + /** + * Use {@link #ABSTRACT_CONSTRAINT} + */ + @Deprecated + public static final Locator ABSTRACT_TOPIC_TYPE_CONSTRAINT = ABSTRACT_CONSTRAINT; + + /** + * + * + * Used as association type. + * + * See 7.2 Abstract Topic Type Constraint + */ + public static final Locator CONSTRAINED_TOPIC_TYPE = _createLocator(_BASE + "constrained-topic-type"); + + /** + * A subject identifier constraint provides a way to constrain the subject + * identifiers of instances of a given topic type. + * + * Used as constraint (topic) type. + * + * See 7.3 Subject Identifier Constraint + */ + public static final Locator SUBJECT_IDENTIFIER_CONSTRAINT = _createLocator(_BASE + "subject-identifier-constraint"); + + /** + * A subject locator constraint provides a way to constrain the subject + * locators of instances of a given topic type. + * + * Used as constraint (topic) type. + * + * See 7.4 Subject Locator Constraint + */ + public static final Locator SUBJECT_LOCATOR_CONSTRAINT = _createLocator(_BASE + "subject-locator-constraint"); + + + /** + * A topic name constraint provides a way to constrain the type and + * cardinality of topic names for instances of a given topic type. + * + * Used as constraint (topic) type. + * + * See 7.5 Topic Name Constraint + */ + public static final Locator TOPIC_NAME_CONSTRAINT = _createLocator(_BASE + "topic-name-constraint"); + + /** + * A topic occurrence constraint defines a way to constrain the type and + * cardinality of occurrences connected to a topic of a given type. + * + * Used as constraint (topic) type. + * + * See 7.6 Topic Occurrence Constraint + */ + public static final Locator TOPIC_OCCURRENCE_CONSTRAINT = _createLocator(_BASE + "topic-occurrence-constraint"); + + /** + * A topic role constraint constrains the types of roles topics of a given + * type can play in associations of a given type. + * It can also be seen as constraining the types of topics which may play + * roles of a given type in associations of a given type. + * + * Used as constraint (topic) type. + * + * See 7.7 Topic Role Constraint + */ + public static final Locator TOPIC_ROLE_CONSTRAINT = _createLocator(_BASE + "topic-role-constraint"); + + /** + * Use {@link #TOPIC_ROLE_CONSTRAINT}. + */ + @Deprecated + public static final Locator ROLE_PLAYER_CONSTRAINT = TOPIC_ROLE_CONSTRAINT; + + /** + * Constrains the types of topics which may appear in the scope of a name, + * occurrence, or association of a particular type. + * + * Used as constraint (topic) type. + * + * See 7.8 Scope Constraint. + */ + public static final Locator SCOPE_CONSTRAINT = _createLocator(_BASE + "scope-constraint"); + + /** + * Constrains whether or not names, occurrence, and associations of a given + * type may be reified, and if so, what the type of the reifying topic must + * be. + * + * Used as constraint (topic) type. + * + * See 7.9 Reifier Constraint + */ + public static final Locator REIFIER_CONSTRAINT = _createLocator(_BASE + "reifier-constraint"); + + /** + * Constrains what types of statements topics of a given type may reify. + * + * Used as constraint (topic) type. + * + * See 7.10 Topic Reifies Constraint + */ + public static final Locator TOPIC_REIFIES_CONSTRAINT = _createLocator(_BASE + "topic-reifies-constraint"); + + /** + * Constrains the number of roles of a particular type that may appear in + * associations of a given type. + * + * Used as constraint (topic) type. + * + * See 7.11 Association Role Constraint + */ + public static final Locator ASSOCIATION_ROLE_CONSTRAINT = _createLocator(_BASE + "association-role-constraint"); + + /** + * Provides a way to restrict which combinations of topic types are allowed + * to appear in associations of a certain type together. + * + * Used as constraint (topic) type. + * + * See 7.12 Role Combination Constraint + */ + public static final Locator ROLE_COMBINATION_CONSTRAINT = _createLocator(_BASE + "role-combination-constraint"); + + /** + * Provides a way to constrain the allowed datatype of an occurrence of a + * given type. + * + * Used as constraint (topic) type. + * + * See 7.13 Occurrence Data Type Constraint. + */ + public static final Locator OCCURRENCE_DATATYPE_CONSTRAINT = _createLocator(_BASE + "occurrence-datatype-constraint"); + + /** + * Provides a way to require all names or occurrences of a given type to + * have different values. + * + * Used as constraint (topic) type. + * + * See 7.14 Unique Value Constraint + */ + public static final Locator UNIQUE_VALUE_CONSTRAINT = _createLocator(_BASE + "unique-value-constraint"); + + /** + * Provides a mechanism for requiring that all values of a given name or + * occurrence type must match a given regular expression. + * + * Used as constraint (topic) type. + * + * See 7.15 Regular Expression Constraint + */ + public static final Locator REGULAR_EXPRESSION_CONSTRAINT = _createLocator(_BASE + "regular-expression-constraint"); + + // Role types + /** + * + * Used as role type. + */ public static final Locator ALLOWS = _createLocator(_BASE + "allows"); + /** + * + * Used as role type. + */ public static final Locator ALLOWED = _createLocator(_BASE + "allowed"); + /** + * + * Used as role type. + */ public static final Locator CONSTRAINS = _createLocator(_BASE + "constrains"); + /** + * + * Used as role type. + */ public static final Locator CONSTRAINED = _createLocator(_BASE + "constrained"); + /** + * + * Used as role type. + */ public static final Locator CONTAINER = _createLocator(_BASE + "container"); + /** + * + * Used as role type. + */ public static final Locator CONTAINEE = _createLocator(_BASE + "containee"); - // Association types - applies-to is no more - public static final Locator CONSTRAINED_TOPIC_TYPE = _createLocator(_BASE + "constrained-topic-type"); - + /* + * Association types + */ + + /** + * + * Used as association type. + */ public static final Locator CONSTRAINED_STATEMENT = _createLocator(_BASE + "constrained-statement"); + /** + * + * Used as association type. + */ public static final Locator CONSTRAINED_ROLE = _createLocator(_BASE + "constrained-role"); + /** + * + * Used as association type. + */ public static final Locator OVERLAPS = _createLocator(_BASE + "overlaps"); + /** + * + * Used as association type. + */ public static final Locator ALLOWED_SCOPE = _createLocator(_BASE + "allowed-scope"); + /** + * + * Used as association type. + */ public static final Locator ALLOWED_REIFIER = _createLocator(_BASE + "allowed-reifier"); + /** + * + * Used as association type. + */ public static final Locator OTHER_CONSTRAINED_TOPIC_TYPE = _createLocator(_BASE + "other-constrained-topic-type"); + /** + * + * Used as association type. + */ public static final Locator OTHER_CONSTRAINED_ROLE = _createLocator(_BASE + "other-constrained-role"); + /** + * + * Used as association type. + */ public static final Locator BELONGS_TO_SCHEMA = _createLocator(_BASE + "belongs-to-schema"); // Model topics - public static final Locator SCHEMA = _createLocator(_BASE + "schema"); - - public static final Locator CONSTRAINT = _createLocator(_BASE + "constraint"); - public static final Locator VALIDATION_EXPRESSION = _createLocator(_BASE + "validation-expression"); + /** + * Indicates a minimum cardinality. + * + * Used as occurrence type. + */ public static final Locator CARD_MIN = _createLocator(_BASE + "card-min"); + /** + * Indicates a maximum cardinality. + * + * Used as occurrence type. + */ public static final Locator CARD_MAX = _createLocator(_BASE + "card-max"); + /** + * Used to define a regular expression. + * + * Used as occurrence type. + */ public static final Locator REGEXP = _createLocator(_BASE + "regexp"); + /** + * Used to define the datatype (an IRI) of an occurrence or variant. + * + * Used as occurrence type. + */ public static final Locator DATATYPE = _createLocator(_BASE + "datatype"); - - public static final Locator VERSION = _createLocator(_BASE + "version"); - public static final Locator DESCRIPTION = _createLocator(_BASE + "description"); + /* + * 10 Schema Documentation. + */ - public static final Locator COMMENT = _createLocator(_BASE + "comment"); + /** + * + * Used as topic type. + * + * See 10.2 The Schema Topic + */ + public static final Locator SCHEMA = _createLocator(_BASE + "schema"); - public static final Locator SEE_ALSO = _createLocator(_BASE + "see-also"); - - // Constraint types + /** + * Used to attach some identifier of the schema's version to the schema + * topic. + * + * Used as occurrence type. + * See 10.2 The Schema Topic + */ + public static final Locator VERSION = _createLocator(_BASE + "version"); - public static final Locator ABSTRACT_TOPIC_TYPE_CONSTRAINT = _createLocator(_BASE + "abstract-constraint"); - public static final Locator OVERLAP_DECLARATION = _createLocator(_BASE + "overlap-declaration"); + /* + * 10.3 Documentation Occurrences + */ - public static final Locator SUBJECT_IDENTIFIER_CONSTRAINT = _createLocator(_BASE + "subject-identifier-constraint"); - - public static final Locator SUBJECT_LOCATOR_CONSTRAINT = _createLocator(_BASE + "subject-locator-constraint"); + /** + * Used to attach a textual description of a TMCL construct to it inside + * the topic map. + * + * Used as occurrence type. + * + * See 10.3 Documentation Occurrences + */ + public static final Locator DESCRIPTION = _createLocator(_BASE + "description"); - public static final Locator TOPIC_NAME_CONSTRAINT = _createLocator(_BASE + "topic-name-constraint"); + /** + * Used to attach any textual information to a TMCL construct inside the + * topic map. + * + * Used as occurrence type. + * + * See 10.3 Documentation Occurrences + */ + public static final Locator COMMENT = _createLocator(_BASE + "comment"); - public static final Locator TOPIC_OCCURRENCE_CONSTRAINT = _createLocator(_BASE + "topic-occurrence-constraint"); - - public static final Locator ROLE_PLAYER_CONSTRAINT = _createLocator(_BASE + "role-player-constraint"); - - public static final Locator SCOPE_CONSTRAINT = _createLocator(_BASE + "scope-constraint"); - - public static final Locator REIFIER_CONSTRAINT = _createLocator(_BASE + "reifier-constraint"); + /** + * Used to attach a to a TMCL construct a reference to any kind of external + * information about that construct. + * + * Used as occurrence type. + * + * See 10.3 Documentation Occurrences + */ + public static final Locator SEE_ALSO = _createLocator(_BASE + "see-also"); - public static final Locator TOPIC_REIFIES_CONSTRAINT = _createLocator(_BASE + "topic-reifies-constraint"); - - public static final Locator ASSOCIATION_ROLE_CONSTRAINT = _createLocator(_BASE + "association-role-constraint"); - - public static final Locator ROLE_COMBINATION_CONSTRAINT = _createLocator(_BASE + "role-combination-constraint"); - - public static final Locator OCCURRENCE_DATATYPE_CONSTRAINT = _createLocator(_BASE + "occurrence-datatype-constraint"); - - public static final Locator UNIQUE_VALUE_CONSTRAINT = _createLocator(_BASE + "unique-value-constraint"); - - public static final Locator REGULAR_EXPRESSION_CONSTRAINT = _createLocator(_BASE + "regular-expression-constraint"); } Modified: tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java =================================================================== --- tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java 2009-08-13 12:40:55 UTC (rev 346) +++ tinytim/trunk/src/main/java/org/tinytim/voc/TMDM.java 2009-08-14 11:43:24 UTC (rev 347) @@ -1,5 +1,5 @@ /* - * Copyright 2008 Lars Heuer (heuer[at]semagia.com) + * Copyright 2008 - 2009 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. @@ -20,8 +20,6 @@ /** * Constants for TMDM 1.0 (model) PSIs. * - * Copied with permission from the Semagia MIO project. - * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> * @version $Rev$ - $Date$ */ @@ -34,6 +32,11 @@ private static final String _BASE = Namespace.TMDM_MODEL; /** + * Core concept of a subject. + */ + public static final Locator SUBJECT = _createLocator(_BASE + "subject"); + + /** * Core concept of type-instance relationships. * Used as association type. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |