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