tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject svn commit: r810297 - in /openejb/trunk/openejb3: container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ container/openejb-core/src/main/java/org/apache/openejb/config/ container/openejb-core/src/main/java/org/apache/openejb/util/ c...
Date Tue, 01 Sep 2009 22:59:24 GMT
Author: jgallimore
Date: Tue Sep  1 22:59:24 2009
New Revision: 810297

URL: http://svn.apache.org/viewvc?rev=810297&view=rev
Log:
OPENEJB-1056 add support for .uc, .lc and .cc for JNDI name formats. Refactored usages of
Swizzle Stream StringTemplate class to use new util class instead

Added:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/StringTemplate.java
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/JndiNameFormatTest.java
    openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
    openejb/trunk/openejb3/server/openejb-webservices/src/main/java/org/apache/openejb/server/webservices/WsService.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java?rev=810297&r1=810296&r2=810297&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiBuilder.java
Tue Sep  1 22:59:24 2009
@@ -38,14 +38,17 @@
 import org.apache.openejb.core.ivm.naming.BusinessRemoteReference;
 import org.apache.openejb.core.ivm.naming.ObjectReference;
 import org.apache.openejb.core.ivm.naming.IntraVmJndiReference;
-import org.codehaus.swizzle.stream.StringTemplate;
+import org.apache.openejb.util.StringTemplate;
 
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Comparator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
 
 
 /**
@@ -160,18 +163,20 @@
     // TODO: put these into the classpath and get them with xbean-finder
     public static class TemplatedStrategy implements JndiNameStrategy {
         private static final String JNDINAME_FORMAT = "openejb.jndiname.format";
-        private org.codehaus.swizzle.stream.StringTemplate template;
+        private org.apache.openejb.util.StringTemplate template;
         private HashMap<String, EnterpriseBeanInfo> beanInfos;
 
         // Set in begin()
         private DeploymentInfo deploymentInfo;
         // Set in begin()
         private Map<String, StringTemplate> templates;
+        
+        private String format;
 
         public TemplatedStrategy(EjbJarInfo ejbJarInfo, Map<String, DeploymentInfo>
deployments) {
             Options options = new Options(ejbJarInfo.properties, SystemInstance.get().getOptions());
 
-            String format = options.get(JNDINAME_FORMAT, "{deploymentId}{interfaceType.annotationName}");
+            format = options.get(JNDINAME_FORMAT, "{deploymentId}{interfaceType.annotationName}");
 
             this.template = new StringTemplate(format);
 
@@ -222,6 +227,7 @@
             contextData.put("interfaceClass", interfce.getName());
             contextData.put("interfaceClass.simpleName", interfce.getSimpleName());
             contextData.put("interfaceClass.packageName", packageName(interfce));
+
             return template.apply(contextData);
         }
     }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java?rev=810297&r1=810296&r2=810297&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/InitEjbDeployments.java
Tue Sep  1 22:59:24 2009
@@ -31,7 +31,7 @@
 import org.apache.openejb.jee.EnterpriseBean;
 import org.apache.openejb.jee.EntityBean;
 import org.apache.openejb.jee.PersistenceType;
-import org.codehaus.swizzle.stream.StringTemplate;
+import org.apache.openejb.util.StringTemplate;
 
 public class InitEjbDeployments implements DynamicDeployer {
     public static Messages messages = new Messages("org.apache.openejb.util.resources");

Added: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/StringTemplate.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/StringTemplate.java?rev=810297&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/StringTemplate.java
(added)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/StringTemplate.java
Tue Sep  1 22:59:24 2009
@@ -0,0 +1,55 @@
+/**
+ * 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.openejb.util;
+
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class StringTemplate {
+
+	public static final Pattern PATTERN = Pattern.compile("(\\{)((\\.|\\w)+)(})");
+	private final String template;
+
+	public StringTemplate(String template) {
+		this.template = template;
+	}
+
+	public String apply(Map<String, String> map) {
+    	Matcher matcher = PATTERN.matcher(template);
+    	StringBuffer buf = new StringBuffer();
+ 
+    	while (matcher.find()) {
+    		String key = matcher.group(2);
+    		String value = map.get(key);
+    		
+    		if (key.toLowerCase().endsWith(".lc")) {
+    			value = map.get(key.substring(0, key.length() - 3)).toLowerCase();
+    		} else if (key.toLowerCase().endsWith(".uc")) {
+    			value = map.get(key.substring(0, key.length() - 3)).toUpperCase();
+    		} else if (key.toLowerCase().endsWith(".cc")) {
+    			value = Strings.camelCase(map.get(key.substring(0, key.length() - 3)));
+			}
+    		
+    		matcher.appendReplacement(buf, value);
+    	}
+
+    	matcher.appendTail(buf);
+    	return buf.toString();
+	}
+
+}

Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/JndiNameFormatTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/JndiNameFormatTest.java?rev=810297&r1=810296&r2=810297&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/JndiNameFormatTest.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/JndiNameFormatTest.java
Tue Sep  1 22:59:24 2009
@@ -17,31 +17,34 @@
 
 package org.apache.openejb.config;
 
-import junit.framework.TestCase;
+import java.io.IOException;
+import java.util.Properties;
 
 import javax.ejb.Remote;
 import javax.ejb.Stateless;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
-import java.util.Properties;
-import java.io.IOException;
+
+import junit.framework.TestCase;
 
 import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.jee.jpa.unit.Persistence;
-import org.apache.openejb.jee.EjbJar;
-import org.apache.openejb.jee.StatelessBean;
 import org.apache.openejb.assembler.classic.Assembler;
-import org.apache.openejb.assembler.classic.TransactionServiceInfo;
 import org.apache.openejb.assembler.classic.SecurityServiceInfo;
+import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.StatelessBean;
+import org.apache.openejb.loader.SystemInstance;
 
 public class JndiNameFormatTest extends TestCase {
 
-    public void setUp() throws OpenEJBException, NamingException, IOException {
-        System.setProperty("openejb.jndiname.format", "{ejbName}/{interfaceType.annotationNameLC}");
+	private Assembler assembler;
+
+	private void deploy(String format) throws OpenEJBException, IOException, NamingException
{
+		SystemInstance.get().setProperty("openejb.jndiname.format", format);
 
-        ConfigurationFactory config = new ConfigurationFactory();
-        Assembler assembler = new Assembler();
+		ConfigurationFactory config = new ConfigurationFactory();
+        assembler = new Assembler();
 
         assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
         assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
@@ -53,18 +56,61 @@
         app.getEjbModules().add(new EjbModule(ejbJar));
 
         assembler.createApplication(config.configureApplication(app));
-    }
+	}
 
     public void testShouldLookupDeployBeanWithLowercaseInterfaceName() throws Exception {
-        Properties p = new Properties();
+        deploy("{ejbName}/{interfaceType.annotationName.lc}");
+    	
+    	Properties p = new Properties();
         p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
 
         InitialContext context = new InitialContext(p);
         Echo echo = (Echo) context.lookup("EchoImpl/remote");
 
         assertEquals("Echoing: This is a test", echo.echo("This is a test"));
+        assembler.destroy();
+    }
+
+    public void testShouldLookupDeployBeanWithUppercaseInterfaceName() throws Exception {
+        deploy("{ejbName}/{interfaceType.annotationName.uc}");
+    	
+    	Properties p = new Properties();
+        p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+
+        InitialContext context = new InitialContext(p);
+        Echo echo = (Echo) context.lookup("EchoImpl/REMOTE");
+
+        assertEquals("Echoing: This is a test", echo.echo("This is a test"));
+        assembler.destroy();
+    }
+
+    public void testShouldLookupDeployBeanWithCamelCaseInterfaceName() throws Exception {
+        deploy("{ejbName}/{interfaceType.annotationName.cc}");
+    	
+    	Properties p = new Properties();
+        p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+
+        InitialContext context = new InitialContext(p);
+        Echo echo = (Echo) context.lookup("EchoImpl/Remote");
+
+        assertEquals("Echoing: This is a test", echo.echo("This is a test"));
+        assembler.destroy();
+    }
+
+    public void testShouldLookupDeployBeanLowerCaseClassNameAndUpperCaseInterfaceName() throws
Exception {
+        deploy("{ejbName.lc}/{interfaceType.annotationName.uc}");
+    	
+    	Properties p = new Properties();
+        p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+
+        InitialContext context = new InitialContext(p);
+        Echo echo = (Echo) context.lookup("echoimpl/REMOTE");
+
+        assertEquals("Echoing: This is a test", echo.echo("This is a test"));
+        assembler.destroy();
     }
 
+    
     @Remote
     public static interface Echo {
         String echo(String input);

Modified: openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java?rev=810297&r1=810296&r2=810297&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
(original)
+++ openejb/trunk/openejb3/server/openejb-server/src/main/java/org/apache/openejb/server/ServiceDaemon.java
Tue Sep  1 22:59:24 2009
@@ -20,7 +20,7 @@
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.loader.Options;
 import org.apache.openejb.loader.SystemInstance;
-import org.codehaus.swizzle.stream.StringTemplate;
+import org.apache.openejb.util.StringTemplate;
 
 import javax.net.ServerSocketFactory;
 import javax.net.ssl.SSLServerSocket;
@@ -170,8 +170,8 @@
 
             DiscoveryAgent agent = SystemInstance.get().getComponent(DiscoveryAgent.class);
             if (agent != null && discoveryUriFormat != null) {
-                Map map = new HashMap();
-                map.put("port", port);
+                Map<String,String> map = new HashMap<String,String>();
+                map.put("port", Integer.toString(port));
                 map.put("host", ip);
                 map.put("bind", ip);
                 String uriString = discoveryUriFormat.apply(map);

Modified: openejb/trunk/openejb3/server/openejb-webservices/src/main/java/org/apache/openejb/server/webservices/WsService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-webservices/src/main/java/org/apache/openejb/server/webservices/WsService.java?rev=810297&r1=810296&r2=810297&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-webservices/src/main/java/org/apache/openejb/server/webservices/WsService.java
(original)
+++ openejb/trunk/openejb3/server/openejb-webservices/src/main/java/org/apache/openejb/server/webservices/WsService.java
Tue Sep  1 22:59:24 2009
@@ -44,7 +44,7 @@
 import org.apache.openejb.Injection;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.LogCategory;
-import org.codehaus.swizzle.stream.StringTemplate;
+import org.apache.openejb.util.StringTemplate;
 
 import javax.naming.Context;
 import java.util.Properties;



Mime
View raw message