ohair@286: /* alanb@368: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@286: * ohair@286: * This code is free software; you can redistribute it and/or modify it ohair@286: * under the terms of the GNU General Public License version 2 only, as ohair@286: * published by the Free Software Foundation. Oracle designates this ohair@286: * particular file as subject to the "Classpath" exception as provided ohair@286: * by Oracle in the LICENSE file that accompanied this code. ohair@286: * ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@286: * version 2 for more details (a copy is included in the LICENSE file that ohair@286: * accompanied this code). ohair@286: * ohair@286: * You should have received a copy of the GNU General Public License version ohair@286: * 2 along with this work; if not, write to the Free Software Foundation, ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@286: * ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@286: * or visit www.oracle.com if you need additional information or have any ohair@286: * questions. ohair@286: */ ohair@286: ohair@286: package com.sun.tools.internal.ws.wsdl.document; ohair@286: ohair@286: import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible; ohair@286: import com.sun.tools.internal.ws.api.wsdl.TWSDLExtension; ohair@286: import com.sun.tools.internal.ws.wsdl.framework.Entity; ohair@286: import com.sun.tools.internal.ws.wsdl.framework.EntityAction; ohair@286: import com.sun.tools.internal.ws.wsdl.framework.ExtensibilityHelper; ohair@286: import org.xml.sax.Locator; ohair@286: ohair@286: import javax.xml.namespace.QName; ohair@286: import java.util.ArrayList; ohair@286: import java.util.List; ohair@286: ohair@286: /** ohair@286: * Entity corresponding to the "operation" child element of a WSDL "binding" element. ohair@286: * ohair@286: * @author WS Development Team ohair@286: */ ohair@286: public class BindingOperation extends Entity implements TWSDLExtensible { ohair@286: ohair@286: public BindingOperation(Locator locator) { ohair@286: super(locator); ohair@286: _faults = new ArrayList(); ohair@286: _helper = new ExtensibilityHelper(); ohair@286: } ohair@286: ohair@286: public String getName() { ohair@286: return _name; ohair@286: } ohair@286: ohair@286: public void setName(String name) { ohair@286: _name = name; ohair@286: } ohair@286: ohair@286: public String getUniqueKey() { ohair@286: if (_uniqueKey == null) { alanb@368: StringBuilder sb = new StringBuilder(); ohair@286: sb.append(_name); ohair@286: sb.append(' '); ohair@286: if (_input != null) { ohair@286: sb.append(_input.getName()); ohair@286: } else { ohair@286: sb.append(_name); ohair@286: if (_style == OperationStyle.REQUEST_RESPONSE) { ohair@286: sb.append("Request"); ohair@286: } else if (_style == OperationStyle.SOLICIT_RESPONSE) { ohair@286: sb.append("Response"); ohair@286: } ohair@286: } ohair@286: sb.append(' '); ohair@286: if (_output != null) { ohair@286: sb.append(_output.getName()); ohair@286: } else { ohair@286: sb.append(_name); ohair@286: if (_style == OperationStyle.SOLICIT_RESPONSE) { ohair@286: sb.append("Solicit"); ohair@286: } else if (_style == OperationStyle.REQUEST_RESPONSE) { ohair@286: sb.append("Response"); ohair@286: } ohair@286: } ohair@286: _uniqueKey = sb.toString(); ohair@286: } ohair@286: ohair@286: return _uniqueKey; ohair@286: } ohair@286: ohair@286: public OperationStyle getStyle() { ohair@286: return _style; ohair@286: } ohair@286: ohair@286: public void setStyle(OperationStyle s) { ohair@286: _style = s; ohair@286: } ohair@286: ohair@286: public BindingInput getInput() { ohair@286: return _input; ohair@286: } ohair@286: ohair@286: public void setInput(BindingInput i) { ohair@286: _input = i; ohair@286: } ohair@286: ohair@286: public BindingOutput getOutput() { ohair@286: return _output; ohair@286: } ohair@286: ohair@286: public void setOutput(BindingOutput o) { ohair@286: _output = o; ohair@286: } ohair@286: ohair@286: public void addFault(BindingFault f) { ohair@286: _faults.add(f); ohair@286: } ohair@286: ohair@286: public Iterable faults() { ohair@286: return _faults; ohair@286: } ohair@286: alanb@368: @Override ohair@286: public QName getElementName() { ohair@286: return WSDLConstants.QNAME_OPERATION; ohair@286: } ohair@286: ohair@286: public Documentation getDocumentation() { ohair@286: return _documentation; ohair@286: } ohair@286: ohair@286: public void setDocumentation(Documentation d) { ohair@286: _documentation = d; ohair@286: } ohair@286: alanb@368: @Override ohair@286: public String getNameValue() { ohair@286: return getName(); ohair@286: } ohair@286: alanb@368: @Override ohair@286: public String getNamespaceURI() { alanb@368: return (parent == null) ? null : parent.getNamespaceURI(); ohair@286: } ohair@286: alanb@368: @Override ohair@286: public QName getWSDLElementName() { ohair@286: return getElementName(); ohair@286: } ohair@286: alanb@368: @Override ohair@286: public void addExtension(TWSDLExtension e) { ohair@286: _helper.addExtension(e); ohair@286: } ohair@286: alanb@368: @Override ohair@286: public Iterable extensions() { ohair@286: return _helper.extensions(); ohair@286: } ohair@286: alanb@368: @Override ohair@286: public TWSDLExtensible getParent() { ohair@286: return parent; ohair@286: } ohair@286: alanb@368: @Override ohair@286: public void withAllSubEntitiesDo(EntityAction action) { ohair@286: if (_input != null) { ohair@286: action.perform(_input); ohair@286: } ohair@286: if (_output != null) { ohair@286: action.perform(_output); ohair@286: } ohair@286: for (BindingFault _fault : _faults) { ohair@286: action.perform(_fault); ohair@286: } ohair@286: _helper.withAllSubEntitiesDo(action); ohair@286: } ohair@286: ohair@286: public void accept(WSDLDocumentVisitor visitor) throws Exception { ohair@286: visitor.preVisit(this); ohair@286: //bug fix: 4947340, extensions should be the first element ohair@286: _helper.accept(visitor); ohair@286: if (_input != null) { ohair@286: _input.accept(visitor); ohair@286: } ohair@286: if (_output != null) { ohair@286: _output.accept(visitor); ohair@286: } ohair@286: for (BindingFault _fault : _faults) { ohair@286: _fault.accept(visitor); ohair@286: } ohair@286: visitor.postVisit(this); ohair@286: } ohair@286: alanb@368: @Override ohair@286: public void validateThis() { ohair@286: if (_name == null) { ohair@286: failValidation("validation.missingRequiredAttribute", "name"); ohair@286: } ohair@286: if (_style == null) { ohair@286: failValidation("validation.missingRequiredProperty", "style"); ohair@286: } ohair@286: ohair@286: // verify operation style ohair@286: if (_style == OperationStyle.ONE_WAY) { ohair@286: if (_input == null) { ohair@286: failValidation("validation.missingRequiredSubEntity", "input"); ohair@286: } ohair@286: if (_output != null) { ohair@286: failValidation("validation.invalidSubEntity", "output"); ohair@286: } alanb@368: if (_faults != null && !_faults.isEmpty()) { ohair@286: failValidation("validation.invalidSubEntity", "fault"); ohair@286: } ohair@286: } ohair@286: } ohair@286: ohair@286: private ExtensibilityHelper _helper; ohair@286: private Documentation _documentation; ohair@286: private String _name; ohair@286: private BindingInput _input; ohair@286: private BindingOutput _output; ohair@286: private List _faults; ohair@286: private OperationStyle _style; ohair@286: private String _uniqueKey; ohair@286: ohair@286: public void setParent(TWSDLExtensible parent) { ohair@286: this.parent = parent; ohair@286: } ohair@286: ohair@286: private TWSDLExtensible parent; ohair@286: }