1    package com.instantbank.lettertemplate.control.web.handlers;
2    
3    import java.io.Serializable;
4    import java.rmi.RemoteException;
5    import java.text.SimpleDateFormat;
6    import javax.ejb.FinderException;
7    
8    import com.instantbank.component.job.ejb.Job;
9    import com.instantbank.component.job.model.JobModel;
10   
11   import com.instantbank.common.utilcomponents.JNDINames;
12   import com.instantbank.common.utilcomponents.LetterTemplateGlobals;
13   import com.instantbank.lettertemplate.control.web.ModelManager;
14   import com.instantbank.lettertemplate.control.web.ModelUpdateListener;
15   import com.instantbank.lettertemplate.control.ejb.LetterTemplateController;
16   import com.instantbank.lettertemplate.control.GeneralFailureException;
17   import com.instantbank.common.utilcomponents.Debug;
18   
19   /**
20    * This class is the web-tier representation of the Job EJB.
21    *
22    * @author Instant-bank (Consuelo Franky)
23    * @created November 2002
24    */
25   public class JobWebImpl extends JobModel
26       implements ModelUpdateListener, Serializable {
27   
28     private ModelManager mm;
29     private Job jobejb;
30     private Debug debug = null;
31   
32   
33     /**
34      * constructor without parameters
35      */
36     public JobWebImpl() {
37       super();
38       debug = new Debug();
39       debug.setDebugginOn(true);
40       debug.setPreMessage("** JobWebImpl: ");
41     }
42   
43   
44     /**
45      * constructor that receives the ModelManager:
46      * this object is registered as listener of changes in the state of Job EJB
47      *
48      * @param mm Description of the Parameter
49      */
50     public JobWebImpl(ModelManager mm) {
51       super();
52       this.mm = mm;
53       mm.addListener(JNDINames.JOB_EJBHOME, this);
54       debug = new Debug();
55       debug.setDebugginOn(true);
56       debug.setPreMessage("** JobWebImpl: ");
57     }
58   
59   
60     /**
61      * reaction to changes in the state of Job EJB:
62      * it requests a copie of the new state
63      */
64     public void performUpdate() {
65       debug.println("performUpdate method");
66   
67       Long jobId = getJobId();
68       debug.println("jobId=" + jobId);
69   
70       // Get data from the EJB
71       try {
72         jobejb = mm.getJobEJB(jobId);
73       }
74       catch(Exception a) {
75         debug.println("Exception: " + a.getMessage());
76         jobejb = null;
77         this.clean();
78       }
79   
80       if(jobejb != null) {
81         try {
82           copy(jobejb.getState());
83           debug.println("model of Job ejb has been copied");
84         }
85         catch(RemoteException re) {
86           throw new GeneralFailureException(re.getMessage());
87         }
88       }
89     }
90   
91   
92     /**
93      * Sets null to jobejb attribute:
94      */
95     public void setJobNull() {
96       this.jobejb = null;
97       debug.println("jobejb has been set to null");
98     }
99   
100  
101    /**
102     *  Tranforms activationDate to a string "MM-dd-yyyy"
103     *
104     * @return string
105     */
106    public String getActivationDateString() {
107      String activationDateString = "";
108      if(this.getActivationDate() != null) {
109        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
110        activationDateString = sdf.format(this.getActivationDate());
111      }
112      return activationDateString;
113    }
114  
115  
116    /**
117     *  clean attributes of jobView: javabean that is model view of Job EJB.
118     */
119    public void clean() {
120  
121      this.setMaster(null, null, null, null, null, null,
122        LetterTemplateGlobals.UNDEF, LetterTemplateGlobals.UNDEF,
123        null, null,
124        LetterTemplateGlobals.UNDEF, LetterTemplateGlobals.UNDEF,
125        null, null, null);
126      this.setJobORDER(null);
127      this.setJobSELECT(null);
128      this.setJobWHERE(null);
129    }
130  
131  }
132  
133