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