com.sapportals.wcm.util.factories

Class AbstractObjectFactory

java.lang.Object
  extended bycom.sapportals.wcm.util.factories.AbstractObjectFactory
Direct Known Subclasses:
ChannelFactory, RecipientFactory

public abstract class AbstractObjectFactory
extends Object

A factory which produces configurable objects.

The classes to load are specified by the classname from the configuration properties.
The objects classes are specified by a commata separated list in the configuration, e.g.:
factory .list = id , id , ...
For each id at least a classname has to be specified and an optional singleton flag, e.g.:
factory . id .class = classname
factory . id .singleton = true
Additional parameters in the form
factory . id . xxx = ...
can be passed to the object's constructor.


Nested Class Summary
protected  class AbstractObjectFactory.ObjectClassEntry
          An object class entry represents the information about the several objects to be created by the factory.
 
Field Summary
protected static String CONFIG_OBJECTLIST_SEPARATOR
          Configuration value for the object id list separator.
protected static String CONFIG_OBJECTLIST_TAG
          Configuration tag for the object id list.
protected static String CONFIG_SINGLETON_DEFAULT
          Default configuration value for the singleton flag.
protected static String CONFIG_SINGLETON_TAG
          Configuration tag for the singleton flag.
protected  String m_ID
          The id of the factory.
protected  String m_LogName
          A short name for logging.
protected  HashMap m_ObjectMap
          The map of ObjectClassEntrys, indexed by object class id.
protected  Properties m_Properties
          The properties (with prefix factory -id) from the config file.
protected static int MULTI
          Code for a multi-instance AbstractObjectFactory .
protected static int SINGLETON
          Code for a singleton AbstractObjectFactory (singleton per id).
 
Constructor Summary
  AbstractObjectFactory(String id)
          Create an AbstractObjectFactory for a given factory-id .
protected AbstractObjectFactory(String logName, String id)
          Create an AbstractObjectFactory for a given factory-id .
 
Method Summary
 Collection getAllObjectInstances()
          Get a list with one instance for each available object class.
protected static AbstractObjectFactory getFactoryInstance(String id, Class classObject, int instanceType)
          Get an initialized instance of a factory for the given id .
protected  Object[] getObjectConstructorParameters(String id, Properties properties)
          Get the actual parameter for the object's constructor.
protected  Class[] getObjectConstructorParameterTypes(String id)
          Get the parameter types for the object classes' constructor.
protected  Object getObjectInstance(String id)
          Create a new instance from the ObjectClassEntry for the given id.
protected  HashMap loadObjectMap(IConfigurable[] configurables)
           
protected  HashMap loadObjectMap(String list, String listSeparator, Properties properties)
          Load the object classes into a map with pairs of id , ObjectEntry s.
protected  AbstractObjectFactory.ObjectClassEntry newObjectListEntry(String id, Constructor constructor, Properties properties, boolean singletonFlag)
          Create a new object class entry for the object class list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_LogName

protected String m_LogName
A short name for logging.


m_ID

protected String m_ID
The id of the factory.


m_Properties

protected Properties m_Properties
The properties (with prefix factory -id) from the config file.


m_ObjectMap

protected HashMap m_ObjectMap
The map of ObjectClassEntrys, indexed by object class id.


CONFIG_OBJECTLIST_TAG

protected static final String CONFIG_OBJECTLIST_TAG
Configuration tag for the object id list.

See Also:
Constant Field Values

CONFIG_OBJECTLIST_SEPARATOR

protected static final String CONFIG_OBJECTLIST_SEPARATOR
Configuration value for the object id list separator.

See Also:
Constant Field Values

CONFIG_SINGLETON_TAG

protected static final String CONFIG_SINGLETON_TAG
Configuration tag for the singleton flag.

See Also:
Constant Field Values

CONFIG_SINGLETON_DEFAULT

protected static final String CONFIG_SINGLETON_DEFAULT
Default configuration value for the singleton flag.

See Also:
Constant Field Values

SINGLETON

protected static final int SINGLETON
Code for a singleton AbstractObjectFactory (singleton per id).

See Also:
Constant Field Values

MULTI

protected static final int MULTI
Code for a multi-instance AbstractObjectFactory .

See Also:
Constant Field Values
Constructor Detail

AbstractObjectFactory

public AbstractObjectFactory(String id)
                      throws WcmException
Create an AbstractObjectFactory for a given factory-id . Should call super( logName , id ) . Note : This constructor has to be public (although it should be protected), to allow the abstract factory the creation of a new derived factories via reflection.

Parameters:
id - a String with the unique id of the factory used as a prefix for the configuration parameters.
Throws:
WcmException - Exception raised in failure situation

AbstractObjectFactory

protected AbstractObjectFactory(String logName,
                                String id)
                         throws WcmException
Create an AbstractObjectFactory for a given factory-id . Note : This constructor has to be public (although it should be protected), to allow the newFactory() -method the creation of new factories.

Parameters:
logName - a String with the factory's short name (for logging).
id - a String with the unique id of the factory used as a prefix for the configuration parameters.
Throws:
WcmException - Exception raised in failure situation
Method Detail

getAllObjectInstances

public Collection getAllObjectInstances()
                                 throws WcmException
Get a list with one instance for each available object class.

Returns:
a Collection of Object s, which may be empty if no object class exists.
Throws:
WcmException - if an error occured while creating the list.

getObjectConstructorParameterTypes

protected Class[] getObjectConstructorParameterTypes(String id)
Get the parameter types for the object classes' constructor.

Parameters:
id - a String with the id of the object class to get the parameter types for.
Returns:
The ObjectConstructorParameterTypes value

getObjectConstructorParameters

protected Object[] getObjectConstructorParameters(String id,
                                                  Properties properties)
                                           throws WcmException
Get the actual parameter for the object's constructor.

Parameters:
id - a String with the id of the object to get the parameter for.
properties -
Returns:
The ObjectConstructorParameters value
Throws:
WcmException - Exception raised in failure situation

getObjectInstance

protected Object getObjectInstance(String id)
                            throws WcmException
Create a new instance from the ObjectClassEntry for the given id.

Parameters:
id - a String with the id of the object class.
Returns:
an Object with an instance of the requested object class specified by the id or null if the id is not found.
Throws:
WcmException - if an object cannot be created.

loadObjectMap

protected HashMap loadObjectMap(String list,
                                String listSeparator,
                                Properties properties)
                         throws WcmException
Load the object classes into a map with pairs of id , ObjectEntry s.

Parameters:
list - a String with a list of id strings for the object classes to load.
listSeparator - a String with the separators for the list string.
properties - the Properties to use for searching the object classes class name and to pass to those object classes.
Returns:
TBD: Description
Throws:
WcmException - if an error occured.

loadObjectMap

protected HashMap loadObjectMap(IConfigurable[] configurables)
                         throws WcmException
Parameters:
configurables -
Returns:
Throws:
WcmException - Exception raised in failure situation

newObjectListEntry

protected AbstractObjectFactory.ObjectClassEntry newObjectListEntry(String id,
                                                                    Constructor constructor,
                                                                    Properties properties,
                                                                    boolean singletonFlag)
Create a new object class entry for the object class list. Create a new object class entry for the object class list. Create a new object class entry for the object class list. Create a new object class entry for the object class list. Create a new object class entry for the object class list. Create a new object class entry for the object class list. Create a new object class entry for the object class list. Create a new object class entry for the object class list. Create a new object class entry for the object class list. create a new object class entry.

Parameters:
id - a String with the id of the object class.
constructor - the Constructor for the object class.
properties - the Properties for the object class.
singletonFlag - a boolean true if this object class should have only one instance, false if not.
Returns:
TDB: Description of the outgoing return value

getFactoryInstance

protected static AbstractObjectFactory getFactoryInstance(String id,
                                                          Class classObject,
                                                          int instanceType)
                                                   throws WcmException
Get an initialized instance of a factory for the given id . This method will handle the type code for the singleton/multi instance behavior.

Parameters:
id - a String with the id for the factory.
classObject - the Class of the (derived) factory.
instanceType - an int with the instance type ( SINGLETON or MULTI ).
Returns:
an AbstractObjectFactory with an instance of the (derived) factory as.
Throws:
WcmException - if the factory cannot be initialized.


Copyright 2006 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.