You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2012/02/19 23:32:13 UTC
svn commit: r1291077 [1/4] - in /openejb/trunk/openejb/examples:
bean-validation-design-by-contract/
bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/
bean-validation-design-by-contract/src/test/java/ cdi-interceptors/ cdi...
Author: dblevins
Date: Sun Feb 19 22:32:10 2012
New Revision: 1291077
URL: http://svn.apache.org/viewvc?rev=1291077&view=rev
Log:
ran dos2unix on files that came with CRLF feeds despite the svn:eol-style=native setting. most due to mixing both CRLF and LF eol styles in the same file.
Modified:
openejb/trunk/openejb/examples/bean-validation-design-by-contract/README.md
openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/OlympicGamesManager.java
openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/PoleVaultingManager.java
openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/PoleVaultingManagerBean.java
openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/test/java/OlympicGamesTest.java
openejb/trunk/openejb/examples/cdi-interceptors/README.md
openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java
openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java
openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java
openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java
openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java
openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java
openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java
openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java
openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java
openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java
openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java
openejb/trunk/openejb/examples/cdi-interceptors/src/main/resources/META-INF/beans.xml
openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java
openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java
openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java
openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java
openejb/trunk/openejb/examples/dynamic-datasource-routing/README.md
openejb/trunk/openejb/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/BoostrapUtility.java
openejb/trunk/openejb/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/DeterminedRouter.java
openejb/trunk/openejb/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/Person.java
openejb/trunk/openejb/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/RoutedPersister.java
openejb/trunk/openejb/examples/dynamic-datasource-routing/src/main/resources/META-INF/org.router/service-jar.xml
openejb/trunk/openejb/examples/dynamic-datasource-routing/src/main/resources/META-INF/persistence.xml
openejb/trunk/openejb/examples/dynamic-datasource-routing/src/test/java/org/superbiz/dynamicdatasourcerouting/DynamicDataSourceTest.java
openejb/trunk/openejb/examples/mbean-auto-registration/README.md
openejb/trunk/openejb/examples/mbean-auto-registration/src/main/java/org/superbiz/mbean/GuessHowManyMBean.java
openejb/trunk/openejb/examples/mbean-auto-registration/src/main/resources/META-INF/beans.xml
openejb/trunk/openejb/examples/mbean-auto-registration/src/test/java/org/superbiz/mbean/GuessHowManyMBeanTest.java
openejb/trunk/openejb/examples/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/beans/BookShow.java
openejb/trunk/openejb/examples/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java
openejb/trunk/openejb/examples/simple-cdi-interceptor/src/main/java/org/superbiz/cdi/bookshow/interceptors/LoggingInterceptor.java
openejb/trunk/openejb/examples/simple-cdi-interceptor/src/main/resources/META-INF/beans.xml
openejb/trunk/openejb/examples/simple-cdi-interceptor/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowTest.java
openejb/trunk/openejb/examples/simple-mdb-with-descriptor/README.md
openejb/trunk/openejb/examples/simple-mdb-with-descriptor/build.xml
openejb/trunk/openejb/examples/simple-mdb-with-descriptor/src/main/resources/META-INF/ejb-jar.xml
openejb/trunk/openejb/examples/simple-osgi/simple-osgi-api/src/main/java/org/superbiz/osgi/calculator/CalculatorLocal.java
openejb/trunk/openejb/examples/simple-osgi/simple-osgi-api/src/main/java/org/superbiz/osgi/calculator/CalculatorRemote.java
openejb/trunk/openejb/examples/simple-osgi/simple-osgi-camel-client/src/main/resources/META-INF/spring/calculator-camel-ctx.xml
openejb/trunk/openejb/examples/simple-osgi/simple-osgi-core/src/main/java/org/superbiz/osgi/calculator/impl/CalculatorBean.java
openejb/trunk/openejb/examples/simple-stateless-with-descriptor/build.xml
openejb/trunk/openejb/examples/simple-stateless-with-descriptor/src/main/resources/META-INF/ejb-jar.xml
openejb/trunk/openejb/examples/webapps/rest-example/README.md
openejb/trunk/openejb/examples/webapps/rest-example/src/main/java/org/superbiz/rest/dao/CommentDAO.java
openejb/trunk/openejb/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/DatedModel.java
openejb/trunk/openejb/examples/webapps/rest-example/src/main/java/org/superbiz/rest/model/Model.java
openejb/trunk/openejb/examples/webservice-inheritance/src/main/java/org/superbiz/inheritance/Item.java
openejb/trunk/openejb/examples/webservice-inheritance/src/main/java/org/superbiz/inheritance/Tower.java
openejb/trunk/openejb/examples/webservice-inheritance/src/main/java/org/superbiz/inheritance/Wakeboard.java
openejb/trunk/openejb/examples/webservice-inheritance/src/main/java/org/superbiz/inheritance/WakeboardBinding.java
openejb/trunk/openejb/examples/webservice-inheritance/src/main/java/org/superbiz/inheritance/Wearable.java
Modified: openejb/trunk/openejb/examples/bean-validation-design-by-contract/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/bean-validation-design-by-contract/README.md?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/bean-validation-design-by-contract/README.md (original)
+++ openejb/trunk/openejb/examples/bean-validation-design-by-contract/README.md Sun Feb 19 22:32:10 2012
@@ -1,217 +1,217 @@
-# Bean Validation - Design By Contract
-
-Bean Validation (aka JSR 303) contains an optional appendix dealing with method validation.
-
-Some implementions of this JSR implement this appendix (Apache bval, Hibernate validator for example).
-
-OpenEJB provides an interceptor which allows you to use this feature to do design by contract.
-
-# Design by contract
-
-The goal is to be able to configure with a finer grain your contract. In the example you specify
-the minimum centimeters a sport man should jump at pole vaulting:
-
- @Local
- public interface PoleVaultingManager {
- int points(@Min(120) int centimeters);
- }
-
-# Usage
-
-To use this feature you have to add the BeanValidationAppendixInterceptor interceptor.
-
-In unit test simply put a properties in your context properties:
-
- properties.setProperty(BeanContext.USER_INTERCEPTOR_KEY, BeanValidationAppendixInterceptor.class.getName());
-
-In a production environment or in tomcat add the properties in conf/system.properties for example:
-
- org.apache.openejb.default.system.interceptors = org.apache.openejb.bval.BeanValidationAppendixInterceptor
-
-# Errors
-
-If a parameter is not validated an exception is thrown, it is an EJBException wrapping a ConstraintViolationException:
-
- try {
- gamesManager.addSportMan("I lose", "EN");
- fail("no space should be in names");
- } catch (EJBException wrappingException) {
- assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
- ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
- assertEquals(1, exception.getConstraintViolations().size());
- }
-
-# Example
-
-## OlympicGamesManager
-
- package org.superbiz.designbycontract;
-
- import javax.ejb.Stateless;
- import javax.validation.constraints.NotNull;
- import javax.validation.constraints.Pattern;
- import javax.validation.constraints.Size;
-
- /**
- * @author Romain Manni-Bucau
- */
- @Stateless
- public class OlympicGamesManager {
- public String addSportMan(@Pattern(regexp = "^[A-Za-z]+$") String name, @Size(min = 2, max = 4) String country) {
- if (country.equals("USA")) {
- return null;
- }
- return new StringBuilder(name).append(" [").append(country).append("]").toString();
- }
- }
-
-## PoleVaultingManager
-
- package org.superbiz.designbycontract;
-
- import javax.ejb.Local;
- import javax.validation.constraints.Min;
-
- /**
- * @author Romain Manni-Bucau
- */
- @Local
- public interface PoleVaultingManager {
- int points(@Min(120) int centimeters);
- }
-
-## PoleVaultingManagerBean
-
- package org.superbiz.designbycontract;
-
- import javax.ejb.Stateless;
-
- /**
- * @author Romain Manni-Bucau
- */
- @Stateless
- public class PoleVaultingManagerBean implements PoleVaultingManager {
- @Override
- public int points(int centimeters) {
- return centimeters - 120;
- }
- }
-
-## OlympicGamesTest
-
- public class OlympicGamesTest {
- private static Context context;
-
- @EJB
- private OlympicGamesManager gamesManager;
-
- @EJB
- private PoleVaultingManager poleVaultingManager;
-
- @BeforeClass
- public static void start() {
- Properties properties = new Properties();
- properties.setProperty(BeanContext.USER_INTERCEPTOR_KEY, BeanValidationAppendixInterceptor.class.getName());
- context = EJBContainer.createEJBContainer(properties).getContext();
- }
-
- @Before
- public void inject() throws Exception {
- context.bind("inject", this);
- }
-
- @AfterClass
- public static void stop() throws Exception {
- if (context != null) {
- context.close();
- }
- }
-
- @Test
- public void sportMenOk() throws Exception {
- assertEquals("IWin [FR]", gamesManager.addSportMan("IWin", "FR"));
- }
-
- @Test
- public void sportMenKoBecauseOfName() throws Exception {
- try {
- gamesManager.addSportMan("I lose", "EN");
- fail("no space should be in names");
- } catch (EJBException wrappingException) {
- assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
- ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
- assertEquals(1, exception.getConstraintViolations().size());
- }
- }
-
- @Test
- public void sportMenKoBecauseOfCountry() throws Exception {
- try {
- gamesManager.addSportMan("ILoseTwo", "TOO-LONG");
- fail("country should be between 2 and 4 characters");
- } catch (EJBException wrappingException) {
- assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
- ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
- assertEquals(1, exception.getConstraintViolations().size());
- }
- }
-
- @Test
- public void polVaulting() throws Exception {
- assertEquals(100, poleVaultingManager.points(220));
- }
-
- @Test
- public void tooShortPolVaulting() throws Exception {
- try {
- poleVaultingManager.points(119);
- fail("the jump is too short");
- } catch (EJBException wrappingException) {
- assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
- ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
- assertEquals(1, exception.getConstraintViolations().size());
- }
- }
- }
-
-# Running
-
-
- -------------------------------------------------------
- T E S T S
- -------------------------------------------------------
- Running OlympicGamesTest
- Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
- http://openejb.apache.org/
- INFO - openejb.home = /Users/dblevins/examples/bean-validation-design-by-contract
- INFO - openejb.base = /Users/dblevins/examples/bean-validation-design-by-contract
- 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: /Users/dblevins/examples/bean-validation-design-by-contract/target/classes
- INFO - Beginning load: /Users/dblevins/examples/bean-validation-design-by-contract/target/classes
- INFO - Configuring enterprise application: /Users/dblevins/examples/bean-validation-design-by-contract
- INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
- INFO - Auto-creating a container for bean PoleVaultingManagerBean: Container(type=STATELESS, id=Default Stateless Container)
- INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
- INFO - Auto-creating a container for bean OlympicGamesTest: Container(type=MANAGED, id=Default Managed Container)
- INFO - Enterprise application "/Users/dblevins/examples/bean-validation-design-by-contract" loaded.
- INFO - Assembling app: /Users/dblevins/examples/bean-validation-design-by-contract
- INFO - Jndi(name="java:global/bean-validation-design-by-contract/PoleVaultingManagerBean!org.superbiz.designbycontract.PoleVaultingManager")
- INFO - Jndi(name="java:global/bean-validation-design-by-contract/PoleVaultingManagerBean")
- INFO - Jndi(name="java:global/bean-validation-design-by-contract/OlympicGamesManager!org.superbiz.designbycontract.OlympicGamesManager")
- INFO - Jndi(name="java:global/bean-validation-design-by-contract/OlympicGamesManager")
- INFO - Jndi(name="java:global/EjbModule236054577/OlympicGamesTest!OlympicGamesTest")
- INFO - Jndi(name="java:global/EjbModule236054577/OlympicGamesTest")
- INFO - Created Ejb(deployment-id=OlympicGamesManager, ejb-name=OlympicGamesManager, container=Default Stateless Container)
- INFO - Created Ejb(deployment-id=PoleVaultingManagerBean, ejb-name=PoleVaultingManagerBean, container=Default Stateless Container)
- INFO - Created Ejb(deployment-id=OlympicGamesTest, ejb-name=OlympicGamesTest, container=Default Managed Container)
- INFO - Started Ejb(deployment-id=OlympicGamesManager, ejb-name=OlympicGamesManager, container=Default Stateless Container)
- INFO - Started Ejb(deployment-id=PoleVaultingManagerBean, ejb-name=PoleVaultingManagerBean, container=Default Stateless Container)
- INFO - Started Ejb(deployment-id=OlympicGamesTest, ejb-name=OlympicGamesTest, container=Default Managed Container)
- INFO - Deployed Application(path=/Users/dblevins/examples/bean-validation-design-by-contract)
- Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.245 sec
-
- Results :
-
- Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
+# Bean Validation - Design By Contract
+
+Bean Validation (aka JSR 303) contains an optional appendix dealing with method validation.
+
+Some implementions of this JSR implement this appendix (Apache bval, Hibernate validator for example).
+
+OpenEJB provides an interceptor which allows you to use this feature to do design by contract.
+
+# Design by contract
+
+The goal is to be able to configure with a finer grain your contract. In the example you specify
+the minimum centimeters a sport man should jump at pole vaulting:
+
+ @Local
+ public interface PoleVaultingManager {
+ int points(@Min(120) int centimeters);
+ }
+
+# Usage
+
+To use this feature you have to add the BeanValidationAppendixInterceptor interceptor.
+
+In unit test simply put a properties in your context properties:
+
+ properties.setProperty(BeanContext.USER_INTERCEPTOR_KEY, BeanValidationAppendixInterceptor.class.getName());
+
+In a production environment or in tomcat add the properties in conf/system.properties for example:
+
+ org.apache.openejb.default.system.interceptors = org.apache.openejb.bval.BeanValidationAppendixInterceptor
+
+# Errors
+
+If a parameter is not validated an exception is thrown, it is an EJBException wrapping a ConstraintViolationException:
+
+ try {
+ gamesManager.addSportMan("I lose", "EN");
+ fail("no space should be in names");
+ } catch (EJBException wrappingException) {
+ assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
+ ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
+ assertEquals(1, exception.getConstraintViolations().size());
+ }
+
+# Example
+
+## OlympicGamesManager
+
+ package org.superbiz.designbycontract;
+
+ import javax.ejb.Stateless;
+ import javax.validation.constraints.NotNull;
+ import javax.validation.constraints.Pattern;
+ import javax.validation.constraints.Size;
+
+ /**
+ * @author Romain Manni-Bucau
+ */
+ @Stateless
+ public class OlympicGamesManager {
+ public String addSportMan(@Pattern(regexp = "^[A-Za-z]+$") String name, @Size(min = 2, max = 4) String country) {
+ if (country.equals("USA")) {
+ return null;
+ }
+ return new StringBuilder(name).append(" [").append(country).append("]").toString();
+ }
+ }
+
+## PoleVaultingManager
+
+ package org.superbiz.designbycontract;
+
+ import javax.ejb.Local;
+ import javax.validation.constraints.Min;
+
+ /**
+ * @author Romain Manni-Bucau
+ */
+ @Local
+ public interface PoleVaultingManager {
+ int points(@Min(120) int centimeters);
+ }
+
+## PoleVaultingManagerBean
+
+ package org.superbiz.designbycontract;
+
+ import javax.ejb.Stateless;
+
+ /**
+ * @author Romain Manni-Bucau
+ */
+ @Stateless
+ public class PoleVaultingManagerBean implements PoleVaultingManager {
+ @Override
+ public int points(int centimeters) {
+ return centimeters - 120;
+ }
+ }
+
+## OlympicGamesTest
+
+ public class OlympicGamesTest {
+ private static Context context;
+
+ @EJB
+ private OlympicGamesManager gamesManager;
+
+ @EJB
+ private PoleVaultingManager poleVaultingManager;
+
+ @BeforeClass
+ public static void start() {
+ Properties properties = new Properties();
+ properties.setProperty(BeanContext.USER_INTERCEPTOR_KEY, BeanValidationAppendixInterceptor.class.getName());
+ context = EJBContainer.createEJBContainer(properties).getContext();
+ }
+
+ @Before
+ public void inject() throws Exception {
+ context.bind("inject", this);
+ }
+
+ @AfterClass
+ public static void stop() throws Exception {
+ if (context != null) {
+ context.close();
+ }
+ }
+
+ @Test
+ public void sportMenOk() throws Exception {
+ assertEquals("IWin [FR]", gamesManager.addSportMan("IWin", "FR"));
+ }
+
+ @Test
+ public void sportMenKoBecauseOfName() throws Exception {
+ try {
+ gamesManager.addSportMan("I lose", "EN");
+ fail("no space should be in names");
+ } catch (EJBException wrappingException) {
+ assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
+ ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
+ assertEquals(1, exception.getConstraintViolations().size());
+ }
+ }
+
+ @Test
+ public void sportMenKoBecauseOfCountry() throws Exception {
+ try {
+ gamesManager.addSportMan("ILoseTwo", "TOO-LONG");
+ fail("country should be between 2 and 4 characters");
+ } catch (EJBException wrappingException) {
+ assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
+ ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
+ assertEquals(1, exception.getConstraintViolations().size());
+ }
+ }
+
+ @Test
+ public void polVaulting() throws Exception {
+ assertEquals(100, poleVaultingManager.points(220));
+ }
+
+ @Test
+ public void tooShortPolVaulting() throws Exception {
+ try {
+ poleVaultingManager.points(119);
+ fail("the jump is too short");
+ } catch (EJBException wrappingException) {
+ assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
+ ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
+ assertEquals(1, exception.getConstraintViolations().size());
+ }
+ }
+ }
+
+# Running
+
+
+ -------------------------------------------------------
+ T E S T S
+ -------------------------------------------------------
+ Running OlympicGamesTest
+ Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06
+ http://openejb.apache.org/
+ INFO - openejb.home = /Users/dblevins/examples/bean-validation-design-by-contract
+ INFO - openejb.base = /Users/dblevins/examples/bean-validation-design-by-contract
+ 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: /Users/dblevins/examples/bean-validation-design-by-contract/target/classes
+ INFO - Beginning load: /Users/dblevins/examples/bean-validation-design-by-contract/target/classes
+ INFO - Configuring enterprise application: /Users/dblevins/examples/bean-validation-design-by-contract
+ INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
+ INFO - Auto-creating a container for bean PoleVaultingManagerBean: Container(type=STATELESS, id=Default Stateless Container)
+ INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+ INFO - Auto-creating a container for bean OlympicGamesTest: Container(type=MANAGED, id=Default Managed Container)
+ INFO - Enterprise application "/Users/dblevins/examples/bean-validation-design-by-contract" loaded.
+ INFO - Assembling app: /Users/dblevins/examples/bean-validation-design-by-contract
+ INFO - Jndi(name="java:global/bean-validation-design-by-contract/PoleVaultingManagerBean!org.superbiz.designbycontract.PoleVaultingManager")
+ INFO - Jndi(name="java:global/bean-validation-design-by-contract/PoleVaultingManagerBean")
+ INFO - Jndi(name="java:global/bean-validation-design-by-contract/OlympicGamesManager!org.superbiz.designbycontract.OlympicGamesManager")
+ INFO - Jndi(name="java:global/bean-validation-design-by-contract/OlympicGamesManager")
+ INFO - Jndi(name="java:global/EjbModule236054577/OlympicGamesTest!OlympicGamesTest")
+ INFO - Jndi(name="java:global/EjbModule236054577/OlympicGamesTest")
+ INFO - Created Ejb(deployment-id=OlympicGamesManager, ejb-name=OlympicGamesManager, container=Default Stateless Container)
+ INFO - Created Ejb(deployment-id=PoleVaultingManagerBean, ejb-name=PoleVaultingManagerBean, container=Default Stateless Container)
+ INFO - Created Ejb(deployment-id=OlympicGamesTest, ejb-name=OlympicGamesTest, container=Default Managed Container)
+ INFO - Started Ejb(deployment-id=OlympicGamesManager, ejb-name=OlympicGamesManager, container=Default Stateless Container)
+ INFO - Started Ejb(deployment-id=PoleVaultingManagerBean, ejb-name=PoleVaultingManagerBean, container=Default Stateless Container)
+ INFO - Started Ejb(deployment-id=OlympicGamesTest, ejb-name=OlympicGamesTest, container=Default Managed Container)
+ INFO - Deployed Application(path=/Users/dblevins/examples/bean-validation-design-by-contract)
+ Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.245 sec
+
+ Results :
+
+ Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
Modified: openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/OlympicGamesManager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/OlympicGamesManager.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/OlympicGamesManager.java (original)
+++ openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/OlympicGamesManager.java Sun Feb 19 22:32:10 2012
@@ -1,31 +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.superbiz.designbycontract;
-
-import javax.ejb.Stateless;
-import javax.validation.constraints.Pattern;
-import javax.validation.constraints.Size;
-
-@Stateless
-public class OlympicGamesManager {
- public String addSportMan(@Pattern(regexp = "^[A-Za-z]+$") String name, @Size(min = 2, max = 4) String country) {
- if (country.equals("USA")) {
- return null;
- }
- return new StringBuilder(name).append(" [").append(country).append("]").toString();
- }
-}
+/**
+ * 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.designbycontract;
+
+import javax.ejb.Stateless;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+
+@Stateless
+public class OlympicGamesManager {
+ public String addSportMan(@Pattern(regexp = "^[A-Za-z]+$") String name, @Size(min = 2, max = 4) String country) {
+ if (country.equals("USA")) {
+ return null;
+ }
+ return new StringBuilder(name).append(" [").append(country).append("]").toString();
+ }
+}
Modified: openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/PoleVaultingManager.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/PoleVaultingManager.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/PoleVaultingManager.java (original)
+++ openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/PoleVaultingManager.java Sun Feb 19 22:32:10 2012
@@ -1,25 +1,25 @@
-/**
- * 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.designbycontract;
-
-import javax.ejb.Local;
-import javax.validation.constraints.Min;
-
-@Local
-public interface PoleVaultingManager {
- int points(@Min(120) int centimeters);
-}
+/**
+ * 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.designbycontract;
+
+import javax.ejb.Local;
+import javax.validation.constraints.Min;
+
+@Local
+public interface PoleVaultingManager {
+ int points(@Min(120) int centimeters);
+}
Modified: openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/PoleVaultingManagerBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/PoleVaultingManagerBean.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/PoleVaultingManagerBean.java (original)
+++ openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/PoleVaultingManagerBean.java Sun Feb 19 22:32:10 2012
@@ -1,27 +1,27 @@
-/**
- * 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.designbycontract;
-
-import javax.ejb.Stateless;
-
-@Stateless
-public class PoleVaultingManagerBean implements PoleVaultingManager {
- @Override
- public int points(int centimeters) {
- return centimeters - 120;
- }
-}
+/**
+ * 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.designbycontract;
+
+import javax.ejb.Stateless;
+
+@Stateless
+public class PoleVaultingManagerBean implements PoleVaultingManager {
+ @Override
+ public int points(int centimeters) {
+ return centimeters - 120;
+ }
+}
Modified: openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/test/java/OlympicGamesTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/test/java/OlympicGamesTest.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/test/java/OlympicGamesTest.java (original)
+++ openejb/trunk/openejb/examples/bean-validation-design-by-contract/src/test/java/OlympicGamesTest.java Sun Feb 19 22:32:10 2012
@@ -1,113 +1,113 @@
-/*
- * 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.
- */
-
-import org.apache.openejb.BeanContext;
-import org.apache.openejb.bval.BeanValidationAppendixInterceptor;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.superbiz.designbycontract.OlympicGamesManager;
-import org.superbiz.designbycontract.PoleVaultingManager;
-
-import javax.ejb.EJB;
-import javax.ejb.EJBException;
-import javax.ejb.embeddable.EJBContainer;
-import javax.naming.Context;
-import javax.validation.ConstraintViolationException;
-import java.util.Properties;
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
-import static junit.framework.Assert.fail;
-
-// TODO This needs to be in a non-default package
-
-public class OlympicGamesTest {
- private static Context context;
-
- @EJB
- private OlympicGamesManager gamesManager;
-
- @EJB
- private PoleVaultingManager poleVaultingManager;
-
- @BeforeClass
- public static void start() {
- Properties properties = new Properties();
- properties.setProperty(BeanContext.USER_INTERCEPTOR_KEY, BeanValidationAppendixInterceptor.class.getName());
- context = EJBContainer.createEJBContainer(properties).getContext();
- }
-
- @Before
- public void inject() throws Exception {
- context.bind("inject", this);
- }
-
- @AfterClass
- public static void stop() throws Exception {
- if (context != null) {
- context.close();
- }
- }
-
- @Test
- public void sportMenOk() throws Exception {
- assertEquals("IWin [FR]", gamesManager.addSportMan("IWin", "FR"));
- }
-
- @Test
- public void sportMenKoBecauseOfName() throws Exception {
- try {
- gamesManager.addSportMan("I lose", "EN");
- fail("no space should be in names");
- } catch (EJBException wrappingException) {
- assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
- ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
- assertEquals(1, exception.getConstraintViolations().size());
- }
- }
-
- @Test
- public void sportMenKoBecauseOfCountry() throws Exception {
- try {
- gamesManager.addSportMan("ILoseTwo", "TOO-LONG");
- fail("country should be between 2 and 4 characters");
- } catch (EJBException wrappingException) {
- assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
- ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
- assertEquals(1, exception.getConstraintViolations().size());
- }
- }
-
- @Test
- public void polVaulting() throws Exception {
- assertEquals(100, poleVaultingManager.points(220));
- }
-
- @Test
- public void tooShortPolVaulting() throws Exception {
- try {
- poleVaultingManager.points(119);
- fail("the jump is too short");
- } catch (EJBException wrappingException) {
- assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
- ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
- assertEquals(1, exception.getConstraintViolations().size());
- }
- }
-}
+/*
+ * 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.
+ */
+
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.bval.BeanValidationAppendixInterceptor;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.superbiz.designbycontract.OlympicGamesManager;
+import org.superbiz.designbycontract.PoleVaultingManager;
+
+import javax.ejb.EJB;
+import javax.ejb.EJBException;
+import javax.ejb.embeddable.EJBContainer;
+import javax.naming.Context;
+import javax.validation.ConstraintViolationException;
+import java.util.Properties;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
+
+// TODO This needs to be in a non-default package
+
+public class OlympicGamesTest {
+ private static Context context;
+
+ @EJB
+ private OlympicGamesManager gamesManager;
+
+ @EJB
+ private PoleVaultingManager poleVaultingManager;
+
+ @BeforeClass
+ public static void start() {
+ Properties properties = new Properties();
+ properties.setProperty(BeanContext.USER_INTERCEPTOR_KEY, BeanValidationAppendixInterceptor.class.getName());
+ context = EJBContainer.createEJBContainer(properties).getContext();
+ }
+
+ @Before
+ public void inject() throws Exception {
+ context.bind("inject", this);
+ }
+
+ @AfterClass
+ public static void stop() throws Exception {
+ if (context != null) {
+ context.close();
+ }
+ }
+
+ @Test
+ public void sportMenOk() throws Exception {
+ assertEquals("IWin [FR]", gamesManager.addSportMan("IWin", "FR"));
+ }
+
+ @Test
+ public void sportMenKoBecauseOfName() throws Exception {
+ try {
+ gamesManager.addSportMan("I lose", "EN");
+ fail("no space should be in names");
+ } catch (EJBException wrappingException) {
+ assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
+ ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
+ assertEquals(1, exception.getConstraintViolations().size());
+ }
+ }
+
+ @Test
+ public void sportMenKoBecauseOfCountry() throws Exception {
+ try {
+ gamesManager.addSportMan("ILoseTwo", "TOO-LONG");
+ fail("country should be between 2 and 4 characters");
+ } catch (EJBException wrappingException) {
+ assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
+ ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
+ assertEquals(1, exception.getConstraintViolations().size());
+ }
+ }
+
+ @Test
+ public void polVaulting() throws Exception {
+ assertEquals(100, poleVaultingManager.points(220));
+ }
+
+ @Test
+ public void tooShortPolVaulting() throws Exception {
+ try {
+ poleVaultingManager.points(119);
+ fail("the jump is too short");
+ } catch (EJBException wrappingException) {
+ assertTrue(wrappingException.getCause() instanceof ConstraintViolationException);
+ ConstraintViolationException exception = ConstraintViolationException.class.cast(wrappingException.getCausedByException());
+ assertEquals(1, exception.getConstraintViolations().size());
+ }
+ }
+}
Modified: openejb/trunk/openejb/examples/cdi-interceptors/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/README.md?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/README.md (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/README.md Sun Feb 19 22:32:10 2012
@@ -1,216 +1,216 @@
-Title: CDI Interceptors
-
-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. Apart from that, there are some methods in our application, that can be accessed only in the working hours. If accessed at non-working-hours we'll throw out an AccessDeniedException.
-
-How do we mark which methods are to be intercepted? Wouldn't it be handy to annotate a method like
-
- @Log
- public void aMethod(){...}
-
-or
-
- @TimeRestricted
- public void bMethod(){...}
-
-Let's create these annotations that would "mark" a method for interception.
-
- @InterceptorBinding
- @Target({ TYPE, METHOD })
- @Retention(RUNTIME)
- public @interface Log {
- }
-
-And
-
- @InterceptorBinding
- @Target({ TYPE, METHOD })
- @Retention(RUNTIME)
- public @interface TimeRestricted {
- }
-
-Sure, you haven't missed the `@InterceptorBinding` annotation above! Now that our custom annotations are created, lets attach them (or to use a better term for it, "bind them") to interceptors.
-
-So here's our logging interceptor. An `@AroundInvoke` method and we are almost done.
-
- @Interceptor
- @Log //binding the interceptor here. now any method annotated with @Log would be intercepted by logMethodEntry
- public class BookForAShowLoggingInterceptor implements Serializable {
- private static final long serialVersionUID = 8139854519874743530L;
- private Logger logger = Logger.getLogger("BookForAShowApplicationLogger");
- @AroundInvoke
- public Object logMethodEntry(InvocationContext ctx) throws Exception {
- logger.info("Before entering method:" + ctx.getMethod().getName());
- InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName());
- InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName());
- return ctx.proceed();
- }
- }
-
-Now the `@Log` annotation we created is bound to this interceptor. (Likewise we bind `@TimeRestrict` for `TimeBasedRestrictingInterceptor`. See links below for source)
-
-That done, let's annotate at class-level or method-level and have fun intercepting!
-
- @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
- }
-
-The `@Log` annotation applied at class level denotes that all the methods should be intercepted with `BookForAShowLoggingInterceptor`.
-
-Before we say "all done" there's one last thing we are left with! To enable the interceptors!
-
-Lets quickly put up a `beans.xml` file like the following in `src/main/resources/META-INF/beans.xml`:
-
- <beans>
- <interceptors>
- <class>org.superbiz.cdi.bookshow.interceptors.BookForAShowLoggingInterceptor
- </class>
- <class>org.superbiz.cdi.bookshow.interceptors.TimeBasedRestrictingInterceptor
- </class>
- </interceptors>
- </beans>
-
-
-By default, a bean archive has no enabled interceptors bound via interceptor
-bindings. An interceptor must be explicitly enabled by listing its class
-in the `beans.xml`.
-
-Those lines in `beans.xml` not only "enable" the interceptors, but also define the "order of execution" of the interceptors.
-
-The order in with a method is annotated has no real significance.
-Eg:
-
- @TimeRestrict
- @Log
- void cMethod(){}
-
-Here the `BookForAShowLoggingInterceptor` would be applied first and then `TimeBasedRestrictingInterceptor`
-
-So now you know that the order is only determined by the order of definition in `beans.xml`. Interceptors which occur earlier in the list are called first.
-
-Also note that a method can be marked for interception by multiple interceptors by applying multiple annotations as above.
-
-This brings us to another question. In the above case there were two interceptors applied together. What if I would require about 4 such interceptors that would go along.... Having to annotate so much makes the code a little clumsy?
-
-No worries! Just create a custom annotation which inherits from others
-
- @Inherited
- @InterceptorBinding
- @Target({ TYPE, METHOD })
- @Retention(RUNTIME)
- @Log
- @TimeRestricted
- public @interface TimeRestrictAndLog {
- }
-
-This is interceptor binding inheritance.
-
-The code below demonstrates the many cases that we have discussed.
-
-Not to forget, the old style binding with `@Interceptors(WhicheverInterceptor.class)` is also supported. Have a look at `BookForAShowOldStyleInterceptorBinding` where the comments explain how the newer way discussed above is better.
-
-# The Code
-
-## BookForAShowOneInterceptorApplied
-
-`BookForAShowOneInterceptorApplied` shows a simple `@Log` interceptor applied.
-
- package org.superbiz.cdi.bookshow.beans;
-
- import org.superbiz.cdi.bookshow.interceptorbinding.Log;
-
- import javax.ejb.Stateful;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.List;
-
- @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;
- }
- }
-
-## BookForAShowTwoInterceptorsApplied
-
-`BookForAShowTwoInterceptorsApplied` shows both `@Log` and `@TimeRestricted` being applied.
-
- package org.superbiz.cdi.bookshow.beans;
-
- import org.superbiz.cdi.bookshow.interceptorbinding.Log;
- import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestricted;
-
- import javax.ejb.Stateful;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.List;
-
- @Log
- @Stateful
- public class BookForAShowTwoInterceptorsApplied 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;
- }
-
- @TimeRestricted
- public Integer getDiscountedPrice(int ticketPrice) {
- return ticketPrice - 50;
- }
- }
-
-## BookShowInterceptorBindingInheritanceExplored
-
-`BookShowInterceptorBindingInheritanceExplored` shows how `@TimeRestrictAndLog` (interceptor-binding-inheritance) can be used as an alternative for annotating a method with multiple annotations explicitly.
-
- package org.superbiz.cdi.bookshow.beans;
-
- import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestrictAndLog;
-
- import javax.ejb.Stateful;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.List;
-
- @Stateful
- public class BookShowInterceptorBindingInheritanceExplored 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;
- }
-
- @TimeRestrictAndLog
- public Integer getDiscountedPrice(int ticketPrice) {
- return ticketPrice - 50;
- }
- }
-
+Title: CDI Interceptors
+
+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. Apart from that, there are some methods in our application, that can be accessed only in the working hours. If accessed at non-working-hours we'll throw out an AccessDeniedException.
+
+How do we mark which methods are to be intercepted? Wouldn't it be handy to annotate a method like
+
+ @Log
+ public void aMethod(){...}
+
+or
+
+ @TimeRestricted
+ public void bMethod(){...}
+
+Let's create these annotations that would "mark" a method for interception.
+
+ @InterceptorBinding
+ @Target({ TYPE, METHOD })
+ @Retention(RUNTIME)
+ public @interface Log {
+ }
+
+And
+
+ @InterceptorBinding
+ @Target({ TYPE, METHOD })
+ @Retention(RUNTIME)
+ public @interface TimeRestricted {
+ }
+
+Sure, you haven't missed the `@InterceptorBinding` annotation above! Now that our custom annotations are created, lets attach them (or to use a better term for it, "bind them") to interceptors.
+
+So here's our logging interceptor. An `@AroundInvoke` method and we are almost done.
+
+ @Interceptor
+ @Log //binding the interceptor here. now any method annotated with @Log would be intercepted by logMethodEntry
+ public class BookForAShowLoggingInterceptor implements Serializable {
+ private static final long serialVersionUID = 8139854519874743530L;
+ private Logger logger = Logger.getLogger("BookForAShowApplicationLogger");
+ @AroundInvoke
+ public Object logMethodEntry(InvocationContext ctx) throws Exception {
+ logger.info("Before entering method:" + ctx.getMethod().getName());
+ InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName());
+ InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName());
+ return ctx.proceed();
+ }
+ }
+
+Now the `@Log` annotation we created is bound to this interceptor. (Likewise we bind `@TimeRestrict` for `TimeBasedRestrictingInterceptor`. See links below for source)
+
+That done, let's annotate at class-level or method-level and have fun intercepting!
+
+ @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
+ }
+
+The `@Log` annotation applied at class level denotes that all the methods should be intercepted with `BookForAShowLoggingInterceptor`.
+
+Before we say "all done" there's one last thing we are left with! To enable the interceptors!
+
+Lets quickly put up a `beans.xml` file like the following in `src/main/resources/META-INF/beans.xml`:
+
+ <beans>
+ <interceptors>
+ <class>org.superbiz.cdi.bookshow.interceptors.BookForAShowLoggingInterceptor
+ </class>
+ <class>org.superbiz.cdi.bookshow.interceptors.TimeBasedRestrictingInterceptor
+ </class>
+ </interceptors>
+ </beans>
+
+
+By default, a bean archive has no enabled interceptors bound via interceptor
+bindings. An interceptor must be explicitly enabled by listing its class
+in the `beans.xml`.
+
+Those lines in `beans.xml` not only "enable" the interceptors, but also define the "order of execution" of the interceptors.
+
+The order in with a method is annotated has no real significance.
+Eg:
+
+ @TimeRestrict
+ @Log
+ void cMethod(){}
+
+Here the `BookForAShowLoggingInterceptor` would be applied first and then `TimeBasedRestrictingInterceptor`
+
+So now you know that the order is only determined by the order of definition in `beans.xml`. Interceptors which occur earlier in the list are called first.
+
+Also note that a method can be marked for interception by multiple interceptors by applying multiple annotations as above.
+
+This brings us to another question. In the above case there were two interceptors applied together. What if I would require about 4 such interceptors that would go along.... Having to annotate so much makes the code a little clumsy?
+
+No worries! Just create a custom annotation which inherits from others
+
+ @Inherited
+ @InterceptorBinding
+ @Target({ TYPE, METHOD })
+ @Retention(RUNTIME)
+ @Log
+ @TimeRestricted
+ public @interface TimeRestrictAndLog {
+ }
+
+This is interceptor binding inheritance.
+
+The code below demonstrates the many cases that we have discussed.
+
+Not to forget, the old style binding with `@Interceptors(WhicheverInterceptor.class)` is also supported. Have a look at `BookForAShowOldStyleInterceptorBinding` where the comments explain how the newer way discussed above is better.
+
+# The Code
+
+## BookForAShowOneInterceptorApplied
+
+`BookForAShowOneInterceptorApplied` shows a simple `@Log` interceptor applied.
+
+ package org.superbiz.cdi.bookshow.beans;
+
+ import org.superbiz.cdi.bookshow.interceptorbinding.Log;
+
+ import javax.ejb.Stateful;
+ import java.io.Serializable;
+ import java.util.ArrayList;
+ import java.util.List;
+
+ @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;
+ }
+ }
+
+## BookForAShowTwoInterceptorsApplied
+
+`BookForAShowTwoInterceptorsApplied` shows both `@Log` and `@TimeRestricted` being applied.
+
+ package org.superbiz.cdi.bookshow.beans;
+
+ import org.superbiz.cdi.bookshow.interceptorbinding.Log;
+ import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestricted;
+
+ import javax.ejb.Stateful;
+ import java.io.Serializable;
+ import java.util.ArrayList;
+ import java.util.List;
+
+ @Log
+ @Stateful
+ public class BookForAShowTwoInterceptorsApplied 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;
+ }
+
+ @TimeRestricted
+ public Integer getDiscountedPrice(int ticketPrice) {
+ return ticketPrice - 50;
+ }
+ }
+
+## BookShowInterceptorBindingInheritanceExplored
+
+`BookShowInterceptorBindingInheritanceExplored` shows how `@TimeRestrictAndLog` (interceptor-binding-inheritance) can be used as an alternative for annotating a method with multiple annotations explicitly.
+
+ package org.superbiz.cdi.bookshow.beans;
+
+ import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestrictAndLog;
+
+ import javax.ejb.Stateful;
+ import java.io.Serializable;
+ import java.util.ArrayList;
+ import java.util.List;
+
+ @Stateful
+ public class BookShowInterceptorBindingInheritanceExplored 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;
+ }
+
+ @TimeRestrictAndLog
+ public Integer getDiscountedPrice(int ticketPrice) {
+ return ticketPrice - 50;
+ }
+ }
+
Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/AccessDeniedException.java Sun Feb 19 22:32:10 2012
@@ -1,31 +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.superbiz.cdi;
-
-import javax.ejb.ApplicationException;
-
-/**
- * @version $Revision$ $Date$
- */
-@ApplicationException
-public class AccessDeniedException extends RuntimeException {
- private static final long serialVersionUID = 1L;
-
- public AccessDeniedException(String s) {
- super(s);
- }
-}
+/**
+ * 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;
+
+import javax.ejb.ApplicationException;
+
+/**
+ * @version $Revision$ $Date$
+ */
+@ApplicationException
+public class AccessDeniedException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ public AccessDeniedException(String s) {
+ super(s);
+ }
+}
Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOldStyleInterceptorBinding.java Sun Feb 19 22:32:10 2012
@@ -1,52 +1,52 @@
-/**
- * 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 org.superbiz.cdi.bookshow.interceptorbinding.Log;
-import org.superbiz.cdi.bookshow.interceptors.BookForAShowLoggingInterceptor;
-
-import javax.ejb.Stateful;
-import javax.interceptor.Interceptors;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * CDI supports binding an interceptor using @Interceptors
- * Not recommended though. Has its disadvantages
- * Cannot be disabled easily
- * Order dependent on how it is listed in class
- * Instead, create interceptor bindings using @InterceptorBinding and bind them
- * See {@link Log}, {@link BookForAShowOneInterceptorApplied}, {@link BookForAShowLoggingInterceptor}
- */
-@Interceptors(BookForAShowLoggingInterceptor.class)
-@Stateful
-public class BookForAShowOldStyleInterceptorBinding implements Serializable {
- private static final long serialVersionUID = 6350400892234496909L;
-
- public List<String> getMoviesList() {
- List<String> moviesAvailable = new ArrayList<String>();
- moviesAvailable.add("KungFu Panda 2");
- moviesAvailable.add("Kings speech");
- return moviesAvailable;
- }
-
- public Integer getDiscountedPrice(int ticketPrice) {
- return ticketPrice - 50;
- }
- // assume more methods are present
-}
+/**
+ * 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 org.superbiz.cdi.bookshow.interceptorbinding.Log;
+import org.superbiz.cdi.bookshow.interceptors.BookForAShowLoggingInterceptor;
+
+import javax.ejb.Stateful;
+import javax.interceptor.Interceptors;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * CDI supports binding an interceptor using @Interceptors
+ * Not recommended though. Has its disadvantages
+ * Cannot be disabled easily
+ * Order dependent on how it is listed in class
+ * Instead, create interceptor bindings using @InterceptorBinding and bind them
+ * See {@link Log}, {@link BookForAShowOneInterceptorApplied}, {@link BookForAShowLoggingInterceptor}
+ */
+@Interceptors(BookForAShowLoggingInterceptor.class)
+@Stateful
+public class BookForAShowOldStyleInterceptorBinding implements Serializable {
+ private static final long serialVersionUID = 6350400892234496909L;
+
+ public List<String> getMoviesList() {
+ List<String> moviesAvailable = new ArrayList<String>();
+ moviesAvailable.add("KungFu Panda 2");
+ moviesAvailable.add("Kings speech");
+ return moviesAvailable;
+ }
+
+ public Integer getDiscountedPrice(int ticketPrice) {
+ return ticketPrice - 50;
+ }
+ // assume more methods are present
+}
Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowOneInterceptorApplied.java Sun Feb 19 22:32:10 2012
@@ -1,42 +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 org.superbiz.cdi.bookshow.interceptorbinding.Log;
-
-import javax.ejb.Stateful;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-@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
-}
+/**
+ * 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 org.superbiz.cdi.bookshow.interceptorbinding.Log;
+
+import javax.ejb.Stateful;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+@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
+}
Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookForAShowTwoInterceptorsApplied.java Sun Feb 19 22:32:10 2012
@@ -1,44 +1,44 @@
-/**
- * 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 org.superbiz.cdi.bookshow.interceptorbinding.Log;
-import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestricted;
-
-import javax.ejb.Stateful;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-@Log
-@Stateful
-public class BookForAShowTwoInterceptorsApplied 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;
- }
-
- @TimeRestricted
- public Integer getDiscountedPrice(int ticketPrice) {
- return ticketPrice - 50;
- }
- // assume more methods are present
-}
+/**
+ * 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 org.superbiz.cdi.bookshow.interceptorbinding.Log;
+import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestricted;
+
+import javax.ejb.Stateful;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+@Log
+@Stateful
+public class BookForAShowTwoInterceptorsApplied 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;
+ }
+
+ @TimeRestricted
+ public Integer getDiscountedPrice(int ticketPrice) {
+ return ticketPrice - 50;
+ }
+ // assume more methods are present
+}
Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/beans/BookShowInterceptorBindingInheritanceExplored.java Sun Feb 19 22:32:10 2012
@@ -1,42 +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 org.superbiz.cdi.bookshow.interceptorbinding.TimeRestrictAndLog;
-
-import javax.ejb.Stateful;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-@Stateful
-public class BookShowInterceptorBindingInheritanceExplored 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;
- }
-
- @TimeRestrictAndLog
- public Integer getDiscountedPrice(int ticketPrice) {
- return ticketPrice - 50;
- }
- // assume more methods are present
-}
+/**
+ * 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 org.superbiz.cdi.bookshow.interceptorbinding.TimeRestrictAndLog;
+
+import javax.ejb.Stateful;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+@Stateful
+public class BookShowInterceptorBindingInheritanceExplored 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;
+ }
+
+ @TimeRestrictAndLog
+ public Integer getDiscountedPrice(int ticketPrice) {
+ return ticketPrice - 50;
+ }
+ // assume more methods are present
+}
Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/Log.java Sun Feb 19 22:32:10 2012
@@ -1,31 +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.superbiz.cdi.bookshow.interceptorbinding;
-
-import javax.interceptor.InterceptorBinding;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-@InterceptorBinding
-@Target({TYPE, METHOD})
-@Retention(RUNTIME)
-public @interface Log {
-}
+/**
+ * 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 javax.interceptor.InterceptorBinding;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@InterceptorBinding
+@Target({TYPE, METHOD})
+@Retention(RUNTIME)
+public @interface Log {
+}