1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/policy/subject/WsdlBindingSubject.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,188 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.policy.subject; 1.30 + 1.31 +import com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages; 1.32 +import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger; 1.33 +import javax.xml.namespace.QName; 1.34 + 1.35 +/** 1.36 + * Provides objects for use as WSDL 1.0/1.1 policy subjects. 1.37 + * 1.38 + * An instance of this class may represent a wsdl:binding element or a wsdl:binding/operation 1.39 + * element or a wsdl:binding/operation/message element. 1.40 + * 1.41 + * @author Fabian Ritzmann 1.42 + */ 1.43 +public class WsdlBindingSubject { 1.44 + 1.45 + /** 1.46 + * For message subjects, this needs to be set to one of the values INPUT, OUTPUT 1.47 + * or FAULT. Any other subject has the message type NO_MESSAGE. 1.48 + */ 1.49 + public enum WsdlMessageType { 1.50 + NO_MESSAGE, 1.51 + INPUT, 1.52 + OUTPUT, 1.53 + FAULT 1.54 + } 1.55 + 1.56 + /** 1.57 + * Identifies the scope to which this subject belongs. See WS-PolicyAttachment 1.58 + * for an explanation on WSDL scopes. 1.59 + * 1.60 + * The SERVICE scope is not actually used and only listed here for completeness 1.61 + * sake. 1.62 + */ 1.63 + public enum WsdlNameScope { 1.64 + SERVICE, 1.65 + ENDPOINT, 1.66 + OPERATION, 1.67 + MESSAGE 1.68 + } 1.69 + 1.70 + private static final PolicyLogger LOGGER = PolicyLogger.getLogger(WsdlBindingSubject.class); 1.71 + 1.72 + private final QName name; 1.73 + private final WsdlMessageType messageType; 1.74 + private final WsdlNameScope nameScope; 1.75 + private final WsdlBindingSubject parent; 1.76 + 1.77 + WsdlBindingSubject(final QName name, final WsdlNameScope scope, final WsdlBindingSubject parent) { 1.78 + this(name, WsdlMessageType.NO_MESSAGE, scope, parent); 1.79 + } 1.80 + 1.81 + WsdlBindingSubject(final QName name, final WsdlMessageType messageType, final WsdlNameScope scope, final WsdlBindingSubject parent) { 1.82 + this.name = name; 1.83 + this.messageType = messageType; 1.84 + this.nameScope = scope; 1.85 + this.parent = parent; 1.86 + } 1.87 + 1.88 + public static WsdlBindingSubject createBindingSubject(QName bindingName) { 1.89 + return new WsdlBindingSubject(bindingName, WsdlNameScope.ENDPOINT, null); 1.90 + } 1.91 + 1.92 + public static WsdlBindingSubject createBindingOperationSubject(QName bindingName, QName operationName) { 1.93 + final WsdlBindingSubject bindingSubject = createBindingSubject(bindingName); 1.94 + return new WsdlBindingSubject(operationName, WsdlNameScope.OPERATION, bindingSubject); 1.95 + } 1.96 + 1.97 + public static WsdlBindingSubject createBindingMessageSubject(QName bindingName, QName operationName, QName messageName, WsdlMessageType messageType) { 1.98 + if (messageType == null) { 1.99 + throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0083_MESSAGE_TYPE_NULL())); 1.100 + } 1.101 + if (messageType == WsdlMessageType.NO_MESSAGE) { 1.102 + throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0084_MESSAGE_TYPE_NO_MESSAGE())); 1.103 + } 1.104 + if ((messageType == WsdlMessageType.FAULT) && (messageName == null)) { 1.105 + throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0085_MESSAGE_FAULT_NO_NAME())); 1.106 + } 1.107 + final WsdlBindingSubject operationSubject = createBindingOperationSubject(bindingName, operationName); 1.108 + return new WsdlBindingSubject(messageName, messageType, WsdlNameScope.MESSAGE, operationSubject); 1.109 + } 1.110 + 1.111 + public QName getName() { 1.112 + return this.name; 1.113 + } 1.114 + 1.115 + public WsdlMessageType getMessageType() { 1.116 + return this.messageType; 1.117 + } 1.118 + 1.119 + public WsdlBindingSubject getParent() { 1.120 + return this.parent; 1.121 + } 1.122 + 1.123 + public boolean isBindingSubject() { 1.124 + if (this.nameScope == WsdlNameScope.ENDPOINT) { 1.125 + return this.parent == null; 1.126 + } 1.127 + else { 1.128 + return false; 1.129 + } 1.130 + } 1.131 + 1.132 + public boolean isBindingOperationSubject() { 1.133 + if (this.nameScope == WsdlNameScope.OPERATION) { 1.134 + if (this.parent != null) { 1.135 + return this.parent.isBindingSubject(); 1.136 + } 1.137 + } 1.138 + return false; 1.139 + } 1.140 + 1.141 + public boolean isBindingMessageSubject() { 1.142 + if (this.nameScope == WsdlNameScope.MESSAGE) { 1.143 + if (this.parent != null) { 1.144 + return this.parent.isBindingOperationSubject(); 1.145 + } 1.146 + } 1.147 + return false; 1.148 + } 1.149 + 1.150 + @Override 1.151 + public boolean equals(final Object that) { 1.152 + if (this == that) { 1.153 + return true; 1.154 + } 1.155 + 1.156 + if (that == null || !(that instanceof WsdlBindingSubject)) { 1.157 + return false; 1.158 + } 1.159 + 1.160 + final WsdlBindingSubject thatSubject = (WsdlBindingSubject) that; 1.161 + boolean isEqual = true; 1.162 + 1.163 + isEqual = isEqual && ((this.name == null) ? thatSubject.name == null : this.name.equals(thatSubject.name)); 1.164 + isEqual = isEqual && this.messageType.equals(thatSubject.messageType); 1.165 + isEqual = isEqual && this.nameScope.equals(thatSubject.nameScope); 1.166 + isEqual = isEqual && ((this.parent == null) ? thatSubject.parent == null : this.parent.equals(thatSubject.parent)); 1.167 + 1.168 + return isEqual; 1.169 + } 1.170 + 1.171 + @Override 1.172 + public int hashCode() { 1.173 + int result = 23; 1.174 + 1.175 + result = 31 * result + ((this.name == null) ? 0 : this.name.hashCode()); 1.176 + result = 31 * result + this.messageType.hashCode(); 1.177 + result = 31 * result + this.nameScope.hashCode(); 1.178 + result = 31 * result + ((this.parent == null) ? 0 : this.parent.hashCode()); 1.179 + 1.180 + return result; 1.181 + } 1.182 + 1.183 + @Override 1.184 + public String toString() { 1.185 + final StringBuilder result = new StringBuilder("WsdlBindingSubject["); 1.186 + result.append(this.name).append(", ").append(this.messageType); 1.187 + result.append(", ").append(this.nameScope).append(", ").append(this.parent); 1.188 + return result.append("]").toString(); 1.189 + } 1.190 + 1.191 +}