Update of /cvsroot/xdoclet/xdoclet/modules/ejb/src/xdoclet/modules/ejb/lookup/resources
In directory 
sc8-pr-cvs1:/tmp/cvs-serv678/modules/ejb/src/xdoclet/modules/ejb/lookup/resources

Modified Files:
        lookup.xdt 
Log Message:
Experimental changes for allowing stateless session beans to be proxied as local calls 
without RMI.  A result of the realization that SLSB is just a nuciance during 
development when Hibernate is already substituting for entity beans.

Index: lookup.xdt
===================================================================
RCS file: 
/cvsroot/xdoclet/xdoclet/modules/ejb/src/xdoclet/modules/ejb/lookup/resources/lookup.xdt,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** lookup.xdt  25 Feb 2003 23:21:04 -0000      1.8
--- lookup.xdt  5 Aug 2003 05:50:05 -0000       1.9
***************
*** 21,24 ****
--- 21,45 ----
   </XDtConfig:ifConfigParamEquals>
  
+    private static Object lookupHome(java.util.Hashtable environment, String 
jndiName, Class narrowTo) throws javax.naming.NamingException {
+     <XDtEjbUtilObj:ifNotGenerateLocalProxy>
+       // Obtain initial context
+       javax.naming.InitialContext initialContext = new 
javax.naming.InitialContext(environment);
+       try {
+          Object objRef = initialContext.lookup(jndiName);
+          // only narrow if necessary
+          if (narrowTo.isInstance(java.rmi.Remote.class))
+             return javax.rmi.PortableRemoteObject.narrow(objRef, narrowTo);
+          else
+             return objRef;
+       } finally {
+          initialContext.close();
+       }
+     </XDtEjbUtilObj:ifNotGenerateLocalProxy>
+     <XDtEjbUtilObj:ifGenerateLocalProxy>
+        return 
java.lang.reflect.Proxy.newProxyInstance(<XDtEjb:shortEjbName/>HomeProxy.class.getClassLoader(),
+                new Class[] {<XDtEjb:shortEjbName/>Home.class}, new 
<XDtEjb:shortEjbName/>HomeProxy());
+     </XDtEjbUtilObj:ifGenerateLocalProxy>
+    }
+ 
     // <XDtI18n:getString bundle="xdoclet.modules.ejb.XDocletModulesEjbMessages" 
resource="util_home_lookups"/>
  
***************
*** 32,55 ****
        <XDtConfig:ifConfigParamEquals paramName="cacheHomes" value="true">
        if (cachedRemoteHome == null) {
!          // <XDtI18n:getString 
bundle="xdoclet.modules.ejb.XDocletModulesEjbMessages" resource="util_obtain_ic"/>
!          javax.naming.InitialContext initialContext = new 
javax.naming.InitialContext();
!          try {
!             java.lang.Object objRef = 
initialContext.lookup(<XDtEjbHome:homeInterface 
type="remote"/>.<XDtEjbUtilObj:lookupKind/>);
!             cachedRemoteHome = (<XDtEjbHome:homeInterface type="remote"/>) 
javax.rmi.PortableRemoteObject.narrow(objRef, <XDtEjbHome:homeInterface 
type="remote"/>.class);
!          } finally {
!             initialContext.close();
!          }
        }
        return cachedRemoteHome;
        </XDtConfig:ifConfigParamEquals>
        <XDtConfig:ifConfigParamNotEquals paramName="cacheHomes" value="true">
!       // <XDtI18n:getString bundle="xdoclet.modules.ejb.XDocletModulesEjbMessages" 
resource="util_obtain_ic"/>
!       javax.naming.InitialContext initialContext = new javax.naming.InitialContext();
!       try {
!          java.lang.Object objRef = initialContext.lookup(<XDtEjbHome:homeInterface 
type="remote"/>.<XDtEjbUtilObj:lookupKind/>);
!          return (<XDtEjbHome:homeInterface type="remote"/>) 
javax.rmi.PortableRemoteObject.narrow(objRef, <XDtEjbHome:homeInterface 
type="remote"/>.class);
!       } finally {
!          initialContext.close();
!       }
        </XDtConfig:ifConfigParamNotEquals>
     }
--- 53,62 ----
        <XDtConfig:ifConfigParamEquals paramName="cacheHomes" value="true">
        if (cachedRemoteHome == null) {
!             cachedRemoteHome = (<XDtEjbHome:homeInterface type="remote"/>) 
lookupHome(null, <XDtEjbHome:homeInterface 
type="remote"/>.<XDtEjbUtilObj:lookupKind/>, <XDtEjbHome:homeInterface 
type="remote"/>.class);
        }
        return cachedRemoteHome;
        </XDtConfig:ifConfigParamEquals>
        <XDtConfig:ifConfigParamNotEquals paramName="cacheHomes" value="true">
!          return (<XDtEjbHome:homeInterface type="remote"/>) lookupHome(null, 
<XDtEjbHome:homeInterface type="remote"/>.<XDtEjbUtilObj:lookupKind/>, 
<XDtEjbHome:homeInterface type="remote"/>.class);
        </XDtConfig:ifConfigParamNotEquals>
     }
***************
*** 62,73 ****
     public static <XDtEjbHome:homeInterface type="remote"/> getHome( 
java.util.Hashtable environment ) throws javax.naming.NamingException
     {
!       // <XDtI18n:getString bundle="xdoclet.modules.ejb.XDocletModulesEjbMessages" 
resource="util_obtain_ic"/>
!       javax.naming.InitialContext initialContext = new 
javax.naming.InitialContext(environment);
!       try {
!          java.lang.Object objRef = initialContext.lookup(<XDtEjbHome:homeInterface 
type="remote"/>.<XDtEjbUtilObj:lookupKind/>);
!          return (<XDtEjbHome:homeInterface type="remote"/>) 
javax.rmi.PortableRemoteObject.narrow(objRef, <XDtEjbHome:homeInterface 
type="remote"/>.class);
!       } finally {
!          initialContext.close();
!       }
     }
     </XDtEjbIntf:ifRemoteEjb>
--- 69,73 ----
     public static <XDtEjbHome:homeInterface type="remote"/> getHome( 
java.util.Hashtable environment ) throws javax.naming.NamingException
     {
!        return (<XDtEjbHome:homeInterface type="remote"/>) lookupHome(environment, 
<XDtEjbHome:homeInterface type="remote"/>.<XDtEjbUtilObj:lookupKind/>, 
<XDtEjbHome:homeInterface type="remote"/>.class);
     }
     </XDtEjbIntf:ifRemoteEjb>
***************
*** 80,104 ****
     public static <XDtEjbHome:homeInterface type="local"/> getLocalHome() throws 
javax.naming.NamingException
     {
-       // <XDtI18n:getString bundle="xdoclet.modules.ejb.XDocletModulesEjbMessages" 
resource="util_localhome_not_narrowed"/>
        <XDtConfig:ifConfigParamEquals paramName="cacheHomes" value="true">
        if (cachedLocalHome == null) {
!          // <XDtI18n:getString 
bundle="xdoclet.modules.ejb.XDocletModulesEjbMessages" resource="util_obtain_ic"/>
!          javax.naming.InitialContext initialContext = new 
javax.naming.InitialContext();
!          try {
!             cachedLocalHome = (<XDtEjbHome:homeInterface type="local"/>) 
initialContext.lookup(<XDtEjbHome:homeInterface 
type="local"/>.<XDtEjbUtilObj:lookupKind/>);
!          } finally {
!             initialContext.close();
!          }
        }
        return cachedLocalHome;
        </XDtConfig:ifConfigParamEquals>
        <XDtConfig:ifConfigParamNotEquals paramName="cacheHomes" value="true">
!       // <XDtI18n:getString bundle="xdoclet.modules.ejb.XDocletModulesEjbMessages" 
resource="util_obtain_ic"/>
!       javax.naming.InitialContext initialContext = new javax.naming.InitialContext();
!       try {
!          return (<XDtEjbHome:homeInterface type="local"/>) 
initialContext.lookup(<XDtEjbHome:homeInterface 
type="local"/>.<XDtEjbUtilObj:lookupKind/>);
!       } finally {
!          initialContext.close();
!       }
        </XDtConfig:ifConfigParamNotEquals>
     }
--- 80,91 ----
     public static <XDtEjbHome:homeInterface type="local"/> getLocalHome() throws 
javax.naming.NamingException
     {
        <XDtConfig:ifConfigParamEquals paramName="cacheHomes" value="true">
        if (cachedLocalHome == null) {
!             cachedLocalHome = (<XDtEjbHome:homeInterface type="local"/>) 
lookupHome(null, <XDtEjbHome:homeInterface 
type="remote"/>.<XDtEjbUtilObj:lookupKind/>, <XDtEjbHome:homeInterface 
type="remote"/>.class);
        }
        return cachedLocalHome;
        </XDtConfig:ifConfigParamEquals>
        <XDtConfig:ifConfigParamNotEquals paramName="cacheHomes" value="true">
!       return (<XDtEjbHome:homeInterface type="local"/>) lookupHome(null, 
<XDtEjbHome:homeInterface type="remote"/>.<XDtEjbUtilObj:lookupKind/>, 
<XDtEjbHome:homeInterface type="remote"/>.class);
        </XDtConfig:ifConfigParamNotEquals>
     }
***************
*** 180,185 ****
     </XDtConfig:ifConfigParamEquals>
  
!    <XDtMerge:merge file="lookup-custom.xdt">
!    </XDtMerge:merge>
!   
  }
--- 167,227 ----
     </XDtConfig:ifConfigParamEquals>
  
!    <XDtEjbUtilObj:ifGenerateLocalProxy>
!     private static 
<XDtClass:classOf><XDtEjbSession:sessionClass/></XDtClass:classOf> singleton = null;
! 
!     static public Object newConcreteProxyInstance() {
!         if (singleton == null) {
!             singleton = new 
<XDtClass:classOf><XDtEjbSession:sessionClass/></XDtClass:classOf>();
!         }
!         return 
java.lang.reflect.Proxy.newProxyInstance(singleton.getClass().getClassLoader(),
!                 new Class[] {<XDtEjb:shortEjbName/>.class}, new 
<XDtEjb:shortEjbName/>Proxy(singleton));
!     }
! 
!     public static class <XDtEjb:shortEjbName/>HomeProxy implements 
java.lang.reflect.InvocationHandler {
!         public <XDtEjb:shortEjbName/>HomeProxy() {
!         }
! 
!         public Object invoke(Object proxy, java.lang.reflect.Method m, Object[] args)
!                 throws Throwable {
!             if (m.getName().equals("create") && m.getParameterTypes().length == 0) {
!                 return newConcreteProxyInstance();
!             } else {
!                 throw new UnsupportedOperationException(m.getName()+": only 
no-argument create() method supported");
!             }
!         }
!     }
! 
!     public static class <XDtEjb:shortEjbName/>Proxy implements 
java.lang.reflect.InvocationHandler
!     {
!         Object real;
!         java.util.HashMap methodMap = new java.util.HashMap();
! 
!         public <XDtEjb:shortEjbName/>Proxy(Object obj)
!         {
!             real = obj;
!         }
! 
!         public Object invoke(Object proxy, java.lang.reflect.Method m, Object[] 
args) throws Throwable
!         {
!             try {
!                 // do something
!                 return getMethod(m, m.getParameterTypes()).invoke(real, args);
!             } catch (java.lang.reflect.InvocationTargetException e) {
!                 throw e.getTargetException();
!             } catch (Exception e) {
!                 throw e;
!             }
!         }
! 
!         // this uses the method object as the key to the hash for caching our local 
object methods
!         private java.lang.reflect.Method getMethod(java.lang.reflect.Method m, 
Class[] parameterTypes) throws NoSuchMethodException {
!             java.lang.reflect.Method localMethod = 
(java.lang.reflect.Method)methodMap.get(m);
!             if (localMethod == null) {
!                 localMethod = real.getClass().getMethod(m.getName(), parameterTypes);
!                 methodMap.put(m, localMethod);
!             }
!             return localMethod;
!         }
!     }
!    </XDtEjbUtilObj:ifGenerateLocalProxy>
  }



-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to