SAP NetWeaver '04

Package com.sapportals.wcm.util.factories

Provides base classes for factory implementations.

See:
          Description

Class Summary
AbstractObjectFactory A factory which produces configurable objects.
ReflectionUtils A wrapper for reflection methods with an WcmException .
ThreadUtils Some tools for starting threads.
 

Package com.sapportals.wcm.util.factories Description

Provides base classes for factory implementations.

Package Specification

Factories are a standard design pattern.
A simple factory, which will create SampleWcmObjects, would look like that:
public class SampleWcmObjectFactory
extends AbstractClassFactory {

  private static final String ID = "samplewcmobject";

  public SampleWcmObjectFactory(String id) {
    super("SampleWcmObjectFactory", id);
  }

  protected void onInitialize()
                       throws WcmException {
    readConfig();
    loadClass();
  }

  protected static SchedulerFactory getInstance()
                                         throws WcmException {
    return (SampleWcmObjectFactory)getFactoryInstance(SampleWcmObjectFactory.class, SINGLETON, ID);
  }

  public static ISampleWcmObject getSampleWcmObject()
                                             throws WcmException {
    return (ISampleWcmObject)getInstance().getClassInstance();
  }

}
To get an object from the factory, one would call the getSampleWcmObject() method, wich will call getInstance() at first:
getInstance() calls the AbstractClassFactory's method getFactoryInstance(). This method expects the class-object of the factory, the type of instanciation (SINGLETON or MULTI) and the id for the factory as parameters. It will call the given classes constructor, passing the id as the constructors parameter. The constructor initializes the base class by calling the AbstractClassFactory's constructor via super().
After creating a new instance of the factory, getFactoryInstance() calls the factories method onInitialize(). The onInitialize() method should do two things:
  1. readConfig() loads the configuration data (the WCM config properties, prefixed by the id of the factory).
  2. loadClass() loads the class with the name defined in the id.class config property (samplewcmobject.class in the sample code).
Afterwards the class for the objects to be produced by the factory is loaded.
So the new factory instance is returned by getInstance() to getSampleWcmObject() and the AbstractClassFactory's method getClassInstance() is called. This method calls the constructor of the class loaded by loadClass(), passing the config properties as the parameter to this constructor.
Finally the newly created instance is returned as the new object.

Therefore, a constructor for SampleWcmObjects should look like this:

public class SampleWcmObject implements ISampleWcmObject {

  public SampleWcmObject(Properities property) {
  }

}
Such an object will be dynamically created by a call to SampleWcmObjectFactory.getSampleWcmObject(), if the SampleWcmObjectFactory is properly configured (with the config entry:
samplewcmobject.class = SampleWcmObject
).


SAP NetWeaver '04

Copyright © 2004 by SAP AG. All Rights Reserved.
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.