public abstract class BeanContext extends Object implements Serializable
| Modifier and Type | Field and Description |
|---|---|
protected static org.slf4j.Logger |
log |
static String |
STATUS |
| Constructor and Description |
|---|
BeanContext() |
| Modifier and Type | Method and Description |
|---|---|
protected <T> T |
checkObject(Object toCheck,
Class<T> expectedClass,
String errorMessage)
Checks whether the specified object is an instance of the specified expected class or throws an
IllegalArgumentException with the specified error message. |
void |
createErrorMessage(String localizedMessageId,
Object... params) |
void |
createErrorMessageFrom(Exception e) |
void |
createErrorMessageFrom(String target,
Exception e)
Creates a localized error message targeting the specified object in the context and using the specified error
information.
|
void |
createInfoMessage(String localizedMessageId) |
protected void |
createInfoMessage(String target,
String localizedMessageId) |
protected void |
createLocalizedMessage(String target,
String localizedMessageId,
Object severity,
Object... params)
Adds a localized message using the appropriate severity to the identified target in the context.
|
protected abstract void |
createMessage(String target,
String message,
Object severity,
Object... additionalParams)
Creates the specified message targeting the specified UI element with the specified severity (semantically left open) with the specified additional parameters.
|
void |
createTargetedErrorMessage(String target,
String localizedMessageId,
Object... params) |
abstract <T> T |
findBean(String name,
Class<T> type)
Finds and retrieves the bean associated with the specified name if it is an instance of the specified type.
|
protected abstract Object |
getErrorSeverity()
Lets subclasses specify the object denoting the error severity
|
abstract <T> T |
getFromFlash(String name,
Class<T> type) |
<T> T |
getFromSession(String name,
Class<T> expectedClass)
Retrieves the session object associated with the specified name and the expected type.
|
protected abstract Object |
getInfoSeverity()
Lets subclasses specify the object denoting the information severity
|
protected abstract Locale |
getLocale()
Retrieves the current locale for the UI.
|
static String |
getLocalizedMessage(String localizationKey,
Locale locale,
Object... params) |
static String |
getLocalizedMessage(String localizationKey,
Locale locale,
String resourceName,
Object... params) |
String |
getMessageFromBundle(String localizedMessageId,
Object... params) |
abstract String |
getParameter(String key)
Retrieves the value of the parameter which name is given from the request.
|
String |
getResourceName() |
abstract String |
getServerAddress()
Retrieves the IP address of the server on which the UI is running.
|
abstract Map<String,Object> |
getSessionMap()
Retrieves the session map where "session" is a concept left up to implementations (for JSF, the session
corresponds quite logically to the HTTP session)
|
abstract void |
putInFlash(String name,
Object value)
Puts the given value in a flash scope that survives across a single request to be retrieved later via the specified name.
|
void |
removeFromSession(String name,
String... otherNames)
Removes the object identified by the specified name(s) from the session.
|
<T> T |
replaceInSession(String name,
T newValue)
Replaces the session object identified by the given name by the specified new one.
|
void |
setResourceName(String resourceName) |
protected static final org.slf4j.Logger log
public static final String STATUS
public void setResourceName(String resourceName)
public String getResourceName()
public abstract String getParameter(String key)
key - name of the parameter which value we want to retrieveprotected abstract void createMessage(String target, String message, Object severity, Object... additionalParams)
target - the identifier of the target UI elementmessage - the message to createdseverity - the severity of the messageadditionalParams - potentially null additional parametersprotected abstract Object getErrorSeverity()
protected abstract Object getInfoSeverity()
protected abstract Locale getLocale()
public abstract String getServerAddress()
public void createTargetedErrorMessage(String target, String localizedMessageId, Object... params)
protected void createLocalizedMessage(String target, String localizedMessageId, Object severity, Object... params)
target - the target in this context that will receive the new messagelocalizedMessageId - a resource bundle identifier identifying which the localized string to use as a messageseverity - an object representing the severity of the message (typically FacesMessage.Severity)params - additional parameters to be passed to replace tokens in localized stringspublic String getMessageFromBundle(String localizedMessageId, Object... params)
public static String getLocalizedMessage(String localizationKey, Locale locale, Object... params)
public static String getLocalizedMessage(String localizationKey, Locale locale, String resourceName, Object... params)
public void createErrorMessageFrom(Exception e)
public void createErrorMessageFrom(String target, Exception e)
UNEXPECTED_ERROR and CAUSE, using the following format for the message: result of getLocalizedMessageOrExceptionName(Throwable) for the exception\n[localized value associated with CAUSEresult of getLocalizedMessageOrExceptionName(Throwable) for the exception's cause if the cause
exists]target - the contextual object target by the message to be createde - the exception that we want to display as an error messagepublic void createInfoMessage(String localizedMessageId)
public void removeFromSession(String name, String... otherNames)
faces-config.xml) to be recreated by
JSF when needed.name - name of the object to be removedotherNames - additional names of objects to be removedpublic abstract Map<String,Object> getSessionMap()
public <T> T replaceInSession(String name, T newValue)
null for
the new value will remove the object reference from the session. If an object was previously assigned to this
name, then only an object of the same type (as defined by Class.isAssignableFrom(Class)) can be assigned
to this name.T - the type of the object to be replacedname - the name identifying the object to be replacednewValue - the new value for the object to be replaced or null if the object is to be removednull if the remove semantics is usedIllegalArgumentException - if the new value for the identified object is not compatible with the currently
stored valuepublic <T> T getFromSession(String name, Class<T> expectedClass)
T - type of the object to be retrievedname - name of the session object to be retrievedexpectedClass - expected class of the objectIllegalArgumentException - if the value associated with the specified name is not null and
does not match the specified expected classprotected <T> T checkObject(Object toCheck, Class<T> expectedClass, String errorMessage)
IllegalArgumentException with the specified error message.T - the type of the expected classtoCheck - the object to checkexpectedClass - the class we expect the object to be an instance oferrorMessage - the error message if the object is not an instance of the expected classpublic abstract <T> T findBean(String name, Class<T> type)
T - the expected type of the beanname - the name of the bean to retrievetype - the expected type of the beanpublic abstract void putInFlash(String name, Object value)
null value switches to a
"remove" semantics where the value (if any) associated with the specified name is removed from the scope.name - the name with which the value can be later retrievedvalue - the value to put in the scope. Using null removes any existing association between the specified name and value in the scope.Copyright © 2006-2014 GateIn. All Rights Reserved.