View Javadoc
1   /*
2    * Copyright (c) 1997, 2013, 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   */
25  
26  package com.sun.xml.internal.ws.model.wsdl;
27  
28  import com.sun.istack.internal.NotNull;
29  import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation;
30  import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLFault;
31  import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLInput;
32  import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLMessage;
33  import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLModel;
34  import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLOperation;
35  import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLOutput;
36  import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPart;
37  import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPortType;
38  import com.sun.xml.internal.ws.util.QNameMap;
39  
40  import javax.xml.namespace.QName;
41  import javax.xml.stream.XMLStreamReader;
42  
43  import java.util.ArrayList;
44  import java.util.List;
45  
46  /**
47   * Implementaiton of {@link WSDLOperation}
48   *
49   * @author Vivek Pandey
50   */
51  public final class WSDLOperationImpl extends AbstractExtensibleImpl implements EditableWSDLOperation {
52      private final QName name;
53      private String parameterOrder;
54      private EditableWSDLInput input;
55      private EditableWSDLOutput output;
56      private final List<EditableWSDLFault> faults;
57      private final QNameMap<EditableWSDLFault> faultMap;
58      protected Iterable<EditableWSDLMessage> messages;
59      private final EditableWSDLPortType owner;
60  
61      public WSDLOperationImpl(XMLStreamReader xsr, EditableWSDLPortType owner, QName name) {
62          super(xsr);
63          this.name = name;
64          this.faults = new ArrayList<EditableWSDLFault>();
65          this.faultMap = new QNameMap<EditableWSDLFault>();
66          this.owner = owner;
67      }
68  
69      public QName getName() {
70          return name;
71      }
72  
73      public String getParameterOrder() {
74          return parameterOrder;
75      }
76  
77      public void setParameterOrder(String parameterOrder) {
78          this.parameterOrder = parameterOrder;
79      }
80  
81      public EditableWSDLInput getInput() {
82          return input;
83      }
84  
85      public void setInput(EditableWSDLInput input) {
86          this.input = input;
87      }
88  
89      public EditableWSDLOutput getOutput() {
90          return output;
91      }
92  
93      public boolean isOneWay() {
94          return output == null;
95      }
96  
97      public void setOutput(EditableWSDLOutput output) {
98          this.output = output;
99      }
100 
101     public Iterable<EditableWSDLFault> getFaults() {
102         return faults;
103     }
104 
105     public EditableWSDLFault getFault(QName faultDetailName) {
106         EditableWSDLFault fault = faultMap.get(faultDetailName);
107         if(fault != null)
108             return fault;
109 
110         for(EditableWSDLFault fi : faults){
111             assert fi.getMessage().parts().iterator().hasNext();
112             EditableWSDLPart part = fi.getMessage().parts().iterator().next();
113             if(part.getDescriptor().name().equals(faultDetailName)){
114                 faultMap.put(faultDetailName, fi);
115                 return fi;
116             }
117         }
118         return null;
119     }
120 
121     @NotNull
122     public QName getPortTypeName() {
123         return owner.getName();
124     }
125 
126     public void addFault(EditableWSDLFault fault) {
127         faults.add(fault);
128     }
129 
130     public void freeze(EditableWSDLModel root) {
131         assert input != null;
132         input.freeze(root);
133         if(output != null)
134             output.freeze(root);
135         for(EditableWSDLFault fault : faults){
136             fault.freeze(root);
137         }
138     }
139 }