Thu, 31 Aug 2017 15:18:52 +0800
merge
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 */
26 package com.sun.xml.internal.ws.model.wsdl;
28 import com.sun.istack.internal.NotNull;
29 import com.sun.istack.internal.Nullable;
30 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
31 import com.sun.xml.internal.ws.api.model.wsdl.WSDLService;
32 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLModel;
33 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLPort;
34 import com.sun.xml.internal.ws.api.model.wsdl.editable.EditableWSDLService;
36 import javax.xml.namespace.QName;
37 import javax.xml.stream.XMLStreamReader;
39 import java.util.LinkedHashMap;
40 import java.util.Map;
42 /**
43 * Implementation of {@link WSDLService}
44 *
45 * @author Vivek Pandey
46 */
47 public final class WSDLServiceImpl extends AbstractExtensibleImpl implements EditableWSDLService {
48 private final QName name;
49 private final Map<QName, EditableWSDLPort> ports;
50 private final EditableWSDLModel parent;
52 public WSDLServiceImpl(XMLStreamReader xsr, EditableWSDLModel parent, QName name) {
53 super(xsr);
54 this.parent = parent;
55 this.name = name;
56 ports = new LinkedHashMap<QName, EditableWSDLPort>();
57 }
59 public @NotNull
60 EditableWSDLModel getParent() {
61 return parent;
62 }
64 public QName getName() {
65 return name;
66 }
68 public EditableWSDLPort get(QName portName) {
69 return ports.get(portName);
70 }
72 public EditableWSDLPort getFirstPort() {
73 if(ports.isEmpty())
74 return null;
75 else
76 return ports.values().iterator().next();
77 }
79 public Iterable<EditableWSDLPort> getPorts(){
80 return ports.values();
81 }
83 /**
84 * gets the first port in this service which matches the portType
85 */
86 public @Nullable
87 EditableWSDLPort getMatchingPort(QName portTypeName){
88 for(EditableWSDLPort port : getPorts()){
89 QName ptName = port.getBinding().getPortTypeName();
90 assert (ptName != null);
91 if(ptName.equals(portTypeName))
92 return port;
93 }
94 return null;
95 }
97 /**
98 * Populates the Map that holds port name as key and {@link WSDLPort} as the value.
99 *
100 * @param portName Must be non-null
101 * @param port Must be non-null
102 * @throws NullPointerException if either opName or ptOp is null
103 */
104 public void put(QName portName, EditableWSDLPort port) {
105 if (portName == null || port == null)
106 throw new NullPointerException();
107 ports.put(portName, port);
108 }
110 public void freeze(EditableWSDLModel root) {
111 for (EditableWSDLPort port : ports.values()) {
112 port.freeze(root);
113 }
114 }
115 }