KickJava   Java API By Example, From Geeks To Geeks.

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


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 /* $Id: Credential.java 42616 2004-03-03 12:56:33Z gregor $ */
19
20 package org.apache.lenya.ac.impl;
21
22
23 import java.util.HashSet JavaDoc;
24 import java.util.Set JavaDoc;
25
26 import org.apache.lenya.ac.Accreditable;
27 import org.apache.lenya.ac.Role;
28
29
30 /**
31  * A credential assigns a set of {@link Role}s to an {@link Accreditable}.
32  */

33 public class Credential {
34     private Accreditable accreditable;
35     private Set JavaDoc roles = new HashSet JavaDoc();
36
37     /**
38      * Creates a new credential object.
39      * @param accreditable The accreditable.
40      */

41     public Credential(Accreditable accreditable) {
42         setAccreditable(accreditable);
43     }
44
45     /**
46      * Sets the accreditable for this credential.
47      * @param accreditable The accreditable.
48      */

49     protected void setAccreditable(Accreditable accreditable) {
50         assert accreditable != null;
51         this.accreditable = accreditable;
52     }
53
54     /**
55      * Returns all roles of this credential.
56      *
57      * @return An array of roles.
58      */

59     public Role[] getRoles() {
60         return (Role[]) roles.toArray(new Role[roles.size()]);
61     }
62
63     /**
64      * Adds a role to this credential.
65      * @param role The role to add.
66      */

67     public void addRole(Role role) {
68         assert role != null;
69         assert !roles.contains(role);
70         roles.add(role);
71     }
72
73     /**
74      * Removes a role from this credential.
75      * @param role The role to remove.
76      */

77     public void removeRole(Role role) {
78         assert role != null;
79         assert roles.contains(role);
80         roles.remove(role);
81     }
82
83     /**
84      * Returns the accreditable of this credential.
85      * @return An accreditable.
86      */

87     public Accreditable getAccreditable() {
88         return accreditable;
89     }
90
91     /**
92      * @see java.lang.Object#toString()
93      */

94     public String JavaDoc toString() {
95         return "[credential of: " + getAccreditable() + "]";
96     }
97     
98     /**
99      * Returns if a role is contained.
100      * @param role A role.
101      * @return A boolean value.
102      */

103     public boolean contains(Role role) {
104         return roles.contains(role);
105     }
106     
107     /**
108      * Returns if the credential is empty (contains no roles).
109      * @return A boolean value.
110      */

111     public boolean isEmpty() {
112         return roles.isEmpty();
113     }
114 }
115
Popular Tags