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

Quick Search    Search Deep

Source code: com/flexstor/common/gateway/AdmGroupGateway.java


1   /*
2    * AdmGroupGateway.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:29 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.gateway;
12  
13  import java.util.Hashtable;
14  
15  import com.flexstor.common.data.ejb.role.RoleData;
16  import com.flexstor.common.data.ejb.user.GroupData;
17  import com.flexstor.common.exceptions.ejb.NotFoundException;
18  import com.flexstor.common.gateway.debug.GatewayDebugOutput;
19  import com.flexstor.common.gateway.exceptions.TransactionFailedException;
20  import com.flexstor.common.keys.ejb.GroupCollectionKey;
21  import com.flexstor.common.keys.ejb.GroupKey;
22  import com.flexstor.common.keys.ejb.RoleKey;
23  import com.flexstor.ejb.EjbObject;
24  import com.flexstor.ejb.user.FlexGroup;
25  import com.flexstor.ejb.user.FlexGroupHome;
26  
27  /**
28   * Retrieves information from the server for a specific group.
29   *
30   * @author Praveen Jani
31   * @since 3.0
32   */
33  public class AdmGroupGateway
34     extends Gateway
35  {
36     // MKS macro expander
37     public final static String IDENTIFIER = "$Id: AdmGroupGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
38  
39     /**
40      * The instance of FlexGroup remote interface.
41      */
42     private FlexGroup group = null;
43  
44     /**
45      * Returns the published name for the home interface of group bean.
46      *
47      * @return String - Published name of the home interface
48      * @since 3.0
49      */
50  
51     protected String getHomeName ( )
52     {
53        return GROUP_HOME;
54     }
55  
56     /**
57      * Returns the bean object.
58      *
59      * @return EjbObject - the bean object
60      */
61     protected EjbObject getBeanObject ( )
62     {
63        return group;
64     }
65  
66     /**
67      * Connects to the EJB.
68      *
69      * @param groupName - The name of the group to be connected for.
70      * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
71      * @since 3.0
72      */
73     public void connect ( String groupName )
74        throws TransactionFailedException
75     {
76        try
77        {
78           if ( canLoadObject() )
79              return;
80           FlexGroupHome home = (FlexGroupHome)getHome ( );
81  
82           GatewayDebugOutput.println ( 3, "Getting FlexGroup object" );
83           group = home.create ( groupName );
84        }
85        catch ( NotFoundException e )
86        {
87           throw new TransactionFailedException ( e );
88        }
89        catch ( Throwable e )
90        {
91           throw buildException(e, "Connecting to FlexGroupHome", IDENTIFIER );
92        }
93     }
94  
95     /**
96      * Connects to the EJB.
97      *
98      * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
99      * @since 3.0
100     */
101    public void connect ()
102       throws TransactionFailedException
103    {
104       try
105       {
106          if ( canLoadObject() )
107             return;
108 
109          FlexGroupHome home = (FlexGroupHome)getHome ( );
110 
111          GatewayDebugOutput.println ( 3, "Getting FlexGroup object" );
112          group = home.create ();
113       }
114       catch ( NotFoundException e )
115       {
116          throw new TransactionFailedException ( e );
117       }
118       catch ( Throwable e )
119       {
120          throw buildException(e, "Connecting to FlexGroupHome", IDENTIFIER );
121       }
122    }
123 
124    /**
125     * Returns the group for the specific group key privided.
126     *
127     * @param key - The GroupKey object
128     * @return GroupData - Group data object
129     * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException
130     */
131    public GroupData getGroup ( GroupKey key )
132       throws TransactionFailedException 
133    {
134       try
135       {
136          GatewayDebugOutput.println ( 3, "Get group data" );
137       
138          if ( canLoadObject() )
139             return (GroupData)retrieveObject ( "Group_getGroup" );
140             
141          GroupData data = group.getGroup( key );
142 
143          if ( canSaveObject() )
144             storeObject ( "Group_getGroup", data );
145             
146          return data;
147       }
148       catch ( Throwable e )
149       {
150          throw buildException(e, "Getting Group", IDENTIFIER );
151       }
152    }
153    
154    
155    /**
156     * Returns the group specified with name.
157     * 
158     * @param gName - the name of the group
159     * @return GroupData - group data object
160     * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown if the transaction fails.
161     * @since 3.0
162     */
163    public GroupData getGroup ( String gName )
164       throws TransactionFailedException 
165    {
166       try
167       {
168          GatewayDebugOutput.println ( 3, "Get user data" );
169       
170          if ( canLoadObject() )
171             return (GroupData)retrieveObject ( "Group_getGroup(name)" );
172             
173          GroupData data = group.getGroup( gName );
174 
175          if ( canSaveObject() )
176             storeObject ( "Group_getGroup(name)", data );
177             
178          return data;
179       }
180       catch ( Throwable e )
181       {
182          throw buildException(e, "Getting Group", IDENTIFIER );
183       }
184    }
185    
186    /**
187     * Returns the union role for the  collection of group provided a group 
188     * collection key.
189     * 
190     * @param aKey - the collection key
191     * @param aRoleKey - the role key
192     * @return RoleData - the role data object
193     * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown if the transaction fails.
194     * @since 3.0
195     */
196    public RoleData getRoleUnion ( GroupCollectionKey aKey, RoleKey aRoleKey )
197       throws TransactionFailedException 
198    {
199       try
200       {
201          GatewayDebugOutput.println ( 3, "Get role union" );
202       
203          if ( canLoadObject() )
204             return (RoleData)retrieveObject ( "Group_getRoleUnion" );
205             
206          RoleData data = group.getRoleUnion( aKey, aRoleKey );
207 
208          if ( canSaveObject() )
209             storeObject ( "Group_getRoleUnion", data );
210             
211          return data;
212       }
213       catch ( Throwable e )
214       {
215          throw buildException(e, "Getting Role Union", IDENTIFIER );
216       }
217    } 
218    
219 
220    /**
221     * Returns the role for the collection of groups.
222     * 
223     * @param aKey - the collection key.
224     * @param aRoleKey - the role key
225     * @return RoleData - the role data object
226     * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown if the transaction fails.
227     * @since 3.0
228     */
229    public Hashtable getRoles ( GroupCollectionKey aKey, RoleKey aRoleKey )
230       throws TransactionFailedException 
231    {
232       try
233       {
234          GatewayDebugOutput.println ( 3, "Get roles" );
235       
236          if ( canLoadObject() )
237             return (Hashtable)retrieveObject ( "Group_getRoles" );
238             
239          Hashtable data = group.getRoles( aKey, aRoleKey );
240 
241          if ( canSaveObject() )
242             storeObject ( "Group_getRoles", data );
243             
244          return data;
245       }
246       catch ( Throwable e )
247       {
248          throw buildException(e, "Getting Roles", IDENTIFIER );
249       }
250    } 
251    
252    /**
253     * Returns the role provided a group collection key.
254     * 
255     * @param aKey - the group collection key
256     * @return RoleData - the role data object
257     * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown if the transaction fails.
258     * @since 3.0
259     */
260    public Hashtable getRoles ( GroupCollectionKey aKey )
261       throws TransactionFailedException 
262    {
263       try
264       {
265          GatewayDebugOutput.println ( 3, "Get roles for collection Key" );
266       
267          if ( canLoadObject() )
268             return (Hashtable)retrieveObject ( "Group_getRoles(aKey)" );
269             
270          Hashtable data = group.getRoles( aKey );
271 
272          if ( canSaveObject() )
273             storeObject ( "Group_getRoles(aKey)", data );
274             
275          return data;
276       }
277       catch ( Throwable e )
278       {
279          throw buildException(e, "Getting Roles", IDENTIFIER );
280       }
281    } 
282    
283    /**
284     * Returns the group data object.
285     *     
286     * @return GroupData - the groupdata object
287     * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown if the transaction fails.
288     * @since 3.0
289     */
290    
291    
292    //public GroupData getGroup()
293    //   throws TransactionFailedException 
294    // {
295    //   try
296    //   {
297    //      GatewayDebugOutput.println ( 3, "Get Group" );
298    //   
299    //      if ( canLoadObject() )
300    //         return ( GroupData )retrieveObject ( "Group_getGroup()" );
301    //         
302    //      GroupData data = null;//group.getGroup();
303 
304    //      if ( canSaveObject() )
305    //         storeObject ( "Group_getGroup()", data );
306             
307    //      return data;
308    //   }
309    //   catch ( Throwable e )
310    //   {
311    //      throw buildException(e);
312    //   }
313    // }    
314    
315    /**
316     * Returns the role data object for the group.
317     *     
318     * @return RoleData - the role data object
319     * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown if the transaction fails.
320     * @since 3.0
321     */   
322    
323    public RoleData getRole()
324       throws TransactionFailedException 
325    {
326       try
327       {
328          GatewayDebugOutput.println ( 3, "Get Group" );
329       
330          if ( canLoadObject() )
331             return ( RoleData )retrieveObject ( "Group_getRole()" );
332             
333          RoleData data = group.getRole();
334 
335          if ( canSaveObject() )
336             storeObject ( "Group_getRole()", data );
337             
338          return data;
339       }
340       catch ( Throwable e )
341       {
342          throw buildException(e, "Getting Role", IDENTIFIER );
343       }
344    }    
345 }