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... [truncated message content] |