You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2008/07/19 00:37:05 UTC

svn commit: r678067 - in /openejb/trunk/openejb3/examples: ./ simple-stateless-with-descriptor/ simple-stateless-with-descriptor/src/ simple-stateless-with-descriptor/src/main/ simple-stateless-with-descriptor/src/main/java/ simple-stateless-with-descr...

Author: jgallimore
Date: Fri Jul 18 15:37:05 2008
New Revision: 678067

URL: http://svn.apache.org/viewvc?rev=678067&view=rev
Log:
Adding sample stateless bean using descriptor (OPENEJB-343)

Added:
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/README.txt
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/build.xml
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/pom.xml
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorImpl.java
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorLocal.java
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorRemote.java
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/resources/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/resources/META-INF/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/resources/META-INF/ejb-jar.xml
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/test/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/test/java/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/test/java/org/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/test/java/org/superbiz/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/test/java/org/superbiz/calculator/
    openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/test/java/org/superbiz/calculator/CalculatorTest.java
Modified:
    openejb/trunk/openejb3/examples/pom.xml

Modified: openejb/trunk/openejb3/examples/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/pom.xml?rev=678067&r1=678066&r2=678067&view=diff
==============================================================================
--- openejb/trunk/openejb3/examples/pom.xml (original)
+++ openejb/trunk/openejb3/examples/pom.xml Fri Jul 18 15:37:05 2008
@@ -32,6 +32,7 @@
   <modules>
     <module>simple-stateful</module>
     <module>simple-stateless</module>
+    <module>simple-stateless-with-descriptor</module>
     <module>simple-singleton</module>
     <module>simple-mdb</module>
     <module>simple-cmp2</module>

Added: openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/README.txt
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/README.txt?rev=678067&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/README.txt (added)
+++ openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/README.txt Fri Jul 18 15:37:05 2008
@@ -0,0 +1,18 @@
+This example shows how to create a session stateless EJB using annotations.
+
+As stated in the "JSR 220: Enterprise JavaBeansTM,Version 3.0 - EJB Core Contracts and Requirements", 
+
+"Stateless session beans are session beans whose instances have no conversational state. This means that
+all bean instances are equivalent when they are not involved in servicing a client-invoked method.
+The term 'stateless' signifies that an instance has no state for a specific client."
+
+With EJB 3.0, it's now possible to write stateless session bean without specifying a deployment descriptor; you basically have to write just
+
+  * a remote or local business interface, which is a plain-old-java-interface, annotated with the @Remote or @Local annotation
+  * the stateless session bean implementation, a plain-old-java-object which implements the remote or the local business interface and is annotated with the @Stateless annotation
+  
+To run the example simply type:
+
+ $ mvn clean install
+
+

Added: openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/build.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/build.xml?rev=678067&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/build.xml (added)
+++ openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/build.xml Fri Jul 18 15:37:05 2008
@@ -0,0 +1,119 @@
+<?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: 635408 $ $Date: 2008-03-10 00:48:40 +0000 (Mon, 10 Mar 2008) $ -->
+
+<project name="MyProject" default="dist" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
+
+  <!-- ===============================================================
+
+  HOW TO RUN
+
+    Download http://www.apache.org/dist/maven/binaries/maven-ant-tasks-2.0.7.jar
+    Then execute ant as follows:
+
+    ant -lib maven-ant-tasks-2.0.7.jar
+
+  NOTE
+
+    You do NOT need maven-ant-tasks-2.0.7.jar to use OpenEJB for embedded EJB
+    testing with Ant.  It is simply used in this example to make the build.xml
+    a bit simpler.  As long as OpenEJB and it's required libraries are in the
+    <junit> classpath, the tests will run with OpenEJB embedded.
+
+  ================================================================= -->
+
+  <artifact:remoteRepository id="apache.snapshot.repository" url="http://people.apache.org/repo/m2-snapshot-repository/" />
+  <artifact:remoteRepository id="m2.repository" url="http://repo1.maven.org/maven2/" />
+
+  <!-- Build Classpath -->
+  <artifact:dependencies pathId="classpath.main">
+    <dependency groupId="org.apache.openejb" artifactId="javaee-api" version="5.0-1"/>
+  </artifact:dependencies>
+
+  <!-- Test Build Classpath -->
+  <artifact:dependencies pathId="classpath.test.build">
+    <dependency groupId="junit" artifactId="junit" version="4.3.1"/>
+  </artifact:dependencies>
+
+  <!-- Test Run Classpath -->
+  <artifact:dependencies pathId="classpath.test.run">
+    <remoteRepository refid="apache.snapshot.repository" />
+    <remoteRepository refid="m2.repository" />
+
+    <dependency groupId="org.apache.openejb" artifactId="openejb-core" version="3.0-SNAPSHOT"/>
+    <dependency groupId="junit" artifactId="junit" version="4.3.1"/>
+  </artifact:dependencies>
+
+  <!-- Properties -->
+
+  <property name="src.main.java" location="src/main/java"/>
+  <property name="src.main.resources" location="src/main/resources"/>
+  <property name="src.test.java" location="src/test/java"/>
+  <property name="build.main" location="target/classes"/>
+  <property name="build.test" location="target/test-classes"/>
+  <property name="test.reports" location="target/test-reports"/>
+  <property name="dist" location="target"/>
+
+
+  <target name="init">
+    <mkdir dir="${build.main}"/>
+    <mkdir dir="${build.test}"/>
+    <mkdir dir="${test.reports}"/>
+  </target>
+
+  <target name="compile" depends="init">
+
+    <javac srcdir="${src.main.java}" destdir="${build.main}">
+      <classpath refid="classpath.main" />
+    </javac>
+    <copy todir="${build.main}">
+      <fileset dir="${src.main.resources}"/>
+    </copy>
+
+    <javac srcdir="${src.test.java}" destdir="${build.test}">
+      <classpath location="${build.main}"/>
+      <classpath refid="classpath.main"/>
+      <classpath refid="classpath.test.build"/>
+    </javac>
+  </target>
+
+  <target name="test" depends="compile">
+    <junit fork="yes" printsummary="yes">
+      <classpath location="${build.main}"/>
+      <classpath location="${build.test}"/>
+      <classpath refid="classpath.main"/>
+      <classpath refid="classpath.test.build"/>
+      <classpath refid="classpath.test.run"/>
+
+      <formatter type="plain"/>
+
+      <batchtest fork="yes" todir="${test.reports}">
+        <fileset dir="${src.test.java}">
+          <include name="**/*Test.java"/>
+        </fileset>
+      </batchtest>
+    </junit>
+  </target>
+
+  <target name="dist" depends="test">
+    <jar jarfile="${dist}/myproject-1.0.jar" basedir="${build.main}"/>
+  </target>
+
+</project>

Added: openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/pom.xml?rev=678067&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/pom.xml (added)
+++ openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/pom.xml Fri Jul 18 15:37:05 2008
@@ -0,0 +1,73 @@
+<?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: 636494 $ $Date: 2008-03-12 20:24:02 +0000 (Wed, 12 Mar 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">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.superbiz</groupId>
+  <artifactId>simple-stateless-with-descriptor</artifactId>
+  <packaging>jar</packaging>
+  <version>1.1-SNAPSHOT</version>
+  <name>OpenEJB :: Examples :: Simple Stateless With Deployment Descriptor</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>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.openejb</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>5.0-1</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.1</version>
+      <scope>test</scope>
+    </dependency>
+
+    <!--
+    The <scope>test</scope> guarantees that non of your runtime
+    code is dependent on any OpenEJB classes.
+    -->
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-core</artifactId>
+      <version>3.1-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

Added: openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorImpl.java?rev=678067&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorImpl.java (added)
+++ openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorImpl.java Fri Jul 18 15:37:05 2008
@@ -0,0 +1,38 @@
+/**
+ * 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.superbiz.calculator;
+
+/**
+ * This is an EJB 3 stateless session bean, configured using an EJB 3
+ * deployment descriptor as opposed to using annotations.
+ * This EJB has 2 business interfaces: CalculatorRemote, a remote business
+ * interface, and CalculatorLocal, a local business interface
+ * 
+ */
+//START SNIPPET: code
+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;
+	}
+
+}
+//END SNIPPET: code

Added: openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorLocal.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorLocal.java?rev=678067&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorLocal.java (added)
+++ openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorLocal.java Fri Jul 18 15:37:05 2008
@@ -0,0 +1,32 @@
+/**
+ * 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.superbiz.calculator;
+
+import javax.ejb.EJBLocalObject;
+
+/**
+ * This is an EJB 3 local business interface
+ * This interface is specified using the business-local tag in the deployment descriptor
+ */
+//START SNIPPET: code
+public interface CalculatorLocal {
+	
+	public int sum(int add1, int add2);
+	
+	public int multiply(int mul1, int mul2);
+}
+//END SNIPPET: code

Added: openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorRemote.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorRemote.java?rev=678067&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorRemote.java (added)
+++ openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/java/org/superbiz/calculator/CalculatorRemote.java Fri Jul 18 15:37:05 2008
@@ -0,0 +1,32 @@
+/**
+ * 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.superbiz.calculator;
+
+
+/**
+ * This is an EJB 3 remote business interface
+ * This interface is specified using the business-local tag in the deployment descriptor
+ */
+//START SNIPPET: code
+public interface CalculatorRemote {
+	
+	public int sum(int add1, int add2);
+	
+	public int multiply(int mul1, int mul2);
+
+}
+//END SNIPPET: code

Added: openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/resources/META-INF/ejb-jar.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/resources/META-INF/ejb-jar.xml?rev=678067&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/resources/META-INF/ejb-jar.xml (added)
+++ openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/main/resources/META-INF/ejb-jar.xml Fri Jul 18 15:37:05 2008
@@ -0,0 +1,15 @@
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
+version="3.0">
+    <enterprise-beans>
+        <session>
+            <ejb-name>CalculatorImpl</ejb-name>
+            <business-local>org.superbiz.calculator.CalculatorLocal</business-local>
+            <business-remote>org.superbiz.calculator.CalculatorRemote</business-remote>
+            <ejb-class>org.superbiz.calculator.CalculatorImpl</ejb-class>
+            <session-type>Stateless</session-type>
+            <transaction-type>Container</transaction-type>
+        </session>
+    </enterprise-beans>
+</ejb-jar>

Added: openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/test/java/org/superbiz/calculator/CalculatorTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/test/java/org/superbiz/calculator/CalculatorTest.java?rev=678067&view=auto
==============================================================================
--- openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/test/java/org/superbiz/calculator/CalculatorTest.java (added)
+++ openejb/trunk/openejb3/examples/simple-stateless-with-descriptor/src/test/java/org/superbiz/calculator/CalculatorTest.java Fri Jul 18 15:37:05 2008
@@ -0,0 +1,73 @@
+/**
+ * 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.superbiz.calculator;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+public class CalculatorTest extends TestCase {
+
+	//START SNIPPET: setup	
+	private InitialContext initialContext;
+
+    protected void setUp() throws Exception {
+        Properties properties = new Properties();
+        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+
+        initialContext = new InitialContext(properties);
+    }
+    //END SNIPPET: setup    
+
+    /**
+     * Lookup the Calculator bean via its remote home interface
+     *
+     * @throws Exception
+     */
+    //START SNIPPET: remote
+    public void testCalculatorViaRemoteInterface() throws Exception {
+        Object object = initialContext.lookup("CalculatorImplRemote");
+
+		assertNotNull(object);
+		assertTrue(object instanceof CalculatorRemote);
+		CalculatorRemote calc = (CalculatorRemote) object;
+		assertEquals(10, calc.sum(4,6));
+		assertEquals(12, calc.multiply(3,4));
+    }
+    //END SNIPPET: remote
+    
+    /**
+     * Lookup the Calculator bean via its local home interface
+     *
+     * @throws Exception
+     */
+    //START SNIPPET: local    
+    public void testCalculatorViaLocalInterface() throws Exception {
+        Object object = initialContext.lookup("CalculatorImplLocal");
+
+		assertNotNull(object);
+		assertTrue(object instanceof CalculatorLocal);
+		CalculatorLocal calc = (CalculatorLocal) object;
+		assertEquals(10, calc.sum(4,6));
+		assertEquals(12, calc.multiply(3,4));
+    }
+    //END SNIPPET: local
+
+}