geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r933722 - in /geronimo/server/trunk/plugins: connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/connector/deployment/ connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/datasource/depl...
Date Tue, 13 Apr 2010 18:02:10 GMT
Author: gawor
Date: Tue Apr 13 18:02:09 2010
New Revision: 933722

URL: http://svn.apache.org/viewvc?rev=933722&view=rev
Log:
GERONIMO-5232: Support @Resource.lookup for env-entry, resource-ref, resource-env-ref, and
message-destination-ref. Also fixes java:app jndi namespace

Modified:
    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
    geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/datasource/deployment/DataSourceBuilder.java
    geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
    geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/jndi/ApplicationJndi.java
    geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/jndi/JndiScope.java
    geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
    geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
    geronimo/server/trunk/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebApplication.java

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=933722&r1=933721&r2=933722&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
Tue Apr 13 18:02:09 2010
@@ -19,6 +19,7 @@ package org.apache.geronimo.connector.de
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -43,6 +44,7 @@ import org.apache.geronimo.kernel.GBeanN
 import org.apache.geronimo.kernel.config.Configuration;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
+import org.apache.geronimo.naming.reference.JndiReference;
 import org.apache.geronimo.naming.reference.ResourceReferenceFactory;
 import org.apache.geronimo.naming.reference.UserTransactionReference;
 import org.apache.geronimo.xbeans.geronimo.naming.GerMessageDestinationDocument;
@@ -114,9 +116,8 @@ public class AdminObjectRefBuilder exten
     public void buildNaming(XmlObject specDD, XmlObject plan, Module module, Map componentContext)
throws DeploymentException {
         XmlObject[] gerResourceEnvRefsUntyped = plan == null ? NO_REFS : plan.selectChildren(GER_ADMIN_OBJECT_REF_QNAME_SET);
         Map<String, GerResourceEnvRefType> refMap = mapResourceEnvRefs(gerResourceEnvRefsUntyped);
-        int initialGerRefSize = refMap.size();
         Map<String, Map<String, GerMessageDestinationType>> messageDestinations
= module.getRootEarContext().getMessageDestinations();
-
+        
         // Discover and process any @Resource annotations (if !metadata-complete)
         if (module.getClassFinder() != null) {
 
@@ -129,42 +130,42 @@ public class AdminObjectRefBuilder exten
             }
         }
 
-        List<ResourceEnvRefType> resourceEnvRefsUntyped = convert(specDD.selectChildren(adminOjbectRefQNameSet),
JEE_CONVERTER, ResourceEnvRefType.class, ResourceEnvRefType.type);
-        int unresolvedRefSize = resourceEnvRefsUntyped.size();
-        Bundle bundle = module.getEarContext().getDeploymentBundle();
+        List<ResourceEnvRefType> resourceEnvRefsUntyped = convert(specDD.selectChildren(adminOjbectRefQNameSet),
JEE_CONVERTER, ResourceEnvRefType.class, ResourceEnvRefType.type);        
+        List<String> unresolvedRefs = new ArrayList<String>();  
         for (ResourceEnvRefType resourceEnvRef : resourceEnvRefsUntyped) {
-            String name = resourceEnvRef.getResourceEnvRefName().getStringValue().trim();
-            if (lookupJndiContextMap(componentContext, ENV + name) != null) {
+            String name = getStringValue(resourceEnvRef.getResourceEnvRefName());
+            if (lookupJndiContextMap(componentContext, name) != null) {
                 // some other builder handled this entry already
                 continue;
             }
             addInjections(name, resourceEnvRef.getInjectionTargetArray(), componentContext);
-            String type = resourceEnvRef.getResourceEnvRefType().getStringValue().trim();
-            Class iface;
-            try {
-                iface = bundle.loadClass(type);
-            } catch (ClassNotFoundException e) {
-                throw new DeploymentException("could not load class " + type, e);
-            }
-            GerResourceEnvRefType gerResourceEnvRef = refMap.get(name);
-            refMap.remove(name);
-            try {
-                String refType = getStringValue(resourceEnvRef.getResourceEnvRefType());
-                if (refType.equals("javax.transaction.UserTransaction")) {
-                    Reference ref = new UserTransactionReference();
-                    put(name, ref, getJndiContextMap(componentContext));
-                } else {
-                    AbstractNameQuery containerId = getAdminObjectContainerId(name, gerResourceEnvRef);
-                    ResourceReferenceFactory<RuntimeException> ref = buildAdminObjectReference(module,
containerId, iface);
-                    put(name, ref, getJndiContextMap(componentContext));
+            String type = getStringValue(resourceEnvRef.getResourceEnvRefType());
+            GerResourceEnvRefType gerResourceEnvRef = refMap.remove(name);
+            
+            Object value = null;
+            if (gerResourceEnvRef == null) {
+                String lookupName = getStringValue(resourceEnvRef.getLookupName());
+                if (lookupName != null) {
+                    if (lookupName.equals(getJndiName(name))) {
+                        throw new DeploymentException("resource-env-ref lookup name refers
to itself");
+                    }
+                    value = new JndiReference(lookupName);
                 }
-            } catch (UnresolvedReferenceException e) {
-                throw new DeploymentException("Unable to resolve resource env reference '"
+ name + "' (" + (e.isMultiple() ? "found multiple matching resources" : "no matching resources
found") + ")", e);
             }
+            
+            if (value == null) {
+                value = buildResourceReference(module, name, type, gerResourceEnvRef);
+            }
+            
+            if (value == null) {
+                unresolvedRefs.add(name);
+            } else {
+                put(name, value, getJndiContextMap(componentContext));
+            }            
         }
         
-        if (refMap.size() > 0 && ((initialGerRefSize - unresolvedRefSize) != refMap.size()))
{
-            log.warn("Failed to build reference to Admin object reference "+refMap.keySet()+"
defined in plan file, reason - corresponding entry in deployment descriptor missing.");
+        if (unresolvedRefs.size() > 0) {
+            log.warn("Failed to build reference to resource env reference " + unresolvedRefs
+ " defined in plan file. The corresponding entry in Geronimo deployment descriptor is missing.");
         }
         
         //message-destination-refs
@@ -191,44 +192,95 @@ public class AdminObjectRefBuilder exten
                 }
                 type = getStringValue(targets[0].getInjectionTargetClass());
                 if (type == null) {
-                    throw new DeploymentException("no type for message destination ref in
injection target: " + targets[0]);
+                    throw new DeploymentException("No type for message-destination-ref in
injection target: " + targets[0]);
                 }
             }
-            Class iface;
-            try {
-                iface = bundle.loadClass(type);
-            } catch (ClassNotFoundException e) {
-                throw new DeploymentException("could not load class " + type, e);
-            }
-            String moduleURI = null;
+
             GerMessageDestinationType destination = getMessageDestination(linkName, messageDestinations);
-            if (destination != null) {
-                if (destination.isSetAdminObjectLink()) {
-                    if (destination.isSetAdminObjectModule()) {
-                        moduleURI = destination.getAdminObjectModule().trim();
+            
+            Object value = null;
+            if (destination == null) {
+                String lookupName = getStringValue(messageDestinationRef.getLookupName());
+                if (lookupName != null) {
+                    if (lookupName.equals(getJndiName(name))) {
+                        throw new DeploymentException("message-destination-ref lookup name
refers to itself");
                     }
-                    linkName = destination.getAdminObjectLink().trim();
-                }
-            } else {
-                //well, we know for sure an admin object is not going to be defined in a
modules that can have a message-destination
-                int pos = linkName.indexOf('#');
-                if (pos > -1) {
-                    //AMM -- the following line causes blowups; e.g. to look in DayTrader
EJB module for a RA -- why is that?!?
-                    //moduleURI = linkName.substring(0, pos);
-                    linkName = linkName.substring(pos + 1);
+                    value = new JndiReference(lookupName);
                 }
             }
+            
+            if (value == null) {
+                value = buildMessageReference(module, linkName, type, destination);
+            }
+            
+            if (value != null) {
+                put(name, value, getJndiContextMap(componentContext));
+            }
+        }
 
-            //try to resolve ref based only matching resource-ref-name
-            //throws exception if it can't locate ref.
-            AbstractNameQuery containerId = buildAbstractNameQuery(null, moduleURI, linkName,
NameFactory.JCA_ADMIN_OBJECT, NameFactory.RESOURCE_ADAPTER_MODULE);
-            ResourceReferenceFactory<RuntimeException> ref = buildAdminObjectReference(module,
containerId, iface);
-            put(name, ref, getJndiContextMap(componentContext));
+    }
 
+    private Object buildResourceReference(Module module, String name, String type, GerResourceEnvRefType
gerResourceEnvRef) 
+        throws DeploymentException {
+        Bundle bundle = module.getEarContext().getDeploymentBundle();
+    
+        Class iface;
+        try {
+            iface = bundle.loadClass(type);
+        } catch (ClassNotFoundException e) {
+            throw new DeploymentException("Could not load resource-env-ref entry class "
+ type, e);
+        }
+    
+        if (type.equals("javax.transaction.UserTransaction")) {
+            return new UserTransactionReference();
+        } else {
+            try {
+                AbstractNameQuery containerId = getAdminObjectContainerId(name, gerResourceEnvRef);
+                ResourceReferenceFactory<RuntimeException> ref = buildAdminObjectReference(module,
containerId, iface);
+                return ref;
+            } catch (UnresolvedReferenceException e) {
+                throw new DeploymentException("Unable to resolve resource env reference '"
+ name + "' (" + (e.isMultiple() ? "found multiple matching resources" : "no matching resources
found") + ")", e);
+            }
+        } 
+    }
+    
+    private Object buildMessageReference(Module module, String linkName, String type, GerMessageDestinationType
destination) 
+        throws DeploymentException {
+        Bundle bundle = module.getEarContext().getDeploymentBundle();
+        
+        Class iface;
+        try {
+            iface = bundle.loadClass(type);
+        } catch (ClassNotFoundException e) {
+            throw new DeploymentException("Could not load message-destination-ref entry type
class " + type, e);
+        }
+        
+        String moduleURI = null;
+        
+        if (destination != null) {
+            if (destination.isSetAdminObjectLink()) {
+                if (destination.isSetAdminObjectModule()) {
+                    moduleURI = destination.getAdminObjectModule().trim();
+                }
+                linkName = destination.getAdminObjectLink().trim();
+            }
+        } else {
+            //well, we know for sure an admin object is not going to be defined in a modules
that can have a message-destination
+            int pos = linkName.indexOf('#');
+            if (pos > -1) {
+                //AMM -- the following line causes blowups; e.g. to look in DayTrader EJB
module for a RA -- why is that?!?
+                //moduleURI = linkName.substring(0, pos);
+                linkName = linkName.substring(pos + 1);
+            }
         }
 
+        //try to resolve ref based only matching resource-ref-name
+        //throws exception if it can't locate ref.
+        AbstractNameQuery containerId = buildAbstractNameQuery(null, moduleURI, linkName,
NameFactory.JCA_ADMIN_OBJECT, NameFactory.RESOURCE_ADAPTER_MODULE);
+        ResourceReferenceFactory<RuntimeException> ref = buildAdminObjectReference(module,
containerId, iface);
+        return ref;
     }
-
+    
     public static GerMessageDestinationType getMessageDestination(String messageDestinationLink,
Map<String, Map<String, GerMessageDestinationType>> messageDestinations) throws
DeploymentException {
         GerMessageDestinationType destination = null;
         int pos = messageDestinationLink.indexOf('#');

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=933722&r1=933721&r2=933722&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
Tue Apr 13 18:02:09 2010
@@ -54,6 +54,7 @@ import org.apache.geronimo.kernel.reposi
 import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
 import org.apache.geronimo.naming.deployment.ResourceEnvironmentBuilder;
 import org.apache.geronimo.naming.deployment.ResourceEnvironmentSetter;
+import org.apache.geronimo.naming.reference.JndiReference;
 import org.apache.geronimo.naming.reference.ORBReference;
 import org.apache.geronimo.naming.reference.ResourceReferenceFactory;
 import org.apache.geronimo.naming.reference.URLReference;
@@ -86,7 +87,6 @@ public class ResourceRefBuilder extends 
     private static final String JAXR_CONNECTION_FACTORY_CLASS = "javax.xml.registry.ConnectionFactory";
     private static final String JAVAX_MAIL_SESSION_CLASS = "javax.mail.Session";
 
-
     private final QNameSet resourceRefQNameSet;
     private final Environment corbaEnvironment;
     private final SingleElementCollection corbaGBeanNameSourceCollection;
@@ -119,115 +119,131 @@ public class ResourceRefBuilder extends 
 
         List<ResourceRefType> resourceRefsUntyped = convert(specDD.selectChildren(resourceRefQNameSet),
J2EE_CONVERTER, ResourceRefType.class, ResourceRefType.type);
         XmlObject[] gerResourceRefsUntyped = plan == null ? NO_REFS : plan.selectChildren(GER_RESOURCE_REF_QNAME_SET);
-        Map refMap = mapResourceRefs(gerResourceRefsUntyped);
-        List unresolvedRefs = new ArrayList();
-        Bundle bundle = module.getEarContext().getDeploymentBundle();
+        Map<String, GerResourceRefType> refMap = mapResourceRefs(gerResourceRefsUntyped);
+        List<String> unresolvedRefs = new ArrayList<String>();        
         for (ResourceRefType resourceRef : resourceRefsUntyped) {
-            String name = resourceRef.getResRefName().getStringValue().trim();
-            if (lookupJndiContextMap(componentContext, ENV + name) != null) {
+            String name = getStringValue(resourceRef.getResRefName());            
+            if (lookupJndiContextMap(componentContext, name) != null) {
                 // some other builder handled this entry already
                 continue;
-            }
+            }            
             addInjections(name, resourceRef.getInjectionTargetArray(), componentContext);
-            String type = resourceRef.getResType().getStringValue().trim();
-            GerResourceRefType gerResourceRef = (GerResourceRefType) refMap.get(name);
+            String type = getStringValue(resourceRef.getResType());
+            GerResourceRefType gerResourceRef = refMap.get(name);
             log.debug("trying to resolve " + name + ", type " + type + ", resourceRef " +
gerResourceRef);
-            if(!refMap.containsKey(name)){
-                unresolvedRefs.add(name);
-            } 
-            Class iface;
-            try {
-                iface = bundle.loadClass(type);
-            } catch (ClassNotFoundException e) {
-                throw new DeploymentException("could not load class " + type, e);
-            }
-            if (iface == URL.class) {
-                if (gerResourceRef == null || !gerResourceRef.isSetUrl()) {
-                    throw new DeploymentException("No url supplied to resolve: " + name);
-                }
-                String url = gerResourceRef.getUrl().trim();
-                //TODO expose jsr-77 objects for these guys
-                try {
-                    //check for malformed URL
-                    new URL(url);
-                } catch (MalformedURLException e) {
-                    throw new DeploymentException("Could not convert " + url + " to URL",
e);
-                }
-                put(name, new URLReference(url), getJndiContextMap(componentContext));
-                unresolvedRefs.remove(name);
-            } else if (ORB.class.isAssignableFrom(iface)) {
-                CorbaGBeanNameSource corbaGBeanNameSource = (CorbaGBeanNameSource) corbaGBeanNameSourceCollection.getElement();
-                if (corbaGBeanNameSource == null) {
-                    throw new DeploymentException("No orb setup but there is a orb reference");
-                }
-                AbstractNameQuery corbaName = corbaGBeanNameSource.getCorbaGBeanName();
-                if (corbaName != null) {
-                    Artifact[] moduleId = module.getConfigId();
-                    Map context = getJndiContextMap(componentContext);
-                    context.put(ENV + name, new ORBReference(moduleId, corbaName));
-                    unresolvedRefs.remove(name);
-                    EnvironmentBuilder.mergeEnvironments(module.getEnvironment(), corbaEnvironment);
+            
+            Object value = null;
+            if (gerResourceRef == null) {
+                String lookupName = getStringValue(resourceRef.getLookupName());
+                if (lookupName != null) {
+                    if (lookupName.equals(getJndiName(name))) {
+                        throw new DeploymentException("resource-ref lookup name refers to
itself");
+                    }
+                    value = new JndiReference(lookupName);
                 }
+            }
+            
+            if (value == null) {
+                value = buildReference(module, name, type, gerResourceRef);
+            }
+            
+            if (value == null) {
+                unresolvedRefs.add(name);
             } else {
-                //determine jsr-77 type from interface
-                String j2eeType;
+                put(name, value, getJndiContextMap(componentContext));
+            }
+            
+        }
 
+        if (unresolvedRefs.size() > 0) {
+            log.warn("Failed to build reference to resource reference " + unresolvedRefs
+ " defined in plan file. The corresponding entry in Geronimo deployment descriptor is missing.");
+        }
+    }
 
-                if (JAVAX_MAIL_SESSION_CLASS.equals(type)) {
-                    j2eeType = NameFactory.JAVA_MAIL_RESOURCE;
-                } else if (JAXR_CONNECTION_FACTORY_CLASS.equals(type)) {
-                    j2eeType = NameFactory.JAXR_CONNECTION_FACTORY;
-                } else {
-                    j2eeType = NameFactory.JCA_CONNECTION_FACTORY;
-                }
-                try {
-                    AbstractNameQuery containerId = getResourceContainerId(name, j2eeType,
null, gerResourceRef);
+    private Object buildReference(Module module, String name, String type, GerResourceRefType
gerResourceRef) 
+        throws DeploymentException {
+        Bundle bundle = module.getEarContext().getDeploymentBundle();
+        
+        Class iface;
+        try {
+            iface = bundle.loadClass(type);
+        } catch (ClassNotFoundException e) {
+            throw new DeploymentException("Could not resource-ref entry class " + type, e);
+        }
+        
+        if (iface == URL.class) {
+            if (gerResourceRef == null || !gerResourceRef.isSetUrl()) {
+                throw new DeploymentException("No url supplied to resolve: " + name);
+            }
+            String url = gerResourceRef.getUrl().trim();
+            //TODO expose jsr-77 objects for these guys
+            try {
+                //check for malformed URL
+                new URL(url);
+            } catch (MalformedURLException e) {
+                throw new DeploymentException("Could not convert " + url + " to URL", e);
+            }
+            return new URLReference(url);
+        } else if (ORB.class.isAssignableFrom(iface)) {
+            CorbaGBeanNameSource corbaGBeanNameSource = (CorbaGBeanNameSource) corbaGBeanNameSourceCollection.getElement();
+            if (corbaGBeanNameSource == null) {
+                throw new DeploymentException("No orb setup but there is a orb reference");
+            }
+            AbstractNameQuery corbaName = corbaGBeanNameSource.getCorbaGBeanName();
+            if (corbaName != null) {
+                Artifact[] moduleId = module.getConfigId();
+                EnvironmentBuilder.mergeEnvironments(module.getEnvironment(), corbaEnvironment);
+                return new ORBReference(moduleId, corbaName);
+            }
+        } else {
+            //determine jsr-77 type from interface
+            String j2eeType;
 
-                    module.getEarContext().findGBean(containerId);
+            if (JAVAX_MAIL_SESSION_CLASS.equals(type)) {
+                j2eeType = NameFactory.JAVA_MAIL_RESOURCE;
+            } else if (JAXR_CONNECTION_FACTORY_CLASS.equals(type)) {
+                j2eeType = NameFactory.JAXR_CONNECTION_FACTORY;
+            } else {
+                j2eeType = NameFactory.JCA_CONNECTION_FACTORY;
+            }
+            try {
+                AbstractNameQuery containerId = getResourceContainerId(name, j2eeType, null,
gerResourceRef);
 
-                    Object ref = new ResourceReferenceFactory<ResourceException>(module.getConfigId(),
containerId, iface);
-                    put(name, ref, getJndiContextMap(componentContext));
-                    // we thought that this might be an unresolved
-                    // name because it wasn't in the refMap, but now
-                    // we've found it so we can take it out of the
-                    // unresolvedRefs list
-                    unresolvedRefs.remove(name);
-                } catch (GBeanNotFoundException e) {
-
-                    StringBuffer errorMessage = new StringBuffer("Unable to resolve resource
reference '");
-                    errorMessage.append(name);
-                    errorMessage.append("' (");
-                    if (e.hasMatches()) {
-                        errorMessage.append("Found multiple matching resources.  Try being
more specific in a resource-ref mapping in your Geronimo deployment plan.\n");
-                        for (AbstractName match : e.getMatches()) {
-                            errorMessage.append(match).append("\n");
-                        }
-                    } else if (gerResourceRef == null) {
-                        errorMessage.append("Could not auto-map to resource.  Try adding
a resource-ref mapping to your Geronimo deployment plan.");
-                    } else if (gerResourceRef.isSetResourceLink()) {
-                        errorMessage.append("Could not find resource '");
-                        errorMessage.append(gerResourceRef.getResourceLink());
-                        errorMessage.append("'.  Perhaps it has not yet been configured,
or your application does not have a dependency declared for that resource module?");
-                    } else {
-                        errorMessage.append("Could not find the resource specified in your
Geronimo deployment plan:");
-                        errorMessage.append(gerResourceRef.getPattern());
-                    }
-                    errorMessage.append("\nSearch conducted in current module and dependencies:\n");
-                    for (Dependency dependency : module.getEnvironment().getDependencies())
{
-                        errorMessage.append(dependency).append("\n");
-                    }
-                    errorMessage.append(")");
+                module.getEarContext().findGBean(containerId);
 
-                    throw new DeploymentException(errorMessage.toString());
+                return new ResourceReferenceFactory<ResourceException>(module.getConfigId(),
containerId, iface);
+            } catch (GBeanNotFoundException e) {
+                StringBuffer errorMessage = new StringBuffer("Unable to resolve resource
reference '");
+                errorMessage.append(name);
+                errorMessage.append("' (");
+                if (e.hasMatches()) {
+                    errorMessage.append("Found multiple matching resources.  Try being more
specific in a resource-ref mapping in your Geronimo deployment plan.\n");
+                    for (AbstractName match : e.getMatches()) {
+                        errorMessage.append(match).append("\n");
+                    }
+                } else if (gerResourceRef == null) {
+                    errorMessage.append("Could not auto-map to resource.  Try adding a resource-ref
mapping to your Geronimo deployment plan.");
+                } else if (gerResourceRef.isSetResourceLink()) {
+                    errorMessage.append("Could not find resource '");
+                    errorMessage.append(gerResourceRef.getResourceLink());
+                    errorMessage.append("'.  Perhaps it has not yet been configured, or your
application does not have a dependency declared for that resource module?");
+                } else {
+                    errorMessage.append("Could not find the resource specified in your Geronimo
deployment plan:");
+                    errorMessage.append(gerResourceRef.getPattern());
                 }
-            }
-        }
+                errorMessage.append("\nSearch conducted in current module and dependencies:\n");
+                for (Dependency dependency : module.getEnvironment().getDependencies()) {
+                    errorMessage.append(dependency).append("\n");
+                }
+                errorMessage.append(")");
 
-        if (unresolvedRefs.size() > 0) {
-            log.warn("Failed to build reference to resource reference "+ unresolvedRefs +"
defined in plan file, reason - corresponding entry in deployment descriptor missing.");
+                throw new DeploymentException(errorMessage.toString());
+            }
         }
+        
+        return null;
     }
-
+    
     public void setResourceEnvironment(ResourceEnvironmentBuilder builder, XmlObject[] resourceRefs,
GerResourceRefType[] gerResourceRefs) throws DeploymentException {
         List<ResourceRefType> resourceRefList = convert(resourceRefs, J2EE_CONVERTER,
ResourceRefType.class, ResourceRefType.type);
         Map refMap = mapResourceRefs(gerResourceRefs);

Modified: geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/datasource/deployment/DataSourceBuilder.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/datasource/deployment/DataSourceBuilder.java?rev=933722&r1=933721&r2=933722&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/datasource/deployment/DataSourceBuilder.java
(original)
+++ geronimo/server/trunk/plugins/connector-1_6/geronimo-connector-builder-1_6/src/main/java/org/apache/geronimo/datasource/deployment/DataSourceBuilder.java
Tue Apr 13 18:02:09 2010
@@ -373,15 +373,7 @@ public class DataSourceBuilder extends A
         
         return dsDescription;
     }
-    
-    private static String getJndiName(String name) {
-        if (name.startsWith("java:")) {
-            return name;
-        } else {
-            return "java:comp/env/" + name;
-        }
-    }
-    
+        
     public QNameSet getPlanQNameSet() {
         return QNameSet.EMPTY; 
     }

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java?rev=933722&r1=933721&r2=933722&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
(original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
Tue Apr 13 18:02:09 2010
@@ -600,6 +600,9 @@ public class EARConfigBuilder implements
                 }
             }
 
+            Map<JndiKey, Map<String, Object>> contexts = NamingBuilder.JNDI_KEY.get(earContext.getGeneralData());
+            contexts.put(JndiScope.app, new HashMap<String, Object>());
+            
             // give each module a chance to populate the earContext now that a classloader
is available
             Bundle bundle = earContext.getDeploymentBundle();
             for (Module module : applicationInfo.getModules()) {
@@ -679,10 +682,10 @@ public class EARConfigBuilder implements
                 EARConfigBuilder.appInfo.set(applicationInfo);
                 throw new DeploymentException();
             }
-            Map<JndiKey, Map<String, Object>> contexts = NamingBuilder.JNDI_KEY.get(earContext.getGeneralData());
+            
             GBeanData appContexts = new GBeanData(appJndiName, ApplicationJndi.class);
             appContexts.setAttribute("globalContextSegment", contexts.get(JndiScope.global));
-            appContexts.setAttribute("applicationContextMap", contexts.get(JndiScope.application));
+            appContexts.setAttribute("applicationContextMap", contexts.get(JndiScope.app));
             appContexts.setReferencePattern("GlobalContext", globalContextAbstractName);
             earContext.addGBean(appContexts);
 

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/jndi/ApplicationJndi.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/jndi/ApplicationJndi.java?rev=933722&r1=933721&r2=933722&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/jndi/ApplicationJndi.java
(original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/jndi/ApplicationJndi.java
Tue Apr 13 18:02:09 2010
@@ -53,7 +53,7 @@ public class ApplicationJndi implements 
         this.globalAdditions = EnterpriseNamingContext.livenReferences(globalContextSegment,
null, kernel, classLoader, JndiScope.global.name() + "/");
         this.globalContext = globalContext;
         this.globalContext.federateContext(this.globalAdditions);
-        this.applicationContext = EnterpriseNamingContext.livenReferences(applicationContext,
null, kernel, classLoader, JndiScope.application.name() + "/");
+        this.applicationContext = EnterpriseNamingContext.livenReferences(applicationContext,
null, kernel, classLoader, JndiScope.app.name() + "/");
     }
 
     public Context getApplicationContext() {

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/jndi/JndiScope.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/jndi/JndiScope.java?rev=933722&r1=933721&r2=933722&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/jndi/JndiScope.java
(original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/jndi/JndiScope.java
Tue Apr 13 18:02:09 2010
@@ -24,5 +24,5 @@ package org.apache.geronimo.j2ee.jndi;
  * @version $Rev$ $Date$
  */
 public enum JndiScope implements JndiKey {
-    global, application, module, comp
+    global, app, module, comp
 }

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java?rev=933722&r1=933721&r2=933722&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
(original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
Tue Apr 13 18:02:09 2010
@@ -169,6 +169,14 @@ public abstract class AbstractNamingBuil
         return NamingBuilder.JNDI_KEY.get(sharedContext);
     }
 
+    protected String getJndiName(String name) {
+        if (name.indexOf(':') != -1) {   
+            return "java:comp/env/" + name;
+        } else {
+            return name;
+        }
+    }
+    
     protected AbstractName getGBeanName(Map<EARContext.Key, Object> sharedContext)
{
         return GBEAN_NAME_KEY.get(sharedContext);
     }

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java?rev=933722&r1=933721&r2=933722&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
(original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
Tue Apr 13 18:02:09 2010
@@ -121,6 +121,9 @@ public class EnvironmentEntryBuilder ext
                 if (strValue == null) {
                     String lookupName = getStringValue(envEntry.getLookupName());
                     if (lookupName != null) {
+                        if (lookupName.equals(getJndiName(name))) {
+                            throw new DeploymentException("env-entry lookup name refers to
itself");
+                        }
                         value = new JndiReference(lookupName);
                     }
                 }

Modified: geronimo/server/trunk/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebApplication.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebApplication.java?rev=933722&r1=933721&r2=933722&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebApplication.java
(original)
+++ geronimo/server/trunk/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebApplication.java
Tue Apr 13 18:02:09 2010
@@ -200,10 +200,13 @@ public class WebApplication implements R
                         bundle);
                 webModule.setEarContext(deploymentContext);
                 webModule.setRootEarContext(deploymentContext);
-
+                
                 deploymentContext.flush();
                 deploymentContext.initializeConfiguration();
 
+                Map<JndiKey, Map<String, Object>> contexts = NamingBuilder.JNDI_KEY.get(deploymentContext.getGeneralData());
+                contexts.put(JndiScope.app, new HashMap<String, Object>());
+                
                 webModuleBuilder.initContext(deploymentContext, webModule, bundle);
 
                 AbstractName appJndiName = naming.createChildName(deploymentContext.getModuleName(),
"ApplicationJndi", "ApplicationJndi");
@@ -211,10 +214,9 @@ public class WebApplication implements R
 
                 webModuleBuilder.addGBeans(deploymentContext, webModule, bundle, extender.getRepositories());
 
-                Map<JndiKey, Map<String, Object>> contexts = NamingBuilder.JNDI_KEY.get(deploymentContext.getGeneralData());
                 GBeanData appContexts = new GBeanData(appJndiName, ApplicationJndi.class);
                 appContexts.setAttribute("globalContextSegment", contexts.get(JndiScope.global));
-                appContexts.setAttribute("applicationContextMap", contexts.get(JndiScope.application));
+                appContexts.setAttribute("applicationContextMap", contexts.get(JndiScope.app));
                 appContexts.setReferencePattern("GlobalContext", extender.getGlobalContextAbstractName());
                 deploymentContext.addGBean(appContexts);
 



Mime
View raw message