Thu, 12 Oct 2017 19:44:07 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.ws.policy.subject; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages; |
aoqi@0 | 29 | import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger; |
aoqi@0 | 30 | import javax.xml.namespace.QName; |
aoqi@0 | 31 | |
aoqi@0 | 32 | /** |
aoqi@0 | 33 | * Provides objects for use as WSDL 1.0/1.1 policy subjects. |
aoqi@0 | 34 | * |
aoqi@0 | 35 | * An instance of this class may represent a wsdl:binding element or a wsdl:binding/operation |
aoqi@0 | 36 | * element or a wsdl:binding/operation/message element. |
aoqi@0 | 37 | * |
aoqi@0 | 38 | * @author Fabian Ritzmann |
aoqi@0 | 39 | */ |
aoqi@0 | 40 | public class WsdlBindingSubject { |
aoqi@0 | 41 | |
aoqi@0 | 42 | /** |
aoqi@0 | 43 | * For message subjects, this needs to be set to one of the values INPUT, OUTPUT |
aoqi@0 | 44 | * or FAULT. Any other subject has the message type NO_MESSAGE. |
aoqi@0 | 45 | */ |
aoqi@0 | 46 | public enum WsdlMessageType { |
aoqi@0 | 47 | NO_MESSAGE, |
aoqi@0 | 48 | INPUT, |
aoqi@0 | 49 | OUTPUT, |
aoqi@0 | 50 | FAULT |
aoqi@0 | 51 | } |
aoqi@0 | 52 | |
aoqi@0 | 53 | /** |
aoqi@0 | 54 | * Identifies the scope to which this subject belongs. See WS-PolicyAttachment |
aoqi@0 | 55 | * for an explanation on WSDL scopes. |
aoqi@0 | 56 | * |
aoqi@0 | 57 | * The SERVICE scope is not actually used and only listed here for completeness |
aoqi@0 | 58 | * sake. |
aoqi@0 | 59 | */ |
aoqi@0 | 60 | public enum WsdlNameScope { |
aoqi@0 | 61 | SERVICE, |
aoqi@0 | 62 | ENDPOINT, |
aoqi@0 | 63 | OPERATION, |
aoqi@0 | 64 | MESSAGE |
aoqi@0 | 65 | } |
aoqi@0 | 66 | |
aoqi@0 | 67 | private static final PolicyLogger LOGGER = PolicyLogger.getLogger(WsdlBindingSubject.class); |
aoqi@0 | 68 | |
aoqi@0 | 69 | private final QName name; |
aoqi@0 | 70 | private final WsdlMessageType messageType; |
aoqi@0 | 71 | private final WsdlNameScope nameScope; |
aoqi@0 | 72 | private final WsdlBindingSubject parent; |
aoqi@0 | 73 | |
aoqi@0 | 74 | WsdlBindingSubject(final QName name, final WsdlNameScope scope, final WsdlBindingSubject parent) { |
aoqi@0 | 75 | this(name, WsdlMessageType.NO_MESSAGE, scope, parent); |
aoqi@0 | 76 | } |
aoqi@0 | 77 | |
aoqi@0 | 78 | WsdlBindingSubject(final QName name, final WsdlMessageType messageType, final WsdlNameScope scope, final WsdlBindingSubject parent) { |
aoqi@0 | 79 | this.name = name; |
aoqi@0 | 80 | this.messageType = messageType; |
aoqi@0 | 81 | this.nameScope = scope; |
aoqi@0 | 82 | this.parent = parent; |
aoqi@0 | 83 | } |
aoqi@0 | 84 | |
aoqi@0 | 85 | public static WsdlBindingSubject createBindingSubject(QName bindingName) { |
aoqi@0 | 86 | return new WsdlBindingSubject(bindingName, WsdlNameScope.ENDPOINT, null); |
aoqi@0 | 87 | } |
aoqi@0 | 88 | |
aoqi@0 | 89 | public static WsdlBindingSubject createBindingOperationSubject(QName bindingName, QName operationName) { |
aoqi@0 | 90 | final WsdlBindingSubject bindingSubject = createBindingSubject(bindingName); |
aoqi@0 | 91 | return new WsdlBindingSubject(operationName, WsdlNameScope.OPERATION, bindingSubject); |
aoqi@0 | 92 | } |
aoqi@0 | 93 | |
aoqi@0 | 94 | public static WsdlBindingSubject createBindingMessageSubject(QName bindingName, QName operationName, QName messageName, WsdlMessageType messageType) { |
aoqi@0 | 95 | if (messageType == null) { |
aoqi@0 | 96 | throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0083_MESSAGE_TYPE_NULL())); |
aoqi@0 | 97 | } |
aoqi@0 | 98 | if (messageType == WsdlMessageType.NO_MESSAGE) { |
aoqi@0 | 99 | throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0084_MESSAGE_TYPE_NO_MESSAGE())); |
aoqi@0 | 100 | } |
aoqi@0 | 101 | if ((messageType == WsdlMessageType.FAULT) && (messageName == null)) { |
aoqi@0 | 102 | throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0085_MESSAGE_FAULT_NO_NAME())); |
aoqi@0 | 103 | } |
aoqi@0 | 104 | final WsdlBindingSubject operationSubject = createBindingOperationSubject(bindingName, operationName); |
aoqi@0 | 105 | return new WsdlBindingSubject(messageName, messageType, WsdlNameScope.MESSAGE, operationSubject); |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | public QName getName() { |
aoqi@0 | 109 | return this.name; |
aoqi@0 | 110 | } |
aoqi@0 | 111 | |
aoqi@0 | 112 | public WsdlMessageType getMessageType() { |
aoqi@0 | 113 | return this.messageType; |
aoqi@0 | 114 | } |
aoqi@0 | 115 | |
aoqi@0 | 116 | public WsdlBindingSubject getParent() { |
aoqi@0 | 117 | return this.parent; |
aoqi@0 | 118 | } |
aoqi@0 | 119 | |
aoqi@0 | 120 | public boolean isBindingSubject() { |
aoqi@0 | 121 | if (this.nameScope == WsdlNameScope.ENDPOINT) { |
aoqi@0 | 122 | return this.parent == null; |
aoqi@0 | 123 | } |
aoqi@0 | 124 | else { |
aoqi@0 | 125 | return false; |
aoqi@0 | 126 | } |
aoqi@0 | 127 | } |
aoqi@0 | 128 | |
aoqi@0 | 129 | public boolean isBindingOperationSubject() { |
aoqi@0 | 130 | if (this.nameScope == WsdlNameScope.OPERATION) { |
aoqi@0 | 131 | if (this.parent != null) { |
aoqi@0 | 132 | return this.parent.isBindingSubject(); |
aoqi@0 | 133 | } |
aoqi@0 | 134 | } |
aoqi@0 | 135 | return false; |
aoqi@0 | 136 | } |
aoqi@0 | 137 | |
aoqi@0 | 138 | public boolean isBindingMessageSubject() { |
aoqi@0 | 139 | if (this.nameScope == WsdlNameScope.MESSAGE) { |
aoqi@0 | 140 | if (this.parent != null) { |
aoqi@0 | 141 | return this.parent.isBindingOperationSubject(); |
aoqi@0 | 142 | } |
aoqi@0 | 143 | } |
aoqi@0 | 144 | return false; |
aoqi@0 | 145 | } |
aoqi@0 | 146 | |
aoqi@0 | 147 | @Override |
aoqi@0 | 148 | public boolean equals(final Object that) { |
aoqi@0 | 149 | if (this == that) { |
aoqi@0 | 150 | return true; |
aoqi@0 | 151 | } |
aoqi@0 | 152 | |
aoqi@0 | 153 | if (that == null || !(that instanceof WsdlBindingSubject)) { |
aoqi@0 | 154 | return false; |
aoqi@0 | 155 | } |
aoqi@0 | 156 | |
aoqi@0 | 157 | final WsdlBindingSubject thatSubject = (WsdlBindingSubject) that; |
aoqi@0 | 158 | boolean isEqual = true; |
aoqi@0 | 159 | |
aoqi@0 | 160 | isEqual = isEqual && ((this.name == null) ? thatSubject.name == null : this.name.equals(thatSubject.name)); |
aoqi@0 | 161 | isEqual = isEqual && this.messageType.equals(thatSubject.messageType); |
aoqi@0 | 162 | isEqual = isEqual && this.nameScope.equals(thatSubject.nameScope); |
aoqi@0 | 163 | isEqual = isEqual && ((this.parent == null) ? thatSubject.parent == null : this.parent.equals(thatSubject.parent)); |
aoqi@0 | 164 | |
aoqi@0 | 165 | return isEqual; |
aoqi@0 | 166 | } |
aoqi@0 | 167 | |
aoqi@0 | 168 | @Override |
aoqi@0 | 169 | public int hashCode() { |
aoqi@0 | 170 | int result = 23; |
aoqi@0 | 171 | |
aoqi@0 | 172 | result = 31 * result + ((this.name == null) ? 0 : this.name.hashCode()); |
aoqi@0 | 173 | result = 31 * result + this.messageType.hashCode(); |
aoqi@0 | 174 | result = 31 * result + this.nameScope.hashCode(); |
aoqi@0 | 175 | result = 31 * result + ((this.parent == null) ? 0 : this.parent.hashCode()); |
aoqi@0 | 176 | |
aoqi@0 | 177 | return result; |
aoqi@0 | 178 | } |
aoqi@0 | 179 | |
aoqi@0 | 180 | @Override |
aoqi@0 | 181 | public String toString() { |
aoqi@0 | 182 | final StringBuilder result = new StringBuilder("WsdlBindingSubject["); |
aoqi@0 | 183 | result.append(this.name).append(", ").append(this.messageType); |
aoqi@0 | 184 | result.append(", ").append(this.nameScope).append(", ").append(this.parent); |
aoqi@0 | 185 | return result.append("]").toString(); |
aoqi@0 | 186 | } |
aoqi@0 | 187 | |
aoqi@0 | 188 | } |