geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1143873 - in /geronimo/server/trunk: framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/ plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/
Date Thu, 07 Jul 2011 15:14:30 GMT
Author: xuhaihong
Date: Thu Jul  7 15:14:29 2011
New Revision: 1143873

URL: http://svn.apache.org/viewvc?rev=1143873&view=rev
Log:
GERONIMO-6045 Support artifact alias for ResourceReference and JndiReference

Modified:
    geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/JndiReference.java
    geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/ResourceReference.java
    geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java
    geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java

Modified: geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/JndiReference.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/JndiReference.java?rev=1143873&r1=1143872&r2=1143873&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/JndiReference.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/JndiReference.java
Thu Jul  7 15:14:29 2011
@@ -19,21 +19,53 @@ package org.apache.geronimo.naming.refer
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.config.ConfigurationUtil;
+import org.apache.geronimo.kernel.repository.MissingDependencyException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * @version $Rev$ $Date$
  */
-public class JndiReference extends SimpleReference {
+public class JndiReference extends SimpleReference implements KernelAwareReference{
 
+    private static final Logger logger = LoggerFactory.getLogger(JndiReference.class);
     private String jndiName;
-    
+    private AbstractName gbeanName;
+    private String prefix;
+
     public JndiReference(String jndiName) {
         this.jndiName = jndiName;
     }
 
+    public JndiReference(String prefix, AbstractName gbeanName) {
+        this.gbeanName = gbeanName;
+        this.prefix = prefix;
+    }
+
     @Override
     public Object getContent() throws NamingException {
         InitialContext ctx = new InitialContext();
         return ctx.lookup(jndiName);
-    }    
-        
+    }
+
+    @Override
+    public void setKernel(Kernel kernel) {
+        if(jndiName == null) {
+            try {
+                ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
+                AbstractName mappedAbstractName = new AbstractName(configurationManager.getArtifactResolver().resolveInClassLoader(gbeanName.getArtifact()),
gbeanName.getName());
+                String osgiJndiName = kernel.getNaming().toOsgiJndiName(mappedAbstractName);
+                jndiName = prefix + osgiJndiName;
+            } catch (GBeanNotFoundException e) {
+                logger.error("Fail to build the jndi name for " + gbeanName, e);
+            } catch (MissingDependencyException e) {
+                logger.error("Fail to build the jndi name for " + gbeanName, e);
+            }
+        }
+    }
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/ResourceReference.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/ResourceReference.java?rev=1143873&r1=1143872&r2=1143873&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/ResourceReference.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-naming/src/main/java/org/apache/geronimo/naming/reference/ResourceReference.java
Thu Jul  7 15:14:29 2011
@@ -23,20 +23,36 @@ package org.apache.geronimo.naming.refer
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.config.ConfigurationUtil;
+import org.apache.geronimo.kernel.repository.MissingDependencyException;
 import org.apache.geronimo.naming.ResourceSource;
 import org.apache.xbean.naming.reference.SimpleReference;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @version $Rev$ $Date$
  */
-public class ResourceReference<E extends Throwable> extends SimpleReference implements
BundleAwareReference {
+public class ResourceReference<E extends Throwable> extends SimpleReference implements
BundleAwareReference, KernelAwareReference {
+
+    private static final Logger logger = LoggerFactory.getLogger(ResourceReference.class);
     private final String type;
-    private final String query;
+    private String query;
+    private AbstractName gbeanName;
     private transient BundleContext bundleContext;
 
+    public ResourceReference(AbstractName gbeanName, String type) {
+        this.gbeanName = gbeanName;
+        this.type = type;
+    }
+
     public ResourceReference(String query, String type) {
         this.query = query;
         this.type = type;
@@ -51,7 +67,7 @@ public class ResourceReference<E extends
                 throw new NameNotFoundException("could not locate osgi service matching "
+ query);
             }
             ref = refs[0];
-            @SuppressWarnings("Unchecked")
+            @SuppressWarnings("unchecked")
             ResourceSource<E> source = (ResourceSource<E>) bundleContext.getService(ref);
             return source.$getResource();
         } catch (Throwable e) {
@@ -72,4 +88,20 @@ public class ResourceReference<E extends
     public void setBundle(Bundle bundle) {
         this.bundleContext = bundle.getBundleContext();
     }
+
+    @Override
+    public void setKernel(Kernel kernel) {
+        if(query == null) {
+            try {
+                ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
+                AbstractName mappedAbstractName = new AbstractName(configurationManager.getArtifactResolver().resolveInClassLoader(gbeanName.getArtifact()),
gbeanName.getName());
+                String osgiJndiName = kernel.getNaming().toOsgiJndiName(mappedAbstractName);
+                query = "(osgi.jndi.service.name=" + osgiJndiName + ')';
+            } catch (GBeanNotFoundException e) {
+                logger.error("Fail to build the jndi name for " + gbeanName, e);
+            } catch (MissingDependencyException e) {
+                logger.error("Fail to build the jndi name for " + gbeanName, e);
+            }
+        }
+    }
 }

Modified: geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java?rev=1143873&r1=1143872&r2=1143873&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java
(original)
+++ geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java
Thu Jul  7 15:14:29 2011
@@ -386,8 +386,8 @@ public class AdminObjectRefBuilder exten
         Configuration localConfiguration = module.getEarContext().getConfiguration();
         try {
             AbstractName abstractName = localConfiguration.findGBean(containerId);
-            String osgiJndiName = "aries:services/" + module.getEarContext().getNaming().toOsgiJndiName(abstractName);
-            return new JndiReference(osgiJndiName);
+            //String osgiJndiName = "aries:services/" + module.getEarContext().getNaming().toOsgiJndiName(abstractName);
+            return new JndiReference("aries:services/", abstractName);
         } catch (GBeanNotFoundException e) {
             throw new DeploymentException("Can not resolve admin object ref " + containerId
+ " in configuration " + localConfiguration.getId(), e);
         }

Modified: geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java?rev=1143873&r1=1143872&r2=1143873&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java
(original)
+++ geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java
Thu Jul  7 15:14:29 2011
@@ -33,6 +33,7 @@ import java.util.Set;
 import javax.annotation.ManagedBean;
 import javax.annotation.Resource;
 import javax.xml.namespace.QName;
+
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.service.EnvironmentBuilder;
 import org.apache.geronimo.gbean.AbstractName;
@@ -145,8 +146,9 @@ public class ResourceRefBuilder extends 
             String type = getStringValue(resourceRef.getResType());
             type = inferAndCheckType(module, bundle, resourceRef.getInjectionTarget(), name,
type);
             GerResourceRefType gerResourceRef = refMap.get(name);
-            log.debug("trying to resolve " + name + ", type " + type + ", resourceRef " +
gerResourceRef);
-
+            if (log.isDebugEnabled()) {
+                log.debug("trying to resolve " + name + ", type " + type + ", resourceRef
" + gerResourceRef);
+            }
             Object value = null;
             if (gerResourceRef == null) {
                 String lookupName = getStringValue(resourceRef.getLookupName());
@@ -235,10 +237,10 @@ public class ResourceRefBuilder extends 
                 String osgiJndiName = module.getEarContext().getNaming().toOsgiJndiName(abstractName);
                 String filter = "(osgi.jndi.service.name=" + osgiJndiName + ')';
 
-                return new ResourceReference(filter, type);
+                return new ResourceReference(abstractName, type);
                         //ResourceReferenceFactory<ResourceException>(module.getConfigId(),
containerId, iface);
             } catch (GBeanNotFoundException e) {
-                StringBuffer errorMessage = new StringBuffer("Unable to resolve resource
reference '");
+                StringBuilder errorMessage = new StringBuilder("Unable to resolve resource
reference '");
                 errorMessage.append(name);
                 errorMessage.append("' (");
                 if (e.hasMatches()) {
@@ -357,12 +359,13 @@ public class ResourceRefBuilder extends 
         }
 
         public boolean processResource(JndiConsumer annotatedApp, Resource annotation, Class
cls, Method method, Field field) {
-            log.debug("processResource( [annotatedApp] " + annotatedApp.toString() + ","
+ '\n' +
-                    "[annotation] " + annotation.toString() + "," + '\n' +
-                    "[cls] " + (cls != null ? cls.getName() : null) + "," + '\n' +
-                    "[method] " + (method != null ? method.getName() : null) + "," + '\n'
+
-                    "[field] " + (field != null ? field.getName() : null) + " ): Entry");
-
+            if(log.isDebugEnabled()) {
+                log.debug("processResource( [annotatedApp] " + annotatedApp.toString() +
"," + '\n' +
+                        "[annotation] " + annotation.toString() + "," + '\n' +
+                        "[cls] " + (cls != null ? cls.getName() : null) + "," + '\n' +
+                        "[method] " + (method != null ? method.getName() : null) + "," +
'\n' +
+                        "[field] " + (field != null ? field.getName() : null) + " ): Entry");
+            }
             String resourceName = getResourceName(annotation, method, field);
             Class resourceTypeClass = getResourceTypeClass(annotation, method, field);
             String resourceType = resourceTypeClass.getCanonicalName();



Mime
View raw message