openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1064997 - in /openwebbeans/trunk/webbeans-jee5-ejb-resource/src/main/java/org/apache/webbeans/resource/spi/ee: EjbResolver.java ExtendedStandaloneResourceInjectionService.java
Date Sat, 29 Jan 2011 11:11:09 GMT
Author: gpetracek
Date: Sat Jan 29 11:11:09 2011
New Revision: 1064997

URL: http://svn.apache.org/viewvc?rev=1064997&view=rev
Log:
OWB-520 spi for the webbeans-jee5-ejb-resource plugin

Added:
    openwebbeans/trunk/webbeans-jee5-ejb-resource/src/main/java/org/apache/webbeans/resource/spi/ee/EjbResolver.java
Modified:
    openwebbeans/trunk/webbeans-jee5-ejb-resource/src/main/java/org/apache/webbeans/resource/spi/ee/ExtendedStandaloneResourceInjectionService.java

Added: openwebbeans/trunk/webbeans-jee5-ejb-resource/src/main/java/org/apache/webbeans/resource/spi/ee/EjbResolver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jee5-ejb-resource/src/main/java/org/apache/webbeans/resource/spi/ee/EjbResolver.java?rev=1064997&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-jee5-ejb-resource/src/main/java/org/apache/webbeans/resource/spi/ee/EjbResolver.java
(added)
+++ openwebbeans/trunk/webbeans-jee5-ejb-resource/src/main/java/org/apache/webbeans/resource/spi/ee/EjbResolver.java
Sat Jan 29 11:11:09 2011
@@ -0,0 +1,26 @@
+/*
+ * 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.webbeans.resource.spi.ee;
+
+import javax.naming.NamingException;
+
+public interface EjbResolver
+{
+    <T> T resolve(Class<T> resourceReference) throws NamingException;
+}

Modified: openwebbeans/trunk/webbeans-jee5-ejb-resource/src/main/java/org/apache/webbeans/resource/spi/ee/ExtendedStandaloneResourceInjectionService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jee5-ejb-resource/src/main/java/org/apache/webbeans/resource/spi/ee/ExtendedStandaloneResourceInjectionService.java?rev=1064997&r1=1064996&r2=1064997&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-jee5-ejb-resource/src/main/java/org/apache/webbeans/resource/spi/ee/ExtendedStandaloneResourceInjectionService.java
(original)
+++ openwebbeans/trunk/webbeans-jee5-ejb-resource/src/main/java/org/apache/webbeans/resource/spi/ee/ExtendedStandaloneResourceInjectionService.java
Sat Jan 29 11:11:09 2011
@@ -21,8 +21,10 @@ package org.apache.webbeans.resource.spi
 import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.resource.spi.se.StandaloneResourceInjectionService;
 import org.apache.webbeans.spi.api.ResourceReference;
+import org.apache.webbeans.util.WebBeansUtil;
 
 import javax.ejb.EJB;
 import javax.enterprise.inject.spi.Bean;
@@ -30,17 +32,31 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import java.lang.annotation.Annotation;
+import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
+import java.util.ServiceLoader;
 
 /**
  * Allows to use @EJB in JEE 5 app servers
  */
 public class ExtendedStandaloneResourceInjectionService extends StandaloneResourceInjectionService
 {
+    private final WebBeansLogger logger = WebBeansLogger.getLogger(ExtendedStandaloneResourceInjectionService.class);
+
+    private List<EjbResolver> ejbResolvers = new ArrayList<EjbResolver>();
 
     public ExtendedStandaloneResourceInjectionService(WebBeansContext webBeansContext)
     {
         super(webBeansContext);
+
+        ServiceLoader<EjbResolver> ejbResolverServiceLoader =
+                ServiceLoader.load(EjbResolver.class, WebBeansUtil.getCurrentClassLoader());
+
+        for (EjbResolver ejbResolver : ejbResolverServiceLoader)
+        {
+            this.ejbResolvers.add(ejbResolver);
+        }
     }
 
     @Override
@@ -48,8 +64,28 @@ public class ExtendedStandaloneResourceI
     {
         if (resourceReference.supports(EJB.class))
         {
+            for (EjbResolver ejbResolver : this.ejbResolvers)
+            {
+                try
+                {
+                    X result = ejbResolver.resolve(resourceReference.getResourceType());
+                    if(result != null)
+                    {
+                        return result;
+                    }
+                }
+                catch (NamingException e)
+                {
+                    if(logger.wblWillLogDebug())
+                    {
+                        logger.debug(ejbResolver.getClass().getName()
+                                + " couldn't find EJB for " + resourceReference.getResourceType().getName());
+                    }
+                }
+            }
+            
             String jndiName = convertToJndiName(resourceReference.getResourceType());
-            X result = lookupRemoteEjb(jndiName, resourceReference.getResourceType());
+            X result = lookupEjb(jndiName, resourceReference.getResourceType());
 
             return result;
         }
@@ -57,12 +93,12 @@ public class ExtendedStandaloneResourceI
         return super.getResourceReference(resourceReference);
     }
 
-        private String convertToJndiName(Class resourceType)
+    private String convertToJndiName(Class resourceType)
     {
         return resourceType.getSimpleName() + "#" + resourceType.getName();
     }
 
-    private <X> X lookupRemoteEjb(String jndiName, Class<X> resourceType)
+    private <X> X lookupEjb(String jndiName, Class<X> resourceType)
     {
         try
         {



Mime
View raw message