Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/obs/client/accounting/delegates/GeneralLedgerDelegate.java


1   /*
2    * Created on Jun 20, 2003
3    */
4   package com.obs.client.accounting.delegates;
5   
6   import java.util.*;
7   
8   import java.rmi.RemoteException;
9   import javax.rmi.PortableRemoteObject;
10  
11  import javax.ejb.FinderException;
12  import javax.ejb.CreateException;
13  import javax.ejb.Handle;
14  import javax.naming.InitialContext;
15  import javax.naming.NamingException;
16  
17  import com.obs.client.templates.EJBDelegate;
18  import com.obs.common.accounting.objects.*;
19  import com.obs.common.accounting.views.*;
20  import com.obs.common.exceptions.DateRangeException;
21  import com.obs.common.exceptions.ServerContactException;
22  import com.obs.common.templates.ViewObject;
23  import com.obs.ejb.accounting.interfaces.*;
24  
25  /**
26   * @author David Durst
27   */
28  public class GeneralLedgerDelegate implements EJBDelegate  {
29    
30    private InitialContext ictx = null;
31    private GeneralLedger generalLedger = null;
32    private Handle handle = null;
33    
34    public GeneralLedgerDelegate() throws ServerContactException {
35      activate();
36    }
37    
38    public void createGeneralLedgerAccount(ViewObject viewObject)  throws ServerContactException {
39      try {
40        if(viewObject != null){
41          //Need type verification
42          generalLedger.createAccount((AccountView)viewObject);
43        }
44      }
45      catch(RemoteException remote_ex) {
46        throw new ServerContactException();
47      }
48      catch(CreateException create_ex) {
49      }
50    }
51    
52  
53    public AccountView getGeneralLedgerAccount(String accountID) throws ServerContactException {
54          try{
55              return generalLedger.getAccountView(accountID);
56          }
57          catch(RemoteException remote_ex){
58              throw new ServerContactException();
59          }
60    }
61      
62    public Collection getGeneralLedgerAccounts() throws ServerContactException {
63      Map map;
64      Iterator i;
65      Collection accounts;
66      AccountView accountView;
67      try {
68        map = new HashMap();
69        return generalLedger.getAccountList();
70      }
71      catch(RemoteException remote_ex) {
72        throw new ServerContactException();
73      }
74      
75    }
76    
77    public List getAccountTypes() {
78      List list = new ArrayList();
79      int c;
80      for(c = AccountType.LOW_RANGE; c <= AccountType.HIGH_RANGE;c++) {
81        list.add(new AccountType(c).getAccountTypeName());
82      }
83      return list;
84    }
85    
86    public Collection getAccountHistory(String accountID, Calendar start, Calendar end) throws ServerContactException {
87      try{
88        return generalLedger.getAccountHistory(accountID,start,end);
89      }
90      catch(RemoteException remote_ex){
91        throw new ServerContactException();
92      }
93      catch(DateRangeException date_ex){
94              date_ex.printStackTrace();
95      }
96          catch(FinderException finder_ex){
97              finder_ex.printStackTrace();
98          }
99      return null;
100   }
101   
102   /*
103    * Interface Methods
104    */
105    
106   public void passivate() throws ServerContactException {
107     try {
108       if(generalLedger != null) {
109         handle = generalLedger.getHandle();
110         generalLedger = null;
111        }
112     }
113     catch(RemoteException remote_ex){
114       throw new ServerContactException();
115     }
116   }
117   
118   public void activate() throws ServerContactException {
119     if(handle != null) {
120       try {
121         generalLedger = (GeneralLedger)handle.getEJBObject();
122       }
123       catch(RemoteException remote_ex) {
124         throw new ServerContactException();
125       }
126     }
127     else {
128       try {
129         ictx = new InitialContext();
130         GeneralLedgerHome glHome = (GeneralLedgerHome)
131                  PortableRemoteObject.narrow(
132                    ictx.lookup("com/obs/ejb/accounting/GeneralLedgerEJB"),
133                    GeneralLedgerHome.class);
134         generalLedger = glHome.create();
135       }
136       catch(NamingException naming_ex) {
137         throw new ServerContactException();
138       }
139       catch(RemoteException remote_ex) {
140         throw new ServerContactException();
141       }
142       catch(CreateException create_ex) {
143       }      
144     }
145   }
146   
147   public void destroy() throws ServerContactException {
148         try{
149             generalLedger.remove();
150         }
151         catch(Exception ex){
152             throw new ServerContactException();
153         }
154     
155   }
156   
157 }