geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/model/geronimo/j2ee ResourceRef.java
Date Tue, 09 Sep 2003 03:47:10 GMT
jboynes     2003/09/08 20:47:10

  Modified:    modules/core/src/java/org/apache/geronimo/naming/java
                        ComponentContextBuilder.java
               modules/core/src/test/org/apache/geronimo/naming/java
                        ContextBuilderTest.java
               modules/core/src/java/org/apache/geronimo/deployment/model/geronimo/j2ee
                        ResourceRef.java
  Log:
  Support resource-ref for java.net.URL
  
  Revision  Changes    Path
  1.6       +27 -2     incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java
  
  Index: ComponentContextBuilder.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ComponentContextBuilder.java	8 Sep 2003 04:30:29 -0000	1.5
  +++ ComponentContextBuilder.java	9 Sep 2003 03:47:10 -0000	1.6
  @@ -55,15 +55,18 @@
    */
   package org.apache.geronimo.naming.java;
   
  +import java.net.MalformedURLException;
  +import java.net.URL;
   import java.util.HashMap;
   import java.util.Map;
   import javax.naming.Context;
   import javax.naming.LinkRef;
   
  -import org.apache.geronimo.kernel.deployment.DeploymentException;
   import org.apache.geronimo.deployment.model.geronimo.j2ee.EjbRef;
   import org.apache.geronimo.deployment.model.geronimo.j2ee.JNDIEnvironmentRefs;
  +import org.apache.geronimo.deployment.model.geronimo.j2ee.ResourceRef;
   import org.apache.geronimo.deployment.model.j2ee.EnvEntry;
  +import org.apache.geronimo.kernel.deployment.DeploymentException;
   
   /**
    *
  @@ -81,6 +84,7 @@
           Map envMap = new HashMap();
           buildEnvEntries(envMap, refs.getEnvEntry());
           buildEJBRefs(envMap, refs.getEJBRef());
  +        buildResourceRefs(envMap, refs.getResourceRef());
   
           Map compMap = new HashMap();
           compMap.put("env", new ReadOnlyContext(envMap));
  @@ -135,6 +139,27 @@
               LinkRef ref = new LinkRef(jndiName);
               if (envMap.put(name, ref) != null) {
                   throw new AssertionError("Duplicate entry for env-entry " + name);
  +            }
  +        }
  +    }
  +
  +    private static void buildResourceRefs(Map envMap, ResourceRef[] resRefs) throws DeploymentException
{
  +        for (int i=0; i < resRefs.length; i++) {
  +            ResourceRef resRef = resRefs[i];
  +            String name = resRef.getResRefName();
  +            String type = resRef.getResType();
  +            Object ref;
  +            if ("java.net.URL".equals(type)) {
  +                try {
  +                    ref = new URL(resRef.getURLRef());
  +                } catch (MalformedURLException e) {
  +                    throw new DeploymentException("Invalid URL for resource-ref "+name,
e);
  +                }
  +            } else {
  +                throw new DeploymentException("Cannot create resource-ref for "+name+",
unknown type "+type);
  +            }
  +            if (envMap.put(name, ref) != null) {
  +                throw new AssertionError("Duplicate entry for resource-ref " + name);
               }
           }
       }
  
  
  
  1.5       +10 -1     incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java
  
  Index: ContextBuilderTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/test/org/apache/geronimo/naming/java/ContextBuilderTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ContextBuilderTest.java	5 Sep 2003 20:47:15 -0000	1.4
  +++ ContextBuilderTest.java	9 Sep 2003 03:47:10 -0000	1.5
  @@ -55,12 +55,14 @@
    */
   package org.apache.geronimo.naming.java;
   
  +import java.net.URL;
   import javax.naming.Context;
   
   import junit.framework.TestCase;
   import org.apache.geronimo.deployment.model.geronimo.appclient.ApplicationClient;
   import org.apache.geronimo.deployment.model.j2ee.EnvEntry;
   import org.apache.geronimo.deployment.model.geronimo.j2ee.EjbRef;
  +import org.apache.geronimo.deployment.model.geronimo.j2ee.ResourceRef;
   
   /**
    *
  @@ -80,13 +82,20 @@
           intEntry.setEnvEntryName("int");
           intEntry.setEnvEntryType("java.lang.Integer");
           intEntry.setEnvEntryValue("12345");
  +
  +        ResourceRef urlRef = new ResourceRef();
  +        urlRef.setResRefName("url/testURL");
  +        urlRef.setResType(URL.class.getName());
  +        urlRef.setJndiName("http://localhost/path");
           client.setEnvEntry(new EnvEntry[] { stringEntry, intEntry });
           client.setEJBRef(new EjbRef[0]);
  +        client.setResourceRef(new ResourceRef[] { urlRef });
       }
   
       public void testEnvEntries() throws Exception {
           Context compCtx = ComponentContextBuilder.buildContext(client);
           assertEquals("Hello World", compCtx.lookup("env/string"));
           assertEquals(new Integer(12345), compCtx.lookup("env/int"));
  +        assertEquals(new URL("http://localhost/path"), compCtx.lookup("env/url/testURL"));
       }
   }
  
  
  
  1.3       +5 -1      incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/model/geronimo/j2ee/ResourceRef.java
  
  Index: ResourceRef.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/model/geronimo/j2ee/ResourceRef.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ResourceRef.java	5 Sep 2003 20:18:03 -0000	1.2
  +++ ResourceRef.java	9 Sep 2003 03:47:10 -0000	1.3
  @@ -87,4 +87,8 @@
       public void setJndiContextParam(int i, JndiContextParam jndiContextParam) {
           this.jndiContextParam[i] = jndiContextParam;
       }
  +
  +    public String getURLRef() {
  +        return jndiName; //@todo use a proper property
  +    }
   }
  
  
  

Mime
View raw message