|
From: <lh...@us...> - 2008-04-20 13:37:15
|
Revision: 12
http://tinytim.svn.sourceforge.net/tinytim/?rev=12&view=rev
Author: lheuer
Date: 2008-04-20 06:23:18 -0700 (Sun, 20 Apr 2008)
Log Message:
-----------
Initial import of classes / interfaces which are considered as stable
Added Paths:
-----------
tinytim/trunk/main/
tinytim/trunk/main/java/
tinytim/trunk/main/java/org/
tinytim/trunk/main/java/org/tinytim/
tinytim/trunk/main/java/org/tinytim/Event.java
tinytim/trunk/main/java/org/tinytim/ICollectionFactory.java
tinytim/trunk/main/java/org/tinytim/IConstruct.java
tinytim/trunk/main/java/org/tinytim/IEventHandler.java
tinytim/trunk/main/java/org/tinytim/IEventPublisher.java
tinytim/trunk/main/java/org/tinytim/IReifiable.java
tinytim/trunk/main/java/org/tinytim/JavaCollectionFactory.java
tinytim/trunk/main/java/org/tinytim/Property.java
tinytim/trunk/main/java/org/tinytim/SignatureGenerator.java
tinytim/trunk/main/java/org/tinytim/TMAPIFeature.java
tinytim/trunk/main/java/org/tinytim/TroveCollectionFactory.java
Added: tinytim/trunk/main/java/org/tinytim/Event.java
===================================================================
--- tinytim/trunk/main/java/org/tinytim/Event.java (rev 0)
+++ tinytim/trunk/main/java/org/tinytim/Event.java 2008-04-20 13:23:18 UTC (rev 12)
@@ -0,0 +1,156 @@
+/*
+ * 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
+
+}
Property changes on: tinytim/trunk/main/java/org/tinytim/Event.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/main/java/org/tinytim/ICollectionFactory.java
===================================================================
--- tinytim/trunk/main/java/org/tinytim/ICollectionFactory.java (rev 0)
+++ tinytim/trunk/main/java/org/tinytim/ICollectionFactory.java 2008-04-20 13:23:18 UTC (rev 12)
@@ -0,0 +1,72 @@
+/*
+ * 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);
+
+}
Property changes on: tinytim/trunk/main/java/org/tinytim/ICollectionFactory.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/main/java/org/tinytim/IConstruct.java
===================================================================
--- tinytim/trunk/main/java/org/tinytim/IConstruct.java (rev 0)
+++ tinytim/trunk/main/java/org/tinytim/IConstruct.java 2008-04-20 13:23:18 UTC (rev 12)
@@ -0,0 +1,66 @@
+/*
+ * 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);
+
+}
Property changes on: tinytim/trunk/main/java/org/tinytim/IConstruct.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/main/java/org/tinytim/IEventHandler.java
===================================================================
--- tinytim/trunk/main/java/org/tinytim/IEventHandler.java (rev 0)
+++ tinytim/trunk/main/java/org/tinytim/IEventHandler.java 2008-04-20 13:23:18 UTC (rev 12)
@@ -0,0 +1,47 @@
+/*
+ * 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);
+
+}
Property changes on: tinytim/trunk/main/java/org/tinytim/IEventHandler.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/main/java/org/tinytim/IEventPublisher.java
===================================================================
--- tinytim/trunk/main/java/org/tinytim/IEventPublisher.java (rev 0)
+++ tinytim/trunk/main/java/org/tinytim/IEventPublisher.java 2008-04-20 13:23:18 UTC (rev 12)
@@ -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;
+
+/**
+ * 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/main/java/org/tinytim/IEventPublisher.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/main/java/org/tinytim/IReifiable.java
===================================================================
--- tinytim/trunk/main/java/org/tinytim/IReifiable.java (rev 0)
+++ tinytim/trunk/main/java/org/tinytim/IReifiable.java 2008-04-20 13:23:18 UTC (rev 12)
@@ -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;
+
+import org.tmapi.core.Topic;
+
+/**
+ * Reifiable Topic Maps construct.
+ *
+ * Every Topic Maps construct != topic is reifiable.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+public interface IReifiable extends IConstruct {
+
+ /**
+ * Returns the reifier of this construct.
+ *
+ * @return The topic that reifies this construct or <code>null</code> if
+ * this construct has no reifier.
+ */
+ public Topic getReifier();
+
+ /**
+ * Sets the reifier of this construct.
+ *
+ * If the <code>reifier</code> reifies another Topic Maps construct, a
+ * {@link org.tmapi.core.ModelConstraintException} is thrown.
+ *
+ * @param reifier The reifier or <code>null</code>.
+ */
+ public void setReifier(Topic reifier);
+}
Property changes on: tinytim/trunk/main/java/org/tinytim/IReifiable.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/main/java/org/tinytim/JavaCollectionFactory.java
===================================================================
--- tinytim/trunk/main/java/org/tinytim/JavaCollectionFactory.java (rev 0)
+++ tinytim/trunk/main/java/org/tinytim/JavaCollectionFactory.java 2008-04-20 13:23:18 UTC (rev 12)
@@ -0,0 +1,64 @@
+/*
+ * 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.HashMap;
+import java.util.HashSet;
+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.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>();
+ }
+
+}
Property changes on: tinytim/trunk/main/java/org/tinytim/JavaCollectionFactory.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/main/java/org/tinytim/Property.java
===================================================================
--- tinytim/trunk/main/java/org/tinytim/Property.java (rev 0)
+++ tinytim/trunk/main/java/org/tinytim/Property.java 2008-04-20 13:23:18 UTC (rev 12)
@@ -0,0 +1,44 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim;
+
+/**
+ * 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.CollectionFactory";
+}
Property changes on: tinytim/trunk/main/java/org/tinytim/Property.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/main/java/org/tinytim/SignatureGenerator.java
===================================================================
--- tinytim/trunk/main/java/org/tinytim/SignatureGenerator.java (rev 0)
+++ tinytim/trunk/main/java/org/tinytim/SignatureGenerator.java 2008-04-20 13:23:18 UTC (rev 12)
@@ -0,0 +1,199 @@
+/*
+ * This is tinyTiM, a tiny Topic Maps engine.
+ *
+ * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+package org.tinytim;
+
+import java.util.Arrays;
+import java.util.Set;
+
+import org.tmapi.core.Association;
+import org.tmapi.core.AssociationRole;
+import org.tmapi.core.Occurrence;
+import org.tmapi.core.ScopedObject;
+import org.tmapi.core.Topic;
+import org.tmapi.core.TopicName;
+import org.tmapi.core.Variant;
+
+/**
+ * Generates signatures for Topic Maps constructs.
+ *
+ * This class can be used to detect duplicates: If two Topic Maps constructs
+ * have the same signature, they should be merged (if they belong to the same
+ * parent).
+ *
+ * Neither the topic map, the parent, the reifier, nor item identifiers
+ * are taken into account.
+ *
+ * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
+ * @version $Rev:$ - $Date:$
+ */
+final class SignatureGenerator {
+
+ private SignatureGenerator() {
+ // noop.
+ }
+
+ /**
+ * Returns the signature of an association.
+ *
+ * Beside of the type and scope of the association, the roles are
+ * taken into account.
+ * The parent is not taken into account.
+ *
+ * @param assoc The association to generate the signature for.
+ * @return The association's signature.
+ */
+ @SuppressWarnings("unchecked")
+ public static String generateSignature(Association assoc) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(_generateTypeSignature((ITyped)assoc))
+ .append('s')
+ .append(_generateScopeSignature((IScoped)assoc))
+ .append('.');
+ Set<AssociationRole> roles = assoc.getAssociationRoles();
+ String[] roleSigs = new String[roles.size()];
+ int i = 0;
+ for (AssociationRole role : roles) {
+ roleSigs[i++] = generateSignature(role);
+ }
+ Arrays.sort(roleSigs);
+ for (String sig : roleSigs) {
+ sb.append(sig)
+ .append('.');
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Generates the signature of a role.
+ *
+ * @param role The role to generate the signature for.
+ * @return The role's signature.
+ */
+ public static String generateSignature(AssociationRole role) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(_generateTypeSignature((ITyped)role))
+ .append('p')
+ .append(role.getPlayer() == null ? "" : role.getPlayer().getObjectId());
+ return sb.toString();
+ }
+
+ /**
+ * Generates the signature for an occurrence.
+ *
+ * @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((ITyped)occ))
+ .append('s')
+ .append(_generateScopeSignature((IScoped)occ))
+ .append('v')
+ .append(_generateDataSignature((IDatatypeAwareConstruct) occ));
+ return sb.toString();
+ }
+
+ /**
+ * Generates a signature for the specified <code>name</code>.
+ *
+ * The parent and the variants are not taken into account.
+ *
+ * @param name The name to generate the signature for.
+ * @return A signature for the name.
+ */
+ public static String generateSignature(TopicName name) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(_generateTypeSignature((ITyped)name))
+ .append('s')
+ .append(_generateScopeSignature((IScoped)name))
+ .append('v')
+ .append(name.getValue() == null ? "" : name.getValue());
+ return sb.toString();
+ }
+
+ /**
+ * Generates a signature for the specified <code>variant</code>.
+ *
+ * @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((IScoped)variant))
+ .append('v')
+ .append(_generateDataSignature((IDatatypeAwareConstruct) variant));
+ return sb.toString();
+ }
+
+ /**
+ * Returns a signature for a value/datatype pair.
+ *
+ * @param construct An occurrence or variant.
+ * @return The signature.
+ */
+ private static String _generateDataSignature(IDatatypeAwareConstruct construct) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(construct.getValue2())
+ .append('.')
+ .append(construct.getDatatype().getReference());
+ return sb.toString();
+ }
+
+ /**
+ * Returns a signature for the type of a typed Topic Maps construct.
+ *
+ * @param typed The typed Topic Maps construct.
+ * @return The signature.
+ */
+ private static String _generateTypeSignature(ITyped typed) {
+ Topic type = typed.getType();
+ return type == null ? "" : type.getObjectId();
+ }
+
+ /**
+ * Returns a signature for the scope of a scoped Topic Maps construct.
+ *
+ * This function returns the signature for the scope, only! No other
+ * properties of the scoped Topic Maps construct are taken into account!
+ *
+ * @param scoped The scoped Topic Maps construct.
+ * @return The signature.
+ */
+ private static String _generateScopeSignature(IScoped scoped) {
+ Set<Topic> scope = scoped.getScope();
+ if (scope.isEmpty()) {
+ return "";
+ }
+ String[] ids = new String[scope.size()];
+ int i = 0;
+ for (Topic topic : scope) {
+ ids[i++] = topic.getObjectId();
+ }
+ Arrays.sort(ids);
+ StringBuilder sb = new StringBuilder();
+ for (String id : ids) {
+ sb.append(id)
+ .append('.');
+ }
+ return sb.toString();
+ }
+
+}
Property changes on: tinytim/trunk/main/java/org/tinytim/SignatureGenerator.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/main/java/org/tinytim/TMAPIFeature.java
===================================================================
--- tinytim/trunk/main/java/org/tinytim/TMAPIFeature.java (rev 0)
+++ tinytim/trunk/main/java/org/tinytim/TMAPIFeature.java 2008-04-20 13:23:18 UTC (rev 12)
@@ -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;
+
+/**
+ * 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:$
+ */
+final class TMAPIFeature {
+
+ private TMAPIFeature() {
+ // 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/main/java/org/tinytim/TMAPIFeature.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
Added: tinytim/trunk/main/java/org/tinytim/TroveCollectionFactory.java
===================================================================
--- tinytim/trunk/main/java/org/tinytim/TroveCollectionFactory.java (rev 0)
+++ tinytim/trunk/main/java/org/tinytim/TroveCollectionFactory.java 2008-04-20 13:23:18 UTC (rev 12)
@@ -0,0 +1,66 @@
+/*
+ * 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 gnu.trove.THashMap;
+import gnu.trove.THashSet;
+
+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.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>();
+ }
+
+}
Property changes on: tinytim/trunk/main/java/org/tinytim/TroveCollectionFactory.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date Id
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|