src/share/jaxws_classes/com/sun/xml/internal/ws/policy/NestedPolicy.java

Thu, 12 Oct 2017 19:44:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 19:44:07 +0800
changeset 760
e530533619ec
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2010, 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
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.policy;
    28 import java.util.Arrays;
    29 import java.util.Iterator;
    31 /**
    32  * A special policy implementation that assures that only no or single policy alternative is possible within this type of policy.
    33  *
    34  * @author Marek Potociar
    35  */
    36 public final class NestedPolicy extends Policy {
    37     private static final String NESTED_POLICY_TOSTRING_NAME = "nested policy";
    39     private NestedPolicy(final AssertionSet set) {
    40         super(NESTED_POLICY_TOSTRING_NAME, Arrays.asList(new AssertionSet[] { set }));
    41     }
    43     private NestedPolicy(final String name, final String policyId, final AssertionSet set) {
    44         super(NESTED_POLICY_TOSTRING_NAME, name, policyId, Arrays.asList(new AssertionSet[] { set }));
    45     }
    47     static NestedPolicy createNestedPolicy(final AssertionSet set) {
    48         return new NestedPolicy(set);
    49     }
    51     static NestedPolicy createNestedPolicy(final String name, final String policyId, final AssertionSet set) {
    52         return new NestedPolicy(name, policyId, set);
    53     }
    55     /**
    56      * Returns the AssertionSet instance representing a single policy alterantive held wihtin this nested policy object.
    57      * If the nested policy represents a policy with no alternatives (i.e. nothing is allowed) the method returns {@code null}.
    58      *
    59      * @return nested policy alternative represented by AssertionSet object. May return {@code null} in case the nested policy
    60      * represents 'nothing allowed' policy.
    61      */
    62     public AssertionSet getAssertionSet() {
    63         final Iterator<AssertionSet> iterator = iterator();
    64         if (iterator.hasNext()) {
    65             return iterator.next();
    66         } else {
    67             return null;
    68         }
    69     }
    71     /**
    72      * An {@code Object.equals(Object obj)} method override.
    73      */
    74     @Override
    75     public boolean equals(final Object obj) {
    76         if (this == obj) {
    77             return true;
    78         }
    80         if (!(obj instanceof NestedPolicy)) {
    81             return false;
    82         }
    84         final NestedPolicy that = (NestedPolicy) obj;
    86         return super.equals(that);
    87     }
    89     @Override
    90     public int hashCode() {
    91         return super.hashCode();
    92     }
    94     /**
    95      * An {@code Object.toString()} method override.
    96      */
    97     @Override
    98     public String toString() {
    99         return toString(0, new StringBuffer()).toString();
   100     }
   102     /**
   103      * A helper method that appends indented string representation of this instance to the input string buffer.
   104      *
   105      * @param indentLevel indentation level to be used.
   106      * @param buffer buffer to be used for appending string representation of this instance
   107      * @return modified buffer containing new string representation of the instance
   108      */
   109     @Override
   110     StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
   111         return super.toString(indentLevel, buffer);
   112     }
   113 }

mercurial