Source code: com/flexstor/common/gateway/PrivilegeGateway.java
1 /*
2 * PrivilegeGateway.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.exceptions.ejb.NotFoundException;
16 import com.flexstor.common.gateway.debug.GatewayDebugOutput;
17 import com.flexstor.common.gateway.exceptions.TransactionFailedException;
18 import com.flexstor.ejb.EjbObject;
19 import com.flexstor.ejb.privilege.persist.PrivilegePersist;
20 import com.flexstor.ejb.privilege.persist.PrivilegePersistHome;
21
22 /**
23 * Retrieves information from the server for privileges.
24 * @author Praveen Jani
25 * @version 3.0
26 */
27 public class PrivilegeGateway
28 extends Gateway
29 {
30 // MKS macro expander
31 public final static String IDENTIFIER = "$Id: PrivilegeGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
32
33 private PrivilegePersist privilege = null;
34
35 protected String getHomeName ( )
36 {
37 return PRIVILEGE_PERSIST_HOME;
38 }
39
40 protected EjbObject getBeanObject ( )
41 {
42 return privilege;
43 }
44
45 /**
46 * Sends the request for privilege data to the server.
47 */
48 public void connect ()
49 throws TransactionFailedException
50 {
51 try
52 {
53 if ( canLoadObject() )
54 return;
55
56 PrivilegePersistHome home = (PrivilegePersistHome)getHome ( );
57
58 GatewayDebugOutput.println ( 3, "Getting PrivilegePersist object" );
59 privilege = home.create ();
60 }
61 catch ( NotFoundException e )
62 {
63 throw new TransactionFailedException ( e );
64 }
65 catch ( Throwable e )
66 {
67 throw buildException(e, "Connecting to PrivilegePersist", IDENTIFIER );
68 }
69 }
70
71 /**
72 * Returns the resource ids of the available privileges (application rights).
73 * @throws TransactionFailedException Throws if this transaction fails.
74 */
75 public Vector getResIdsForAllPrivileges ()
76 throws TransactionFailedException
77 {
78 try
79 {
80 GatewayDebugOutput.println ( 3, "Get resource ids of all available privileges" );
81
82 if ( canLoadObject() )
83 return ( Vector )retrieveObject ( "PrivilegePersist_getResIdsForAllPrivileges" );
84
85 Vector data = privilege.getResIdsForAllPrivileges();
86
87 if ( canSaveObject() )
88 storeObject ( "PrivilegePersist_getResIdsForAllPrivileges", data );
89
90 return data;
91 }
92 catch ( Throwable e )
93 {
94 throw buildException(e, "Get resource ids of all available privileges", IDENTIFIER );
95 }
96 }
97 }