You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2009/03/26 11:17:07 UTC

svn commit: r758581 - in /geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder: ./ src/main/java/org/apache/geronimo/naming/deployment/ src/main/xsd/ src/test/java/org/apache/geronimo/naming/deployment/

Author: djencks
Date: Thu Mar 26 10:16:51 2009
New Revision: 758581

URL: http://svn.apache.org/viewvc?rev=758581&view=rev
Log:
GERONIMO-3954 allow overrides of env-entry values in geronimo plan

Modified:
    geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/   (props changed)
    geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
    geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/main/xsd/geronimo-naming-1.2.xsd
    geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/test/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilderTest.java

Propchange: geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Thu Mar 26 10:16:51 2009
@@ -0,0 +1,2 @@
+/geronimo/server/branches/2.1.4/plugins/j2ee/geronimo-naming-builder:756973
+/geronimo/server/trunk/plugins/j2ee/geronimo-naming-builder:695597,695602,758570

Modified: geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java?rev=758581&r1=758580&r2=758581&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java (original)
+++ geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java Thu Mar 26 10:16:51 2009
@@ -22,8 +22,10 @@
 import java.util.List;
 import java.util.Map;
 import java.util.HashMap;
+import java.util.ArrayList;
 
 import javax.annotation.Resource;
+import javax.xml.namespace.QName;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -36,6 +38,8 @@
 import org.apache.geronimo.j2ee.deployment.annotation.ResourceAnnotationHelper;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.naming.reference.KernelReference;
+import org.apache.geronimo.xbeans.geronimo.naming.GerEnvEntryDocument;
+import org.apache.geronimo.xbeans.geronimo.naming.GerEnvEntryType;
 import org.apache.geronimo.xbeans.javaee.DescriptionType;
 import org.apache.geronimo.xbeans.javaee.EnvEntryType;
 import org.apache.geronimo.xbeans.javaee.EnvEntryTypeValuesType;
@@ -58,6 +62,8 @@
         NAMESPACE_UPDATES.put("http://geronimo.apache.org/xml/ns/naming-1.1", "http://geronimo.apache.org/xml/ns/naming-1.2");
     }
 
+    private static final QName GER_ENV_ENTRY_QNAME = GerEnvEntryDocument.type.getDocumentElementName();
+    private static final QNameSet GER_ENV_ENTRY_QNAME_SET = QNameSet.singleton(GER_ENV_ENTRY_QNAME);
     private final QNameSet envEntryQNameSet;
 
     public EnvironmentEntryBuilder(String[] eeNamespaces) {
@@ -91,10 +97,15 @@
         }
 
         List<EnvEntryType> envEntriesUntyped = convert(specDD.selectChildren(envEntryQNameSet), JEE_CONVERTER, EnvEntryType.class, EnvEntryType.type);
+        XmlObject[] gerEnvEntryUntyped = plan == null ? NO_REFS : plan.selectChildren(GER_ENV_ENTRY_QNAME_SET);
+        Map<String, String> envEntryMap = mapEnvEntries(gerEnvEntryUntyped);
         for (EnvEntryType envEntry: envEntriesUntyped) {
             String name = getStringValue(envEntry.getEnvEntryName());
             String type = getStringValue(envEntry.getEnvEntryType());
-            String text = getStringValue(envEntry.getEnvEntryValue());
+            String text = envEntryMap.remove(name);
+            if (text == null) {
+                text = getStringValue(envEntry.getEnvEntryValue());
+            }
             try {
                 Object value;
                 if (text == null) {
@@ -134,9 +145,22 @@
                 throw new DeploymentException("Invalid env-entry value for name: " + name, e);
             }
         }
+        if (!envEntryMap.isEmpty()) {
+            throw new DeploymentException("Unknown env-entry elements in geronimo plan: " + envEntryMap);
+        }
 
     }
 
+    private Map<String, String> mapEnvEntries(XmlObject[] refs) {
+        Map<String, String> envEntryMap = new HashMap<String, String>();
+        if (refs != null) {
+            for (XmlObject ref1 : refs) {
+                GerEnvEntryType ref = (GerEnvEntryType) ref1.copy().changeType(GerEnvEntryType.type);
+                envEntryMap.put(ref.getEnvEntryName().trim(), ref.getEnvEntryValue().trim());
+            }
+        }
+        return envEntryMap;
+    }
     public QNameSet getSpecQNameSet() {
         return envEntryQNameSet;
     }

Modified: geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/main/xsd/geronimo-naming-1.2.xsd
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/main/xsd/geronimo-naming-1.2.xsd?rev=758581&r1=758580&r2=758581&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/main/xsd/geronimo-naming-1.2.xsd (original)
+++ geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/main/xsd/geronimo-naming-1.2.xsd Thu Mar 26 10:16:51 2009
@@ -49,6 +49,16 @@
         </xsd:annotation>
     </xsd:import>
 
+    <xsd:element name="env-entry" type="gernaming:env-entryType">
+        <xsd:annotation>
+            <xsd:documentation>
+                The element env-entry is used to override env-entry
+                values supplied in the JavaEE deployment descriptor
+                or annotations.  There must be an env-entry with the
+                same name in the deployment descriptor.
+            </xsd:documentation>
+        </xsd:annotation>
+    </xsd:element>
     <xsd:element name="ejb-ref" type="gernaming:ejb-refType">
         <xsd:annotation>
             <xsd:documentation>
@@ -126,6 +136,17 @@
         <xsd:sequence>
             <xsd:element ref="gernaming:abstract-naming-entry" minOccurs="0"
                 maxOccurs="unbounded" />
+            <xsd:element name="env-entry" type="gernaming:env-entryType"
+                minOccurs="0" maxOccurs="unbounded">
+                <xsd:annotation>
+                    <xsd:documentation>
+                        The element env-entry is used to override env-entry
+                        values supplied in the JavaEE deployment descriptor
+                        or annotations.  There must be an env-entry with the
+                        same name in the deployment descriptor.
+                    </xsd:documentation>
+                </xsd:annotation>
+            </xsd:element>
             <xsd:element name="ejb-ref" type="gernaming:ejb-refType"
                 minOccurs="0" maxOccurs="unbounded">
                 <xsd:annotation>
@@ -207,6 +228,33 @@
         <xsd:sequence></xsd:sequence>
     </xsd:complexType>
 
+    <xsd:complexType name="env-entryType">
+        <xsd:sequence>
+            <xsd:element name="env-entry-name" type="xsd:string">
+                <xsd:annotation>
+                    <xsd:documentation>
+                        The element env-entry-name is used to identify this env-entry.
+                        This name should be unique in a module and
+                        will be used by application as a part of JNDI name for
+                        the environment entry. The JNDI name used will be
+                        "java:/comp/env/env-entry-name. It must be identical to the
+                        "env-entry-name" provided in the deployment descriptor.
+                    </xsd:documentation>
+                </xsd:annotation>
+            </xsd:element>
+            <xsd:element name="env-entry-value" type="xsd:string">
+                <xsd:annotation>
+                    <xsd:documentation>
+                        The element env-entry-value supplies the value
+                        for the environment entry to be used instead of
+                        the value provided in the deployment descriptor
+                        or annotation.
+                    </xsd:documentation>
+                </xsd:annotation>
+            </xsd:element>
+        </xsd:sequence>
+    </xsd:complexType>
+
     <!--ejb-link acts like ejb-link in spec descriptors-->
     <!--resource-link contains the name of the outbound-connectionfactory-instance -->
     <!--message-destination-link acts like message-destination-link in spec descriptors-->

Modified: geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/test/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilderTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/test/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilderTest.java?rev=758581&r1=758580&r2=758581&view=diff
==============================================================================
--- geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/test/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilderTest.java (original)
+++ geronimo/server/branches/2.1/plugins/j2ee/geronimo-naming-builder/src/test/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilderTest.java Thu Mar 26 10:16:51 2009
@@ -96,6 +96,52 @@
             "<env-entry-value>TRUE</env-entry-value>" +
             "</env-entry>" +
             "</tmp>";
+    private static final String TEST_PLAN = "<tmp xmlns=\"http://geronimo.apache.org/xml/ns/naming-1.2\">" +
+            "<env-entry>" +
+            "<env-entry-name>string</env-entry-name>" +
+            "<env-entry-value>Goodbye World</env-entry-value>" +
+            "</env-entry>" +
+
+            "<env-entry>" +
+            "<env-entry-name>char</env-entry-name>" +
+            "<env-entry-value>K</env-entry-value>" +
+            "</env-entry>" +
+
+            "<env-entry>" +
+            "<env-entry-name>byte</env-entry-name>" +
+            "<env-entry-value>21</env-entry-value>" +
+            "</env-entry>" +
+
+            "<env-entry>" +
+            "<env-entry-name>short</env-entry-name>" +
+            "<env-entry-value>4321</env-entry-value>" +
+            "</env-entry>" +
+
+            "<env-entry>" +
+            "<env-entry-name>int</env-entry-name>" +
+            "<env-entry-value>87654321</env-entry-value>" +
+            "</env-entry>" +
+
+            "<env-entry>" +
+            "<env-entry-name>long</env-entry-name>" +
+            "<env-entry-value>6543210987654321</env-entry-value>" +
+            "</env-entry>" +
+
+            "<env-entry>" +
+            "<env-entry-name>float</env-entry-name>" +
+            "<env-entry-value>654.321</env-entry-value>" +
+            "</env-entry>" +
+
+            "<env-entry>" +
+            "<env-entry-name>double</env-entry-name>" +
+            "<env-entry-value>9876.54321</env-entry-value>" +
+            "</env-entry>" +
+
+            "<env-entry>" +
+            "<env-entry-name>boolean</env-entry-name>" +
+            "<env-entry-value>FALSE</env-entry-value>" +
+            "</env-entry>" +
+            "</tmp>";
 
     public void testEnvEntries() throws Exception {
 
@@ -137,6 +183,54 @@
         assertEquals(booleanVal, context.lookup("env/boolean"));
     }
 
+    public void testEnvEntriesOverride() throws Exception {
+
+        String stringVal = "Goodbye World";
+        Character charVal = new Character('K');
+        Byte byteVal = new Byte((byte) 21);
+        Short shortVal = new Short((short) 4321);
+        Integer intVal = new Integer(87654321);
+        Long longVal = new Long(6543210987654321L);
+        Float floatVal = new Float(654.321);
+        Double doubleVal = new Double(9876.54321);
+        Boolean booleanVal = Boolean.FALSE;
+
+        XmlObject doc = XmlObject.Factory.parse(TEST);
+        XmlCursor cursor = doc.newCursor();
+        try {
+            cursor.toFirstChild();
+            doc = cursor.getObject();
+        } finally {
+            cursor.dispose();
+        }
+        XmlObject plan = XmlObject.Factory.parse(TEST_PLAN);
+        cursor = plan.newCursor();
+        try {
+            cursor.toFirstChild();
+            plan = cursor.getObject();
+        } finally {
+            cursor.dispose();
+        }
+        environmentEntryBuilder.buildNaming(doc, plan, null, componentContext);
+        Context context = EnterpriseNamingContext.createEnterpriseNamingContext(NamingBuilder.JNDI_KEY.get(componentContext));
+        Set actual = new HashSet();
+        for (NamingEnumeration e = context.listBindings("env"); e.hasMore();) {
+            NameClassPair pair = (NameClassPair) e.next();
+            actual.add(pair.getName());
+        }
+        Set expected = new HashSet(Arrays.asList(new String[]{"string", "char", "byte", "short", "int", "long", "float", "double", "boolean"}));
+        assertEquals(expected, actual);
+        assertEquals(stringVal, context.lookup("env/string"));
+        assertEquals(charVal, context.lookup("env/char"));
+        assertEquals(byteVal, context.lookup("env/byte"));
+        assertEquals(shortVal, context.lookup("env/short"));
+        assertEquals(intVal, context.lookup("env/int"));
+        assertEquals(longVal, context.lookup("env/long"));
+        assertEquals(floatVal, context.lookup("env/float"));
+        assertEquals(doubleVal, context.lookup("env/double"));
+        assertEquals(booleanVal, context.lookup("env/boolean"));
+    }
+
     public void xtestEmptyEnvironment() throws NamingException {
         Context context = EnterpriseNamingContext.createEnterpriseNamingContext(componentContext);
         try {