Source code: com/flexstor/common/gateway/PrivAssetGateway.java
1 /*
2 * PrivAssetGateway.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.Vector;
14
15 import com.flexstor.common.data.ejb.privasset.PrivAssetData;
16 import com.flexstor.common.gateway.debug.GatewayDebugOutput;
17 import com.flexstor.common.gateway.exceptions.TransactionFailedException;
18 import com.flexstor.common.keys.ejb.PrivAssetKey;
19 import com.flexstor.ejb.EjbObject;
20 import com.flexstor.ejb.privasset.persist.PrivAssetPersist;
21 import com.flexstor.ejb.privasset.persist.PrivAssetPersistHome;
22
23 /**
24 * Retrieves and updates privileges.
25 *
26 * @author Praveen Jani
27 * @since 3.0
28 */
29 public class PrivAssetGateway
30 extends Gateway
31 {
32 // MKS macro expander
33 public final static String IDENTIFIER = "$Id: PrivAssetGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
34
35 /**
36 * Instance of PrivAssetPersist remote interface.
37 *
38 * @since 3.0
39 * @see com.flexstor.ejb.privasset.persist.PrivAssetPersist
40 */
41
42 private PrivAssetPersist priv;
43
44 /**
45 * Returns the home name of the bean to be accessed.
46 *
47 * @return String - the home interface name
48 * @since 3.0
49 * @see com.flexstor.common.constants.EjbHomeInterfacesI
50 */
51
52
53 protected String getHomeName ( )
54 {
55 return PRIV_ASSET_HOME;
56 }
57
58 /**
59 * Returns the bean object (EjbObject)
60 *
61 * @return com.flexstor.ejb.EjbObject
62 * @since 3.0
63 * @see com.flexstor.ejb.EjbObject
64 */
65
66 protected EjbObject getBeanObject ( )
67 {
68 return (EjbObject)priv;
69 }
70
71 /**
72 * Connects the EJB.
73 *
74 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails.
75 * @since 3.0
76 * @see com.flexstor.common.gateway.exceptions.TransactionFailedException
77 * @see com.flexstor.ejb.privasset.persist.GroupPersist
78 * @see com.flexstor.ejb.privasset.persist.GroupPersistHome
79 */
80
81 public void connect ()
82 throws TransactionFailedException
83 {
84 try
85 {
86 if ( canLoadObject() )
87 return;
88
89 PrivAssetPersistHome home = (PrivAssetPersistHome) getHome();
90 GatewayDebugOutput.println ( 3, "Getting PrivAssetPersist object" );
91 priv = home.create();
92 }
93 catch ( Throwable e )
94 {
95 throw buildException(e, "Connecting to PrivAssetPersist", IDENTIFIER );
96 }
97 }
98
99
100
101
102
103 /**
104 * Updates a priv data.
105 *
106 * @param data - the priv's data.
107 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails
108 * @since 3.0
109 * @see com.flexstor.common.data.ejb.privasset.PrivAssetData
110 */
111
112 public void update ( PrivAssetData data )
113 throws TransactionFailedException
114 {
115 try
116 {
117 if ( canLoadObject() )
118 return;
119
120 GatewayDebugOutput.println ( 3, "Update priv data" );
121 priv.update ( data );
122
123 }
124 catch ( Throwable e )
125 {
126 throw buildException(e, "Updating", IDENTIFIER );
127 }
128 }
129 /**
130 * Updates a collection priv data objects.
131 *
132 * @param Vector - collection of the priv's data objects.
133 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails
134 * @since 3.0
135 * @see com.flexstor.common.data.ejb.privasset.PrivAssetData
136 */
137
138 public void update ( Vector data )
139 throws TransactionFailedException
140 {
141 if ( data == null )
142 return;
143
144 try
145 {
146 if ( canLoadObject() )
147 return;
148
149 GatewayDebugOutput.println ( 3, "Update a collection of priv data objects" );
150 priv.update ( data );
151
152 }
153 catch ( Throwable e )
154 {
155 throw buildException(e, "Updating", IDENTIFIER );
156 }
157 }
158 /**
159 * Inserts a priv data.
160 *
161 * @param data - the priv's data.
162 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails
163 * @since 3.0
164 * @see com.flexstor.common.data.ejb.privasset.PrivAssetData
165 */
166
167 public PrivAssetKey insert ( PrivAssetData data )
168 throws TransactionFailedException
169 {
170 PrivAssetKey key = null;
171 try
172 {
173 if ( canLoadObject() )
174 return null;
175
176 GatewayDebugOutput.println ( 3, "Insert priv data" );
177
178 key = priv.insert ( data );
179 }
180 catch ( Throwable e )
181 {
182 throw buildException(e, "Inserting", IDENTIFIER );
183 }
184 return key;
185 }
186
187 /**
188 * Inserts a collection of priv data objects.
189 *
190 * @param Vector - the collection of priv's data objects.
191 * @exception com.flexstor.common.gateway.exceptions.TransactionFailedException Thrown whenever the transaction fails
192 * @since 3.0
193 * @see com.flexstor.common.data.ejb.privasset.PrivAssetData
194 */
195
196 public Vector insert ( Vector data )
197 throws TransactionFailedException
198 {
199 if ( data == null )
200 return null;
201
202 try
203 {
204 if ( canLoadObject() )
205 return null;
206
207 GatewayDebugOutput.println ( 3, "Insert a collection of priv data" );
208
209 return priv.insert ( data );
210 }
211 catch ( Throwable e )
212 {
213 throw buildException(e, "Inserting", IDENTIFIER );
214 }
215 }
216 public Vector getPrivileges ( Vector collectionKeys )
217 throws TransactionFailedException
218 {
219 try
220 {
221 if ( canLoadObject() )
222 return (Vector)retrieveObject( "PrivAsset_getPrivileges" );
223
224 GatewayDebugOutput.println ( 3, "Getting privileges for collection key." );
225 Vector privs = priv.getDataObjects ( collectionKeys );
226
227 if ( canSaveObject() )
228 storeObject( "PrivAsset_getPrivileges", privs );
229
230 return privs;
231 }
232 catch ( Throwable e )
233 {
234 throw buildException( e, "Getting Privileges", IDENTIFIER );
235 }
236 }
237 public Vector getPrivileges ( Vector collectionKeys, int disguiseID )
238 throws TransactionFailedException
239 {
240 try
241 {
242 if ( canLoadObject() )
243 return (Vector)retrieveObject( "PrivAsset_getPrivileges(collectionKeys, disguiseID)" );
244
245 GatewayDebugOutput.println ( 3, "Getting privileges for collection key provided a disguise ID." );
246 Vector privs = priv.getDataObjects ( collectionKeys, disguiseID );
247
248 if ( canSaveObject() )
249 storeObject( "PrivAsset_getPrivileges(collectionKeys, disguiseID)", privs );
250
251 return privs;
252 }
253 catch ( Throwable e )
254 {
255 throw buildException( e, "Getting Privileges", IDENTIFIER );
256 }
257 }
258
259
260 }