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.
Modifier and Type | Class and Description |
---|---|
static class |
ManagedBeanFactory.Scope |
Constructor and Description |
---|
ManagedBeanFactory() |
Modifier and Type | Method and Description |
---|---|
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<java.lang.String, com.sun.faces.spi.ManagedBeanFactory>) . |
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. |
public abstract ManagedBeanFactory.Scope getScope()
Return the ManagedBeanFactory.Scope
of the managed-bean created by this
factory.
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.
public abstract void setManagedBeanBean(ManagedBeanBean bean)
Set the JavaBean that encapsulates the configuration data for the bean instance to be created by this factory.
public abstract ManagedBeanBean getManagedBeanBean()
Get the JavaBean that encapsulates the configuration data for the bean instance to be created by this factory.
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.
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<java.lang.String, com.sun.faces.spi.ManagedBeanFactory>)
.
Note that this property enables the factory to know the complete set of configured managed-beans in this application.
public abstract boolean isInjectable()
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.