KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > ac > impl > AbstractItem


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.lenya.ac.impl;
19
20 import org.apache.lenya.ac.Item;
21
22 /**
23  * Abstract superclass for all access control objects that can be managed by an
24  * {@link org.apache.lenya.ac.ItemManager}. It is only used for code reuse.
25  * @version $Id: AbstractItem.java 43241 2004-08-16 16:36:57Z andreas $
26  */

27 public abstract class AbstractItem implements Item {
28
29     private String JavaDoc id;
30     private String JavaDoc description = "";
31     private String JavaDoc name = "";
32
33     /**
34      * Ctor.
35      */

36     public AbstractItem() {
37     }
38
39     /**
40      * Sets the ID.
41      * @param string The ID.
42      */

43     protected void setId(String JavaDoc string) {
44         assert isValidId(string);
45         id = string;
46     }
47
48     /**
49      * Returns the ID.
50      * @return The ID.
51      */

52     public String JavaDoc getId() {
53         return id;
54     }
55
56     /**
57      * Returns the description of this object.
58      * @return A string.
59      */

60     public String JavaDoc getDescription() {
61         return description;
62     }
63
64     /**
65      * Sets the description of this object.
66      * @param description A string.
67      */

68     public void setDescription(String JavaDoc description) {
69         assert description != null;
70         this.description = description;
71     }
72
73     /**
74      * @see java.lang.Object#toString()
75      */

76     public String JavaDoc toString() {
77         return getId();
78
79     }
80
81     /**
82      * Returns the name of this object.
83      *
84      * @return A <code>String</code>.
85      */

86     public String JavaDoc getName() {
87         return name;
88     }
89
90     /**
91      * Set the full name
92      *
93      * @param name the new full name
94      */

95     public void setName(String JavaDoc name) {
96         assert name != null;
97         this.name = name;
98     }
99
100     /**
101      * Checks if a string is a valid ID.
102      * @param id The string to test.
103      * @return A boolean value.
104      */

105     public static boolean isValidId(String JavaDoc id) {
106         return id != null && id.matches("\\w+");
107     }
108
109     /**
110      * @see java.lang.Object#equals(Object)
111      */

112     public boolean equals(Object JavaDoc otherObject) {
113         boolean equals = false;
114
115         if (getClass().isInstance(otherObject)) {
116             AbstractItem otherManageable = (AbstractItem) otherObject;
117             equals = getId().equals(otherManageable.getId());
118         }
119
120         return equals;
121     }
122
123     /**
124      * @see java.lang.Object#hashCode()
125      */

126     public int hashCode() {
127         return getId().hashCode();
128     }
129
130 }
Popular Tags