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

Quick Search    Search Deep

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


1   /*
2    * GroupGateway.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 com.flexstor.common.data.ejb.role.RoleData;
14  import com.flexstor.common.exceptions.ejb.NotFoundException;
15  import com.flexstor.common.gateway.debug.GatewayDebugOutput;
16  import com.flexstor.common.gateway.exceptions.TransactionFailedException;
17  import com.flexstor.common.keys.ejb.GroupCollectionKey;
18  import com.flexstor.common.keys.ejb.RoleKey;
19  import com.flexstor.ejb.EjbObject;
20  import com.flexstor.ejb.user.FlexGroup;
21  import com.flexstor.ejb.user.FlexGroupHome;
22  
23  /**
24   * Retrieves information from the server for a specific group.
25   * @author Praveen Jani
26   * @version 3.0
27   */
28  public class GroupGateway
29     extends Gateway
30  {
31     // MKS macro expander
32     public final static String IDENTIFIER = "$Id: GroupGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
33  
34     private FlexGroup group = null;
35     
36     protected String getHomeName ( )
37     {
38        return GROUP_HOME;
39     }
40  
41     protected EjbObject getBeanObject ( )
42     {
43        return group;
44     }
45  
46     /**
47      * Sends the request for group data to the server.
48      */
49     public void connect ()
50        throws TransactionFailedException
51     {
52        try
53        {
54           if ( canLoadObject() )
55              return;
56  
57           FlexGroupHome home = (FlexGroupHome)getHome ( );
58  
59           GatewayDebugOutput.println ( 3, "Getting FlexGroup object" );
60           group = home.create ();
61        }
62        catch ( NotFoundException e )
63        {
64           throw new TransactionFailedException ( e );
65        }
66        catch ( Throwable e )
67        {
68           throw buildException(e, "Connecting to FlexGroup", IDENTIFIER );
69        }
70     }
71  
72     /**
73      * Sends the request for group data to the server.
74      */
75     public void connect ( String groupName )
76        throws TransactionFailedException
77     {
78        try
79        {
80           if ( canLoadObject() )
81              return;
82  
83           FlexGroupHome home = (FlexGroupHome)getHome ( );
84  
85           GatewayDebugOutput.println ( 3, "Getting FlexGroup object provided a group name" );
86           group = home.create ( groupName );
87        }
88        catch ( NotFoundException e )
89        {
90           throw new TransactionFailedException ( e );
91        }
92        catch ( Throwable e )
93        {
94           throw buildException(e, "Connecting to FlexGroup", IDENTIFIER );
95        }
96     }
97  
98     /**
99      * Gets the role data for this group.
100     * @return the group's role data.
101     * @throws TransactionFailedException Throws if this transaction fails.
102     */
103    public RoleData getRoleData ()
104       throws TransactionFailedException
105    {
106       try
107       {
108          GatewayDebugOutput.println ( 3, "Get group role data" );
109 
110          if ( canLoadObject() )
111             return (RoleData)retrieveObject ( "Group_getRole" );
112 
113          RoleData data = group.getRole();
114 
115          if ( canSaveObject() )
116             storeObject ( "Group_getRole", data );
117 
118          return data;
119       }
120       catch ( Throwable e )
121       {
122          throw buildException(e, "Getting Role Data", IDENTIFIER );
123       }
124    }
125 
126    /**
127     * Gets the role data for this group.
128     * @return the user's role data.
129     * @throws TransactionFailedException Throws if this transaction fails.
130     */
131    public RoleData getGroupRoleUnion ( GroupCollectionKey groupKey, RoleKey userRoleKey )
132       throws TransactionFailedException
133    {
134       try
135       {
136          GatewayDebugOutput.println ( 3, "Get role for GroupCollectionKey" );
137 
138          if ( canLoadObject() )
139             return (RoleData)retrieveObject ( "Group_getRole_GroupCollectionKey" );
140 
141          RoleData data = group.getGroupRoleUnion( groupKey, userRoleKey );
142 
143          if ( canSaveObject() )
144             storeObject ( "Group_getRole_GroupCollectionKey", data );
145 
146          return data;
147       }
148       catch ( Throwable e )
149       {
150          throw buildException(e, "Getting Group Role Union", IDENTIFIER );
151       }
152    }
153 }