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 2006/12/07 00:27:45 UTC
svn commit: r483291 - in /incubator/openejb/trunk/openejb3/examples: ./
calculator-stateless-pojo/ calculator-stateless-pojo/src/
calculator-stateless-pojo/src/main/ calculator-stateless-pojo/src/main/java/
calculator-stateless-pojo/src/main/java/org/ ...
Author: dblevins
Date: Wed Dec 6 15:27:41 2006
New Revision: 483291
URL: http://svn.apache.org/viewvc?view=rev&rev=483291
Log:
First Patch from Filippo Diotalevi OPENEJB-346: Example: Minimal Statetless Bean via @Stateless and OPENEJB-347: Example: Minimal Stateful Bean via @Stateful
Thanks Filippo!
Added:
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/pom.xml
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorImpl.java
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorLocal.java
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorRemote.java
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/calculator/
incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/calculator/CalculatorTest.java
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/pom.xml
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterImpl.java
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterLocal.java
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterRemote.java
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/test/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/test/java/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/test/java/org/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/test/java/org/apache/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/test/java/org/apache/openejb/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/test/java/org/apache/openejb/examples/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/test/java/org/apache/openejb/examples/counter/
incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/test/java/org/apache/openejb/examples/counter/CounterImplTest.java
Modified:
incubator/openejb/trunk/openejb3/examples/pom.xml
Added: incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/pom.xml?view=auto&rev=483291
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/pom.xml (added)
+++ incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/pom.xml Wed Dec 6 15:27:41 2006
@@ -0,0 +1,91 @@
+<?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.
+-->
+<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">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>simple-calculator-stateless</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>OpenEJB :: Examples :: Calculator Stateless Pojo</name>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <id>codehaus-m2-snapshot</id>
+ <name>Codehaus Snapshot Repository</name>
+ <url>http://snapshots.repository.codehaus.org</url>
+ </repository>
+ <repository>
+ <id>apache-m2-snapshot</id>
+ <name>Apache Snapshot Repository</name>
+ <url>http://people.apache.org/repo/m2-snapshot-repository/</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-ejb_3.0_spec</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!--
+ Nice thing about maven2 is it has test-only dependencies.
+ This guarantees that non of your runtime code is dependent
+ on any OpenEJB classes.
+
+ For those of you who want to know the minimum steps required
+ to add OpenEJB for testing to an existing maven 2 build, you
+ simply add this dependency below and in your test code create
+ your InitialContext like such:
+
+ Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+
+ // Tells OpenEJB to look for META-INF/ejb-jar.xml files in the classpath
+ properties.setProperty("openejb.deployments.classpath", "true");
+
+ initialContext = new InitialContext(properties);
+
+ -->
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-core</artifactId>
+ <version>3.0-incubating-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorImpl.java?view=auto&rev=483291
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorImpl.java (added)
+++ incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorImpl.java Wed Dec 6 15:27:41 2006
@@ -0,0 +1,40 @@
+/**
+ * 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.examples.calculator;
+
+import javax.ejb.Stateless;
+
+/**
+ * This is an EJB 3 style pojo stateless session bean
+ * Every stateless session bean implementation must be annotated
+ * using the annotation @Stateless
+ * This EJB has 2 business interfaces: CalculatorRemote, a remote business
+ * interface, and CalculatorLocal, a local business interface
+ *
+ */
+@Stateless
+public class CalculatorImpl implements CalculatorRemote, CalculatorLocal {
+
+ public int sum(int add1, int add2) {
+ return add1+add2;
+ }
+
+ public int multiply(int mul1, int mul2) {
+ return mul1*mul2;
+ }
+
+}
Added: incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorLocal.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorLocal.java?view=auto&rev=483291
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorLocal.java (added)
+++ incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorLocal.java Wed Dec 6 15:27:41 2006
@@ -0,0 +1,30 @@
+/**
+ * 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.examples.calculator;
+
+/**
+ * This is an EJB 3 local business interface
+ * A local business interface may be annotated with the @Local
+ * annotation, but it's optional. A business interface which is
+ * not annotated with @Local or @Remote is assumed to be Local
+ */
+public interface CalculatorLocal {
+
+ public int sum(int add1, int add2);
+
+ public int multiply(int mul1, int mul2);
+}
Added: incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorRemote.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorRemote.java?view=auto&rev=483291
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorRemote.java (added)
+++ incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorRemote.java Wed Dec 6 15:27:41 2006
@@ -0,0 +1,33 @@
+/**
+ * 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.examples.calculator;
+
+import javax.ejb.Remote;
+
+/**
+ * This is an EJB 3 remote business interface
+ * A remote business interface must be annotated with the @Remote
+ * annotation
+ */
+@Remote
+public interface CalculatorRemote {
+
+ public int sum(int add1, int add2);
+
+ public int multiply(int mul1, int mul2);
+
+}
Added: incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/calculator/CalculatorTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/calculator/CalculatorTest.java?view=auto&rev=483291
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/calculator/CalculatorTest.java (added)
+++ incubator/openejb/trunk/openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/calculator/CalculatorTest.java Wed Dec 6 15:27:41 2006
@@ -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.examples.calculator;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+public class CalculatorTest extends TestCase {
+
+ private InitialContext initialContext;
+
+ protected void setUp() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+ properties.setProperty("openejb.deployments.classpath.include", ".*calculator.*");
+
+ initialContext = new InitialContext(properties);
+ }
+
+ /**
+ * Lookup the Calculator bean via its remote home interface
+ *
+ * @throws Exception
+ */
+ public void testCalculatorViaRemoteInterface() throws Exception {
+ Object object = initialContext.lookup("CalculatorImplBusinessRemote");
+
+ assertNotNull(object);
+ assertTrue(object instanceof CalculatorRemote);
+ CalculatorRemote calc = (CalculatorRemote) object;
+ assertEquals(10, calc.sum(4,6));
+ assertEquals(12, calc.multiply(3,4));
+ }
+
+ /**
+ * Lookup the Calculator bean via its local home interface
+ *
+ * @throws Exception
+ */
+ public void testCalculatorViaLocalInterface() throws Exception {
+ Object object = initialContext.lookup("CalculatorImplBusinessLocal");
+
+ assertNotNull(object);
+ assertTrue(object instanceof CalculatorLocal);
+ CalculatorLocal calc = (CalculatorLocal) object;
+ assertEquals(10, calc.sum(4,6));
+ assertEquals(12, calc.multiply(3,4));
+ }
+
+}
Added: incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/pom.xml?view=auto&rev=483291
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/pom.xml (added)
+++ incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/pom.xml Wed Dec 6 15:27:41 2006
@@ -0,0 +1,91 @@
+<?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.
+-->
+<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">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>simple-counter-statefuls</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>OpenEJB :: Examples :: Counter Stateful Pojo</name>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <id>codehaus-m2-snapshot</id>
+ <name>Codehaus Snapshot Repository</name>
+ <url>http://snapshots.repository.codehaus.org</url>
+ </repository>
+ <repository>
+ <id>apache-m2-snapshot</id>
+ <name>Apache Snapshot Repository</name>
+ <url>http://people.apache.org/repo/m2-snapshot-repository/</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-ejb_3.0_spec</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!--
+ Nice thing about maven2 is it has test-only dependencies.
+ This guarantees that non of your runtime code is dependent
+ on any OpenEJB classes.
+
+ For those of you who want to know the minimum steps required
+ to add OpenEJB for testing to an existing maven 2 build, you
+ simply add this dependency below and in your test code create
+ your InitialContext like such:
+
+ Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+
+ // Tells OpenEJB to look for META-INF/ejb-jar.xml files in the classpath
+ properties.setProperty("openejb.deployments.classpath", "true");
+
+ initialContext = new InitialContext(properties);
+
+ -->
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-core</artifactId>
+ <version>3.0-incubating-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterImpl.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterImpl.java?view=auto&rev=483291
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterImpl.java (added)
+++ incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterImpl.java Wed Dec 6 15:27:41 2006
@@ -0,0 +1,42 @@
+/**
+ * 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.examples.counter;
+
+import javax.ejb.Stateful;
+
+/**
+ * This is an EJB 3 style pojo stateful session bean
+ * Every stateful session bean implementation must be annotated
+ * using the annotation @Stateful
+ * This EJB has 2 business interfaces: CounterRemote, a remote business
+ * interface, and CounterLocal, a local business interface
+ *
+ */
+@Stateful
+public class CounterImpl implements CounterLocal, CounterRemote {
+
+ private int count = 0;
+
+ public int increment() {
+ return ++count;
+ }
+
+ public int reset() {
+ return (count = 0);
+ }
+
+}
Added: incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterLocal.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterLocal.java?view=auto&rev=483291
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterLocal.java (added)
+++ incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterLocal.java Wed Dec 6 15:27:41 2006
@@ -0,0 +1,31 @@
+/**
+ * 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.examples.counter;
+
+/**
+ * This is an EJB 3 local business interface
+ * A local business interface may be annotated with the @Local
+ * annotation, but it's optional. A business interface which is
+ * not annotated with @Local or @Remote is assumed to be Local
+ */
+public interface CounterLocal {
+
+ public int increment();
+
+ public int reset();
+
+}
Added: incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterRemote.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterRemote.java?view=auto&rev=483291
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterRemote.java (added)
+++ incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterRemote.java Wed Dec 6 15:27:41 2006
@@ -0,0 +1,33 @@
+/**
+ * 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.examples.counter;
+
+import javax.ejb.Remote;
+
+/**
+ * This is an EJB 3 remote business interface
+ * A remote business interface must be annotated with the @Remote
+ * annotation
+ */
+@Remote
+public interface CounterRemote {
+
+ public int increment();
+
+ public int reset();
+
+}
Added: incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/test/java/org/apache/openejb/examples/counter/CounterImplTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/test/java/org/apache/openejb/examples/counter/CounterImplTest.java?view=auto&rev=483291
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/test/java/org/apache/openejb/examples/counter/CounterImplTest.java (added)
+++ incubator/openejb/trunk/openejb3/examples/counter-stateful-pojo/src/test/java/org/apache/openejb/examples/counter/CounterImplTest.java Wed Dec 6 15:27:41 2006
@@ -0,0 +1,72 @@
+/**
+ * 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.examples.counter;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+public class CounterImplTest extends TestCase {
+
+ private InitialContext initialContext;
+
+ protected void setUp() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+ properties.setProperty("openejb.deployments.classpath.include", ".*counter-stateful.*");
+
+ initialContext = new InitialContext(properties);
+ }
+
+ /**
+ * Lookup the Counter bean via its remote home interface
+ *
+ * @throws Exception
+ */
+ public void testCounterViaRemoteInterface() throws Exception {
+ Object object = initialContext.lookup("CounterImplBusinessRemote");
+
+ assertNotNull(object);
+ assertTrue(object instanceof CounterRemote);
+ CounterRemote counter = (CounterRemote) object;
+ assertEquals(0, counter.reset());
+ assertEquals(1, counter.increment());
+ assertEquals(2, counter.increment());
+ assertEquals(0, counter.reset());
+ }
+
+ /**
+ * Lookup the Counter bean via its local home interface
+ *
+ * @throws Exception
+ */
+ public void testCounterViaLocalInterface() throws Exception {
+ Object object = initialContext.lookup("CounterImplBusinessLocal");
+
+ assertNotNull(object);
+ assertTrue(object instanceof CounterLocal);
+ CounterLocal counter = (CounterLocal) object;
+ assertEquals(0, counter.reset());
+ assertEquals(1, counter.increment());
+ assertEquals(2, counter.increment());
+ assertEquals(0, counter.reset());
+ }
+
+}
Modified: incubator/openejb/trunk/openejb3/examples/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/pom.xml?view=diff&rev=483291&r1=483290&r2=483291
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/examples/pom.xml Wed Dec 6 15:27:41 2006
@@ -32,5 +32,7 @@
<modules>
<module>helloworld-stateful-pojo</module>
- </modules>
+ <module>calculator-stateless-pojo</module>
+ <module>counter-stateful-pojo</module>
+ </modules>
</project>