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

Quick Search    Search Deep

Source code: com/obs/client/system/delegates/UGMgmtDelegate.java


1   /*
2    * Created on Sep 5, 2003
3    */
4   package com.obs.client.system.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.shared.exceptions.NoSuchObjectException;
18  import com.obs.common.shared.exceptions.ServerContactException;
19  import com.obs.common.system.views.UserView;
20  import com.obs.ejb.system.interfaces.UGMgmt;
21  import com.obs.ejb.system.interfaces.UGMgmtHome;
22  
23  /**
24   * @author David Durst
25   */
26  public class UGMgmtDelegate extends EJBDelegateHelper implements IEJBDelegate {
27  
28      private UGMgmt remote;
29      private String jndiREF = "com/obs/ejb/system/UGMgmtEJB";
30      
31      public UGMgmtDelegate() throws ServerContactException {
32          super();
33          init();
34      }
35      public UGMgmtDelegate(InitialContext ctx) throws ServerContactException {
36          super(ctx);
37          init();
38      }
39      public UGMgmtDelegate(Properties props) throws ServerContactException {
40          super(props);    
41          init();
42      }
43      
44  
45  
46      
47      public UserView createUser(UserView userView, String companyId) throws ServerContactException {
48          //TODO Catch and handle other exceptions                                                                        
49          if(remote != null) {
50              try {
51                  return remote.createUser(userView,companyId);
52              }
53              catch(RemoteException remote_ex) {
54                  throw new ServerContactException(remote_ex.getMessage());                                                                                    
55              }
56              catch(CreateException create_ex) {
57                  create_ex.printStackTrace();
58                  throw new ServerContactException(create_ex.getMessage());
59              }
60          }
61          
62          return null;
63      }
64  
65      public UserView setUserPassword(String userID, String password)
66                                                                      throws ServerContactException,
67                                                                                    NoSuchObjectException {
68          try {             
69              return remote.setUserPassword(userID,password);                                                                         
70          }
71          catch(RemoteException remote_ex) {
72              throw new ServerContactException();
73          }
74      }
75      
76      public UserView getUserByID(String userID)
77                                                          throws ServerContactException,
78                                                                       NoSuchObjectException {
79          try {
80              return remote.getUser(userID);
81          }
82          catch(RemoteException remote_ex) {
83              throw new ServerContactException("Can not contact server");            
84          }
85  
86      }
87  
88      public UserView getUserByUsername(String username, String companyID)
89                                                          throws ServerContactException,
90                                                                       NoSuchObjectException {
91          try {
92              return remote.getUser(username, companyID);
93          }
94          catch(RemoteException remote_ex) {
95              throw new ServerContactException("Can not contact server");            
96          }
97  
98      }
99  
100    
101     public Collection getCompanyUsers(String companyID)
102                                                                      throws ServerContactException,
103                                                                      NoSuchObjectException {
104         try {
105             return remote.getCompanyUsers(companyID);
106         }
107         catch(RemoteException remote_ex) {
108             throw new ServerContactException();            
109         }        
110 
111     }
112     
113     //TODO Low Priority - Make following function work
114     /*
115     public Collection getCompanyUsersByCompanyName(String companyName)
116                                                                                                  throws ServerContactException, NoSuchObjectException {
117     }
118     */
119     private void init() throws ServerContactException {
120         try {
121             UGMgmtHome vmHome = (UGMgmtHome)
122                              PortableRemoteObject.narrow(ictx.lookup(jndiREF),
123                                                                                 UGMgmtHome.class);
124             remote = vmHome.create();
125         }
126         catch(NamingException naming_ex) {
127             naming_ex.printStackTrace();
128             throw new ServerContactException(naming_ex.getMessage());
129         }
130         catch(RemoteException remote_ex) {
131             remote_ex.printStackTrace();
132             throw new ServerContactException(remote_ex.getMessage());
133         }
134         catch(CreateException create_ex) {
135             create_ex.printStackTrace();
136             throw new ServerContactException(create_ex.getMessage());
137         }    
138         inited = true;    
139     }    
140     
141     public void passivate() throws ServerContactException {
142         gPassivate(remote);
143     }
144     
145     public void activate() throws ServerContactException {
146         remote = (UGMgmt)gActivate();
147     }
148 
149     public void destroy() throws ServerContactException {
150         gDestroy(remote);   
151     }    
152 }