source: trunk/src/gcc/libjava/java/security/PermissionCollection.java@ 2

Last change on this file since 2 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.2 KB
Line 
1/* PermissionCollection.java -- A collection of permission objects
2 Copyright (C) 1998, 2001 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package java.security;
39
40import java.io.Serializable;
41import java.util.Enumeration;
42
43 /**
44 * This class models a group of Java permissions. It has convenient
45 * methods for determining whether or not a given permission is implied
46 * by any of the permissions in this collection.
47 * <p>
48 * Some care must be taken in storing permissions. First, a collection of
49 * the appropriate type must be created. This is done by calling the
50 * <code>newPermissionCollection</code> method on an object of the
51 * permission class you wish to add to the collection. If this method
52 * returns <code>null</code>, any type of <code>PermissionCollection</code>
53 * can be used to store permissions of that type. However, if a
54 * <code>PermissionCollection</code> collection object is returned, that
55 * type must be used.
56 * <p>
57 * The <code>PermissionCollection</code>'s returned
58 * by the <code>newPermissionCollection</code> instance in a subclass of
59 * <code>Permission</code> is a homogeneous collection. It only will
60 * hold permissions of one specified type - instances of the class that
61 * created it. Not all <code>PermissionCollection</code> subclasses
62 * have to hold permissions of only one type however. For example,
63 * the <code>Permissions</code> class holds permissions of many types.
64 * <p>
65 * Since the <code>newPermissionCollection</code> in <code>Permission</code>
66 * itself returns <code>null</code>, by default a permission can be stored
67 * in any type of collection unless it overrides that method to create its
68 * own collection type.
69 *
70 * @version 0.0
71 *
72 * @author Aaron M. Renn ([email protected])
73 */
74public abstract class PermissionCollection
75 extends Object
76 implements Serializable
77{
78 private static final String linesep = null;
79
80 static
81 {
82 String linesep = System.getProperty("line.separator");
83 if (linesep == null);
84 linesep = "\n";
85 }
86
87 /**
88 * Indicates whether or not this collection is read only.
89 */
90 private boolean readOnly;
91
92 /**
93 * This method initializes a new instance of <code>PermissionCollection</code>.
94 * This is provided only as a default constructor and does nothing in this
95 * class.
96 */
97 public PermissionCollection()
98 {
99 }
100
101 /**
102 * This method tests whether or not this <code>PermissionCollection</code>
103 * object is read only.
104 *
105 * @return <code>true</code> if this collection is read only, <code>false</code> otherwise
106 */
107 public boolean isReadOnly()
108 {
109 return (readOnly);
110 }
111
112 /**
113 * This method sets this <code>PermissionCollection</code> object to be
114 * read only. No further permissions can be added to it after calling this
115 * method.
116 */
117 public void setReadOnly()
118 {
119 readOnly = true;
120 }
121
122 /**
123 * This method adds a new <code>Permission</code> object to the collection.
124 *
125 * @param perm The <code>Permission</code> to add.
126 *
127 * @exception SecurityException If the collection is marked read only.
128 * @exception IllegalArgumentException If a permission of the specified type cannot be added
129 */
130 public abstract void
131 add(Permission perm) throws SecurityException, IllegalArgumentException;
132
133 /**
134 * This method returns an <code>Enumeration</code> of all the objects in
135 * this collection.
136 *
137 * @return An <code>Enumeration</code> of this collection's objects.
138 */
139 public abstract Enumeration elements();
140
141 /**
142 * This method tests whether the specified <code>Permission</code> object is
143 * implied by this collection of <code>Permission</code> objects.
144 *
145 * @param perm The <code>Permission</code> object to test.
146 *
147 * @return <code>true</code> if the specified <code>Permission</code> is implied by this collection, <code>false</code> otherwise.
148 */
149 public abstract boolean implies(Permission perm);
150
151 /**
152 * This method returns a <code>String</code> representation of this
153 * collection. It will print the class name and has code in the same
154 * manner as <code>Object.toString()</code> then print a listing of all
155 * the <code>Permission</code> objects contained.
156 *
157 * @return A <code>String</code> representing this object.
158 */
159 public String toString()
160 {
161 StringBuffer sb = new StringBuffer("");
162
163 sb.append(super.toString() + " (" + linesep);
164 Enumeration e = elements();
165 while (e.hasMoreElements())
166 {
167 Object obj = e.nextElement();
168 if (obj instanceof Permission)
169 sb.append(((Permission) obj).toString() + linesep);
170 }
171
172 sb.append(")" + linesep);
173 return (sb.toString());
174 }
175}
Note: See TracBrowser for help on using the repository browser.