summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors')
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/AuditorInterceptor.java18
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/LoggerInterceptor.java16
2 files changed, 34 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/AuditorInterceptor.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/AuditorInterceptor.java
new file mode 100644
index 0000000..853a891
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/AuditorInterceptor.java
@@ -0,0 +1,18 @@
+package examples.stateless.interceptors;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+public class AuditorInterceptor {
+ @AroundInvoke
+ public Object checkCost(InvocationContext inv) throws Exception {
+ if (inv.getMethod().getName().startsWith("getTax")) {
+ Object[] o = inv.getParameters();
+ double cost = ((Double)o[0]).doubleValue();
+ if (cost > 50) {
+ System.out.println("Cost is > 50!");
+ }
+ }
+ return inv.proceed();
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/LoggerInterceptor.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/LoggerInterceptor.java
new file mode 100644
index 0000000..ee37d23
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/interceptors/LoggerInterceptor.java
@@ -0,0 +1,16 @@
+package examples.stateless.interceptors;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+public class LoggerInterceptor {
+ @AroundInvoke
+ public Object logger(InvocationContext inv) throws Exception {
+ System.out.println("Intercepted call via external class to: "+inv.getMethod().getName());
+ Object[] params = inv.getParameters();
+ for (int i=0;i<params.length;i++) {
+ System.out.println("\tparam: "+params[i]);
+ }
+ return inv.proceed();
+ }
+}