KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > security > torque > TorquePermission


1 package org.apache.turbine.services.security.torque;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
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,v 1.4.2.2 2004/05/20 03:06:50 seade Exp $
36  */

37
38 public class TorquePermission
39     extends TorqueObject
40     implements Permission,
41                Comparable JavaDoc,
42                Persistent
43 {
44     /**
45      * Constructs a Permission
46      */

47     public TorquePermission()
48     {
49       super();
50     }
51
52     /**
53      * Constructs a new Permission with the sepcified name.
54      *
55      * @param name The name of the new object.
56      */

57     public TorquePermission(String JavaDoc name)
58     {
59         super(name);
60     }
61
62     /**
63      * The package private Constructor is used when the PermissionPeerManager
64      * has retrieved a list of Database Objects from the peer and
65      * must 'wrap' them into TorquePermission Objects.
66      * You should not use it directly!
67      *
68      * @param obj An Object from the peer
69      */

70
71     public TorquePermission(Persistent obj)
72     {
73         super(obj);
74     }
75
76     /**
77      * Returns the underlying Object for the Peer
78      *
79      * Used in the PermissionPeerManager when building a new Criteria.
80      *
81      * @return The underlying Persistent Object
82      *
83      */

84
85     public Persistent getPersistentObj()
86     {
87         if (obj == null)
88         {
89             obj = PermissionPeerManager.newPersistentInstance();
90         }
91         return obj;
92     }
93
94     /**
95      * Returns the name of this object.
96      *
97      * @return The name of the object.
98      */

99     public String JavaDoc getName()
100     {
101         return PermissionPeerManager.getPermissionName(getPersistentObj());
102     }
103
104     /**
105      * Sets the name of this object.
106      *
107      * @param name The name of the object.
108      */

109     public void setName(String JavaDoc name)
110     {
111         PermissionPeerManager.setPermissionName(getPersistentObj(), name);
112     }
113
114     /**
115      * Gets the Id of this object
116      *
117      * @return The Id of the object
118      */

119     public int getId()
120     {
121         return PermissionPeerManager.getIdAsObj(getPersistentObj()).intValue();
122     }
123
124     /**
125      * Gets the Id of this object
126      *
127      * @return The Id of the object
128      */

129     public Integer JavaDoc getIdAsObj()
130     {
131         return PermissionPeerManager.getIdAsObj(getPersistentObj());
132     }
133
134     /**
135      * Sets the Id of this object
136      *
137      * @param id The new Id
138      */

139     public void setId(int id)
140     {
141         PermissionPeerManager.setId(getPersistentObj(), id);
142     }
143
144     /**
145      * Creates a new Permission in the system.
146      *
147      * @param name The name of the new Permission.
148      * @return An object representing the new Permission.
149      * @throws TurbineSecurityException if the Permission could not be created.
150      * @deprecated Please use the createPermission method in TurbineSecurity.
151      */

152     public static Permission create(String JavaDoc name)
153         throws TurbineSecurityException
154     {
155         return TurbineSecurity.createPermission(name);
156     }
157
158     /**
159      * Makes changes made to the Permission attributes permanent.
160      *
161      * @throws TurbineSecurityException if there is a problem while
162      * saving data.
163      */

164     public void save()
165         throws TurbineSecurityException
166     {
167         TurbineSecurity.savePermission(this);
168     }
169
170     /**
171      * Removes a permission from the system.
172      *
173      * @throws TurbineSecurityException if the Permission could not be removed.
174      */

175     public void remove()
176         throws TurbineSecurityException
177     {
178         TurbineSecurity.removePermission(this);
179     }
180
181     /**
182      * Renames the permission.
183      *
184      * @param name The new Permission name.
185      * @throws TurbineSecurityException if the Permission could not be renamed.
186      */

187     public void rename(String JavaDoc name)
188         throws TurbineSecurityException
189     {
190         TurbineSecurity.renamePermission(this, name);
191     }
192 }
193
194
195
196
Popular Tags