|
1 /* |
|
2 * Copyright (c) 1997, 2010, 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.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 |
|
33 import javax.xml.namespace.QName; |
|
34 import javax.xml.stream.XMLStreamReader; |
|
35 import java.util.LinkedHashMap; |
|
36 import java.util.Map; |
|
37 |
|
38 /** |
|
39 * Implementation of {@link WSDLService} |
|
40 * |
|
41 * @author Vivek Pandey |
|
42 */ |
|
43 public final class WSDLServiceImpl extends AbstractExtensibleImpl implements WSDLService { |
|
44 private final QName name; |
|
45 private final Map<QName, WSDLPortImpl> ports; |
|
46 private final WSDLModelImpl parent; |
|
47 |
|
48 public WSDLServiceImpl(XMLStreamReader xsr,WSDLModelImpl parent, QName name) { |
|
49 super(xsr); |
|
50 this.parent = parent; |
|
51 this.name = name; |
|
52 ports = new LinkedHashMap<QName,WSDLPortImpl>(); |
|
53 } |
|
54 |
|
55 public @NotNull |
|
56 WSDLModelImpl getParent() { |
|
57 return parent; |
|
58 } |
|
59 |
|
60 public QName getName() { |
|
61 return name; |
|
62 } |
|
63 |
|
64 public WSDLPortImpl get(QName portName) { |
|
65 return ports.get(portName); |
|
66 } |
|
67 |
|
68 public WSDLPort getFirstPort() { |
|
69 if(ports.isEmpty()) |
|
70 return null; |
|
71 else |
|
72 return ports.values().iterator().next(); |
|
73 } |
|
74 |
|
75 public Iterable<WSDLPortImpl> getPorts(){ |
|
76 return ports.values(); |
|
77 } |
|
78 |
|
79 /** |
|
80 * gets the first port in this service which matches the portType |
|
81 */ |
|
82 public @Nullable |
|
83 WSDLPortImpl getMatchingPort(QName portTypeName){ |
|
84 for(WSDLPortImpl port : getPorts()){ |
|
85 QName ptName = port.getBinding().getPortTypeName(); |
|
86 assert (ptName != null); |
|
87 if(ptName.equals(portTypeName)) |
|
88 return port; |
|
89 } |
|
90 return null; |
|
91 } |
|
92 |
|
93 /** |
|
94 * Populates the Map that holds port name as key and {@link WSDLPort} as the value. |
|
95 * |
|
96 * @param portName Must be non-null |
|
97 * @param port Must be non-null |
|
98 * @throws NullPointerException if either opName or ptOp is null |
|
99 */ |
|
100 public void put(QName portName, WSDLPortImpl port) { |
|
101 if (portName == null || port == null) |
|
102 throw new NullPointerException(); |
|
103 ports.put(portName, port); |
|
104 } |
|
105 |
|
106 void freeze(WSDLModelImpl root) { |
|
107 for (WSDLPortImpl port : ports.values()) { |
|
108 port.freeze(root); |
|
109 } |
|
110 } |
|
111 } |