KickJava   Java API By Example, From Geeks To Geeks.

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


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: RemovedAccreditablePolicyBuilder.java 42660 2004-03-08 16:48:21Z gregor $ */
19
20 package org.apache.lenya.ac.impl;
21
22 import org.apache.lenya.ac.AccessControlException;
23 import org.apache.lenya.ac.Accreditable;
24 import org.apache.lenya.ac.AccreditableManager;
25 import org.apache.lenya.ac.Group;
26 import org.apache.lenya.ac.IPRange;
27 import org.apache.lenya.ac.User;
28
29 /**
30  * A PolicyBuilder which can be used after an accreditable was removed.
31  */

32 public class RemovedAccreditablePolicyBuilder extends PolicyBuilder {
33
34     /**
35      * Ctor.
36      * @param accreditableManager The accreditable manager.
37      */

38     public RemovedAccreditablePolicyBuilder(AccreditableManager accreditableManager) {
39         super(accreditableManager);
40     }
41
42     private Accreditable removedAccreditable;
43
44     /**
45      * Sets the removed accreditable.
46      *
47      * @param accreditable An accreditable.
48      */

49     public void setRemovedAccreditable(Accreditable accreditable) {
50         this.removedAccreditable = accreditable;
51     }
52
53     /**
54      * @see org.apache.lenya.ac.impl.PolicyBuilder#getAccreditable(java.lang.String, java.lang.String)
55      */

56     protected Accreditable getAccreditable(String JavaDoc elementName, String JavaDoc id)
57         throws AccessControlException {
58
59         Accreditable accreditable;
60
61         if (removedAccreditable instanceof User
62             && elementName.equals(USER_ELEMENT)
63             && ((User) removedAccreditable).getId().equals(id)) {
64             accreditable = removedAccreditable;
65         } else if (
66             removedAccreditable instanceof Group
67                 && elementName.equals(GROUP_ELEMENT)
68                 && ((Group) removedAccreditable).getId().equals(id)) {
69             accreditable = removedAccreditable;
70         } else if (
71             removedAccreditable instanceof IPRange
72                 && elementName.equals(IP_RANGE_ELEMENT)
73                 && ((IPRange) removedAccreditable).getId().equals(id)) {
74             accreditable = removedAccreditable;
75         } else {
76
77             accreditable = super.getAccreditable(elementName, id);
78         }
79         return accreditable;
80     }
81
82 }
83
Popular Tags