org.apache.jetspeed.services.psmlmanager.db
Class DatabasePsmlManagerService

java.lang.Object
  extended byorg.apache.turbine.services.BaseInitable
      extended byorg.apache.turbine.services.BaseService
          extended byorg.apache.turbine.services.TurbineBaseService
              extended byorg.apache.jetspeed.services.psmlmanager.db.DatabasePsmlManagerService
All Implemented Interfaces:
DatabasePsmlManager, DBOperations, org.apache.turbine.services.Initable, javax.jms.MessageListener, PsmlManagerService, org.apache.turbine.services.Service

public class DatabasePsmlManagerService
extends org.apache.turbine.services.TurbineBaseService
implements DatabasePsmlManager, javax.jms.MessageListener

This service is responsible for loading and saving PSML documents. It uses database to persist the PSML documents.

Version:
$Id: DatabasePsmlManagerService.java,v 1.37 2005/01/17 23:35:30 morciuch Exp $
Author:
Atul Dambalkar, Medha Vaidya, David Sean Taylor

Field Summary
protected static java.lang.String CACHING_ON
           
protected  boolean cachingOn
          whether caching is allowed
protected  PsmlManagerService consumer
          the import/export consumer service
protected static boolean DEFAULT_CACHING_ON
           
static java.lang.String DEFAULT_MAPPING
           
protected static long DEFAULT_REFRESH_RATE
           
protected  boolean enableMessaging
           
protected static JetspeedLogger logger
          Static initialization of the logger for this class
protected  org.exolab.castor.mapping.Mapping mapping
          the Castor mapping file name
protected static java.lang.String POOL_NAME
           
protected  java.lang.String poolName
          The pool name to use for database requests.
protected  java.util.Map psmlCache
           
protected static java.lang.String REFRESH_RATE
           
protected  org.apache.jetspeed.services.psmlmanager.db.DatabasePsmlManagerService.CacheRefresher refresher
          The watcher for the document locations
protected  long refreshRate
          the base refresh rate for documents
 
Fields inherited from class org.apache.turbine.services.BaseService
configuration, name, properties, serviceBroker
 
Fields inherited from class org.apache.turbine.services.BaseInitable
initableBroker, isInitialized
 
Fields inherited from interface org.apache.jetspeed.services.psmlmanager.PsmlManagerService
SERVICE_NAME
 
Fields inherited from interface org.apache.jetspeed.services.psmlmanager.db.DBOperations
DELETE, INSERT, UPDATE
 
Constructor Summary
DatabasePsmlManagerService()
           
 
Method Summary
 PSMLDocument createDocument(Profile profile)
          Stores the PSML document in DB for the given profile
 Profile createGroupProfile(org.apache.jetspeed.om.dbpsml.JetspeedGroupProfile entity, Portlets portlets)
          Creates a group profile from a JetspeedGroupProfile database object.
protected  PSMLDocument createOrSaveDocument(Profile profile, int operation)
           
 Profile createRoleProfile(org.apache.jetspeed.om.dbpsml.JetspeedRoleProfile entity, Portlets portlets)
          Creates a role profile from a JetspeedRoleProfile database object.
 Profile createUserProfile(org.apache.jetspeed.om.dbpsml.JetspeedUserProfile entity, Portlets portlets)
          Creates a user profile from a JetspeedUserProfile database object.
 int export(PsmlManagerService consumer, QueryLocator locator)
          Query for a collection of profiles given a profile locator criteria.
protected  java.sql.Connection getDbConnection()
          Get a database connection to the default or specifed torque database pool
 PSMLDocument getDocument(java.util.List locators)
          Given ordered list of locators, find the first document matching a profile locator, starting from the beginning of the list and working to the end.
 PSMLDocument getDocument(ProfileLocator locator)
          Returns a PSML document for the given locator
 PSMLDocument getDocument(java.lang.String name)
          Returns a PSML document of the given name.
 org.exolab.castor.mapping.Mapping getMapping()
           
protected  java.util.List getProfiles(java.util.List data)
          Get profile iterator from given list of objects.
protected  PSMLDocument getPSMLDocument(java.lang.String page, Portlets portlets)
          Get PSMLDocument object for given pagename and portlets.
 void init()
          Late init method from Turbine Service model
 void init(javax.servlet.ServletConfig conf)
          This is the early initialization method called by the Turbine Service framework
protected  void initConfiguration(javax.servlet.ServletConfig conf)
          Loads the configuration parameters for this service from the JetspeedResources.properties file.
protected  void loadMapping()
           
protected  java.lang.String locatorToString(ProfileLocator locator)
          Return a unique string identifying this object.
 void onMessage(javax.jms.Message message)
           
 java.util.Iterator query(QueryLocator locator)
          Query for a collection of profiles given a profile locator criteria.
 PSMLDocument refresh(ProfileLocator locator)
          Returns a PSML document for the given locator, it is called by the cache refresher
 void removeDocument(ProfileLocator locator)
          Remove the PSMLDocument/profile for given locator object.
 void removeGroupDocuments(Group group)
          Removes all documents for a given group.
 void removeRoleDocuments(Role role)
          Removes all documents for a given role.
 void removeUserDocuments(JetspeedUser user)
          Removes all documents for a given user.
 boolean saveDocument(PSMLDocument doc)
          Save the PSML document on disk, using its name as filepath
 boolean saveDocument(java.lang.String fileOrUrl, PSMLDocument doc)
          Save the PSML document on disk to the specififed fileOrUrl
 void shutdown()
          This is the shutdown method called by the Turbine Service framework
 boolean store(Profile profile)
          Update the PSML document in DB for the given profile
protected  ProfileLocator stringToLocator(java.lang.String locstr)
           
 
Methods inherited from class org.apache.turbine.services.TurbineBaseService
init, init
 
Methods inherited from class org.apache.turbine.services.BaseService
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
 
Methods inherited from class org.apache.turbine.services.BaseInitable
getInit, getInitableBroker, setInit, setInitableBroker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.services.Service
getConfiguration, getName, getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, init, setInitableBroker
 

Field Detail

logger

protected static final JetspeedLogger logger
Static initialization of the logger for this class


psmlCache

protected java.util.Map psmlCache

refresher

protected org.apache.jetspeed.services.psmlmanager.db.DatabasePsmlManagerService.CacheRefresher refresher
The watcher for the document locations


refreshRate

protected long refreshRate
the base refresh rate for documents


REFRESH_RATE

protected static final java.lang.String REFRESH_RATE
See Also:
Constant Field Values

DEFAULT_REFRESH_RATE

protected static final long DEFAULT_REFRESH_RATE
See Also:
Constant Field Values

cachingOn

protected boolean cachingOn
whether caching is allowed


CACHING_ON

protected static final java.lang.String CACHING_ON
See Also:
Constant Field Values

DEFAULT_CACHING_ON

protected static final boolean DEFAULT_CACHING_ON
See Also:
Constant Field Values

POOL_NAME

protected static final java.lang.String POOL_NAME
See Also:
Constant Field Values

consumer

protected PsmlManagerService consumer
the import/export consumer service


DEFAULT_MAPPING

public static final java.lang.String DEFAULT_MAPPING
See Also:
Constant Field Values

mapping

protected org.exolab.castor.mapping.Mapping mapping
the Castor mapping file name


poolName

protected java.lang.String poolName
The pool name to use for database requests.


enableMessaging

protected boolean enableMessaging
Constructor Detail

DatabasePsmlManagerService

public DatabasePsmlManagerService()
Method Detail

init

public void init(javax.servlet.ServletConfig conf)
          throws org.apache.turbine.services.InitializationException
This is the early initialization method called by the Turbine Service framework

Throws:
org.apache.turbine.services.InitializationException

initConfiguration

protected void initConfiguration(javax.servlet.ServletConfig conf)
                          throws org.apache.turbine.services.InitializationException
Loads the configuration parameters for this service from the JetspeedResources.properties file.

Throws:
throws - a InitializationException if the service fails to initialize
org.apache.turbine.services.InitializationException

init

public void init()
          throws org.apache.turbine.services.InitializationException
Late init method from Turbine Service model

Specified by:
init in interface org.apache.turbine.services.Initable
Throws:
org.apache.turbine.services.InitializationException

loadMapping

protected void loadMapping()
                    throws org.apache.turbine.services.InitializationException
Throws:
org.apache.turbine.services.InitializationException

shutdown

public void shutdown()
This is the shutdown method called by the Turbine Service framework

Specified by:
shutdown in interface org.apache.turbine.services.Initable

locatorToString

protected java.lang.String locatorToString(ProfileLocator locator)
Return a unique string identifying this object.


stringToLocator

protected ProfileLocator stringToLocator(java.lang.String locstr)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

getDocument

public PSMLDocument getDocument(java.lang.String name)
Description copied from interface: PsmlManagerService
Returns a PSML document of the given name. For this implementation, the name must be the document URL or absolute filepath

Specified by:
getDocument in interface PsmlManagerService
Parameters:
name - the name of the document to retrieve

saveDocument

public boolean saveDocument(java.lang.String fileOrUrl,
                            PSMLDocument doc)
Description copied from interface: PsmlManagerService
Save the PSML document on disk to the specififed fileOrUrl

Specified by:
saveDocument in interface PsmlManagerService
Parameters:
fileOrUrl - a String representing either an absolute URL or an absolute filepath
doc - the document to save
Returns:
true if the operation succeeded

saveDocument

public boolean saveDocument(PSMLDocument doc)
Description copied from interface: PsmlManagerService
Save the PSML document on disk, using its name as filepath

Specified by:
saveDocument in interface PsmlManagerService
Parameters:
doc - the document to save
Returns:
true if the operation succeeded

getDocument

public PSMLDocument getDocument(ProfileLocator locator)
Returns a PSML document for the given locator

Specified by:
getDocument in interface PsmlManagerService
Parameters:
locator - The locator descriptor(ProfileLocator object) of the document to be retrieved.
Returns:
psmldoc The PSMLDocument object

createDocument

public PSMLDocument createDocument(Profile profile)
Stores the PSML document in DB for the given profile

Specified by:
createDocument in interface PsmlManagerService
Parameters:
profile - The profile that holds the PSMLDocument.
Returns:
PSMLDocument The PSMLDocument that got created in DB.

store

public boolean store(Profile profile)
Update the PSML document in DB for the given profile

Specified by:
store in interface PsmlManagerService
Parameters:
profile - The profile that holds the PSMLDocument.
Returns:
PSMLDocument The PSMLDocument that got created in DB.

createOrSaveDocument

protected PSMLDocument createOrSaveDocument(Profile profile,
                                            int operation)

removeDocument

public void removeDocument(ProfileLocator locator)
Remove the PSMLDocument/profile for given locator object.

Specified by:
removeDocument in interface PsmlManagerService
Parameters:
locator - The profile locator criteria for profile to be removed.

query

public java.util.Iterator query(QueryLocator locator)
Query for a collection of profiles given a profile locator criteria. Use SQL engine to get the required profiles.

Specified by:
query in interface PsmlManagerService
Parameters:
locator - The profile locator criteria.
Returns:
Iterator object with the PSMLDocuments satisfying query

getProfiles

protected java.util.List getProfiles(java.util.List data)
Get profile iterator from given list of objects.

Parameters:
data - List of JetspeedUserProfile, JetspeedGroupProfile, JetspeedRoleProfile, objects
Returns:
List of profiles

getPSMLDocument

protected PSMLDocument getPSMLDocument(java.lang.String page,
                                       Portlets portlets)
Get PSMLDocument object for given pagename and portlets.

Parameters:
portlets - Portlets for the given page name
page - page name for this resource
Returns:
PSMLDocument object for given page and portlets

getDocument

public PSMLDocument getDocument(java.util.List locators)
Given ordered list of locators, find the first document matching a profile locator, starting from the beginning of the list and working to the end.

Specified by:
getDocument in interface PsmlManagerService
Returns:
PSMLDocument object for the first document matching a locator

refresh

public PSMLDocument refresh(ProfileLocator locator)
Returns a PSML document for the given locator, it is called by the cache refresher

Specified by:
refresh in interface PsmlManagerService
Parameters:
locator - The locator descriptor(ProfileLocator object) of the document to be retrieved.
Returns:
psmldoc The PSMLDocument object

removeUserDocuments

public void removeUserDocuments(JetspeedUser user)
Removes all documents for a given user.

Specified by:
removeUserDocuments in interface PsmlManagerService
Parameters:
user - The user object.

removeRoleDocuments

public void removeRoleDocuments(Role role)
Removes all documents for a given role.

Specified by:
removeRoleDocuments in interface PsmlManagerService
Parameters:
role - The role object.

removeGroupDocuments

public void removeGroupDocuments(Group group)
Removes all documents for a given group.

Specified by:
removeGroupDocuments in interface PsmlManagerService
Parameters:
group - The group object.

export

public int export(PsmlManagerService consumer,
                  QueryLocator locator)
Query for a collection of profiles given a profile locator criteria. This method should be used when importing or exporting profiles between services.

Specified by:
export in interface PsmlManagerService
Parameters:
locator - The profile locator criteria.
consumer - The PSML consumer service, receives PSML from this service.
Returns:
The count of profiles exported.

getMapping

public org.exolab.castor.mapping.Mapping getMapping()
Specified by:
getMapping in interface DatabasePsmlManager

createUserProfile

public Profile createUserProfile(org.apache.jetspeed.om.dbpsml.JetspeedUserProfile entity,
                                 Portlets portlets)
Creates a user profile from a JetspeedUserProfile database object.

Parameters:
entity - The user profile entity in the database.
portlets - The PSML blob.
Returns:
A new profile object representing the locator and PSML blob.

createGroupProfile

public Profile createGroupProfile(org.apache.jetspeed.om.dbpsml.JetspeedGroupProfile entity,
                                  Portlets portlets)
Creates a group profile from a JetspeedGroupProfile database object.

Parameters:
entity - The group profile entity in the database.
portlets - The PSML blob.
Returns:
A new profile object representing the locator and PSML blob.

createRoleProfile

public Profile createRoleProfile(org.apache.jetspeed.om.dbpsml.JetspeedRoleProfile entity,
                                 Portlets portlets)
Creates a role profile from a JetspeedRoleProfile database object.

Parameters:
entity - The group profile entity in the database.
portlets - The PSML blob.
Returns:
A new profile object representing the locator and PSML blob.

getDbConnection

protected java.sql.Connection getDbConnection()
Get a database connection to the default or specifed torque database pool


onMessage

public void onMessage(javax.jms.Message message)
Specified by:
onMessage in interface javax.jms.MessageListener


Copyright © 2000-2005 Apache Software Foundation. All Rights Reserved.