1 package com.instantbank.lettertemplate.control.web;
2
3 import java.io.Serializable;
4 import java.util.HashMap;
5 import java.util.ArrayList;
6 import java.util.Collection;
7 import java.util.Iterator;
8 import java.rmi.RemoteException;
9 import javax.servlet.http.HttpSession;
10 import javax.servlet.ServletContext;
11 import javax.ejb.CreateException;
12 import javax.ejb.FinderException;
13 import com.instantbank.lettertemplate.control.GeneralFailureException;
14 import com.instantbank.lettertemplate.control.util.EJBUtil;
15 import com.instantbank.lettertemplate.control.util.WebKeys;
16 import com.instantbank.lettertemplate.control.web.handlers.JobWebImpl;
17 import com.instantbank.component.job.ejb.Job;
18
19 import com.instantbank.common.utilcomponents.Debug;
20 import com.instantbank.common.utilcomponents.LetterTemplateExceptionMessage;
21 import com.instantbank.lettertemplate.control.ejb.LetterTemplateController;
22
23
32 public class ModelManager extends ModelUpdateNotifier
33 implements Serializable {
34
35 private ServletContext context;
36 private HttpSession session;
37 private LetterTemplateController sccEjb = null;
38 private LetterTemplateControllerProxy scc = null;
39 private Job jobEjb = null;
40
41 private Debug debug = null;
42
43
44
47 public ModelManager() {
48 debug = new Debug();
49 debug.setDebugginOn(true);
50 debug.setPreMessage("** ModelManager");
51 }
52
53
54
62 public void init(ServletContext context, HttpSession session) {
63 debug.println("init");
64 this.session = session;
65 this.context = context;
66
67 getJobModel();
68
69 }
70
71
72
77 public void setSCC(LetterTemplateControllerProxy scc) {
78 this.scc = scc;
79 debug.println("scc assigned");
80 }
81
82
83
88 public JobWebImpl getJobModel() {
89 JobWebImpl jobView = (JobWebImpl)
90 session.getAttribute(WebKeys.JobModelKey);
91 if(jobView == null) {
92 jobView = new JobWebImpl(this);
93 session.setAttribute(WebKeys.JobModelKey, jobView);
94 }
95 return jobView;
96 }
97
98
99
104 public LetterTemplateController getSCCEJB() {
105 debug.println("getSCCEJB method");
106
107 if(sccEjb == null) {
108 try {
109 sccEjb = EJBUtil.getLetterTemplateControllerHome().create();
110 }
111 catch(CreateException ce) {
112 throw new GeneralFailureException(ce.getMessage());
113 }
114 catch(RemoteException re) {
115 throw new GeneralFailureException(re.getMessage());
116 }
117 catch(javax.naming.NamingException ne) {
118 throw new GeneralFailureException(ne.getMessage());
119 }
120 catch(Exception e) {
121 throw new GeneralFailureException(e.getMessage());
122 }
123 }
124 return sccEjb;
125 }
126
127
128
134 public Job getJobEJB(Long jobId) {
135 if(scc == null) {
136 throw new
137 GeneralFailureException
138 ("ModelManager: Can not get Job EJB");
139 }
140 debug.println("scc.getJobEJB(jobId) requested");
141 jobEjb = scc.getJobEJB(jobId);
142 return jobEjb;
143 }
144
145 }
146
147