tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r800451 - in /websites/staging/openejb/trunk/content: ./ examples-trunk/ examples-trunk/simple-cdi-interceptor/ examples-trunk/simple-cdi-interceptor/src/ examples-trunk/simple-cdi-interceptor/src/main/ examples-trunk/simple-cdi-interceptor...
Date Sun, 18 Dec 2011 14:05:06 GMT
Author: buildbot
Date: Sun Dec 18 14:05:05 2011
New Revision: 800451

Log:
Staging update by buildbot

Added:
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/README.html
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/pom.xml
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/beans/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/beans/BookShow.java
  (with props)
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java
  (with props)
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptors/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptors/LoggingInterceptor.java
  (with props)
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/resources/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/resources/META-INF/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/resources/META-INF/beans.xml
  (with props)
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/test/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/test/java/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/test/java/org/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/test/java/org/superbiz/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/test/java/org/superbiz/cdi/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/test/java/org/superbiz/cdi/bookshow/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/test/java/org/superbiz/cdi/bookshow/interceptors/
    websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowTest.java
  (with props)
Modified:
    websites/staging/openejb/trunk/content/examples-trunk/pom.xml
    websites/staging/openejb/trunk/content/singleton-example.html

Modified: websites/staging/openejb/trunk/content/examples-trunk/pom.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/pom.xml (original)
+++ websites/staging/openejb/trunk/content/examples-trunk/pom.xml Sun Dec 18 14:05:05 2011
@@ -17,7 +17,7 @@
     limitations under the License.
 -->
 
-<!-- $Rev: 1208817 $ $Date: 2011-11-30 21:52:15 +0000 (Wed, 30 Nov 2011) $ -->
+<!-- $Rev: 1214912 $ $Date: 2011-12-15 19:01:22 +0000 (Thu, 15 Dec 2011) $ -->
 
 <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">
   <parent>
@@ -94,6 +94,7 @@
     <module>cdi-events</module>
     <module>dynamic-proxy-to-access-mbean</module>
     <module>reload-persistence-unit-properties</module>
+    <module>simple-cdi-interceptor</module>
   </modules>
   <profiles>
     <profile>

Added: websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/README.html
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/README.html
(added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/README.html
Sun Dec 18 14:05:05 2011
@@ -0,0 +1,232 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+
+    <meta charset="utf-8">
+      <title></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>
+
+  </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/simple-cdi-interceptor/">Simple Cdi Interceptor</a></small><br>
+    </div>
+    <div class="span8">
+        <div class="pull-right">
+            <small><a href="http://ci.apache.org/projects/openejb/examples-generated/simple-cdi-interceptor/simple-cdi-interceptor.zip">download
example</a>
+        </div>
+    </div>
+</div>
+
+<div class="page-header">
+<h1></h1>
+</div>
+
+<h1>Simple CDI Interceptor</h1>
+
+<p>Let's write a simple application that would allow us to book tickets for a movie
show. As with all applications, logging is one cross-cutting concern that we have. </p>
+
+<p>(Relevant snippets are inlined but you can check out the complete code, from the
links provided)</p>
+
+<p>How do we mark which methods are to be intercepted ? Wouldn't it be handy to annotate
a method like </p>
+
+<pre><code>
+@Log
+public void aMethod(){...} 
+</code></pre>
+
+<p>Let's create an  annotation that would "mark" a method for interception. </p>
+
+<pre><code>
+@InterceptorBinding
+@Target({ TYPE, METHOD })
+@Retention(RUNTIME)
+public @interface Log {</div>
+</pre>
+
+<p></code></p>
+
+<p>Sure, you haven't missed the @InterceptorBinding annotation above ! Now that our
custom annotation is created, lets attach it (or to use a better term for it, "bind it" )
+to an interceptor. </p>
+
+<p>So here's our logging interceptor. An @AroundInvoke method and we are almost done.</p>
+
+<pre><code>
+@Interceptor
+@Log  //binding the interceptor here. now any method annotated with @Log would be intercepted
by logMethodEntry
+public class LoggingInterceptor {
+    @AroundInvoke
+    public Object logMethodEntry(InvocationContext ctx) throws Exception {
+        System.out.println("Entering method: " + ctx.getMethod().getName());
+        //or logger.info statement 
+        return ctx.proceed();
+    </div>}
+</pre>
+
+<p></code></p>
+
+<p>Now the @Log annotation we created is bound to this interceptor.</p>
+
+<p>That done, let's annotate at class-level or method-level and have fun intercepting
! </p>
+
+<pre><code>
+@Log
+@Stateful
+public class BookForAShowOneInterceptorApplied implements Serializable {
+    private static final long serialVersionUID = 6350400892234496909L;
+    public List<String> getMoviesList() {
+        List<String> moviesAvailable = new ArrayList<String>();
+        moviesAvailable.add("12 Angry Men");
+        moviesAvailable.add("Kings speech");
+        return moviesAvailable;
+    }
+    public Integer getDiscountedPrice(int ticketPrice) {
+        return ticketPrice - 50;
+    }
+    // assume more methods are present</div>
+</code></pre>
+
+<p>The <code>@Log</code> annotation applied at class level denotes that
all the methods should be intercepted with <code>LoggingInterceptor</code>.</p>
+
+<p>Before we say "all done" there's one last thing we are left with ! To enable the
interceptors ! </p>
+
+<p>Lets quickly put up a [beans.xml file]</p>
+
+<pre><code>
+&lt;beans&gt;<br/>  &lt;interceptors&gt;<br/>    &lt;class&gt;org.superbiz.cdi.bookshow.interceptors.LoggingInterceptor<br/>
   &lt;/class&gt;<br/>  &lt;/interceptors&gt;<br/>&lt;/beans&gt;
+</code></pre>
+
+<p>in META-INF</p>
+
+<p>Those lines in beans.xml not only "enable" the interceptors, but also define the
"order of execution" of the interceptors.
+But we'll see that in another example on multiple-cdi-interceptors.</p>
+
+<p>Fire up the test, and we should see a 'Entering method: getMoviesList' printed in
the console.</p>
+
+<h1>Code</h1>
+
+<h4>Java files</h4>
+
+<p>${javas}</p>
+
+<h5>Resource files</h5>
+
+<p>${resources} </p>
+
+<h1>Download</h1>
+
+<p><a href="${zip}">Download as zip</a> </p>
+
+<pre><code>
+#Tests
+Apache OpenEJB 4.0.0-beta-2-SNAPSHOT    build: 20111103-01:00
+http://openejb.apache.org/
+INFO - openejb.home = /media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors
+INFO - openejb.base = /media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors
+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: /media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors/target/classes
+INFO - Beginning load: /media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors/target/classes
+INFO - Configuring enterprise application: /media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors
+INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default
Managed Container)
+INFO - Auto-creating a container for bean cdi-simple-interceptors.Comp: Container(type=MANAGED,
id=Default Managed Container)
+INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default
Stateful Container)
+INFO - Auto-creating a container for bean BookShow: Container(type=STATEFUL, id=Default Stateful
Container)
+INFO - Enterprise application "/media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors"
loaded.
+INFO - Assembling app: /media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors
+INFO - Jndi(name="java:global/cdi-simple-interceptors/BookShow!org.superbiz.cdi.bookshow.beans.BookShow")
+INFO - Jndi(name="java:global/cdi-simple-interceptors/BookShow")
+INFO - Created Ejb(deployment-id=BookShow, ejb-name=BookShow, container=Default Stateful
Container)
+INFO - Started Ejb(deployment-id=BookShow, ejb-name=BookShow, container=Default Stateful
Container)
+INFO - Deployed Application(path=/media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors)
+Entering method: getMoviesList
+</code></pre>
+
+
+<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>
+      </footer>
+
+    </div> <!-- /container -->
+
+  <SPAN style="display: none">
+    <SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript">
+    </SCRIPT>
+    <SCRIPT type="text/javascript">
+      _uacct = "UA-2717626-1";
+      urchinTracker();
+    </SCRIPT>
+  </SPAN>
+
+  </body>
+</html>

Added: websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/pom.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/pom.xml (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/pom.xml Sun
Dec 18 14:05:05 2011
@@ -0,0 +1,87 @@
+<?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: 1090810 $ $Date: 2011-04-10 07:49:26 -0700 (Sun, 10 Apr 2011) 
+	$ -->
+
+<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-cdi-interceptor</artifactId>
+  <packaging>jar</packaging>
+  <version>1.1-SNAPSHOT</version>
+  <name>OpenEJB :: Examples :: Simple CDI Interceptor</name>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  <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>
+  <repositories>
+    <repository>
+      <id>apache-m2-snapshot</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://repository.apache.org/snapshots</url>
+    </repository>
+  </repositories>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>6.0-3-SNAPSHOT</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.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>4.0.0-beta-2-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <!-- This section allows you to configure where to publish libraries for
+    sharing. It is not required and may be deleted. For more information see:
+    http://maven.apache.org/plugins/maven-deploy-plugin/ -->
+  <distributionManagement>
+    <repository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/repo/</url>
+    </repository>
+    <snapshotRepository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/snapshot-repo/</url>
+    </snapshotRepository>
+  </distributionManagement>
+
+</project>
+

Added: websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/beans/BookShow.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/beans/BookShow.java
(added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/beans/BookShow.java
Sun Dec 18 14:05:05 2011
@@ -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.superbiz.cdi.bookshow.beans;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Stateful;
+
+import org.superbiz.cdi.bookshow.interceptorbinding.Log;
+
+@Log
+@Stateful
+public class BookShow implements Serializable {
+	private static final long serialVersionUID = 6350400892234496909L;
+
+	public List<String> getMoviesList() {
+		List<String> moviesAvailable = new ArrayList<String>();
+		moviesAvailable.add("12 Angry Men");
+		moviesAvailable.add("Kings speech");
+		return moviesAvailable;
+	}
+	public Integer getDiscountedPrice(int ticketPrice) {
+		return ticketPrice - 50;
+	}
+	// assume more methods are present
+}

Propchange: websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/beans/BookShow.java
------------------------------------------------------------------------------
    svn:executable = *

Added: websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java
(added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java
Sun Dec 18 14:05:05 2011
@@ -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.superbiz.cdi.bookshow.interceptorbinding;
+
+import static java.lang.annotation.ElementType.*;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.*;
+import java.lang.annotation.Target;
+
+import javax.interceptor.InterceptorBinding;
+
+@InterceptorBinding
+@Target({ TYPE, METHOD })
+@Retention(RUNTIME)
+public @interface Log {
+}

Propchange: websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java
------------------------------------------------------------------------------
    svn:executable = *

Added: websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptors/LoggingInterceptor.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptors/LoggingInterceptor.java
(added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptors/LoggingInterceptor.java
Sun Dec 18 14:05:05 2011
@@ -0,0 +1,50 @@
+/**
+ * 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.
+ */
+/**
+ * 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.cdi.bookshow.interceptors;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+import org.superbiz.cdi.bookshow.interceptorbinding.Log;
+
+@Interceptor
+@Log
+public class LoggingInterceptor {
+	private static final long serialVersionUID = 8139854519874743530L;
+	@AroundInvoke
+	public Object logMethodEntry(InvocationContext ctx) throws Exception {
+		System.out.println("Entering method: " + ctx.getMethod().getName());
+		return ctx.proceed();
+	}
+}

Propchange: websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptors/LoggingInterceptor.java
------------------------------------------------------------------------------
    svn:executable = *

Added: websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/resources/META-INF/beans.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/resources/META-INF/beans.xml
(added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/resources/META-INF/beans.xml
Sun Dec 18 14:05:05 2011
@@ -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.
+-->
+<beans>
+  <!-- By default, a bean archive has no enabled interceptors bound via interceptor 
+    bindings. An interceptor must be explicitly enabled by listing its class 
+    under the element of the beans.xml file of the bean archive. The order of 
+    the interceptor declarations determines the interceptor ordering. Interceptors 
+    which occur earlier in the list are called first. If the same class is listed 
+    twice under the interceptors element, the container automatically detects 
+    the problem and treats it as a deployment problem. -->
+
+  <interceptors>
+    <class>org.superbiz.cdi.bookshow.interceptors.LoggingInterceptor
+    </class>
+  </interceptors>
+</beans>

Propchange: websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/main/resources/META-INF/beans.xml
------------------------------------------------------------------------------
    svn:executable = *

Added: websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowTest.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowTest.java
(added)
+++ websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowTest.java
Sun Dec 18 14:05:05 2011
@@ -0,0 +1,49 @@
+/**
+ * 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.cdi.bookshow.interceptors;
+
+import javax.ejb.EJB;
+import javax.ejb.embeddable.EJBContainer;
+
+import junit.framework.TestCase;
+
+import org.superbiz.cdi.bookshow.beans.BookShow;
+
+public class BookShowTest extends TestCase {
+	@EJB
+	private BookShow bookForAShowBean;
+	EJBContainer ejbContainer;
+	/**
+	 * Bootstrap the Embedded EJB Container
+	 * 
+	 * @throws Exception
+	 */
+	@Override
+	protected void setUp() throws Exception {
+		ejbContainer = EJBContainer.createEJBContainer();
+		ejbContainer.getContext().bind("inject", this);
+	}
+	/**
+	 * Test basic interception
+	 */
+	public void testMethodShouldBeIntercepted() {
+
+		bookForAShowBean.getMoviesList();
+
+	}
+
+}

Propchange: websites/staging/openejb/trunk/content/examples-trunk/simple-cdi-interceptor/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowTest.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: websites/staging/openejb/trunk/content/singleton-example.html
==============================================================================
--- websites/staging/openejb/trunk/content/singleton-example.html (original)
+++ websites/staging/openejb/trunk/content/singleton-example.html Sun Dec 18 14:05:05 2011
@@ -72,147 +72,183 @@
 <h1>Singleton Example</h1>
 </div>
 
-<p><div class="tip">:title=OpenEJB 3.1 or later required}
-<a name="SingletonExample-Overview"></a></p>
-
 <h1>Overview</h1>
 
-<p>As the name implies a javax.ejb.Singleton is a session bean with a
-guarantee that there is at most one instance in the application.</p>
-
-<p>What it gives you that is completely missing in EJB 3.0 and prior versions
-is the ability to have an EJB that is notified when the application starts
-and notified when the application stops.  So you can do all sorts of things
-that you previously could only do with a load-on-startup servlet.  It also
-gives you a place to hold data that pertains to the entire application and
-all users using it, without the need for a static.  Additionally, Singleton
-beans can be invoked by several threads at one time similar to a Servlet.</p>
+<p>As the name implies a javax.ejb.Singleton is a session bean with a guarantee that
there is at most one instance in the application.</p>
 
-<p><em>See the <a href="singleton-beans.html">Singleton Beans</a>
- page for a full description of the javax.ejb.Singleton api.</em></p>
+<p>What it gives that is completely missing in EJB 3.0 and prior versions is the ability
to have an EJB that is notified when the application starts and notified when the application
stops. So you can do all sorts of things that you previously could only do with a load-on-startup
servlet. It also gives you a place to hold data that pertains to the entire application and
all users using it, without the need for a static. Additionally, Singleton beans can be invoked
by several threads at one time similar to a Servlet.</p>
 
-<p><a name="SingletonExample-TheCode"></a></p>
+<p>See the Singleton Beans Javadocs linked at the bottom for a full description.</p>
 
 <h1>The Code</h1>
 
-<p><a name="SingletonExample-PropertyRegistryBean"></a></p>
+<p>PropertyRegistryBean</p>
 
-<h2>PropertyRegistryBean</h2>
+<p>Here we see a bean that uses the Bean-Managed Concurrency option as well as the
@Startup annotation which causes the bean to be instantiated by the container when the application
starts. Singleton beans with @ConcurrencyManagement(BEAN) are responsible for their own thread-safety.
The bean shown is a simple properties "registry" and provides a place where options could
be set and retrieved by all beans in the application.</p>
 
-<p>Here we see a bean that uses the Bean-Managed Concurrency option as well as
-the <em>@Startup</em> annotation which causes the bean to be instantiated by
the
-container when the application starts.  Singleton beans with
-<em>@ConcurrencyManagement(BEAN)</em> are responsible for their own thread-safety.
- The bean shown is a simple properties "registry" and provides a place
-where options could be set and retrieved by all beans in the application.
-<div class="snippet">:url=openejb3/examples/simple-singleton/src/main/java/org/superbiz/registry/PropertyRegistryBean.java|lang=java|id=code}</p>
-
-<p><a name="SingletonExample-ComponentRegistryBean"></a></p>
-
-<h2>ComponentRegistryBean</h2>
-
-<p>Here we see a bean that uses the Container-Managed Concurrency option, the
-default.  With <em>@ConcurrencyManagement(CONTAINER)</em> the container controls
-whether multi-threaded access should be allowed to the bean (<em>@Lock(READ)</em>)
-or if single-threaded access should be enforced (<em>@Lock(WRITE)</em>).
-<div class="snippet">:url=openejb3/examples/simple-singleton/src/main/java/org/superbiz/registry/ComponentRegistryBean.java|lang=java|id=code}</p>
-
-<p>Unless specified explicitly on the bean class or a method, the default
-@Lock value is @Lock(WRITE).  The code above uses the @Lock(READ)
-annotation on bean class to change the default so that multi-threaded
-access is granted by default.  We then only need to apply the @Lock(WRITE)
-annotation to the methods that modify the state of the bean.</p>
-
-<p>Essentially @Lock(READ) allows multithreaded access to the Singleton bean
-instance <em>unless</em> someone is invoking an @Lock(WRITE) method.  With
-@Lock(WRITE), the thread invoking the bean will be guaranteed to have
-exclusive access to the Singleton bean instance for the duration of its
-invocation.  This combination allows the bean instance to use data types
-that are not normally thread safe.  Great care must still be used, though.  </p>
+<pre><code>
+import static javax.ejb.ConcurrencyManagementType.BEAN;
+import javax.ejb.Singleton;
+import javax.ejb.ConcurrencyManagement;
+import javax.ejb.Startup;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import java.util.Properties;
+@Singleton
+@ConcurrencyManagement(BEAN)
+@Startup
+public class PropertyRegistryBean implements PropertyRegistry {
+    // Note the java.util.Properties object is a thread-safe
+    // collections that uses synchronization.  If it didn't
+    // you would have to use some form of synchronization
+    // to ensure the PropertyRegistryBean is thread-safe.
+    private final Properties properties = new Properties();
+
+    // The @Startup method ensures that this method is
+    // called when the application starts up.
+    @PostConstruct
+    public void applicationStartup() {
+        properties.putAll(System.getProperties());
+    }
+    @PreDestroy
+    public void applicationShutdown() {
+        properties.clear();
+    }
+    public String getProperty(String key) {
+        return properties.getProperty(key);
+    }
+
+    public String setProperty(String key, String value) {
+        return (String) properties.setProperty(key, value);
+    }
+
+    public String removeProperty(String key) {
+        return (String) properties.remove(key);
+    }
+</div>
+</pre>
 
-<p>In the example we see ComponentRegistryBean using a java.util.HashMap which
-is not synchronized.  To make this ok we do three things:</p>
+<p></code></p>
 
-<ol>
-<li>Encapsulation.  We don't expose the HashMap instance directly; including
-its iterators, key set, value set or entry set.</li>
-<li>We use @Lock(WRITE) on the methods that mutate the map such as the put()
-and remove() methods.  </li>
-<li>We use @Lock(READ) on the get() and values() methods as they do not
-change the map state and are guaranteed not to be called at the same as any
-of the @Lock(WRITE) methods, so we know the state of the HashMap is no
-being mutated and therefore safe for reading.</li>
-</ol>
+<p>ComponentRegistryBean</p>
+
+<p>Here we see a bean that uses the Container-Managed Concurrency option, the default.
With @ConcurrencyManagement(CONTAINER) the container controls whether multi-threaded access
should be allowed to the bean (@Lock(READ)) or if single-threaded access should be enforced
(@Lock(WRITE)).</p>
+
+<pre><code>
+import static javax.ejb.LockType.READ;
+import static javax.ejb.LockType.WRITE;
+import javax.ejb.Lock;
+import javax.ejb.Singleton;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Collection;
+import java.util.ArrayList;
+
+@Singleton
+@Lock(READ)
+public class ComponentRegistryBean implements ComponentRegistry {
+
+    private final Map<Class, Object> components = new HashMap<Class, Object>();
+
+    public <T> T getComponent(Class<T> type) {
+        return (T) components.get(type);
+    }
+
+    public Collection<?> getComponents() {
+        return new ArrayList(components.values());
+    }
+
+    @Lock(WRITE)
+    public <T> T setComponent(Class<T> type, T value) {
+        return (T) components.put(type, value);
+    }
+
+    @Lock(WRITE)
+    public <T> T removeComponent(Class<T> type) {
+        return (T) components.remove(type);
+    }
+</div>
+</code></pre>
 
-<p>The end result is that the threading model for this bean will switch from
-multi-threaded access to single-threaded access dynamically as needed
-depending on the which methods are being invoked.  This gives Singletons a
-bit of an advantage over Servlets for processing multi-threaded requests.</p>
+<p>Unless specified explicitly on the bean class or a method, the default @Lock value
is @Lock(WRITE). The code above uses the @Lock(READ) annotation on bean class to change the
default so that multi-threaded access is granted by default. We then only need to apply the
@Lock(WRITE) annotation to the methods that modify the state of the bean.</p>
 
-<p><em>See the <a href="singleton-beans.html">Singleton Beans</a>
- page for more advanced details on Container-Managed Concurrency.</em></p>
+<p>Essentially @Lock(READ) allows multithreaded access to the Singleton bean instance
unless someone is invoking an @Lock(WRITE) method. With @Lock(WRITE), the thread invoking
the bean will be guaranteed to have exclusive access to the Singleton bean instance for the
duration of its invocation. This combination allows the bean instance to use data types that
are not normally thread safe. Great care must still be used, though.</p>
 
-<p><a name="SingletonExample-TestCase"></a></p>
+<p>In the example we see ComponentRegistryBean using a java.util.HashMap which is not
synchronized. To make this ok we do three things:</p>
 
-<h1>Test Case</h1>
+<ol>
+<li>Encapsulation. We don't expose the HashMap instance directly; including its iterators,
key set, value set or entry set.</li>
+<li>We use @Lock(WRITE) on the methods that mutate the map such as the put() and remove()
methods.</li>
+<li>We use @Lock(READ) on the get() and values() methods as they do not change the
map state and are guaranteed not to be called at the same as any of the @Lock(WRITE) methods,
so we know the state of the HashMap is no being mutated and therefore safe for reading.</li>
+</ol>
+
+<p>The end result is that the threading model for this bean will switch from multi-threaded
access to single-threaded access dynamically as needed depending on the which methods are
being invoked. This gives Singletons a bit of an advantage over Servlets for processing multi-threaded
requests.</p>
 
-<p><div class="snippet">:url=openejb3/examples/simple-singleton/src/test/java/org/superbiz/registry/ComponentRegistryBeanTest.java|lang=java|id=code}</p>
+<p>See the Singleton Beans page for more advanced details on Container-Managed Concurrency.
+Test Case</p>
 
-<p><a name="SingletonExample-Running"></a></p>
+<pre><code>
+public class ComponentRegistryBeanTest extends TestCase {
+    public void test() throws Exception {
+        Properties props = new Properties();
+        props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
+        InitialContext context = new InitialContext(props);
+        // Both references below will point to the exact same instance
+        ComponentRegistry one = (ComponentRegistry) context.lookup("ComponentRegistryBeanLocal");
+        ComponentRegistry two = (ComponentRegistry) context.lookup("ComponentRegistryBeanLocal");
+        URI expectedUri = new URI("foo://bar/baz");
+        one.setComponent(URI.class, expectedUri);
+        URI actualUri = two.getComponent(URI.class);
+        assertSame(expectedUri, actualUri);
+        Date expectedDate = new Date();
+        two.setComponent(Date.class, expectedDate);
+        Date actualDate = one.getComponent(Date.class);
+        assertSame(expectedDate, actualDate);
+    </div>}
+</pre>
+
+<p></code></p>
 
 <h1>Running</h1>
 
-<p>Running the example is fairly simple.  In the "simple-singleton" directory
-run:</p>
+<p>Running the example is fairly simple. In the "simple-singleton" directory run:</p>
 
 <p>$ mvn clean install</p>
 
 <p>Which should create output like the following.</p>
 
-<pre><code>-------------------------------------------------------
- T E S T S
--------------------------------------------------------
+<h1>Tests</h1>
+
+<pre><code>
 Running org.superbiz.registry.ComponentRegistryBeanTest
 Apache OpenEJB 3.1-SNAPSHOT    build: 20080820-09:53
 http://openejb.apache.org/
-INFO - openejb.home =
-</code></pre>
-
-<p>/Users/dblevins/work/openejb3/examples/simple-singleton
-    INFO - openejb.base =
-/Users/dblevins/work/openejb3/examples/simple-singleton
-    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:
-/Users/dblevins/work/openejb3/examples/simple-singleton/target/classes
-    INFO - Beginning load:
-/Users/dblevins/work/openejb3/examples/simple-singleton/target/classes
-    INFO - Configuring enterprise application: classpath.ear
-    INFO - Configuring Service(id=Default Singleton Container, type=Container,
-provider-id=Default Singleton Container)
-    INFO - Auto-creating a container for bean ComponentRegistryBean:
-Container(type=SINGLETON, id=Default Singleton Container)
-    INFO - Enterprise application "classpath.ear" loaded.
-    INFO - Assembling app: classpath.ear
-    INFO - Jndi(name=ComponentRegistryBeanLocal) -->
-Ejb(deployment-id=ComponentRegistryBean)
-    INFO - Jndi(name=PropertyRegistryBeanLocal) -->
-Ejb(deployment-id=PropertyRegistryBean)
-    INFO - Created Ejb(deployment-id=ComponentRegistryBean,
-ejb-name=ComponentRegistryBean, container=Default Singleton Container)
-    INFO - Created Ejb(deployment-id=PropertyRegistryBean,
-ejb-name=PropertyRegistryBean, container=Default Singleton Container)
-    INFO - Deployed Application(path=classpath.ear)
-    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.879 sec
-    Running org.superbiz.registry.PropertiesRegistryBeanTest
-    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.009 sec</p>
+INFO - openejb.home = /Users/dblevins/work/openejb3/examples/simple-singleton
+INFO - openejb.base = /Users/dblevins/work/openejb3/examples/simple-singleton
+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: /Users/dblevins/work/openejb3/examples/simple-singleton/target/classes
+INFO - Beginning load: /Users/dblevins/work/openejb3/examples/simple-singleton/target/classes
+INFO - Configuring enterprise application: classpath.ear
+INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default
Singleton Container)
+INFO - Auto-creating a container for bean ComponentRegistryBean: Container(type=SINGLETON,
id=Default Singleton Container)
+INFO - Enterprise application "classpath.ear" loaded.
+INFO - Assembling app: classpath.ear
+INFO - Jndi(name=ComponentRegistryBeanLocal) --> Ejb(deployment-id=ComponentRegistryBean)
+INFO - Jndi(name=PropertyRegistryBeanLocal) --> Ejb(deployment-id=PropertyRegistryBean)
+INFO - Created Ejb(deployment-id=ComponentRegistryBean, ejb-name=ComponentRegistryBean, container=Default
Singleton Container)
+INFO - Created Ejb(deployment-id=PropertyRegistryBean, ejb-name=PropertyRegistryBean, container=Default
Singleton Container)
+INFO - Deployed Application(path=classpath.ear)
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.879 sec
+Running org.superbiz.registry.PropertiesRegistryBeanTest
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.009 sec
 
-<pre><code>Results :
+Results :
 
 Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
-</code></pre>
+</pre>
+
+<p></code></p>
 
 
 



Mime
View raw message