KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > om > security > SecurityObject


1 package org.apache.turbine.om.security;
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 java.util.Collections JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.torque.om.BaseObject;
24
25 /**
26  * This class represents a generic object used in the Access Control Lists.
27  *
28  * @author <a HREF="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
29  * @author <a HREF="mailto:john.mcnally@clearink.com">John D. McNally</a>
30  * @author <a HREF="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
31  * @author <a HREF="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
32  * @version $Id: SecurityObject.java,v 1.6.2.2 2004/05/20 03:05:17 seade Exp $
33  */

34 public abstract class SecurityObject extends BaseObject implements Comparable JavaDoc
35 {
36     /** The name of this object. */
37     private String JavaDoc name;
38
39     /** The id of this object */
40     private int id;
41
42     /** The attributes of this object. */
43     private Map JavaDoc attributes;
44
45     /**
46      * Constructs a new SecurityObject
47      */

48     public SecurityObject()
49     {
50         this("");
51     }
52
53     /**
54      * Constructs a new SecurityObject with the specified name.
55      *
56      * @param name The name of the new object.
57      */

58     public SecurityObject(String JavaDoc name)
59     {
60         setName(name);
61         setId(0);
62         setAttributes(Collections.synchronizedMap(new HashMap JavaDoc()));
63     }
64
65     /**
66      * Returns a Map containing this object's attributes.
67      *
68      * @return the object's attributes.
69      */

70     public Map JavaDoc getAttributes()
71     {
72         return attributes;
73     }
74
75     /**
76      * Replaces this object's attributes with the specified Map.
77      *
78      * @param attributes The new attributes of the object.
79      */

80     public void setAttributes(Map JavaDoc attributes)
81     {
82         this.attributes = attributes;
83     }
84
85     /**
86      * Retrieves the value of specific attribute of this object.
87      *
88      * @param name the name of the attribute
89      * @return the value of the attribute
90      */

91     public Object JavaDoc getAttribute(String JavaDoc name)
92     {
93         return attributes.get(name);
94     }
95
96     /**
97      * Sets the value of specific attribute of this object.
98      *
99      * @param name the name of the attribute
100      * @param value the value of the attribute
101      */

102     public void setAttribute(String JavaDoc name, Object JavaDoc value)
103     {
104         attributes.put(name, value);
105     }
106
107     /**
108      * Returns the name of this object.
109      *
110      * @return The name of the object.
111      */

112     public String JavaDoc getName()
113     {
114         return name;
115     }
116
117     /**
118      * Sets the name of this object.
119      *
120      * @param name The name of the object.
121      */

122     public void setName(String JavaDoc name)
123     {
124         this.name = name;
125     }
126
127     /**
128      * Unused. There is an ID column in the
129      * database scheme but it doesn't seem
130      * to be used.
131      *
132      * @return 0
133      */

134     public int getId()
135     {
136         return id;
137     }
138             
139     /**
140      * Unused. There is an ID column in the
141      * database scheme but it doesn't seem
142      * to be used.
143      *
144      * @return null
145      */

146     public Integer JavaDoc getIdAsObj()
147     {
148         return new Integer JavaDoc(id);
149     }
150
151     /**
152      * Unused. There is an ID column in the
153      * database scheme but it doesn't seem
154      * to be used.
155      *
156      * @param id The id of the User.
157      */

158     public void setId(int id)
159     {
160         this.id = id;
161     }
162
163     /**
164      * Used for ordering SecurityObjects.
165      *
166      * @param obj The Object to compare to.
167      * @return -1 if the name of the other object is lexically greater than this
168      * group, 1 if it is lexically lesser, 0 if they are equal.
169      */

170     public int compareTo(Object JavaDoc obj)
171     {
172         if (this.getClass() != obj.getClass())
173         {
174             throw new ClassCastException JavaDoc();
175         }
176         String JavaDoc name1 = ((SecurityObject) obj).getName();
177         String JavaDoc name2 = this.getName();
178
179         return name2.compareTo(name1);
180     }
181
182     /**
183      * Returns a textual representation of this object, consisted by
184      * it's name and attributes.
185      *
186      * @return a textual representation of this group.
187      */

188     public String JavaDoc toString()
189     {
190         return (getName() + ':' + getAttributes().toString());
191     }
192 }
193
Popular Tags