jakarta.faces.application.Application Maven / Gradle / Ivy
Show all versions of myfaces-api Show documentation
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package jakarta.faces.application;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import jakarta.el.ELContextListener;
import jakarta.el.ELException;
import jakarta.el.ELResolver;
import jakarta.el.ExpressionFactory;
import jakarta.el.ValueExpression;
import jakarta.faces.FacesException;
import jakarta.faces.component.UIComponent;
import jakarta.faces.context.ExternalContext;
import jakarta.faces.component.behavior.Behavior;
import jakarta.faces.component.search.SearchExpressionHandler;
import jakarta.faces.component.search.SearchKeywordResolver;
import jakarta.faces.context.FacesContext;
import jakarta.faces.convert.Converter;
import jakarta.faces.event.ActionListener;
import jakarta.faces.event.SystemEvent;
import jakarta.faces.event.SystemEventListener;
import jakarta.faces.flow.FlowHandler;
import jakarta.faces.validator.Validator;
/**
*
* Application represents a per-web-application singleton object where applications based on JavaServer Faces (or
* implementations wishing to provide extended functionality) can register application-wide singletons that provide
* functionality required by JavaServer Faces. Default implementations of each object are provided for cases where the
* application does not choose to customize the behavior.
*
*
*
* The instance of {@link Application} is created by calling the getApplication()
method of
* {@link ApplicationFactory}. Because this instance is shared, it must be implemented in a thread-safe manner.
*
*
* Holds webapp-wide resources for a Faces application. There is a single one of these for a web application, accessable
* via
*
*
* FacesContext.getCurrentInstance().getApplication()
*
*
* In particular, this provides a factory for UIComponent objects. It also provides convenience methods for creating
* ValueBinding objects.
*
* See Javadoc of Faces Specification
*/
@SuppressWarnings("deprecation")
public abstract class Application
{
/**
* Retrieve the current Myfaces Application Instance, lookup
* on the application map. All methods introduced on jsf 1.2
* for Application interface should thrown by default
* UnsupportedOperationException, but the ri scan and find the
* original Application impl, and redirect the call to that
* method instead throwing it, allowing application implementations
* created before jsf 1.2 continue working.
*
* Note: every method, which uses getMyfacesApplicationInstance() to
* delegate itself to the current ApplicationImpl MUST be
* overriden by the current ApplicationImpl to prevent infinite loops.
*/
private Application getMyfacesApplicationInstance()
{
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext != null)
{
ExternalContext externalContext = facesContext.getExternalContext();
if (externalContext != null)
{
return (Application) externalContext.getApplicationMap().get(
"org.apache.myfaces.application.ApplicationImpl");
}
}
return null;
}
private Application getMyfacesApplicationInstance(FacesContext facesContext)
{
if (facesContext != null)
{
ExternalContext externalContext = facesContext.getExternalContext();
if (externalContext != null)
{
return (Application) externalContext.getApplicationMap().get(
"org.apache.myfaces.application.ApplicationImpl");
}
}
return null;
}
// The concrete methods throwing UnsupportedOperationExceptiom were added for Faces 1.2.
// They supply default to allows old Application implementations to still work.
/**
* @since 2.0
*
* FIXME: Notify EG, this should not be abstract and throw UnsupportedOperationException
*
* @param behaviorId
* @param behaviorClass
*/
public void addBehavior(String behaviorId, String behaviorClass)
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
application.addBehavior(behaviorId, behaviorClass);
return;
}
throw new UnsupportedOperationException();
}
/**
* Define a new mapping from a logical "component type" to an actual java class name. This controls what type is
* created when method createComponent of this class is called.
*
* Param componentClass must be the fully-qualified class name of some class extending the UIComponent class. The
* class must have a default constructor, as instances of it will be created using Class.newInstance.
*
* It is permitted to override a previously defined mapping, ie to call this method multiple times with the same
* componentType string. The createComponent method will simply use the last defined mapping.
*/
/**
* Register a new mapping of component type to the name of the corresponding {@link UIComponent} class. This allows
* subsequent calls to createComponent()
to serve as a factory for {@link UIComponent} instances.
*
* @param componentType
* - The component type to be registered
* @param componentClass
* - The fully qualified class name of the corresponding {@link UIComponent} implementation
*
* @throws NullPointerException
* if componentType
or componentClass
is null
*/
public abstract void addComponent(String componentType, String componentClass);
/**
* Register a new converter class that is capable of performing conversions for the specified target class.
*
* @param targetClass
* - The class for which this converter is registered
* @param converterClass
* - The fully qualified class name of the corresponding {@link Converter} implementation
*
* @throws NullPointerException
* if targetClass
or converterClass
is null
*/
public abstract void addConverter(Class> targetClass, String converterClass);
/**
* Register a new mapping of converter id to the name of the corresponding {@link Converter} class. This allows
* subsequent calls to createConverter() to serve as a factory for {@link Converter} instances.
*
* @param converterId
* - The converterId to be registered
* @param converterClass
* - The fully qualified class name of the corresponding {@link Converter} implementation
*
* @throws NullPointerException
* if componentType
or componentClass
is null
*/
public abstract void addConverter(String converterId, String converterClass);
/**
*
* @since 2.0
* @param validatorId
*/
public void addDefaultValidatorId(String validatorId)
{
}
/**
*
* Provide a way for Faces applications to register an ELContextListener
that will be notified on
* creation of ELContext
instances.
*
*
*
* An implementation is provided that throws UnsupportedOperationException
so that users that decorate
* the Application
continue to work.
*
*
* @since 1.2
*/
public void addELContextListener(ELContextListener listener)
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
application.addELContextListener(listener);
return;
}
throw new UnsupportedOperationException();
}
/**
*
* Cause an the argument resolver
to be added to the resolver chain as specified in section 5.5.1 of
* the JavaServer Faces Specification.
*
*
*
* It is not possible to remove an ELResolver
registered with this method, once it has been registered.
*
*
*
* It is illegal to register an ELResolver after the application has received any requests from the client. If an
* attempt is made to register a listener after that time, an IllegalStateException must be thrown.
* ELResolvers
are in the chain, aside from the standard ones. It is permissible to add
* ELResolvers
before or after initialization to a CompositeELResolver that is already in the chain.
*
*
*
* The default implementation throws UnsupportedOperationException
and is provided for the sole purpose
* of not breaking existing applications that extend {@link Application}.
*
*
* @since 1.2
*/
public void addELResolver(ELResolver resolver)
{
// The following concrete methods were added for Faces 1.2. They supply default
// implementations that throw UnsupportedOperationException.
// This allows old Application implementations to still work.
Application application = getMyfacesApplicationInstance();
if (application != null)
{
application.addELResolver(resolver);
return;
}
throw new UnsupportedOperationException();
}
/**
*Register a new mapping of validator id to the name of the corresponding Validator
class. This allows
* subsequent calls to createValidator()
to serve as a factory for Validator
instances.
*
*@param validatorId The validator id to be registered
*@param validatorClass The fully qualified class name of the corresponding Validator implementation
*
*@throws NullPointerException
* if validatorId
or validatorClass
is null
*/
public abstract void addValidator(String validatorId, String validatorClass);
/**
*
* @param behaviorId
* @return
* @throws FacesException
* @since 2.0
*
* FIXME: Notify EG, this should not be abstract and throw UnsupportedOperationException
*/
public Behavior createBehavior(String behaviorId) throws FacesException
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
return application.createBehavior(behaviorId);
}
throw new UnsupportedOperationException();
}
/**
* ???
*
* @param context
* @param componentResource
* @return
*
* @since 2.0
*/
public UIComponent createComponent(FacesContext context, Resource componentResource)
{
Application application = getMyfacesApplicationInstance(context);
if (application != null)
{
return application.createComponent(context, componentResource);
}
throw new UnsupportedOperationException();
}
/**
*
* @param context
* @param componentType
* @param rendererType
* @return
*
* @since 2.0
*/
public UIComponent createComponent(FacesContext context, String componentType, String rendererType)
{
Application application = getMyfacesApplicationInstance(context);
if (application != null)
{
return application.createComponent(context, componentType, rendererType);
}
throw new UnsupportedOperationException();
}
/**
*
* Create a new UIComponent subclass, using the mappings defined by previous calls to the addComponent method of
* this class.
*
*
* @throws FacesException
* if there is no mapping defined for the specified componentType, or if an instance of the specified
* type could not be created for any reason.
*/
public abstract UIComponent createComponent(String componentType) throws FacesException;
/**
*
* Call the getValue()
method on the specified ValueExpression
. If it returns a
* {@link UIComponent}
instance, return it as the value of this method. If it does not, instantiate a
* new {@link UIComponent}
instance of the specified component type, pass the new component to the
* setValue()
method of the specified ValueExpression
, and return it.
*
*
* @param componentExpression
* - ValueExpression
representing a component value expression (typically specified by the
* component
attribute of a custom tag)
* @param context
* - {@link FacesContext} for the current request
* @param componentType
* - Component type to create if the ValueExpression does not return a component instance
*
* @throws FacesException
* if a {@link UIComponent}
cannot be created
* @throws NullPointerException
* if any parameter is null
*
* A default implementation is provided that throws UnsupportedOperationException
so that
* users that decorate Application
can continue to function
*
*
* @since 1.2
*/
public UIComponent createComponent(ValueExpression componentExpression, FacesContext context, String componentType)
throws FacesException
{
Application application = getMyfacesApplicationInstance(context);
if (application != null)
{
return application.createComponent(componentExpression, context, componentType);
}
throw new UnsupportedOperationException();
}
/**
*
* @param componentExpression
* @param context
* @param componentType
* @param rendererType
* @return
*
* @since 2.0
*/
public UIComponent createComponent(ValueExpression componentExpression, FacesContext context, String componentType,
String rendererType)
{
Application application = getMyfacesApplicationInstance(context);
if (application != null)
{
return application.createComponent(componentExpression, context, componentType, rendererType);
}
throw new UnsupportedOperationException();
}
/**
*
* Instantiate and return a new {@link Converter}
instance of the class that has registered itself as
* capable of performing conversions for objects of the specified type. If no such {@link Converter}
* class can be identified, return null.
*
*
*
* To locate an appropriate {@link Converter}
class, the following algorithm is performed, stopping as
* soon as an appropriate {@link Converter}
class is found: Locate a {@link Converter}
* registered for the target class itself. Locate a {@link Converter}
registered for interfaces that
* are implemented by the target class (directly or indirectly). Locate a {@link Converter}
registered
* for the superclass (if any) of the target class, recursively working up the inheritance hierarchy.
*
*
*
* If the {@link Converter}
has a single argument constructor that accepts a Class, instantiate the
* {@link Converter}
using that constructor, passing the argument targetClass
as
* the sole argument. Otherwise, simply use the zero-argument constructor.
*
* @param targetClass
* - Target class for which to return a {@link Converter}
*
* @throws FacesException
* if the {@link Converter}
cannot be created
* @throws NullPointerException
* if targetClass
is null
*
*/
public abstract Converter createConverter(Class> targetClass);
/**
* Instantiate and return a new {@link Converter}
instance of the class specified by a previous call to
* addConverter()
for the specified converter id. If there is no such registration for this converter
* id, return null
.
*
* @param converterId
* - The converter id for which to create and return a new {@link Converter}
instance
*
* @throws FacesException
* if the {@link Converter}
cannot be created
* @throws NullPointerException
* if converterId is null
*/
public abstract Converter createConverter(String converterId);
/**
* Instantiate and return a new {@link Validator}
instance of the class specified by a previous call to
* addValidator()
for the specified validator id.
*
* @param validatorId The {@link Validator}
id for which to create and return a new
* Validator instance
*
* @throws FacesException
* if a {@link Validator}
of the specified id cannot be created
* @throws NullPointerException
* if validatorId is null
*/
public abstract Validator createValidator(String validatorId) throws FacesException;
/**
*
* Get a value by evaluating an expression.
*
*
*
* Call {@link #getExpressionFactory()}
then call
* ExpressionFactory.createValueExpression(jakarta.el.ELContext, java.lang.String, java.lang.Class)
* passing the argument expression
and expectedType
. Call
* {@link FacesContext#getELContext()}
and pass it to
* ValueExpression.getValue(jakarta.el.ELContext)
, returning the result.
*
*
*
* An implementation is provided that throws UnsupportedOperationException
so that users that decorate
* the Application
continue to work.
*
*
* @throws jakarta.el.ELException
*/
public T evaluateExpressionGet(FacesContext context, String expression, Class extends T> expectedType)
throws ELException
{
Application application = getMyfacesApplicationInstance(context);
if (application != null)
{
return application.evaluateExpressionGet(context, expression, expectedType);
}
throw new UnsupportedOperationException();
}
/**
*
* Return the default ActionListener
to be registered for all ActionSource
components
* in this appication. If not explicitly set, a default implementation must be provided that performs the
* following functions:
*
*
* - The
processAction()
method must first call FacesContext.renderResponse()
in order to
* bypass any intervening lifecycle phases, once the method returns.
*
* - The
processAction()
method must next determine the logical
* outcome of this event, as follows:
*
* - If the originating component has a non-
null action
property, retrieve the
* MethodExpression
from the property, and call invoke()
* on it. Convert the returned value (if any) to a String, and use it as the logical outcome.
* - Otherwise, the logical outcome is null.
* - The
processAction()
method must finally retrieve the NavigationHandler
instance
* for this application and call
* NavigationHandler.handleNavigation(jakarta.faces.context.FacesContext,
* java.lang.String, java.lang.String)
passing:
*
* - the {@link FacesContext} for the current request
* - If there is a
MethodExpression
instance for the action
property of this component,
* the result of calling {@link jakarta.el.MethodExpression#getExpressionString()} on it, null otherwise
* - the logical outcome as determined above
*
*
* Note that the specification for the default ActionListener
contiues to call for the use of a
* deprecated property (action
) and class (MethodExpression
). Unfortunately, this is
* necessary because the default ActionListener must continue to work with components that do not implement
* {@link jakarta.faces.component.ActionSource2}, and only implement {@link jakarta.faces.component.ActionSource}.
*/
public abstract ActionListener getActionListener();
/**
*
* @return
*
* @since 2.0
*
* FIXME: Notify EG, this should not be abstract and throw UnsupportedOperationException
*/
public Iterator getBehaviorIds()
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
return application.getBehaviorIds();
}
// It is better to return an empty iterator,
// to keep compatiblity with previous jsf 2.0 Application
// instances
return Collections.EMPTY_LIST.iterator();
}
/**
* Return an Iterator
over the set of currently defined component types for this
* Application
.
*/
public abstract Iterator getComponentTypes();
/**
* Return an Iterator
over the set of currently registered converter ids for this
* Application
*
* @return
*/
public abstract Iterator getConverterIds();
/**
*Return an Iterator
over the set of Class
instances for which {@link Converter}
*
classes
have been explicitly registered.
*
* @return
*/
public abstract Iterator> getConverterTypes();
/**
*Return the default Locale
for this application. If not explicitly set, null
is
* returned.
*
* @return
*/
public abstract Locale getDefaultLocale();
/**
* Return the renderKitId
to be used for rendering this application. If not explicitly set,
* null
is returned.
*
* @return
*/
public abstract String getDefaultRenderKitId();
/**
*
* @return
*
* @since 2.0
*/
public Map getDefaultValidatorInfo()
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
return application.getDefaultValidatorInfo();
}
throw new UnsupportedOperationException();
}
/**
*
* If no calls have been made to addELContextListener(jakarta.el.ELContextListener)
, this method must
* return an empty array
*
* .
*
*
* Otherwise, return an array representing the list of listeners added by calls to
* addELContextListener(jakarta.el.ELContextListener)
.
*
*
*
* An implementation
is provided that throws UnsupportedOperationException so that users that decorate
* the Application
continue to work.
*
*
* @since 1.2
*/
public ELContextListener[] getELContextListeners()
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
return application.getELContextListeners();
}
throw new UnsupportedOperationException();
}
/**
* Return the singleton ELResolver
instance to be used for all EL resolution. This is actually an
* instance of CompositeELResolver
that must contain the following ELResolver instances in the
* following order:
*
* ELResolver
instances declared using the <el-resolver> element in the application
* configuration resources.
*
* - An
implementation
that wraps the head of the legacy VariableResolver chain, as per section
* VariableResolver ChainWrapper
in Chapter 5 in the spec document.
*
* - An
implementation
that wraps the head of the legacy PropertyResolver chain, as per section
* PropertyResolver ChainWrapper
in Chapter 5 in the spec document.
*
* - Any
ELResolver
instances added by calls to
* {@link #addELResolver(jakarta.el.ELResolver)}
.
*
* - The default implementation throws
UnsupportedOperationException
and is provided for the sole
* purpose of not breaking existing applications that extend {@link Application}
.
*
*
* @since 1.2
*/
public ELResolver getELResolver()
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
return application.getELResolver();
}
throw new UnsupportedOperationException();
}
/**
*
* Return the ExpressionFactory
instance for this application.
* This instance is used by the convenience method
* {@link #evaluateExpressionGet(jakarta.faces.context.FacesContext, java.lang.String, java.lang.Class)}.
*
*
*
*
* An implementation is provided that throws UnsupportedOperationException
so that users that decorate
* the Application
continue to work.
*
*
* @since 1.2
* @return
*/
public ExpressionFactory getExpressionFactory()
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
return application.getExpressionFactory();
}
throw new UnsupportedOperationException();
}
/**
* Return the fully qualified class name of the ResourceBundle
to be used for JavaServer Faces messages
* for this application. If not explicitly set, null
is returned.
*/
public abstract String getMessageBundle();
/**
*Return the {@link NavigationHandler}
instance that will be passed the outcome returned by any
* invoked application action for this web application. If not explicitly set, a default implementation must be
* provided that performs the functions described in the {@link NavigationHandler}
class description.
*/
public abstract NavigationHandler getNavigationHandler();
/**
*
* Return the project stage for the currently running application instance. The default value is
* {@link ProjectStage#Production}
*
*
*
* The implementation of this method must perform the following algorithm or an equivalent with the same end result
* to determine the value to return.
*
*
*
* - If the value has already been determined by a previous call to this method, simply return that value.
* - Look for a
JNDI
environment entry under the key given by the value of
* {@link ProjectStage#PROJECT_STAGE_JNDI_NAME}
(return type of java.lang.String). If found, continue
* with the algorithm below, otherwise, look for an entry in the initParamMap
of the
* ExternalContext
from the current FacesContext
with the key
* {@link ProjectStage#PROJECT_STAGE_PARAM_NAME}
* - If a value is found found, see if an enum constant can be obtained by calling
*
ProjectStage.valueOf()
, passing the value from the initParamMap
. If this succeeds
* without exception, save the value and return it.
* - If not found, or any of the previous attempts to discover the enum constant value have failed, log a
* descriptive error message, assign the value as
ProjectStage.Production
and return it.
*
*
* @since 2.0
*/
public ProjectStage getProjectStage()
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
return application.getProjectStage();
}
throw new UnsupportedOperationException();
}
/**
*
* Find a ResourceBundle
as defined in the application configuration resources under the specified
* name. If a ResourceBundle
was defined for the name, return an instance that uses the locale of the
* current {@link jakarta.faces.component.UIViewRoot}
.
*
*
*
* The default implementation throws UnsupportedOperationException
and is provided for the sole purpose
* of not breaking existing applications that extend this class.
*
*
* @return ResourceBundle
for the current UIViewRoot, otherwise null
*
* @throws FacesException
* if a bundle was defined, but not resolvable
* @throws NullPointerException
* if ctx == null || name == null
*/
public ResourceBundle getResourceBundle(FacesContext ctx, String name)
{
Application application = getMyfacesApplicationInstance(ctx);
if (application != null)
{
return application.getResourceBundle(ctx, name);
}
throw new UnsupportedOperationException();
}
/**
*
* Return the singleton, stateless, thread-safe {@link ResourceHandler}
for this application. The Faces
* implementation must support the following techniques for declaring an alternate implementation of
* ResourceHandler
.
*
*
*
* - The
ResourceHandler
implementation is declared in the application configuration resources by
* giving the fully qualified class name as the value of the <resource-handler>
element
* within the
* application
element.
* - RELEASE_PENDING(edburns) It can also be declared via an annotation as
* specified in [287-ConfigAnnotations].
*
*
*
* In all of the above cases, the runtime must employ the decorator pattern as for every other pluggable artifact in
* Faces.
*
*
* @since 2.0
*/
public ResourceHandler getResourceHandler()
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
return application.getResourceHandler();
}
throw new UnsupportedOperationException();
}
/**
* Return the StateManager
instance that will be utilized during the Restore View and Render Response
* phases of the request processing lifecycle. If not explicitly set, a default implementation must be provided that
* performs the functions described in the StateManager
description in the JavaServer Faces
* Specification.
*/
public abstract StateManager getStateManager();
/**
* Return an Iterator
over the supported Locales
for this appication.
*/
public abstract Iterator getSupportedLocales();
/**
*Return an Iterator
over the set of currently registered validator ids for this
* Application
.
*/
public abstract Iterator getValidatorIds();
/**
* Set the {@link ViewHandler}
instance that will be utilized during the
* Restore View and Render Response
phases of the request processing lifecycle.
*
* @return
*/
public abstract ViewHandler getViewHandler();
/**
*
* @param facesContext
* @param systemEventClass
* @param sourceBaseType
* @param source
*
* @since 2.0
*/
public void publishEvent(FacesContext facesContext, Class extends SystemEvent> systemEventClass,
Class> sourceBaseType, Object source)
{
Application application = getMyfacesApplicationInstance(facesContext);
if (application != null)
{
application.publishEvent(facesContext, systemEventClass, sourceBaseType, source);
return;
}
throw new UnsupportedOperationException();
}
/**
*
* If there are one or more listeners for events of the type represented by systemEventClass
, call
* those listeners,passing source as the source
of the event. The implementation should be as fast as
* possible in determining whether or not a listener for the given systemEventClass
and
* source
has been installed, and should return immediately once such a determination has been made.
* The implementation of publishEvent
must honor the requirements stated in
* {@link #subscribeToEvent(java.lang.Class, java.lang.Class,
* jakarta.faces.event.SystemEventListener)}
*
*
* The default implementation must implement an algorithm semantically equivalent to the following to locate
* listener instances and to invoke them.
*
*
* - If the
source
argument implements
* {@link jakarta.faces.event.SystemEventListenerHolder}
, call
* {@link jakarta.faces.event.SystemEventListenerHolder#getListenersForEventClass(java.lang.Class)}
* on it, passing the
* systemEventClass
argument. If the list is not empty, perform algorithm
* traverseListenerList
on the list.
*
* - If any
Application
level listeners have been installed by previous calls to {@link
* #subscribeToEvent(java.lang.Class, java.lang.Class, SystemEventListener)}
, perform algorithm
* traverseListenerList
on the list.
*
* - If any
Application
level listeners have been installed by previous calls to
* {@link #subscribeToEvent(java.lang.Class, SystemEventListener)}
, perform algorithm
* traverseListenerList
on the list.
*
*
*
* If the act of invoking the processListener
method causes an
* {@link jakarta.faces.event.AbortProcessingException}
to be thrown,
* processing of the listeners must be aborted.
*
*
*
* Algorithm traverseListenerList
: For each listener in the list,
*
*
*
* - Call
*
{@link SystemEventListener#isListenerForSource(java.lang.Object)}
, passing the source
* argument. If this returns false
, take no action on the listener.
*
* - Otherwise, if the event to be passed to the listener instances has not yet been constructed, construct the
* event, passing
source
as the argument to the one-argument constructor that takes an
* Object
. This same event instance must be passed to all listener instances.
*
* - Call
*
{@link SystemEvent#isAppropriateListener(jakarta.faces.event.FacesListener)}
, passing the listener
* instance as the argument. If this returns false
, take no action on the listener.
*
* - Call
*
{@link SystemEvent#processListener(jakarta.faces.event.FacesListener)}
,
* passing the listener instance.
*
*
* @param systemEventClass
* - The Class of event that is being published. Must be non-null.
*
* @param source
* - The source
for the event of type systemEventClass. Must be non- null
, and
* must implement {@link jakarta.faces.event.SystemEventListenerHolder}
.
*
* @since 2.0
*/
public void publishEvent(FacesContext facesContext, Class extends SystemEvent> systemEventClass, Object source)
{
Application application = getMyfacesApplicationInstance(facesContext);
if (application != null)
{
application.publishEvent(facesContext, systemEventClass, source);
return;
}
throw new UnsupportedOperationException();
}
/**
*
* Remove the argument listener
from the list of ELContextListeners
. If listener
*
is null, no exception is thrown and no action is performed. If listener
is not in the list,
* no exception is thrown and no action is performed.
*
*
*
* An implementation is provided that throws UnsupportedOperationException
so that users that decorate
* the Application
continue to work.
*
* @param listener
*/
public void removeELContextListener(ELContextListener listener)
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
application.removeELContextListener(listener);
return;
}
throw new UnsupportedOperationException();
}
/**
* Set the default {@link ActionListener}
to be registered for all
* {@link jakarta.faces.component.ActionSource}
* components.
*
* @param listener
* - The new default {@link ActionListener}
*
* @throws NullPointerException
* if listener is null
*/
public abstract void setActionListener(ActionListener listener);
/**
* Set the default Locale
for this application.
*
* @param locale
* - The new default Locale
*
* @throws NullPointerException
* if listener is null
*/
public abstract void setDefaultLocale(Locale locale);
/**
* Return the renderKitId
to be used for rendering this application. If not explicitly set, null
*
is returned.
*
* @param renderKitId
*/
public abstract void setDefaultRenderKitId(String renderKitId);
/**
* Set the fully qualified class name of the ResourceBundle
to be used for JavaServer Faces messages
* for this application. See the JavaDocs for the java.util.ResourceBundle
class for more information
* about the syntax for resource bundle names.
*
* @param bundle
* - Base name of the resource bundle to be used
*
* @throws NullPointerException
* if bundle is null
*/
public abstract void setMessageBundle(String bundle);
/**
* Set the {@link NavigationHandler} instance that will be passed the outcome returned by any invoked application
* action for this web application.
*
* @param handler
* - The new NavigationHandler instance
*/
public abstract void setNavigationHandler(NavigationHandler handler);
/**
*
* @param resourceHandler
*
* @since 2.0
*/
public void setResourceHandler(ResourceHandler resourceHandler)
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
application.setResourceHandler(resourceHandler);
return;
}
throw new UnsupportedOperationException();
}
/**
*Set the {@link StateManager} instance that will be utilized during the Restore View and Render Response
*
phases of the request processing lifecycle.
*
* @param manager The new {@link StateManager}instance
*
* @throws IllegalStateException
* if this method is called after at least one request has been processed by the Lifecycle
* instance for this application.
* @throws NullPointerException
* if manager is null
*/
public abstract void setStateManager(StateManager manager);
/**
* Set the Locale
instances representing the supported Locales
for this application.
*
* @param locales The set of supported Locales
for this application
*
* @throws NullPointerException
* if the argument newLocales is null
.
*
*/
public abstract void setSupportedLocales(Collection locales);
/**
* Set the {@link ViewHandler} instance that will be utilized during the Restore View and Render Response
*
phases of the request processing lifecycle.
*
* @param handler
* - The new {@link ViewHandler} instance
*
* @throws IllegalStateException
* if this method is called after at least one request has been processed by the Lifecycle
* instance for this application.
* @throws NullPointerException
* if handler
is null
*/
public abstract void setViewHandler(ViewHandler handler);
/**
*
* @param systemEventClass
* @param sourceClass
* @param listener
*
* @since 2.0
*/
public void subscribeToEvent(Class extends SystemEvent> systemEventClass, Class> sourceClass,
SystemEventListener listener)
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
application.subscribeToEvent(systemEventClass, sourceClass, listener);
return;
}
throw new UnsupportedOperationException();
}
/**
*
* @param systemEventClass
* @param listener
*
* @since 2.0
*/
public void subscribeToEvent(Class extends SystemEvent> systemEventClass, SystemEventListener listener)
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
application.subscribeToEvent(systemEventClass, listener);
return;
}
subscribeToEvent(systemEventClass, null, listener);
}
/**
*
* @param systemEventClass
* @param sourceClass
* @param listener
*
* @since 2.0
*/
public void unsubscribeFromEvent(Class extends SystemEvent> systemEventClass, Class> sourceClass,
SystemEventListener listener)
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
application.unsubscribeFromEvent(systemEventClass, sourceClass, listener);
return;
}
throw new UnsupportedOperationException();
}
/**
*
* @param systemEventClass
* @param listener
*
* @since 2.0
*/
public void unsubscribeFromEvent(Class extends SystemEvent> systemEventClass, SystemEventListener listener)
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
application.unsubscribeFromEvent(systemEventClass, listener);
return;
}
unsubscribeFromEvent(systemEventClass, null, listener);
}
/**
* @since 2.2
* @return
*/
public FlowHandler getFlowHandler()
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
return application.getFlowHandler();
}
throw new UnsupportedOperationException();
}
/**
* @since 2.2
* @param flowHandler
*/
public void setFlowHandler(FlowHandler flowHandler)
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
application.setFlowHandler(flowHandler);
return;
}
throw new UnsupportedOperationException();
}
public void addSearchKeywordResolver(SearchKeywordResolver resolver)
{
// The following concrete methods were added for Faces 1.2. They supply default
// implementations that throw UnsupportedOperationException.
// This allows old Application implementations to still work.
Application application = getMyfacesApplicationInstance();
if (application != null)
{
application.addSearchKeywordResolver(resolver);
return;
}
throw new UnsupportedOperationException();
}
public SearchKeywordResolver getSearchKeywordResolver()
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
return application.getSearchKeywordResolver();
}
throw new UnsupportedOperationException();
}
/**
* @since 2.3
* @return
*/
public SearchExpressionHandler getSearchExpressionHandler()
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
return application.getSearchExpressionHandler();
}
throw new UnsupportedOperationException();
}
/**
* @since 2.3
* @param searchExpressionHandler
*/
public void setSearchExpressionHandler(SearchExpressionHandler searchExpressionHandler)
{
Application application = getMyfacesApplicationInstance();
if (application != null)
{
application.setSearchExpressionHandler(searchExpressionHandler);
return;
}
throw new UnsupportedOperationException();
}
}