You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by bu...@apache.org on 2012/01/30 03:01:16 UTC

svn commit: r803538 - in /websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/superbiz/ src/main/java/org/superbiz/cdi/ src/main/java/org/superbiz/cdi/applic...

Author: buildbot
Date: Mon Jan 30 02:01:15 2012
New Revision: 803538

Log:
Staging update by buildbot for openejb

Added:
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/README.html
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/pom.xml
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/org/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/org/superbiz/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/org/superbiz/cdi/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/org/superbiz/cdi/applicationscope/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/org/superbiz/cdi/applicationscope/Soup.java
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/org/superbiz/cdi/applicationscope/Waiter.java
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/resources/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/resources/META-INF/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/resources/META-INF/beans.xml
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/test/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/test/java/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/test/java/org/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/test/java/org/superbiz/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/test/java/org/superbiz/cdi/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/test/java/org/superbiz/cdi/applicationscope/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/test/java/org/superbiz/cdi/applicationscope/RestaurantTest.java

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/README.html
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/README.html (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/README.html Mon Jan 30 02:01:15 2012
@@ -0,0 +1,253 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+
+    <meta charset="utf-8">
+      <title>CDI @ApplicationScoped</title>
+    <meta name="description" content="">
+    <meta name="author" content="">
+
+    <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
+    <!--[if lt IE 9]>
+      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+    <![endif]-->
+
+    <!-- Le styles -->
+    <link href="./../../bootstrap.css" rel="stylesheet">
+    <link href="./../../prettify.css" rel="stylesheet">
+    <link href="./../../bootstrap-mods.css" rel="stylesheet">
+
+    <style type="text/css">
+      body {
+        padding-top: 60px;
+      }
+    </style>
+
+
+    <!-- Le fav and touch icons -->
+    <link rel="shortcut icon" href="./../../images/favicon.ico">
+    <link rel="apple-touch-icon" href="./../../images/apple-touch-icon.png">
+    <link rel="apple-touch-icon" sizes="72x72" href="./../../images/apple-touch-icon-72x72.png">
+    <link rel="apple-touch-icon" sizes="114x114" href="./../../images/apple-touch-icon-114x114.png">
+
+    <script src="./../../javascript/prettify.js" type="text/javascript"></script>
+    <script src="./../../javascript/jquery-latest.js"></script>
+    <script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
+    <script src="./../../javascript/common.js"></script>
+    <script src="./../../javascript/prettyprint.js"></script>
+
+    <script type="text/javascript">
+
+      var _gaq = _gaq || [];
+      _gaq.push(['_setAccount', 'UA-2717626-1']);
+      _gaq.push(['_setDomainName', 'apache.org']);
+      _gaq.push(['_trackPageview']);
+
+      (function() {
+        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+      })();
+
+    </script>
+
+
+  </head>
+
+  <body>
+
+    <div class="topbar">
+      <div class="fill">
+        <div class="container">
+          <a class="brand" href="./../../index.html">Apache TomEE</a>
+          <ul class="nav">
+            <li><a href="./../../index.html">Home</a></li>
+            <li><a href="./../../downloads.html">Downloads</a></li>
+            <li><a href="./../../documentation.html">Documentation</a></li>
+            <li><a href="./../../support.html">Support</a></li>
+          </ul>
+
+            <!-- Google CSE Search Box Begins  -->
+            <FORM class="pull-right" id="searchbox_010475492895890475512:_t4iqjrgx90" action="http://www.google.com/cse">
+                <INPUT type="hidden" name="cx" value="010475492895890475512:_t4iqjrgx90">
+                <INPUT type="hidden" name="cof" value="FORID:0">
+                <INPUT name="q" type="text" placeholder="Search">
+            </FORM>
+            <!--<SCRIPT type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_010475492895890475512:_t4iqjrgx90"></SCRIPT>-->
+            <!-- Google CSE Search Box Ends -->
+        </div>
+      </div>
+    </div>
+
+    <div class="container">
+
+    
+
+<div class="row">
+    <div class="span8">
+        <small><a href="./../..//index.html">Home</a>&nbsp;&raquo&nbsp;<a href="./../..//examples-trunk/">Examples Trunk</a>&nbsp;&raquo&nbsp;<a href="./../..//examples-trunk/cdi-application-scope/">Cdi Application Scope</a></small><br>
+    </div>
+    <div class="span8">
+        <div class="pull-right">
+            <small><a href="http://ci.apache.org/projects/openejb/examples-generated/cdi-application-scope/cdi-application-scope.zip">download example</a>
+        </div>
+    </div>
+</div>
+
+<div class="page-header">
+<h1>CDI @ApplicationScoped</h1>
+</div>
+
+<p>This example show the use of <code>@ApplicationScoped</code> annotation for injected objects. An object
+which is defined as <code>@ApplicationScoped</code> is created once for the duration of the application.</p>
+
+<h1>Example</h1>
+
+<p>This example depicts a similar scenario to cdi-request-scope. A restaurant guest orders
+a soup from the waiter. The waiter then delivers the soup back to the guest. Another
+guest can order the same soup that was ordered by the previous client - this is where
+the application scope is used. </p>
+
+<h2>Waiter</h2>
+
+<p>The <code>Waiter</code> session bean receives a request from the test class via the <code>orderSoup()</code> method
+and sets the name for the <code>soup</code> field. The <code>orderWhatTheOtherGuyHad()</code> method returns
+the name of the <code>soup</code> field.</p>
+
+<p>@Stateless
+public class Waiter {</p>
+
+<pre><code>@Inject
+public Soup soup;
+
+public String orderSoup(String name){
+    soup.setName(name);
+    return soup.getName();
+}
+
+public String orderWhatTheOtherGuyHad() {
+    String name = soup.getName();
+    return name;
+}
+</code></pre>
+
+<p></div></p>
+
+<h2>Soup</h2>
+
+<p>The <code>Soup</code> class is an injectable POJO, defined as <code>@ApplicationScoped</code>. This means that an instance
+will be created only once for the duration of the whole application. Try changing the <code>@ApplicationScoped</code>
+annotation to <code>@RequestScoped</code> and see what happens.</p>
+
+<p>@ApplicationScoped
+public class Soup {</p>
+
+<pre><code>private String name = "Soup of the day";
+
+@PostConstruct
+public void afterCreate() {
+    System.out.println("Soup created");
+}
+
+public String getName() {
+    return name;
+}
+
+public void setName(String name){
+    this.name = name;
+</div>}
+</code></pre>
+
+<h1>Test Case</h1>
+
+<p>This is the entry class for this example. First a soup is ordered via <code>orderSoup()</code> method.
+This initiates the <code>soup</code> field. Next, <code>orderWhatTheOtherGuyHad()</code> method returns the soup
+from the application context.</p>
+
+<p>public class RestaurantTest {</p>
+
+<pre><code>private static String TOMATO_SOUP = "Tomato Soup";
+private EJBContainer container;
+
+@EJB
+private Waiter joe;
+
+@Before
+public void startContainer() throws Exception {
+    container = EJBContainer.createEJBContainer();
+    container.getContext().bind("inject", this);
+}
+
+@Test
+public void orderSoup(){
+    String someSoup = joe.orderSoup(TOMATO_SOUP);
+    assertEquals(TOMATO_SOUP, someSoup);
+
+    String sameSoup = joe.orderWhatTheOtherGuyHad();
+    assertEquals(TOMATO_SOUP, sameSoup);
+}
+
+@After
+public void closeContainer() throws Exception {
+    container.close();
+</div>}
+</code></pre>
+
+<h1>Running</h1>
+
+<p>In the output you can see that there is just one <code>Soup</code> instance created - one for
+the whole application.</p>
+
+<hr />
+
+<h2> T E S T S</h2>
+
+<p>Running org.superbiz.cdi.applicationscope.RestaurantTest
+Apache OpenEJB 4.0.0-beta-2-SNAPSHOT    build: 20111224-11:09
+http://openejb.apache.org/
+INFO - openejb.home = C:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-application-scope
+INFO - openejb.base = C:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-application-scope
+INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+INFO - Found EjbModule in classpath: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-application-scope\target\classes
+INFO - Beginning load: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-application-scope\target\classes
+INFO - Configuring enterprise application: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-application-scope
+INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+INFO - Auto-creating a container for bean cdi-application-scope.Comp: Container(type=MANAGED, id=Default Managed Container)
+INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
+INFO - Auto-creating a container for bean Waiter: Container(type=STATELESS, id=Default Stateless Container)
+INFO - Enterprise application "c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-application-scope" loaded.
+INFO - Assembling app: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-application-scope
+INFO - Jndi(name="java:global/cdi-application-scope/Waiter!org.superbiz.cdi.applicationscope.Waiter")
+INFO - Jndi(name="java:global/cdi-application-scope/Waiter")
+INFO - Created Ejb(deployment-id=Waiter, ejb-name=Waiter, container=Default Stateless Container)
+INFO - Started Ejb(deployment-id=Waiter, ejb-name=Waiter, container=Default Stateless Container)
+INFO - Deployed Application(path=c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-application-scope)
+Soup created
+INFO - Undeploying app: c:\Users\Daniel\workspaces\openejb\openejb\examples\cdi-application-scope
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.42 sec</p>
+
+<p>Results :</p>
+
+<p>Tests run: 1, Failures: 0, Errors: 0, Skipped: 0</p>
+
+
+<div class="page-header">&nbsp;</div>
+<h4>APIs Used</h4>
+
+
+
+
+      <footer>
+        <p>
+        Copyright &copy; 2011 The Apache Software Foundation, Licensed under the Apache License, Version 2.0.
+        Apache and the Apache feather logo are trademarks of The Apache Software Foundation.
+        </p>
+          <p><a href="/sitemap.html">sitemap</a></p>
+      </footer>
+
+    </div> <!-- /container -->
+
+  </body>
+</html>

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/pom.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/pom.xml (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/pom.xml Mon Jan 30 02:01:15 2012
@@ -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. -->
+<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/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.superbiz</groupId>
+	<artifactId>cdi-application-scope</artifactId>
+	<version>1.0-SNAPSHOT</version>
+
+	<build>
+		<defaultGoal>install</defaultGoal>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.3.2</version>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.openejb</groupId>
+			<artifactId>javaee-api</artifactId>
+			<version>6.0-3</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.8.1</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.openejb</groupId>
+			<artifactId>openejb-core</artifactId>
+			<version>4.0.0-beta-3-SNAPSHOT</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+</project>

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/org/superbiz/cdi/applicationscope/Soup.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/org/superbiz/cdi/applicationscope/Soup.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/org/superbiz/cdi/applicationscope/Soup.java Mon Jan 30 02:01:15 2012
@@ -0,0 +1,23 @@
+package org.superbiz.cdi.applicationscope;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
+public class Soup {
+
+	private String name = "Soup of the day";
+
+	@PostConstruct
+	public void afterCreate() {
+		System.out.println("Soup created");
+	}
+
+	public String getName() {
+		return name;
+	}
+	
+	public void setName(String name){
+		this.name = name;
+	}
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/org/superbiz/cdi/applicationscope/Waiter.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/org/superbiz/cdi/applicationscope/Waiter.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/java/org/superbiz/cdi/applicationscope/Waiter.java Mon Jan 30 02:01:15 2012
@@ -0,0 +1,22 @@
+package org.superbiz.cdi.applicationscope;
+
+import javax.ejb.Stateless;
+import javax.inject.Inject;
+
+@Stateless
+public class Waiter {
+	
+	@Inject
+	public Soup soup;
+	
+	public String orderSoup(String name){
+		soup.setName(name);
+		return soup.getName();
+	}
+
+	public String orderWhatTheOtherGuyHad() {
+		String name = soup.getName();
+		return name;
+	}
+
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/resources/META-INF/beans.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/resources/META-INF/beans.xml (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/main/resources/META-INF/beans.xml Mon Jan 30 02:01:15 2012
@@ -0,0 +1,19 @@
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans>
+</beans>
\ No newline at end of file

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/test/java/org/superbiz/cdi/applicationscope/RestaurantTest.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/test/java/org/superbiz/cdi/applicationscope/RestaurantTest.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-application-scope/src/test/java/org/superbiz/cdi/applicationscope/RestaurantTest.java Mon Jan 30 02:01:15 2012
@@ -0,0 +1,39 @@
+package org.superbiz.cdi.applicationscope;
+
+import javax.ejb.EJB;
+import javax.ejb.embeddable.EJBContainer;
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.superbiz.cdi.applicationscope.Waiter;
+
+public class RestaurantTest {
+	
+	private static String TOMATO_SOUP = "Tomato Soup";
+	private EJBContainer container;
+	
+	@EJB
+	private Waiter joe;
+	
+	@Before
+    public void startContainer() throws Exception {
+        container = EJBContainer.createEJBContainer();
+        container.getContext().bind("inject", this);
+    }
+	
+	@Test
+	public void orderSoup(){
+		String someSoup = joe.orderSoup(TOMATO_SOUP);
+		assertEquals(TOMATO_SOUP, someSoup);
+		
+		String sameSoup = joe.orderWhatTheOtherGuyHad();
+		assertEquals(TOMATO_SOUP, sameSoup);
+	}
+	
+	@After
+	public void closeContainer() throws Exception {
+		container.close();
+	}
+}