Adding recursive call to the getResolvedClassInfo() method: look into the parent...
[jpf-core.git] / src / classes / java / security / AllPermission.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The Java Pathfinder core (jpf-core) platform is licensed under the
7  * Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package java.security;
19
20 import java.util.Enumeration;
21 import sun.security.util.SecurityConstants;
22
23 // TODO: Fix for Groovy's model-checking
24 /**
25  * MJI model class for java.security.AllPermission library abstraction
26  */
27 public final class AllPermission extends Permission {
28
29     private static final long serialVersionUID = -2916474571451318075L;
30
31     public AllPermission() {
32         super("<all permissions>");
33     }
34
35     public boolean implies(Permission p) {
36         return true;
37     }
38
39     public boolean equals(Object obj) {
40         return (obj instanceof AllPermission);
41     }
42
43     public int hashCode() {
44         return 1;
45     }
46
47     public String getActions() {
48         return "<all actions>";
49     }
50
51     public PermissionCollection newPermissionCollection() {
52         return new AllPermissionCollection();
53     }
54
55 }
56
57
58 final class AllPermissionCollection
59         extends PermissionCollection
60         implements java.io.Serializable
61 {
62
63     // use serialVersionUID from JDK 1.2.2 for interoperability
64     private static final long serialVersionUID = -4023755556366636806L;
65
66     private boolean all_allowed; // true if any all permissions have been added
67
68     public AllPermissionCollection() {
69         all_allowed = false;
70     }
71
72     public void add(Permission permission) {
73         if (! (permission instanceof AllPermission))
74             throw new IllegalArgumentException("invalid permission: "+
75                     permission);
76         if (isReadOnly())
77             throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");
78
79         all_allowed = true; // No sync; staleness OK
80     }
81
82     public boolean implies(Permission permission) {
83         return all_allowed; // No sync; staleness OK
84     }
85
86     public Enumeration<Permission> elements() {
87         return new Enumeration<Permission>() {
88             private boolean hasMore = all_allowed;
89
90             public boolean hasMoreElements() {
91                 return hasMore;
92             }
93
94             public Permission nextElement() {
95                 hasMore = false;
96                 return SecurityConstants.ALL_PERMISSION;
97             }
98         };
99     }
100 }