You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2008/08/13 11:20:46 UTC
svn commit: r685490 [1/2] - in /openejb/trunk/openejb3/container: ./
openejb-core/
openejb-core/src/main/java/org/apache/openejb/assembler/classic/
openejb-core/src/main/java/org/apache/openejb/config/
openejb-core/src/main/java/org/apache/openejb/util...
Author: dain
Date: Wed Aug 13 02:20:31 2008
New Revision: 685490
URL: http://svn.apache.org/viewvc?rev=685490&view=rev
Log:
Embedding OpenEJB into Spring initial draft
Added:
openejb/trunk/openejb3/container/openejb-spring/ (with props)
openejb/trunk/openejb3/container/openejb-spring/pom.xml
openejb/trunk/openejb3/container/openejb-spring/src/
openejb/trunk/openejb3/container/openejb-spring/src/main/
openejb/trunk/openejb3/container/openejb-spring/src/main/java/
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/BmpContainer.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/CmpContainer.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ContainerProvider.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/Exported.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/MdbContainer.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/OpenEJB.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/OpenEJBDataSource.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/Resource.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SingletonContainer.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SpringAssembler.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SpringReference.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/StatefulContainer.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/StatelessContainer.java
openejb/trunk/openejb3/container/openejb-spring/src/main/resources/
openejb/trunk/openejb3/container/openejb-spring/src/test/
openejb/trunk/openejb3/container/openejb-spring/src/test/java/
openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/
openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/
openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/
openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/
openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/MockSecurityService.java
openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/MockTransactionManager.java
openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/SpringTest.java
openejb/trunk/openejb3/container/openejb-spring/src/test/resources/
openejb/trunk/openejb3/container/openejb-spring/src/test/resources/org/
openejb/trunk/openejb3/container/openejb-spring/src/test/resources/org/apache/
openejb/trunk/openejb3/container/openejb-spring/src/test/resources/org/apache/openejb/
openejb/trunk/openejb3/container/openejb-spring/src/test/resources/org/apache/openejb/spring/
openejb/trunk/openejb3/container/openejb-spring/src/test/resources/org/apache/openejb/spring/spring.xml
Modified:
openejb/trunk/openejb3/container/openejb-core/pom.xml
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java
openejb/trunk/openejb3/container/openejb-core/src/test/resources/org/apache/openejb/core/mdb/activemq.xml
openejb/trunk/openejb3/container/pom.xml
Modified: openejb/trunk/openejb3/container/openejb-core/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/pom.xml?rev=685490&r1=685489&r2=685490&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/pom.xml (original)
+++ openejb/trunk/openejb3/container/openejb-core/pom.xml Wed Aug 13 02:20:31 2008
@@ -369,13 +369,12 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
- <version>2.5.5</version>
- <scope>test</scope>
+ <version>2.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
- <version>3.4.3</version>
+ <version>3.4.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=685490&r1=685489&r2=685490&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java Wed Aug 13 02:20:31 2008
@@ -34,7 +34,6 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Set;
-import java.util.LinkedHashSet;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
@@ -88,12 +87,10 @@
import org.apache.openejb.util.OpenEJBErrorHandler;
import org.apache.openejb.util.SafeToolkit;
import org.apache.openejb.util.References;
-import org.apache.openejb.util.CircularReferencesException;
import org.apache.openejb.util.proxy.ProxyFactory;
import org.apache.openejb.util.proxy.ProxyManager;
import org.apache.xbean.recipe.ObjectRecipe;
import org.apache.xbean.recipe.Option;
-import org.apache.xbean.recipe.StaticRecipe;
import org.apache.xbean.recipe.UnsetPropertiesRecipe;
public class Assembler extends AssemblerTool implements org.apache.openejb.spi.Assembler {
@@ -118,7 +115,7 @@
private final JndiBuilder jndiBuilder;
private TransactionManager transactionManager;
private SecurityService securityService;
- private OpenEjbConfigurationFactory configFactory;
+ protected OpenEjbConfigurationFactory configFactory;
private final Map<String, AppInfo> deployedApplications = new HashMap<String, AppInfo>();
private final List<DeploymentListener> deploymentListeners = new ArrayList<DeploymentListener>();
@@ -261,7 +258,7 @@
public void build() throws OpenEJBException {
setContext(new HashMap<String, Object>());
try {
- OpenEjbConfiguration config = configFactory.getOpenEjbConfiguration();
+ OpenEjbConfiguration config = getOpenEjbConfiguration();
buildContainerSystem(config);
} catch (OpenEJBException ae) {
/* OpenEJBExceptions contain useful information and are debbugable.
@@ -281,6 +278,11 @@
}
}
+ protected OpenEjbConfiguration getOpenEjbConfiguration() throws OpenEJBException {
+ OpenEjbConfiguration config = configFactory.getOpenEjbConfiguration();
+ return config;
+ }
+
/////////////////////////////////////////////////////////////////////
////
//// Public Methods Used for Assembly
@@ -834,9 +836,9 @@
ObjectRecipe serviceRecipe = createRecipe(serviceInfo);
- serviceRecipe.setProperty("id", new StaticRecipe(serviceInfo.id));
- serviceRecipe.setProperty("transactionManager", new StaticRecipe(props.get(TransactionManager.class.getName())));
- serviceRecipe.setProperty("securityService", new StaticRecipe(props.get(SecurityService.class.getName())));
+ serviceRecipe.setProperty("id", serviceInfo.id);
+ serviceRecipe.setProperty("transactionManager", props.get(TransactionManager.class.getName()));
+ serviceRecipe.setProperty("securityService", props.get(SecurityService.class.getName()));
// MDB container has a resource adapter string name that
// must be replaced with the real resource adapter instance
@@ -1054,7 +1056,7 @@
ObjectRecipe serviceRecipe = createRecipe(serviceInfo);
Object object = props.get("TransactionManager");
- serviceRecipe.setProperty("transactionManager", new StaticRecipe(object));
+ serviceRecipe.setProperty("transactionManager", object);
Object service = serviceRecipe.create();
@@ -1187,7 +1189,8 @@
private ObjectRecipe createRecipe(ServiceInfo info) {
Logger serviceLogger = logger.getChildLogger("service");
serviceLogger.info("createService", info.service, info.id, info.className);
- ObjectRecipe serviceRecipe = new ObjectRecipe(info.className, info.factoryMethod, info.constructorArgs.toArray(new String[0]), null);
+ String[] constructorArgs = info.constructorArgs.toArray(new String[info.constructorArgs.size()]);
+ ObjectRecipe serviceRecipe = new ObjectRecipe(info.className, info.factoryMethod, constructorArgs, null);
serviceRecipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
serviceRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
serviceRecipe.setAllProperties(info.properties);
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java?rev=685490&r1=685489&r2=685490&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/AssemblerTool.java Wed Aug 13 02:20:31 2008
@@ -22,10 +22,8 @@
import org.apache.openejb.util.proxy.ProxyFactory;
import javax.transaction.TransactionManager;
-import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Properties;
-import java.util.List;
import java.util.Map;
public class AssemblerTool {
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=685490&r1=685489&r2=685490&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java Wed Aug 13 02:20:31 2008
@@ -310,13 +310,7 @@
}
for (Container declaration : openejb.getContainer()) {
- Class<? extends ContainerInfo> infoClass = getContainerInfoType(declaration.getType());
- if (infoClass == null) {
- throw new OpenEJBException(messages.format("unrecognizedContainerType", declaration.getType()));
- }
-
- ContainerInfo info = configureService(declaration, infoClass);
-
+ ContainerInfo info = createContainerInfo(declaration);
sys.containerSystem.containers.add(info);
}
@@ -386,6 +380,16 @@
return sys;
}
+ public ContainerInfo createContainerInfo(Container container) throws OpenEJBException {
+ Class<? extends ContainerInfo> infoClass = getContainerInfoType(container.getType());
+ if (infoClass == null) {
+ throw new OpenEJBException(messages.format("unrecognizedContainerType", container.getType()));
+ }
+
+ ContainerInfo info = configureService(container, infoClass);
+ return info;
+ }
+
private static boolean getBooleanOption(String name, boolean defaultValue) {
String flag = SystemInstance.get().getProperty(name, defaultValue + "");
return Boolean.parseBoolean(flag);
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java?rev=685490&r1=685489&r2=685490&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java Wed Aug 13 02:20:31 2008
@@ -16,15 +16,15 @@
*/
package org.apache.openejb.util;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.Binding;
-import javax.naming.NamingEnumeration;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.TreeMap;
-import java.util.Iterator;
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
/**
* @version $Rev$ $Date$
@@ -38,7 +38,7 @@
}
public static Map<String,Object> contextToMap(Context context) throws NamingException {
- Map<String, Object> map = new TreeMap<String, Object>();
+ Map<String, Object> map = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
contextToMap(context, "", map);
return map;
}
@@ -63,10 +63,21 @@
public static Map<String,Object> printContext(Context context, PrintStream out) throws NamingException {
Map<String, Object> map = contextToMap(context);
- for (Iterator<Map.Entry<String, Object>> iterator = map.entrySet().iterator(); iterator.hasNext();) {
- Map.Entry<String, Object> entry = iterator.next();
+ for (Entry<String, Object> entry : map.entrySet()) {
out.println(entry.getKey() + "=" + entry.getValue().getClass().getName());
}
return map;
}
+
+ public static Map<String,Object> printContextValues(Context context) throws NamingException {
+ return printContextValues(context, System.out);
+ }
+
+ public static Map<String,Object> printContextValues(Context context, PrintStream out) throws NamingException {
+ Map<String, Object> map = contextToMap(context);
+ for (Entry<String, Object> entry : map.entrySet()) {
+ out.println(entry.getKey() + "=" + entry.getValue());
+ }
+ return map;
+ }
}
Modified: openejb/trunk/openejb3/container/openejb-core/src/test/resources/org/apache/openejb/core/mdb/activemq.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/resources/org/apache/openejb/core/mdb/activemq.xml?rev=685490&r1=685489&r2=685490&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/resources/org/apache/openejb/core/mdb/activemq.xml (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/resources/org/apache/openejb/core/mdb/activemq.xml Wed Aug 13 02:20:31 2008
@@ -1,3 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Propchange: openejb/trunk/openejb3/container/openejb-spring/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Aug 13 02:20:31 2008
@@ -0,0 +1,10 @@
+*.iws
+*.ipr
+*.iml
+.classpath
+.project
+.settings
+*.log
+junit*.properties
+target
+bin
Added: openejb/trunk/openejb3/container/openejb-spring/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/pom.xml?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/pom.xml (added)
+++ openejb/trunk/openejb3/container/openejb-spring/pom.xml Wed Aug 13 02:20:31 2008
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+
+<!-- $Rev: 685052 $ $Date: 2008-08-11 23:31:13 -0700 (Mon, 11 Aug 2008) $ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>container</artifactId>
+ <groupId>org.apache.openejb</groupId>
+ <version>3.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>openejb-spring</artifactId>
+ <packaging>jar</packaging>
+ <name>OpenEJB :: Container :: Spring</name>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <filtering>true</filtering>
+ </testResource>
+ </testResources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-javaagent</artifactId>
+ <version>${version}</version>
+ <outputDirectory>${project.build.directory}</outputDirectory>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>pertest</forkMode>
+ <argLine>"-javaagent:${basedir}/target/openejb-javaagent-${version}.jar" -enableassertions</argLine>
+ <workingDirectory>${basedir}/target</workingDirectory>
+ <systemProperties>
+ <property>
+ <name>openejb.home</name>
+ <value>${basedir}/target/test-classes</value>
+ </property>
+ <property>
+ <name>log4j.configuration</name>
+ <value>file:///${basedir}/target/classes/embedded.logging.properties</value>
+ </property>
+ </systemProperties>
+ <excludes>
+ <exclude>**/TestHandler.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-core</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-itests-app</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-itests-beans</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-itests-client</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ <version>2.5.5</version>
+ </dependency>
+ </dependencies>
+ <profiles>
+ <profile>
+ <id>openejb.debug</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>pertest</forkMode>
+ <argLine>"-javaagent:${basedir}/target/openejb-javaagent-${version}.jar" -enableassertions
+ -agentlib:jdwp=transport=dt_socket,server=y,address=5005</argLine>
+ <workingDirectory>${basedir}/target</workingDirectory>
+ <systemProperties>
+ <property>
+ <name>openejb.home</name>
+ <value>${basedir}/target/test-classes</value>
+ </property>
+ <property>
+ <name>log4j.configuration</name>
+ <value>file:///${basedir}/target/classes/embedded.logging.properties</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
+
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/BmpContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/BmpContainer.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/BmpContainer.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/BmpContainer.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,83 @@
+/**
+ *
+ * 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.spring;
+
+import java.util.Properties;
+
+import org.springframework.beans.factory.BeanNameAware;
+import org.apache.openejb.config.sys.Container;
+import org.apache.openejb.config.BeanTypes;
+import org.apache.openejb.OpenEJBException;
+
+public class BmpContainer implements ContainerProvider, BeanNameAware {
+ private String id;
+ private String beanName;
+ private String provider;
+ private Integer poolSize;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setBeanName(String beanName) {
+ this.beanName = beanName;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ public Integer getPoolSize() {
+ return poolSize;
+ }
+
+ public void setPoolSize(Integer poolSize) {
+ this.poolSize = poolSize;
+ }
+
+ public Container getContainerDefinition() throws OpenEJBException {
+ Container container = new Container();
+ container.setCtype(BeanTypes.BMP_ENTITY);
+
+ if (id != null) {
+ container.setId(id);
+ } else if (beanName != null) {
+ container.setId(beanName);
+ } else {
+ throw new OpenEJBException("No id defined for BmpContainer");
+ }
+
+ if (provider != null) {
+ container.setProvider(provider);
+ }
+
+ Properties properties = container.getProperties();
+ if (poolSize != null) {
+ properties.put("PoolSize", poolSize);
+ }
+ return container;
+ }
+}
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/CmpContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/CmpContainer.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/CmpContainer.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/CmpContainer.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,83 @@
+/**
+ *
+ * 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.spring;
+
+import java.util.Properties;
+
+import org.springframework.beans.factory.BeanNameAware;
+import org.apache.openejb.config.sys.Container;
+import org.apache.openejb.config.BeanTypes;
+import org.apache.openejb.OpenEJBException;
+
+public class CmpContainer implements ContainerProvider, BeanNameAware {
+ private String id;
+ private String beanName;
+ private String provider;
+ private String cmpEngineFactory;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setBeanName(String beanName) {
+ this.beanName = beanName;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ public String getCmpEngineFactory() {
+ return cmpEngineFactory;
+ }
+
+ public void setCmpEngineFactory(String cmpEngineFactory) {
+ this.cmpEngineFactory = cmpEngineFactory;
+ }
+
+ public Container getContainerDefinition() throws OpenEJBException {
+ Container container = new Container();
+ container.setCtype(BeanTypes.CMP_ENTITY);
+
+ if (id != null) {
+ container.setId(id);
+ } else if (beanName != null) {
+ container.setId(beanName);
+ } else {
+ throw new OpenEJBException("No id defined for CmpContainer");
+ }
+
+ if (provider != null) {
+ container.setProvider(provider);
+ }
+
+ Properties properties = container.getProperties();
+ if (cmpEngineFactory != null) {
+ properties.put("CmpEngineFactory", cmpEngineFactory);
+ }
+ return container;
+ }
+}
\ No newline at end of file
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ContainerProvider.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ContainerProvider.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ContainerProvider.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ContainerProvider.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,27 @@
+/**
+ *
+ * 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.spring;
+
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.config.sys.Container;
+
+public interface ContainerProvider {
+ String getId();
+
+ Container getContainerDefinition() throws OpenEJBException;
+}
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/Exported.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/Exported.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/Exported.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/Exported.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,5 @@
+package org.apache.openejb.spring;
+
+@java.lang.annotation.Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
+public @interface Exported {
+}
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/MdbContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/MdbContainer.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/MdbContainer.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/MdbContainer.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,119 @@
+/**
+ *
+ * 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.spring;
+
+import java.util.Properties;
+
+import org.springframework.beans.factory.BeanNameAware;
+import org.apache.openejb.config.sys.Container;
+import org.apache.openejb.config.BeanTypes;
+import org.apache.openejb.OpenEJBException;
+
+public class MdbContainer implements ContainerProvider, BeanNameAware {
+ private String id;
+ private String beanName;
+ private String provider;
+ private String resourceAdapter;
+ private String messageListenerInterface;
+ private String activationSpecClass;
+ private Integer instanceLimit;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setBeanName(String beanName) {
+ this.beanName = beanName;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ public String getResourceAdapter() {
+ return resourceAdapter;
+ }
+
+ public void setResourceAdapter(String resourceAdapter) {
+ this.resourceAdapter = resourceAdapter;
+ }
+
+ public String getMessageListenerInterface() {
+ return messageListenerInterface;
+ }
+
+ public void setMessageListenerInterface(String messageListenerInterface) {
+ this.messageListenerInterface = messageListenerInterface;
+ }
+
+ public String getActivationSpecClass() {
+ return activationSpecClass;
+ }
+
+ public void setActivationSpecClass(String activationSpecClass) {
+ this.activationSpecClass = activationSpecClass;
+ }
+
+ public Integer getInstanceLimit() {
+ return instanceLimit;
+ }
+
+ public void setInstanceLimit(Integer instanceLimit) {
+ this.instanceLimit = instanceLimit;
+ }
+
+ public Container getContainerDefinition() throws OpenEJBException {
+ Container container = new Container();
+ container.setCtype(BeanTypes.MESSAGE);
+
+ if (id != null) {
+ container.setId(id);
+ } else if (beanName != null) {
+ container.setId(beanName);
+ } else {
+ throw new OpenEJBException("No id defined for MdbContainer");
+ }
+
+ if (provider != null) {
+ container.setProvider(provider);
+ }
+
+ Properties properties = container.getProperties();
+ if (resourceAdapter != null) {
+ properties.put("ResourceAdapter", resourceAdapter);
+ }
+ if (messageListenerInterface != null) {
+ properties.put("MessageListenerInterface", messageListenerInterface);
+ }
+ if (activationSpecClass != null) {
+ properties.put("ActivationSpecClass", activationSpecClass);
+ }
+ if (instanceLimit != null) {
+ properties.put("InstanceLimit", instanceLimit);
+ }
+ return container;
+ }
+}
\ No newline at end of file
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/OpenEJB.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/OpenEJB.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/OpenEJB.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/OpenEJB.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,350 @@
+/**
+ *
+ * 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.spring;
+
+import java.util.Date;
+import java.util.Properties;
+import java.util.Collection;
+import java.util.ArrayList;
+import javax.annotation.PostConstruct;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.transaction.TransactionManager;
+
+import org.apache.openejb.Container;
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.core.ServerFederation;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ApplicationServer;
+import org.apache.openejb.spi.Assembler;
+import org.apache.openejb.spi.ContainerSystem;
+import org.apache.openejb.spi.SecurityService;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.Logger;
+import org.apache.openejb.util.Messages;
+import org.apache.openejb.util.OpenEjbVersion;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+@Exported
+public class OpenEJB implements ApplicationContextAware{
+ private static Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP, "org.apache.openejb.util.resources");
+ private static Messages messages = new Messages("org.apache.openejb.util.resources");
+
+ private final Properties properties = new Properties();
+
+ /**
+ * The assembler for Spring embedded.
+ */
+ private SpringAssembler assembler;
+
+ /**
+ * The TransactionManager to be used by the OpenEJB server, or null for the
+ * default TransactionManager.
+ */
+ private TransactionManager transactionManager;
+
+ /**
+ * The SecurityService to be used by the OpenEJB server, or null for the
+ * default SecurityService.
+ */
+ private SecurityService securityService;
+
+ /**
+ * The ApplicationServer to be used by the OpenEJB server, or null for the
+ * default ApplicationServer.
+ */
+ private ApplicationServer applicationServer;
+
+ private final Collection<ContainerProvider> containers = new ArrayList<ContainerProvider>();
+
+ private final Collection<Resource> resources = new ArrayList<Resource>();
+
+ private boolean importContext = true;
+
+ private Throwable initialized;
+ private ApplicationContext applicationContext;
+
+ public ApplicationContext getApplicationContext() {
+ return applicationContext;
+ }
+
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ this.applicationContext = applicationContext;
+ }
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Properties properties) {
+ this.properties.clear();
+ this.properties.putAll(properties);
+ }
+
+ public TransactionManager getTransactionManager() {
+ return transactionManager;
+ }
+
+ public void setTransactionManager(TransactionManager transactionManager) {
+ this.transactionManager = transactionManager;
+ }
+
+ public SecurityService getSecurityService() {
+ return securityService;
+ }
+
+ public void setSecurityService(SecurityService securityService) {
+ this.securityService = securityService;
+ }
+
+ public ApplicationServer getApplicationServer() {
+ return applicationServer;
+ }
+
+ public void setApplicationServer(ApplicationServer applicationServer) {
+ this.applicationServer = applicationServer;
+ }
+
+ public Collection<ContainerProvider> getContainers() {
+ return containers;
+ }
+
+ public void setContainers(Collection<ContainerProvider> containers) {
+ this.containers.clear();
+ this.containers.addAll(containers);
+ }
+
+ public Collection<Resource> getResources() {
+ return resources;
+ }
+
+ public void setResources(Collection<Resource> resources) {
+ this.resources.clear();
+ this.resources.addAll(resources);
+ }
+
+ public boolean isImportContext() {
+ return importContext;
+ }
+
+ public void setImportContext(boolean importContext) {
+ this.importContext = importContext;
+ }
+
+ public Context getInitialContext() throws NamingException {
+ if (!org.apache.openejb.OpenEJB.isInitialized()) {
+ throw new IllegalStateException("Not started");
+ }
+
+ Context context = new org.apache.openejb.core.ivm.naming.InitContextFactory().getInitialContext(properties);
+ return context;
+ }
+
+ public boolean isStarted() {
+ return initialized != null || SystemInstance.get().getComponent(ContainerSystem.class) != null;
+ }
+
+ @PostConstruct
+ public void start() throws OpenEJBException {
+ //
+ // Already started?
+ //
+ if (isStarted()) {
+ if (initialized != null){
+ String msg = messages.message("startup.alreadyInitialized");
+ logger.error(msg, initialized);
+ throw new OpenEJBException(msg, initialized);
+ } else {
+ String msg = messages.message("startup.alreadyInitialized");
+ logger.error(msg);
+ throw new OpenEJBException(msg);
+ }
+ }
+ initialized = new Exception("Initialized at " + new Date()).fillInStackTrace();
+
+ //
+ // System Instance
+ //
+ try {
+ SystemInstance.init(properties);
+ } catch (Exception e) {
+ throw new OpenEJBException(e);
+ }
+ SystemInstance system = SystemInstance.get();
+
+ // do not deploy applications in claspath
+ system.setProperty("openejb.deployments.classpath", "false");
+
+ // we are in embedded mode
+ system.setProperty("openejb.embedded", "true");
+
+
+ //
+ // Startup message
+ //
+ OpenEjbVersion versionInfo = OpenEjbVersion.get();
+
+ if (properties.getProperty("openejb.nobanner") == null) {
+ System.out.println("Apache OpenEJB " + versionInfo.getVersion() + " build: " + versionInfo.getDate() + "-" + versionInfo.getTime());
+ System.out.println("" + versionInfo.getUrl());
+ }
+
+ Logger logger2 = Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources");
+ logger2.info("startup.banner", versionInfo.getUrl(), new Date(), versionInfo.getCopyright(),
+ versionInfo.getVersion(), versionInfo.getDate(), versionInfo.getTime());
+
+ logger.info("openejb.home = " + SystemInstance.get().getHome().getDirectory().getAbsolutePath());
+ logger.info("openejb.base = " + SystemInstance.get().getBase().getDirectory().getAbsolutePath());
+
+ Properties props = new Properties(SystemInstance.get().getProperties());
+
+ if (properties.isEmpty()) {
+ logger.debug("startup.noInitializationProperties");
+ } else {
+ props.putAll(properties);
+ }
+
+ //
+ // Application Server
+ //
+ if (applicationServer == null) {
+ applicationServer = new ServerFederation();
+ }
+ system.setComponent(ApplicationServer.class, applicationServer);
+
+ //
+ // Assembler
+ //
+ assembler = new SpringAssembler(this);
+ SystemInstance.get().setComponent(Assembler.class, assembler);
+
+ try {
+ assembler.init(props);
+ } catch (OpenEJBException oe) {
+ logger.fatal("startup.assemblerFailedToInitialize", oe);
+ throw oe;
+ } catch (Throwable t) {
+ String msg = messages.message("startup.assemblerEncounteredUnexpectedError");
+ logger.fatal(msg, t);
+ throw new OpenEJBException(msg, t);
+ }
+
+ try {
+ assembler.build();
+ } catch (OpenEJBException oe) {
+ logger.fatal("startup.assemblerFailedToBuild", oe);
+ throw oe;
+ } catch (Throwable t) {
+ String msg = messages.message("startup.assemblerEncounterUnexpectedBuildError");
+ logger.fatal(msg, t);
+ throw new OpenEJBException(msg, t);
+ }
+
+ //
+ // Container System
+ //
+ ContainerSystem containerSystem = assembler.getContainerSystem();
+ if (containerSystem == null) {
+ String msg = messages.message("startup.assemblerReturnedNullContainer");
+ logger.fatal(msg);
+ throw new OpenEJBException(msg);
+ }
+ system.setComponent(ContainerSystem.class, containerSystem);
+ printContainerSystem(containerSystem);
+
+
+ //
+ // Done
+ //
+ logger.debug("startup.ready");
+ }
+
+ private void printContainerSystem(ContainerSystem containerSystem) {
+ if (logger.isDebugEnabled()) {
+ //
+ // Log Containers
+ //
+ logger.debug("startup.debugContainers", containerSystem.containers().length);
+ if (containerSystem.containers().length > 0) {
+ logger.debug("startup.debugContainersType");
+ for (Container container : containerSystem.containers()) {
+ String entry = " ";
+ switch (container.getContainerType()) {
+ case BMP_ENTITY:
+ entry += "BMP ENTITY ";
+ break;
+ case CMP_ENTITY:
+ entry += "CMP ENTITY ";
+ break;
+ case STATEFUL:
+ entry += "STATEFUL ";
+ break;
+ case STATELESS:
+ entry += "STATELESS ";
+ break;
+ case MESSAGE_DRIVEN:
+ entry += "MESSAGE ";
+ break;
+ }
+ entry += container.getContainerID();
+ logger.debug("startup.debugEntry", entry);
+ }
+ }
+
+ //
+ // Log Deployments
+ //
+ logger.debug("startup.debugDeployments", containerSystem.deployments().length);
+ if (containerSystem.deployments().length > 0) {
+ logger.debug("startup.debugDeploymentsType");
+ for (DeploymentInfo deployment : containerSystem.deployments()) {
+ String entry = " ";
+ switch (deployment.getComponentType()) {
+ case BMP_ENTITY:
+ entry += "BMP_ENTITY ";
+ break;
+ case CMP_ENTITY:
+ entry += "CMP_ENTITY ";
+ break;
+ case STATEFUL:
+ entry += "STATEFUL ";
+ break;
+ case STATELESS:
+ entry += "STATELESS ";
+ break;
+ case SINGLETON:
+ entry += "SINGLETON ";
+ break;
+ case MESSAGE_DRIVEN:
+ entry += "MESSAGE ";
+ break;
+ }
+ entry += deployment.getDeploymentID();
+ logger.debug("startup.debugEntry", entry);
+ }
+ }
+ }
+ }
+
+ public Throwable getInitialized() {
+ return initialized;
+ }
+}
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/OpenEJBDataSource.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/OpenEJBDataSource.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/OpenEJBDataSource.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/OpenEJBDataSource.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,56 @@
+/**
+ *
+ * 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.spring;
+
+import javax.naming.Context;
+import javax.sql.DataSource;
+
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.springframework.beans.factory.FactoryBean;
+
+@Exported
+public class OpenEJBDataSource implements FactoryBean {
+ private String resourceId;
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public void setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ }
+
+ public Object getObject() throws Exception {
+ ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+ if (containerSystem == null) return null;
+ Context initialContext = containerSystem.getJNDIContext();
+ if (initialContext == null) return null;
+
+ DataSource dataSource = (DataSource) initialContext.lookup("openejb/Resource/" + resourceId);
+ return dataSource;
+ }
+
+ public Class getObjectType() {
+ return DataSource.class;
+ }
+
+ public boolean isSingleton() {
+ return false;
+ }
+}
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/Resource.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/Resource.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/Resource.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/Resource.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,92 @@
+/**
+ *
+ * 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.spring;
+
+import java.util.Properties;
+
+import org.apache.openejb.OpenEJBException;
+import org.springframework.beans.factory.BeanNameAware;
+
+public class Resource implements BeanNameAware {
+ private String id;
+ private String beanName;
+ private String provider;
+ private String type;
+ private Properties properties;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setBeanName(String beanName) {
+ this.beanName = beanName;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Properties properties) {
+ this.properties = properties;
+ }
+
+ public org.apache.openejb.config.sys.Resource getResourceDefinition() throws OpenEJBException {
+ org.apache.openejb.config.sys.Resource resource = new org.apache.openejb.config.sys.Resource();
+
+ if (id != null) {
+ resource.setId(id);
+ } else if (beanName != null) {
+ resource.setId(beanName);
+ } else {
+ throw new OpenEJBException("No id defined for Resource");
+ }
+
+ if (provider != null) {
+ resource.setProvider(provider);
+ }
+
+ if (type != null) {
+ resource.setType(type);
+ }
+
+ if (properties != null) {
+ resource.getProperties().putAll(properties);
+ }
+ return resource;
+ }
+}
\ No newline at end of file
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SingletonContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SingletonContainer.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SingletonContainer.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SingletonContainer.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,68 @@
+/**
+ *
+ * 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.spring;
+
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.config.BeanTypes;
+import org.apache.openejb.config.sys.Container;
+import org.springframework.beans.factory.BeanNameAware;
+
+public class SingletonContainer implements ContainerProvider, BeanNameAware {
+ private String id;
+ private String beanName;
+ private String provider;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setBeanName(String beanName) {
+ this.beanName = beanName;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ public Container getContainerDefinition() throws OpenEJBException {
+ Container container = new Container();
+ container.setCtype(BeanTypes.SINGLETON);
+
+ if (id != null) {
+ container.setId(id);
+ } else if (beanName != null) {
+ container.setId(beanName);
+ } else {
+ throw new OpenEJBException("No id defined for SingletonContainer");
+ }
+
+ if (provider != null) {
+ container.setProvider(provider);
+ }
+
+ return container;
+ }
+}
\ No newline at end of file
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SpringAssembler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SpringAssembler.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SpringAssembler.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SpringAssembler.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,170 @@
+/**
+ *
+ * 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.spring;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import javax.transaction.TransactionManager;
+
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.ContainerInfo;
+import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
+import org.apache.openejb.assembler.classic.ResourceInfo;
+import org.apache.openejb.assembler.classic.SecurityServiceInfo;
+import org.apache.openejb.assembler.classic.ServiceInfo;
+import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.assembler.dynamic.PassthroughFactory;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.spi.SecurityService;
+import org.springframework.context.ApplicationContext;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+
+public class SpringAssembler extends Assembler {
+ private final OpenEJB openEJB;
+ private final Set<String> importedResourceIds = new TreeSet<String>();
+
+ public SpringAssembler(OpenEJB openEJB) {
+ this.openEJB = openEJB;
+ }
+
+ protected OpenEjbConfiguration getOpenEjbConfiguration() throws OpenEJBException {
+ OpenEjbConfiguration configuration = super.getOpenEjbConfiguration();
+ ApplicationContext applicationContext = openEJB.getApplicationContext();
+
+ // todo this is cheating
+ ConfigurationFactory configurationFactory = (ConfigurationFactory) this.configFactory;
+
+ //
+ // Transaction Manager
+ //
+ TransactionManager transactionManager = openEJB.getTransactionManager();
+ if (transactionManager == null) {
+ transactionManager = getBeanForType(applicationContext, TransactionManager.class);
+ }
+ if (transactionManager != null) {
+ TransactionServiceInfo info = initPassthrough(new TransactionServiceInfo(), "TransactionManager", transactionManager);
+ configuration.facilities.transactionService = info;
+ }
+
+ //
+ // Security Service
+ //
+ SecurityService securityService = openEJB.getSecurityService();
+ if (securityService == null) {
+ securityService = getBeanForType(applicationContext, SecurityService.class);
+ }
+ if (securityService != null) {
+ SecurityServiceInfo info = initPassthrough(new SecurityServiceInfo(), "SecurityService", securityService);
+ configuration.facilities.securityService = info;
+ }
+
+ //
+ // Resources
+ //
+ for (Resource resource : openEJB.getResources()) {
+ ResourceInfo info = configurationFactory.configureService(resource.getResourceDefinition(), ResourceInfo.class);
+ importedResourceIds.add(info.id);
+ configuration.facilities.resources.add(info);
+ }
+ if (openEJB.isImportContext() && applicationContext != null) {
+ for (String beanName : applicationContext.getBeanDefinitionNames()) {
+ if (!importedResourceIds.contains(beanName)) {
+ Class beanType = applicationContext.getType(beanName);
+ Class factoryType = applicationContext.getType("&" + beanName);
+ if (isImportableType(beanType, factoryType)) {
+ SpringReference factory = new SpringReference(applicationContext, beanName, beanType);
+
+ ResourceInfo info = initPassthrough(beanName, new ResourceInfo(), "Resource", factory);
+ info.types = getTypes(beanType);
+ configuration.facilities.resources.add(info);
+ }
+ }
+ }
+ }
+
+ //
+ // Containers
+ //
+ for (ContainerProvider containerProvider: openEJB.getContainers()) {
+ ContainerInfo info = configurationFactory.createContainerInfo(containerProvider.getContainerDefinition());
+ configuration.containerSystem.containers.add(info);
+ }
+
+ return configuration;
+ }
+
+ private <T> T getBeanForType(ApplicationContext applicationContext, Class<T> type) throws OpenEJBException {
+ String[] names = applicationContext.getBeanNamesForType(type);
+ if (names.length == 0) {
+ return null;
+ }
+ if (names.length > 1) {
+ throw new OpenEJBException("Multiple " + type.getSimpleName() + " beans in application context: " + Arrays.toString(names));
+ }
+
+ String name = names[0];
+ importedResourceIds.add(name);
+ return (T) applicationContext.getBean(name);
+ }
+
+ protected boolean isImportableType(Class type, Class factoryType) {
+ return !type.isAnnotationPresent(Exported.class) &&
+ !BeanPostProcessor.class.isAssignableFrom(type) &&
+ !BeanFactoryPostProcessor.class.isAssignableFrom(type) &&
+ (factoryType == null || !factoryType.isAnnotationPresent(Exported.class));
+ }
+
+ private <T extends ServiceInfo> T initPassthrough(T info, String serviceType, Object instance) {
+ return initPassthrough("Spring SuppliedÊ" + serviceType, info, serviceType, instance);
+ }
+
+ private <T extends ServiceInfo> T initPassthrough(String id, T info, String serviceType, Object instance) {
+ info.id = id;
+ info.service = serviceType;
+ info.types = getTypes(instance);
+ PassthroughFactory.add(info, instance);
+ return info;
+ }
+
+ private List<String> getTypes(Object instance) {
+ LinkedHashSet<String> types = new LinkedHashSet<String>();
+ Class clazz = instance.getClass();
+ addTypes(clazz, types);
+ return new ArrayList<String>(types);
+ }
+
+ private void addTypes(Class clazz, LinkedHashSet<String> types) {
+ if (clazz == null || Object.class.equals(clazz) || Serializable.class.equals(clazz)) {
+ return;
+ }
+ if (types.add(clazz.getName())) {
+ addTypes(clazz.getSuperclass(), types);
+ for (Class intf : clazz.getInterfaces()) {
+ addTypes(intf, types);
+ }
+ }
+ }
+
+}
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SpringReference.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SpringReference.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SpringReference.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/SpringReference.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,50 @@
+/**
+ *
+ * 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.spring;
+
+import org.apache.openejb.core.ivm.naming.Reference;
+import org.springframework.context.ApplicationContext;
+
+public class SpringReference extends Reference {
+ private final ApplicationContext applicationContext;
+ private final String beanName;
+ private final Class beanType;
+
+ public SpringReference(ApplicationContext applicationContext, String beanName, Class beanType) {
+ this.applicationContext = applicationContext;
+ this.beanName = beanName;
+ this.beanType = beanType;
+ }
+
+ public ApplicationContext getApplicationContext() {
+ return applicationContext;
+ }
+
+ public String getBeanName() {
+ return beanName;
+ }
+
+ public Class getBeanType() {
+ return beanType;
+ }
+
+ public Object getObject() {
+ Object bean = applicationContext.getBean(beanName);
+ return bean;
+ }
+}
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/StatefulContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/StatefulContainer.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/StatefulContainer.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/StatefulContainer.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,119 @@
+/**
+ *
+ * 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.spring;
+
+import java.util.Properties;
+
+import org.springframework.beans.factory.BeanNameAware;
+import org.apache.openejb.config.sys.Container;
+import org.apache.openejb.config.BeanTypes;
+import org.apache.openejb.OpenEJBException;
+
+public class StatefulContainer implements ContainerProvider, BeanNameAware {
+ private String id;
+ private String beanName;
+ private String provider;
+ private String passivator;
+ private Integer timeOut;
+ private Integer poolSize;
+ private Integer bulkPassivate;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setBeanName(String beanName) {
+ this.beanName = beanName;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ public String getPassivator() {
+ return passivator;
+ }
+
+ public void setPassivator(String passivator) {
+ this.passivator = passivator;
+ }
+
+ public Integer getTimeOut() {
+ return timeOut;
+ }
+
+ public void setTimeOut(Integer timeOut) {
+ this.timeOut = timeOut;
+ }
+
+ public Integer getPoolSize() {
+ return poolSize;
+ }
+
+ public void setPoolSize(Integer poolSize) {
+ this.poolSize = poolSize;
+ }
+
+ public Integer getBulkPassivate() {
+ return bulkPassivate;
+ }
+
+ public void setBulkPassivate(Integer bulkPassivate) {
+ this.bulkPassivate = bulkPassivate;
+ }
+
+ public Container getContainerDefinition() throws OpenEJBException {
+ Container container = new Container();
+ container.setCtype(BeanTypes.STATEFUL);
+
+ if (id != null) {
+ container.setId(id);
+ } else if (beanName != null) {
+ container.setId(beanName);
+ } else {
+ throw new OpenEJBException("No id defined for StatefulContainer");
+ }
+
+ if (provider != null) {
+ container.setProvider(provider);
+ }
+
+ Properties properties = container.getProperties();
+ if (passivator != null) {
+ properties.put("Passivator", passivator);
+ }
+ if (timeOut != null) {
+ properties.put("TimeOut", timeOut);
+ }
+ if (poolSize != null) {
+ properties.put("PoolSize", poolSize);
+ }
+ if (bulkPassivate != null) {
+ properties.put("BulkPassivate", bulkPassivate);
+ }
+ return container;
+ }
+}
\ No newline at end of file
Added: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/StatelessContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/StatelessContainer.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/StatelessContainer.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/StatelessContainer.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,119 @@
+/**
+ *
+ * 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.spring;
+
+import java.util.Properties;
+
+import org.springframework.beans.factory.BeanNameAware;
+import org.apache.openejb.config.sys.Container;
+import org.apache.openejb.config.BeanTypes;
+import org.apache.openejb.OpenEJBException;
+
+public class StatelessContainer implements ContainerProvider, BeanNameAware {
+ private String id;
+ private String beanName;
+ private String provider;
+ private String passivator;
+ private Integer timeOut;
+ private Integer poolSize;
+ private Boolean strictPooling;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setBeanName(String beanName) {
+ this.beanName = beanName;
+ }
+
+ public String getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String provider) {
+ this.provider = provider;
+ }
+
+ public String getPassivator() {
+ return passivator;
+ }
+
+ public void setPassivator(String passivator) {
+ this.passivator = passivator;
+ }
+
+ public Integer getTimeOut() {
+ return timeOut;
+ }
+
+ public void setTimeOut(Integer timeOut) {
+ this.timeOut = timeOut;
+ }
+
+ public Integer getPoolSize() {
+ return poolSize;
+ }
+
+ public void setPoolSize(Integer poolSize) {
+ this.poolSize = poolSize;
+ }
+
+ public Boolean getStrictPooling() {
+ return strictPooling;
+ }
+
+ public void setStrictPooling(Boolean strictPooling) {
+ this.strictPooling = strictPooling;
+ }
+
+ public Container getContainerDefinition() throws OpenEJBException {
+ Container container = new Container();
+ container.setCtype(BeanTypes.STATELESS);
+
+ if (id != null) {
+ container.setId(id);
+ } else if (beanName != null) {
+ container.setId(beanName);
+ } else {
+ throw new OpenEJBException("No id defined for StatelessContainer");
+ }
+
+ if (provider != null) {
+ container.setProvider(provider);
+ }
+
+ Properties properties = container.getProperties();
+ if (passivator != null) {
+ properties.put("Passivator", passivator);
+ }
+ if (timeOut != null) {
+ properties.put("TimeOut", timeOut);
+ }
+ if (poolSize != null) {
+ properties.put("PoolSize", poolSize);
+ }
+ if (strictPooling != null) {
+ properties.put("StrictPooling", strictPooling);
+ }
+ return container;
+ }
+}
\ No newline at end of file
Added: openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/MockSecurityService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/MockSecurityService.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/MockSecurityService.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/MockSecurityService.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,23 @@
+/**
+ *
+ * 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.spring;
+
+import org.apache.openejb.ri.sp.PseudoSecurityService;
+
+public class MockSecurityService extends PseudoSecurityService {
+}
Added: openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/MockTransactionManager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/MockTransactionManager.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/MockTransactionManager.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/MockTransactionManager.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,27 @@
+/**
+ *
+ * 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.spring;
+
+import javax.transaction.xa.XAException;
+
+import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
+
+public class MockTransactionManager extends GeronimoTransactionManager {
+ public MockTransactionManager() throws XAException {
+ }
+}
Added: openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/SpringTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/SpringTest.java?rev=685490&view=auto
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/SpringTest.java (added)
+++ openejb/trunk/openejb3/container/openejb-spring/src/test/java/org/apache/openejb/spring/SpringTest.java Wed Aug 13 02:20:31 2008
@@ -0,0 +1,116 @@
+/**
+ *
+ * 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.spring;
+
+import javax.naming.Context;
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+
+import junit.framework.TestCase;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.openejb.Container;
+import org.apache.openejb.util.Debug;
+import org.apache.openejb.core.entity.EntityContainer;
+import org.apache.openejb.core.cmp.*;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.apache.openejb.spi.SecurityService;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringTest extends TestCase {
+ public void test() throws Exception {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/apache/openejb/spring/spring.xml");
+ assertTrue(context.getBeanDefinitionCount() > 0);
+
+ //
+ // OpenEJB
+ //
+ OpenEJB openEJB = (OpenEJB) context.getBean("OpenEJB");
+ assertNotNull("openEJB is null", openEJB);
+ assertTrue(openEJB.isStarted());
+ assertTrue(org.apache.openejb.OpenEJB.isInitialized());
+
+ //
+ // ContainerSystem
+ //
+ ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+ assertNotNull("containerSystem is null", containerSystem);
+ Context initialContext = containerSystem.getJNDIContext();
+ assertNotNull(initialContext);
+
+ //
+ // TransactionManager
+ //
+ Object tm = context.getBean("tm");
+ TransactionManager springTM = (TransactionManager) tm;
+ assertNotNull("springTM is null", springTM);
+ assertTrue("springTM should be an instance of MockTransactionManager", springTM instanceof MockTransactionManager);
+
+ TransactionManager systemTM = SystemInstance.get().getComponent(TransactionManager.class);
+ assertNotNull("systemTM is null", systemTM);
+ assertSame(springTM, systemTM);
+
+ assertSame(springTM, initialContext.lookup("openejb/TransactionManager"));
+
+ //
+ // SecurityService
+ //
+ SecurityService springSecurityService = (SecurityService) context.getBean("sec");
+ assertNotNull("springSecurityService is null", springSecurityService);
+ assertTrue("springSecurityService should be an instance of MockSecurityService", springSecurityService instanceof MockSecurityService);
+
+ SecurityService systemSecurityService = SystemInstance.get().getComponent(SecurityService.class);
+ assertNotNull("systemSecurityService is null", systemSecurityService);
+ assertSame(springSecurityService, systemSecurityService);
+
+ assertSame(springSecurityService, initialContext.lookup("openejb/SecurityService"));
+
+ //
+ // DataSource
+ //
+ DataSource springDataSource = (DataSource) context.getBean("ds");
+ assertNotNull("springDataSource is null", springDataSource);
+ assertTrue("springDataSource should be an instance of BasicDataSource", springDataSource instanceof BasicDataSource);
+
+ DataSource jndiDataSource = (DataSource) initialContext.lookup("openejb/Resource/ds");
+ assertSame(springDataSource, jndiDataSource);
+
+ DataSource exportedDS = (DataSource) context.getBean("openejbDS");
+ assertSame(springDataSource, exportedDS);
+
+ //
+ // Container
+ //
+ Container singletonContainer = containerSystem.getContainer("Spring Defined SingletonContainer");
+ assertTrue("singletonContainer should be an instance of SingletonContainer", singletonContainer instanceof org.apache.openejb.core.singleton.SingletonContainer);
+ Container statelessContainer = containerSystem.getContainer("Spring Defined StatelessContainer");
+ assertTrue("statelessContainer should be an instance of StatelessContainer", statelessContainer instanceof org.apache.openejb.core.stateless.StatelessContainer);
+ Container statefulContainer = containerSystem.getContainer("Spring Defined StatefulContainer");
+ assertTrue("statefulContainer should be an instance of StatefulContainer", statefulContainer instanceof org.apache.openejb.core.stateful.StatefulContainer);
+ Container mdbContainer = containerSystem.getContainer("Spring Defined MdbContainer");
+ assertTrue("mdbContainer should be an instance of MdbContainer", mdbContainer instanceof org.apache.openejb.core.mdb.MdbContainer);
+ Container bmpContainer = containerSystem.getContainer("Spring Defined BmpContainer");
+ assertTrue("bmpContainer should be an instance of BmpContainer", bmpContainer instanceof EntityContainer);
+ Container cmpContainer = containerSystem.getContainer("Spring Defined CmpContainer");
+ assertTrue("cmpContainer should be an instance of CmpContainer", cmpContainer instanceof org.apache.openejb.core.cmp.CmpContainer);
+
+ System.out.println();
+ System.out.println();
+ Debug.printContext(initialContext);
+ }
+}