Index: openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/AnnotationDeployer.java =================================================================== --- openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/AnnotationDeployer.java (revision 482558) +++ openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/AnnotationDeployer.java (working copy) @@ -133,8 +133,9 @@ for (Class beanClass : classes) { Stateless stateless = (Stateless) beanClass.getAnnotation(Stateless.class); String ejbName = stateless.name().length() == 0 ? beanClass.getSimpleName() : stateless.name(); - if (ejbJar.getEnterpriseBean(ejbName) == null) { - ejbJar.addEnterpriseBean(new StatelessBean(ejbName, beanClass.getName())); + StatelessBean statelessBean = new StatelessBean(ejbName, beanClass); + if (ejbJar.getEnterpriseBean(statelessBean.getEjbName()) == null) { + ejbJar.addEnterpriseBean(statelessBean); } } @@ -140,10 +141,11 @@ classes = finder.findAnnotatedClasses(Stateful.class); for (Class beanClass : classes) { - Stateful stateless = (Stateful) beanClass.getAnnotation(Stateful.class); - String ejbName = stateless.name().length() == 0 ? beanClass.getName() : stateless.name(); - if (ejbJar.getEnterpriseBean(ejbName) == null) { - ejbJar.addEnterpriseBean(new StatefulBean(ejbName, beanClass.getName())); + Stateful stateful = (Stateful) beanClass.getAnnotation(Stateful.class); + String ejbName = stateful.name().length() == 0 ? beanClass.getSimpleName() : stateful.name(); + StatefulBean statefulBean = new StatefulBean(ejbName, beanClass); + if (ejbJar.getEnterpriseBean(statefulBean.getEjbName()) == null) { + ejbJar.addEnterpriseBean(statefulBean); } } Index: openejb3/container/openejb-jee/pom.xml =================================================================== --- openejb3/container/openejb-jee/pom.xml (revision 482558) +++ openejb3/container/openejb-jee/pom.xml (working copy) @@ -46,6 +46,10 @@ 1.0 + org.apache.geronimo.specs + geronimo-ejb_3.0_spec + + com.sun.xml.bind jaxb-impl 2.0.3 Index: openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java =================================================================== --- openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java (revision 482558) +++ openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/SessionBean.java (working copy) @@ -18,6 +18,7 @@ package org.apache.openejb.jee; +import javax.ejb.Remote; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -207,6 +208,19 @@ this.ejbClass = ejbClass; this.sessionType = sessionType; } + + public SessionBean(String ejbName, Class beanClass, SessionType sessionType) { + for (Class anInterface: beanClass.getInterfaces()) + { + if (anInterface.isAnnotationPresent(Remote.class)) + this.setBusinessRemote(anInterface.getName()); + else + this.setBusinessLocal(anInterface.getName()); + } + this.ejbName = ejbName; + this.setEjbClass(beanClass.getName()); + this.sessionType = sessionType; + } @XmlElement(name = "description", required = true) public Text[] getDescriptions() { Index: openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/StatefulBean.java =================================================================== --- openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/StatefulBean.java (revision 482558) +++ openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/StatefulBean.java (working copy) @@ -17,6 +17,8 @@ */ package org.apache.openejb.jee; +import java.util.Collections; + /** * @version $Revision$ $Date$ */ @@ -27,9 +29,14 @@ } public StatefulBean() { - this(null, null); } - public void setSessionType(SessionType value) { + public StatefulBean(String ejbName, Class beanClass) { + super(ejbName, beanClass, SessionType.STATEFUL); + postActivate = Collections.EMPTY_LIST; + prePassivate = Collections.EMPTY_LIST; + } + + public void setSessionType(SessionType value) { } } Index: openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/StatelessBean.java =================================================================== --- openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/StatelessBean.java (revision 482558) +++ openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/StatelessBean.java (working copy) @@ -30,10 +30,15 @@ } public StatelessBean() { - this(null, null); } - public void setSessionType(SessionType value) { + public StatelessBean(String ejbName, Class beanClass) { + super(ejbName, beanClass, SessionType.STATELESS); + postActivate = Collections.EMPTY_LIST; + prePassivate = Collections.EMPTY_LIST; + } + + public void setSessionType(SessionType value) { } } Index: openejb3/examples/calculator-stateless-pojo/pom.xml =================================================================== --- openejb3/examples/calculator-stateless-pojo/pom.xml (revision 0) +++ openejb3/examples/calculator-stateless-pojo/pom.xml (revision 0) @@ -0,0 +1,91 @@ + + + + 4.0.0 + org.apache.openejb + simple-calculator-stateless + jar + 1.0-SNAPSHOT + OpenEJB :: Examples :: Calculator Stateless Pojo + + install + + + maven-compiler-plugin + + 1.5 + 1.5 + + + + + + + codehaus-m2-snapshot + Codehaus Snapshot Repository + http://snapshots.repository.codehaus.org + + + apache-m2-snapshot + Apache Snapshot Repository + http://people.apache.org/repo/m2-snapshot-repository/ + + + + + org.apache.geronimo.specs + geronimo-ejb_3.0_spec + 1.0-SNAPSHOT + provided + + + junit + junit + 3.8.1 + test + + + + + org.apache.openejb + openejb-core + 3.0-incubating-SNAPSHOT + test + + + Index: openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorImpl.java =================================================================== --- openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorImpl.java (revision 0) +++ openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorImpl.java (revision 0) @@ -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; + } + +} Index: openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorLocal.java =================================================================== --- openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorLocal.java (revision 0) +++ openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorLocal.java (revision 0) @@ -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); +} Index: openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorRemote.java =================================================================== --- openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorRemote.java (revision 0) +++ openejb3/examples/calculator-stateless-pojo/src/main/java/org/apache/openejb/examples/calculator/CalculatorRemote.java (revision 0) @@ -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); + +} Index: openejb3/examples/calculator-stateless-pojo/src/main/resources/META-INF/ejb-jar.xml =================================================================== --- openejb3/examples/calculator-stateless-pojo/src/main/resources/META-INF/ejb-jar.xml (revision 0) +++ openejb3/examples/calculator-stateless-pojo/src/main/resources/META-INF/ejb-jar.xml (revision 0) @@ -0,0 +1,21 @@ + + + + + \ No newline at end of file Index: openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/calculator/CalculatorTest.java =================================================================== --- openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/calculator/CalculatorTest.java (revision 0) +++ openejb3/examples/calculator-stateless-pojo/src/test/java/org/apache/openejb/examples/calculator/CalculatorTest.java (revision 0) @@ -0,0 +1,71 @@ +/** + * 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 org.apache.openejb.examples.calculator.CalculatorRemote; + +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", "true"); + + 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)); + } + +} Index: openejb3/examples/counter-stateful-pojo/pom.xml =================================================================== --- openejb3/examples/counter-stateful-pojo/pom.xml (revision 0) +++ openejb3/examples/counter-stateful-pojo/pom.xml (revision 0) @@ -0,0 +1,91 @@ + + + + 4.0.0 + org.apache.openejb + simple-counter-statefuls + jar + 1.0-SNAPSHOT + OpenEJB :: Examples :: Counter Stateful Pojo + + install + + + maven-compiler-plugin + + 1.5 + 1.5 + + + + + + + codehaus-m2-snapshot + Codehaus Snapshot Repository + http://snapshots.repository.codehaus.org + + + apache-m2-snapshot + Apache Snapshot Repository + http://people.apache.org/repo/m2-snapshot-repository/ + + + + + org.apache.geronimo.specs + geronimo-ejb_3.0_spec + 1.0-SNAPSHOT + provided + + + junit + junit + 3.8.1 + test + + + + + org.apache.openejb + openejb-core + 3.0-incubating-SNAPSHOT + test + + + Index: openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterImpl.java =================================================================== --- openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterImpl.java (revision 0) +++ openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterImpl.java (revision 0) @@ -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); + } + +} Index: openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterLocal.java =================================================================== --- openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterLocal.java (revision 0) +++ openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterLocal.java (revision 0) @@ -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(); + +} Index: openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterRemote.java =================================================================== --- openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterRemote.java (revision 0) +++ openejb3/examples/counter-stateful-pojo/src/main/java/org/apache/openejb/examples/counter/CounterRemote.java (revision 0) @@ -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(); + +} Index: openejb3/examples/counter-stateful-pojo/src/main/resources/META-INF/ejb-jar.xml =================================================================== --- openejb3/examples/counter-stateful-pojo/src/main/resources/META-INF/ejb-jar.xml (revision 0) +++ openejb3/examples/counter-stateful-pojo/src/main/resources/META-INF/ejb-jar.xml (revision 0) @@ -0,0 +1,21 @@ + + + + + \ No newline at end of file Index: openejb3/examples/counter-stateful-pojo/src/test/java/org/apache/openejb/examples/counter/CounterImplTest.java =================================================================== --- openejb3/examples/counter-stateful-pojo/src/test/java/org/apache/openejb/examples/counter/CounterImplTest.java (revision 0) +++ openejb3/examples/counter-stateful-pojo/src/test/java/org/apache/openejb/examples/counter/CounterImplTest.java (revision 0) @@ -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.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", "true"); + + 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 calc = (CounterRemote) object; + assertEquals(0, calc.reset()); + assertEquals(1, calc.increment()); + assertEquals(2, calc.increment()); + assertEquals(0, calc.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 calc = (CounterLocal) object; + assertEquals(0, calc.reset()); + assertEquals(1, calc.increment()); + assertEquals(2, calc.increment()); + assertEquals(0, calc.reset()); + } + +} Index: openejb3/examples/pom.xml =================================================================== --- openejb3/examples/pom.xml (revision 482558) +++ openejb3/examples/pom.xml (working copy) @@ -32,5 +32,7 @@ helloworld-stateful-pojo - + calculator-stateless-pojo + counter-stateful-pojo +