org.apache.jetspeed.services.psmlmanager
Class CastorPsmlManagerService

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.CastorPsmlManagerService
All Implemented Interfaces:
FileCacheEventListener, org.apache.turbine.services.Initable, javax.jms.MessageListener, PsmlManagerService, org.apache.turbine.services.Service

public class CastorPsmlManagerService
extends org.apache.turbine.services.TurbineBaseService
implements FileCacheEventListener, PsmlManagerService, javax.jms.MessageListener

This service is responsible for loading and saving PSML documents.

Version:
$Id: CastorPsmlManagerService.java,v 1.48 2005/03/21 18:21:44 sgala Exp $
Author:
Raphaël Luta, David Sean Taylor, Santiago Gala

Nested Class Summary
protected  class CastorPsmlManagerService.QueryState
           
 
Field Summary
protected  int cacheSize
          the default cache size
protected static java.lang.String CONFIG_CACHE_SIZE
           
protected static java.lang.String CONFIG_EXT
           
protected static java.lang.String CONFIG_ROOT
           
protected static java.lang.String CONFIG_SCAN_RATE
           
protected  PsmlManagerService consumer
          the import/export consumer service
static java.lang.String DEFAULT_EXT
           
static java.lang.String DEFAULT_MAPPING
           
static java.lang.String DEFAULT_RESOURCE
           
static java.lang.String DEFAULT_ROOT
           
protected  java.lang.String defaultEncoding
          The default encoding used to serialize PSML files to disk
protected  FileCache documents
          The documents loaded by this manager
protected  boolean enableMessaging
           
protected  java.lang.String ext
           
protected  org.apache.xml.serialize.OutputFormat format
          the output format for pretty printing when saving registries
protected  boolean importFlag
           
protected static JetspeedLogger logger
          Static initialization of the logger for this class
protected  java.lang.String mapFile
           
protected  org.exolab.castor.mapping.Mapping mapping
          the Castor mapping file name
protected static java.lang.String PATH_GROUP
           
protected static java.lang.String PATH_ROLE
           
protected static java.lang.String PATH_USER
           
protected  java.lang.String root
           
protected  java.io.File rootDir
           
protected  long scanRate
          the base refresh rate for documents
protected static int STATE_BASE
           
protected static int STATE_COUNTRY
           
protected static int STATE_INIT
           
protected static int STATE_LANGUAGE
           
protected static int STATE_MEDIA
           
protected static int STATE_NAME
           
 
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
 
Constructor Summary
CastorPsmlManagerService()
           
 
Method Summary
 PSMLDocument createDocument(Profile profile)
          Create a new document.
protected  javax.jms.Message createMessage(java.io.Serializable messageObject)
           
protected  Profile createProfile()
          Create a profile based on import flag.
protected  Profile createProfile(ProfileLocator locator)
           
protected  void dump(java.util.Iterator it)
           
protected  void dumpProfile(Profile profile)
           
 void evict(FileCacheEntry entry)
          Evict event, called when the entry is being evicted out of the cache
 int export(PsmlManagerService consumer, QueryLocator locator)
          Query for a collection of profiles given a profile locator criteria.
 PSMLDocument getDocument(java.util.List locators)
          Given a 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 cached PSML document for the given locator
protected  PSMLDocument getDocument(ProfileLocator locator, boolean getCached)
          Returns a PSML document for the given locator
 PSMLDocument getDocument(java.lang.String name)
          Deprecated.  
protected  java.io.File getFile(java.lang.String fileOrUrl)
          Tests wether the passed argument is an URL string or a file name and returns the corresponding file object, using diskcache for remote URLs
 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  Portlets load(java.io.Reader reader)
          Deserializes a PSML structure read from the reader using Castor XML unmarshaller
protected  PSMLDocument loadDocument(java.lang.String fileOrUrl)
          Load a PSMLDOcument from disk
protected  void loadMapping()
           
protected  java.lang.String mapLocatorToFile(ProfileLocator locator)
          Maps a ProfileLocator to a file.
 void onMessage(javax.jms.Message message)
           
 java.util.Iterator query(QueryLocator locator)
          Query for a collection of profiles given a profile locator criteria.
 void refresh(FileCacheEntry entry)
          Refresh event, called when the entry is being refreshed from file system.
 PSMLDocument refresh(ProfileLocator locator)
          Loads a PSML document from disk bypassing the cache
 void removeDocument(ProfileLocator locator)
          Removes a document.
 void removeDocument(ProfileLocator locator, boolean sendMessage)
           
 void removeGroupDocuments(Group group)
          Removes all documents for a given group.
 void removeGroupDocuments(Group group, boolean sendMessage)
           
 void removeRoleDocuments(Role role)
          Removes all documents for a given role.
 void removeRoleDocuments(Role role, boolean sendMessage)
           
 void removeUserDocuments(JetspeedUser user)
          Removes all documents for a given user.
 void removeUserDocuments(JetspeedUser user, boolean sendMessage)
           
protected  void save(java.io.Writer writer, Portlets portlets)
          Serializes a PSML structure using the specified writer with Castor XML marshaller and a Xerces serializer for pretty printing
 boolean saveDocument(PSMLDocument doc)
          Deprecated.  
 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)
          Store the PSML document on disk, using its locator
protected  void subQuery(CastorPsmlManagerService.QueryState qs, java.lang.String path)
          Query for a collection of profiles given a profile locator criteria.
protected  void testCases()
           
 
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


PATH_GROUP

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

PATH_ROLE

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

PATH_USER

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

CONFIG_ROOT

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

CONFIG_EXT

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

CONFIG_SCAN_RATE

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

CONFIG_CACHE_SIZE

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

DEFAULT_ROOT

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

DEFAULT_EXT

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

DEFAULT_RESOURCE

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

root

protected java.lang.String root

rootDir

protected java.io.File rootDir

ext

protected java.lang.String ext

documents

protected FileCache documents
The documents loaded by this manager


format

protected org.apache.xml.serialize.OutputFormat format
the output format for pretty printing when saving registries


scanRate

protected long scanRate
the base refresh rate for documents


cacheSize

protected int cacheSize
the default cache size


consumer

protected PsmlManagerService consumer
the import/export consumer service


importFlag

protected boolean importFlag

DEFAULT_MAPPING

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

mapFile

protected java.lang.String mapFile

mapping

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


defaultEncoding

protected java.lang.String defaultEncoding
The default encoding used to serialize PSML files to disk


enableMessaging

protected boolean enableMessaging

STATE_INIT

protected static int STATE_INIT

STATE_BASE

protected static int STATE_BASE

STATE_NAME

protected static int STATE_NAME

STATE_MEDIA

protected static int STATE_MEDIA

STATE_LANGUAGE

protected static int STATE_LANGUAGE

STATE_COUNTRY

protected static int STATE_COUNTRY
Constructor Detail

CastorPsmlManagerService

public CastorPsmlManagerService()
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

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

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

getDocument

public PSMLDocument getDocument(java.lang.String name)
Deprecated.  

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

getDocument

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

Specified by:
getDocument in interface PsmlManagerService
Parameters:
locator - The locator descriptor of the document to be retrieved.
Returns:
PSML document from cache (or disk if not yet cached)

getDocument

protected PSMLDocument getDocument(ProfileLocator locator,
                                   boolean getCached)
Returns a PSML document for the given locator

Parameters:
locator - The locator descriptor of the document to be retrieved.
getCached - Look in the cache (true) or umarshall a fresh copy from disk (false)
Returns:

refresh

public PSMLDocument refresh(ProfileLocator locator)
Loads a PSML document from disk bypassing the cache

Specified by:
refresh in interface PsmlManagerService
Parameters:
locator -
Returns:
PSML document from disk

loadDocument

protected PSMLDocument loadDocument(java.lang.String fileOrUrl)
Load a PSMLDOcument from disk

Parameters:
fileOrUrl - a String representing either an absolute URL or an absolute filepath

store

public boolean store(Profile profile)
Store the PSML document on disk, using its locator

Specified by:
store in interface PsmlManagerService
Parameters:
profile - the profile locator description.
Returns:
true if the operation succeeded

saveDocument

public boolean saveDocument(PSMLDocument doc)
Deprecated.  

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

saveDocument

public boolean saveDocument(java.lang.String fileOrUrl,
                            PSMLDocument doc)
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

load

protected Portlets load(java.io.Reader reader)
                 throws java.io.IOException,
                        org.exolab.castor.xml.MarshalException,
                        org.exolab.castor.xml.ValidationException,
                        org.exolab.castor.mapping.MappingException
Deserializes a PSML structure read from the reader using Castor XML unmarshaller

Parameters:
reader - the reader to load the PSML from
Throws:
java.io.IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException
org.exolab.castor.mapping.MappingException

loadMapping

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

save

protected void save(java.io.Writer writer,
                    Portlets portlets)
             throws java.io.IOException,
                    org.exolab.castor.xml.MarshalException,
                    org.exolab.castor.xml.ValidationException,
                    org.exolab.castor.mapping.MappingException
Serializes a PSML structure using the specified writer with Castor XML marshaller and a Xerces serializer for pretty printing

Parameters:
writer - the writer to use for serialization
portlets - the structure to save
Throws:
java.io.IOException
org.exolab.castor.xml.MarshalException
org.exolab.castor.xml.ValidationException
org.exolab.castor.mapping.MappingException

getFile

protected java.io.File getFile(java.lang.String fileOrUrl)
Tests wether the passed argument is an URL string or a file name and returns the corresponding file object, using diskcache for remote URLs

Parameters:
fileOrUrl - the URL string or file path
Returns:
a File object. This file may not exist on disk.

createDocument

public PSMLDocument createDocument(Profile profile)
Create a new document.

Specified by:
createDocument in interface PsmlManagerService
Parameters:
profile - The description and default value for the new document.
Returns:
The newly created document;

getDocument

public PSMLDocument getDocument(java.util.List locators)
Given a 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

removeDocument

public void removeDocument(ProfileLocator locator)
Removes a document.

Specified by:
removeDocument in interface PsmlManagerService
Parameters:
locator - The description of the profile resource to be removed.

removeDocument

public void removeDocument(ProfileLocator locator,
                           boolean sendMessage)

removeUserDocuments

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

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

removeUserDocuments

public void removeUserDocuments(JetspeedUser user,
                                boolean sendMessage)

removeRoleDocuments

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

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

removeRoleDocuments

public void removeRoleDocuments(Role role,
                                boolean sendMessage)

removeGroupDocuments

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

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

removeGroupDocuments

public void removeGroupDocuments(Group group,
                                 boolean sendMessage)

mapLocatorToFile

protected java.lang.String mapLocatorToFile(ProfileLocator locator)
Maps a ProfileLocator to a file.

Parameters:
locator - The profile locator describing the PSML resource to be found.
Returns:
the String path of the file.

query

public java.util.Iterator query(QueryLocator locator)
Query for a collection of profiles given a profile locator criteria.

Specified by:
query in interface PsmlManagerService
Parameters:
locator - The profile locator criteria.
Returns:
A collection of profiles that match the criteria specified in the locator.

createProfile

protected Profile createProfile()
Create a profile based on import flag.


createProfile

protected Profile createProfile(ProfileLocator locator)

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.

subQuery

protected void subQuery(CastorPsmlManagerService.QueryState qs,
                        java.lang.String path)
Query for a collection of profiles given a profile locator criteria. To specify 'all' - use '*' in the criteria


testCases

protected void testCases()

dump

protected void dump(java.util.Iterator it)

dumpProfile

protected void dumpProfile(Profile profile)

refresh

public void refresh(FileCacheEntry entry)
Refresh event, called when the entry is being refreshed from file system.

Specified by:
refresh in interface FileCacheEventListener
Parameters:
entry - the entry being refreshed.

evict

public void evict(FileCacheEntry entry)
Evict event, called when the entry is being evicted out of the cache

Specified by:
evict in interface FileCacheEventListener
Parameters:
entry - the entry being refreshed.

createMessage

protected javax.jms.Message createMessage(java.io.Serializable messageObject)

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.