Source code: com/obs/client/organizational/delegates/OrgMgmtDelegate.java
1 /*
2 * Created on Sep 5, 2003
3 */
4 package com.obs.client.organizational.delegates;
5
6 import java.rmi.RemoteException;
7 import java.util.Collection;
8 import java.util.Properties;
9
10 import javax.ejb.CreateException;
11 import javax.naming.InitialContext;
12 import javax.naming.NamingException;
13 import javax.rmi.PortableRemoteObject;
14
15 import com.obs.client.templates.EJBDelegateHelper;
16 import com.obs.client.templates.IEJBDelegate;
17 import com.obs.common.accounting.views.GLAccountView;
18 import com.obs.common.organizational.views.CompanyView;
19 import com.obs.common.shared.exceptions.NoSuchObjectException;
20 import com.obs.common.shared.exceptions.ServerContactException;
21 import com.obs.ejb.organizational.interfaces.OrganizationalMgmt;
22 import com.obs.ejb.organizational.interfaces.OrganizationalMgmtHome;
23
24 /**
25 * @author David Durst
26 */
27 public class OrgMgmtDelegate extends EJBDelegateHelper implements IEJBDelegate {
28
29 private OrganizationalMgmt remote;
30 private String jndiREF = "com/obs/ejb/organizational/OrganizationalMgmtEJB";
31
32 public OrgMgmtDelegate() throws ServerContactException {
33 super();
34 init();
35 }
36 public OrgMgmtDelegate(InitialContext ctx) throws ServerContactException {
37 super(ctx);
38 init();
39 }
40 public OrgMgmtDelegate(Properties props) throws ServerContactException {
41 super(props);
42 init();
43 }
44
45
46
47 public void passivate() throws ServerContactException {
48 gPassivate(remote);
49 }
50
51 public void activate() throws ServerContactException {
52 remote = (OrganizationalMgmt)gActivate();
53 }
54
55 public void destroy() throws ServerContactException {
56 gDestroy(remote);
57 }
58
59
60 public CompanyView createCompany(CompanyView companyView,
61 GLAccountView cashAccountView,
62 GLAccountView commonStockView)
63 throws ServerContactException, CreateException {
64 //TODO Catch and handle other exceptions
65 if(remote != null) {
66 try {
67 return remote.createCompany(companyView,cashAccountView,commonStockView);
68 }
69 catch(RemoteException remote_ex) {
70 throw new ServerContactException();
71 }
72 catch(CreateException create_ex) {
73 throw new ServerContactException();
74 }
75 }
76 return null;
77 }
78
79
80 public CompanyView getCompany(String id) throws ServerContactException, NoSuchObjectException {
81 //TODO Catch and handle other exceptions
82 if(remote != null) {
83 try {
84 return remote.getCompany(id);
85 }
86 catch(RemoteException remote_ex) {
87 throw new ServerContactException();
88 }
89
90 }
91 return null;
92 }
93 public CompanyView getCompanyByName(String companyName)
94 throws ServerContactException,
95 NoSuchObjectException {
96 if(remote != null) {
97 try {
98 return remote.getCompanyByName(companyName);
99 }
100 catch(RemoteException remote_ex) {
101 throw new ServerContactException();
102 }
103
104 }
105 return null;
106 }
107
108 public Collection getCompanies() throws ServerContactException {
109 try {
110 return remote.getCompanies();
111 }
112 catch(RemoteException remote_ex) {
113 throw new ServerContactException();
114 }
115 }
116
117 private void init() throws ServerContactException {
118 try {
119 OrganizationalMgmtHome vmHome = (OrganizationalMgmtHome)
120 PortableRemoteObject.narrow(ictx.lookup(jndiREF),
121 OrganizationalMgmtHome.class
122 );
123 remote = vmHome.create();
124 }
125 catch(NamingException naming_ex) {
126 naming_ex.printStackTrace();
127 throw new ServerContactException(naming_ex.getMessage());
128 }
129 catch(RemoteException remote_ex) {
130 remote_ex.printStackTrace();
131 throw new ServerContactException(remote_ex.getMessage());
132 }
133 catch(CreateException create_ex) {
134 create_ex.printStackTrace();
135 throw new ServerContactException(create_ex.getMessage());
136 }
137 inited = true;
138 }
139 }