KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fulcrum > security > impl > db > entity > SecurityObject


1 package org.apache.fulcrum.security.impl.db.entity;
2
3 /* ====================================================================
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 2001 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowledgment may appear in the software itself,
26  * if and wherever such third-party acknowledgments normally appear.
27  *
28  * 4. The names "Apache" and "Apache Software Foundation" and
29  * "Apache Turbine" must not be used to endorse or promote products
30  * derived from this software without prior written permission. For
31  * written permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache",
34  * "Apache Turbine", nor may "Apache" appear in their name, without
35  * prior written permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation. For more
53  * information on the Apache Software Foundation, please see
54  * <http://www.apache.org/>.
55  */

56
57 import java.util.Collections JavaDoc;
58 import java.util.HashMap JavaDoc;
59 import java.util.Map JavaDoc;
60 import org.apache.torque.om.BaseObject;
61
62 import org.apache.fulcrum.security.entity.SecurityEntity;
63
64 /**
65  * This class represents a generic object used in the Access Control Lists.
66  *
67  * @author <a HREF="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
68  * @author <a HREF="mailto:jmcnally@collab.net">John D. McNally</a>
69  * @author <a HREF="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
70  * @author <a HREF="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
71  * @author <a HREF="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
72  * @author <a HREF="mailto:marco@intermeta.de">Marco Kn&uuml;ttel</a>
73  * @version $Id: SecurityObject.java,v 1.1 2004/11/12 10:25:43 epugh Exp $
74  */

75 public abstract class SecurityObject
76     extends BaseObject
77     implements Comparable JavaDoc,
78                SecurityEntity
79 {
80     /** The name of this object. */
81     private String JavaDoc name;
82
83     /** The attributes of this object. */
84     private Map JavaDoc attributes;
85
86     /**
87      * Constructs a new SecurityObject
88      */

89     public SecurityObject()
90     {
91         this("");
92     }
93
94     /**
95      * Constructs a new SecurityObject with the specified name.
96      *
97      * @param name The name of the new object.
98      */

99     public SecurityObject( String JavaDoc name )
100     {
101         setName(name);
102         setAttributes(Collections.synchronizedMap(new HashMap JavaDoc()));
103     }
104
105     /**
106      * Returns a Map containing this object's attributes.
107      *
108      * @return the object's attributes.
109      */

110     public Map JavaDoc getAttributes()
111     {
112         return attributes;
113     }
114
115     /**
116      * Replaces this object's attributes with the specified Map.
117      *
118      * @param attributes The new attributes of the object.
119      */

120     public void setAttributes( Map JavaDoc attributes )
121     {
122         this.attributes = attributes;
123     }
124
125     /**
126      * Retrieves the value of specific attribute of this object.
127      *
128      * @param name the name of the attribute
129      * @return the value of the attribute
130      */

131     public Object JavaDoc getAttribute( String JavaDoc name )
132     {
133         return attributes.get(name);
134     }
135
136     /**
137      * Sets the value of specific attribute of this object.
138      *
139      * @param name the name of the attribute
140      * @return the value of the attribute
141      */

142     public void setAttribute( String JavaDoc name, Object JavaDoc value )
143     {
144         attributes.put(name, value);
145     }
146
147     /**
148      * Returns the name of this object.
149      *
150      * @return The name of the object.
151      */

152     public String JavaDoc getName()
153     {
154         return name;
155     }
156
157     /**
158      * Sets the name of this object.
159      *
160      * @param name The name of the object.
161      */

162     public void setName(String JavaDoc name)
163     {
164         this.name = name;
165     }
166
167     /**
168      * Used for ordering SecurityObjects.
169      *
170      * @param obj The Object to compare to.
171      * @return -1 if the name of the other object is lexically greater than this
172      * group, 1 if it is lexically lesser, 0 if they are equal.
173      */

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

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