1 package com.instantbank.lettertemplate.control.ejb.handlers;
2
3 import java.util.ArrayList;
4 import java.rmi.RemoteException;
5 import javax.naming.InitialContext;
6 import javax.naming.NamingException;
7 import javax.ejb.CreateException;
8 import javax.ejb.DuplicateKeyException;
9 import javax.ejb.FinderException;
10 import com.instantbank.lettertemplate.control.event.ComponentsEvent;
11 import com.instantbank.common.utilcomponents.Debug;
12 import com.instantbank.component.lettertemplate.ejb.LetterTemplate;
13 import com.instantbank.lettertemplate.control.LetterTemplateEventException;
14 import com.instantbank.lettertemplate.control.event.LetterTemplateEvent;
15
16
22 public class ComponentsHandler extends StateHandlerSupport {
23
24 private Debug debug = null;
25
26
27
34 public Object perform(LetterTemplateEvent event)
35 throws LetterTemplateEventException {
36 debug = new Debug();
37 debug.setDebugginOn(true);
38 debug.setPreMessage("** ComponentsHandler-services tier: ");
39
40 Object answer = "";
41 ComponentsEvent ce = (ComponentsEvent)event;
42
43 switch (ce.getActionType()) {
44
45 case ComponentsEvent.LIST_COMPONENTS:
46 {
47 debug.println("LIST_COMPONENTS event");
48 try {
49 LetterTemplate letterTemplate
50 = machine.getLetterTemplateControllerEJB()
51 .getLetterTemplate
52 (ce.getCompanyId(), ce.getUserId());
53
54
55 answer = letterTemplate.loadUnlikedComponents();
56 }
57 catch(Exception e) {
58
59
60 throw new LetterTemplateEventException(e.getMessage());
61 }
62
63 }
64 break;
65 case ComponentsEvent.UPDATE_COMPONENTS:
66 {
67 debug.println("UPDATE_CATEGORIES event");
68 try {
69 LetterTemplate letterTemplate
70 = machine.getLetterTemplateControllerEJB()
71 .getLetterTemplate
72 (ce.getCompanyId(), ce.getUserId());
73
74 answer = letterTemplate.applyItemsComponent(ce.getItems());
75 }
76 catch(Exception e) {
77 throw new LetterTemplateEventException(e.getMessage());
78 }
79
80 }
81 break;
82 default:
83 debug.println("Error: not implemented yet");
84 break;
85 }
86 return answer;
87 }
88 }
89
90