1 package org.apache.turbine.services.security.torque;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.apache.torque.om.Persistent;
20
21 import org.apache.turbine.om.security.Permission;
22 import org.apache.turbine.services.security.TurbineSecurity;
23 import org.apache.turbine.util.security.TurbineSecurityException;
24
25 /***
26 * This class represents a permission given to a Role associated with the
27 * current Session. It is separated from the actual Torque peer object
28 * to be able to replace the Peer with an user supplied Peer (and Object)
29 *
30 * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
31 * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
32 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
33 * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
34 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
35 * @version $Id: TorquePermission.java 264148 2005-08-29 14:21:04Z henning $
36 */
37
38 public class TorquePermission
39 extends TorqueObject
40 implements Permission,
41 Comparable
42 {
43 /***
44 * Constructs a Permission
45 */
46 public TorquePermission()
47 {
48 super();
49 }
50
51 /***
52 * Constructs a new Permission with the sepcified name.
53 *
54 * @param name The name of the new object.
55 */
56 public TorquePermission(String name)
57 {
58 super(name);
59 }
60
61 /***
62 * The package private Constructor is used when the PermissionPeerManager
63 * has retrieved a list of Database Objects from the peer and
64 * must 'wrap' them into TorquePermission Objects.
65 * You should not use it directly!
66 *
67 * @param obj An Object from the peer
68 */
69
70 public TorquePermission(Persistent obj)
71 {
72 super(obj);
73 }
74
75 /***
76 * Returns the underlying Object for the Peer
77 *
78 * Used in the PermissionPeerManager when building a new Criteria.
79 *
80 * @return The underlying Persistent Object
81 *
82 */
83
84 public Persistent getPersistentObj()
85 {
86 if (obj == null)
87 {
88 obj = PermissionPeerManager.newPersistentInstance();
89 }
90 return obj;
91 }
92
93 /***
94 * Returns the name of this object.
95 *
96 * @return The name of the object.
97 */
98 public String getName()
99 {
100 return PermissionPeerManager.getPermissionName(getPersistentObj());
101 }
102
103 /***
104 * Sets the name of this object.
105 *
106 * @param name The name of the object.
107 */
108 public void setName(String name)
109 {
110 PermissionPeerManager.setPermissionName(getPersistentObj(), name);
111 }
112
113 /***
114 * Gets the Id of this object
115 *
116 * @return The Id of the object
117 */
118 public int getId()
119 {
120 return PermissionPeerManager.getIdAsObj(getPersistentObj()).intValue();
121 }
122
123 /***
124 * Gets the Id of this object
125 *
126 * @return The Id of the object
127 */
128 public Integer getIdAsObj()
129 {
130 return PermissionPeerManager.getIdAsObj(getPersistentObj());
131 }
132
133 /***
134 * Sets the Id of this object
135 *
136 * @param id The new Id
137 */
138 public void setId(int id)
139 {
140 PermissionPeerManager.setId(getPersistentObj(), id);
141 }
142
143 /***
144 * Creates a new Permission in the system.
145 *
146 * @param name The name of the new Permission.
147 * @return An object representing the new Permission.
148 * @throws TurbineSecurityException if the Permission could not be created.
149 * @deprecated Please use the createPermission method in TurbineSecurity.
150 */
151 public static Permission create(String name)
152 throws TurbineSecurityException
153 {
154 return TurbineSecurity.createPermission(name);
155 }
156
157 /***
158 * Makes changes made to the Permission attributes permanent.
159 *
160 * @throws TurbineSecurityException if there is a problem while
161 * saving data.
162 */
163 public void save()
164 throws TurbineSecurityException
165 {
166 TurbineSecurity.savePermission(this);
167 }
168
169 /***
170 * Removes a permission from the system.
171 *
172 * @throws TurbineSecurityException if the Permission could not be removed.
173 */
174 public void remove()
175 throws TurbineSecurityException
176 {
177 TurbineSecurity.removePermission(this);
178 }
179
180 /***
181 * Renames the permission.
182 *
183 * @param name The new Permission name.
184 * @throws TurbineSecurityException if the Permission could not be renamed.
185 */
186 public void rename(String name)
187 throws TurbineSecurityException
188 {
189 TurbineSecurity.renamePermission(this, name);
190 }
191 }
192
193
194