summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src
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/Gerald Examples/src
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src')
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/annotations/CodeCategory.java18
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/annotations/FirstTest.javabin0 -> 1376 bytes
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/Account.java1
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountBean.java70
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountClient.java1
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountInterface.java13
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/Bank.java60
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/BankBean.java119
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/Client.java1
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/ConflictingClient.java1
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/META-INF/persistence.xml13
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/MyListener.java34
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/build.xml32
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Client.java22
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/InitContext.java11
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGenerator.java13
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java29
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Startup.java32
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/build.xml62
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/jndi.properties4
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogBean.java33
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogClient.java38
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/META-INF/sun-ejb-jar.xml20
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java40
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/Readme11
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/build.xml30
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogBean.java22
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogClient.java34
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/ejb-jar.xml19
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/sun-ejb-jar.xml13
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/build.xml30
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/Count.java24
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountBean.java53
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountCallbacks.java53
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java63
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/META-INF/ejb-jar.xml5
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/build.xml29
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/Count.java24
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountBean.java47
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountCallbacks.java43
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountClient.java63
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/META-INF/ejb-jar.xml35
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/build.xml32
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/Hello.java13
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/HelloBean.java16
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/HelloClient.java35
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/META-INF/ejb-jar.xml5
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/build.xml32
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/Hello.java15
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/HelloBean.java18
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/JAXWSClient.java40
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/META-INF/ejb-jar.xml5
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/build.xml72
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/application.xml21
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/ejb-jar.xml22
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/persistence.xml13
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/sun-ejb-jar.xml13
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/WEB-INF/sun-web.xml5
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/WEB-INF/web.xml38
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/build.xml87
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/PricerClient.java52
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/SetupClient.java58
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Customer.java104
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/LineItem.java132
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Order.java183
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Product.java93
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/mdb/OrderProcessorBean.java68
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/CartBean.java320
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/CatalogBean.java41
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/PricerBean.java138
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/UserManagerBean.java86
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/Cart.java81
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/Catalog.java31
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/InvalidLoginNameException.java19
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/InvalidPasswordException.java19
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/OrderException.java19
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/Pricer.java50
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/PricerException.java19
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/UserManager.java38
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/catalog.jsp44
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/clearQuote.jsp15
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/emptyQuote.jsp15
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/error.jsp11
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/footer.jsp5
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/login.jsp70
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/productInfo.jsp32
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/receipt.jsp19
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/showQuote.jsp87
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/title.jsp8
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/wsf.jsp22
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/servlet/CatalogServlet.java167
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/servlet/LoginServlet.java166
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/servlet/ShowQuoteServlet.java200
93 files changed, 4159 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/annotations/CodeCategory.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/annotations/CodeCategory.java
new file mode 100644
index 0000000..2b77770
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/annotations/CodeCategory.java
@@ -0,0 +1,18 @@
+package examples.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+enum Visibility {
+ INTERNAL, PUBLIC
+}
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface CodeCategory {
+ Visibility visibility() default Visibility.INTERNAL;
+ boolean isUnitTested() default false;
+ boolean isReviewed() default false;
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/annotations/FirstTest.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/annotations/FirstTest.java
new file mode 100644
index 0000000..6980ac9
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/annotations/FirstTest.java
Binary files differ
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/Account.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/Account.java
new file mode 100644
index 0000000..1efa132
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/Account.java
@@ -0,0 +1 @@
+package examples.entity.intro; import java.io.Serializable; import javax.persistence.AccessType; import javax.persistence.Entity; import javax.persistence.EntityListener; import javax.persistence.Id; import javax.persistence.NamedQuery; import javax.persistence.PostLoad; import javax.persistence.PostUpdate; import javax.persistence.PrePersist; import javax.persistence.PreUpdate; import javax.persistence.Version; /** * This demo entity represents a Bank Account. * <p> * The entity is not a remote object and can only be accessed locally by * clients. However, it is made serializable so that instances can be passed by * value to remote clients for local inspection. * <p> * Access to persistent state is by direct field access. */ @Entity(access = AccessType.FIELD) @EntityListener(MyListener.class) @NamedQuery(name="findThem", query="SELECT a FROM Account a") public class Account implements Serializable { /** The account number is the primary key for the persistent object */ @Id public int accountNumber; public String ownerName; public int balance; @Version public int version; /** * Entity beans must have a public no-arg constructor */ public Account() { // our own primary key generation, workaround for the // time being as Glassfish persistence does not support // auto-generation accountNumber = (int) System.nanoTime(); } public String toString() { return "Acc.# " + accountNumber + ", owner" + ownerName + ", balance: " + balance + " $"; } @PrePersist void prepersist() { System.out.println("pre persist!!"); } @PreUpdate void preupdate() { System.out.println("pre update!!"); } @PostUpdate void postupdate() { System.out.println("post update!!"); } @PostLoad void postload() { System.out.println("post load!!"); } } \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountBean.java
new file mode 100644
index 0000000..45f05c3
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountBean.java
@@ -0,0 +1,70 @@
+package examples.entity.intro;
+
+import javax.ejb.Interceptors;
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.persistence.EntityListener;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+
+/**
+ * Stateful session bean facade for account entities, remotely accessible
+ */
+
+@Stateful
+@Remote(AccountInterface.class)
+public class AccountBean implements AccountInterface {
+
+ /** The entity manager, injected by the container */
+ @PersistenceContext(type=PersistenceContextType.EXTENDED)
+ private EntityManager manager;
+
+ private Account account;
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public void open(int accountNumber) {
+ account = manager.find(Account.class, accountNumber);
+ if(account == null)
+ account = new Account();
+
+ account.ownerName = "anonymous";
+ account.accountNumber = accountNumber;
+ manager.persist(account);
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public int getBalance() {
+ if(account==null)
+ throw new IllegalStateException();
+ return account.balance;
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public void deposit(int amount) {
+ if(account==null)
+ throw new IllegalStateException();
+ //manager = emf.createEntityManager(PersistenceContextType.EXTENDED);
+ //account = manager.merge(account);
+ account.balance += amount;
+ //manager.flush();
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public int withdraw(int amount) {
+ if(account==null)
+ throw new IllegalStateException();
+ // manager.lock(account, LockMode.WRITE);
+ if (amount > account.balance) {
+ return 0;
+ } else {
+ account.balance -= amount;
+ return amount;
+ }
+ }
+
+
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountClient.java
new file mode 100644
index 0000000..ae85824
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountClient.java
@@ -0,0 +1 @@
+package examples.entity.intro; import java.util.Iterator; import java.util.List; import javax.naming.Context; import javax.naming.InitialContext; /** * Sample client code for an Account entity that is accessed through * a stateful session bean facade. */ public class AccountClient { public static void main(String[] args) { AccountInterface account = null; try { /* * Get a reference to the Account Session Object */ Context ctx = new InitialContext(System.getProperties()); account = (AccountInterface)ctx.lookup(AccountInterface.class.getName()); Bank bank = (Bank)ctx.lookup(Bank.class.getName()); /* * Let's find existing accounts in the bank... */ List<Account> accounts = bank.listAccounts(); /* * ... and print them to the screen */ System.out.println("--- Accounts in this bank ---"); for(Iterator iter = accounts.iterator(); iter.hasNext();) { System.out.println(iter.next()); } System.out.println("-----------------------------"); /* * Open the account */ account.open(4444); System.out.println("Initial Balance = " + account.getBalance()); /* * Deposit $100 into the account */ account.deposit(100); /* * Retrieve the resulting balance both from * the original and the local copy */ System.out.println("After depositing $100, the account balance is: $" + account.getBalance()); /* * Try to withdraw $150 */ System.out.println("Now trying to withdraw $150."); int withdrawn = account.withdraw(150); if(withdrawn != 150) System.out.println("No success..."); else System.out.println("Success, got the money!"); System.out.println("Finally, the account balance is: $" + account.getBalance()); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } } } \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountInterface.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountInterface.java
new file mode 100644
index 0000000..132accf
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/AccountInterface.java
@@ -0,0 +1,13 @@
+package examples.entity.intro;
+
+public interface AccountInterface {
+
+ public void open(int accountNumber) ;
+
+ public int getBalance();
+
+ public void deposit(int amount) ;
+
+ public int withdraw(int amount) ;
+
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/Bank.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/Bank.java
new file mode 100644
index 0000000..625978e
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/Bank.java
@@ -0,0 +1,60 @@
+package examples.entity.intro;
+
+import java.util.List;
+
+/**
+ * Business interface of the Bank session bean, a facade for the
+ * Account entity bean.
+ */
+
+public interface Bank {
+
+ /**
+ * List accounts in the bank
+ * @return the list of accounts
+ */
+ List<Account> listAccounts();
+
+ /**
+ * Opens a new account
+ * @param ownerName
+ * @return the account object
+ */
+ Account openAccount(String ownerName);
+
+ Account openAccount(String ownerName, int accNum);
+
+ void printBigAccounts();
+
+ /**
+ * Find out the balance of account with given accountNumber
+ * @param accountNumber
+ * @return the current balance
+ */
+ int getBalance(int accountNumber);
+
+ /**
+ * Increases the balance of account with given accountNumber by amount
+ * @param accountNumber
+ * @param amount the amount
+ */
+ void deposit(int accountNumber, int amount);
+
+ /**
+ * Withdraws a given amount, the current balance permitting
+ * @param accountNumber
+ * @param amount
+ * @return amount, if successful, 0 otherwise
+ */
+ int withdraw(int accountNumber, int amount);
+
+ public void checkBalance(int accountNumber);
+
+ /**
+ * Destroys the entity permanently
+ * @param accountNumber
+ */
+ void close(int accountNumber);
+
+ void update(Account a);
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/BankBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/BankBean.java
new file mode 100644
index 0000000..de5e59a
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/BankBean.java
@@ -0,0 +1,119 @@
+package examples.entity.intro;
+
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.ejb.Remote;
+import javax.persistence.*;
+
+/**
+ * Stateless session bean facade for account entities, remotely accessible
+ */
+@Stateless
+@Remote(Bank.class)
+@EntityListener(MyListener.class)
+public class BankBean implements Bank {
+ /**
+ * The entity manager object, injected by the container
+ */
+ @PersistenceContext
+ private EntityManager manager;
+
+ public List<Account> listAccounts() {
+ //Query query = manager.createQuery("SELECT a FROM Account a");
+ Query query = manager.createNamedQuery("findThem");
+ return query.getResultList();
+ }
+
+ public void printBigAccounts() {
+ Query query =
+ manager.createQuery("SELECT a FROM Account a WHERE a.balance > 1000");
+
+ System.out.println("Got " + query.getResultList().size() + " records.");
+
+ // do sth else in the meantime
+ try {
+ Thread.sleep(15000);
+ } catch (InterruptedException e )
+ {}
+
+ query =
+ manager.createQuery("SELECT a FROM Account a WHERE a.balance > 1000");
+
+ System.out.println("Got " + query.getResultList().size() + " records.");
+ }
+
+
+ public Account openAccount(String ownerName) {
+ Account account = new Account();
+ account.ownerName = ownerName;
+ System.out.println("Entity belongs to persistence context: " +
+ manager.contains(account));
+ manager.persist(account);
+ System.out.println("Entity belongs to persistence context: " +
+ manager.contains(account));
+ return account;
+ }
+
+ public Account openAccount(String ownerName, int accNum) {
+ Account account = new Account();
+ account.ownerName = ownerName;
+ account.accountNumber = accNum;
+ System.out.println("Entity belongs to persistence context: " +
+ manager.contains(account));
+ manager.persist(account);
+ System.out.println("Entity belongs to persistence context: " +
+ manager.contains(account));
+ return account;
+ }
+
+ public int getBalance(int accountNumber) {
+ Account account = manager.find(Account.class, accountNumber);
+ return account.balance;
+ }
+
+ public void deposit(int accountNumber, int amount) {
+ Account account = manager.find(Account.class, accountNumber);
+ account.balance += amount;
+ }
+
+ public int withdraw(int accountNumber, int amount) {
+ Account account = manager.find(Account.class, accountNumber);
+ System.out.println("Withdrawing... " );
+
+ account.balance -= amount;
+ System.out.println("... amount now... " + account.balance );
+ manager.flush();
+ return amount;
+ }
+
+ public void close(int accountNumber) {
+ Account account = manager.find(Account.class, accountNumber);
+ try {
+ Thread.sleep(20000);
+ } catch (InterruptedException e )
+ {}
+ manager.remove(account);
+ try {
+ Thread.sleep(20000);
+ } catch (InterruptedException e )
+ {}
+ }
+
+ public void update(Account a) {
+ manager.merge(a);
+ }
+
+ public void checkBalance(int accountNumber) {
+ System.out.println("Checking... sleep");
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException e )
+ {}
+ Account account = manager.find(Account.class, accountNumber);
+ manager.refresh(account);
+ int b = account.balance;
+ System.out.println("Checking... " + b );
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/Client.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/Client.java
new file mode 100644
index 0000000..16863fc
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/Client.java
@@ -0,0 +1 @@
+package examples.entity.intro; import java.util.Iterator; import java.util.List; import javax.naming.*; /** * Sample client code for an Account entity that is accessed through * a stateless session bean. */ public class Client { public static void main(String[] args) { Bank bank = null; Account account = null; int accountNumber = 0; try { /* * Get a reference to the Account Session Object */ Context ctx = new InitialContext(System.getProperties()); bank = (Bank)ctx.lookup(Bank.class.getName()); /* * Let's find existing accounts in the bank... */ List<Account> accounts = bank.listAccounts(); /* * ... and print them to the screen */ System.out.println("--- Accounts in this bank ---"); for(Iterator iter = accounts.iterator(); iter.hasNext();) { System.out.println(iter.next()); } System.out.println("-----------------------------"); /* * Open an account and get a local copy of the account object * We can access the object in the bank by using our account number. */ account = bank.openAccount("Ben Johnson"); accountNumber = account.accountNumber; /* * Call the balance() method, and print it */ System.out.println("Initial Balance = " + bank.getBalance(accountNumber)); /* * Deposit $100 into the account */ bank.deposit(accountNumber,100); /* * Retrieve the resulting balance both from * the original and the local copy */ System.out.println("After depositing $100, the account balance is: $" + bank.getBalance(accountNumber)); System.out.println("Sadly, the local account balance still is: $" + account.balance); /* * Try to withdraw $150 */ System.out.println("Now trying to withdraw $150, which is more than is currently available."); int withdrawn = bank.withdraw(accountNumber,150); if(withdrawn != 150) System.out.println("No success..."); else System.out.println("Success"); // account.balance += 10000; // bank.update(account); // // System.out.println("After depositing $10,000 locally and updating, the account balance is: $" // + bank.getBalance(accountNumber)); } catch (Exception e) { System.out.println("Message: " + e.getMessage()); } finally { /* * Destroy the Entity permanently try { if (account != null) { System.out.println("Destroying account.."); bank.close(accountNumber); } } catch (Exception e) { e.printStackTrace(); } */ } } } \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/ConflictingClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/ConflictingClient.java
new file mode 100644
index 0000000..f19d236
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/ConflictingClient.java
@@ -0,0 +1 @@
+package examples.entity.intro; import javax.naming.Context; import javax.naming.InitialContext; /** * Sample client code for an Account entity that is accessed through * a stateful session bean facade. */ public class ConflictingClient { static Bank bank = null; static int num = 13; static class SecondClientThread extends Thread { public void run() { System.out.println("Withdrawing... " ); try { bank.withdraw(num, 100000); } catch (Exception e) { //System.out.println("Exception: " + e.getMessage()); } System.out.println("Balance = " + bank.getBalance(num)); } } static class FirstClientThread extends Thread { public void run() { bank.printBigAccounts(); } } public static void main(String[] args) { try { Context ctx = new InitialContext(System.getProperties()); bank = (Bank)ctx.lookup(Bank.class.getName()); bank.openAccount("blub", num); bank.deposit(num, 100000); Thread fst = new FirstClientThread(); Thread scn = new SecondClientThread(); fst.start(); scn.start(); fst.join(); scn.join(); System.out.println("Balance = " + bank.getBalance(num)); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } } } \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/META-INF/persistence.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/META-INF/persistence.xml
new file mode 100644
index 0000000..3427b20
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/META-INF/persistence.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence">
+ <persistence-unit name="intro">
+ <jta-data-source>jdbc/__default</jta-data-source>
+ <properties>
+ <property name="ddl-generation" value="createtables"/>
+ <property name="toplink.platform.class.name"
+ value="oracle.toplink.essentials.platform.database.DerbyPlatform"/>
+<!-- <property name="toplink.logging.level" value="FINEST"/> -->
+
+ </properties>
+ </persistence-unit>
+</persistence> \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/MyListener.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/MyListener.java
new file mode 100644
index 0000000..f6cabcd
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/MyListener.java
@@ -0,0 +1,34 @@
+package examples.entity.intro;
+
+import javax.persistence.PostLoad;
+import javax.persistence.PostUpdate;
+import javax.persistence.PrePersist;
+import javax.persistence.PreUpdate;
+
+public class MyListener {
+
+ public MyListener() {
+ }
+
+ @PrePersist
+ public void prepersist(Account a) {
+ System.out.println("pre persist " + a );
+ }
+
+ @PreUpdate
+ public void preupdate(Account a) {
+ System.out.println("pre update " + a);
+ }
+
+ @PostUpdate
+ public void postupdate(Account a) {
+ System.out.println("post update " + a);
+ }
+
+
+ @PostLoad
+ public void postload(Account a) {
+ System.out.println("post load!!" + a );
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/build.xml
new file mode 100644
index 0000000..1f2983f
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/entity/intro/build.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../../etc/common.xml"> ]>
+
+<project name="ejb3-examples-entity-intro" default="jar"
+ basedir="../../../..">
+
+ <!-- basic settings -->
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property name="appname" value="AccountEntity"/>
+ <property name="client.class" value="examples.entity.intro.AccountClient"/>
+ <property name="app.pkg" value="examples/entity/intro"/>
+ <property name="package" value="${app.pkg}"/>
+ <property name="pack.dir" value="${src.dir}/${app.pkg}"/>
+ <property name="jar.pkg" value="examples/entity/intro"/>
+
+
+ <!-- Include common.xml -->
+ &include;
+
+ <property name="deploy.file" value="${assemble.ejbjar}/${ejbjar}" />
+
+ <target name="jar" depends="compile_common, create_ejbjar_common"/>
+ <target name="ear" depends="jar,create_ear_common"/>
+
+ <target name="deploy" depends="jar">
+ <copy file="${deploy.file}" todir="${deploy.dir}"/>
+ </target>
+
+</project>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Client.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Client.java
new file mode 100644
index 0000000..1500a48
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Client.java
@@ -0,0 +1,22 @@
+package examples.jndi;
+
+import javax.naming.*;
+import javax.rmi.*;
+
+public class Client {
+
+ public static void main (String[] args) throws Exception {
+
+ // Lookup the remote object via JNDI
+ Context ctx = new InitialContext(System.getProperties());
+ Object remoteObject = ctx.lookup("PKGenerator");
+
+ // Cast the remote object, RMI-IIOP style
+ PrimaryKeyGenerator generator = (PrimaryKeyGenerator)
+ PortableRemoteObject.narrow(
+ remoteObject, PrimaryKeyGenerator.class);
+
+ // Generate a PK by calling the RMI-IIOP stub
+ System.out.println(generator.generate());
+ }
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/InitContext.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/InitContext.java
new file mode 100644
index 0000000..dca940f
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/InitContext.java
@@ -0,0 +1,11 @@
+package examples.jndi;
+
+public class InitContext {
+ public static void main(String args[]) throws Exception {
+ // Form an Initial Context
+ javax.naming.Context ctx =
+ new javax.naming.InitialContext(System.getProperties());
+ System.err.println("Success!");
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGenerator.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGenerator.java
new file mode 100644
index 0000000..d866f9d
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGenerator.java
@@ -0,0 +1,13 @@
+package examples.jndi;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+/**
+ * The remote interface for the remote object. Clients use it
+ * for all operations on the remote object.
+ */
+
+public interface PrimaryKeyGenerator extends Remote {
+ public long generate() throws RemoteException;
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java
new file mode 100644
index 0000000..eeb08cb
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java
@@ -0,0 +1,29 @@
+package examples.jndi;
+
+import java.rmi.RemoteException;
+import javax.rmi.PortableRemoteObject;
+
+/**
+ * The implementation of a remote object which generates primary keys
+ */
+public class PrimaryKeyGeneratorImpl
+ extends PortableRemoteObject
+ implements PrimaryKeyGenerator {
+
+ private static long i = System.currentTimeMillis();
+
+ public PrimaryKeyGeneratorImpl() throws Exception, RemoteException {
+ /*
+ * Since we extend PortableRemoteObject, the super
+ * class will export our remote object here.
+ */
+ super();
+ }
+
+ /**
+ * Generates a unique primary key
+ */
+ public synchronized long generate() throws RemoteException {
+ return i++;
+ }
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Startup.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Startup.java
new file mode 100644
index 0000000..c6e9afa
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/Startup.java
@@ -0,0 +1,32 @@
+package examples.jndi;
+import javax.naming.*;
+
+/**
+ * A helper class which starts our RMI-IIOP server
+ */
+public class Startup {
+
+ /**
+ * Our main() method starts things up
+ */
+ public static void main(String args[]) throws Exception {
+
+ /*
+ * Start up our PKGenerator remote object. It will
+ * automatically export itself.
+ */
+ PrimaryKeyGenerator generator = new PrimaryKeyGeneratorImpl();
+
+ /*
+ * Bind our PKGenerator remote object to the JNDI tree
+ */
+ Context ctx = new InitialContext(System.getProperties());
+ ctx.rebind("PKGenerator", generator);
+ System.out.println("PKGenerator bound to JNDI tree.");
+
+ // wait for clients
+ synchronized (generator) {
+ generator.wait();
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/build.xml
new file mode 100644
index 0000000..d7c9690
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/build.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0"?>
+<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../etc/common.xml"> ]>
+
+<project name="ejb3-examples-jndi" default="compile" basedir="../../..">
+
+ &include;
+
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property file="${basedir}/etc/common.properties"/>
+
+ <path id="classpath">
+ <pathelement location="${build.classes.dir}"/>
+ </path>
+
+ <!-- =================================================================== -->
+ <!-- Prepares the build directory -->
+ <!-- =================================================================== -->
+ <target name="prepare">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.classes.dir}"/>
+ </target>
+
+ <target name="rmic" depends="prepare">
+ <javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="on" deprecation="on" optimize="off" includes="examples/jndi/PrimaryKeyGeneratorImpl.java">
+ <classpath refid="classpath" />
+ </javac>
+ <rmic base="${build.classes.dir}" classpath="${build.classes.dir}" classname="examples.jndi.PrimaryKeyGeneratorImpl" iiop="true" />
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the source code -->
+ <!-- =================================================================== -->
+ <target name="compile" depends="rmic">
+ <javac srcdir="${src.dir}"
+ destdir="${build.classes.dir}"
+ debug="on"
+ deprecation="on"
+ optimize="off"
+ includes="examples/jndi/**">
+ </javac>
+ </target>
+
+ <target name="run" depends="compile">
+ <parallel>
+ <java classname="examples.jndi.Startup" fork="yes" dir=".">
+ <classpath refid="classpath"/>
+ </java>
+
+ <java classname="examples.jndi.Client" fork="yes" dir=".">
+ <classpath refid="classpath"/>
+ </java>
+ </parallel>
+ </target>
+
+ <target name="clean">
+ <delete dir="${build.dir}/classes/examples/jndi"/>
+ </target>
+
+</project>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/jndi.properties b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/jndi.properties
new file mode 100644
index 0000000..98cfb22
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/jndi.properties
@@ -0,0 +1,4 @@
+java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory
+#java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory
+#java.naming.provider.url=file:c
+java.naming.provider.url=corbaloc::localhost:3528/NameService \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogBean.java
new file mode 100644
index 0000000..c8ff738
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogBean.java
@@ -0,0 +1,33 @@
+package examples.messaging;
+
+import javax.jms.*;
+import javax.ejb.*;
+import javax.annotation.PreDestroy;
+
+@MessageDriven(activationConfig = {
+ @ActivationConfigProperty(propertyName = "destinationType",
+ propertyValue = "javax.jms.Topic")
+ })
+public class LogBean implements MessageListener {
+
+ public LogBean() {
+ System.out.println("LogBean created");
+ }
+
+ public void onMessage(Message msg) {
+ if (msg instanceof TextMessage) {
+ TextMessage tm = (TextMessage) msg;
+ try {
+ String text = tm.getText();
+ System.out.println("Received new message : " + text);
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ @PreDestroy
+ public void remove() {
+ System.out.println("LogBean destroyed.");
+ }
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogClient.java
new file mode 100644
index 0000000..483c0f1
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/LogClient.java
@@ -0,0 +1,38 @@
+package examples.messaging;
+
+import javax.jms.*;
+import javax.naming.InitialContext;
+
+public class LogClient {
+
+ public static void main(String[] args) throws Exception {
+ // Initialize JNDI
+ InitialContext ctx = new InitialContext(System.getProperties());
+
+ // 1: Lookup connection factory
+ TopicConnectionFactory factory =
+ (TopicConnectionFactory) ctx.lookup("jms/TopicConnectionFactory");
+
+ // 2: Use connection factory to create JMS connection
+ TopicConnection connection = factory.createTopicConnection();
+
+ // 3: Use connection to create a session
+ TopicSession session =
+ connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
+
+ // 4: Lookup destination
+ Topic topic = (Topic)ctx.lookup("jms/Topic");
+
+ // 5: Create a message publisher
+ TopicPublisher publisher = session.createPublisher(topic);
+
+ // 6: Create and publish a message
+ TextMessage msg = session.createTextMessage();
+ msg.setText("This is a test message.");
+ publisher.send(msg);
+
+ // finish
+ publisher.close();
+ System.out.println("Message published. Please check application server's console to see the response from MDB.");
+ }
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/META-INF/sun-ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/META-INF/sun-ejb-jar.xml
new file mode 100644
index 0000000..6389cbf
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/META-INF/sun-ejb-jar.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sun-ejb-jar>
+ <enterprise-beans>
+ <name>LogBean</name>
+ <ejb>
+ <ejb-name>LogBean</ejb-name>
+ <jndi-name>jms/Topic</jndi-name>
+ <mdb-connection-factory>
+ <jndi-name>jms/TopicConnectionFactory</jndi-name>
+ </mdb-connection-factory>
+ </ejb>
+ <ejb>
+ <ejb-name>PoisonBean</ejb-name>
+ <jndi-name>jms/Topic</jndi-name>
+ <mdb-connection-factory>
+ <jndi-name>jms/TopicConnectionFactory</jndi-name>
+ </mdb-connection-factory>
+ </ejb>
+ </enterprise-beans>
+</sun-ejb-jar>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java
new file mode 100644
index 0000000..2bdfcba
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/PoisonBean.java
@@ -0,0 +1,40 @@
+package examples.messaging;
+
+import javax.jms.*;
+import javax.ejb.*;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+
+@MessageDriven(activationConfig =
+{ @ActivationConfigProperty(propertyName = "destinationType",
+ propertyValue = "javax.jms.Topic") })
+public class PoisonBean implements MessageListener {
+
+ @Resource
+ private MessageDrivenContext ctx;
+
+ public PoisonBean() {
+ System.out.println("PoisonBean created");
+ }
+
+ public void onMessage(Message msg) {
+ try {
+ System.out.println("Received msg " + msg.getJMSMessageID());
+
+ // Let’s sleep a little bit so that we don’t
+ // see rapid fire re-sends of the message.
+ Thread.sleep(3000);
+
+ // We could either throw a system exception here or
+ // manually force a rollback of the transaction.
+ ctx.setRollbackOnly();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @PreDestroy
+ public void remove() {
+ System.out.println("PoisonBean destroyed.");
+ }
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/Readme b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/Readme
new file mode 100644
index 0000000..2800cc7
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/Readme
@@ -0,0 +1,11 @@
+The messagin examples require that JMS connection factories and
+destination resources be created before deploying and running
+the samples.
+
+More specifically, you must create a javax.jms.TopicConnectionFactory
+resource with an JNDI name jms/TopicConnectionFactory, and a
+javax.jms.Topic destination resource with JNDI name jms/Topic. In
+Sun RI/Glassfish, the destination resource must have an additional
+property that links it with a physical destination. To provide that,
+add the property "name" with value "Topic" to that resource in the admin
+GUI.
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/build.xml
new file mode 100644
index 0000000..140b55e
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/build.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../etc/common.xml"> ]>
+
+<project name="ejb3-examples-messaging" default="deploy"
+ basedir="../../..">
+
+ <!-- basic settings -->
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property name="appname" value="MessageDrivenLog"/>
+ <property name="client.class" value="examples.messaging.LogClient"/>
+ <property name="app.pkg" value="examples/messaging"/>
+ <property name="package" value="${app.pkg}"/>
+ <property name="pack.dir" value="${src.dir}/${app.pkg}"/>
+ <property name="jar.pkg" value="${app.pkg}"/>
+
+ <!-- Include common.xml -->
+ &include;
+
+
+ <target name="jar" depends="compile_common, create_ejbjar_common"/>
+
+ <target name="deploy" depends="jar">
+ <copy file="${assemble.ejbjar}/${ejbjar}"
+ todir="${deploy.dir}"/>
+ </target>
+
+</project>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogBean.java
new file mode 100644
index 0000000..89364d9
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogBean.java
@@ -0,0 +1,22 @@
+package examples.messaging.dd;
+
+import javax.jms.*;
+
+public class LogBean implements MessageListener {
+
+ public LogBean() {
+ }
+
+ public void onMessage(Message msg) {
+ if (msg instanceof TextMessage) {
+ TextMessage tm = (TextMessage) msg;
+ try {
+ String text = tm.getText();
+ System.err.println("Received new message : " + text);
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogClient.java
new file mode 100644
index 0000000..14b6008
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/LogClient.java
@@ -0,0 +1,34 @@
+package examples.messaging.dd;
+
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.naming.InitialContext;
+
+public class LogClient {
+
+ public static void main(String[] args) throws Exception {
+ InitialContext ctx = new InitialContext(System.getProperties());
+
+ Topic topic = (Topic) ctx.lookup("jms/Topic");
+ TopicConnectionFactory factory =
+ (TopicConnectionFactory) ctx
+ .lookup("jms/TopicConnectionFactory");
+ TopicConnection connection = factory.createTopicConnection();
+ TopicSession session = connection.createTopicSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+
+ TopicPublisher publisher = session.createPublisher(topic);
+
+ // create and publish a message
+ TextMessage msg = session.createTextMessage();
+ msg.setText("This is a test message.");
+ publisher.publish(msg);
+
+ System.out.println("Message published. Please check application server's console to see the response from MDB.");
+ }
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/ejb-jar.xml
new file mode 100644
index 0000000..92cee32
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/ejb-jar.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<ejb-jar>
+ <enterprise-beans>
+ <message-driven>
+ <ejb-name>LogBeanDD</ejb-name>
+ <ejb-class>examples.messaging.dd.LogBean</ejb-class>
+ <messaging-type>javax.jms.MessageListener</messaging-type>
+ <transaction-type>Bean</transaction-type>
+ <message-destination-type>javax.jms.Topic</message-destination-type>
+ <!-- further details -->
+ <activation-config>
+ <activation-config-property>
+ <activation-config-property-name>destinationType</activation-config-property-name>
+ <activation-config-property-value>javax.jms.Topic</activation-config-property-value>
+ </activation-config-property>
+ </activation-config>
+ </message-driven>
+ </enterprise-beans>
+</ejb-jar> \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/sun-ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/sun-ejb-jar.xml
new file mode 100644
index 0000000..85caf26
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/META-INF/sun-ejb-jar.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sun-ejb-jar>
+ <enterprise-beans>
+ <name>LogBeanDD</name>
+ <ejb>
+ <ejb-name>LogBeanDD</ejb-name>
+ <jndi-name>jms/Topic</jndi-name>
+ <mdb-connection-factory>
+ <jndi-name>jms/TopicConnectionFactory</jndi-name>
+ </mdb-connection-factory>
+ </ejb>
+ </enterprise-beans>
+</sun-ejb-jar>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/build.xml
new file mode 100644
index 0000000..b6b0013
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/messaging/dd/build.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../../etc/common.xml"> ]>
+
+<project name="ejb3-examples-messaging-dd" default="deploy"
+ basedir="../../../..">
+
+ <!-- basic settings -->
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property name="appname" value="MessageDrivenLogDD"/>
+ <property name="client.class" value="examples.messaging.dd.LogClient"/>
+ <property name="app.pkg" value="examples/messaging/dd"/>
+ <property name="package" value="${app.pkg}"/>
+ <property name="pack.dir" value="${src.dir}/${app.pkg}"/>
+ <property name="jar.pkg" value="${app.pkg}"/>
+
+ <!-- Include common.xml -->
+ &include;
+
+
+ <target name="jar" depends="compile_common, create_ejbjar_common"/>
+
+ <target name="deploy" depends="jar">
+ <copy file="${assemble.ejbjar}/${ejbjar}"
+ todir="${deploy.dir}"/>
+ </target>
+
+</project>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/Count.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/Count.java
new file mode 100644
index 0000000..21be867
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/Count.java
@@ -0,0 +1,24 @@
+package examples.session.stateful;
+
+/**
+ * The business interface - a plain Java interface with only business methods.
+ */
+public interface Count {
+
+ /**
+ * Increments the counter by 1
+ */
+ public int count();
+
+ /**
+ * Sets the counter to val
+ *
+ * @param val
+ */
+ public void set(int val);
+
+ /**
+ * removes the counter
+ */
+ public void remove();
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountBean.java
new file mode 100644
index 0000000..6afd4a3
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountBean.java
@@ -0,0 +1,53 @@
+package examples.session.stateful;
+
+import javax.ejb.*;
+
+/**
+ * A Stateful Session Bean Class that shows the basics of
+ * how to write a stateful session bean.
+ *
+ * This Bean is initialized to some integer value. It has a
+ * business method which increments the value.
+ *
+ * The annotations below declare that:
+ * <ul>
+ * <li>this is a Stateful Session Bean
+ * <li>the bean's remote business interface is <code>Count</code>
+ * <li>any lifecycle callbacks go to the class <code>CountCallbacks</code>
+ * </ul>
+ */
+
+@Stateful
+@Remote(Count.class)
+@Interceptors(CountCallbacks.class)
+public class CountBean implements Count {
+
+ /** The current counter is our conversational state. */
+ private int val;
+
+ /**
+ * The count() business method.
+ */
+ public int count() {
+ System.out.println("count()");
+ return ++val;
+ }
+
+ /**
+ * The set() business method.
+ */
+ public void set(int val) {
+ this.val = val;
+ System.out.println("set()");
+ }
+
+ /**
+ * The remove method is annotated so that the container knows
+ * it can remove the bean after this method returns.
+ */
+ @Remove
+ public void remove() {
+ System.out.println("remove()");
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountCallbacks.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountCallbacks.java
new file mode 100644
index 0000000..d6f6aa1
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountCallbacks.java
@@ -0,0 +1,53 @@
+package examples.session.stateful;
+
+import javax.ejb.InvocationContext;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+/**
+ * This class is a lifecycle callback interceptor for the Count bean.
+ * The callback methods simply print a message when invoked by the
+ * container.
+ */
+public class CountCallbacks {
+
+ public CountCallbacks() {}
+ /**
+ * Called by the container after construction
+ */
+ @PostConstruct
+ public void construct(InvocationContext ctx) throws Exception {
+ System.out.println("cb:construct() ");
+ ctx.proceed();
+ }
+
+ /**
+ * Called by the container after activation
+ */
+ @PostActivate
+ public void activate(InvocationContext ctx) throws Exception {
+ System.out.println("cb:activate()");
+ ctx.proceed();
+ }
+
+ /**
+ * Called by the container before passivation
+ */
+ @PrePassivate
+ public void passivate(InvocationContext ctx) throws Exception {
+ System.out.println("cb:passivate()");
+ ctx.proceed();
+ }
+
+ /**
+ * Called by the container before destruction
+ */
+ @PreDestroy
+ public void destroy(InvocationContext ctx) throws Exception {
+ System.out.println("cb:destroy()");
+ ctx.proceed();
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java
new file mode 100644
index 0000000..3536705
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/CountClient.java
@@ -0,0 +1,63 @@
+package examples.session.stateful;
+
+import javax.naming.*;
+
+/**
+ * This class is a simple client for a stateful session bean.
+ *
+ * To illustrate how passivation works, configure your EJB server
+ * to allow only 2 stateful session beans in memory. (Consult your
+ * vendor documentation for details on how to do this.) We create
+ * 3 beans in this example to see how and when beans are passivated.
+ */
+public class CountClient {
+
+ public static final int noOfClients = 3;
+
+ public static void main(String[] args) {
+ try {
+ /* Get a reference to the bean */
+ Context ctx = new InitialContext(System.getProperties());
+
+ /* An array to hold the Count beans */
+ Count count[] = new Count[noOfClients];
+ int countVal = 0;
+
+ /* Create and count() on each member of array */
+ System.out.println("Instantiating beans...");
+ for (int i = 0; i < noOfClients; i++) {
+ count[i] = (Count) ctx.lookup(Count.class.getName());
+
+ /* initialize each bean to the current count value */
+ count[i].set(countVal);
+
+ /* Add 1 and print */
+ countVal = count[i].count();
+ System.out.println(countVal);
+
+ /* Sleep for 1/2 second */
+ Thread.sleep(100);
+ }
+
+ /*
+ * Let's call count() on each bean to make sure the
+ * beans were passivated and activated properly.
+ */
+ System.out.println("Calling count() on beans...");
+ for (int i = 0; i < noOfClients; i++) {
+
+ /* Add 1 and print */
+ countVal = count[i].count();
+ System.out.println(countVal);
+
+ /* call remove to let the container dispose of the bean */
+ count[i].remove();
+
+ /* Sleep for 1/2 second */
+ Thread.sleep(50);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/META-INF/ejb-jar.xml
new file mode 100644
index 0000000..9503e74
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/META-INF/ejb-jar.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+ <ejb-jar>
+ <enterprise-beans>
+ </enterprise-beans>
+</ejb-jar> \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/build.xml
new file mode 100644
index 0000000..d958085
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful/build.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../../etc/common.xml"> ]>
+
+<project name="ejb3-examples-session-stateful" default="deploy"
+ basedir="../../../..">
+
+ <!-- basic settings -->
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property name="appname" value="StatefulSession"/>
+ <property name="client.class" value="examples.session.stateful.CountClient"/>
+ <property name="app.pkg" value="examples/session/stateful"/>
+ <property name="package" value="${app.pkg}"/>
+ <property name="pack.dir" value="${src.dir}/${app.pkg}"/>
+ <property name="jar.pkg" value="examples/session/stateful"/>
+
+ <!-- Include common.xml -->
+ &include;
+
+ <target name="jar" depends="compile_common, create_ejbjar_common"/>
+
+ <target name="deploy" depends="jar">
+ <copy file="${assemble.ejbjar}/${ejbjar}"
+ todir="${deploy.dir}"/>
+ </target>
+
+</project>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/Count.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/Count.java
new file mode 100644
index 0000000..f20ae5e
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/Count.java
@@ -0,0 +1,24 @@
+package examples.session.stateful_dd;
+
+/**
+ * The business interface - a plain Java interface with only business methods.
+ */
+public interface Count {
+
+ /**
+ * Increments the counter by 1
+ */
+ public int count();
+
+ /**
+ * Sets the counter to val
+ *
+ * @param val
+ */
+ public void set(int val);
+
+ /**
+ * removes the counter
+ */
+ public void remove();
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountBean.java
new file mode 100644
index 0000000..0a2ab2c
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountBean.java
@@ -0,0 +1,47 @@
+package examples.session.stateful_dd;
+
+import java.io.Serializable;
+
+/**
+ * A Stateful Session Bean Class that shows the basics of
+ * how to write a stateful session bean.
+ *
+ * This Bean is initialized to some integer value. It has a
+ * business method which increments the value.
+ *
+ * The annotations below declare that:
+ * <ul>
+ * <li>this is a Stateful Session Bean
+ * <li>the bean's remote business interface is <code>Count</code>
+ * <li>any lifecycle callbacks go to the class <code>CountCallbacks</code>
+ * </ul>
+ */
+
+public class CountBean implements Count {
+
+ /** The current counter is our conversational state. */
+ private int val;
+
+ /**
+ * The count() business method.
+ */
+ public int count() {
+ System.out.println("count()");
+ return ++val;
+ }
+
+ /**
+ * The set() business method.
+ */
+ public void set(int val) {
+ this.val = val;
+ System.out.println("set()");
+ }
+
+ /**
+ */
+ public void remove() {
+ System.out.println("remove()");
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountCallbacks.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountCallbacks.java
new file mode 100644
index 0000000..f2ed8b0
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountCallbacks.java
@@ -0,0 +1,43 @@
+package examples.session.stateful_dd;
+
+import javax.ejb.InvocationContext;
+
+/**
+ * This class is a lifecycle callback interceptor for the Count bean.
+ * The callback methods simply print a message when invoked by
+ * the container.
+ */
+public class CountCallbacks {
+
+ public CountCallbacks() {}
+
+ /**
+ * Called by the container after construction
+ */
+ public void construct(InvocationContext ctx) {
+ System.out.println("cb:construct()");
+ }
+
+ /**
+ * Called by the container after activation
+ */
+ public void activate(InvocationContext ctx) {
+ System.out.println("cb:activate()");
+ }
+
+ /**
+ * Called by the container before passivation
+ */
+ public void passivate(InvocationContext ctx) {
+ System.out.println("cb:passivate()");
+ }
+
+ /**
+ * Called by the container before destruction
+ */
+
+ public void destroy(InvocationContext ctx) {
+ System.out.println("cb:destroy()");
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountClient.java
new file mode 100644
index 0000000..46fb0cc
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/CountClient.java
@@ -0,0 +1,63 @@
+package examples.session.stateful_dd;
+
+import javax.naming.*;
+
+/**
+ * This class is a simple client for a stateful session bean.
+ *
+ * To illustrate how passivation works, configure your EJB server
+ * to allow only 2 stateful session beans in memory. (Consult your
+ * vendor documentation for details on how to do this.) We create
+ * 3 beans in this example to see how and when beans are passivated.
+ */
+public class CountClient {
+
+ public static final int noOfClients = 3;
+
+ public static void main(String[] args) {
+ try {
+ /* Get a reference to the bean */
+ Context ctx = new InitialContext();
+
+ /* An array to hold the Count beans */
+ Count count[] = new Count[noOfClients];
+ int countVal = 0;
+
+ /* Create and count() on each member of array */
+ System.out.println("Instantiating beans...");
+ for (int i = 0; i < noOfClients; i++) {
+ //count[i] = (Count) ctx.lookup("StatefulCount" );
+ count[i] = (Count) ctx.lookup(Count.class.getName());
+ /* initialize each bean to the current count value */
+ count[i].set(countVal);
+
+ /* Add 1 and print */
+ countVal = count[i].count();
+ System.out.println(countVal);
+
+ /* Sleep for 1/2 second */
+ Thread.sleep(100);
+ }
+
+ /*
+ * Let's call count() on each bean to make sure the
+ * beans were passivated and activated properly.
+ */
+ System.out.println("Calling count() on beans...");
+ for (int i = 0; i < noOfClients; i++) {
+
+ /* Add 1 and print */
+ countVal = count[i].count();
+ System.out.println(countVal);
+
+ /* call remove to let the container dispose of the bean */
+ count[i].remove();
+
+ /* Sleep for 1/2 second */
+ Thread.sleep(50);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/META-INF/ejb-jar.xml
new file mode 100644
index 0000000..a483584
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/META-INF/ejb-jar.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
+ <description>Stateful Session Bean Example</description>
+ <display-name>Stateful Session Bean Example</display-name>
+ <enterprise-beans>
+ <session>
+ <ejb-name>CountBean</ejb-name>
+ <business-remote>examples.session.stateful_dd.Count</business-remote>
+ <ejb-class>examples.session.stateful_dd.CountBean</ejb-class>
+ <session-type>Stateful</session-type>
+ <transaction-type>Container</transaction-type>
+ </session>
+ </enterprise-beans>
+
+ <interceptors>
+ <interceptor>
+ <interceptor-class>examples.session.stateful_dd.CountCallbacks
+ </interceptor-class>
+ <post-construct><lifecycle-callback-method>construct</lifecycle-callback-method></post-construct>
+ <post-activate><lifecycle-callback-method>activate</lifecycle-callback-method></post-activate>
+ <pre-passivate><lifecycle-callback-method>passivate</lifecycle-callback-method></pre-passivate>
+<!-- <pre-destroy><lifecycle-callback-method>destroy</lifecycle-callback-method></pre-destroy> -->
+ </interceptor>
+ </interceptors>
+
+ <assembly-descriptor>
+ <interceptor-binding>
+ <ejb-name>CountBean</ejb-name>
+ <interceptor-class>examples.session.stateful_dd.CountCallbacks
+ </interceptor-class>
+ </interceptor-binding>
+ </assembly-descriptor>
+</ejb-jar> \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/build.xml
new file mode 100644
index 0000000..8c9181a
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateful_dd/build.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../../etc/common.xml"> ]>
+
+<project name="ejb3-examples-session-statefull_dd" default="all"
+ basedir="../../../..">
+
+ <!-- basic settings -->
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property name="appname" value="StatefulSession-Hello"/>
+ <property name="client.class" value="examples.session.stateful_dd.CountClient"/>
+ <property name="app.pkg" value="examples/session/stateful_dd"/>
+ <property name="package" value="${app.pkg}"/>
+ <property name="pack.dir" value="${src.dir}/${app.pkg}"/>
+ <property name="jar.pkg" value="examples/session/stateful_dd"/>
+
+ <!-- Include common.xml -->
+ &include;
+
+ <target name="jar" depends="compile_common, create_ejbjar_common"/>
+ <target name="all" depends="compile_common, jar, deploy"/>
+
+ <target name="deploy" depends="jar">
+ <copy file="${assemble.ejbjar}/${ejbjar}"
+ todir="${deploy.dir}"/>
+ </target>
+
+ <target name="clean" depends="undeploy_common, clean_common" />
+
+</project>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/Hello.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/Hello.java
new file mode 100644
index 0000000..fa4648b
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/Hello.java
@@ -0,0 +1,13 @@
+package examples.session.stateless;
+
+/**
+ * This is the Hello business interface.
+ */
+
+public interface Hello {
+
+ /**
+ * @return a greeting to the client.
+ */
+ public String hello();
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/HelloBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/HelloBean.java
new file mode 100644
index 0000000..10e6baf
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/HelloBean.java
@@ -0,0 +1,16 @@
+package examples.session.stateless;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+/**
+ * Demonstration stateless session bean.
+ */
+@Stateless
+@Remote(Hello.class)
+public class HelloBean implements Hello {
+ public String hello() {
+ System.out.println("hello()");
+ return "Hello, World!";
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/HelloClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/HelloClient.java
new file mode 100644
index 0000000..29ebd03
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/HelloClient.java
@@ -0,0 +1,35 @@
+package examples.session.stateless;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+/**
+ * This class is an example of client code which invokes
+ * methods on a simple, remote stateless session bean.
+ */
+public class HelloClient {
+
+ public static void main(String[] args) throws Exception {
+ /*
+ * Obtain the JNDI initial context.
+ *
+ * The initial context is a starting point for
+ * connecting to a JNDI tree. We choose our JNDI
+ * driver, the network location of the server, etc
+ * by passing in the environment properties.
+ */
+ Context ctx = new InitialContext(System.getProperties());
+
+ /*
+ * Get a reference to a bean instance, looked up by class name
+ */
+ Hello hello = (Hello) ctx.lookup(Hello.class.getName());
+
+ /*
+ * Call the hello() method on the bean.
+ * We then print the result to the screen.
+ */
+ System.out.println(hello.hello());
+
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/META-INF/ejb-jar.xml
new file mode 100644
index 0000000..9503e74
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/META-INF/ejb-jar.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+ <ejb-jar>
+ <enterprise-beans>
+ </enterprise-beans>
+</ejb-jar> \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/build.xml
new file mode 100644
index 0000000..33b4751
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/stateless/build.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../../etc/common.xml"> ]>
+
+<project name="ejb3-examples-session-stateless" default="jar"
+ basedir="../../../..">
+
+ <!-- basic settings -->
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property name="appname" value="StatelessSession"/>
+ <property name="client.class" value="examples.session.stateless.HelloClient"/>
+ <property name="app.pkg" value="examples/session/stateless"/>
+ <property name="package" value="${app.pkg}"/>
+ <property name="pack.dir" value="${src.dir}/${app.pkg}"/>
+ <property name="jar.pkg" value="examples/session/stateless"/>
+
+
+ <!-- Include common.xml -->
+ &include;
+
+ <property name="deploy.file" value="${assemble.ejbjar}/${ejbjar}" />
+
+ <target name="jar" depends="compile_common, create_ejbjar_common"/>
+ <target name="ear" depends="jar,create_ear_common"/>
+
+ <target name="deploy" depends="jar">
+ <copy file="${deploy.file}" todir="${deploy.dir}"/>
+ </target>
+
+</project>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/Hello.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/Hello.java
new file mode 100644
index 0000000..22ad6ea
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/Hello.java
@@ -0,0 +1,15 @@
+package examples.session.ws;
+
+
+/**
+ * This is the Hello business interface.
+ */
+
+
+public interface Hello {
+
+ public String hello();
+
+ public void foo();
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/HelloBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/HelloBean.java
new file mode 100644
index 0000000..13e6eef
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/HelloBean.java
@@ -0,0 +1,18 @@
+package examples.session.ws;
+
+import javax.ejb.Stateless;
+import javax.jws.WebService;
+
+@Stateless
+@WebService(serviceName="Greeter", portName="GreeterPort")
+public class HelloBean {
+
+ public String hello() {
+ System.out.println("hello()");
+ return "Hello, World!";
+ }
+
+ public void foo() {
+ ;
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/JAXWSClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/JAXWSClient.java
new file mode 100644
index 0000000..be8401e
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/JAXWSClient.java
@@ -0,0 +1,40 @@
+package examples.session.ws;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+/**
+ * This is an example of a standalone JAX-WS client. To compile,
+ * it requires some XML artifacts to be generated from the service's
+ * WSDL. This is done in the build file.
+ *
+ * The mapped XML classes used her are
+ * 1. the HelloBean port type class (this is NOT the bean impl. class!)
+ * 2. the Greeter service class
+ */
+public class JAXWSClient {
+
+ static String host = "localhost";
+ static String portType = "HelloBean";
+ static String serviceName = "Greeter";
+ static String serviceEndpointAddress = "http://" + host + ":8080/" + serviceName;
+ static String nameSpace = "urn:ws.session.examples";
+
+ public static void main(String[] args) throws Exception {
+
+ URL wsdlLocation = new URL(serviceEndpointAddress + "/" + portType + "?WSDL");
+ QName serviceNameQ = new QName( nameSpace, serviceName);
+
+ // dynamic service usage
+ Service service = Service.create(wsdlLocation, serviceNameQ);
+ HelloBean firstGreeterPort = service.getPort(HelloBean.class);
+ System.out.println("1: " + firstGreeterPort.hello());
+
+ // static service usage
+// Greeter greeter = new Greeter();
+// HelloBean secondGreeterPort = greeter.getGreeterPort();
+// System.out.println("2: " +secondGreeterPort.hello());
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/META-INF/ejb-jar.xml
new file mode 100644
index 0000000..9503e74
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/META-INF/ejb-jar.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+ <ejb-jar>
+ <enterprise-beans>
+ </enterprise-beans>
+</ejb-jar> \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/build.xml
new file mode 100644
index 0000000..2d4a975
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/session/ws/build.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0"?>
+<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../../etc/common.xml"> ]>
+
+<project name="ejb3-examples-session-ws" default="all"
+ basedir="../../../..">
+
+ <!-- properties overriding common ones -->
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property name="appname" value="WS"/>
+ <property name="client.class" value="examples.session.ws.JAXWSClient"/>
+ <property name="app.pkg" value="examples/session/ws"/>
+ <property name="package" value="${app.pkg}"/>
+ <property name="pack.dir" value="${src.dir}/${app.pkg}"/>
+ <property name="jar.pkg" value="examples/session/ws"/>
+ <property name="ServiceName" value="Greeter" />
+ <property name="PortType" value="HelloBean" />
+
+ <!-- Include common.xml -->
+ &include;
+
+ <!-- specific properties -->
+ <property name="deploy.file" value="${ejbjar}" />
+ <property name="assemble.dir" value="${assemble.ejbjar}" />
+
+ <!-- targets -->
+ <target name="client_jar" depends="compile_client, create_client_jar"/>
+ <target name="all" depends="client_jar"/>
+
+ <target name="compile_service" depends="init_common">
+ <mkdir dir="${build.classes.dir}"/>
+ <javac srcdir="${pack.dir}" debug="true" excludes="**/*Client.java"
+ destdir="${build.classes.dir}"
+ classpath="${build.classpath}"/>
+ </target>
+
+ <target name="compile_client" depends="init_common,clean_clientjar_common">
+ <mkdir dir="${assemble.clientjar}"/>
+ <mkdir dir="${build.classes.dir}"/>
+ <get src="${service.wsdl}" dest="${build.classes.dir}/service.wsdl"/>
+ <wsimport
+ fork="true" keep="true"
+ wsdl="${build.classes.dir}/service.wsdl"
+ sourcedestdir="${build.classes.dir}"
+ destdir="${assemble.clientjar}" >
+ </wsimport>
+ <javac srcdir="${pack.dir}" debug="true" includes="**/*Client.java"
+ destdir="${assemble.clientjar}"
+ classpath="${build.classpath}"/>
+ </target>
+
+ <target name="run_wsclient_standalone" depends="client_jar">
+ <java classname="${client.class}"
+ classpath="${assemble.clientjar}/${clientjar};${appserver.home}/lib/appserv-rt.jar;${appserver.home}/lib/appserv-ws.jar;${appserver.home}/lib/appserv-admin.jar;${appserver.home}/lib/javaee.jar;" fork="yes">
+ </java>
+ </target>
+
+ <target name="create_ejbjar" depends="clean_ejbjar_common,compile_service">
+ <mkdir dir="${assemble.ejbjar}"/>
+ <jar destfile="${assemble.ejbjar}/${ejbjar}">
+ <zipfileset dir="${build.classesdir}/${app.pkg}/" includes="**/*.class"
+ excludes="**/servlet/, **/client/" prefix="${jar.pkg}"/>
+ <fileset dir="${src.dir}/${package}" includes="META-INF/${jarDD}"/>
+ </jar>
+ </target>
+
+ <target name="deploy" depends="compile_service,create_ejbjar, deploy_common" />
+ <target name="clean" depends="undeploy_common, clean_common" />
+
+</project>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/application.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/application.xml
new file mode 100644
index 0000000..fe5919f
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/application.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<application version="5"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd">
+
+ <description>Application description</description>
+ <display-name>Jasmine</display-name>
+ <module>
+ <web>
+ <web-uri>shop.war</web-uri>
+ <context-root>jasmine</context-root>
+ </web>
+ </module>
+ <module>
+ <ejb>shopEjb.jar</ejb>
+ </module>
+
+</application>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/ejb-jar.xml
new file mode 100644
index 0000000..9ca92e0
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/ejb-jar.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+ <ejb-jar>
+ <enterprise-beans>
+ <session>
+ <ejb-name>PricerBean</ejb-name>
+ <ejb-class>examples.shop.impl.session.PricerBean</ejb-class>
+ <session-type>Stateless</session-type>
+ <transaction-type>Container</transaction-type>
+ <env-entry>
+ <env-entry-name>taxRate</env-entry-name>
+ <env-entry-type>java.lang.Integer</env-entry-type>
+ <env-entry-value>6</env-entry-value>
+ </env-entry>
+ <env-entry>
+ <env-entry-name>bulkDiscountRate</env-entry-name>
+ <env-entry-type>java.lang.Integer</env-entry-type>
+ <env-entry-value>10</env-entry-value>
+ </env-entry>
+ </session>
+
+ </enterprise-beans>
+</ejb-jar> \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/persistence.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/persistence.xml
new file mode 100644
index 0000000..893e1c7
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/persistence.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence">
+ <persistence-unit name="shop">
+ <jta-data-source>jdbc/__default</jta-data-source>
+ <properties>
+ <property name="ddl-generation" value="createtables"/>
+ <property name="toplink.platform.class.name"
+ value="oracle.toplink.essentials.platform.database.DerbyPlatform"/>
+<!-- <property name="toplink.logging.level" value="FINEST"/> -->
+
+ </properties>
+ </persistence-unit>
+</persistence> \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/sun-ejb-jar.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/sun-ejb-jar.xml
new file mode 100644
index 0000000..71fa2ad
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/META-INF/sun-ejb-jar.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sun-ejb-jar>
+ <enterprise-beans>
+ <name>OrderProcessorBean</name>
+ <ejb>
+ <ejb-name>OrderProcessorBean</ejb-name>
+ <jndi-name>jms/OrderQueue</jndi-name>
+ <mdb-connection-factory>
+ <jndi-name>jms/QueueConnectionFactory</jndi-name>
+ </mdb-connection-factory>
+ </ejb>
+ </enterprise-beans>
+</sun-ejb-jar>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/WEB-INF/sun-web.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/WEB-INF/sun-web.xml
new file mode 100644
index 0000000..cca518c
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/WEB-INF/sun-web.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sun-web-app>
+ <context-root>jasmine</context-root>
+ <class-loader delegate="true"/>
+</sun-web-app>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/WEB-INF/web.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/WEB-INF/web.xml
new file mode 100644
index 0000000..7bf9dbb
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/WEB-INF/web.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+
+<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <welcome-file-list>
+ <welcome-file></welcome-file>
+ </welcome-file-list>
+
+ <servlet>
+ <servlet-name>LoginServlet</servlet-name>
+ <servlet-class>examples.shop.web.servlet.LoginServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>LoginServlet</servlet-name>
+ <url-pattern>/login/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>ShowQuoteServlet</servlet-name>
+ <servlet-class>examples.shop.web.servlet.ShowQuoteServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>ShowQuoteServlet</servlet-name>
+ <url-pattern>/showQuote/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>CatalogServlet</servlet-name>
+ <servlet-class>examples.shop.web.servlet.CatalogServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>CatalogServlet</servlet-name>
+ <url-pattern>/catalog/*</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/build.xml b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/build.xml
new file mode 100644
index 0000000..a403dda
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/build.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0"?>
+<!DOCTYPE project [ <!ENTITY include SYSTEM "../../../etc/common.xml"> ]>
+
+<project name="ejb3-examples-shop" default="jar"
+ basedir="../../..">
+
+ <!-- basic settings -->
+ <property name="src.dir" value="${basedir}/src"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build.classes.dir" value="${build.dir}/classes"/>
+ <property name="appname" value="shop"/>
+ <property name="client.class" value="examples.shop.client.SetupClient"/>
+ <property name="wsclient.class" value="examples.shop.client.PricerClient"/>
+ <property name="app.pkg" value="examples/shop"/>
+ <property name="package" value="${app.pkg}"/>
+ <property name="pack.dir" value="${src.dir}/${app.pkg}"/>
+ <property name="jar.pkg" value="examples/shop"/>
+ <property name="war.pkg" value="examples/shop"/>
+ <property name="ServiceName" value="PricerService" />
+ <property name="PortType" value="PricerBean" />
+
+ <!-- Include common.xml -->
+ &include;
+
+ <property name="deploy.file" value="${assemble.ear}/${ear}" />
+
+ <target name="compile_client" depends="init_common,clean_clientjar_common">
+ <mkdir dir="${assemble.clientjar}"/>
+ <mkdir dir="${build.classes.dir}"/>
+ <get src="${service.wsdl}" dest="${build.classes.dir}/service.wsdl"/>
+ <wsimport
+ fork="true" keep="true"
+ wsdl="${build.classes.dir}/service.wsdl"
+ sourcedestdir="${build.classes.dir}"
+ destdir="${assemble.clientjar}" >
+ </wsimport>
+ <javac srcdir="${pack.dir}" debug="true" includes="**/*Client.java"
+ destdir="${assemble.clientjar}"
+ classpath="${build.classpath}"/>
+ </target>
+
+ <target name="jar" depends="compile_common, create_ejbjar_common"/>
+
+ <target name="client_jar" depends="compile_client, create_client_jar"/>
+
+ <target name="ear" depends="jar,war,clean_ear_common,mkdir_ear_dir">
+ <jar destfile="${assemble.ear}/${ear}" update="true">
+ <fileset dir="${assemble.war}" includes="${war}"/>
+ </jar>
+ <echo message="${src.dir}/${package}/META-INF/${earDD}"/>
+ <jar destfile="${assemble.ear}/${ear}" update="true">
+ <fileset dir="${assemble.ejbjar}" includes="${ejbjar}"/>
+ <fileset dir="${assemble.ejbjar}" includes="sun-application.xml"/>
+ <fileset dir="${src.dir}/${package}" includes="META-INF/${earDD}"/>
+ </jar>
+ <delete file="../${ejbjar}" />
+ </target>
+
+ <target name="run_wsclient_standalone" depends="client_jar">
+ <java classname="${wsclient.class}"
+ classpath="${assemble.clientjar}/${clientjar};${appserver.home}/lib/appserv-rt.jar;${appserver.home}/lib/appserv-ws.jar;${appserver.home}/lib/appserv-admin.jar;${appserver.home}/lib/javaee.jar;" fork="yes">
+ </java>
+ </target>
+
+
+ <target name="war" depends="mkdir_war, create_ejbjar_common">
+ <jar destfile="${assemble.war}/${war}" update="true" >
+ <fileset dir="${src.dir}/${package}" includes="WEB-INF/*.xml" />
+ </jar>
+ <echo message="${src.dir}/${war.pkg}/"/>
+ <jar destfile="${assemble.war}/${war}" update="true">
+ <zipfileset dir="${src.dir}/${war.pkg}/web/jsp/" includes="*.jsp"
+ />
+ </jar>
+ <jar destfile="${assemble.war}/${war}" update="true">
+ <zipfileset dir="${build.classesdir}/${war.pkg}/" includes="**/*Servlet.class"
+ prefix="WEB-INF/classes/${war.pkg}"/>
+ </jar>
+ </target>
+
+
+ <target name="deploy" depends="ear, war">
+ <copy file="${deploy.file}" todir="${deploy.dir}"/>
+ </target>
+
+</project>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/PricerClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/PricerClient.java
new file mode 100644
index 0000000..0bd285b
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/PricerClient.java
@@ -0,0 +1,52 @@
+package examples.shop.client;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+import examples.shop.impl.session.PricerBean;
+
+/**
+ * This class is an example of a standalone JAX-RPC client code which uses both
+ * the static stub and the dynamic proxy approach to get a reference to the
+ * remote Web Service
+ */
+public class PricerClient {
+ static String host = "localhost";
+
+ static String portType = "PricerBean";
+
+ static String serviceName = "PricerService";
+
+ static String serviceEndpointAddress = "http://" + host + ":8080/"
+ + serviceName;
+
+ static String nameSpace = "urn:session.impl.shop.examples";
+
+ public static void main(String[] args) throws Exception {
+
+ URL wsdlLocation = new URL(serviceEndpointAddress + "/" + portType
+ + "?WSDL");
+ QName serviceNameQ = new QName(nameSpace, serviceName);
+
+ // dynamic service usage
+ Service service = Service.create(wsdlLocation, serviceNameQ);
+ PricerBean pricerPort = service.getPort(PricerBean.class);
+
+ String user = "Gerald";
+
+ System.out.println("Tax rate: " + pricerPort.getTaxRate());
+ System.out.println("Discount for : " + user + " is "
+ + pricerPort.getPersonalDiscountRate(user));
+
+ System.out
+ .println("Discount for 1 item (at $1000,- per piece) for " + user + " is "
+ + pricerPort.getDiscount(1, 1000, user));
+
+ System.out
+ .println("Discount for 5 items (at $1000,- per piece) for " + user + " is "
+ + pricerPort.getDiscount(5, 5000, user));
+
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/SetupClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/SetupClient.java
new file mode 100644
index 0000000..c1fbc27
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/SetupClient.java
@@ -0,0 +1,58 @@
+package examples.shop.client;
+
+import java.util.Iterator;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import examples.shop.impl.entity.Product;
+import examples.shop.logic.Catalog;
+import examples.shop.logic.UserManager;
+
+/**
+ * Client test application on a CMP Entity Bean, Product.
+ */
+public class SetupClient {
+
+ public static void main(String[] args) throws Exception {
+
+ try {
+
+ Context ctx = new InitialContext(System.getProperties());
+ Catalog catalog = (Catalog) ctx.lookup(Catalog.class.getName());
+
+ /*
+ * Use the catalog to create Products
+ */
+ catalog.addProduct(new Product().init("123-456-7890", "P4-1.8",
+ "1.8 GHz Pentium 4", 200));
+ catalog.addProduct(new Product().init("123-456-7891", "P4-3",
+ "3 GHz Pentium 4", 300));
+ catalog.addProduct(new Product().init("123-456-7892", "P4-4",
+ "4 GHz Pentium", 400));
+ catalog.addProduct(new Product().init("123-456-7893", "SD-256",
+ "256 MB SDRAM", 50));
+ catalog.addProduct(new Product().init("123-456-7894", "SD-512",
+ "512 MB SDRAM", 100));
+ catalog.addProduct(new Product().init("123-456-7895", "DD-1000",
+ "1GB MB DDRAM", 200));
+ catalog.addProduct(new Product().init("123-456-7896", "MP3-x",
+ "MP3 Player", 200));
+
+ /*
+ * Find a Product, and print out it's description
+ */
+ for (Iterator<Product> i = catalog.getProductList().iterator(); i
+ .hasNext();) {
+ System.out.println(i.next().getDescription());
+ }
+
+ UserManager userManager =
+ (UserManager) ctx.lookup(UserManager.class.getName());
+ userManager.createUser("Gerald", "Gerald Brose", "password",
+ "D-13509 Berlin, Germany");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Customer.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Customer.java
new file mode 100644
index 0000000..c986436
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Customer.java
@@ -0,0 +1,104 @@
+package examples.shop.impl.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * This entity represents customer details.
+ */
+@Entity
+public class Customer implements java.io.Serializable {
+
+ private String customerID;
+
+ private String name;
+
+ private String password;
+
+ private String address;
+
+ private double discount;
+
+ /**
+ * Returns the Id of the customer
+ */
+ @Id
+ public String getCustomerID() {
+ return customerID;
+ }
+
+ /**
+ * Sets the id of the customer
+ */
+ public void setCustomerID(String customerId) {
+ this.customerID = customerId;
+ }
+ /**
+ * Returns the name of the customer
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the customer
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the password of the customer
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * Sets the password of the customer
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ /**
+ * Returns the address of the customer
+ */
+ public String getAddress() {
+ return address;
+ }
+
+ /**
+ * Sets the address of the customer
+ */
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public double getDiscount() {
+ return discount;
+ }
+
+ public void setDiscount(double discount) {
+ this.discount = discount;
+ }
+
+ public Customer() {
+ }
+
+ /**
+ * Called when new data is created.
+ *
+ * We need to initialize our Bean's state with the parameters
+ * passed from the client by calling our own abstract set
+ * methods. The Container can then inspect our Bean and
+ * INSERT the corresponding database entries.
+ */
+ public void init(String id, String name, String password, String address) {
+ setCustomerID(id);
+ setName(name);
+ setAddress(address);
+ setPassword(password);
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/LineItem.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/LineItem.java
new file mode 100644
index 0000000..447cc75
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/LineItem.java
@@ -0,0 +1,132 @@
+package examples.shop.impl.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+
+
+/**
+ * A line item entity is a quantity of a single product.
+ *
+ * Instances of this class are used for both in-memory represenation
+ * of carts and the persistent representation of orders in
+ * the database
+ */
+@Entity
+public class LineItem implements java.io.Serializable {
+
+ private String id;
+
+ /** the product */
+ private Product product;
+
+ /** Number of items */
+ private int quantity;
+
+ /** Amount of the discount for each item */
+ private double discount;
+
+ /**
+ * Constructor
+ * @param productitem
+ * @param number of items
+ * @Param discount for each item
+ */
+ public LineItem(Product productItem, int quantity, double discount) {
+ System.out.println("LineItem(...) called");
+ this.product = productItem;
+ this.quantity = quantity;
+ this.discount = discount;
+ }
+
+ public LineItem() {
+ System.out.println("New LineItem created.");
+ }
+
+ /**
+ * The id number of this line item. This is our primary key as well.
+ *
+ * @return the id
+ */
+ @Id
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the id
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+
+ /**
+ * @return the productitem.
+ * productitem has product id, name of the product and description
+ */
+ @OneToOne
+ public Product getProduct() {
+ System.out.println("LineItem.getProduct() called.");
+ return product;
+ }
+
+ /**
+ * @param productItem.
+ */
+ public void setProduct(Product product) {
+ System.out.println("LineItem.setProduct() called.");
+ this.product = product;
+ }
+
+ /**
+ * @return the number of items.
+ */
+ public int getQuantity() {
+ System.out.println("LineItem.getQuantity() called.");
+ return quantity;
+ }
+
+ /**
+ * @param the number of items.
+ */
+ public void setQuantity(int quantity) {
+ System.out.println("LineItem.setQuantity() called.");
+ this.quantity = quantity;
+ }
+
+ /**
+ * @return the base price. The base price is the
+ * product's price times the quantity ordered. This
+ * figure does not take discounts into consideration.
+ */
+ public double basePrice() {
+ System.out.println("LineItem.getBasePrice() called.");
+ return quantity * product.getBasePrice();
+ }
+
+ /**
+ * @return the discount that the customer gets on
+ * this order.
+ *
+ * Note: The discount is a whole number, not
+ * a percentage discount.
+ */
+ public double getDiscount() {
+ System.out.println("LineItem.getDiscount() called.");
+ return discount;
+ }
+
+ /**
+ * @param the discount that the customer gets on
+ * this order.
+ *
+ * Note: The discount is a whole number, not
+ * a percentage discount.
+ */
+ public void setDiscount(double discount) {
+ System.out.println("LineItem.setDiscount(" + discount + ") called.");
+ this.discount = discount;
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Order.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Order.java
new file mode 100644
index 0000000..8986495
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Order.java
@@ -0,0 +1,183 @@
+package examples.shop.impl.entity;
+
+import java.sql.Timestamp;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+/**
+ * This entity represents an order placed for goods.
+ *
+ * Note: This entity could easily be extended to include other things, such as:
+ * <ul>
+ * <li>Shipping charges
+ * <li>Shipping address vs. Billing address
+ * <li>A date which this order is scheduled to be completed/shipped.
+ * </ul>
+ */
+
+@Entity
+@Table(name = "ORDERS")
+public class Order {
+
+ public enum Status {
+ Submitted, Unverified, Approved, Shipping, Delivered, Returned
+ };
+
+ private String orderId;
+
+ private List<LineItem> lineItems;
+
+ private Customer customer;
+
+ private Timestamp orderDate;
+
+ private Status status;
+
+ private double taxes;
+
+ private double subTotal;
+
+ /**
+ * This order's identification number. It's also our Primary Key.
+ *
+ * @return order id
+ */
+ @Id
+ public String getOrderID() {
+ return orderId;
+ }
+
+ /**
+ * Sets the order id of an order
+ */
+ public void setOrderID(String id) {
+ orderId = id;
+ }
+
+ /**
+ * This represents a one-to-many relationship to the
+ * line items in the order. Persisting the order cascades
+ * to the line items.
+ *
+ * @return the set of order line items
+ */
+ @OneToMany(cascade = CascadeType.PERSIST)
+ public List<LineItem> getLineItems() {
+ return lineItems;
+ }
+
+ /**
+ * Sets set of the order line items
+ */
+ public void setLineItems(List<LineItem> lineItems) {
+ this.lineItems = lineItems;
+ }
+
+ /**
+ * @returns the Customer who placed this Order.
+ */
+ public Customer getCustomer() {
+ return customer;
+ }
+
+ /**
+ * set customer who placed this order.
+ */
+ public void setCustomer(Customer customer) {
+ this.customer = customer;
+ }
+
+ /**
+ * Returns the date this order was placed.
+ */
+ public Timestamp getOrderDate() {
+ return orderDate;
+ }
+
+ /**
+ * Sets the date this order
+ */
+ public void setOrderDate(Timestamp orderDate) {
+ this.orderDate = orderDate;
+ }
+
+ /**
+ * @return status information about the order.
+ */
+ public Status getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets status information about the order.
+ */
+ public void setStatus(Status status) {
+ this.status = status;
+ }
+
+ /**
+ * Sets the subtotal of this order
+ */
+
+ public double getSubTotal() {
+ return subTotal;
+ }
+
+ /**
+ * Returns the subtotal of this order
+ */
+ public void setSubTotal(double subTotal) {
+ this.subTotal = subTotal;
+ }
+
+ /**
+ * Returns taxes of this order
+ */
+ public double getTaxes() {
+ return taxes;
+ }
+
+ /**
+ * Sets the taxes of this order
+ */
+ public void setTaxes(double taxes) {
+ this.taxes = taxes;
+ }
+
+ /**
+ * Returns the subtotal rice of the entire order, ie. the sum of
+ * the base prices of all line items in this order.
+ */
+ public double totalPrice() {
+ double totalPrice = 0;
+ for (Iterator<LineItem> iter = getLineItems().iterator(); iter
+ .hasNext();) {
+ LineItem item = iter.next();
+ totalPrice += item.getProduct().basePrice;
+ }
+ return totalPrice;
+ }
+
+ /**
+ * Called to initialize a new order entity
+ *
+ * We need to initialize our entity's state with the parameters passed from
+ * the client.
+ */
+ public void init(String orderID, Customer customer, Status status,
+ double subTotal, double taxes) {
+ System.out.println("Order.init(" + orderID + ") called");
+ setOrderID(orderID);
+ setOrderDate(new java.sql.Timestamp(System.currentTimeMillis()));
+ setStatus(status);
+ setSubTotal(subTotal);
+ setTaxes(taxes);
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Product.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Product.java
new file mode 100644
index 0000000..99fb29a
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Product.java
@@ -0,0 +1,93 @@
+package examples.shop.impl.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * Entity
+ *
+ * This is a product that's persistent. It has an ID #, a name,
+ * a description, and a base price.
+ */
+@Entity
+public class Product implements java.io.Serializable {
+
+ public String name;
+ public String description;
+ public double basePrice;
+ public String productID;
+
+ public Product() {
+ }
+
+ /**
+ * @return the product id.
+ */
+ @Id
+ public String getProductID() {
+ return productID;
+ }
+
+ /**
+ * Sets the product id.
+ */
+ public void setProductID(String productID) {
+ this.productID = productID;
+ }
+
+ /**
+ * @return the name of the product.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the product.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the description of the product.
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description of the product.
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * @return the base price of the product.
+ */
+ public double getBasePrice() {
+ return basePrice;
+ }
+
+ /**
+ * Sets the base price of the product.
+ */
+ public void setBasePrice(double price) {
+ this.basePrice = price;
+ }
+
+
+ /**
+ * This is the initialization method
+ */
+ public Product init(String productID, String name, String description,
+ double basePrice) {
+ this.productID = productID;
+ this.name = name;
+ this.description = description;
+ this.basePrice = basePrice;
+ return this;
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/mdb/OrderProcessorBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/mdb/OrderProcessorBean.java
new file mode 100644
index 0000000..a1056d1
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/mdb/OrderProcessorBean.java
@@ -0,0 +1,68 @@
+package examples.shop.impl.mdb;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJBException;
+import javax.ejb.MessageDriven;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import examples.shop.impl.entity.Order;
+
+
+/**
+ * This message-driven bean receives JMS messages
+ * to process orders. It then performs the order
+ * processing.
+ */
+@MessageDriven(activationConfig = {
+ @ActivationConfigProperty(
+ propertyName = "destinationType",
+ propertyValue = "javax.jms.Queue")
+ })
+public class OrderProcessorBean implements MessageListener {
+
+ @PersistenceContext
+ EntityManager manager;
+
+ public OrderProcessorBean() {
+ }
+
+ /**
+ * The one business method that message-driven beans have
+ * Here we perform the actual order processing
+ */
+ public void onMessage(Message msg) {
+ TextMessage tm = (TextMessage) msg;
+ try {
+ String orderID = tm.getText();
+ System.out.println("Processing order " + orderID);
+
+ Order order = manager.find(Order.class, orderID);
+
+ /*
+ * At this point, we could perform lots of tasks:
+ *
+ * - A call-out to a credit card company (perhaps through
+ * web services) to check the user's credit
+ * card rating and perform a debit.
+ *
+ * - Check the product inventory to ensure availability
+ *
+ * - Check the current backlog for shipping orders
+ *
+ * - Send an email confirmation
+ *
+ * In this example, we'll merely set the order status to
+ * "approved".
+ */
+ order.setStatus(Order.Status.Approved);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new EJBException(e);
+ }
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/CartBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/CartBean.java
new file mode 100644
index 0000000..d5e2b1b
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/CartBean.java
@@ -0,0 +1,320 @@
+package examples.shop.impl.session;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import examples.shop.impl.entity.Customer;
+import examples.shop.impl.entity.LineItem;
+import examples.shop.impl.entity.Order;
+import examples.shop.impl.entity.Product;
+import examples.shop.logic.Cart;
+
+/**
+ * This stateful session bean represents a cart which a customer is
+ * working on. A cart is a set of products that the customer is
+ * interested in, but has not committed to buying yet.
+ *
+ * A cart consists of a series of line items. Each line item
+ * represents one particular product the customer wants, as well as a
+ * quantity and discount for that product.
+ *
+ * The distinction between a cart and an order is that a quote is only
+ * temporary and in-memory (hence a stateful session bean), whereas an
+ * order is a persistent record (hence an entity). The cart bean
+ * knows how to transform itself into an order (via the purchase()
+ * method).
+ */
+
+@Stateful
+@Remote(Cart.class)
+public class CartBean implements Cart {
+
+ /**
+ * The shopping cart owner
+ */
+ private String owner;
+
+ /**
+ * The shopping cart contents - a vector of LineItems
+ */
+ private List<LineItem> contents = new ArrayList();
+
+ /**
+ * The subtotal (price before taxes) of the goods
+ */
+ private double subTotal;
+
+ /**
+ * The taxes on the goods
+ */
+ private double taxes;
+
+ @PersistenceContext
+ private EntityManager manager;
+
+ public CartBean() {
+ }
+
+ /**
+ * Get method for the shopping cart owner's name
+ *
+ * @return shopping cart owner
+ */
+ public String getOwner() {
+ return owner;
+ }
+
+ /**
+ * Set method for the shopping cart owner's name
+ *
+ * @param shopping
+ * cart owner
+ */
+ public void setOwner(String owner) {
+ this.owner = owner;
+ }
+
+ /**
+ * Adds an item to the shopping cart
+ *
+ * @param shopping
+ * cart lineitem
+ */
+ public void add(LineItem lineItem) {
+ /*
+ * Search for an exiting line item in the cart that match
+ * the productID passed in.
+ */
+ for (Iterator<LineItem> iter = contents.iterator(); iter.hasNext();) {
+ LineItem item = iter.next();
+ Product product = item.getProduct();
+
+ if (product != null
+ && product.getProductID().equals(
+ lineItem.getProduct().getProductID())) {
+ // found one, modify that line item's quantity and return
+ item.setQuantity(item.getQuantity() + lineItem.getQuantity());
+ return;
+ }
+ }
+
+ /*
+ * Did not find a match, so add the line item as new.
+ */
+ contents.add(lineItem);
+ }
+
+ /**
+ * Changes the quantities of contents in the shopping cart
+ *
+ * @param product
+ * Id
+ * @param number
+ * of items.
+ */
+ public void modify(String productID, int quantity) throws Exception {
+ System.out.println("CartBean.modify()");
+
+ /*
+ * Search for a lineitem in the cart that match the productID passed in.
+ * If found, modify that lineitem.
+ */
+ for (Iterator<LineItem> iter = contents.iterator(); iter.hasNext();) {
+ LineItem item = iter.next();
+ Product product = item.getProduct();
+ if (product != null && product.getProductID().equals(productID)) {
+ item.setQuantity(quantity);
+ if (quantity == 0) {
+ iter.remove();
+ }
+ return;
+ }
+ }
+ throw new Exception("CartBean.modify() error: Could not find product "
+ + productID);
+ }
+
+ /**
+ * Returns all the shopping cart line items
+ *
+ * @return A collection of Cart LineItems
+ */
+ public List<LineItem> getAll() {
+ return contents;
+ }
+
+ /**
+ * @return the subtotal price which has been previously set by
+ * setSubtotal().
+ */
+ public double getSubtotal() {
+ return subTotal;
+ }
+
+ /**
+ * Sets the subtotal price.
+ * @param subTotal the subtotal price
+ */
+ public void setSubtotal(double subTotal) {
+ this.subTotal = subTotal;
+ }
+
+ /**
+ * @return the taxes computed for this Cart.
+ */
+ public double getTaxes() {
+ return taxes;
+ }
+
+ /**
+ * Sets the taxes for this Cart.
+ */
+ public void setTaxes(double taxes) {
+ System.out.println("CartBean.setTaxes(): " + taxes);
+ this.taxes = taxes;
+ }
+
+ /**
+ * Get the total price. The total Price is computed from:
+ * <ol>
+ * <li>Subtotal price
+ * <li>Tax
+ * </ol>
+ * @return the total price.
+ */
+ public double getTotalPrice() {
+ return subTotal + taxes;
+ }
+
+ /**
+ * Empties the shopping cart
+ */
+ public void clear() {
+ contents.clear();
+ }
+
+ /**
+ * Purchases this cart. The cart will create an order in the database
+ * and return the order ID as a confirmation number.
+ *
+ * @return The Order confirmation number
+ */
+ public String purchase() {
+ System.out.println("CartBean.purchase()");
+ Customer customer = manager.find(Customer.class, owner);
+
+ /*
+ * Create the order entity
+ */
+ Order order = new Order();
+ String orderID = makeUniqueID();
+ order.init(orderID, customer, Order.Status.Unverified, subTotal, taxes);
+ order.setLineItems(prepareContents());
+ manager.persist(order);
+
+ /*
+ * Sends the JMS message to the topic
+ */
+ try {
+ sendMessage(orderID);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ /*
+ * Return the order ID
+ */
+ return orderID;
+ }
+
+ /**
+ * Sends a JMS message to a destination (Queue or Topic)
+ *
+ * @param a
+ * message string, in this case orderId
+ */
+ private void sendMessage(String text) throws Exception {
+ Connection connection = null;
+ MessageProducer producer = null;
+ Session session = null;
+
+ try {
+ Context jndiContext = new InitialContext();
+ ConnectionFactory connectionFactory = (ConnectionFactory) jndiContext
+ .lookup("jms/QueueConnectionFactory");
+ Destination destination = (Destination) jndiContext
+ .lookup("jms/OrderQueue");
+ connection = connectionFactory.createConnection();
+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ producer = session.createProducer(destination);
+
+ connection.start();
+ TextMessage msg = session.createTextMessage();
+ msg.setText(text);
+ producer.send(msg);
+ } catch (Exception ex) {
+ throw ex;
+ } finally {
+ if (connection != null) {
+ try {
+ producer.close();
+ connection.close();
+ session.close();
+ } catch (JMSException e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ /**
+ * Generates primary keys for line items and loads the products
+ * into the persistence context.
+ */
+
+ private List<LineItem> prepareContents() {
+ for (Iterator<LineItem> iter = contents.iterator(); iter.hasNext();) {
+ LineItem lineItem = iter.next();
+ Product p = manager.find(Product.class, lineItem.getProduct()
+ .getProductID());
+ lineItem.setProduct(p);
+ lineItem.setId(makeUniqueID());
+ }
+ return contents;
+ }
+
+ /**
+ * Returns a unique Id based on current time. Can be removed
+ * when AUTO key generation works in Glassfish *
+ */
+ private String makeUniqueID() {
+ String id = new Long(System.nanoTime()).toString();
+ System.out.println("makeUniqueID: " + id);
+ return id;
+ }
+
+ /**
+ * Removes this quote, and hence all client-
+ * specific state.
+ */
+ @Remove
+ public void remove() {
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/CatalogBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/CatalogBean.java
new file mode 100644
index 0000000..658b675
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/CatalogBean.java
@@ -0,0 +1,41 @@
+package examples.shop.impl.session;
+
+import java.util.List;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import examples.shop.impl.entity.Product;
+import examples.shop.logic.Catalog;
+
+/**
+ * This catalog Stateless Session Bean retrieves a list of productitems.
+ * ProductItem has product Id, name of the product and description
+ */
+@Stateless
+@Remote(Catalog.class)
+public class CatalogBean implements Catalog {
+
+ @PersistenceContext
+ private EntityManager manager;
+
+ public CatalogBean() {
+ }
+
+ public Product getProduct(String productId) {
+ return manager.find(Product.class, productId);
+ }
+
+ public List<Product> getProductList() {
+ /* find all products */
+ return manager.createQuery("SELECT p FROM Product p")
+ .getResultList();
+ }
+
+ public void addProduct(Product product) {
+ manager.persist(product);
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/PricerBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/PricerBean.java
new file mode 100644
index 0000000..cbcb73f
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/PricerBean.java
@@ -0,0 +1,138 @@
+package examples.shop.impl.session;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.jws.WebService;
+
+import examples.shop.impl.entity.Customer;
+import examples.shop.impl.entity.LineItem;
+import examples.shop.logic.Pricer;
+import examples.shop.logic.UserManager;
+
+/**
+ * Stateless Session Bean which computes prices based
+ * upon a set of pricing rules. The pricing rules are
+ * deployed with the bean as environment properties.
+ */
+@Stateless
+@Remote(Pricer.class)
+@WebService(serviceName="PricerService", portName="PricerPort")
+public class PricerBean implements Pricer {
+
+ @Resource(name="taxRate")
+ public int taxRate = 0;
+
+ @Resource(name="bulkDiscountRate")
+ public int bulkDiscountRate = 0;
+
+ @EJB
+ UserManager userManager;
+
+ public PricerBean() {
+ }
+
+ /**
+ * bulk discounts apply to quantities of BULK or more items
+ */
+ private static final int BULK = 5;
+
+ /**
+ * This method computes the applicable discount in absolute
+ * figure, based on bulk and personal discounts that may apply.
+ *
+ * @param quantity the number of items that a user intends to buy
+ * @param basePrice the overall, non-discounted volume of the
+ * purchase (individual price times quantity)
+ * @param the user name
+ * @return the subTotal for the line item after applying any
+ * applicable discounts, excluding taxes
+ */
+ public double getDiscount(int quantity, double basePrice, String user) {
+ double discountRate = getPersonalDiscountRate(user);
+ if (quantity >= BULK) {
+ discountRate += getBulkDiscountRate();
+ System.out.println("Using getBulkDiscountRate " + getBulkDiscountRate());
+ }
+
+ /*
+ * Calculate the discount in absolute figures
+ */
+ return basePrice * (discountRate / 100);
+ }
+
+ /**
+ * A bulk discount applies to quantities of more than 5 pieces.
+ * @return the bulk discount rate int percent
+ */
+ public double getBulkDiscountRate() {
+ return this.bulkDiscountRate;
+ }
+
+ /**
+ * Customers with certain names get discounts. The discount rules
+ * are stored in the environment properties that the bean is
+ * deployed with.
+ */
+ public double getPersonalDiscountRate(String userName) {
+ /*
+ * Get the name of this customer.
+ */
+ Customer user = userManager.getUser(userName);
+ if( user != null)
+ return user.getDiscount();
+ else
+ return 0;
+ }
+
+ /**
+ * Computes the subtotal price for a set of products the customer
+ * is interested in. The subtotal takes into account the price of
+ * each product the customer wants, the quantity of each product,
+ * and any personal discounts the customer gets. However, the
+ * subtotal ignores taxes.
+ *
+ * @param quote All the data needed to compute the
+ * subtotal is in this parameter.
+ */
+ public double priceSubtotal(String user, List<LineItem> items) {
+ System.out.println("PricerBean.priceSubtotal() called");
+
+ /*
+ * Compute the subtotal
+ */
+ double subTotal = 0;
+
+ for(Iterator<LineItem> iter = items.iterator(); iter.hasNext(); ) {
+ LineItem item = iter.next();
+ item.setDiscount(
+ getDiscount(item.getQuantity(), item.basePrice(),user));
+
+ /*
+ * Add the price to the subtotal.
+ */
+ subTotal += (item.basePrice() - item.getDiscount());
+ }
+
+ return subTotal;
+ }
+
+ /**
+ * Computes the taxes on a quote.
+ */
+ public double priceTaxes(double subtotal) {
+ System.out.println("PricerBean.priceTaxes() called, taxes: " + getTaxRate());
+ return (getTaxRate() / 100) * subtotal;
+ }
+
+ /**
+ * @return the applicable tax rate
+ */
+ public double getTaxRate() {
+ return taxRate;
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/UserManagerBean.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/UserManagerBean.java
new file mode 100644
index 0000000..babb67e
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/session/UserManagerBean.java
@@ -0,0 +1,86 @@
+package examples.shop.impl.session;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import examples.shop.impl.entity.Customer;
+import examples.shop.logic.InvalidPasswordException;
+import examples.shop.logic.UserManager;
+
+/**
+ * UserManager is Stateless session bean resposible for creating and
+ * retrieving a customer record. It also authenticates the user.
+ */
+
+@Stateless
+@Remote(UserManager.class)
+public class UserManagerBean implements UserManager {
+
+ @PersistenceContext
+ EntityManager manager;
+
+ public UserManagerBean() {
+ }
+
+ /**
+ * Returns an customer object for the given customer id.
+ */
+ public Customer getUser(String customerId) {
+ return manager.find(Customer.class, customerId);
+ }
+
+ /**
+ * It uses the customer entity bean to create a record in the databse
+ * @param customerId
+ * @param name
+ * @param password
+ * @param address
+ */
+
+ public Customer createUser(String customerId, String name, String password, String address) {
+ Customer customer = new Customer();
+ customer.init(customerId, name, password, address);
+ manager.persist(customer);
+ return customer;
+ }
+
+ /**
+ * This method authenticates the user
+ *
+ * @return true, if the password is correct
+ * @throws an InvalidPasswordException if password is incorrect.
+ */
+
+ public boolean validateUser(String customerID, String password)
+ throws InvalidPasswordException {
+ if(customerID== null || password == null)
+ throw new IllegalArgumentException("id " + customerID + " pw " + password);
+ Customer user = getUser(customerID);
+ if (user != null && password.equals(user.getPassword())) {
+ return true;
+ } else {
+ System.out.println("Failure to validate user ID " + customerID
+ + " with password " + password + " against password "
+ + user.getPassword());
+
+ throw new InvalidPasswordException("Invalid Password:"
+ + password);
+ }
+ }
+
+ public List<Customer> findAllCustomers() {
+ return manager.createQuery("SELECT c FROM Customer c").getResultList();
+ }
+
+ public void removeAllCustomers() {
+ List l = manager.createQuery("SELECT c FROM Customer c ").getResultList();
+ for(Iterator iter = l.iterator(); iter.hasNext();) {
+ manager.remove(iter.next());
+ }
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/Cart.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/Cart.java
new file mode 100644
index 0000000..b636de2
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/Cart.java
@@ -0,0 +1,81 @@
+package examples.shop.logic;
+
+import java.util.List;
+
+import examples.shop.impl.entity.LineItem;
+
+/**
+ * The Cart interface.
+ */
+public interface Cart {
+
+ /**
+ * Adds an item to the shopping cart
+ */
+ public void add(LineItem lineItem);
+
+ /**
+ * Changes the quantities of contents in the shopping cart
+ */
+ public void modify(String productID, int quantity)
+ throws Exception;
+
+ /**
+ * Returns all the shopping cart line items
+ *
+ * @return A collection of Cart LineItems
+ */
+ public List<LineItem> getAll();
+
+ /**
+ * Empties the shopping cart
+ */
+ public void clear();
+
+ /**
+ * Get/set methods for the shopping cart owner's name
+ */
+ public String getOwner();
+
+ public void setOwner(String owner);
+
+ /**
+ * Purchases this cart. The cart will create an order in the database.
+ *
+ * @return The Order confirmation number
+ */
+ public String purchase();
+
+ /**
+ * Returns the subtotal price which has been previously set by
+ * setSubtotal().
+ *
+ * @return the subtotal of this cart items.
+ */
+ public double getSubtotal();
+
+ /**
+ * Sets the subtotal price. Our external pricer bean is responsible for
+ * calculating the subtotal. It calculates it based upon customer discounts
+ * (and can be extended to include other rules as well).
+ */
+ public void setSubtotal(double subTotal);
+
+ /**
+ * Returns the taxes for this Quote.
+ */
+ public double getTaxes();
+
+ /**
+ * Sets the taxes for this Quote.
+ */
+ public void setTaxes(double taxes);
+
+ /**
+ * Returns the total price. Total Price is computed from: 1) Subtotal price
+ * 2) Tax
+ */
+ public double getTotalPrice();
+
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/Catalog.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/Catalog.java
new file mode 100644
index 0000000..32310fd
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/Catalog.java
@@ -0,0 +1,31 @@
+package examples.shop.logic;
+
+import java.util.*;
+
+import examples.shop.impl.entity.Product;
+
+/**
+ * This is the Catalog business interface.
+ */
+
+public interface Catalog {
+
+ /**
+ * @return a vector of Products
+ */
+ public List<Product> getProductList();
+
+ /**
+ * @return a Product for the given product id.
+ */
+ public Product getProduct(String productId);
+
+ /**
+ * Add a new product to the catalog
+ * @param product
+ */
+ public void addProduct(Product product);
+
+}
+
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/InvalidLoginNameException.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/InvalidLoginNameException.java
new file mode 100644
index 0000000..4583f48
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/InvalidLoginNameException.java
@@ -0,0 +1,19 @@
+package examples.shop.logic;
+
+/**
+ * Exceptions thrown by usermanager
+ */
+public class InvalidLoginNameException extends Exception {
+
+ public InvalidLoginNameException() {
+ super();
+ }
+
+ public InvalidLoginNameException(Exception e) {
+ super(e.toString());
+ }
+
+ public InvalidLoginNameException(String s) {
+ super(s);
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/InvalidPasswordException.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/InvalidPasswordException.java
new file mode 100644
index 0000000..5d0db3c
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/InvalidPasswordException.java
@@ -0,0 +1,19 @@
+package examples.shop.logic;
+
+/**
+ * Exceptions thrown by usermanager
+ */
+public class InvalidPasswordException extends Exception {
+
+ public InvalidPasswordException() {
+ super();
+ }
+
+ public InvalidPasswordException(Exception e) {
+ super(e.toString());
+ }
+
+ public InvalidPasswordException(String s) {
+ super(s);
+ }
+} \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/OrderException.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/OrderException.java
new file mode 100644
index 0000000..bd08de0
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/OrderException.java
@@ -0,0 +1,19 @@
+package examples.shop.logic;
+
+/**
+ * Exceptions thrown by Order
+ */
+public class OrderException extends Exception {
+
+ public OrderException() {
+ super();
+ }
+
+ public OrderException(Exception e) {
+ super(e.toString());
+ }
+
+ public OrderException(String s) {
+ super(s);
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/Pricer.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/Pricer.java
new file mode 100644
index 0000000..5c10b41
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/Pricer.java
@@ -0,0 +1,50 @@
+package examples.shop.logic;
+
+import java.util.List;
+
+import examples.shop.impl.entity.LineItem;
+
+/**
+ * These are the business logic methods exposed publicly by the
+ * Pricer component, a function that computes a price for a
+ * given user and base price.
+ */
+
+public interface Pricer {
+ /**
+ * Computes the price of a set of goods
+ */
+
+ public double priceSubtotal(String user, List<LineItem> items);
+
+ public double priceTaxes(double subtotal);
+
+ /**
+ * @return the applicable tax rate
+ */
+ double getTaxRate();
+
+ /**
+ * @return the current discount rate for buying lots of items
+ */
+ double getBulkDiscountRate();
+
+ /**
+ * @return the discount rate for a given user in percent
+ */
+ double getPersonalDiscountRate(String userName);
+
+ /**
+ * This method computes the applicable discount in absolute
+ * figure, based on bulk and personal discounts that may apply.
+ *
+ * @param quantity the number of items that a user intends to buy
+ * @param basePrice the overall, non-discounted volume of the
+ * purchase (individual price times quantity)
+ * @param the user name
+ * @return the subTotal for the line item after applying any
+ * applicable discounts, excluding taxes
+ */
+ double getDiscount(int quantity, double basePrice, String user);
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/PricerException.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/PricerException.java
new file mode 100644
index 0000000..e198a6a
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/PricerException.java
@@ -0,0 +1,19 @@
+package examples.shop.logic;
+
+/**
+ * Exceptions thrown by Pricer
+ */
+public class PricerException extends Exception {
+
+ public PricerException() {
+ super();
+ }
+
+ public PricerException(Exception e) {
+ super(e.toString());
+ }
+
+ public PricerException(String s) {
+ super(s);
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/UserManager.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/UserManager.java
new file mode 100644
index 0000000..f34575d
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/logic/UserManager.java
@@ -0,0 +1,38 @@
+package examples.shop.logic;
+
+import java.util.List;
+
+import examples.shop.impl.entity.Customer;
+
+/**
+ * This is the UserManager interface.
+ */
+public interface UserManager {
+
+ /**
+ * It uses the customer entity bean to crate a record in the databse
+ */
+ public Customer createUser(String customerId, String name, String password,
+ String address);
+
+ /**
+ * Returns an user object for the given customer id. It uses customer entity
+ * bean to retrieve the user record.
+ */
+ public Customer getUser(String customerId);
+
+ /**
+ * Authenticate the user.
+ */
+ public boolean validateUser(String login, String password)
+ throws InvalidPasswordException;
+
+ /**
+ * Demo lookup
+ *
+ * @return
+ */
+ public List<Customer> findAllCustomers();
+
+ public void removeAllCustomers();
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/catalog.jsp b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/catalog.jsp
new file mode 100644
index 0000000..92ccf8d
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/catalog.jsp
@@ -0,0 +1,44 @@
+<%-- This JSP Retrieves products vector from HttpSession and displays in table format.
+ The product details includes name the product and its base price. User can view the
+ product details by clicking on name of the product. User can also add a product to
+ the shopping cart by clicking on add to cart link. When user clicks on add to cart
+ link, item is added to the cart and displays same at the bottom of the screen.
+
+--%>
+<%@ page import="examples.shop.impl.entity.Product" %>
+<html>
+ <head><title> Jasmine's Catalog page </title></head>
+ <body>
+ <jsp:include page="title.jsp" />
+ <h3><A HREF="/jasmine/showQuote">View Current Shopping Cart</A></h3>
+ <h3>Please choose from our selections</h3>
+ <center><table>
+ <%
+ //Retrieves catalog vector from HTTPSession and displays product item details in a table format
+ session = request.getSession(false);
+ java.util.Vector products=(java.util.Vector)session.getAttribute("products");
+ int size=products.size();
+ Product item=null;
+ for(int i=0; i<size;i++){
+ item=(Product)products.elementAt(i);
+ %>
+ <tr>
+ <td bgcolor="#ffffaa"><a href="/jasmine/catalog?productId=<%=item.getProductID()%>"><b><%=item.getName()%><b></td>
+ <td align="right" bgcolor="#ffffaa"><%=item.getBasePrice()%></td>
+ <td bgcolor="#ffffaa"> <A HREF="/jasmine/catalog?Buy=<%=item.getProductID()%>"> Add to Cart</A></td>
+ </tr>
+ <%}%>
+ </table></center>
+ <P>
+ <%
+ // Displays the name of the product item added to the cart, at the bottom of the page.
+ String productName = (String) request.getAttribute("ProductPurchased");
+ if (productName != null) {
+ %>
+ <i> <%=productName%></i> has been added to your shopping cart.
+ <% } %>
+
+ <jsp:include page="footer.jsp" />
+
+ </body>
+</html>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/clearQuote.jsp b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/clearQuote.jsp
new file mode 100644
index 0000000..0c13d29
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/clearQuote.jsp
@@ -0,0 +1,15 @@
+<%-- When user clicks on clear cart button, servlet forwards request to this jsp --%>
+<html>
+ <head><title>Jasmine's Clear Cart page</title></head>
+
+ <BODY>
+ <jsp:include page="title.jsp" />
+ <font size="+2"><strong>You just cleared your Cart!</strong></font>
+ <br>&nbsp;
+ <br>
+ <center>
+ <a href="/jasmine/wsf.jsp">Back to the main page</a>
+ </center>
+ <jsp:include page="footer.jsp" />
+ </BODY>
+</html>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/emptyQuote.jsp b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/emptyQuote.jsp
new file mode 100644
index 0000000..f0779bd
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/emptyQuote.jsp
@@ -0,0 +1,15 @@
+<%-- If shopping cart is empty and user clicks on shopping cart link, servlet forwards request to this jsp --%>
+<html>
+ <head><title> Jasmine's Empty Cart page</title></head>
+ <BODY>
+ <jsp:include page="title.jsp" />
+ <font size="+2">Your Cart is empty.</font>
+ <br>&nbsp;
+ <br>
+ <center>
+ <a href="/jasmine/wsf.jsp">Back to the web storefront.</a>
+ </center>
+ <jsp:include page="footer.jsp" />
+
+ </BODY>
+</html>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/error.jsp b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/error.jsp
new file mode 100644
index 0000000..47aaca8
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/error.jsp
@@ -0,0 +1,11 @@
+<%-- JSP container forwards request to this jsp, if any exceptions in processing --%>
+<html>
+ <head><title> Jasmine's Error page </title></head>
+ <body>
+ <jsp:include page="title.jsp" />
+ <p>Error in processing your request.
+ <p>Please contact System Administrator
+ <p><i><a href="/jasmine/wsf.jsp">Click here to return to the main page.</a></i>
+ </body>
+</html>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/footer.jsp b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/footer.jsp
new file mode 100644
index 0000000..2df4e29
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/footer.jsp
@@ -0,0 +1,5 @@
+<%-- Diplays Footer --%>
+<hr>
+<i>&copy; 2004-2006, Jasmine's Computer Parts, Inc., All rights reserved.</i>
+<br>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/login.jsp b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/login.jsp
new file mode 100644
index 0000000..8d773b3
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/login.jsp
@@ -0,0 +1,70 @@
+<%--
+ This JSP displays a login screen. When the user fills out the login
+ screen, it will submit it to the Login Servlet, which will verify the
+ user's credentials by calling EJB components.
+
+ If the verification is unsuccessful, the login servlet will return
+ the user to this page to re-enter his credentials.
+
+ If the verification is successful, Jasmine's main page will be displayed.
+--%>
+
+<html>
+<head>
+ <title>Jasmine's Login page </title>
+</head>
+
+<body>
+
+<%-- Include the title, which is "Jasmine's Computer Parts"--%>
+<jsp:include page="title.jsp" />
+
+<%-- Indicate the error page to use if an error occurs --%>
+<jsp:directive.page errorPage="error.jsp" />
+
+<%-- Display the login form --%>
+<h4>Please enter login information</h4>
+<p>
+<form action="/jasmine/login" method="get">
+ <table>
+ <tr>
+ <td><b>Name:</b></td>
+ <td>
+ <input type="text" name="Login" size="19"/>
+ </td>
+ </tr>
+ <tr>
+ <td><b>Password:</b></td>
+ <td>
+ <input type="text" name="Password" size="19"/>
+ </td>
+ </tr>
+ <tr>
+ <td></td>
+ <td>
+ <input type="submit" value="Submit Information"/>
+ <input type="submit" value="Register"/>
+ </td>
+ </tr>
+ </table>
+</form>
+
+<%
+ // get whether the person logged in successfully
+ Boolean failed = (Boolean) request.getAttribute("loginFailed");
+ if (failed != null) {
+ if (failed.booleanValue() == true) {
+%>
+ <p>
+ <strong>Could not log in! Please try again.</strong>
+ <p>
+<%
+ }
+ }
+%>
+
+<%-- Include the page footer --%>
+<jsp:include page="footer.jsp" />
+
+</body>
+</html>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/productInfo.jsp b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/productInfo.jsp
new file mode 100644
index 0000000..e18ea8a
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/productInfo.jsp
@@ -0,0 +1,32 @@
+<%--This JSP displays details of the selected product.
+ Customer can add this item to the shopping cart by clicking on add to cart link.
+ Customer has provision to navigate to the catalog as well as to the shopping cart pages.
+ --%>
+<%@ page import="examples.shop.impl.entity.Product" %>
+
+<html>
+ <head><title> Jasmine's Product Info page</title></head>
+ <body>
+ <jsp:include page="title.jsp" />
+ <jsp:directive.page errorPage="error.jsp" />
+
+ <%
+ //Retrieves the productItem from request object and displays.
+ Product item=(Product)request.getAttribute("productItem");
+ %>
+
+ <b><%=item.getName()%><b>
+ <h4> Description:</h4>
+ <%=item.getDescription()%>
+ <h4>Base price (before discounts):<%=item.getBasePrice()%></h4>
+
+ <center>
+ <A href="/jasmine/catalog?Buy=<%=item.getProductID()%>">Add this item to Cart</A><br>
+ <A href="/jasmine/catalog">See the Catalog</A><br>
+ <A href="/jasmine/showQuote">View Current Shopping Cart</A>
+
+ <jsp:include page="footer.jsp" />
+
+ </center>
+ </body>
+</html>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/receipt.jsp b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/receipt.jsp
new file mode 100644
index 0000000..448a26b
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/receipt.jsp
@@ -0,0 +1,19 @@
+<%--This JSP displays order confirmation. When user clicks on order button,
+ Order will be created in the database and order confirmation number will be
+ displayed to the customer.
+ --%>
+<html>
+ <head><title> Jasmine's Order Confirmation page </title></head>
+ <body>
+ <jsp:include page="title.jsp" />
+ <jsp:directive.page errorPage="error.jsp" />
+ <%-- Retrieves Order Id from request object and displays.--%>
+ <h3>Thank you for shopping with us.
+ <p>Your order number is <%=request.getAttribute("orderID")%>
+ <p>Please shop with us again soon!
+ </h3>
+ <p><i><a href="/jasmine/wsf.jsp">Click here to return to the main page.</a></i>
+ <jsp:include page="footer.jsp" />
+ </body>
+</html>
+
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/showQuote.jsp b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/showQuote.jsp
new file mode 100644
index 0000000..d01abbb
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/showQuote.jsp
@@ -0,0 +1,87 @@
+<%--
+ This JSP displays details of the products added to the cart.
+ The details includes the name of the product, quantity, base price,
+ discount and total price of each line item. It also displays subtotal,
+ taxes and grand total of the entire cart. Customer has provision to
+ modify the quantities, order the contents and clear the cart.
+
+--%>
+<HTML>
+ <head><title> Jasmine's Shopping Cart page </title></head>
+ <body>
+ <jsp:include page="title.jsp" />
+ <jsp:directive.page errorPage="error.jsp" />
+ <%@ page import="examples.shop.impl.entity.Product" %>
+ <%@ page import="examples.shop.impl.entity.LineItem" %>
+ <%@ page import="java.util.List" %>
+ <%@ page import="java.util.Iterator" %>
+ <%@ page import="java.text.NumberFormat" %>
+ <form action="/jasmine/showQuote" method="get">
+ <center><table>
+ <tr>
+ <th align=left> Name </TH>
+ <th align=left> Quantity </TH>
+ <th align=left> Individual Base Price </TH>
+ <th align=left> Discount </TH>
+ <th align=left><strong> Total Price </strong></TH>
+ </tr>
+ <%
+ // get the lineItems from the request object and displays in a table format.
+ List<LineItem> lineItems = (List<LineItem>)request.getAttribute("lineItems");
+ double subTotal=((Double)request.getAttribute("subTotal")).doubleValue();
+ double taxes=((Double)request.getAttribute("taxes")).doubleValue();
+ double taxRate=((Double)request.getAttribute("taxRate")).doubleValue();
+ double total=((Double)request.getAttribute("total")).doubleValue();
+
+ for(Iterator<LineItem> iter = lineItems.iterator(); iter.hasNext();) {
+ LineItem li = iter.next();
+ int quantity = li.getQuantity();
+ double discount = li.getDiscount();
+ Product product = li.getProduct();
+ String productID = product.getProductID();
+ double basePrice = product.getBasePrice();
+ %>
+ <tr>
+ <td bgcolor="#ffffaa"><a href="/jasmine/catalog?productId=<%=product.getProductID()%>"><b><%=product.getName()%><b></td>
+ <td><input type="text" name="<%=productID%>" value="<%=quantity%>"></td>
+ <td bgcolor="#ffffaa" align="right"><%=basePrice%></td>
+ <td bgcolor="#ffffaa" align="right"><%=discount%></td>
+ <td bgcolor="#ffffaa" align="right"><%=basePrice*quantity-discount%></td>
+
+ </tr>
+ <% } %>
+ </table></center>
+ <br>
+ <center><table>
+ <tr>
+ <td colspan="2" align="right" bgcolor="#ffffff"> Subtotal:</td>
+ <td bgcolor="#ffffaa" align="right"><%=subTotal%></td>
+ <td> <br></td>
+ </tr>
+ <tr>
+ <td colspan="2" align="right" bgcolor="#ffffff">Sales Tax: </td>
+ <td bgcolor="#ffffaa" align="right"><%=taxes%></td><td align="right">(<%=taxRate%>)%</td>
+ <td><br></td>
+ </tr>
+ <tr>
+ <td colspan="2" align="right" bgcolor="ffffff"> <font color="ff0000"> <strong>Grand Total:</strong></font> </td>
+ <td bgcolor="#ffffaa" align="right"><%=total%></td>
+ <td><br></td>
+ </tr>
+ </table></center>
+ <!--
+ Print out links and buttons for user feedback.
+ When the customer clicks a button to perform an
+ action (such as submitting an order), sends request to
+ the servlet with necessary parameters to process the request.
+ //-->
+ <p>
+ <A href="/jasmine/catalog">See the Catalog</A>
+ <input type="submit" name="Update" value="Update Quantities"> &nbsp; &nbsp; &nbsp;
+ <input type="submit" name="Order" value="Submit Order"> &nbsp; &nbsp; &nbsp;
+ <input type="submit" name="Clear" value="Clear Cart"> &nbsp; &nbsp; &nbsp;
+
+ <jsp:include page="footer.jsp" />
+ </form>
+ </body>
+</html>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/title.jsp b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/title.jsp
new file mode 100644
index 0000000..afaaea1
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/title.jsp
@@ -0,0 +1,8 @@
+<%-- Diplays title --%>
+<hr>
+<p>
+ <center>
+ <h1>Jasmine's Computer Parts</h1>
+ </center>
+</p>
+<hr> \ No newline at end of file
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/wsf.jsp b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/wsf.jsp
new file mode 100644
index 0000000..de589f1
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/jsp/wsf.jsp
@@ -0,0 +1,22 @@
+<%--
+ This JSP page displays Jasmine's main screen.
+ Customers can navigate to the catalog as well as
+ to the shopping cart page.
+--%>
+
+<html>
+ <head>
+ <title>Jasmine's Main page</title>
+ </head>
+ <body>
+ <jsp:include page="title.jsp" />
+ <jsp:directive.page errorPage="error.jsp" />
+
+ <h3><A href="/jasmine/catalog"><b>Catalog</b></A></h3>
+ <h4><p> Choose from our excellent selection of computer parts.</p><br></h4>
+ <h3><A href="/jasmine/showQuote"><b>Shopping Cart</b></A></h3>
+ <h4><p> Look at your shopping cart to see the equipment you've chosen.</p></h4>
+
+ <jsp:include page="footer.jsp" />
+ </body>
+</html>
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/servlet/CatalogServlet.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/servlet/CatalogServlet.java
new file mode 100644
index 0000000..1a0049a
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/servlet/CatalogServlet.java
@@ -0,0 +1,167 @@
+package examples.shop.web.servlet;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import examples.shop.impl.entity.LineItem;
+import examples.shop.impl.entity.Product;
+import examples.shop.logic.Cart;
+import examples.shop.logic.Catalog;
+
+/**
+ * This servlet displays a catalog of products to
+ * the end-user.
+ *
+ * By the time this servlet is called, the user has
+ * logged in (via the Login servlet), and has a shopping
+ * cart started (i.e. Cart bean). Since this servlet is
+ * pooled and re-used for different user requests, the
+ * servlet code does not store any information specific to
+ * any user. Rather, we store a reference to the user's
+ * Cart in the user's HttpSession object, which is
+ * globally accessible to all servlets.
+ */
+public class CatalogServlet extends HttpServlet {
+
+ public Catalog catalog;
+
+ /**
+ * The servlet engine calls this method once to
+ * initialize a servlet instance.
+ */
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ try {
+ Context ctx = new InitialContext();
+ catalog = (Catalog)ctx.lookup(Catalog.class.getName());
+ } catch (NamingException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * The servlet engine calls this method when the user's
+ * desktop browser sends an HTTP request.
+ */
+ public void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ List<Product> products = null;
+ try {
+ /*
+ * Get the user's HttpSession, and from that get
+ * the user's current cart.
+ */
+ HttpSession session = request.getSession(false);
+ if (session == null) {
+ /*
+ * Redirect user to login page if he
+ * doesn't have a session.
+ */
+ response.sendRedirect(response
+ .encodeRedirectURL("/jasmine/login"));
+ return;
+ }
+
+ Object obj = session.getAttribute("cart");
+ if (obj == null) {
+ /*
+ * Redirect user to login page if he
+ * doesn't have a session.
+ */
+ response.sendRedirect(response
+ .encodeRedirectURL("/jasmine/login"));
+ return;
+ }
+ Cart cart = (Cart) obj;
+ String productIDToAdd = request.getParameter("Buy");
+ products = (Vector) session.getAttribute("products");
+ String productId = (String) request.getParameter("productId");
+
+ /*
+ * If user wants to purchase something (via
+ * the URL parameter 'Buy'), add the desired
+ * product item to the cart.
+ */
+
+ if (productIDToAdd != null) {
+ /*
+ * Creates LineItem, and add to the cart.
+ */
+ try {
+ Product item = getProductItem(products, productIDToAdd);
+ cart.add(new LineItem(item, 1, 0));
+ // Set a flag so that JSP knows which product we purchased
+ request.setAttribute("ProductPurchased", item.getName());
+ // Forwards the request to the catalog JSP
+ this.getServletContext().getRequestDispatcher(
+ "/catalog.jsp").forward(request, response);
+ return;
+ } catch (Exception e) {
+ throw new ServletException(e.toString());
+ }
+ }
+ /*
+ * If user wants to view the product details (via
+ * the URL parameter 'productId')
+ */
+ else if (productId != null) {
+ //Retrieves the product item from the prducts vector and pass it in request object.
+ request.setAttribute("productItem", getProductItem(products,
+ productId));
+ // Forwards the request to the productInfo JSP
+ this.getServletContext().getRequestDispatcher(
+ "/productInfo.jsp").forward(request, response);
+ return;
+ }
+ /*
+ * If products vector = null,Retrieves productItems vector
+ * from Catalog stateless session bean and put it in the
+ * HttpSession. we may need to put this vector in
+ * application level instead of session.
+ */
+ else {
+ if (products == null) {
+ products = catalog.getProductList();
+ session.setAttribute("products", products);
+ }
+ // Forwards the request to the catalog JSP
+ this.getServletContext().getRequestDispatcher("/catalog.jsp")
+ .forward(request, response);
+ return;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Returns the product for the given product id, if it is in the vector
+ */
+
+ private Product getProductItem(List<Product> products, String productIDToAdd) {
+ for (Iterator<Product> iter = products.iterator(); iter.hasNext();) {
+ Product item = iter.next();
+ if (item.getProductID().equals(productIDToAdd)) {
+ return item;
+ }
+ }
+ return null;
+ }
+
+ public String getServletInfo() {
+ return "The Catalog servlet adds products to the user's "
+ + "cart and prints the catalog.";
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/servlet/LoginServlet.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/servlet/LoginServlet.java
new file mode 100644
index 0000000..0340fd9
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/servlet/LoginServlet.java
@@ -0,0 +1,166 @@
+package examples.shop.web.servlet;
+
+import java.io.IOException;
+
+import javax.ejb.EJB;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import examples.shop.logic.Cart;
+import examples.shop.logic.UserManager;
+
+/**
+ * This is the very first servlet the client deals with. It's a Login
+ * authentication servlet and asks the user for his name and password,
+ * and pass it to the UserManager stateless session bean for verificatiion.
+ *
+ * If the user authenticates properly, a reference to a new Cart is saved
+ * in his HttpSession object, and the user can begin to add items to his
+ * cart and shop around.
+ */
+public class LoginServlet extends HttpServlet {
+
+ /** the user manager used to authenticate the user */
+ @EJB
+ UserManager userManager;
+
+ /** the user's cart object */
+ @EJB
+ Cart cart;
+
+ /**
+ * The servlet engine calls this method once to initialize a servlet
+ * instance.
+ */
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ try {
+ /*
+ * Get the initial context using the above startup params.
+ */
+
+ Context ctx = new InitialContext();
+ userManager = (UserManager) ctx.lookup(UserManager.class
+ .getName());
+ cart = (Cart) ctx.lookup(Cart.class.getName());
+
+ } catch (Exception e) {
+ log(e);
+ throw new ServletException(e.toString());
+ }
+ }
+
+ /**
+ * The servlet engine calls this method when the user's desktop browser
+ * sends an HTTP request.
+ */
+ public void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ /*
+ * Set up the user's HttpSession
+ */
+ HttpSession session = request.getSession(true);
+
+ System.out.println(request.getAttributeNames().toString());
+ /*
+ * Retrieve the login name / password from the URL string.
+ */
+ String loginName = request.getParameter("Login");
+ String password = request.getParameter("Password");
+ boolean isLogin = false;
+
+ /*
+ * If user has not tried to log in yet, present him with the login
+ * screen.
+ */
+ if ((loginName == null) || (password == null)) {
+ writeForm(request, response, false);
+ return;
+ } else {
+ /*
+ * Otherwise, the user has been to this screen already, and has
+ * entered some information. Verify that information.
+ */
+ try {
+ isLogin = userManager.validateUser(loginName, password);
+ } catch (Exception e) {
+ writeForm(request, response, true);
+ e.printStackTrace();
+ return;
+ }
+ /*
+ * If the passwords match, make a new Cart Session Bean, and add it
+ * to the user's HttpSession object. When the user navigates to
+ * other servlets, the other servlets can access the HttpSession to
+ * get the user's Cart.
+ */
+ if (isLogin) {
+ try {
+ cart.setOwner(loginName);
+ cart.clear();
+ session.setAttribute("cart", cart);
+
+ /*
+ * Call the main page
+ */
+ RequestDispatcher disp = this.getServletContext()
+ .getRequestDispatcher("/wsf.jsp");
+ disp.forward(request, response);
+
+ return;
+ } catch (Exception e) {
+ log(e);
+ throw new ServletException(e.toString());
+ }
+ } else
+ writeForm(request, response, true);
+ }
+
+ /*
+ * If there was no match, the user is not authenticated. Present another
+ * login screen to him, with an error message indicating that he is not
+ * authenticated.
+ */
+ writeForm(request, response, true);
+ }
+
+ /**
+ * Writes the Login Screen (private use only)
+ *
+ * @param showError
+ * true means show an error b/c client was not authenticated last
+ * time.
+ */
+ private void writeForm(HttpServletRequest request,
+ HttpServletResponse response, boolean showError)
+ throws ServletException, IOException {
+
+ /*
+ * Set a variable indicating whether or not we failed to log-in. The JSP
+ * will read this variable.
+ */
+ request.setAttribute("loginFailed", new Boolean(showError));
+
+ /*
+ * Forward the request to the login JSP
+ */
+ RequestDispatcher disp = this.getServletContext().getRequestDispatcher(
+ "/login.jsp");
+ disp.forward(request, response);
+ }
+
+ private void log(Exception e) {
+ e.printStackTrace();
+ }
+
+ public String getServletInfo() {
+ return "The Login servlet verifies a user.";
+ }
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/servlet/ShowQuoteServlet.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/servlet/ShowQuoteServlet.java
new file mode 100644
index 0000000..d4449d4
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/web/servlet/ShowQuoteServlet.java
@@ -0,0 +1,200 @@
+package examples.shop.web.servlet;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import examples.shop.impl.entity.LineItem;
+import examples.shop.logic.Cart;
+import examples.shop.logic.Pricer;
+
+/**
+ * This servlet allows the user to view and modify his current selections.
+ *
+ * By the time this servlet is called, the user has logged in (via the Login
+ * servlet), and has a shopping cart started (i.e. cart bean). Since this
+ * servlet is pooled and re-used for different user requests, the servlet code
+ * does not store any information specific to any user. Rather, we store a
+ * reference to the user's cart in the user's HttpSession object, which is
+ * globally accessible to all servlets.
+ */
+public class ShowQuoteServlet extends HttpServlet {
+
+ // Pricer for pricing the cart
+ private Pricer pricer;
+
+ /**
+ * The servlet engine calls this method once to initialize a servlet
+ * instance.
+ *
+ * In the body of this method, we need to acquire a Pricer EJB Object for
+ * pricing the carts.
+ */
+ public void init(ServletConfig config) throws ServletException {
+ /*
+ * Call parent to store the config object, so that getServletConfig()
+ * can return it.
+ */
+ super.init(config);
+ try {
+ Context ctx = new InitialContext();
+ pricer = (Pricer)ctx.lookup(Pricer.class.getName());
+ } catch (NamingException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * The servlet engine calls this method when the user's desktop browser
+ * sends an HTTP GET request.
+ */
+ public void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ /*
+ * Get the user's HttpSession, and from that get the user's current
+ * cart.
+ */
+ HttpSession session = request.getSession(false);
+ if (session == null) {
+ /*
+ * Redirect user to login page if no session
+ */
+ response.sendRedirect(response.encodeRedirectURL("/jasmine/login"));
+ return;
+ }
+
+ Object obj = session.getAttribute("cart");
+ if (obj == null) {
+ /*
+ * Redirect user to login page if no session
+ */
+ response.sendRedirect(response.encodeRedirectURL("/jasmine/login"));
+ return;
+ }
+
+ Cart cart = (Cart) obj;
+
+ /*
+ * If the user clicked the 'Order' button, he wants to purchase his
+ * selections. We forward the user to the servlet that handles
+ * purchasing.
+ */
+ if (request.getParameter("Order") != null) {
+ /*
+ * First, turn the cart into an order
+ */
+ String orderId = cart.purchase();
+ /*
+ * Stick the orderID in the request so the JSP gets it
+ */
+ request.setAttribute("orderID", orderId);
+ cart.clear();
+ this.getServletContext().getRequestDispatcher("/receipt.jsp")
+ .forward(request, response);
+ return;
+ }
+
+ /*
+ * Next, we need to figure out what button the user clicked, if any.
+ * These come to us as form parameters. We need to loop through each
+ * parameter and interpret it.
+ */
+ Enumeration paramNames = request.getParameterNames();
+ while (paramNames.hasMoreElements()) {
+ String paramName = (String) paramNames.nextElement();
+ String paramValue = request.getParameter(paramName);
+
+ /*
+ * If user clicked 'Update' button, then the user wants to change
+ * the quantities of each product he is ordering. We'll process
+ * those quantities below.
+ */
+ if (paramName.equals("Update")) {
+ } else if (paramName.equals("Clear")) {
+ /*
+ * The user wants to clear the form
+ */
+ cart.clear();
+ this.getServletContext()
+ .getRequestDispatcher("/clearQuote.jsp").forward(
+ request, response);
+ return;
+ } else {
+ /*
+ * If the parameter represents a quantity of a particular
+ * product the user is interested in, then we should update that
+ * product's quantity to reflect this new value.
+ */
+ try {
+ /*
+ * Convert the quantity to int format, and set the new
+ * quantity
+ */
+ int quantity = Integer.parseInt(paramValue);
+ cart.modify(paramName, quantity);
+ } catch (NumberFormatException e) {
+ throw new ServletException("Bad parameter to servlet: "
+ + paramName + ", " + paramValue);
+ } catch (Exception e) {
+ throw new ServletException(e.toString());
+ }
+ }
+ }
+
+ /*
+ * Recalculate all totals based upon new quantities
+ */
+ try {
+ cart.setSubtotal(pricer.priceSubtotal(cart.getOwner(), cart.getAll()));
+ cart.setTaxes(pricer.priceTaxes(cart.getSubtotal()));
+ } catch (Exception e) {
+ log(e);
+ throw new ServletException(e.toString());
+ }
+
+ /*
+ * Otherwise, show the current cart again
+ */
+ List<LineItem> lineItems = cart.getAll();
+ if (lineItems.size() > 0) {
+ /*
+ * Stick lineitems, subtotal, taxes and total in request
+ */
+ request.setAttribute("lineItems", lineItems);
+ request.setAttribute("subTotal", new Double(cart.getSubtotal()));
+ request.setAttribute("taxes", new Double(cart.getTaxes()));
+ request.setAttribute("taxRate", new Double(pricer.getTaxRate()));
+ request.setAttribute("total", new Double(cart.getTotalPrice()));
+ // Forwards the request to the showQuote JSP.
+ this.getServletContext().getRequestDispatcher("/showQuote.jsp")
+ .forward(request, response);
+ return;
+ } else {
+ /*
+ * If there are no products, print out that the cart is empty.
+ */
+ this.getServletContext().getRequestDispatcher("/emptyQuote.jsp")
+ .forward(request, response);
+ return;
+ }
+ }
+
+ private void log(Exception e) {
+ e.printStackTrace();
+ }
+
+ public String getServletInfo() {
+ return "The ShowQuote servlet returns information about"
+ + "the products that the user is in the process of ordering.";
+ }
+}