You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2007/01/11 11:49:54 UTC
svn commit: r495181 - in /incubator/openejb/trunk/openejb3/examples: ./
resource-injection/ resource-injection/src/ resource-injection/src/main/
resource-injection/src/main/java/ resource-injection/src/main/java/org/
resource-injection/src/main/java/or...
Author: jlaskowski
Date: Thu Jan 11 02:49:51 2007
New Revision: 495181
URL: http://svn.apache.org/viewvc?view=rev&rev=495181
Log:
OPENEJB-355 Example: @Resource for Field Injection
Submitted by: Raj Saini
Added:
incubator/openejb/trunk/openejb3/examples/resource-injection/ (with props)
incubator/openejb/trunk/openejb3/examples/resource-injection/pom.xml (with props)
incubator/openejb/trunk/openejb3/examples/resource-injection/src/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/LineItem.java (with props)
incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/PurchaseOrder.java (with props)
incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/PurchaseOrderBean.java (with props)
incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/TooManyItemsException.java (with props)
incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/java/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/java/org/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/java/org/apache/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/java/org/apache/openejb/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/java/org/apache/openejb/examples/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/java/org/apache/openejb/examples/injection/
incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/java/org/apache/openejb/examples/injection/PurchaseOrderBeanTest.java (with props)
Modified:
incubator/openejb/trunk/openejb3/examples/pom.xml
Modified: incubator/openejb/trunk/openejb3/examples/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/pom.xml?view=diff&rev=495181&r1=495180&r2=495181
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/examples/pom.xml Thu Jan 11 02:49:51 2007
@@ -29,12 +29,12 @@
<artifactId>examples</artifactId>
<packaging>pom</packaging>
<name>OpenEJB :: Examples</name>
-
<modules>
<module>helloworld-stateful-pojo</module>
<module>calculator-stateless-pojo</module>
- <module>counter-stateful-pojo</module>
- <module>ejb-injection</module>
- <module>telephone-stateful</module>
- </modules>
+ <module>counter-stateful-pojo</module>
+ <module>ejb-injection</module>
+ <module>resource-injection</module>
+ <module>telephone-stateful</module>
+ </modules>
</project>
Propchange: incubator/openejb/trunk/openejb3/examples/resource-injection/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jan 11 02:49:51 2007
@@ -0,0 +1,11 @@
+*.iws
+*.ipr
+*.iml
+.classpath
+.project
+.settings
+*.log
+junit*.properties
+target
+bin
+
Added: incubator/openejb/trunk/openejb3/examples/resource-injection/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/resource-injection/pom.xml?view=auto&rev=495181
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/resource-injection/pom.xml (added)
+++ incubator/openejb/trunk/openejb3/examples/resource-injection/pom.xml Thu Jan 11 02:49:51 2007
@@ -0,0 +1,103 @@
+<?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$ $Date$ -->
+
+<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>resource-injection</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>OpenEJB :: Examples :: Resource Injection</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>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.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>
Propchange: incubator/openejb/trunk/openejb3/examples/resource-injection/pom.xml
------------------------------------------------------------------------------
svn:keywords = Date Rev Author Id Revision HeadURL
Added: incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/LineItem.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/LineItem.java?view=auto&rev=495181
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/LineItem.java (added)
+++ incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/LineItem.java Thu Jan 11 02:49:51 2007
@@ -0,0 +1,53 @@
+/**
+ * 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.injection;
+
+import java.io.Serializable;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LineItem implements Serializable {
+
+ private String productId;
+
+ private String description;
+
+ private static final long serialVersionUID = 1L;
+
+ public LineItem(String productId, String description) {
+ this.productId = productId;
+ this.description = description;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getProductId() {
+ return productId;
+ }
+
+ public void setProductId(String productId) {
+ this.productId = productId;
+ }
+
+}
Propchange: incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/LineItem.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author Id Revision HeadURL
Added: incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/PurchaseOrder.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/PurchaseOrder.java?view=auto&rev=495181
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/PurchaseOrder.java (added)
+++ incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/PurchaseOrder.java Thu Jan 11 02:49:51 2007
@@ -0,0 +1,28 @@
+/**
+ * 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.injection;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface PurchaseOrder {
+
+ void addLineItem(LineItem item) throws TooManyItemsException;
+
+ int getMaxLineItems();
+
+}
Propchange: incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/PurchaseOrder.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author Id Revision HeadURL
Added: incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/PurchaseOrderBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/PurchaseOrderBean.java?view=auto&rev=495181
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/PurchaseOrderBean.java (added)
+++ incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/PurchaseOrderBean.java Thu Jan 11 02:49:51 2007
@@ -0,0 +1,67 @@
+/**
+ * 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.injection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Resource;
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+/**
+ * This example demostrates the use of the injection of environment entries
+ * using <b>Resource</b> annotation.
+ *
+ * "EJB Core Contracts and Requirements" specification section 16.4.1.1.
+ *
+ * Resource annotation is used to annotate the maxLineItems and default value of
+ * 10 is assigned. Deployer can modify the values of the environment entries at
+ * deploy time in deployment descriptor.
+ *
+ * @version $Rev$ $Date$
+ */
+
+@Stateful
+@Remote
+public class PurchaseOrderBean implements PurchaseOrder {
+
+ @Resource
+ int maxLineItems = 10;
+
+ private List<LineItem> items = new ArrayList<LineItem>();
+
+ private int itemCount;
+
+ public void addLineItem(LineItem item) throws TooManyItemsException {
+ if (item == null) {
+ throw new IllegalArgumentException("Line item must not be null");
+ }
+
+ if (itemCount <= maxLineItems) {
+ items.add(item);
+ itemCount++;
+ } else {
+ throw new TooManyItemsException("Number of items exceeded the maximum limit");
+ }
+ }
+
+ public int getMaxLineItems() {
+ return this.maxLineItems;
+ }
+
+}
Propchange: incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/PurchaseOrderBean.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author Id Revision HeadURL
Added: incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/TooManyItemsException.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/TooManyItemsException.java?view=auto&rev=495181
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/TooManyItemsException.java (added)
+++ incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/TooManyItemsException.java Thu Jan 11 02:49:51 2007
@@ -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.injection;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TooManyItemsException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public TooManyItemsException() {
+ super();
+ }
+
+ public TooManyItemsException(String message) {
+ super(message);
+ }
+}
Propchange: incubator/openejb/trunk/openejb3/examples/resource-injection/src/main/java/org/apache/openejb/examples/injection/TooManyItemsException.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author Id Revision HeadURL
Added: incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/java/org/apache/openejb/examples/injection/PurchaseOrderBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/java/org/apache/openejb/examples/injection/PurchaseOrderBeanTest.java?view=auto&rev=495181
==============================================================================
--- incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/java/org/apache/openejb/examples/injection/PurchaseOrderBeanTest.java (added)
+++ incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/java/org/apache/openejb/examples/injection/PurchaseOrderBeanTest.java Thu Jan 11 02:49:51 2007
@@ -0,0 +1,63 @@
+/**
+ * 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.injection;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PurchaseOrderBeanTest 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",
+ ".*resource-injection.*");
+
+ initialContext = new InitialContext(properties);
+ }
+
+ public void testAddLineItem() throws Exception {
+ PurchaseOrder order = (PurchaseOrder) initialContext.lookup("PurchaseOrderBeanBusinessRemote");
+ assertNotNull(order);
+ LineItem item = new LineItem("ABC-1", "Test Item");
+
+ try {
+ order.addLineItem(item);
+ } catch (TooManyItemsException tmie) {
+ fail("Test failed due to: " + tmie.getMessage());
+ }
+ }
+
+ public void testGetMaxLineItems() throws Exception {
+ PurchaseOrder order = (PurchaseOrder) initialContext.lookup("PurchaseOrderBeanBusinessRemote");
+ assertNotNull(order);
+
+ int maxLineItems = order.getMaxLineItems();
+
+ assertEquals(10, maxLineItems);
+ }
+}
Propchange: incubator/openejb/trunk/openejb3/examples/resource-injection/src/test/java/org/apache/openejb/examples/injection/PurchaseOrderBeanTest.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author Id Revision HeadURL