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.tools.internal.ws.wsdl.document;
325N/A
325N/Aimport com.sun.codemodel.internal.JClass;
325N/Aimport com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
325N/Aimport com.sun.tools.internal.ws.api.wsdl.TWSDLExtension;
325N/Aimport com.sun.tools.internal.ws.api.wsdl.TWSDLOperation;
325N/Aimport com.sun.tools.internal.ws.wsdl.framework.Entity;
325N/Aimport com.sun.tools.internal.ws.wsdl.framework.EntityAction;
325N/Aimport com.sun.tools.internal.ws.wsdl.framework.ExtensibilityHelper;
325N/Aimport org.xml.sax.Locator;
325N/A
325N/Aimport javax.xml.namespace.QName;
325N/Aimport java.util.*;
325N/A
325N/A/**
325N/A * Entity corresponding to the "operation" child element of a "portType" WSDL element.
325N/A *
325N/A * @author WS Development Team
325N/A */
325N/Apublic class Operation extends Entity implements TWSDLOperation {
325N/A
325N/A public Operation(Locator locator) {
325N/A super(locator);
325N/A _faults = new ArrayList<Fault>();
325N/A _helper = new ExtensibilityHelper();
325N/A }
325N/A
325N/A public String getName() {
325N/A return _name;
325N/A }
325N/A
325N/A public void setName(String name) {
325N/A _name = name;
325N/A }
325N/A
325N/A public String getUniqueKey() {
325N/A if (_uniqueKey == null) {
325N/A StringBuffer sb = new StringBuffer();
325N/A sb.append(_name);
325N/A sb.append(' ');
325N/A if (_input != null) {
325N/A sb.append(_input.getName());
325N/A } else {
325N/A sb.append(_name);
325N/A if (_style == OperationStyle.REQUEST_RESPONSE) {
325N/A sb.append("Request");
325N/A } else if (_style == OperationStyle.SOLICIT_RESPONSE) {
325N/A sb.append("Response");
325N/A }
325N/A }
325N/A sb.append(' ');
325N/A if (_output != null) {
325N/A sb.append(_output.getName());
325N/A } else {
325N/A sb.append(_name);
325N/A if (_style == OperationStyle.SOLICIT_RESPONSE) {
325N/A sb.append("Solicit");
325N/A } else if (_style == OperationStyle.REQUEST_RESPONSE) {
325N/A sb.append("Response");
325N/A }
325N/A }
325N/A _uniqueKey = sb.toString();
325N/A }
325N/A
325N/A return _uniqueKey;
325N/A }
325N/A
325N/A public OperationStyle getStyle() {
325N/A return _style;
325N/A }
325N/A
325N/A public void setStyle(OperationStyle s) {
325N/A _style = s;
325N/A }
325N/A
325N/A public Input getInput() {
325N/A return _input;
325N/A }
325N/A
325N/A public void setInput(Input i) {
325N/A _input = i;
325N/A }
325N/A
325N/A public Output getOutput() {
325N/A return _output;
325N/A }
325N/A
325N/A public void setOutput(Output o) {
325N/A _output = o;
325N/A }
325N/A
325N/A public void addFault(Fault f) {
325N/A _faults.add(f);
325N/A }
325N/A
325N/A public Iterable<Fault> faults() {
325N/A return _faults;
325N/A }
325N/A
325N/A public String getParameterOrder() {
325N/A return _parameterOrder;
325N/A }
325N/A
325N/A public void setParameterOrder(String s) {
325N/A _parameterOrder = s;
325N/A }
325N/A
325N/A public QName getElementName() {
325N/A return WSDLConstants.QNAME_OPERATION;
325N/A }
325N/A
325N/A public Documentation getDocumentation() {
325N/A return _documentation;
325N/A }
325N/A
325N/A public void setDocumentation(Documentation d) {
325N/A _documentation = d;
325N/A }
325N/A
325N/A public void withAllSubEntitiesDo(EntityAction action) {
325N/A super.withAllSubEntitiesDo(action);
325N/A
325N/A if (_input != null) {
325N/A action.perform(_input);
325N/A }
325N/A if (_output != null) {
325N/A action.perform(_output);
325N/A }
325N/A for (Fault _fault : _faults) {
325N/A action.perform(_fault);
325N/A }
325N/A _helper.withAllSubEntitiesDo(action);
325N/A }
325N/A
325N/A public void accept(WSDLDocumentVisitor visitor) throws Exception {
325N/A visitor.preVisit(this);
325N/A if (_input != null) {
325N/A _input.accept(visitor);
325N/A }
325N/A if (_output != null) {
325N/A _output.accept(visitor);
325N/A }
325N/A for (Fault _fault : _faults) {
325N/A _fault.accept(visitor);
325N/A }
325N/A visitor.postVisit(this);
325N/A }
325N/A
325N/A public void validateThis() {
325N/A if (_name == null) {
325N/A failValidation("validation.missingRequiredAttribute", "name");
325N/A }
325N/A if (_style == null) {
325N/A failValidation("validation.missingRequiredProperty", "style");
325N/A }
325N/A
325N/A // verify operation style
325N/A if (_style == OperationStyle.ONE_WAY) {
325N/A if (_input == null) {
325N/A failValidation("validation.missingRequiredSubEntity", "input");
325N/A }
325N/A if (_output != null) {
325N/A failValidation("validation.invalidSubEntity", "output");
325N/A }
325N/A if (_faults != null && _faults.size() != 0) {
325N/A failValidation("validation.invalidSubEntity", "fault");
325N/A }
325N/A } else if (_style == OperationStyle.NOTIFICATION) {
325N/A if (_parameterOrder != null) {
325N/A failValidation("validation.invalidAttribute", "parameterOrder");
325N/A }
325N/A }
325N/A }
325N/A
325N/A public String getNameValue() {
325N/A return getName();
325N/A }
325N/A
325N/A public String getNamespaceURI() {
325N/A return parent.getNamespaceURI();
325N/A }
325N/A
325N/A public QName getWSDLElementName() {
325N/A return getElementName();
325N/A }
325N/A
325N/A /* (non-Javadoc)
325N/A * @see TWSDLExtensible#addExtension(ExtensionImpl)
325N/A */
325N/A public void addExtension(TWSDLExtension e) {
325N/A _helper.addExtension(e);
325N/A
325N/A }
325N/A
325N/A /* (non-Javadoc)
325N/A * @see TWSDLExtensible#extensions()
325N/A */
325N/A public Iterable<? extends TWSDLExtension> extensions() {
325N/A return _helper.extensions();
325N/A }
325N/A
325N/A public TWSDLExtensible getParent() {
325N/A return parent;
325N/A }
325N/A
325N/A public void setParent(TWSDLExtensible parent) {
325N/A this.parent = parent;
325N/A }
325N/A
325N/A public Map<String, JClass> getFaults() {
325N/A return unmodifiableFaultClassMap;
325N/A }
325N/A
325N/A public void putFault(String faultName, JClass exception){
325N/A faultClassMap.put(faultName, exception);
325N/A }
325N/A
325N/A private TWSDLExtensible parent;
325N/A private Documentation _documentation;
325N/A private String _name;
325N/A private Input _input;
325N/A private Output _output;
325N/A private List<Fault> _faults;
325N/A private OperationStyle _style;
325N/A private String _parameterOrder;
325N/A private String _uniqueKey;
325N/A private ExtensibilityHelper _helper;
325N/A private final Map<String, JClass> faultClassMap = new HashMap<String, JClass>();
325N/A private final Map<String, JClass> unmodifiableFaultClassMap = Collections.unmodifiableMap(faultClassMap);
325N/A}