Update of /cvsroot/tm4j/tm4j/src/com/techquila/topicmap/ozone In directory usw-pr-cvs1:/tmp/cvs-serv10403 Added Files: OzoneAssociation.java OzoneAssociationImpl.java OzoneBaseName.java OzoneBaseNameImpl.java OzoneMember.java OzoneMemberImpl.java OzoneOccurrence.java OzoneOccurrenceImpl.java OzoneScope.java OzoneScopeImpl.java OzoneScopedObject.java OzoneScopedObjectImpl.java OzoneTopic.java OzoneTopicImpl.java OzoneTopicMap.java OzoneTopicMapFactoryImpl.java OzoneTopicMapImpl.java OzoneTopicMapObject.java OzoneTopicMapObjectImpl.java OzoneTopicMapUtils.java OzoneTopicMapUtilsImpl.java OzoneVariant.java OzoneVariantImpl.java OzoneVariantName.java OzoneVariantNameImpl.java Log Message: - initial checkin --- NEW FILE: OzoneAssociation.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneAssociation.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.Association; import com.techquila.topicmap.Topic; import com.techquila.topicmap.Member; import org.ozoneDB.OzoneRemote; /** * This interface describes a single topic association link. * * The type of the Association is defined by an optional string and/or an optional Topic * An Association contains of one or more Member objects * which define the members of the association link and may include * a Scope object whichs define the scope of validity of the Association. * * @see com.techquila.topicmap.Topic * @see com.techquila.topicmap.Member * @see com.techquila.topicmap.ScopedObject */ public abstract interface OzoneAssociation extends OzoneScopedObject, Association { public void dispose(); // update /** * Defines the member constructs which are members of this association. * * @param roles An array of Member objects to be set as members of the link. * @return An unmodifiable Collection of Member objects. * @see Member */ public void setMembers( Member[] roles ); // update /** * Adds a Member as a member role of the association. * * @param role The Member to be added. * @see Member */ public void addMember( Member member ); // update /** * Removes a member from the roles of this association. * * @param member The member to be removed. */ public void removeMember( Member member ); // update /** * Sets the Topic defining the type of this Association. * * @param type The Topic to define the type of the association. */ public void setType( Topic type ); // update } --- NEW FILE: OzoneAssociationImpl.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneAssociationImpl.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.Topic; import com.techquila.topicmap.Member; import com.techquila.topicmap.TMTypes; import java.util.ArrayList; import java.util.Iterator; import java.util.Collection; import java.util.Collections; /** * Instances of this class represent a single topic association link. * Each Association is defined by a single Topic describing the type of * the association and consists of one or more Member objects which define * the members of the association link and may include one or more scoping * Topics which define the scope of validity of the Association. * * @see com.techquila.topicmap.Topic * @see com.techquila.topicmap.Member */ public class OzoneAssociationImpl extends OzoneScopedObjectImpl implements OzoneAssociation { final static long serialVersionUID = 1L; protected Topic m_type; protected ArrayList m_members; /** * Constructs a new AssociationImpl with an assigned ID. * * @param id The unique identifier assigned to the AssociationImpl object. */ public OzoneAssociationImpl() { m_type = null; m_members = null; } /** * Cleans up the Association by notifying all of its contained * Member objects to drop their back-pointers. */ public void dispose() { // FIXME: // m_type = null; // if (m_members != null) { // Iterator it = m_members.iterator(); // while (it.hasNext()) { // try { // MemberImpl ar = (MemberImpl)it.next(); // ar.dispose(); // } catch (ClassCastException ex) { // } // } // } } /** * Constructor for creating an Association object. * * @param id A unique identifier to be assigned to the Association. * @param type A Topic object defining the type of the Association. * This parameter may be null if there is no Topic defining * the type of the link. * @param members An array of Member objects each defining one of the roles * of the link. This parameter may be null if there are no * Members defined for the Association yet. * @param scope The scope of validity of the association. This parameter * may be null if the scope of the Association is currently * the unconstrained scope. */ // public AssociationImpl( String id, Topic type, Member[] members, // Scope scope ) { // super( scope ); // setID( id ); // m_type = type; // m_members = null; // if (members != null) { // setMembers( members ); // } // } /** */ public Collection getMembers() { Collection ret = m_members; if (ret == null) { ret = new ArrayList(); } return Collections.unmodifiableCollection( ret ); } /** */ public void setMembers( Member[] members ) { ArrayList oldMembers = null; if (m_members != null) { new ArrayList( m_members ); } m_members = new ArrayList(); for (int i = 0; i < members.length; i++) { members[i].setParent( this ); m_members.add( members[i] ); } firePropertyChange( "members", oldMembers, m_members ); } /** */ public void addMember( Member member ) { ArrayList oldMembers = null; if (m_members != null) { new ArrayList( m_members ); } if (m_members == null) { m_members = new ArrayList(); } m_members.add( member ); member.setParent( this ); firePropertyChange( "members", oldMembers, m_members ); } /** */ public void removeMember( Member member ) { if (m_members != null) { ArrayList oldMembers = new ArrayList( m_members ); if (m_members.contains( member )) { m_members.remove( member ); if (m_members.isEmpty()) { m_members = null; } member.setParent( null ); } firePropertyChange( "members", oldMembers, m_members ); } } /** * @return The Topic defining the type of this Association. If there is no such Topic, * null is returned. */ public Topic getType() { return m_type; } /** * Sets the Topic defining the type of this Association. * @param type The Topic to define the type of the association. */ public void setType( Topic type ) { Topic oldType = m_type; m_type = type; firePropertyChange( "type", oldType, m_type ); } /** * @return True if the type of this Association is defined by the topic <i>type</i> */ public boolean ofType( Topic type ) { if (m_type == null) { return false; } return m_type == type; } /** */ public int getObjectType() { return TMTypes.TM_ASSOC; } /** */ public Member getMemberOfRole( Topic roleSpec ) { Iterator it = m_members.iterator(); while (it.hasNext()) { Member m = (Member)it.next(); Topic rs = m.getRoleSpec(); if (rs != null && rs.getBaseTopic().equals( roleSpec.getBaseTopic() )) { return m; } } return null; } } --- NEW FILE: OzoneBaseName.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneBaseName.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.BaseName; import com.techquila.topicmap.Variant; import com.techquila.topicmap.NamedObject; import org.ozoneDB.OzoneRemote; /** */ public interface OzoneBaseName extends OzoneScopedObject, BaseName { public void setString( String data ); // update public void setVariants( Variant[] variants ); // update public void addVariant( Variant variant ); // update public void setParent( NamedObject parent ); // update } --- NEW FILE: OzoneBaseNameImpl.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneBaseNameImpl.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.TMTypes; import com.techquila.topicmap.NamedObject; import com.techquila.topicmap.Variant; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.beans.PropertyChangeEvent; /** */ public class OzoneBaseNameImpl extends OzoneScopedObjectImpl implements OzoneBaseName { final static long serialVersionUID = 1L; private NamedObject m_parent; protected String m_string; private ArrayList m_variants; public OzoneBaseNameImpl() { m_parent = null; m_string = null; m_variants = null; } public void setParent( NamedObject parent ) { m_parent = parent; } public NamedObject getParent() { return m_parent; } public void setString( String str ) { String oldString = m_string; m_string = str; firePropertyChange( "string", oldString, m_string ); } public String getString() { return m_string; } public void setVariants( Variant[] variants ) { ArrayList oldVariants = null; if (m_variants != null) { oldVariants = new ArrayList( m_variants ); } if (variants == null || variants.length == 0) { m_variants = null; } else { m_variants = new ArrayList(); for (int i = 0; i < variants.length; i++) { m_variants.add( variants[i] ); } } firePropertyChange( "variants", oldVariants, m_variants ); } public void addVariant( Variant v ) { ArrayList oldVariants = null; if (m_variants != null) { oldVariants = new ArrayList( m_variants ); } if (m_variants == null) { m_variants = new ArrayList(); } m_variants.add( v ); firePropertyChange( "variants", oldVariants, m_variants ); } public Collection getVariants() { if (m_variants == null) { return Collections.unmodifiableCollection( new ArrayList() ); } else { return Collections.unmodifiableCollection( m_variants ); } } public int getObjectType() { return TMTypes.TM_BASENAME; } /** * Handles property change events received from the contained * Scope object. In particular, handles change in the scopeString property * by notifying listeners of a change of scoped name */ public void propertyChange( PropertyChangeEvent ev ) { if (ev.getPropertyName().equals( "scopeString" )) { String oldScopedName = (String)ev.getOldValue() + "." + getID(); String newScopedName = getScope().toString() + "." + getID(); firePropertyChange( "scopeString", oldScopedName, newScopedName ); } super.propertyChange( ev ); } } --- NEW FILE: OzoneMember.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneMember.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.Member; import com.techquila.topicmap.Association; import com.techquila.topicmap.Topic; import org.ozoneDB.OzoneRemote; /** */ public interface OzoneMember extends OzoneTopicMapObject, Member { public void setParent( Association parent ); // update public void setRoleSpec( Topic roleSpec ); // update public void addPlayer( Topic player ); // update public void setPlayers( Topic[] players ); // update } --- NEW FILE: OzoneMemberImpl.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneMemberImpl.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.Member; import com.techquila.topicmap.Association; import com.techquila.topicmap.Topic; import com.techquila.topicmap.TMTypes; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; /** */ public class OzoneMemberImpl extends OzoneScopedObjectImpl implements OzoneMember { final static long serialVersionUID = 1L; /** */ protected Association m_parent; protected Topic m_roleSpec; protected ArrayList m_players; /** */ public OzoneMemberImpl() { } /** * Applications should not call this function directly. * It is called indirectly from Association.addMember(), Association.removeMember() and Association.setMembers() */ public void setParent( Association parent ) { Association oldParent = m_parent; m_parent = parent; firePropertyChange( "parent", oldParent, m_parent ); } public Association getParent() { return m_parent; } public void setRoleSpec( Topic roleSpec ) { Topic oldRoleSpec = m_roleSpec; m_roleSpec = roleSpec; firePropertyChange("roleSpec", oldRoleSpec, m_roleSpec); } public Topic getRoleSpec() { return m_roleSpec; } public void addPlayer( Topic player ) { ArrayList oldPlayers = null; if (m_players != null) { oldPlayers = new ArrayList( m_players ); } if (m_players == null) { m_players = new ArrayList(); } m_players.add( player ); player.addRolePlayed( this ); firePropertyChange( "players", oldPlayers, m_players ); } public void setPlayers( Topic[] players ) { ArrayList oldPlayers = null; if (m_players != null) { oldPlayers = new ArrayList( m_players ); } if (players == null || players.length == 0) { m_players = null; } else { m_players = new ArrayList(); for (int i = 0; i < players.length; i++) { m_players.add( players[i] ); players[i].addRolePlayed( this ); } } } public Collection getPlayers() { if (m_players == null) { return Collections.unmodifiableCollection( new ArrayList() ); } return Collections.unmodifiableCollection( m_players ); } public int getObjectType() { return TMTypes.TM_MEMBER; } } --- NEW FILE: OzoneOccurrence.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneOccurrence.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.Occurrence; import com.techquila.topicmap.BaseName; import com.techquila.topicmap.Topic; import org.ozoneDB.OzoneRemote; /** * This interface defines a single occurence (<code>occurs</code>) construct in a Topic Map. * * An occurrence is defined by a string rolename and an optional type Topic. * An occurrence contains a reference to a resource or in-line resource data. * * @see Topic */ public interface OzoneOccurrence extends OzoneScopedObject, Occurrence { /** * Sets the Topic defining the type of this Occurrence. */ public void setType( Topic type ); // update /** * Sets the resource reference associatedc with this occurrence. The new value overwrites * any previous resource reference of resource data string. */ public void setResourceRef( String resourceRef ); // update /** * Sets the resource data string associated with this occurrence. The new value overwrites * and previous resource data or resource reference strings. */ public void setResourceData( String resourceData ); // update /** * Sets the name of this occurrence */ public void setName( BaseName bn ); // update } --- NEW FILE: OzoneOccurrenceImpl.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneOccurrenceImpl.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.TMTypes; import com.techquila.topicmap.BaseName; import com.techquila.topicmap.Topic; import com.techquila.utils.URLS; import java.net.URL; /** * Defines an occurrence instance of a Topic. * The type of an Occurrence is defined either by a Topic defining the type. * An occurrence may be scoped and may contain either an in-line data resource (as a string) or * a reference to an external resource (specified as a URI). */ public class OzoneOccurrenceImpl extends OzoneScopedObjectImpl implements OzoneOccurrence { final static long serialVersionUID = 1L; /** */ protected BaseName m_name; protected Topic m_type; protected String m_data; protected boolean m_isResourceReference; /** */ public OzoneOccurrenceImpl() { m_name = null; m_type = null; m_data = null; m_isResourceReference = false; } /** * Gets the base name of this occurrence. * Returns null if no base name is defined for the occurrence. */ public BaseName getName() { return m_name; } /** * Sets the base name of this occurrence */ public void setName( BaseName name ) { BaseName oldName = m_name; if (m_name != null) { m_name.setParent( null ); } m_name = name; if (m_name != null) { m_name.setParent( this ); } firePropertyChange( "name", oldName, m_name ); } /** * @return The Topic defining the type of this Occurrence, or null if no such Topic has been specified. */ public Topic getType() { return m_type; } /** * Sets the Topic defining the type of this Occurrence. */ public void setType( Topic type ) { Topic oldType = m_type; m_type = type; firePropertyChange( "type", oldType, m_type ); } /** * Returns the resource reference associated with this occurrence. This may be null. */ public String getResourceRef() { if (!m_isResourceReference) { return null; } return m_data; } /** * Sets the resource reference associatedc with this occurrence. The new value overwrites * any previous resource reference of resource data string. * If the reference is recognised as an HTTP protocol URL, it will be normalised. */ public void setResourceRef( String resourceRef ) { String oldRef = getResourceRef(); try { URL du = URLS.normalize( new URL( resourceRef ) ); m_data = du.toString(); } catch (Exception ex) { m_data = resourceRef; } m_isResourceReference = true; firePropertyChange("resourceRef", oldRef, m_data); } /** * Sets the resource data string associated with this occurrence. The new value overwrites * and previous resource data or resource reference strings. */ public void setResourceData( String resourceData ) { String oldData = getResourceData(); m_isResourceReference = false; m_data = resourceData; firePropertyChange("resource", oldData, m_data); } /** * Gets the resource data string associated with this occurrence. This function returns * null if there is no resource data string associated with this occurrence. */ public String getResourceData() { if (m_isResourceReference) { return null; } return m_data; } public int getObjectType() { return TMTypes.TM_OCCURRENCE; } } --- NEW FILE: OzoneScope.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneScope.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.Scope; import com.techquila.topicmap.Topic; /** */ public interface OzoneScope extends OzoneTopicMapObject, Scope { public void setThemes( Topic[] themes ); // update public void addTheme( Topic theme ); // update public void addScope( Scope scope ); // update public void removeThemes(); // update public void removeTheme( Topic theme ); // update public void setID( String id ); // update public void setResourceID( String id ); // update public String toString(); } --- NEW FILE: OzoneScopeImpl.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneScopeImpl.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.TMTypes; import com.techquila.topicmap.Scope; import com.techquila.topicmap.Topic; import com.techquila.topicmap.TopicMapObject; import java.util.Collection; import java.util.Collections; import java.util.ArrayList; import java.util.HashSet; import java.util.TreeSet; import java.util.Iterator; import java.beans.PropertyChangeEvent; /** */ public class OzoneScopeImpl extends OzoneTopicMapObjectImpl implements OzoneScope { final static long serialVersionUID = 1L; private HashSet m_themes; private String m_stringified; public OzoneScopeImpl() { m_themes = null; m_stringified = UNCONSTRAINED; } public void setThemes( Topic[] themes ) { removeThemes(); m_themes = new HashSet(); for (int i = 0; i < themes.length; i++) { m_themes.add( themes[i] ); } stringify(); } public void addTheme( Topic theme ) { if (m_themes == null) { m_themes = new HashSet(); } m_themes.add( theme ); stringify(); } public void addScope( Scope scope ) { Collection c = scope.getThemes(); if (c.isEmpty()) { return; } if (m_themes == null) { m_themes = new HashSet(); } Iterator it = c.iterator(); while (it.hasNext()) { Topic t = (Topic)it.next(); m_themes.add( t ); } stringify(); } public void removeThemes() { if (m_themes != null) { Iterator themesIt = m_themes.iterator(); while (themesIt.hasNext()) { Topic theme = (Topic)themesIt.next(); unregister( theme ); } } m_themes = null; m_stringified = UNCONSTRAINED; } public void removeTheme( Topic theme ) { m_themes.remove( theme ); if (m_themes.isEmpty()) { m_themes = null; } stringify(); // No longer need to listen for changes to this theme Topic unregister( theme ); } public Collection getThemes() { if (m_themes == null) { return Collections.unmodifiableCollection( new ArrayList() ); } else { return Collections.unmodifiableCollection( m_themes ); } } public boolean inScope( Topic theme ) { if (m_themes == null) { return false; } Iterator it = m_themes.iterator(); while (it.hasNext()) { Topic t = (Topic)it.next(); if (t.getID().equals( theme.getID() )) { return true; } Iterator mit = t.getMergedTopics().iterator(); while (mit.hasNext()) { Topic mt = (Topic)mit.next(); if (mt.getID().equals( theme.getID() )) { return true; } } } return false; } public boolean inScope( Topic[] themes ) { for (int i = 0; i < themes.length; i++) { if (!inScope( themes[i] )) { return false; } } return true; } public boolean inScope( Scope sc ) { Iterator themes = sc.getThemes().iterator(); while (themes.hasNext()) { if (!inScope( (Topic)themes.next() )) { return false; } } return true; } public void propertyChange( PropertyChangeEvent e ) { if (e.getPropertyName().equals( "baseTopic" )) { // Some topic in scope has changed its base topic id. // Need to regenerate the stringified scope id. System.out.println("base topic in scope altered"); stringify(); } } public void register( Topic t ) { ((TopicMapObject)t).addPropertyChangeListener( "baseTopic", this ); } public void unregister( Topic t ) { ((TopicMapObject)t).removePropertyChangeListener( this ); } protected void stringify() { String oldString = m_stringified; if (m_themes == null) { m_stringified = UNCONSTRAINED; } else { TreeSet sortedIds = new TreeSet(); Iterator it = m_themes.iterator(); while (it.hasNext()) { Topic t = (Topic)it.next(); register( t ); sortedIds.add( t.getBaseTopic().getID() ); } it = sortedIds.iterator(); StringBuffer s = new StringBuffer(); while (it.hasNext()) { s.append( (String)it.next() ); if (it.hasNext()) { s.append( "|" ); } } m_stringified = s.toString(); } // Finally notify listeners if the scope string has changed if (!m_stringified.equals( oldString )) { firePropertyChange( "scopeString", oldString, m_stringified ); } } public int getObjectType() { return TMTypes.TM_SCOPE; } public int hashCode() { return m_stringified.hashCode(); } public String toString() { return m_stringified; } } --- NEW FILE: OzoneScopedObject.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneScopedObject.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.ScopedObject; import com.techquila.topicmap.Topic; import com.techquila.topicmap.Scope; import org.ozoneDB.OzoneRemote; /** */ public interface OzoneScopedObject extends OzoneTopicMapObject, ScopedObject { public void addTheme( Topic theme ); // update public void removeTheme( Topic theme ); // update public void dispose(); // update public void setScope( Scope newScope ); // update } --- NEW FILE: OzoneScopedObjectImpl.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneScopedObjectImpl.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.TopicMapObject; import com.techquila.topicmap.Scope; import com.techquila.topicmap.Topic; import java.beans.PropertyChangeEvent; /** * Base class for all topic map objects which have a validity scope. */ public abstract class OzoneScopedObjectImpl extends OzoneTopicMapObjectImpl implements OzoneScopedObject { final static long serialVersionUID = 1L; private Scope m_scope; /** */ public OzoneScopedObjectImpl() { m_scope = null; } /** * Clears contained scope references. */ public void dispose() { m_scope = null; } /** * Defines the scope of validity of this scoped object. * @param themes An array of Topics defining the scope for this scoped object. */ public void setScope( Scope newScope ) { Scope oldScope = m_scope; m_scope = newScope; firePropertyChange( "scope", oldScope, m_scope ); m_scope.addPropertyChangeListener( this ); } public Scope getScope() { return m_scope; } // Add/Remove themes from scope: public void addTheme( Topic theme ) { m_scope.addTheme( theme ); } public void removeTheme( Topic theme ) { m_scope.removeTheme( theme ); } /** * @deprecated Use getScope().inScope() instead * @return True if the specified theme is in the scope of this object. */ public boolean inScope( Topic theme ) { return m_scope.inScope( theme ); } /** * @deprecated Use getScope().inScope() instead. * @return True if the one or more of the specified themes are in the scope of this object. */ public boolean inScope( Topic[] themes ) { return m_scope.inScope( themes ); } } --- NEW FILE: OzoneTopic.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneTopic.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.Topic; import com.techquila.topicmap.TopicMap; import com.techquila.topicmap.Occurrence; import com.techquila.topicmap.BaseName; import com.techquila.topicmap.Member; import com.techquila.topicmap.MergedTopicSubjectClashException; import org.ozoneDB.OzoneRemote; /** * This interface describes a Topic (<code>topic</code>) construct in a Topic Map */ public interface OzoneTopic extends OzoneScopedObject, Topic { /** */ public void setParent( TopicMap parent ); // update /** */ public TopicMap getParent(); // update /** * Sets the reference to the subject of this topic. * @param resourceRef The URI reference to the resource which is the subject of this topic. */ public void setSubject( String resourceRef ); // update /** * Adds a subject indicator to this topic */ public void addSubjectIndicator( String subjectIdentity ); // update /** * Sets the collection of subject indicators for this topic. */ public void setSubjectIndicators( String[] indicators ); // update /** * @deprecated * Sets the compound link type of this topic. */ public void setLinktype( String linktype ); // update /** * Defines the type of this topic. * @param types An array of Topics defining the type of this topic. */ public void setTypes( Topic[] types ); // update /** * Adds a new topic into the list of those defining the type of this topic. * @param type The typing topic to be added. */ public void addType( Topic type ); // update /** * Sets the names of this Topic * @param names The names to be assigned to this topic. */ public void setNames( BaseName[] names ); // update /** * Adds another name or set of names to the list of names of this Topic * @param name The scoped name(s) to be added */ public void addName( BaseName name ); // update /** * Sets the list of occurrences for this Topic. * @param occurs The Occurrences to be associated with this Topic. */ public void setOccurrences( Occurrence[] occurs ); // update /** * Adds an occurrence to this Topic. * @param occurs The Occurrence to be added. */ public void addOccurrence( Occurrence occurs ); // update /** * Sets the list of roles which this Topic is playing. */ public void setRolesPlayed( Member[] rolesPlayed ); // update /** * Adds a Member object to the list of roles played by this topic. */ public void addRolePlayed( Member rolePlayed ); // update /** * Adds another Topic to the list of merged topics. */ public void addMergedTopic( Topic mergedTopic ) throws MergedTopicSubjectClashException; // update /** * Removes all merged topics from this topic. */ public void removeMergedTopics(); // update /** * Sets a reference to the topic that this topic is merged with. */ public void setBaseTopic( Topic baseTopic ); // update } --- NEW FILE: OzoneTopicImpl.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneTopicImpl.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.Topic; import com.techquila.topicmap.TopicMap; import com.techquila.topicmap.TopicMapUtils; import com.techquila.topicmap.Association; import com.techquila.topicmap.Occurrence; import com.techquila.topicmap.TMTypes; import com.techquila.topicmap.PSI; [...1057 lines suppressed...] */ public void propertyChange( PropertyChangeEvent ev ) { // Changes to themes of the scope should get propagated as a change // to this topic's scope. if (ev.getPropertyName().equals( "themes" )) { firePropertyChange( "scope", null, getScope() ); } else if ((ev.getPropertyName().equals( "scope" )) || (ev.getPropertyName().equals( "scopeString" )) || (ev.getPropertyName().equals( "string" ))) { if (m_names.contains( ev.getSource() )) { System.out.println("Scope string of topic (" + getID() + ") base name changed"); makeScopedNames(); } else { System.out.println("Property change received from an object which is not in m_names."); } } } } --- NEW FILE: OzoneTopicMap.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneTopicMap.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.TopicMap; import com.techquila.topicmap.TopicMapUtils; import com.techquila.topicmap.Topic; import com.techquila.topicmap.Association; import com.techquila.topicmap.TopicNotFoundException; import com.techquila.topicmap.MergedTopicSubjectClashException; import com.techquila.topicmap.DuplicateTopicException; import org.ozoneDB.OzoneRemote; import java.net.URL; /** * This interface defines the whole Topic Map construct. */ public interface OzoneTopicMap extends OzoneTopicMapObject, TopicMap { /** * Adds an added theme to the topic map. */ public void addAddedTheme( Topic theme ); // update /** * Adds the association to this topic map. */ public void addAssociation( Association association ); // update /** * Add the topic to this topic map. * Automatically determines if the topic should be merged. * @param topic The topic to be added to the map * @throws DuplicateTopicException */ public Topic addTopic( Topic topic ) throws DuplicateTopicException, MergedTopicSubjectClashException; // update /** * Delete a topic from the topic map. * @param topic The topic to be removed from the map * @throws TopicNotFoundException */ public void removeTopic( Topic topic ) throws TopicNotFoundException; // update /** * Delete an association from the topic map. * @param assoc The association to be removed from the map */ public void removeAssociation( Association assoc ); // update /** * setName * Set the name of the topic map. * @param name The name to be assigned to the topic map. */ public void setName( String name ); // update /** * Sets the topic map's base URL */ public void setBase( URL base ); // update /** * Returns a TopicMapUtils object and creates a new one if * necessary. */ public TopicMapUtils getUtils(); // update } --- NEW FILE: OzoneTopicMapFactoryImpl.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneTopicMapFactoryImpl.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import org.ozoneDB.OzoneInterface; import com.techquila.topicmap.TopicMapFactory; import com.techquila.topicmap.Topic; import com.techquila.topicmap.TopicMap; import com.techquila.topicmap.Association; import com.techquila.topicmap.Occurrence; import com.techquila.topicmap.BaseName; import com.techquila.topicmap.Variant; import com.techquila.topicmap.VariantName; import com.techquila.topicmap.Member; import com.techquila.topicmap.Scope; import com.techquila.topicmap.TopicMapProcessingException; import com.techquila.topicmap.TopicMapRuntimeException; import java.net.URL; import java.net.MalformedURLException; /** * Implements the TopicMapFactory interface for creating in-memory Topic Map objects. */ public class OzoneTopicMapFactoryImpl extends Object implements TopicMapFactory { public final static String DEFAULT_BASE_URL = "http://topicmap.techquila.com/default"; private OzoneInterface m_database; private TopicMap m_topicMap; private URL m_defaultBaseURL; private URL m_baseURL; /** */ public OzoneTopicMapFactoryImpl( OzoneInterface database ) { this( database, null ); } /** */ public OzoneTopicMapFactoryImpl( OzoneInterface database, TopicMap tm ) { m_topicMap = tm; m_database = database; try { String urlString = System.getProperty( "com.techquila.topicmap.baseURL", DEFAULT_BASE_URL ); m_defaultBaseURL = new URL( urlString ); } catch (MalformedURLException ex) { throw new TopicMapRuntimeException( "Cannot initialise base URL for TopicMapFactoryImpl.", ex ); } } /** */ public void setBase( URL base ) { m_baseURL = base; } /** */ public TopicMap createTopicMap() { //System.out.println( " --> createTopicMap" ); return createTopicMap( m_defaultBaseURL ); } /** */ public TopicMap createTopicMap( URL baseURL ) { //System.out.println( " --> createTopicMap" ); try { m_topicMap = (OzoneTopicMap)m_database.createObject( OzoneTopicMapImpl.class.getName() ); m_topicMap.setBase( baseURL ); return m_topicMap; } catch (Exception e) { e.printStackTrace(); return null; } } /** */ public Topic createTopic( String id ) throws TopicMapProcessingException { //System.out.println( " --> createTopic: " + id ); try { OzoneTopic ret = (OzoneTopic)m_database.createObject( OzoneTopicImpl.class.getName() ); ret.setID( normaliseID( id ) ); ret.setParent( m_topicMap ); ret.setScope( createScope( null ) ); m_topicMap.addTopic( ret ); ret.getScope().addPropertyChangeListener( ret ); return ret; } catch (Exception e) { e.printStackTrace(); return null; } } /** */ public Scope createScope( String id ) { //System.out.println( " --> createScope" ); try { Scope ret = (Scope)m_database.createObject( OzoneScopeImpl.class.getName() ); ret.setID( normaliseID( id ) ); return ret; } catch (Exception e) { e.printStackTrace(); return null; } } /** */ public Association createAssociation( String id ) { return createAssociation( id, null ); } /** */ public Association createAssociation( String id, Topic type ) { //System.out.println( " --> createAssociation: " + id ); try { Association ret = (Association)m_database.createObject( OzoneAssociationImpl.class.getName() ); ret.setID( normaliseID( id ) ); ret.setScope( createScope( null ) ); ret.setType( type ); return ret; } catch (Exception e) { e.printStackTrace(); return null; } } /** */ public Member createMember( Association parent, String id ) { //System.out.println( " --> createMember" ); try { Member ret = (Member)m_database.createObject( OzoneMemberImpl.class.getName() ); ret.setID( normaliseID( id ) ); parent.addMember( ret ); return ret; } catch (Exception e) { e.printStackTrace(); return null; } } /** */ public BaseName createBaseName( String id ) { //System.out.println( " --> createBaseName" ); try { BaseName ret = (BaseName)m_database.createObject( OzoneBaseNameImpl.class.getName() ); ret.setID( normaliseID( id ) ); ret.setScope( createScope( null ) ); return ret; } catch (Exception e) { e.printStackTrace(); return null; } } /** */ public Variant createVariant( String id ) { //System.out.println( " --> createVariant" ); try { Variant ret = (Variant)m_database.createObject( OzoneVariantImpl.class.getName() ); ret.setID( normaliseID( id ) ); ret.setScope( createScope( null ) ); return ret; } catch (Exception e) { e.printStackTrace(); return null; } } /** */ public VariantName createVariantName( String id ) { //System.out.println( " --> createVariantName" ); try { VariantName ret = (VariantName)m_database.createObject( OzoneVariantNameImpl.class.getName() ); ret.setID( normaliseID( id ) ); return ret; } catch (Exception e) { e.printStackTrace(); return null; } } /** */ public Occurrence createOccurrence( String id ) { //System.out.println( " --> createOccurrence" ); try { Occurrence ret = (Occurrence)m_database.createObject( OzoneOccurrenceImpl.class.getName() ); ret.setID( normaliseID( id ) ); ret.setScope( createScope( null ) ); return ret; } catch (Exception e) { e.printStackTrace(); return null; } } /** */ protected String normaliseID( String id ) { return id; } } --- NEW FILE: OzoneTopicMapImpl.java --- /* * You can redistribute this software and/or modify it under the terms of * the Infozone Software License version 2 published by the Infozone Group * (http://www.infozone-group.org). * * Copyright (C) @year@ by The Infozone Group. All rights reserved. * * $Id: OzoneTopicMapImpl.java,v 1.1 2001/05/29 17:32:45 lilli Exp $ */ package com.techquila.topicmap.ozone; import com.techquila.topicmap.TopicMap; import com.techquila.topicmap.TopicMapObject; import com.techquila.topicmap.Topic; import com.techquila.topicmap.TMTypes; import com.techquila.topicmap.TopicMapUtils; import com.techquila.topicmap.TopicMapUtilsImpl; import com.techquila.topicmap.TopicMapFactory; import com.techquila.topicmap.Association; import com.techquila.topicmap.BaseName; import com.techquila.topicmap.ScopedObject; import com.techquila.topicmap.TopicNotFoundException; import com.techquila.topicmap.MergedTopicSubjectClashException; import com.techquila.topicmap.DuplicateTopicException; import com.techquila.topicmap.TopicMapProcessingException; import com.techquila.topicmap.TopicMapRuntimeException; import com.techquila.utils.URLS; import java.beans.PropertyChangeEvent; import java.net.URL; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.ArrayList; import java.util.Set; import java.util.HashSet; import java.util.Hashtable; import java.beans.PropertyChangeEvent; /** * The TopicMap is the root container for all of the other topic map objects. * This implementation of the TopicMap interface maintains all indices in memory. */ public class OzoneTopicMapImpl extends OzoneTopicMapObjectImpl implements OzoneTopicMap { final static long serialVersionUID = 1L; // Protected Memeber Variables protected String m_name; protected String m_id; protected ArrayList m_addthemes; protected HashSet m_topics; protected Hashtable m_objectsByID; protected Hashtable m_objectsByResourceID; protected Hashtable m_topicsBySubject; protected Hashtable m_topicsBySubjectIndicator; protected Hashtable m_topicsByScopedName; protected ArrayList m_associations; protected URL m_baseURL; transient protected TopicMapFactory m_factory; transient protected TopicMapUtils m_utils; /** * Creates a new, empty TopicMap */ public OzoneTopicMapImpl() { m_addthemes = new ArrayList(); m_topics = new HashSet(); m_objectsByID = new Hashtable(); m_objectsByResourceID = new Hashtable(); m_associations = new ArrayList(); m_topicsBySubject = new Hashtable(); m_topicsBySubjectIndicator = new Hashtable(); m_topicsByScopedName = new Hashtable(); m_factory = null; } //////////////////////////////////////////////////// // Public Member Functions //////////////////////////////////////////////////// /** * Adds an added theme to the topic map. */ public void addAddedTheme( Topic theme ) { m_addthemes.add( theme ); } /** * Adds the association to this topic map. */ public void addAssociation( Association association ) { m_associations.add( association ); } /** * Add the topic to this topic map. * Automatically determines if the topic should be merged. * @param topic The topic to be added to the map * @returns The topic added or the Topic that the added topic was merged into. * @throws DuplicateTopicException */ public Topic addTopic( Topic topic ) throws DuplicateTopicException, MergedTopicSubjectClashException { Topic ret = topic; boolean didMerge = false; // Check for merge by matching subject String subject = topic.getSubject(); if (subject != null && subject.length() > 0) { if (m_topicsBySubject.containsKey( subject )) { //System.out.println("Merge by subject: " + subject); Topic t = (Topic)m_topicsBySubject.get( subject ); t.addMergedTopic( topic ); indexTopic( t, topic ); didMerge = true; } } // Check for merge by matching subject indicator Collection subjectIndicators = ret.getSubjectIndicators(); Iterator it = subjectIndicators.iterator(); while (it.hasNext()) { String subjectIndicator = (String)it.next(); if (subjectIndicator != null && subjectIndicator.length() > 0) { if (m_topicsBySubjectIndicator.containsKey( subjectIndicator )) { // Merge the new topic with the topic with a matching identity Topic t = (Topic)m_topicsBySubjectIndicator.get( subjectIndicator ); // It is possible to get the topic currently being added at this point // This will happen if the topic being added has multiple subject indicators // which cause merges. To avoid merging the topic with itself, check the returned // topic id. //System.out.println("Subject Indicator Merge: " + topic.getID() + " into " + t.getID()); if (t.getID().equals( topic.getID() )) { continue; } t.addMergedTopic( topic ); // Record the merged topic under the ID of this topic. indexTopic( t, topic ); didMerge = true; } } } // Check for merge by matching scoped name Iterator scopedNames = ret.getScopedNames().iterator(); while (scopedNames.hasNext()) { String scName = (String)scopedNames.next(); if (m_topicsByScopedName.containsKey( scName )) { Topic t = (Topic)m_topicsByScopedName.get( scName ); //System.out.println("Name Merge: " + topic.getID() + " into " + t.getID() + ": " + scName); if (t.getBaseTopic().getID().equals( topic.getBaseTopic().getID() )) { continue; } t.addMergedTopic( ret ); // Record the merged topic under the ID of this topic. indexTopic( t, ret ); ret = t; didMerge = true; } } if (!didMerge) { // Topic is not merged. Check that its SGML Id is not a duplicate if (m_objectsByID.containsKey( topic.getID() )) { throw new DuplicateTopicException( "Duplicate topic ID: " + topic.getID() ); } m_topics.add( ret ); indexTopic( ret, null ); } return ret; } private void indexObject( TopicMapObject tmo ) { m_objectsByID.put( tmo.getID(), tmo ); if (tmo.getResourceID() != null) { m_objectsByResourceID.put( tmo.getResourceID(), tmo ); } } private void unindexObject( TopicMapObject tmo ) { m_objectsByID.remove( tmo.getID() ); if (tmo.getResourceID() != null) { m_objectsByResourceID.remove( tmo.getResourceID() ); } } /** * Adds entries in all internal indices for the specified topic. * */ private void indexTopic( Topic t, Topic mt ) { // Unique ID & Resource ID if (mt != null) { indexObject( mt ); /* * For a merged topic, record the containing * topic under the merged topic's id * NOTE: this overwrites the indexing done by indexObject() */ m_objectsByID.put( mt.getID(), t ); } else { indexObject( t ); m_objectsByID.put( t.getID(), t ); if (t.getResourceID() != null) { m_objectsByResourceID.put( t.getResourceID(), t ); } } // Scoped names index Iterator scopedNames = t.getScopedNames().iterator(); while (scopedNames.hasNext()) { String scName = (String)scopedNames.next(); m_topicsByScopedName.put( scName, t ); } // Topic identity index Iterator subjectIDs = t.getSubjectIndicators().iterator(); while (subjectIDs.hasNext()) { String topicId = (String)subjectIDs.next(); if (topicId != null) { if (topicId.length() > 0) { m_topicsBySubjectIndicator.put( topicId, t ); } } } // Topic subject index String subject = t.getSubject(); if (subject != null && subject.length() > 0) { m_topicsBySubject.put( subject, t ); } // Register as listener to topic and its base names: if (mt != null) { register( mt ); } else { register( t ); } } /** * Registers this TopicMapImpl as a property change listener for the specified topic * and its base names. */ public void register( Topic t ) { t.addPropertyChangeListener( this ); Iterator it = t.getNames().iterator(); while (it.hasNext()) { BaseName bn = (BaseName)it.next(); bn.addPropertyChangeListener( this ); } } public void unregister( Topic t ) { t.removePropertyChangeListener( this ); Iterator it = t.getNames().iterator(); while (it.hasNext()) { BaseName bn = (BaseName)it.next(); bn.removePropertyChangeListener( this ); } } protected void unindexTopic( Topic topic, boolean unindexMergedTopics ) { m_topics.remove( topic ); unindexObject( topic ); if (unindexMergedTopics) { Iterator it = topic.getMergedTopics().iterator(); while (it.hasNext()) { Topic mt = (Topic)it.next(); m_topics.remove( mt ); m_objectsByID.remove( mt.getID() ); } } } protected void unindexSubject( Topic topic, String oldSubject ) { if (oldSubject != null && m_topicsBySubject.containsKey( oldSubject )) { Topic t = (Topic)m_topicsBySubject.get( oldSubject ); if (t.getID() == topic.getID()) { m_topicsBySubject.remove( oldSubject ); } } } /** * Remove all entries in m_topicsByScopedName for this topic. * @param topic Topic to remove entries for * @param scopedNames Collection of keys under which the topic may be found */ protected void unindexScopedNames( Topic topic, Collection scopedNames ) { if (scopedNames == null) { return; } Iterator it = scopedNames.iterator(); while (it.hasNext()) { String scopedName = (String)it.next(); Topic t = (Topic)m_topicsByScopedName.get( scopedName ); if (t != null && t.getID().equals( topic.getID() )) { m_topicsByScopedName.remove( scopedName ); } } } protected void unindexSubjectIndicators( Topic topic, Collection indicators ) { if (indicators == null) { return; } Iterator it = indicators.iterator(); while (it.hasNext()) { String indicator = (String)it.next(); Topic t = (Topic)m_topicsBySubjectIndicator.get( indicator ); if (t != null && t.getID().equals( topic.getID() )) { m_topicsBySubjectIndicator.remove( indicator ); } } } /** * removeTopic * Delete a topic from the topic map. * @param topic The topic to be removed from the map * @throws TopicNotFoundException */ public void removeTopic( Topic topic ) throws TopicNotFoundException { if (!m_objectsByID.containsKey( topic.getID() )) { throw new TopicNotFoundException( topic.getID() ); } unindexTopic( topic, false ); unindexSubject( topic, topic.getSubject() ); // Subject Indicators Iterator it = topic.getSubjectIndicators().iterator(); while (it.hasNext()) { String subjectIndicator = (String)it.next(); m_topicsBySubjectIndicator.remove( subjectIndicator ); } // Scoped Names Iterator scopedNames = topic.getScopedNames().iterator(); while (scopedNames.hasNext()) { String scName = (String)scopedNames.next(); m_topicsByScopedName.remove( scName ); } } public void removeAssociation( Association assoc ) { m_associations.remov... [truncated message content] |