Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2012, 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.api.policy.subject; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import javax.xml.namespace.QName; |
aoqi@0 | 29 | |
aoqi@0 | 30 | import com.sun.istack.internal.logging.Logger; |
aoqi@0 | 31 | import com.sun.xml.internal.ws.resources.BindingApiMessages; |
aoqi@0 | 32 | |
aoqi@0 | 33 | /** |
aoqi@0 | 34 | * Experimental: This class identifies WSDL scopes. That allows to attach and |
aoqi@0 | 35 | * retrieve elements to and from WSDL scopes. |
aoqi@0 | 36 | * |
aoqi@0 | 37 | * @author Fabian Ritzmann |
aoqi@0 | 38 | */ |
aoqi@0 | 39 | public class BindingSubject { |
aoqi@0 | 40 | |
aoqi@0 | 41 | /** |
aoqi@0 | 42 | * For message subjects, this needs to be set to one of the values INPUT, OUTPUT |
aoqi@0 | 43 | * or FAULT. Any other subject has the message type NO_MESSAGE. |
aoqi@0 | 44 | */ |
aoqi@0 | 45 | private enum WsdlMessageType { |
aoqi@0 | 46 | NO_MESSAGE, |
aoqi@0 | 47 | INPUT, |
aoqi@0 | 48 | OUTPUT, |
aoqi@0 | 49 | FAULT |
aoqi@0 | 50 | } |
aoqi@0 | 51 | |
aoqi@0 | 52 | /** |
aoqi@0 | 53 | * Identifies the scope to which this subject belongs. See WS-PolicyAttachment |
aoqi@0 | 54 | * for an explanation on WSDL scopes. |
aoqi@0 | 55 | * |
aoqi@0 | 56 | * The SERVICE scope is not actually used and only listed here for completeness |
aoqi@0 | 57 | * sake. |
aoqi@0 | 58 | */ |
aoqi@0 | 59 | private enum WsdlNameScope { |
aoqi@0 | 60 | SERVICE, |
aoqi@0 | 61 | ENDPOINT, |
aoqi@0 | 62 | OPERATION, |
aoqi@0 | 63 | MESSAGE |
aoqi@0 | 64 | } |
aoqi@0 | 65 | |
aoqi@0 | 66 | private static final Logger LOGGER = Logger.getLogger(BindingSubject.class); |
aoqi@0 | 67 | |
aoqi@0 | 68 | private final QName name; |
aoqi@0 | 69 | private final WsdlMessageType messageType; |
aoqi@0 | 70 | private final WsdlNameScope nameScope; |
aoqi@0 | 71 | private final BindingSubject parent; |
aoqi@0 | 72 | |
aoqi@0 | 73 | BindingSubject(final QName name, final WsdlNameScope scope, final BindingSubject parent) { |
aoqi@0 | 74 | this(name, WsdlMessageType.NO_MESSAGE, scope, parent); |
aoqi@0 | 75 | } |
aoqi@0 | 76 | |
aoqi@0 | 77 | BindingSubject(final QName name, final WsdlMessageType messageType, final WsdlNameScope scope, final BindingSubject parent) { |
aoqi@0 | 78 | this.name = name; |
aoqi@0 | 79 | this.messageType = messageType; |
aoqi@0 | 80 | this.nameScope = scope; |
aoqi@0 | 81 | this.parent = parent; |
aoqi@0 | 82 | } |
aoqi@0 | 83 | |
aoqi@0 | 84 | public static BindingSubject createBindingSubject(QName bindingName) { |
aoqi@0 | 85 | return new BindingSubject(bindingName, WsdlNameScope.ENDPOINT, null); |
aoqi@0 | 86 | } |
aoqi@0 | 87 | |
aoqi@0 | 88 | public static BindingSubject createOperationSubject(QName bindingName, QName operationName) { |
aoqi@0 | 89 | final BindingSubject bindingSubject = createBindingSubject(bindingName); |
aoqi@0 | 90 | return new BindingSubject(operationName, WsdlNameScope.OPERATION, bindingSubject); |
aoqi@0 | 91 | } |
aoqi@0 | 92 | |
aoqi@0 | 93 | public static BindingSubject createInputMessageSubject(QName bindingName, QName operationName, QName messageName) { |
aoqi@0 | 94 | final BindingSubject operationSubject = createOperationSubject(bindingName, operationName); |
aoqi@0 | 95 | return new BindingSubject(messageName, WsdlMessageType.INPUT, WsdlNameScope.MESSAGE, operationSubject); |
aoqi@0 | 96 | } |
aoqi@0 | 97 | |
aoqi@0 | 98 | public static BindingSubject createOutputMessageSubject(QName bindingName, QName operationName, QName messageName) { |
aoqi@0 | 99 | final BindingSubject operationSubject = createOperationSubject(bindingName, operationName); |
aoqi@0 | 100 | return new BindingSubject(messageName, WsdlMessageType.OUTPUT, WsdlNameScope.MESSAGE, operationSubject); |
aoqi@0 | 101 | } |
aoqi@0 | 102 | |
aoqi@0 | 103 | public static BindingSubject createFaultMessageSubject(QName bindingName, QName operationName, QName messageName) { |
aoqi@0 | 104 | if (messageName == null) { |
aoqi@0 | 105 | throw LOGGER.logSevereException(new IllegalArgumentException(BindingApiMessages.BINDING_API_NO_FAULT_MESSAGE_NAME())); |
aoqi@0 | 106 | } |
aoqi@0 | 107 | final BindingSubject operationSubject = createOperationSubject(bindingName, operationName); |
aoqi@0 | 108 | return new BindingSubject(messageName, WsdlMessageType.FAULT, WsdlNameScope.MESSAGE, operationSubject); |
aoqi@0 | 109 | } |
aoqi@0 | 110 | |
aoqi@0 | 111 | public QName getName() { |
aoqi@0 | 112 | return this.name; |
aoqi@0 | 113 | } |
aoqi@0 | 114 | |
aoqi@0 | 115 | public BindingSubject getParent() { |
aoqi@0 | 116 | return this.parent; |
aoqi@0 | 117 | } |
aoqi@0 | 118 | |
aoqi@0 | 119 | public boolean isBindingSubject() { |
aoqi@0 | 120 | if (this.nameScope == WsdlNameScope.ENDPOINT) { |
aoqi@0 | 121 | return this.parent == null; |
aoqi@0 | 122 | } |
aoqi@0 | 123 | else { |
aoqi@0 | 124 | return false; |
aoqi@0 | 125 | } |
aoqi@0 | 126 | } |
aoqi@0 | 127 | |
aoqi@0 | 128 | public boolean isOperationSubject() { |
aoqi@0 | 129 | if (this.nameScope == WsdlNameScope.OPERATION) { |
aoqi@0 | 130 | if (this.parent != null) { |
aoqi@0 | 131 | return this.parent.isBindingSubject(); |
aoqi@0 | 132 | } |
aoqi@0 | 133 | } |
aoqi@0 | 134 | return false; |
aoqi@0 | 135 | } |
aoqi@0 | 136 | |
aoqi@0 | 137 | public boolean isMessageSubject() { |
aoqi@0 | 138 | if (this.nameScope == WsdlNameScope.MESSAGE) { |
aoqi@0 | 139 | if (this.parent != null) { |
aoqi@0 | 140 | return this.parent.isOperationSubject(); |
aoqi@0 | 141 | } |
aoqi@0 | 142 | } |
aoqi@0 | 143 | return false; |
aoqi@0 | 144 | } |
aoqi@0 | 145 | |
aoqi@0 | 146 | public boolean isInputMessageSubject() { |
aoqi@0 | 147 | return isMessageSubject() && (this.messageType == WsdlMessageType.INPUT); |
aoqi@0 | 148 | } |
aoqi@0 | 149 | |
aoqi@0 | 150 | public boolean isOutputMessageSubject() { |
aoqi@0 | 151 | return isMessageSubject() && (this.messageType == WsdlMessageType.OUTPUT); |
aoqi@0 | 152 | } |
aoqi@0 | 153 | |
aoqi@0 | 154 | public boolean isFaultMessageSubject() { |
aoqi@0 | 155 | return isMessageSubject() && (this.messageType == WsdlMessageType.FAULT); |
aoqi@0 | 156 | } |
aoqi@0 | 157 | |
aoqi@0 | 158 | @Override |
aoqi@0 | 159 | public boolean equals(final Object that) { |
aoqi@0 | 160 | if (this == that) { |
aoqi@0 | 161 | return true; |
aoqi@0 | 162 | } |
aoqi@0 | 163 | |
aoqi@0 | 164 | if (that == null || !(that instanceof BindingSubject)) { |
aoqi@0 | 165 | return false; |
aoqi@0 | 166 | } |
aoqi@0 | 167 | |
aoqi@0 | 168 | final BindingSubject thatSubject = (BindingSubject) that; |
aoqi@0 | 169 | boolean isEqual = true; |
aoqi@0 | 170 | |
aoqi@0 | 171 | isEqual = isEqual && ((this.name == null) ? thatSubject.name == null : this.name.equals(thatSubject.name)); |
aoqi@0 | 172 | isEqual = isEqual && this.messageType.equals(thatSubject.messageType); |
aoqi@0 | 173 | isEqual = isEqual && this.nameScope.equals(thatSubject.nameScope); |
aoqi@0 | 174 | isEqual = isEqual && ((this.parent == null) ? thatSubject.parent == null : this.parent.equals(thatSubject.parent)); |
aoqi@0 | 175 | |
aoqi@0 | 176 | return isEqual; |
aoqi@0 | 177 | } |
aoqi@0 | 178 | |
aoqi@0 | 179 | @Override |
aoqi@0 | 180 | public int hashCode() { |
aoqi@0 | 181 | int result = 23; |
aoqi@0 | 182 | |
aoqi@0 | 183 | result = 29 * result + ((this.name == null) ? 0 : this.name.hashCode()); |
aoqi@0 | 184 | result = 29 * result + this.messageType.hashCode(); |
aoqi@0 | 185 | result = 29 * result + this.nameScope.hashCode(); |
aoqi@0 | 186 | result = 29 * result + ((this.parent == null) ? 0 : this.parent.hashCode()); |
aoqi@0 | 187 | |
aoqi@0 | 188 | return result; |
aoqi@0 | 189 | } |
aoqi@0 | 190 | |
aoqi@0 | 191 | @Override |
aoqi@0 | 192 | public String toString() { |
aoqi@0 | 193 | final StringBuilder result = new StringBuilder("BindingSubject["); |
aoqi@0 | 194 | result.append(this.name).append(", ").append(this.messageType); |
aoqi@0 | 195 | result.append(", ").append(this.nameScope).append(", ").append(this.parent); |
aoqi@0 | 196 | return result.append("]").toString(); |
aoqi@0 | 197 | } |
aoqi@0 | 198 | |
aoqi@0 | 199 | } |