summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/PricerBean.java
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/PricerBean.java
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/PricerBean.java')
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/PricerBean.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/PricerBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/PricerBean.java
new file mode 100644
index 0000000..58697d6
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Micah Examples/src/examples/stateless/PricerBean.java
@@ -0,0 +1,66 @@
+package examples.stateless;
+
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.Stateless;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptors;
+import javax.interceptor.InvocationContext;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import examples.stateless.interceptors.AuditorInterceptor;
+import examples.stateless.interceptors.LoggerInterceptor;
+import examples.stateless.interfaces.PricerInjection;
+import examples.stateless.interfaces.PricerLookup;
+import examples.stateless.interfaces.TaxRate;
+
+@Stateless
+@Interceptors({LoggerInterceptor.class,AuditorInterceptor.class})
+@Remote({PricerInjection.class,PricerLookup.class})
+public class PricerBean implements PricerInjection, PricerLookup {
+ private TaxRate taxRate;
+
+ @EJB
+ private TaxRate taxRate2;
+
+ public double getTaxLookup(double cost, String state) {
+ double tax = -1;
+ tax = cost * taxRate.getTaxRate(state);
+ return tax;
+ }
+
+ public double getTaxInjection(double cost, String state) {
+ double tax = -1;
+ tax = cost * taxRate2.getTaxRate(state);
+ return tax;
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ try {
+ InitialContext ic = new InitialContext();
+ taxRate = (TaxRate)ic.lookup(TaxRate.class.getName());
+ }
+ catch (NamingException e) {
+ // some kind of appropriate handling here
+ }
+ }
+
+ @PreDestroy
+ public void preDestroy() {
+ taxRate = null;
+ }
+
+ @AroundInvoke
+ public Object logger(InvocationContext inv) throws Exception {
+ System.out.println("Intercepted call via internal method 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();
+ }
+}