From: <lh...@us...> - 2008-04-20 13:41:34
|
Revision: 14 http://tinytim.svn.sourceforge.net/tinytim/?rev=14&view=rev Author: lheuer Date: 2008-04-20 06:28:10 -0700 (Sun, 20 Apr 2008) Log Message: ----------- Initial import of the TopicMapsSystem and the TMSysFactory Added Paths: ----------- tinytim/trunk/main/java/org/tinytim/TopicMapSystemFactoryImpl.java tinytim/trunk/main/java/org/tinytim/TopicMapSystemImpl.java Added: tinytim/trunk/main/java/org/tinytim/TopicMapSystemFactoryImpl.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/TopicMapSystemFactoryImpl.java (rev 0) +++ tinytim/trunk/main/java/org/tinytim/TopicMapSystemFactoryImpl.java 2008-04-20 13:28:10 UTC (rev 14) @@ -0,0 +1,191 @@ +/* + * 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.Map; +import java.util.Properties; + +import org.tmapi.core.FeatureNotRecognizedException; +import org.tmapi.core.FeatureNotSupportedException; +import org.tmapi.core.TMAPIException; +import org.tmapi.core.TopicMapSystem; +import org.tmapi.core.TopicMapSystemFactory; + +/** + * {@link org.tmapi.core.TopicMapSystemFactory} implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class TopicMapSystemFactoryImpl extends TopicMapSystemFactory { + + private static final String _COLL_FACTORY_JAVA = "org.tinytim.JavaCollectionFactory"; + private static final String _COLL_FACTORY_TROVE = "org.tinytim.TroveCollectionFactory"; + private static final FeatureInfo[] _FEATURES = new FeatureInfo[] { + // Feature IRI, default value, fixed? + new FeatureInfo(TMAPIFeature.NOTATION_URI, true, true), + new FeatureInfo(TMAPIFeature.XTM_1_0, false, true), + new FeatureInfo(TMAPIFeature.XTM_1_1, true, true), + new FeatureInfo(TMAPIFeature.AUTOMERGE, false, true), + new FeatureInfo(TMAPIFeature.TNC, false, true), + new FeatureInfo(TMAPIFeature.READ_ONLY, false, true) + }; + + private Properties _properties; + private Map<String, Boolean> _features; + + public TopicMapSystemFactoryImpl() { + _properties = new Properties(); + _features = new HashMap<String, Boolean>(_FEATURES.length); + for (FeatureInfo feature: _FEATURES) { + _features.put(feature.name, feature.defaultValue); + } + _properties.setProperty(Property.COLLECTION_FACTORY, _COLL_FACTORY_JAVA); + try { + // Probe if Trove is available. + Class.forName("gnu.trove.THashSet"); + _properties.setProperty(Property.COLLECTION_FACTORY, _COLL_FACTORY_TROVE); + } + catch (Exception ex) { + // noop. + } + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystemFactory#newTopicMapSystem() + */ + @Override + public TopicMapSystem newTopicMapSystem() throws TMAPIException { + return new TopicMapSystemImpl(_createCollectionFactory(), new HashMap<String, Boolean>(_features), new Properties(_properties)); + } + + /** + * Creates a collection factory based according to the + * {@link Property#COLLECTION_FACTORY} value. If the collection factory + * is not available, a default collection factory implementation is returned. + * + * @return A collection factory. + */ + private ICollectionFactory _createCollectionFactory() { + String className = _properties.getProperty(Property.COLLECTION_FACTORY, _COLL_FACTORY_JAVA); + try { + return (ICollectionFactory) Class.forName(className).newInstance(); + } + catch (Exception ex) { + // Irgendwas geht immer ;) + return new JavaCollectionFactory(); + } + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystemFactory#getFeature(java.lang.String) + */ + @Override + public boolean getFeature(String featureName) throws FeatureNotRecognizedException { + final Boolean supported = _features.get(featureName); + if (supported == null) { + reportFeatureNotRecognized(featureName); + } + return supported.booleanValue(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystemFactory#hasFeature(java.lang.String) + */ + @Override + public boolean hasFeature(String featureName) { + return _features.containsKey(featureName); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystemFactory#setFeature(java.lang.String, boolean) + */ + @Override + public void setFeature(String featureName, boolean enabled) + throws FeatureNotSupportedException, FeatureNotRecognizedException { + if (!_features.containsKey(featureName)) { + reportFeatureNotRecognized(featureName); + } + FeatureInfo feature = null; + for (FeatureInfo feature_: _FEATURES) { + if (feature_.name.equals(featureName)) { + feature = feature_; + } + } + if (feature.fixed && feature.defaultValue != enabled) { + throw new FeatureNotSupportedException("The feature '" + featureName + "' cannot be changed."); + } + _features.put(featureName, enabled); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystemFactory#getProperty(java.lang.String) + */ + @Override + public String getProperty(String propertyName) { + return _properties.getProperty(propertyName); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystemFactory#setProperties(java.util.Properties) + */ + @Override + public void setProperties(Properties properties) { + _properties = new Properties(properties); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystemFactory#setProperty(java.lang.String, java.lang.String) + */ + @Override + public void setProperty(String propertyName, String value) { + _properties.setProperty(propertyName, value); + } + + /** + * Throws a {@link org.tmapi.core.FeatureNotRecognizedException} with a + * message. + * + * @param featureName The name of the feature which is unknown. + * @throws FeatureNotRecognizedException Thrown in any case. + */ + static void reportFeatureNotRecognized(String featureName) throws FeatureNotRecognizedException { + throw new FeatureNotRecognizedException("The feature '" + featureName + "' is unknown"); + } + + /** + * Simple structure that holds a feature name, the default value and an + * indication if the feature is changable. + */ + private static class FeatureInfo { + String name; + boolean defaultValue; + boolean fixed; + + FeatureInfo(String name, boolean defaultValue, boolean fixed) { + this.name = name; + this.defaultValue = defaultValue; + this.fixed = fixed; + } + } + +} Property changes on: tinytim/trunk/main/java/org/tinytim/TopicMapSystemFactoryImpl.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/main/java/org/tinytim/TopicMapSystemImpl.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/TopicMapSystemImpl.java (rev 0) +++ tinytim/trunk/main/java/org/tinytim/TopicMapSystemImpl.java 2008-04-20 13:28:10 UTC (rev 14) @@ -0,0 +1,166 @@ +/* + * 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.Properties; +import java.util.Set; + +import org.tmapi.core.FeatureNotRecognizedException; +import org.tmapi.core.Locator; +import org.tmapi.core.TopicMap; +import org.tmapi.core.TopicMapExistsException; +import org.tmapi.core.TopicMapSystem; + +/** + * {@link org.tmapi.core.TopicMapSystem} implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +final class TopicMapSystemImpl implements TopicMapSystem { + + private Map<Locator, TopicMap> _topicMaps; + private Properties _properties; + private Map<String, Boolean> _features; + private ICollectionFactory _collectionFactory; + + + TopicMapSystemImpl(ICollectionFactory collFactory, Map<String, Boolean> features, Properties properties) { + _collectionFactory = collFactory; + _features = features; + _properties = properties; + _topicMaps = collFactory.<Locator, TopicMap>createMap(); + } + + /** + * Returns the collection factory. + * + * @return The collection factory. + */ + ICollectionFactory getCollectionFactory() { + return _collectionFactory; + } + + /** + * Removes a topic map from this system. + * + * @param tm The topic map to remove. + */ + void removeTopicMap(TopicMap tm) { + _topicMaps.remove(tm.getBaseLocator()); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#createTopicMap(java.lang.String) + */ + public TopicMap createTopicMap(String baseLocator) throws TopicMapExistsException { + return _createTopicMap(new IRI(baseLocator)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#createTopicMap(java.lang.String, java.lang.String) + */ + public TopicMap createTopicMap(String reference, String notation) + throws TopicMapExistsException { + assert "URI".equals(notation); + return _createTopicMap(new IRI(reference)); + } + + /** + * Creates a topic map with the specified <code>locator</code>. + * + * @param locator The locator which is used to address the topic map. + * @return A newly created topic map instance. + * @throws TopicMapExistsException If a topic map with the specified <code>locator</code> + * exists. + */ + private TopicMap _createTopicMap(Locator locator) throws TopicMapExistsException { + if (_topicMaps.containsKey(locator)) { + throw new TopicMapExistsException("A topic map with the IRI + '" + locator.getReference() + "' exists in the system"); + } + TopicMap tm = new TopicMapImpl(this, locator); + _topicMaps.put(locator, tm); + return tm; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#getBaseLocators() + */ + public Set<Locator> getBaseLocators() { + //FIXME: For some reason the TMAPI tests assume that this method returns a copy + Set<Locator> locs = _topicMaps.keySet(); + Set<Locator> locators = _collectionFactory.createSet(locs.size()); + locators.addAll(locs); + return locators; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#getFeature(java.lang.String) + */ + public boolean getFeature(String featureName) throws FeatureNotRecognizedException { + final Boolean supported = _features.get(featureName); + if (supported == null) { + TopicMapSystemFactoryImpl.reportFeatureNotRecognized(featureName); + } + return supported; + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#getProperty(java.lang.String) + */ + public String getProperty(String propertyName) { + return _properties.getProperty(propertyName); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#getTopicMap(java.lang.String) + */ + public TopicMap getTopicMap(String reference) { + return getTopicMap(new IRI(reference)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#getTopicMap(org.tmapi.core.Locator) + */ + public TopicMap getTopicMap(Locator iri) { + return _topicMaps.get(iri); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#getTopicMap(java.lang.String, java.lang.String) + */ + public TopicMap getTopicMap(String reference, String notation) { + assert "URI".equals(notation); + return getTopicMap(new IRI(reference)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.TopicMapSystem#close() + */ + public void close() { + _features = null; + _properties = null; + _topicMaps = null; + _collectionFactory = null; + } + +} Property changes on: tinytim/trunk/main/java/org/tinytim/TopicMapSystemImpl.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. |
From: <lh...@us...> - 2008-04-20 14:35:31
|
Revision: 15 http://tinytim.svn.sourceforge.net/tinytim/?rev=15&view=rev Author: lheuer Date: 2008-04-20 07:35:37 -0700 (Sun, 20 Apr 2008) Log Message: ----------- Initial import of the base classes for Topic Maps constructs. Added Paths: ----------- tinytim/trunk/main/java/org/tinytim/Construct.java tinytim/trunk/main/java/org/tinytim/IScoped.java tinytim/trunk/main/java/org/tinytim/ITyped.java tinytim/trunk/main/java/org/tinytim/Scoped.java tinytim/trunk/main/java/org/tinytim/Typed.java Added: tinytim/trunk/main/java/org/tinytim/Construct.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/Construct.java (rev 0) +++ tinytim/trunk/main/java/org/tinytim/Construct.java 2008-04-20 14:35:37 UTC (rev 15) @@ -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; + +import java.util.Collections; +import java.util.Set; + +import org.tmapi.core.DuplicateSourceLocatorException; +import org.tmapi.core.Locator; +import org.tmapi.core.TopicMap; +import org.tmapi.core.TopicMapObject; + +/** + * 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 TopicMapObject, 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 = _tm.getCollectionFactory().createSet(); + } + if (_iids.contains(itemIdentifier)) { + return; + } + _fireEvent(Event.ADD_IID, null, itemIdentifier); + _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 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 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; + } + +} Property changes on: tinytim/trunk/main/java/org/tinytim/Construct.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/main/java/org/tinytim/IScoped.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/IScoped.java (rev 0) +++ tinytim/trunk/main/java/org/tinytim/IScoped.java 2008-04-20 14:35:37 UTC (rev 15) @@ -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; + +import java.util.Set; + +import org.tmapi.core.ScopedObject; +import org.tmapi.core.Topic; + +/** + * Scoped Topic Maps construct. + * + * Associations, occurrences, names and variants are scoped Topic Maps + * constructs. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +interface IScoped extends IConstruct, ScopedObject { + + /* (non-Javadoc) + * @see org.tmapi.core.ScopedObject#getScope() + */ + public Set<Topic> getScope(); + + /** + * Adds a theme to the scope. + * + * @param theme The theme to add. + */ + public void addTheme(Topic theme); + + /** + * Removes a theme from the scope. + * + * @param theme The theme to remove. + */ + public void removeTheme(Topic theme); +} Property changes on: tinytim/trunk/main/java/org/tinytim/IScoped.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/main/java/org/tinytim/ITyped.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/ITyped.java (rev 0) +++ tinytim/trunk/main/java/org/tinytim/ITyped.java 2008-04-20 14:35:37 UTC (rev 15) @@ -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; + +import org.tmapi.core.Topic; + +/** + * Typed Topic Maps construct. + * + * Associations, roles, occurrences, and names are typed Topic Maps constructs. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +interface ITyped extends IConstruct { + + /** + * Returns the type of the construct. + * + * @return The typing topic or <code>null</code>. + */ + public Topic getType(); + + /** + * Sets the type of the construct. + * + * @param type The topic or <code>null</code>. + */ + public void setType(Topic type); +} Property changes on: tinytim/trunk/main/java/org/tinytim/ITyped.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/main/java/org/tinytim/Scoped.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/Scoped.java (rev 0) +++ tinytim/trunk/main/java/org/tinytim/Scoped.java 2008-04-20 14:35:37 UTC (rev 15) @@ -0,0 +1,135 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +import org.tmapi.core.Topic; + +/** + * Class that provides a "scope" property and sends events if that + * scope property changes. Additionally, this class provides + * a {@link IReifiable} implementation. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +abstract class Scoped extends Construct implements IReifiable { + + //NOTE: This class does NOT implement IScoped by intention! + // Typed extends this class and roles are not IScoped! + + private Set<Topic> _scope; + private Topic _reifier; + + Scoped(TopicMapImpl topicMap, Collection<Topic> scope) { + super(topicMap); + if (scope != null) { + for(Topic theme: scope) { + addTheme(theme); + } + } + } + + /* (non-Javadoc) + * @see org.tmapi.core.ScopedObject#getScope() + */ + public Set<Topic> getScope() { + return _scope == null ? Collections.<Topic>emptySet() + : Collections.unmodifiableSet(_scope); + } + + /* (non-Javadoc) + * @see org.tinytim.IScoped#addTheme(org.tmapi.core.Topic) + */ + public void addTheme(Topic theme) { + if (_scope != null && _scope.contains(theme)) { + return; + } + _fireEvent(Event.ADD_THEME, null, theme); + if (_scope == null) { + _scope = _tm.getCollectionFactory().createSet(4); + } + _scope.add(theme); + } + + /* (non-Javadoc) + * @see org.tinytim.IScoped#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); + } + + /* (non-Javadoc) + * @see org.tmapi.core.ScopedObject#addScopingTopic(org.tmapi.core.Topic) + */ + public void addScopingTopic(Topic theme) { + addTheme(theme); + } + + /* (non-Javadoc) + * @see org.tmapi.core.ScopedObject#removeScopingTopic(org.tmapi.core.Topic) + */ + public void removeScopingTopic(Topic theme) { + removeTheme(theme); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Association#getReifier() + */ + public Topic getReifier() { + return _reifier; + } + + /* (non-Javadoc) + * @see org.tinytim.IReifiable#setReifier(org.tmapi.core.Topic) + */ + public void setReifier(Topic reifier) { + if (_reifier == reifier) { + return; + } + _fireEvent(Event.SET_REIFIER, _reifier, reifier); + if (_reifier != null) { + ((TopicImpl) _reifier)._reified = null; + } + _reifier = reifier; + if (reifier != null) { + ((TopicImpl) reifier)._reified = this; + } + } + + /* (non-Javadoc) + * @see org.tinytim.Construct#dispose() + */ + @Override + protected void dispose() { + _scope = null; + _reifier = null; + super.dispose(); + } + +} Property changes on: tinytim/trunk/main/java/org/tinytim/Scoped.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/main/java/org/tinytim/Typed.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/Typed.java (rev 0) +++ tinytim/trunk/main/java/org/tinytim/Typed.java 2008-04-20 14:35:37 UTC (rev 15) @@ -0,0 +1,73 @@ +/* + * 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.Topic; + +/** + * Class that provides a "type" property and fires and event if that type + * property changes. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +abstract class Typed extends Scoped { + + //NOTE: This class does NOT implement ITyped by intention! + // DatatypeAwareConstruct extends this class and variants are not ITyped! + + private Topic _type; + + Typed(TopicMapImpl topicMap, Topic type, Collection<Topic> scope) { + super(topicMap, scope); + _type = type; + } + + /* (non-Javadoc) + * @see org.tinytim.ITyped#getType() + */ + public Topic getType() { + return _type; + } + + /* (non-Javadoc) + * @see org.tinytim.ITyped#setType(org.tmapi.core.Topic) + */ + public void setType(Topic type) { + if (_type == type) { + return; + } + _fireEvent(Event.SET_TYPE, _type, type); + _type = type; + } + + /* (non-Javadoc) + * @see org.tinytim.Scoped#dispose() + */ + @Override + protected void dispose() { + _type = null; + super.dispose(); + } + +} Property changes on: tinytim/trunk/main/java/org/tinytim/Typed.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. |
From: <lh...@us...> - 2008-04-20 15:33:35
|
Revision: 19 http://tinytim.svn.sourceforge.net/tinytim/?rev=19&view=rev Author: lheuer Date: 2008-04-20 08:30:50 -0700 (Sun, 20 Apr 2008) Log Message: ----------- Initial (partially) import of the index package Added Paths: ----------- tinytim/trunk/main/java/org/tinytim/index/ tinytim/trunk/main/java/org/tinytim/index/IIndex.java tinytim/trunk/main/java/org/tinytim/index/IScopedIndex.java tinytim/trunk/main/java/org/tinytim/index/ITypeInstanceIndex.java tinytim/trunk/main/java/org/tinytim/index/IndexFlagsImpl.java Added: tinytim/trunk/main/java/org/tinytim/index/IIndex.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/index/IIndex.java (rev 0) +++ tinytim/trunk/main/java/org/tinytim/index/IIndex.java 2008-04-20 15:30:50 UTC (rev 19) @@ -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.index; + +/** + * Simplified interface for indexes. + * + * Copied from the TMAPIX-project. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IIndex { + + /** + * Returns if this index is automatically kept in sync. with the + * topic map values. + * + * @return <code>true</code> if the index synchronizes itself with the + * underlying topic map, otherwise <code>false</code> + */ + public boolean isAutoUpdated(); + + /** + * Resynchronizes this index with the data in the topic map. + * + * Indexes that are automatically kept in sync should ignore this. + */ + public void reindex(); + + /** + * Closes the index. + * + * This operation is optional but useful to release resources. + * After closing the index must not be used further. + */ + public void close(); + +} Property changes on: tinytim/trunk/main/java/org/tinytim/index/IIndex.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/main/java/org/tinytim/index/IScopedIndex.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/index/IScopedIndex.java (rev 0) +++ tinytim/trunk/main/java/org/tinytim/index/IScopedIndex.java 2008-04-20 15:30:50 UTC (rev 19) @@ -0,0 +1,79 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.index; + +import java.util.Collection; + +import org.tinytim.AssociationImpl; +import org.tinytim.OccurrenceImpl; +import org.tinytim.TopicNameImpl; +import org.tinytim.VariantImpl; +import org.tmapi.core.Topic; + +/** + * Index for all scoped Topic Maps Constructs. + * + * Copied from the TMAPIX-project, this interface is not meant to be used + * outside of the tinyTiM package. Once TMAPI exposes <code>ITyped</code> this + * interface should be changed to return interfaces rather than the + * implementations. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface IScopedIndex extends IIndex { + + /** + * Returns all associations which use the specified topic as theme. + * + * @param theme The theme. + * @return A (maybe empty) collection of associations which use the theme + * in their [scope] property. + */ + public Collection<AssociationImpl> getAssociationsByTheme(Topic theme); + + /** + * Returns all occurrences which use the specified topic as theme. + * + * @param theme The theme. + * @return A (maybe empty) collection of occurrences which use the theme + * in their [scope] property. + */ + public Collection<OccurrenceImpl> getOccurrencesByTheme(Topic theme); + + /** + * Returns all names which use the specified topic as theme. + * + * @param theme The theme. + * @return A (maybe empty) collection of names which use the theme + * in their [scope] property. + */ + public Collection<TopicNameImpl> getNamesByTheme(Topic theme); + + /** + * Returns all variants which use the specified topic as theme. + * + * @param theme The theme. + * @return A (maybe empty) collection of variants which use the theme + * in their [scope] property. + */ + public Collection<VariantImpl> getVariantsByTheme(Topic theme); +} Property changes on: tinytim/trunk/main/java/org/tinytim/index/IScopedIndex.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/main/java/org/tinytim/index/ITypeInstanceIndex.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/index/ITypeInstanceIndex.java (rev 0) +++ tinytim/trunk/main/java/org/tinytim/index/ITypeInstanceIndex.java 2008-04-20 15:30:50 UTC (rev 19) @@ -0,0 +1,138 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.index; + +import java.util.Collection; + +import org.tinytim.AssociationImpl; +import org.tinytim.AssociationRoleImpl; +import org.tinytim.OccurrenceImpl; +import org.tinytim.TopicNameImpl; +import org.tmapi.core.Topic; + +/** + * Type-instance index. This index allows the retrieval of all typed Topic Maps + * constructs and topics. + * + * Copied from the TMAPIX-project, this interface is not meant to be used + * outside of the tinyTiM package. Once TMAPI exposes <code>ITyped</code> this + * interface should be changed to return interfaces rather than the + * implementations. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public interface ITypeInstanceIndex extends IIndex { + + /** + * Returns the topics that include the <code>type</code> as one of + * their types. + * + * @param type The type of topics to be returned. If <code>type</code> is + * <code>null</code> all untyped topics will be returned. + * @return A (maybe empty) collection of topic instances. + */ + public Collection<Topic> getTopics(Topic... type); + + /** + * Returns the associations that are typed by the {@link org.tmapi.core.Topic} + * <code>type</code>. + * + * @param type The type of associations to be returned. + * If <code>type</code> is <code>null</code> all untyped + * associations will be returned. + * @return A (maybe empty) collection of topic instances. + */ + public Collection<AssociationImpl> getAssociations(Topic type); + + /** + * Returns the association roles that are typed by the + * {@link org.tmapi.core.Topic} <code>type</code>. + * + * @param type The type of association roles to be returned. + * If <code>type</code> is <code>null</code> all untyped + * association roles will be returned. + * @return A (maybe empty) collection of topic instances. + */ + public Collection<AssociationRoleImpl> getRoles(Topic type); + + /** + * Returns the occurrences that are typed by the {@link org.tmapi.core.Topic} + * <code>type</code>. + * + * @param type The type of occurrences to be returned. + * If <code>type</code> is <code>null</code> all untyped + * occurrences will be returned. + * @return A (maybe empty) collection of topic instances. + */ + public Collection<OccurrenceImpl> getOccurrences(Topic type); + + /** + * Returns the topic names that are typed by the {@link org.tmapi.core.Topic} + * <code>type</code>. + * + * @param type The type of topic names to be returned. + * If <code>type</code> is <code>null</code> all untyped + * topic names will be returned. + * @return A (maybe empty) collection of topic instances. + */ + public Collection<TopicNameImpl> getNames(Topic type); + + /** + * Returns the topics that are used as type of {@link org.tmapi.core.Topic}s. + * + * @return A (maybe empty) collection of topic instances. + */ + public Collection<Topic> getTopicTypes(); + + /** + * Returns the topics that are used as type of + * {@link org.tmapi.core.Association}s. + * + * @return A (maybe empty) collection of topic instances. + */ + public Collection<Topic> getAssociationTypes(); + + /** + * Returns the topics that are used as type of + * {@link org.tmapi.core.AssociationRole}s. + * + * @return A (maybe empty) collection of topic instances. + */ + public Collection<Topic> getRoleTypes(); + + /** + * Returns the topics that are used as type of + * {@link org.tmapi.core.Occurrence}s. + * + * @return A (maybe empty) collection of topic instances. + */ + public Collection<Topic> getOccurrenceTypes(); + + /** + * Returns the topics that are used as type of + * {@link org.tmapi.core.TopicName}s. + * + * @return A (maybe empty) collection of topic instances. + */ + public Collection<Topic> getNameTypes(); + +} Property changes on: tinytim/trunk/main/java/org/tinytim/index/ITypeInstanceIndex.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Added: tinytim/trunk/main/java/org/tinytim/index/IndexFlagsImpl.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/index/IndexFlagsImpl.java (rev 0) +++ tinytim/trunk/main/java/org/tinytim/index/IndexFlagsImpl.java 2008-04-20 15:30:50 UTC (rev 19) @@ -0,0 +1,51 @@ +/* + * This is tinyTiM, a tiny Topic Maps engine. + * + * Copyright (C) 2008 Lars Heuer (heuer[at]semagia.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ +package org.tinytim.index; + +import org.tmapi.index.IndexFlags; + +/** + * Immutable {@link org.tmapi.index.IndexFlags} implementation. + * + * Use {@link #AUTOUPDATED} or {@link #NOT_AUTOUPDATED} + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public class IndexFlagsImpl implements IndexFlags { + + public static IndexFlags AUTOUPDATED = new IndexFlagsImpl(true); + public static IndexFlags NOT_AUTOUPDATED = new IndexFlagsImpl(false); + + private final boolean _autoUpdated; + + private IndexFlagsImpl(boolean autoUpdated) { + _autoUpdated = autoUpdated; + } + + /* (non-Javadoc) + * @see org.tmapi.index.IndexFlags#isAutoUpdated() + */ + public boolean isAutoUpdated() { + return _autoUpdated; + } + +} Property changes on: tinytim/trunk/main/java/org/tinytim/index/IndexFlagsImpl.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. |
From: <lh...@us...> - 2008-04-20 15:34:45
|
Revision: 18 http://tinytim.svn.sourceforge.net/tinytim/?rev=18&view=rev Author: lheuer Date: 2008-04-20 08:21:48 -0700 (Sun, 20 Apr 2008) Log Message: ----------- - Added locator impl - Removed unnecessary generics from _topicmaps initialization Modified Paths: -------------- tinytim/trunk/main/java/org/tinytim/TopicMapSystemImpl.java Added Paths: ----------- tinytim/trunk/main/java/org/tinytim/IRI.java Added: tinytim/trunk/main/java/org/tinytim/IRI.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/IRI.java (rev 0) +++ tinytim/trunk/main/java/org/tinytim/IRI.java 2008-04-20 15:21:48 UTC (rev 18) @@ -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; + +import java.net.URI; + +import org.tmapi.core.Locator; + +/** + * Immutable representation of an IRI. + * + * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> + * @version $Rev:$ - $Date:$ + */ +public final class IRI implements Locator { + + private final URI _uri; + + public IRI(String reference) { + this(URI.create(reference)); + } + + private IRI(URI uri) { + _uri = uri; + } + + /* (non-Javadoc) + * @see org.tmapi.core.Locator#getNotation() + */ + public String getNotation() { + return "URI"; + } + + /* (non-Javadoc) + * @see org.tmapi.core.Locator#getReference() + */ + public String getReference() { + return _uri.toString(); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Locator#resolveRelative(java.lang.String) + */ + public Locator resolveRelative(String reference) { + return new IRI(_uri.resolve(reference)); + } + + /* (non-Javadoc) + * @see org.tmapi.core.Locator#toExternalForm() + */ + public String toExternalForm() { + return _uri.toASCIIString(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return this == obj || (obj instanceof IRI && _uri.equals(((IRI) obj)._uri)); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return _uri.hashCode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return _uri.toString(); + } + +} Property changes on: tinytim/trunk/main/java/org/tinytim/IRI.java ___________________________________________________________________ Name: svn:keywords + Rev Date Id Name: svn:eol-style + native Modified: tinytim/trunk/main/java/org/tinytim/TopicMapSystemImpl.java =================================================================== --- tinytim/trunk/main/java/org/tinytim/TopicMapSystemImpl.java 2008-04-20 15:11:15 UTC (rev 17) +++ tinytim/trunk/main/java/org/tinytim/TopicMapSystemImpl.java 2008-04-20 15:21:48 UTC (rev 18) @@ -34,7 +34,7 @@ * {@link org.tmapi.core.TopicMapSystem} implementation. * * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a> - * @version $Rev:$ - $Date:$ + * @version $Rev$ - $Date$ */ final class TopicMapSystemImpl implements TopicMapSystem { @@ -48,7 +48,7 @@ _collectionFactory = collFactory; _features = features; _properties = properties; - _topicMaps = collFactory.<Locator, TopicMap>createMap(); + _topicMaps = collFactory.createMap(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |