001: package org.apache.turbine.om.security;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.util.Collections;
023: import java.util.HashMap;
024: import java.util.Map;
025:
026: import org.apache.torque.om.BaseObject;
027:
028: /**
029: * This class represents a generic object used in the Access Control Lists.
030: *
031: * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
032: * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
033: * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
034: * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
035: *
036: * @deprecated Use {@link org.apache.turbine.services.security.torque.TorqueSecurityService}
037: * instead.
038: *
039: * @version $Id: SecurityObject.java 534527 2007-05-02 16:10:59Z tv $
040: */
041: public abstract class SecurityObject extends BaseObject implements
042: Comparable {
043: /** The name of this object. */
044: private String name;
045:
046: /** The id of this object */
047: private int id;
048:
049: /** The attributes of this object. */
050: private Map attributes;
051:
052: /**
053: * Constructs a new SecurityObject
054: */
055: public SecurityObject() {
056: this ("");
057: }
058:
059: /**
060: * Constructs a new SecurityObject with the specified name.
061: *
062: * @param name The name of the new object.
063: */
064: public SecurityObject(String name) {
065: setName(name);
066: setId(0);
067: setAttributes(Collections.synchronizedMap(new HashMap()));
068: }
069:
070: /**
071: * Returns a Map containing this object's attributes.
072: *
073: * @return the object's attributes.
074: */
075: public Map getAttributes() {
076: return attributes;
077: }
078:
079: /**
080: * Replaces this object's attributes with the specified Map.
081: *
082: * @param attributes The new attributes of the object.
083: */
084: public void setAttributes(Map attributes) {
085: this .attributes = attributes;
086: }
087:
088: /**
089: * Retrieves the value of specific attribute of this object.
090: *
091: * @param name the name of the attribute
092: * @return the value of the attribute
093: */
094: public Object getAttribute(String name) {
095: return attributes.get(name);
096: }
097:
098: /**
099: * Sets the value of specific attribute of this object.
100: *
101: * @param name the name of the attribute
102: * @param value the value of the attribute
103: */
104: public void setAttribute(String name, Object value) {
105: attributes.put(name, value);
106: }
107:
108: /**
109: * Returns the name of this object.
110: *
111: * @return The name of the object.
112: */
113: public String getName() {
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 name) {
123: this .name = name;
124: }
125:
126: /**
127: * Unused. There is an ID column in the
128: * database scheme but it doesn't seem
129: * to be used.
130: *
131: * @return 0
132: */
133: public int getId() {
134: return id;
135: }
136:
137: /**
138: * Unused. There is an ID column in the
139: * database scheme but it doesn't seem
140: * to be used.
141: *
142: * @return null
143: */
144: public Integer getIdAsObj() {
145: return new Integer(id);
146: }
147:
148: /**
149: * Unused. There is an ID column in the
150: * database scheme but it doesn't seem
151: * to be used.
152: *
153: * @param id The id of the User.
154: */
155: public void setId(int id) {
156: this .id = id;
157: }
158:
159: /**
160: * Used for ordering SecurityObjects.
161: *
162: * @param obj The Object to compare to.
163: * @return -1 if the name of the other object is lexically greater than this
164: * group, 1 if it is lexically lesser, 0 if they are equal.
165: */
166: public int compareTo(Object obj) {
167: if (this .getClass() != obj.getClass()) {
168: throw new ClassCastException();
169: }
170: String name1 = ((SecurityObject) obj).getName();
171: String name2 = this .getName();
172:
173: return name2.compareTo(name1);
174: }
175:
176: /**
177: * Returns a textual representation of this object, consisted by
178: * it's name and attributes.
179: *
180: * @return a textual representation of this group.
181: */
182: public String toString() {
183: return (getName() + ':' + getAttributes().toString());
184: }
185: }
|