src/share/jaxws_classes/com/sun/xml/internal/ws/policy/subject/WsdlBindingSubject.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.subject;
    28 import com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages;
    29 import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
    30 import javax.xml.namespace.QName;
    32 /**
    33  * Provides objects for use as WSDL 1.0/1.1 policy subjects.
    34  *
    35  * An instance of this class may represent a wsdl:binding element or a wsdl:binding/operation
    36  * element or a wsdl:binding/operation/message element.
    37  *
    38  * @author Fabian Ritzmann
    39  */
    40 public class WsdlBindingSubject {
    42     /**
    43      * For message subjects, this needs to be set to one of the values INPUT, OUTPUT
    44      * or FAULT. Any other subject has the message type NO_MESSAGE.
    45      */
    46     public enum WsdlMessageType {
    47         NO_MESSAGE,
    48         INPUT,
    49         OUTPUT,
    50         FAULT
    51     }
    53     /**
    54      * Identifies the scope to which this subject belongs. See WS-PolicyAttachment
    55      * for an explanation on WSDL scopes.
    56      *
    57      * The SERVICE scope is not actually used and only listed here for completeness
    58      * sake.
    59      */
    60     public enum WsdlNameScope {
    61         SERVICE,
    62         ENDPOINT,
    63         OPERATION,
    64         MESSAGE
    65     }
    67     private static final PolicyLogger LOGGER = PolicyLogger.getLogger(WsdlBindingSubject.class);
    69     private final QName name;
    70     private final WsdlMessageType messageType;
    71     private final WsdlNameScope nameScope;
    72     private final WsdlBindingSubject parent;
    74     WsdlBindingSubject(final QName name, final WsdlNameScope scope, final WsdlBindingSubject parent) {
    75         this(name, WsdlMessageType.NO_MESSAGE, scope, parent);
    76     }
    78     WsdlBindingSubject(final QName name, final WsdlMessageType messageType, final WsdlNameScope scope, final WsdlBindingSubject parent) {
    79         this.name = name;
    80         this.messageType = messageType;
    81         this.nameScope = scope;
    82         this.parent = parent;
    83     }
    85     public static WsdlBindingSubject createBindingSubject(QName bindingName) {
    86         return new WsdlBindingSubject(bindingName, WsdlNameScope.ENDPOINT, null);
    87     }
    89     public static WsdlBindingSubject createBindingOperationSubject(QName bindingName, QName operationName) {
    90         final WsdlBindingSubject bindingSubject = createBindingSubject(bindingName);
    91         return new WsdlBindingSubject(operationName, WsdlNameScope.OPERATION, bindingSubject);
    92     }
    94     public static WsdlBindingSubject createBindingMessageSubject(QName bindingName, QName operationName, QName messageName, WsdlMessageType messageType) {
    95         if (messageType == null) {
    96             throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0083_MESSAGE_TYPE_NULL()));
    97         }
    98         if (messageType == WsdlMessageType.NO_MESSAGE) {
    99             throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0084_MESSAGE_TYPE_NO_MESSAGE()));
   100         }
   101         if ((messageType == WsdlMessageType.FAULT) && (messageName == null)) {
   102             throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0085_MESSAGE_FAULT_NO_NAME()));
   103         }
   104         final WsdlBindingSubject operationSubject = createBindingOperationSubject(bindingName, operationName);
   105         return new WsdlBindingSubject(messageName, messageType, WsdlNameScope.MESSAGE, operationSubject);
   106     }
   108     public QName getName() {
   109         return this.name;
   110     }
   112     public WsdlMessageType getMessageType() {
   113         return this.messageType;
   114     }
   116     public WsdlBindingSubject getParent() {
   117         return this.parent;
   118     }
   120     public boolean isBindingSubject() {
   121         if (this.nameScope == WsdlNameScope.ENDPOINT) {
   122             return this.parent == null;
   123         }
   124         else {
   125             return false;
   126         }
   127     }
   129     public boolean isBindingOperationSubject() {
   130         if (this.nameScope == WsdlNameScope.OPERATION) {
   131             if (this.parent != null) {
   132                 return this.parent.isBindingSubject();
   133             }
   134         }
   135         return false;
   136     }
   138     public boolean isBindingMessageSubject() {
   139         if (this.nameScope == WsdlNameScope.MESSAGE) {
   140             if (this.parent != null) {
   141                 return this.parent.isBindingOperationSubject();
   142             }
   143         }
   144         return false;
   145     }
   147     @Override
   148     public boolean equals(final Object that) {
   149         if (this == that) {
   150             return true;
   151         }
   153         if (that == null || !(that instanceof WsdlBindingSubject)) {
   154             return false;
   155         }
   157         final WsdlBindingSubject thatSubject = (WsdlBindingSubject) that;
   158         boolean isEqual = true;
   160         isEqual = isEqual && ((this.name == null) ? thatSubject.name == null : this.name.equals(thatSubject.name));
   161         isEqual = isEqual && this.messageType.equals(thatSubject.messageType);
   162         isEqual = isEqual && this.nameScope.equals(thatSubject.nameScope);
   163         isEqual = isEqual && ((this.parent == null) ? thatSubject.parent == null : this.parent.equals(thatSubject.parent));
   165         return isEqual;
   166     }
   168     @Override
   169     public int hashCode() {
   170         int result = 23;
   172         result = 31 * result + ((this.name == null) ? 0 : this.name.hashCode());
   173         result = 31 * result + this.messageType.hashCode();
   174         result = 31 * result + this.nameScope.hashCode();
   175         result = 31 * result + ((this.parent == null) ? 0 : this.parent.hashCode());
   177         return result;
   178     }
   180     @Override
   181     public String toString() {
   182         final StringBuilder result = new StringBuilder("WsdlBindingSubject[");
   183         result.append(this.name).append(", ").append(this.messageType);
   184         result.append(", ").append(this.nameScope).append(", ").append(this.parent);
   185         return result.append("]").toString();
   186     }
   188 }

mercurial