You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/01/18 09:03:25 UTC

svn commit: r1232779 - in /openejb/trunk/openejb: container/openejb-core/src/main/java/org/apache/openejb/util/proxy/ProxyEJB.java osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java

Author: rmannibucau
Date: Wed Jan 18 08:03:24 2012
New Revision: 1232779

URL: http://svn.apache.org/viewvc?rev=1232779&view=rev
Log:
adding ProxyEJB

Added:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/proxy/ProxyEJB.java
Modified:
    openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java

Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/proxy/ProxyEJB.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/proxy/ProxyEJB.java?rev=1232779&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/proxy/ProxyEJB.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/proxy/ProxyEJB.java Wed Jan 18 08:03:24 2012
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.util.proxy;
+
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.RpcContainer;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+public class ProxyEJB {
+    private ProxyEJB() {
+        // no-op
+    }
+
+    public static Object proxy(final BeanContext beanContext, final Class<?>[] itfs) {
+        if (beanContext.isLocalbean()) {
+            return LocalBeanProxyFactory.newProxyInstance(itfs[0].getClassLoader(), itfs[0], new Handler(beanContext));
+        }
+        return Proxy.newProxyInstance(itfs[0].getClassLoader(), itfs, new Handler(beanContext));
+    }
+
+    private static class Handler implements java.lang.reflect.InvocationHandler {
+        private BeanContext beanContext;
+
+        public Handler(BeanContext bc) {
+            beanContext = bc;
+        }
+
+        @Override
+        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+            final RpcContainer container = RpcContainer.class.cast(beanContext.getContainer());
+            return container.invoke(beanContext.getDeploymentID(),
+                    beanContext.getInterfaceType(method.getDeclaringClass()),
+                    method.getDeclaringClass(), method, args, null);
+        }
+    }
+}

Modified: openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java?rev=1232779&r1=1232778&r2=1232779&view=diff
==============================================================================
--- openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java (original)
+++ openejb/trunk/openejb/osgi/openejb-core-osgi/src/main/java/org/apache/openejb/core/osgi/impl/Deployer.java Wed Jan 18 08:03:24 2012
@@ -30,6 +30,7 @@ import org.apache.openejb.config.Deploym
 import org.apache.openejb.config.UnknownModuleTypeException;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.proxy.LocalBeanProxyFactory;
+import org.apache.openejb.util.proxy.ProxyEJB;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
@@ -247,15 +248,9 @@ public class Deployer implements BundleL
 
     private void registerService(BeanContext beanContext, BundleContext context, List<Class> interfaces) {
         if (!interfaces.isEmpty()) {
-            Class<?>[] itfs = interfaces.toArray(new Class<?>[interfaces.size()]);
+            final Class<?>[] itfs = interfaces.toArray(new Class<?>[interfaces.size()]);
             try {
-                Object service;
-                if (!beanContext.isLocalbean()) {
-                    service = Proxy.newProxyInstance(itfs[0].getClassLoader(), itfs, new Handler(beanContext));
-                } else {
-                    service = LocalBeanProxyFactory.newProxyInstance(itfs[0].getClassLoader(), itfs[0], new Handler(beanContext));
-                }
-
+                final Object service = ProxyEJB.proxy(beanContext, itfs);
                 registrations.get(context.getBundle()).add(context.registerService(str(itfs), service, new Properties()));
                 LOGGER.info("EJB registered: {} for interfaces {}", beanContext.getEjbName(), interfaces);
             } catch (IllegalArgumentException iae) {
@@ -276,22 +271,6 @@ public class Deployer implements BundleL
         return itfsStr;
     }
 
-    private static class Handler implements InvocationHandler {
-        private BeanContext beanContext;
-
-        public Handler(BeanContext bc) {
-            beanContext = bc;
-        }
-
-        @Override
-        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-            final RpcContainer container = RpcContainer.class.cast(beanContext.getContainer());
-            return container.invoke(beanContext.getDeploymentID(),
-                    beanContext.getInterfaceType(method.getDeclaringClass()),
-                    method.getDeclaringClass(), method, args, null);
-        }
-    }
-
     /**
      * using dynamic imports can be too tricky when this class is often enough.
      * Note: user can stil refine the version he needs...but manually.