Author: thomas.heute(a)jboss.com
Date: 2007-06-21 18:13:14 -0400 (Thu, 21 Jun 2007)
New Revision: 7510
Added:
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeException.java
trunk/faces/src/main/org/jboss/portal/faces/portlet/MyFacesJSFBridge.java
trunk/faces/src/main/org/jboss/portal/faces/portlet/SunRIJSFBridge.java
Modified:
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridge.java
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeFacesContextFactoryImpl.java
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeFactory.java
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeLifecycleFactoryImpl.java
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeViewHandlerImpl.java
Log:
Since it works, let's make it a bit more OO
Modified: trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridge.java
===================================================================
--- trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridge.java 2007-06-21
22:12:43 UTC (rev 7509)
+++ trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridge.java 2007-06-21
22:13:14 UTC (rev 7510)
@@ -22,28 +22,19 @@
******************************************************************************/
package org.jboss.portal.faces.portlet;
+import javax.faces.application.ViewHandler;
+import javax.faces.context.FacesContextFactory;
+import javax.faces.lifecycle.LifecycleFactory;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
* @version $Revision: 1.1 $
*/
-public class JSFMetaBridge
+public abstract class JSFMetaBridge
{
/** . */
- static final JSFMetaBridge SUN_JSF = new JSFMetaBridge(
- "jsfportletbridge",
- "com.sun.faces.portlet.FacesPortlet",
- "com.sun.faces.portlet.INIT_VIEW"
- );
-
- /** . */
- static final JSFMetaBridge MYFACES_JSF = new JSFMetaBridge(
- "myfaces",
- "org.apache.myfaces.portlet.MyFacesGenericPortlet",
- "default-view"
- );
-
- /** . */
private final String name;
/** . */
@@ -51,12 +42,23 @@
/** . */
private final String initParamViewName;
+
+ protected FacesContextFactory facesContextFactory;
+ protected LifecycleFactory lifecycleFactory;
+
+ protected ViewHandler viewHandler;
+
public JSFMetaBridge(String name, String portletClassName, String initParamViewName)
{
this.name = name;
this.portletClassName = portletClassName;
this.initParamViewName = initParamViewName;
+ try {
+ init();
+ } catch (JSFMetaBridgeException e) {
+ e.printStackTrace();
+ }
}
public String getName()
@@ -73,4 +75,29 @@
{
return initParamViewName;
}
+
+ protected abstract void init() throws JSFMetaBridgeException;
+
+ public FacesContextFactory getFacesContextFactory()
+ {
+ return facesContextFactory;
+ }
+
+ public LifecycleFactory getLifecycleFactory()
+ {
+ return lifecycleFactory;
+ }
+
+ public ViewHandler getViewHandler()
+ {
+ return viewHandler;
+ }
+
+ protected Object getInstance(String className) throws ClassNotFoundException,
InstantiationException, IllegalAccessException
+ {
+ Class clazz;
+ clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
+ return clazz.newInstance();
+ }
+
}
Added: trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeException.java
===================================================================
--- trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeException.java
(rev 0)
+++
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeException.java 2007-06-21
22:13:14 UTC (rev 7510)
@@ -0,0 +1,42 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.faces.portlet;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision: 1.1 $
+ */
+public class JSFMetaBridgeException extends Exception
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3083908834311924353L;
+
+ public JSFMetaBridgeException(String string, Exception e)
+ {
+ super(string, e);
+ }
+
+}
Modified:
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeFacesContextFactoryImpl.java
===================================================================
---
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeFacesContextFactoryImpl.java 2007-06-21
22:12:43 UTC (rev 7509)
+++
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeFacesContextFactoryImpl.java 2007-06-21
22:13:14 UTC (rev 7510)
@@ -39,44 +39,7 @@
public JSFMetaBridgeFacesContextFactoryImpl()
{
JSFMetaBridge metaBridge = JSFMetaBridgeFactory.getMetaBridge();
- if
(metaBridge.getPortletClassName().equals(JSFMetaBridge.SUN_JSF.getPortletClassName()))
- {
- Class clazz;
- try
- {
- clazz =
Thread.currentThread().getContextClassLoader().loadClass("com.sun.faces.portlet.FacesContextFactoryImpl");
- facesContextFactory = (FacesContextFactory) clazz.newInstance();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- else if
(metaBridge.getPortletClassName().equals(JSFMetaBridge.MYFACES_JSF.getPortletClassName()))
- {
- Class clazz;
- try
- {
- clazz =
Thread.currentThread().getContextClassLoader().loadClass("org.apache.myfaces.context.FacesContextFactoryImpl");
- facesContextFactory = (FacesContextFactory) clazz.newInstance();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-
+ facesContextFactory = metaBridge.getFacesContextFactory();
}
public FacesContext getFacesContext(Object context, Object request, Object response,
Lifecycle lifecycle) throws FacesException
Modified: trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeFactory.java
===================================================================
---
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeFactory.java 2007-06-21
22:12:43 UTC (rev 7509)
+++
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeFactory.java 2007-06-21
22:13:14 UTC (rev 7510)
@@ -44,11 +44,11 @@
String className =
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY).getClass().getName();
if
("com.sun.faces.application.ApplicationFactoryImpl".equals(className))
{
- metaBridge = JSFMetaBridge.SUN_JSF;
+ metaBridge = new SunRIJSFBridge();
}
else if
("org.apache.myfaces.application.ApplicationFactoryImpl".equals(className))
{
- metaBridge = JSFMetaBridge.MYFACES_JSF;
+ metaBridge = new MyFacesJSFBridge();
}
//
Modified:
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeLifecycleFactoryImpl.java
===================================================================
---
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeLifecycleFactoryImpl.java 2007-06-21
22:12:43 UTC (rev 7509)
+++
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeLifecycleFactoryImpl.java 2007-06-21
22:13:14 UTC (rev 7510)
@@ -39,50 +39,12 @@
public JSFMetaBridgeLifecycleFactoryImpl()
{
JSFMetaBridge metaBridge = JSFMetaBridgeFactory.getMetaBridge();
- if
(metaBridge.getPortletClassName().equals(JSFMetaBridge.SUN_JSF.getPortletClassName()))
- {
- Class clazz;
- try
- {
- clazz =
Thread.currentThread().getContextClassLoader().loadClass("com.sun.faces.portlet.LifecycleFactoryImpl");
- lifecycleFactory = (LifecycleFactory) clazz.newInstance();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- else if
(metaBridge.getPortletClassName().equals(JSFMetaBridge.MYFACES_JSF.getPortletClassName()))
- {
- Class clazz;
- try
- {
- clazz =
Thread.currentThread().getContextClassLoader().loadClass("org.apache.myfaces.lifecycle.LifecycleFactoryImpl");
- lifecycleFactory = (LifecycleFactory) clazz.newInstance();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-
+ lifecycleFactory = metaBridge.getLifecycleFactory();
}
public void addLifecycle(String lifecycleId, Lifecycle lifecycle)
{
lifecycleFactory.addLifecycle(lifecycleId, lifecycle);
-
}
public Lifecycle getLifecycle(String lifecycleId)
Modified:
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeViewHandlerImpl.java
===================================================================
---
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeViewHandlerImpl.java 2007-06-21
22:12:43 UTC (rev 7509)
+++
trunk/faces/src/main/org/jboss/portal/faces/portlet/JSFMetaBridgeViewHandlerImpl.java 2007-06-21
22:13:14 UTC (rev 7510)
@@ -23,14 +23,9 @@
package org.jboss.portal.faces.portlet;
import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import javax.faces.FacesException;
-import javax.faces.FactoryFinder;
-import javax.faces.application.Application;
-import javax.faces.application.ApplicationFactory;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
@@ -47,66 +42,7 @@
public JSFMetaBridgeViewHandlerImpl()
{
JSFMetaBridge metaBridge = JSFMetaBridgeFactory.getMetaBridge();
- if
(metaBridge.getPortletClassName().equals(JSFMetaBridge.SUN_JSF.getPortletClassName()))
- {
- Application application = ((ApplicationFactory)
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
- ViewHandler oldViewHandler = application.getViewHandler();
-
- Class clazz;
- try
- {
- Class[] parameterTypes = new Class[] { ViewHandler.class };
- clazz =
Thread.currentThread().getContextClassLoader().loadClass("com.sun.faces.portlet.ViewHandlerImpl");
- Constructor constructor = clazz.getConstructor(parameterTypes);
- viewHandler = (ViewHandler) constructor.newInstance(new Object[] {
oldViewHandler });
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
- else if
(metaBridge.getPortletClassName().equals(JSFMetaBridge.MYFACES_JSF.getPortletClassName()))
- {
- Application application = ((ApplicationFactory)
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
- viewHandler = application.getViewHandler();
-/*
- Class clazz;
- try
- {
- clazz =
Thread.currentThread().getContextClassLoader().loadClass("org.apache.myfaces.application.jsp.JspViewHandlerImpl");
- viewHandler = (ViewHandler) clazz.newInstance();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InstantiationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-*/
- }
-
-
+ viewHandler = metaBridge.getViewHandler();
}
public Locale calculateLocale(FacesContext context)
Added: trunk/faces/src/main/org/jboss/portal/faces/portlet/MyFacesJSFBridge.java
===================================================================
--- trunk/faces/src/main/org/jboss/portal/faces/portlet/MyFacesJSFBridge.java
(rev 0)
+++ trunk/faces/src/main/org/jboss/portal/faces/portlet/MyFacesJSFBridge.java 2007-06-21
22:13:14 UTC (rev 7510)
@@ -0,0 +1,86 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.faces.portlet;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.application.ViewHandler;
+import javax.faces.context.FacesContextFactory;
+import javax.faces.lifecycle.LifecycleFactory;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision: 1.1 $
+ */
+public class MyFacesJSFBridge extends JSFMetaBridge
+{
+
+ private ViewHandler viewHandler;
+
+ public MyFacesJSFBridge()
+ {
+ super("myfaces",
"org.apache.myfaces.portlet.MyFacesGenericPortlet",
+ "default-view");
+ }
+
+ protected void init() throws JSFMetaBridgeException
+ {
+ try
+ {
+ lifecycleFactory = (LifecycleFactory)
getInstance("org.apache.myfaces.lifecycle.LifecycleFactoryImpl");
+ }
+ catch (Exception e)
+ {
+ throw new JSFMetaBridgeException(
+ "Cannot create the JSF lifecycle Factory", e);
+ }
+
+ try
+ {
+ facesContextFactory = (FacesContextFactory)
getInstance("org.apache.myfaces.context.FacesContextFactoryImpl");
+ }
+ catch (Exception e)
+ {
+ throw new JSFMetaBridgeException(
+ "Cannot create the JSF Faces Context Factory", e);
+ }
+
+ Application application = ((ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
+ viewHandler = application.getViewHandler();
+ }
+
+ public ViewHandler getViewHandler()
+ {
+ if (viewHandler == null)
+ {
+ Application application = ((ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
+ viewHandler = application.getViewHandler();
+ }
+ return viewHandler;
+
+ }
+
+}
Added: trunk/faces/src/main/org/jboss/portal/faces/portlet/SunRIJSFBridge.java
===================================================================
--- trunk/faces/src/main/org/jboss/portal/faces/portlet/SunRIJSFBridge.java
(rev 0)
+++ trunk/faces/src/main/org/jboss/portal/faces/portlet/SunRIJSFBridge.java 2007-06-21
22:13:14 UTC (rev 7510)
@@ -0,0 +1,93 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.faces.portlet;
+
+import java.lang.reflect.Constructor;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.application.ViewHandler;
+import javax.faces.context.FacesContextFactory;
+import javax.faces.lifecycle.LifecycleFactory;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision: 1.1 $
+ */
+public class SunRIJSFBridge extends JSFMetaBridge
+{
+
+ public SunRIJSFBridge()
+ {
+ super("jsfportletbridge",
"com.sun.faces.portlet.FacesPortlet",
+ "com.sun.faces.portlet.INIT_VIEW");
+ }
+
+ protected void init() throws JSFMetaBridgeException
+ {
+ try
+ {
+ lifecycleFactory = (LifecycleFactory)
getInstance("com.sun.faces.portlet.LifecycleFactoryImpl");
+ }
+ catch (Exception e)
+ {
+ throw new JSFMetaBridgeException("Cannot create the JSF lifecycle
Factory", e);
+ }
+
+ try
+ {
+ facesContextFactory = (FacesContextFactory)
getInstance("com.sun.faces.portlet.FacesContextFactoryImpl");
+ }
+ catch (Exception e)
+ {
+ throw new JSFMetaBridgeException("Cannot create the JSF Faces Context
Factory", e);
+ }
+ }
+
+ public ViewHandler getViewHandler()
+ {
+ if (viewHandler == null)
+ {
+ try
+ {
+ Application application = ((ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
+ ViewHandler oldViewHandler = application.getViewHandler();
+
+ Class[] parameterTypes = new Class[] { ViewHandler.class };
+ Class clazz = Thread.currentThread().getContextClassLoader()
+ .loadClass("com.sun.faces.portlet.ViewHandlerImpl");
+ Constructor constructor = clazz.getConstructor(parameterTypes);
+ viewHandler = (ViewHandler) constructor
+ .newInstance(new Object[] { oldViewHandler });
+ }
+ catch (Exception e)
+ {
+ Exception e1 = new JSFMetaBridgeException("Cannot create the JSF View
Handler",e);
+ e1.printStackTrace();
+ }
+ }
+ return viewHandler;
+ }
+}