author | mkos |
Sun, 30 Dec 2012 00:00:00 +0100 | |
changeset 22678 | ac1ea46be942 |
parent 12009 | 4abb694f273a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22678
ac1ea46be942
8029237: Update copyright year to match last edit in jaxws repository for 2012
mkos
parents:
12009
diff
changeset
|
2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
12009 | 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 |
*/ |
|
25 |
||
26 |
package com.sun.xml.internal.ws.policy; |
|
27 |
||
28 |
import java.util.Arrays; |
|
29 |
import java.util.Iterator; |
|
30 |
||
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"; |
|
38 |
||
39 |
private NestedPolicy(final AssertionSet set) { |
|
40 |
super(NESTED_POLICY_TOSTRING_NAME, Arrays.asList(new AssertionSet[] { set })); |
|
41 |
} |
|
42 |
||
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 |
} |
|
46 |
||
47 |
static NestedPolicy createNestedPolicy(final AssertionSet set) { |
|
48 |
return new NestedPolicy(set); |
|
49 |
} |
|
50 |
||
51 |
static NestedPolicy createNestedPolicy(final String name, final String policyId, final AssertionSet set) { |
|
52 |
return new NestedPolicy(name, policyId, set); |
|
53 |
} |
|
54 |
||
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 |
} |
|
70 |
||
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 |
} |
|
79 |
||
80 |
if (!(obj instanceof NestedPolicy)) { |
|
81 |
return false; |
|
82 |
} |
|
83 |
||
84 |
final NestedPolicy that = (NestedPolicy) obj; |
|
85 |
||
86 |
return super.equals(that); |
|
87 |
} |
|
88 |
||
89 |
@Override |
|
90 |
public int hashCode() { |
|
91 |
return super.hashCode(); |
|
92 |
} |
|
93 |
||
94 |
/** |
|
95 |
* An {@code Object.toString()} method override. |
|
96 |
*/ |
|
97 |
@Override |
|
98 |
public String toString() { |
|
99 |
return toString(0, new StringBuffer()).toString(); |
|
100 |
} |
|
101 |
||
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 |
} |