com.sun.faces.spi
Class ManagedBeanFactory

java.lang.Object
  extended by com.sun.faces.spi.ManagedBeanFactory
Direct Known Subclasses:
ManagedBeanFactoryImpl, ManagedBeanFactoryWrapper

public abstract class ManagedBeanFactory
extends java.lang.Object

Define the interface for instantiating a jsf managed-bean instance and discovering its scope. This class primarily has value when used in concert with the ManagedBeanFactoryWrapper class. Clients may provide a <context-param>, as in the following example:


<context-param>
  <param-name>com.sun.faces.managedBeanFactoryDecoratorClass</param-name>
  <param-value>com.sun.faces.systest.NewManagedBeanFactory</param-value>
</context-param>
 

If the class identified by the <param-value> element above has a public constructor that takes a reference to a ManagedBeanFactory as its only argument, it will be called for every <managed-bean> element in the application configuration resources. This argument ManagedBeanFactory instance, called the "parent" will have already been populated with a ManagedBeanBean instance that is a JavaBean that represents the information from the application configuration resources for that particular bean. If desired, the custom ManagedBeanFactory class can leverage any public methods from the parent.

Usage Example


public class NewManagedBeanFactory extends ManagedBeanFactoryWrapper {

    private ManagedBeanFactory parent = null;

    public NewManagedBeanFactory(ManagedBeanFactory old) {
        this.parent = old;
    }

    public ManagedBeanFactory getWrapped() {
        return parent;
    }

    public Object newInstance(FacesContext context) {
      Object newBean = parent.newInstance(context);
      // Take some action after the instantiation of every managed 
      // bean, for example, notify a bean lifecycle listener.

      Scope scope = parent.getScope();
      if (scope == Scope.SESSION) {
        // Take some action involving an HttpSessionListener
        // to call a lifecycle method when the session is destroyed
      }
      else if (scope == Scope.REQUEST) {
        // Take some action involving an ServletRequestListener
        // to call a lifecycle method when the session is destroyed
      }
      else if (scope == Scope.APPLICATION) {
        // Take some action involving a ServletContextListener to call
        // a lifecycle method when the application is destroyed.
      }
    }
}

 

This example shows how you can provide a simple class that hooks into the managed bean creation lifecycle to provide a lifecycle notification scheme.

Author:
edburns, rlubke

Nested Class Summary
static class ManagedBeanFactory.Scope
           
 
Constructor Summary
ManagedBeanFactory()
           
 
Method Summary
abstract  ManagedBeanBean getManagedBeanBean()
          Get the JavaBean that encapsulates the configuration data for the bean instance to be created by this factory.
abstract  java.util.Map<java.lang.String,ManagedBeanFactory> getManagedBeanFactoryMap()
          Get the Map of managed-bean-name to ManagedBeanFactory instances passed in a previous call to setManagedBeanFactoryMap(java.util.Map).
abstract  ManagedBeanFactory.Scope getScope()
          Return the ManagedBeanFactory.Scope of the managed-bean created by this factory.
abstract  boolean isInjectable()
           
abstract  java.lang.Object newInstance(javax.faces.context.FacesContext context)
          Return a new instance of this managed-bean.
abstract  void setManagedBeanBean(ManagedBeanBean bean)
          Set the JavaBean that encapsulates the configuration data for the bean instance to be created by this factory.
abstract  void setManagedBeanFactoryMap(java.util.Map<java.lang.String,ManagedBeanFactory> others)
          Set the Map of managed-bean-name to ManagedBeanFactory instances into this factory instance so that properties that are managed beans may be instantiated if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ManagedBeanFactory

public ManagedBeanFactory()
Method Detail

getScope

public abstract ManagedBeanFactory.Scope getScope()

Return the ManagedBeanFactory.Scope of the managed-bean created by this factory.


newInstance

public abstract java.lang.Object newInstance(javax.faces.context.FacesContext context)

Return a new instance of this managed-bean. It is the caller's responsibility to call getScope() and store the returned managed-bean in the proper scope.


setManagedBeanBean

public abstract void setManagedBeanBean(ManagedBeanBean bean)

Set the JavaBean that encapsulates the configuration data for the bean instance to be created by this factory.


getManagedBeanBean

public abstract ManagedBeanBean getManagedBeanBean()

Get the JavaBean that encapsulates the configuration data for the bean instance to be created by this factory.


setManagedBeanFactoryMap

public abstract void setManagedBeanFactoryMap(java.util.Map<java.lang.String,ManagedBeanFactory> others)

Set the Map of managed-bean-name to ManagedBeanFactory instances into this factory instance so that properties that are managed beans may be instantiated if necessary.


getManagedBeanFactoryMap

public abstract java.util.Map<java.lang.String,ManagedBeanFactory> getManagedBeanFactoryMap()

Get the Map of managed-bean-name to ManagedBeanFactory instances passed in a previous call to setManagedBeanFactoryMap(java.util.Map).

Note that this property enables the factory to know the complete set of configured managed-beans in this application.


isInjectable

public abstract boolean isInjectable()
Returns:
true if the managed bean instance created by this factory is a candidate for resource injection otherwise, returns false


Copyright ? 2002-2006 Sun Microsystems, Inc. All Rights Reserved.