325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.policy.subject;
325N/A
325N/Aimport com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages;
325N/Aimport com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
325N/Aimport javax.xml.namespace.QName;
325N/A
325N/A/**
325N/A * Provides objects for use as WSDL 1.0/1.1 policy subjects.
325N/A *
325N/A * An instance of this class may represent a wsdl:binding element or a wsdl:binding/operation
325N/A * element or a wsdl:binding/operation/message element.
325N/A *
325N/A * @author Fabian Ritzmann
325N/A */
325N/Apublic class WsdlBindingSubject {
325N/A
325N/A /**
325N/A * For message subjects, this needs to be set to one of the values INPUT, OUTPUT
325N/A * or FAULT. Any other subject has the message type NO_MESSAGE.
325N/A */
325N/A public enum WsdlMessageType {
325N/A NO_MESSAGE,
325N/A INPUT,
325N/A OUTPUT,
325N/A FAULT
325N/A }
325N/A
325N/A /**
325N/A * Identifies the scope to which this subject belongs. See WS-PolicyAttachment
325N/A * for an explanation on WSDL scopes.
325N/A *
325N/A * The SERVICE scope is not actually used and only listed here for completeness
325N/A * sake.
325N/A */
325N/A public enum WsdlNameScope {
325N/A SERVICE,
325N/A ENDPOINT,
325N/A OPERATION,
325N/A MESSAGE
325N/A }
325N/A
325N/A private static final PolicyLogger LOGGER = PolicyLogger.getLogger(WsdlBindingSubject.class);
325N/A
325N/A private final QName name;
325N/A private final WsdlMessageType messageType;
325N/A private final WsdlNameScope nameScope;
325N/A private final WsdlBindingSubject parent;
325N/A
325N/A WsdlBindingSubject(final QName name, final WsdlNameScope scope, final WsdlBindingSubject parent) {
325N/A this(name, WsdlMessageType.NO_MESSAGE, scope, parent);
325N/A }
325N/A
325N/A WsdlBindingSubject(final QName name, final WsdlMessageType messageType, final WsdlNameScope scope, final WsdlBindingSubject parent) {
325N/A this.name = name;
325N/A this.messageType = messageType;
325N/A this.nameScope = scope;
325N/A this.parent = parent;
325N/A }
325N/A
325N/A public static WsdlBindingSubject createBindingSubject(QName bindingName) {
325N/A return new WsdlBindingSubject(bindingName, WsdlNameScope.ENDPOINT, null);
325N/A }
325N/A
325N/A public static WsdlBindingSubject createBindingOperationSubject(QName bindingName, QName operationName) {
325N/A final WsdlBindingSubject bindingSubject = createBindingSubject(bindingName);
325N/A return new WsdlBindingSubject(operationName, WsdlNameScope.OPERATION, bindingSubject);
325N/A }
325N/A
325N/A public static WsdlBindingSubject createBindingMessageSubject(QName bindingName, QName operationName, QName messageName, WsdlMessageType messageType) {
325N/A if (messageType == null) {
325N/A throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0083_MESSAGE_TYPE_NULL()));
325N/A }
325N/A if (messageType == WsdlMessageType.NO_MESSAGE) {
325N/A throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0084_MESSAGE_TYPE_NO_MESSAGE()));
325N/A }
325N/A if ((messageType == WsdlMessageType.FAULT) && (messageName == null)) {
325N/A throw LOGGER.logSevereException(new IllegalArgumentException(LocalizationMessages.WSP_0085_MESSAGE_FAULT_NO_NAME()));
325N/A }
325N/A final WsdlBindingSubject operationSubject = createBindingOperationSubject(bindingName, operationName);
325N/A return new WsdlBindingSubject(messageName, messageType, WsdlNameScope.MESSAGE, operationSubject);
325N/A }
325N/A
325N/A public QName getName() {
325N/A return this.name;
325N/A }
325N/A
325N/A public WsdlMessageType getMessageType() {
325N/A return this.messageType;
325N/A }
325N/A
325N/A public WsdlBindingSubject getParent() {
325N/A return this.parent;
325N/A }
325N/A
325N/A public boolean isBindingSubject() {
325N/A if (this.nameScope == WsdlNameScope.ENDPOINT) {
325N/A return this.parent == null;
325N/A }
325N/A else {
325N/A return false;
325N/A }
325N/A }
325N/A
325N/A public boolean isBindingOperationSubject() {
325N/A if (this.nameScope == WsdlNameScope.OPERATION) {
325N/A if (this.parent != null) {
325N/A return this.parent.isBindingSubject();
325N/A }
325N/A }
325N/A return false;
325N/A }
325N/A
325N/A public boolean isBindingMessageSubject() {
325N/A if (this.nameScope == WsdlNameScope.MESSAGE) {
325N/A if (this.parent != null) {
325N/A return this.parent.isBindingOperationSubject();
325N/A }
325N/A }
325N/A return false;
325N/A }
325N/A
325N/A @Override
325N/A public boolean equals(final Object that) {
325N/A if (this == that) {
325N/A return true;
325N/A }
325N/A
325N/A if (that == null || !(that instanceof WsdlBindingSubject)) {
325N/A return false;
325N/A }
325N/A
325N/A final WsdlBindingSubject thatSubject = (WsdlBindingSubject) that;
325N/A boolean isEqual = true;
325N/A
325N/A isEqual = isEqual && ((this.name == null) ? thatSubject.name == null : this.name.equals(thatSubject.name));
325N/A isEqual = isEqual && this.messageType.equals(thatSubject.messageType);
325N/A isEqual = isEqual && this.nameScope.equals(thatSubject.nameScope);
325N/A isEqual = isEqual && ((this.parent == null) ? thatSubject.parent == null : this.parent.equals(thatSubject.parent));
325N/A
325N/A return isEqual;
325N/A }
325N/A
325N/A @Override
325N/A public int hashCode() {
325N/A int result = 23;
325N/A
325N/A result = 31 * result + ((this.name == null) ? 0 : this.name.hashCode());
325N/A result = 31 * result + this.messageType.hashCode();
325N/A result = 31 * result + this.nameScope.hashCode();
325N/A result = 31 * result + ((this.parent == null) ? 0 : this.parent.hashCode());
325N/A
325N/A return result;
325N/A }
325N/A
325N/A @Override
325N/A public String toString() {
325N/A final StringBuilder result = new StringBuilder("WsdlBindingSubject[");
325N/A result.append(this.name).append(", ").append(this.messageType);
325N/A result.append(", ").append(this.nameScope).append(", ").append(this.parent);
325N/A return result.append("]").toString();
325N/A }
325N/A
325N/A}