KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > MethodPermission


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment;
25
26 import com.sun.enterprise.deployment.Role;
27
28 /**
29  * Represents a method permission. A method permission can be associated to
30  * a role, be unchecked or excluded.
31  *
32  * @author Jerome Dochez
33  * @version
34  */

35 public class MethodPermission extends Descriptor {
36
37     private static MethodPermission unchecked;
38     private static MethodPermission excluded;
39     private boolean isUnchecked = false;
40     private boolean isExcluded = false;
41     private Role role;
42     
43     /**
44      * construct a new MethodPermission based on a security role
45      *
46      * @param role the security role associated to the method permission
47      */

48     public MethodPermission(Role role) {
49         this.role = role;
50     }
51
52     // We don't want uninitialized method permissins
53
private MethodPermission() {
54     }
55     
56     /**
57      * @return an unchecked method permission. Methods associated with such a
58      * method permission can be invoked by anyone
59      */

60     public static MethodPermission getUncheckedMethodPermission() {
61         if (unchecked==null) {
62             unchecked = new MethodPermission();
63             unchecked.isUnchecked=true;
64         }
65         return unchecked;
66     }
67     
68     /**
69      * @return an ecluded method permission. Methods associated with such a
70      * method permission cannot be invoked by anyone.
71      */

72     public static MethodPermission getExcludedMethodPermission() {
73         if (excluded==null) {
74             excluded = new MethodPermission();
75             excluded.isExcluded=true;
76         }
77         return excluded;
78     }
79     
80     /**
81      * @return true if the method permission is based on a security role
82      */

83     public boolean isRoleBased() {
84         return role!=null;
85     }
86     
87     /**
88      * @return true if the method permission is unchecked
89      */

90     public boolean isUnchecked() {
91         return isUnchecked;
92     }
93     
94     /**
95      * @return true if the method permission is excluded
96      */

97     public boolean isExcluded() {
98         return isExcluded;
99     }
100     
101     /**
102      * @return the security role associated with this method permission when
103      * applicable (role based method permission)
104      */

105     public Role getRole() {
106         return role;
107     }
108     
109     // For Map storage
110
public int hashCode() {
111         if (role!=null)
112             return role.hashCode();
113         else
114             return super.hashCode();
115     }
116     
117     // for Map storage
118
public boolean equals(Object JavaDoc other) {
119     boolean ret = false;
120     if(other instanceof MethodPermission) {
121             MethodPermission o = (MethodPermission) other;
122             if (isRoleBased()) {
123             ret = role.equals(o.getRole());
124             } else {
125                 ret = (isExcluded == o.isExcluded()) && (isUnchecked == o.isUnchecked());
126             }
127     }
128     return ret;
129     }
130     
131     public void print(StringBuffer JavaDoc toStringBuffer) {
132         if (isRoleBased()) {
133             toStringBuffer.append(role.toString());
134         } else {
135             if (isExcluded)
136                 toStringBuffer.append("excluded");
137             else
138                 toStringBuffer.append("unchecked");
139         }
140     }
141 }
142         
143
Popular Tags