src/share/jaxws_classes/com/sun/xml/internal/ws/api/policy/subject/BindingSubject.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/policy/subject/BindingSubject.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,199 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2011, 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.api.policy.subject;
    1.30 +
    1.31 +import javax.xml.namespace.QName;
    1.32 +
    1.33 +import com.sun.istack.internal.logging.Logger;
    1.34 +import com.sun.xml.internal.ws.resources.BindingApiMessages;
    1.35 +
    1.36 +/**
    1.37 + * Experimental: This class identifies WSDL scopes. That allows to attach and
    1.38 + * retrieve elements to and from WSDL scopes.
    1.39 + *
    1.40 + * @author Fabian Ritzmann
    1.41 + */
    1.42 +public class BindingSubject {
    1.43 +
    1.44 +    /**
    1.45 +     * For message subjects, this needs to be set to one of the values INPUT, OUTPUT
    1.46 +     * or FAULT. Any other subject has the message type NO_MESSAGE.
    1.47 +     */
    1.48 +    private enum WsdlMessageType {
    1.49 +        NO_MESSAGE,
    1.50 +        INPUT,
    1.51 +        OUTPUT,
    1.52 +        FAULT
    1.53 +    }
    1.54 +
    1.55 +    /**
    1.56 +     * Identifies the scope to which this subject belongs. See WS-PolicyAttachment
    1.57 +     * for an explanation on WSDL scopes.
    1.58 +     *
    1.59 +     * The SERVICE scope is not actually used and only listed here for completeness
    1.60 +     * sake.
    1.61 +     */
    1.62 +    private enum WsdlNameScope {
    1.63 +        SERVICE,
    1.64 +        ENDPOINT,
    1.65 +        OPERATION,
    1.66 +        MESSAGE
    1.67 +    }
    1.68 +
    1.69 +    private static final Logger LOGGER = Logger.getLogger(BindingSubject.class);
    1.70 +
    1.71 +    private final QName name;
    1.72 +    private final WsdlMessageType messageType;
    1.73 +    private final WsdlNameScope nameScope;
    1.74 +    private final BindingSubject parent;
    1.75 +
    1.76 +    BindingSubject(final QName name, final WsdlNameScope scope, final BindingSubject parent) {
    1.77 +        this(name, WsdlMessageType.NO_MESSAGE, scope, parent);
    1.78 +    }
    1.79 +
    1.80 +    BindingSubject(final QName name, final WsdlMessageType messageType, final WsdlNameScope scope, final BindingSubject parent) {
    1.81 +        this.name = name;
    1.82 +        this.messageType = messageType;
    1.83 +        this.nameScope = scope;
    1.84 +        this.parent = parent;
    1.85 +    }
    1.86 +
    1.87 +    public static BindingSubject createBindingSubject(QName bindingName) {
    1.88 +        return new BindingSubject(bindingName, WsdlNameScope.ENDPOINT, null);
    1.89 +    }
    1.90 +
    1.91 +    public static BindingSubject createOperationSubject(QName bindingName, QName operationName) {
    1.92 +        final BindingSubject bindingSubject = createBindingSubject(bindingName);
    1.93 +        return new BindingSubject(operationName, WsdlNameScope.OPERATION, bindingSubject);
    1.94 +    }
    1.95 +
    1.96 +    public static BindingSubject createInputMessageSubject(QName bindingName, QName operationName, QName messageName) {
    1.97 +        final BindingSubject operationSubject = createOperationSubject(bindingName, operationName);
    1.98 +        return new BindingSubject(messageName, WsdlMessageType.INPUT, WsdlNameScope.MESSAGE, operationSubject);
    1.99 +    }
   1.100 +
   1.101 +    public static BindingSubject createOutputMessageSubject(QName bindingName, QName operationName, QName messageName) {
   1.102 +        final BindingSubject operationSubject = createOperationSubject(bindingName, operationName);
   1.103 +        return new BindingSubject(messageName, WsdlMessageType.OUTPUT, WsdlNameScope.MESSAGE, operationSubject);
   1.104 +    }
   1.105 +
   1.106 +    public static BindingSubject createFaultMessageSubject(QName bindingName, QName operationName, QName messageName) {
   1.107 +        if (messageName == null) {
   1.108 +            throw LOGGER.logSevereException(new IllegalArgumentException(BindingApiMessages.BINDING_API_NO_FAULT_MESSAGE_NAME()));
   1.109 +        }
   1.110 +        final BindingSubject operationSubject = createOperationSubject(bindingName, operationName);
   1.111 +        return new BindingSubject(messageName, WsdlMessageType.FAULT, WsdlNameScope.MESSAGE, operationSubject);
   1.112 +    }
   1.113 +
   1.114 +    public QName getName() {
   1.115 +        return this.name;
   1.116 +    }
   1.117 +
   1.118 +    public BindingSubject getParent() {
   1.119 +        return this.parent;
   1.120 +    }
   1.121 +
   1.122 +    public boolean isBindingSubject() {
   1.123 +        if (this.nameScope == WsdlNameScope.ENDPOINT) {
   1.124 +            return this.parent == null;
   1.125 +        }
   1.126 +        else {
   1.127 +            return false;
   1.128 +        }
   1.129 +    }
   1.130 +
   1.131 +    public boolean isOperationSubject() {
   1.132 +        if (this.nameScope == WsdlNameScope.OPERATION) {
   1.133 +            if (this.parent != null) {
   1.134 +                return this.parent.isBindingSubject();
   1.135 +            }
   1.136 +        }
   1.137 +        return false;
   1.138 +    }
   1.139 +
   1.140 +    public boolean isMessageSubject() {
   1.141 +        if (this.nameScope == WsdlNameScope.MESSAGE) {
   1.142 +            if (this.parent != null) {
   1.143 +                return this.parent.isOperationSubject();
   1.144 +            }
   1.145 +        }
   1.146 +        return false;
   1.147 +    }
   1.148 +
   1.149 +    public boolean isInputMessageSubject() {
   1.150 +        return isMessageSubject() && (this.messageType == WsdlMessageType.INPUT);
   1.151 +    }
   1.152 +
   1.153 +    public boolean isOutputMessageSubject() {
   1.154 +        return isMessageSubject() && (this.messageType == WsdlMessageType.OUTPUT);
   1.155 +    }
   1.156 +
   1.157 +    public boolean isFaultMessageSubject() {
   1.158 +        return isMessageSubject() && (this.messageType == WsdlMessageType.FAULT);
   1.159 +    }
   1.160 +
   1.161 +    @Override
   1.162 +    public boolean equals(final Object that) {
   1.163 +        if (this == that) {
   1.164 +            return true;
   1.165 +        }
   1.166 +
   1.167 +        if (that == null || !(that instanceof BindingSubject)) {
   1.168 +            return false;
   1.169 +        }
   1.170 +
   1.171 +        final BindingSubject thatSubject = (BindingSubject) that;
   1.172 +        boolean isEqual = true;
   1.173 +
   1.174 +        isEqual = isEqual && ((this.name == null) ? thatSubject.name == null : this.name.equals(thatSubject.name));
   1.175 +        isEqual = isEqual && this.messageType.equals(thatSubject.messageType);
   1.176 +        isEqual = isEqual && this.nameScope.equals(thatSubject.nameScope);
   1.177 +        isEqual = isEqual && ((this.parent == null) ? thatSubject.parent == null : this.parent.equals(thatSubject.parent));
   1.178 +
   1.179 +        return isEqual;
   1.180 +    }
   1.181 +
   1.182 +    @Override
   1.183 +    public int hashCode() {
   1.184 +        int result = 23;
   1.185 +
   1.186 +        result = 29 * result + ((this.name == null) ? 0 : this.name.hashCode());
   1.187 +        result = 29 * result + this.messageType.hashCode();
   1.188 +        result = 29 * result + this.nameScope.hashCode();
   1.189 +        result = 29 * result + ((this.parent == null) ? 0 : this.parent.hashCode());
   1.190 +
   1.191 +        return result;
   1.192 +    }
   1.193 +
   1.194 +    @Override
   1.195 +    public String toString() {
   1.196 +        final StringBuilder result = new StringBuilder("BindingSubject[");
   1.197 +        result.append(this.name).append(", ").append(this.messageType);
   1.198 +        result.append(", ").append(this.nameScope).append(", ").append(this.parent);
   1.199 +        return result.append("]").toString();
   1.200 +    }
   1.201 +
   1.202 +}

mercurial