src/java.base/share/classes/java/security/PermissionCollection.java
author igerasim
Wed, 16 Oct 2019 18:47:11 -0700
changeset 58659 4113f16d5109
parent 58242 94bb65cb37d3
child 58679 9c3209ff7550
permissions -rw-r--r--
8231859: Extra dash after the exception name in @throws clause of javadoc Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
    29
import java.util.stream.Stream;
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
    30
import java.util.stream.StreamSupport;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Abstract class representing a collection of Permission objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>With a PermissionCollection, you can:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <UL>
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    37
 * <LI> add a permission to the collection using the {@code add} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <LI> check to see if a particular permission is implied in the
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    39
 *      collection, using the {@code implies} method.
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    40
 * <LI> enumerate all the permissions, using the {@code elements} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>When it is desirable to group together a number of Permission objects
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    44
 * of the same type, the {@code newPermissionCollection} method on that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * particular type of Permission object should first be called. The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * behavior (from the Permission class) is to simply return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Subclasses of class Permission override the method if they need to store
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * their permissions in a particular PermissionCollection object in order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * to provide the correct semantics when the
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    50
 * {@code PermissionCollection.implies} method is called.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * If a non-null value is returned, that PermissionCollection must be used.
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    52
 * If null is returned, then the caller of {@code newPermissionCollection}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * is free to store permissions of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * given type in any PermissionCollection they choose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * (one that uses a Hashtable, one that uses a Vector, etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>The PermissionCollection returned by the
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    58
 * {@code Permission.newPermissionCollection}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * method is a homogeneous collection, which stores only Permission objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * for a given Permission type.  A PermissionCollection may also be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * heterogeneous.  For example, Permissions is a PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * subclass that represents a collection of PermissionCollections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * That is, its members are each a homogeneous PermissionCollection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * For example, a Permissions object might have a FilePermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * for all the FilePermission objects, a SocketPermissionCollection for all the
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    66
 * SocketPermission objects, and so on. Its {@code add} method adds a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * permission to the appropriate collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <p>Whenever a permission is added to a heterogeneous PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * such as Permissions, and the PermissionCollection doesn't yet contain a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * PermissionCollection of the specified permission's type, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * PermissionCollection should call
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    73
 * the {@code newPermissionCollection} method on the permission's class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * to see if it requires a special PermissionCollection. If
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    75
 * {@code newPermissionCollection}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * returns null, the PermissionCollection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * is free to store the permission in any type of PermissionCollection it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * desires (one using a Hashtable, one using a Vector, etc.). For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * the Permissions object uses a default PermissionCollection implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * that stores the permission objects in a Hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <p> Subclass implementations of PermissionCollection should assume
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * that they may be called simultaneously from multiple threads,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * and therefore should be synchronized properly.  Furthermore,
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    85
 * Enumerations returned via the {@code elements} method are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * not <em>fail-fast</em>.  Modifications to a collection should not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * performed while enumerating over that collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @see Permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @see Permissions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * @author Roland Schemers
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 35302
diff changeset
    94
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
public abstract class PermissionCollection implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47216
diff changeset
    99
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static final long serialVersionUID = -6727011328946861783L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // when set, add will throw an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private volatile boolean readOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Adds a permission object to the current collection of permission objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param permission the Permission object to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
58659
4113f16d5109 8231859: Extra dash after the exception name in @throws clause of javadoc
igerasim
parents: 58242
diff changeset
   110
     * @throws    SecurityException    if this PermissionCollection object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *                                 has been marked readonly
58659
4113f16d5109 8231859: Extra dash after the exception name in @throws clause of javadoc
igerasim
parents: 58242
diff changeset
   112
     * @throws    IllegalArgumentException   if this PermissionCollection
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *                object is a homogeneous collection and the permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *                is not of the correct type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public abstract void add(Permission permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Checks to see if the specified permission is implied by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * the collection of Permission objects held in this PermissionCollection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param permission the Permission object to compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @return true if "permission" is implied by the  permissions in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * the collection, false if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public abstract boolean implies(Permission permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Returns an enumeration of all the Permission objects in the collection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @return an enumeration of all the Permissions.
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   133
     * @see #elementsAsStream()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public abstract Enumeration<Permission> elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   138
     * Returns a stream of all the Permission objects in the collection.
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   139
     *
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   140
     * <p> The collection should not be modified (see {@link #add}) during the
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   141
     * execution of the terminal stream operation. Otherwise, the result of the
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   142
     * terminal stream operation is undefined.
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   143
     *
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   144
     * @implSpec
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   145
     * The default implementation creates a stream whose source is derived from
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   146
     * the enumeration returned from a call to {@link #elements()}.
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   147
     *
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   148
     * @return a stream of all the Permissions.
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 31469
diff changeset
   149
     * @since 9
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   150
     */
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   151
    public Stream<Permission> elementsAsStream() {
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   152
        int characteristics = isReadOnly()
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   153
                ? Spliterator.NONNULL | Spliterator.IMMUTABLE
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   154
                : Spliterator.NONNULL;
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   155
        return StreamSupport.stream(
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   156
                Spliterators.spliteratorUnknownSize(
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   157
                        elements().asIterator(), characteristics),
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   158
                false);
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   159
    }
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   160
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 25859
diff changeset
   161
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Marks this PermissionCollection object as "readonly". After
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * a PermissionCollection object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * is marked as readonly, no new Permission objects can be added to it
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   165
     * using {@code add}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public void setReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        readOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Returns true if this PermissionCollection object is marked as readonly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * If it is readonly, no new Permission objects can be added to it
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   174
     * using {@code add}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * <p>By default, the object is <i>not</i> readonly. It can be set to
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   177
     * readonly by a call to {@code setReadOnly}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @return true if this PermissionCollection object is marked as readonly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return readOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Returns a string describing this PermissionCollection object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * providing information about all the permissions it contains.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * The format is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * super.toString() (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *   // enumerate all the Permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *   // objects and call toString() on them,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *   // one per line..
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * )</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   197
     * {@code super.toString} is a call to the {@code toString}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * method of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * object's superclass, which is Object. The result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * this PermissionCollection's type name followed by this object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * hashcode, thus enabling clients to differentiate different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * PermissionCollections object, even if they contain the same permissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @return information about this PermissionCollection object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *         as described above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        Enumeration<Permission> enum_ = elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        sb.append(super.toString()+" (\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        while (enum_.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                sb.append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                sb.append(enum_.nextElement().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                sb.append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            } catch (NoSuchElementException e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        sb.append(")\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
}