1 package org.directwebremoting.beehive; 2 3 import java.lang.reflect.InvocationTargetException ; 4 import java.lang.reflect.Method ; 5 6 import javax.servlet.http.HttpServletRequest ; 7 8 import org.directwebremoting.WebContextFactory; 9 import org.directwebremoting.create.AbstractCreator; 10 import org.directwebremoting.extend.Creator; 11 import org.directwebremoting.util.LocalUtil; 12 import org.directwebremoting.util.Logger; 13 14 22 public class PageFlowCreator extends AbstractCreator implements Creator 23 { 24 28 public PageFlowCreator() throws ClassNotFoundException 29 { 30 try 32 { 33 bhFlowClass = LocalUtil.classForName("org.apache.beehive.netui.pageflow.PageFlowController"); 34 35 Class bhUtilClass = LocalUtil.classForName("org.apache.beehive.netui.pageflow.PageFlowUtils"); 36 bhGetter = bhUtilClass.getMethod("getCurrentPageFlow", new Class [] { HttpServletRequest .class }); 37 } 38 catch (Exception ex) 39 { 40 } 42 43 try 45 { 46 wlFlowClass = LocalUtil.classForName("com.bea.wlw.netui.pageflow.PageFlowController"); 47 48 Class wlUtilClass = LocalUtil.classForName("com.bea.wlw.netui.pageflow.PageFlowUtils"); 49 wlGetter = wlUtilClass.getMethod("getCurrentPageFlow", new Class [] { HttpServletRequest .class }); 50 } 51 catch (Exception ex) 52 { 53 } 55 56 if ((bhGetter == null && wlGetter == null) || (bhFlowClass == null && wlFlowClass == null)) 57 { 58 throw new ClassNotFoundException ("Beehive/Weblogic jar file not available."); 59 } 60 } 61 62 67 public void setForceWebLogic(boolean forceWebLogic) 68 { 69 if (forceWebLogic) 70 { 71 bhGetter = null; 72 bhFlowClass = null; 73 } 74 } 75 76 79 public Object getInstance() throws InstantiationException 80 { 81 if (getter == null) 82 { 83 getter = (bhGetter != null) ? bhGetter : wlGetter; 84 } 85 86 try 87 { 88 HttpServletRequest request = WebContextFactory.get().getHttpServletRequest(); 89 return getter.invoke(null, new Object [] { request }); 90 } 91 catch (InvocationTargetException ex) 92 { 93 throw new InstantiationException (ex.getTargetException().toString()); 94 } 95 catch (Exception ex) 96 { 97 throw new InstantiationException (ex.toString()); 98 } 99 } 100 101 104 public Class getType() 105 { 106 if (instanceType == null) 107 { 108 try 109 { 110 instanceType = getInstance().getClass(); 111 } 112 catch (InstantiationException ex) 113 { 114 log.error("Failed to instansiate object to detect type.", ex); 115 return Object .class; 116 } 117 } 118 119 return instanceType; 120 } 121 122 125 private static final Logger log = Logger.getLogger(PageFlowCreator.class); 126 127 private Class instanceType; 128 129 private Method getter; 130 131 private Method bhGetter; 132 133 private Method wlGetter; 134 135 private Class bhFlowClass; 136 137 private Class wlFlowClass; 138 } 139 | Popular Tags |