You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2007/01/26 11:27:42 UTC

svn commit: r500210 - in /incubator/openejb/trunk/openejb3/container/openejb-core/src: main/java/org/apache/openejb/core/stateful/ main/java/org/apache/openejb/core/stateless/ test/java/org/apache/openejb/core/stateless/

Author: dblevins
Date: Fri Jan 26 02:27:42 2007
New Revision: 500210

URL: http://svn.apache.org/viewvc?view=rev&rev=500210
Log:
Don't wrap strings with a StaticRecipe

Added:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/ExtendedInjectionTest.java
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java?view=diff&rev=500210&r1=500209&r2=500210
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java Fri Jan 26 02:27:42 2007
@@ -138,7 +138,14 @@
                 try {
                     String jndiName = injection.getJndiName();
                     Object object = ctx.lookup("java:comp/env/" + jndiName);
-                    objectRecipe.setProperty(injection.getName(), new StaticRecipe(object));
+                    if (object instanceof String) {
+                        String string = (String) object;
+                        // Pass it in raw so it could be potentially converted to
+                        // another data type by an xbean-reflect property editor
+                        objectRecipe.setProperty(injection.getName(), string);
+                    } else {
+                        objectRecipe.setProperty(injection.getName(), new StaticRecipe(object));
+                    }
                 } catch (NamingException e) {
                     logger.warning("Injection data not found in enc: jndiName='" + injection.getJndiName() + "', target=" + injection.getTarget() + "/" + injection.getName());
                 }

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java?view=diff&rev=500210&r1=500209&r2=500210
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessInstanceManager.java Fri Jan 26 02:27:42 2007
@@ -115,7 +115,14 @@
                     try {
                         String jndiName = injection.getJndiName();
                         Object object = ctx.lookup("java:comp/env/" + jndiName);
-                        objectRecipe.setProperty(injection.getName(), new StaticRecipe(object));
+                        if (object instanceof String) {
+                            String string = (String) object;
+                            // Pass it in raw so it could be potentially converted to
+                            // another data type by an xbean-reflect property editor
+                            objectRecipe.setProperty(injection.getName(), string);
+                        } else {
+                            objectRecipe.setProperty(injection.getName(), new StaticRecipe(object));
+                        }
                     } catch (NamingException e) {
                         logger.warn("Injection data not found in enc: jndiName='"+injection.getJndiName()+"', target="+injection.getTarget()+"/"+injection.getName());
                     }

Added: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/ExtendedInjectionTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/ExtendedInjectionTest.java?view=auto&rev=500210
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/ExtendedInjectionTest.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/ExtendedInjectionTest.java Fri Jan 26 02:27:42 2007
@@ -0,0 +1,167 @@
+/**
+ * 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.core.stateless;
+
+import junit.framework.TestCase;
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.assembler.classic.EjbJarBuilder;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
+import org.apache.openejb.util.proxy.ProxyManager;
+import org.apache.openejb.util.proxy.Jdk13ProxyFactory;
+import org.apache.openejb.spi.SecurityService;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.ri.sp.PseudoTransactionService;
+import org.apache.openejb.ri.sp.PseudoSecurityService;
+import org.apache.openejb.config.EjbModule;
+import org.apache.openejb.config.EjbJarInfoBuilder;
+import org.apache.openejb.jee.StatelessBean;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.EnvEntry;
+import org.apache.openejb.jee.InjectionTarget;
+import org.apache.openejb.jee.oejb3.OpenejbJar;
+import org.apache.openejb.jee.oejb3.EjbDeployment;
+import org.apache.openejb.core.CoreDeploymentInfo;
+
+import javax.ejb.SessionContext;
+import java.util.Stack;
+import java.util.List;
+import java.util.Arrays;
+import java.util.Properties;
+import java.util.HashMap;
+import java.net.URL;
+
+/**
+ * @version $Revision: 500061 $ $Date: 2007-01-25 15:47:53 -0800 (Thu, 25 Jan 2007) $
+ */
+public class ExtendedInjectionTest extends TestCase {
+    private StatelessContainer container;
+    private DeploymentInfo deploymentInfo;
+
+    public void testBusinessLocalInterface() throws Exception {
+
+        CoreDeploymentInfo coreDeploymentInfo = (CoreDeploymentInfo) deploymentInfo;
+        DeploymentInfo.BusinessLocalHome businessLocalHome = coreDeploymentInfo.getBusinessLocalHome();
+        assertNotNull("businessLocalHome", businessLocalHome);
+
+        Object object = businessLocalHome.create();
+        assertNotNull("businessLocalHome.create()", businessLocalHome);
+
+        assertTrue("instanceof widget", object instanceof Widget);
+
+        Widget widget = (Widget) object;
+
+        // Do a business method...
+        URL homepage = widget.getHomepage();
+        assertNotNull(homepage);
+        assertEquals("http://people.apache.org/~dblevins/", homepage.toExternalForm());
+
+    }
+
+    public void testBusinessRemoteInterface() throws Exception {
+
+        CoreDeploymentInfo coreDeploymentInfo = (CoreDeploymentInfo) deploymentInfo;
+        DeploymentInfo.BusinessRemoteHome businessRemoteHome = coreDeploymentInfo.getBusinessRemoteHome();
+        assertNotNull("businessRemoteHome", businessRemoteHome);
+
+        Object object = businessRemoteHome.create();
+        assertNotNull("businessRemoteHome.create()", businessRemoteHome);
+
+        assertTrue("instanceof widget", object instanceof RemoteWidget);
+
+        RemoteWidget widget = (RemoteWidget) object;
+
+        // Do a business method...
+        URL homepage = widget.getHomepage();
+        assertNotNull(homepage);
+        assertEquals("http://people.apache.org/~dblevins/", homepage.toExternalForm());
+
+    }
+
+    protected void setUp() throws Exception {
+        StatelessBean bean = new StatelessBean("widget", WidgetBean.class.getName());
+        bean.setBusinessLocal(Widget.class.getName());
+        bean.setBusinessRemote(RemoteWidget.class.getName());
+
+        EnvEntry envEntry = new EnvEntry("homepage", String.class.getName(), "http://people.apache.org/~dblevins/");
+        envEntry.getInjectionTarget().add(new InjectionTarget(bean.getEjbClass(), "homepage"));
+        bean.getEnvEntry().add(envEntry);
+
+        EjbJar ejbJar = new EjbJar();
+        ejbJar.addEnterpriseBean(bean);
+
+        OpenejbJar openejbJar = new OpenejbJar();
+        openejbJar.addEjbDeployment(new EjbDeployment("Stateless Container", "widget", "widget"));
+
+        EjbModule jar = new EjbModule(this.getClass().getClassLoader(), "", ejbJar, openejbJar);
+
+        PseudoTransactionService transactionManager = new PseudoTransactionService();
+        PseudoSecurityService securityService = new PseudoSecurityService();
+        SystemInstance.get().setComponent(SecurityService.class, securityService);
+        container = new StatelessContainer("Stateless Container", transactionManager, securityService, 10, 0, false);
+        Properties props = new Properties();
+        props.put(container.getContainerID(), container);
+
+        HashMap<String, DeploymentInfo> ejbs = build(props, jar);
+        deploymentInfo = ejbs.get("widget");
+
+        ProxyManager.registerFactory("ivm_server", new Jdk13ProxyFactory());
+        ProxyManager.setDefaultFactory("ivm_server");
+
+    }
+
+    private static String join(String delimeter, List items) {
+        StringBuffer sb = new StringBuffer();
+        for (Object item : items) {
+            sb.append(item.toString()).append(delimeter);
+        }
+        return sb.toString();
+    }
+
+    private HashMap<String, DeploymentInfo> build(Properties props, EjbModule jar) throws OpenEJBException {
+        EjbJarInfoBuilder infoBuilder = new EjbJarInfoBuilder();
+        EjbJarBuilder builder = new EjbJarBuilder(props, this.getClass().getClassLoader());
+        EjbJarInfo jarInfo = infoBuilder.buildInfo(jar);
+        HashMap<String, DeploymentInfo> ejbs = builder.build(jarInfo,null);
+        return ejbs;
+    }
+
+    public static interface Widget {
+        URL getHomepage();
+    }
+
+    public static interface RemoteWidget extends Widget {
+
+    }
+
+    public static enum Lifecycle {
+        CONSTRUCTOR, POST_CONSTRUCT, BUSINESS_METHOD, PRE_DESTROY
+    }
+
+    public static class WidgetBean implements Widget, RemoteWidget {
+
+        private URL homepage;
+
+        public URL getHomepage() {
+            return homepage;
+        }
+
+        public void setHomepage(URL homepage) {
+            this.homepage = homepage;
+        }
+    }
+}