< prev index next >

## src/java.base/share/classes/java/security/PermissionCollection.java

Print this page

      1 /*
      2  * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
      3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
      4  *
      5  * This code is free software; you can redistribute it and/or modify it
      6  * under the terms of the GNU General Public License version 2 only, as
      7  * published by the Free Software Foundation.  Oracle designates this
      8  * particular file as subject to the "Classpath" exception as provided
      9  * by Oracle in the LICENSE file that accompanied this code.
     10  *
     11  * This code is distributed in the hope that it will be useful, but WITHOUT
     12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14  * version 2 for more details (a copy is included in the LICENSE file that
     15  * accompanied this code).
     16  *
     17  * You should have received a copy of the GNU General Public License version
     18  * 2 along with this work; if not, write to the Free Software Foundation,
     19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     20  *
     21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     22  * or visit www.oracle.com if you need additional information or have any
     82  * <p> Subclass implementations of PermissionCollection should assume
     83  * that they may be called simultaneously from multiple threads,
     84  * and therefore should be synchronized properly.  Furthermore,
     85  * Enumerations returned via the {@code elements} method are
     86  * not <em>fail-fast</em>.  Modifications to a collection should not be
     87  * performed while enumerating over that collection.
     88  *
     89  * @see Permission
     90  * @see Permissions
     91  *
     92  *
     93  * @author Roland Schemers
     94  * @since 1.2
     95  */
     96
     97 public abstract class PermissionCollection implements java.io.Serializable {
     98
     99     @java.io.Serial
    100     private static final long serialVersionUID = -6727011328946861783L;
    101
    102     // when set, add will throw an exception.

    103     private volatile boolean readOnly;
    104
    105     /**
    106      * Constructor for subclasses to call.
    107      */
    108     public PermissionCollection() {}
    109
    110     /**
    111      * Adds a permission object to the current collection of permission objects.
    112      *
    113      * @param permission the Permission object to add.
    114      *
    115      * @throws    SecurityException    if this PermissionCollection object
    116      *                                 has been marked readonly
    117      * @throws    IllegalArgumentException   if this PermissionCollection
    118      *                object is a homogeneous collection and the permission
    119      *                is not of the correct type.
    120      */
    121     public abstract void add(Permission permission);
    122
      1 /*
      2  * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
      3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
      4  *
      5  * This code is free software; you can redistribute it and/or modify it
      6  * under the terms of the GNU General Public License version 2 only, as
      7  * published by the Free Software Foundation.  Oracle designates this
      8  * particular file as subject to the "Classpath" exception as provided
      9  * by Oracle in the LICENSE file that accompanied this code.
     10  *
     11  * This code is distributed in the hope that it will be useful, but WITHOUT
     12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14  * version 2 for more details (a copy is included in the LICENSE file that
     15  * accompanied this code).
     16  *
     17  * You should have received a copy of the GNU General Public License version
     18  * 2 along with this work; if not, write to the Free Software Foundation,
     19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     20  *
     21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     22  * or visit www.oracle.com if you need additional information or have any
     82  * <p> Subclass implementations of PermissionCollection should assume
     83  * that they may be called simultaneously from multiple threads,
     84  * and therefore should be synchronized properly.  Furthermore,
     85  * Enumerations returned via the {@code elements} method are
     86  * not <em>fail-fast</em>.  Modifications to a collection should not be
     87  * performed while enumerating over that collection.
     88  *
     89  * @see Permission
     90  * @see Permissions
     91  *
     92  *
     93  * @author Roland Schemers
     94  * @since 1.2
     95  */
     96
     97 public abstract class PermissionCollection implements java.io.Serializable {
     98
     99     @java.io.Serial
    100     private static final long serialVersionUID = -6727011328946861783L;
    101
    102     /**
    103      * Whether this permission collection is read-only.
    104      * <p>
    105      * If set, the {@code add} method will throw an exception.
    106      */
    107     private volatile boolean readOnly;
    108
    109     /**
    110      * Constructor for subclasses to call.
    111      */
    112     public PermissionCollection() {}
    113
    114     /**
    115      * Adds a permission object to the current collection of permission objects.
    116      *
    117      * @param permission the Permission object to add.
    118      *
    119      * @throws    SecurityException    if this PermissionCollection object
    120      *                                 has been marked readonly
    121      * @throws    IllegalArgumentException   if this PermissionCollection
    122      *                object is a homogeneous collection and the permission
    123      *                is not of the correct type.
    124      */
    125     public abstract void add(Permission permission);
    126

< prev index next >