diff --git a/src/dynamo-framework/com/silverwrist/dynamo/Namespaces.java b/src/dynamo-framework/com/silverwrist/dynamo/Namespaces.java index 5ee1964..17a2ae0 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/Namespaces.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/Namespaces.java @@ -92,4 +92,10 @@ public interface Namespaces public static final String UNISTORE_PERMISSIONS_NAMESPACE = "http://www.silverwrist.com/NS/dynamo/2003/06/10/unistore.permissions"; + /** + * Default resolvers namespace for the Index Manager. + */ + public static final String DEFAULT_INDEX_RESOLVERS_NAMESPACE = + "http://www.silverwrist.com/NS/dynamo/2003/06/14/std.index.resolvers"; + } // end interface Namespaces diff --git a/src/dynamo-framework/com/silverwrist/dynamo/except/IndexException.java b/src/dynamo-framework/com/silverwrist/dynamo/except/IndexException.java index 91b9680..9065a23 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/except/IndexException.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/except/IndexException.java @@ -55,4 +55,10 @@ public class IndexException extends ExternalException } // end constructor + public IndexException(DatabaseException de) + { + super(de); + + } // end constructor + } // end class IndexException diff --git a/src/dynamo-framework/com/silverwrist/dynamo/unistore/UniStoreManager.java b/src/dynamo-framework/com/silverwrist/dynamo/unistore/UniStoreManager.java index 2a7da7d..5922d37 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/unistore/UniStoreManager.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/unistore/UniStoreManager.java @@ -22,6 +22,7 @@ import org.apache.log4j.Logger; import org.w3c.dom.*; import com.silverwrist.util.*; import com.silverwrist.util.xml.*; +import com.silverwrist.dynamo.Namespaces; import com.silverwrist.dynamo.db.NamespaceCache; import com.silverwrist.dynamo.db.UserManagement; import com.silverwrist.dynamo.event.*; @@ -32,6 +33,118 @@ import com.silverwrist.dynamo.util.*; public class UniStoreManager implements NamedObject, ComponentInitialize, ComponentShutdown, UniStore { + /*-------------------------------------------------------------------------------- + * Internal class for resolving message references + *-------------------------------------------------------------------------------- + */ + + private class UniStoreResolver implements IndexedObjectResolver + { + /*==================================================================== + * Constructor + *==================================================================== + */ + + UniStoreResolver() + { // do nothing + } // end constructor + + /*==================================================================== + * Implementations from interface IndexedObjectResolver + *==================================================================== + */ + + public String getResolverTag(Object obj) throws IndexException + { + if (obj instanceof UniStoreMessage) + return String.valueOf(((UniStoreMessage)obj).getMessageID()); + else if (obj instanceof UniStorePart) + return String.valueOf(((UniStorePart)obj).getMessageID()); + else + throw new IndexException(UniStoreManager.class,"UniStoreMessages","resolver.must.be.message"); + + } // end getResolverTag + + public Object resolveObject(String tag) throws IndexException + { + try + { // parse tag into longint, get the message + return UniStoreManager.this.getMessage(Long.parseLong(tag)); + + } // end try + catch (NumberFormatException nfe) + { // not a valid number + throw new IndexException(UniStoreManager.class,"UniStoreMessages","invalid.tag"); + + } // end catch + catch (DatabaseException de) + { // just translate it straight across + throw new IndexException(de); + + } // end catch + + } // end resolveObject + + } // end class UniStoreResolver + + /*-------------------------------------------------------------------------------- + * Internal class for resolving message part references + *-------------------------------------------------------------------------------- + */ + + private class UniStorePartResolver implements IndexedObjectResolver + { + /*==================================================================== + * Constructor + *==================================================================== + */ + + UniStorePartResolver() + { // do nothing + } // end constructor + + /*==================================================================== + * Implementations from interface IndexedObjectResolver + *==================================================================== + */ + + public String getResolverTag(Object obj) throws IndexException + { + if (obj instanceof UniStoreTextPart) + { // return the message ID and the part namespace and name + QualifiedNameKey qname = ((UniStorePart)obj).getPartIdentity(); + return String.valueOf(((UniStorePart)obj).getMessageID()) + "|" + qname.getNamespace() + "|" + qname.getName(); + + } // end if + else + throw new IndexException(UniStoreManager.class,"UniStoreMessages","resolver.must.be.textpart"); + + } // end getResolverTag + + public Object resolveObject(String tag) throws IndexException + { + try + { // break up the tag and resolve it into a UniStoreTextPart + String[] bits = StringUtils.split1(tag,'|',3); + UniStoreMessage msg = UniStoreManager.this.getMessage(Long.parseLong(bits[0])); + return msg.getTextPart(bits[1],bits[2]); + + } // end try + catch (NumberFormatException nfe) + { // not a valid number + throw new IndexException(UniStoreManager.class,"UniStoreMessages","invalid.tag"); + + } // end catch + catch (DatabaseException de) + { // just translate it straight across + throw new IndexException(de); + + } // end catch + + } // end resolveObject + + } // end class UniStorePartResolver + /*-------------------------------------------------------------------------------- * Static data members *-------------------------------------------------------------------------------- @@ -57,6 +170,8 @@ public class UniStoreManager implements NamedObject, ComponentInitialize, Compon private UserManagement m_users; // user management object private PostDynamicUpdate m_post; // dynamic update posting private HardSoftCache m_msgcache; // message cache + private ComponentShutdown m_res1; + private ComponentShutdown m_res2; /*-------------------------------------------------------------------------------- * Constructor @@ -158,6 +273,13 @@ public class UniStoreManager implements NamedObject, ComponentInitialize, Compon m_users = (UserManagement)(GetObjectUtils.getDynamoComponent(services,UserManagement.class,users_name)); m_post = (PostDynamicUpdate)(services.queryService(PostDynamicUpdate.class)); + // Register our index resolvers. + IndexManagerConfig imcfg = (IndexManagerConfig)(services.queryService(IndexManagerConfig.class)); + m_res1 = imcfg.registerResolver(Namespaces.DEFAULT_INDEX_RESOLVERS_NAMESPACE,"unistore.message", + new UniStoreResolver()); + m_res2 = imcfg.registerResolver(Namespaces.DEFAULT_INDEX_RESOLVERS_NAMESPACE,"unistore.message.part", + new UniStorePartResolver()); + } // end initialize /*-------------------------------------------------------------------------------- @@ -167,6 +289,10 @@ public class UniStoreManager implements NamedObject, ComponentInitialize, Compon public void shutdown() { + m_res1.shutdown(); + m_res1 = null; + m_res2.shutdown(); + m_res2 = null; m_msgcache.clear(); m_post = null; m_srm = null; diff --git a/src/dynamo-framework/com/silverwrist/dynamo/unistore/UniStoreMessages.properties b/src/dynamo-framework/com/silverwrist/dynamo/unistore/UniStoreMessages.properties index 3945167..aab3446 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/unistore/UniStoreMessages.properties +++ b/src/dynamo-framework/com/silverwrist/dynamo/unistore/UniStoreMessages.properties @@ -32,3 +32,6 @@ no.deletePart=You are not authorized to delete a part from message #{0} in the U part.deleted=This part has been deleted. no.deleteMessage=You are not authorized to delete message #{0} in the Universal Message Store. message.deleted=This message has been deleted. +resolver.must.be.message=The object passed to the resolver must be a UniStoreMessage. +invalid.tag=The message tag passed to the resolver was invalid. +resolver.must.be.textpart=The object passed to the resolver must be a UniStoreTextPart.