Java源码示例:javax.faces.FactoryFinder
示例1
public static FacesContext createFacesContext(AbstractXspTest test,
HttpServletRequest request) throws Exception {
FacesController controller = (FacesController) test.getTestLocalVars().get("controller");
if( null == controller ){
bootstrap(test);
controller = (FacesController) test.getTestLocalVars().get("controller");
}
LocalServletContext servletContext = (LocalServletContext) test.getTestLocalVars().get("servletContext");
HttpServletResponse response = new LocalHttpServletResponse(servletContext, null);
FacesContextFactory factory1 = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
FacesContext context = factory1.getFacesContext(servletContext, request, response, controller.getLifecycle());
String sessionId = request.getSession().getId();
SessionUtil.setSessionId(context, sessionId);
test.getTestLocalVars().put("facesContext", context);
return context;
}
示例2
/**
* Calls through to {@link javax.faces.FactoryFinder#releaseFactories()}
* ignoring any exceptions.
*/
private void releaseFactories() {
try {
FactoryFinder.releaseFactories();
} catch (FacesException ignored) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE,
"Exception thrown from FactoryFinder.releaseFactories()",
ignored);
}
}
}
示例3
public void listAllPhaseListeners() {
LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder
.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle applicationLifecycle = lifecycleFactory
.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
PhaseListener phaseListeners[] = applicationLifecycle
.getPhaseListeners();
for (PhaseListener phaseListener : phaseListeners) {
System.out.println(phaseListener.getPhaseId());
}
}
示例4
@Test
public void testInitJsfActionListener() throws NoSuchMethodException, SecurityException,
InvocationTargetException, IllegalAccessException {
final ServletContext servletContext = createNiceMock(ServletContext.class);
expect(servletContext.getInitParameter("com.sun.faces.enableTransitionTimeNoOpFlash"))
.andReturn(null).anyTimes();
final Enumeration<String> initParameterNames = Collections.emptyEnumeration();
expect(servletContext.getInitParameterNames()).andReturn(initParameterNames).anyTimes();
replay(servletContext);
final InitFacesContext facesContext = new InitFacesContext(servletContext);
final Method setter = FacesContext.class.getDeclaredMethod("setCurrentInstance",
FacesContext.class);
setter.setAccessible(true);
setter.invoke(null, facesContext);
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, AppFactory.class.getName());
verify(servletContext);
final ActionListener delegateActionListener = createNiceMock(ActionListener.class);
FacesContext.getCurrentInstance().getApplication()
.setActionListener(delegateActionListener);
JsfActionHelper.initJsfActionListener();
final UIComponent uiComponent = createNiceMock(UIComponent.class);
final ActionEvent actionEvent = new ActionEvent(uiComponent);
final ActionListener actionListener = FacesContext.getCurrentInstance().getApplication()
.getActionListener();
actionListener.processAction(actionEvent);
MonitoringProxy.getJsfCounter().setDisplayed(false);
actionListener.processAction(actionEvent);
MonitoringProxy.getJsfCounter().setDisplayed(true);
}
示例5
/**
* Helper method to look up template backing bean.
* @param context the faces context
* @return the backing bean
* @throws FacesException
*/
protected TemplateBean lookupTemplateBean(FacesContext context) throws
FacesException
{
TemplateBean templateBean;
//FacesContext facesContext = FacesContext.getCurrentInstance();
ApplicationFactory factory = (ApplicationFactory) FactoryFinder.getFactory(
FactoryFinder.APPLICATION_FACTORY);
Application application = factory.getApplication();
templateBean = (TemplateBean)
application.getVariableResolver().resolveVariable(context, "template");
return templateBean;
}
示例6
/**
* Helper method to look up backing bean.
* Don't forget to cast!
* e.g. (TemplateBean) ContextUtil.lookupBean("template")
* @param context the faces context
* @return the backing bean
* @throws FacesException
*/
public static Serializable lookupBean(String beanName)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
ApplicationFactory factory = (ApplicationFactory) FactoryFinder.
getFactory(
FactoryFinder.APPLICATION_FACTORY);
Application application = factory.getApplication();
Serializable bean = (Serializable)
application.getVariableResolver().resolveVariable(
facesContext, beanName);
return bean;
}
示例7
/**
* Helper method to look up backing bean, when OUTSIDE faces in a servlet.
* Don't forget to cast!
* e.g. (TemplateBean) ContextUtil.lookupBean("template")
*
* @param beanName
* @param request servlet request
* @param response servlet response
* @return the backing bean
*/
public static Serializable lookupBeanFromExternalServlet(String beanName,
HttpServletRequest request, HttpServletResponse response)
{
// prepare lifecycle
LifecycleFactory lFactory = (LifecycleFactory)
FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle =
lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
FacesContextFactory fcFactory = (FacesContextFactory)
FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
// in the integrated environment, we can't get the ServletContext from the
// HttpSession of the request - because the HttpSession is webcontainer-wide,
// its not tied to a particular servlet.
ServletContext servletContext = M_servletContext;
if (servletContext == null)
{
servletContext = request.getSession().getServletContext();
}
FacesContext facesContext =
fcFactory.getFacesContext(servletContext, request, response, lifecycle);
ApplicationFactory factory = (ApplicationFactory) FactoryFinder.
getFactory(
FactoryFinder.APPLICATION_FACTORY);
Application application = factory.getApplication();
Serializable bean = (Serializable)
application.getVariableResolver().resolveVariable(
facesContext, beanName);
return bean;
}
示例8
public ValueBinding getValueBinding(String valueRef) {
ApplicationFactory af =
(ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
Application a = af.getApplication();
return (a.createValueBinding(valueRef));
}
示例9
/**
* Helper method to look up backing bean, when OUTSIDE faces in a servlet.
* Don't forget to cast! e.g. (TemplateBean)
* ContextUtil.lookupBean("template")
*
* @param beanName
* @param request
* servlet request
* @param response
* servlet response
* @return the backing bean
*/
public Serializable lookupBeanFromExternalServlet(String beanName,
HttpServletRequest request, HttpServletResponse response) {
// prepare lifecycle
LifecycleFactory lFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle = lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
FacesContextFactory fcFactory = (FacesContextFactory) FactoryFinder
.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
// in the integrated environment, we can't get the ServletContext from
// the
// HttpSession of the request - because the HttpSession is
// webcontainer-wide,
// its not tied to a particular servlet.
if (this.servletContext == null) {
servletContext = request.getSession().getServletContext();
}
FacesContext facesContext = fcFactory.getFacesContext(servletContext,
request, response, lifecycle);
ApplicationFactory factory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
Application application = factory.getApplication();
Serializable bean = (Serializable) application.getVariableResolver().resolveVariable(facesContext, beanName);
return bean;
}
示例10
private RenderKitCheckInfo[] getRenderKitInfos(FacesContext context) {
// get from subclass
RenderKitCheckInfo[] kitInfos = createRenderKitInfos();
// validate RenderKitInfos RenderKits exist
RenderKitFactory factory = (RenderKitFactory) FactoryFinder
.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
for (int i = 0; i < kitInfos.length; i++) {
RenderKit kit = kitInfos[i].findRenderKit(context, factory);
if (null == kit) {
assertNotNull("No faces-config containing the renderKit "+ kitInfos[i].getRenderKitId(), /*kit*/null);
}
}
return kitInfos;
}
示例11
/**
* Helper method to look up template backing bean.
* @param context the faces context
* @return the backing bean
* @throws FacesException
*/
protected TemplateBean lookupTemplateBean(FacesContext context) throws
FacesException
{
TemplateBean templateBean;
//FacesContext facesContext = FacesContext.getCurrentInstance();
ApplicationFactory factory = (ApplicationFactory) FactoryFinder.getFactory(
FactoryFinder.APPLICATION_FACTORY);
Application application = factory.getApplication();
templateBean = (TemplateBean)
application.getVariableResolver().resolveVariable(context, "template");
return templateBean;
}
示例12
/**
* Helper method to look up backing bean.
* Don't forget to cast!
* e.g. (TemplateBean) ContextUtil.lookupBean("template")
* @param context the faces context
* @return the backing bean
* @throws FacesException
*/
public static Serializable lookupBean(String beanName)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
ApplicationFactory factory = (ApplicationFactory) FactoryFinder.
getFactory(
FactoryFinder.APPLICATION_FACTORY);
Application application = factory.getApplication();
Serializable bean = (Serializable)
application.getVariableResolver().resolveVariable(
facesContext, beanName);
return bean;
}
示例13
/**
* Helper method to look up backing bean, when OUTSIDE faces in a servlet.
* Don't forget to cast!
* e.g. (TemplateBean) ContextUtil.lookupBean("template")
*
* @param beanName
* @param request servlet request
* @param response servlet response
* @return the backing bean
*/
public static Serializable lookupBeanFromExternalServlet(String beanName,
HttpServletRequest request, HttpServletResponse response)
{
// prepare lifecycle
LifecycleFactory lFactory = (LifecycleFactory)
FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle =
lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
FacesContextFactory fcFactory = (FacesContextFactory)
FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
// in the integrated environment, we can't get the ServletContext from the
// HttpSession of the request - because the HttpSession is webcontainer-wide,
// its not tied to a particular servlet.
ServletContext servletContext = M_servletContext;
if (servletContext == null)
{
servletContext = request.getSession().getServletContext();
}
FacesContext facesContext =
fcFactory.getFacesContext(servletContext, request, response, lifecycle);
ApplicationFactory factory = (ApplicationFactory) FactoryFinder.
getFactory(
FactoryFinder.APPLICATION_FACTORY);
Application application = factory.getApplication();
Serializable bean = (Serializable)
application.getVariableResolver().resolveVariable(
facesContext, beanName);
return bean;
}
示例14
public ValueBinding getValueBinding(String valueRef) {
ApplicationFactory af =
(ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
Application a = af.getApplication();
return (a.createValueBinding(valueRef));
}
示例15
/**
* Helper method to look up backing bean, when OUTSIDE faces in a servlet.
* Don't forget to cast! e.g. (TemplateBean)
* ContextUtil.lookupBean("template")
*
* @param beanName
* @param request
* servlet request
* @param response
* servlet response
* @return the backing bean
*/
public Serializable lookupBeanFromExternalServlet(String beanName,
HttpServletRequest request, HttpServletResponse response) {
// prepare lifecycle
LifecycleFactory lFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle = lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
FacesContextFactory fcFactory = (FacesContextFactory) FactoryFinder
.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
// in the integrated environment, we can't get the ServletContext from
// the
// HttpSession of the request - because the HttpSession is
// webcontainer-wide,
// its not tied to a particular servlet.
if (this.servletContext == null) {
servletContext = request.getSession().getServletContext();
}
FacesContext facesContext = fcFactory.getFacesContext(servletContext,
request, response, lifecycle);
ApplicationFactory factory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
Application application = factory.getApplication();
Serializable bean = (Serializable) application.getVariableResolver().resolveVariable(facesContext, beanName);
return bean;
}
示例16
public void runTask() throws Exception {
RenderKitFactory rkFactory = (RenderKitFactory) FactoryFinder.getFactory("javax.faces.render.RenderKitFactory");
RenderKitImpl html_basic = (RenderKitImpl) rkFactory.getRenderKit(FacesContext.getCurrentInstance(), "HTML_BASIC");
final RenderKit renderKit = new MyRenderKit();
Field rendererFamiliesField = RenderKitImpl.class.getDeclaredField("rendererFamilies");
rendererFamiliesField.setAccessible(true);
HashMap rendererFamiles = (HashMap) rendererFamiliesField.get(html_basic);
rendererFamiliesField.set(renderKit, rendererFamiles);
rkFactory.addRenderKit("HTML_BASIC", renderKit);
JsonElement jsonElement = new Gson().toJsonTree(renderKit);
}
示例17
protected void initJsf()
{
FactoryFinder.releaseFactories();
onPreInitJsf();
initLifecycle();
initApplication();
initRenderKit();
}
示例18
protected void onPreInitJsf()
{
//init mocked jsf factories
addFactory(FactoryFinder.APPLICATION_FACTORY, MockApplicationFactory.class.getName());
addFactory(FactoryFinder.FACES_CONTEXT_FACTORY, MockFacesContextFactory.class.getName());
addFactory(FactoryFinder.LIFECYCLE_FACTORY, MockLifecycleFactory.class.getName());
addFactory(FactoryFinder.RENDER_KIT_FACTORY, MockRenderKitFactory.class.getName());
addFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY, MockExceptionHandlerFactory.class.getName());
addFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY, MockPartialViewContextFactory.class.getName());
addFactory(FactoryFinder.VISIT_CONTEXT_FACTORY, MockVisitContextFactory.class.getName());
}
示例19
protected void initRenderKit()
{
RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
this.renderKit = new MockRenderKit();
renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, this.renderKit);
}
示例20
protected void initFacesContext()
{
FacesContextFactory facesContextFactory =
(FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
this.facesContext = facesContextFactory.getFacesContext(
this.servletContext, this.request, this.response, this.lifecycle);
((MockFacesContext) this.facesContext).setApplication(this.application);
ExceptionHandler exceptionHandler = ((ExceptionHandlerFactory)
FactoryFinder.getFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY)).getExceptionHandler();
this.facesContext.setExceptionHandler(exceptionHandler);
((MockFacesContext) this.facesContext).setExternalContext(
new MockExternalContext(this.servletContext, this.request, this.response));
}
示例21
public void shutdown()
{
this.application = null;
this.servletConfig = null;
this.containerConfig = null;
this.lifecycle = null;
this.renderKit = null;
this.servletContext = null;
FactoryFinder.releaseFactories();
}
示例22
public void init(ServletConfig servletConfig) throws ServletException {
this.servletConfig = servletConfig;
// Create the FacesContextFactory
this.contextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
}
示例23
protected void addFactory(String factoryName, String className)
{
FactoryFinder.setFactory(factoryName, className);
}
示例24
protected void initLifecycle()
{
LifecycleFactory lifecycleFactory =
(LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
this.lifecycle = lifecycleFactory.getLifecycle(getLifecycleId());
}
示例25
protected void initApplication()
{
ApplicationFactory applicationFactory =
(ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
this.application = applicationFactory.getApplication();
}