001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.lenya.ac.impl;
020:
021: import org.apache.avalon.framework.container.ContainerUtil;
022: import org.apache.avalon.framework.logger.AbstractLogEnabled;
023: import org.apache.avalon.framework.logger.Logger;
024: import org.apache.lenya.ac.AccreditableManager;
025: import org.apache.lenya.ac.Item;
026: import org.apache.lenya.ac.ItemManager;
027: import org.apache.lenya.ac.ItemUtil;
028: import org.apache.lenya.util.Assert;
029:
030: /**
031: * Abstract superclass for all access control objects that can be managed by an
032: * {@link org.apache.lenya.ac.ItemManager}. It is only used for code reuse.
033: * @version $Id: AbstractItem.java 499016 2007-01-23 13:18:39Z andreas $
034: */
035: public abstract class AbstractItem extends AbstractLogEnabled implements
036: Item, Comparable {
037:
038: private String id;
039: private String description = "";
040: private String name = "";
041:
042: private ItemManager itemManager;
043:
044: /**
045: * Ctor.
046: * @param itemManager The item manager this item belongs to.
047: * @param logger The logger.
048: */
049: public AbstractItem(ItemManager itemManager, Logger logger) {
050: Assert.notNull("item manager", itemManager);
051: this .itemManager = itemManager;
052:
053: Assert.notNull("logger", logger);
054: ContainerUtil.enableLogging(this , logger);
055: }
056:
057: /**
058: * @return The accreditable manager.
059: */
060: public AccreditableManager getAccreditableManager() {
061: return getItemManager().getAccreditableManager();
062: }
063:
064: /**
065: * Sets the ID.
066: * @param string The ID.
067: */
068: protected void setId(String string) {
069: assert ItemUtil.isValidId(string);
070: this .id = string;
071: }
072:
073: /**
074: * Returns the ID.
075: * @return The ID.
076: */
077: public String getId() {
078: return this .id;
079: }
080:
081: /**
082: * Returns the description of this object.
083: * @return A string.
084: */
085: public String getDescription() {
086: return this .description;
087: }
088:
089: /**
090: * Sets the description of this object.
091: * @param _description A string.
092: */
093: public void setDescription(String _description) {
094: assert _description != null;
095: this .description = _description;
096: }
097:
098: /**
099: * @see java.lang.Object#toString()
100: */
101: public String toString() {
102: return getId();
103:
104: }
105:
106: /**
107: * Returns the name of this object.
108: * @return A <code>String</code>.
109: */
110: public String getName() {
111: return this .name;
112: }
113:
114: /**
115: * Set the full name
116: * @param _name the new full name
117: */
118: public void setName(String _name) {
119: assert _name != null;
120: this .name = _name;
121: }
122:
123: /**
124: * @see java.lang.Object#equals(Object)
125: */
126: public boolean equals(Object otherObject) {
127: boolean equals = false;
128:
129: if (getClass().isInstance(otherObject)) {
130: AbstractItem otherManageable = (AbstractItem) otherObject;
131: String this MgrId = getAccreditableManager().getId();
132: String otherMgrId = otherManageable
133: .getAccreditableManager().getId();
134: equals = getId().equals(otherManageable.getId())
135: && this MgrId.equals(otherMgrId);
136: }
137: return equals;
138: }
139:
140: /**
141: * @see java.lang.Object#hashCode()
142: */
143: public int hashCode() {
144: return getId().hashCode();
145: }
146:
147: /**
148: * @see java.lang.Comparable#compareTo(java.lang.Object)
149: */
150: public int compareTo(Object obj) {
151: if (obj instanceof AbstractItem) {
152: return getId().compareTo(((AbstractItem) obj).getId());
153: }
154: return 0;
155: }
156:
157: public ItemManager getItemManager() {
158: return this.itemManager;
159: }
160:
161: }
|