|
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.xml.internal.ws.api.model.wsdl.WSDLExtensible; |
|
29 import com.sun.xml.internal.ws.api.model.wsdl.WSDLExtension; |
|
30 import com.sun.xml.internal.ws.api.model.wsdl.WSDLObject; |
|
31 import com.sun.xml.internal.ws.resources.UtilMessages; |
|
32 import com.sun.xml.internal.ws.wsdl.parser.WSDLConstants; |
|
33 import com.sun.istack.internal.NotNull; |
|
34 |
|
35 import javax.xml.stream.XMLStreamReader; |
|
36 import javax.xml.stream.Location; |
|
37 import javax.xml.namespace.QName; |
|
38 import javax.xml.ws.WebServiceException; |
|
39 import java.util.ArrayList; |
|
40 import java.util.HashSet; |
|
41 import java.util.List; |
|
42 import java.util.Set; |
|
43 |
|
44 import org.xml.sax.Locator; |
|
45 import org.xml.sax.helpers.LocatorImpl; |
|
46 |
|
47 /** |
|
48 * All the WSDL 1.1 elements that are extensible should subclass from this abstract implementation of |
|
49 * {@link WSDLExtensible} interface. |
|
50 * |
|
51 * @author Vivek Pandey |
|
52 * @author Kohsuke Kawaguchi |
|
53 */ |
|
54 abstract class AbstractExtensibleImpl extends AbstractObjectImpl implements WSDLExtensible { |
|
55 protected final Set<WSDLExtension> extensions = new HashSet<WSDLExtension>(); |
|
56 // this captures any wsdl extensions that are not understood by WSDLExtensionParsers |
|
57 // and have wsdl:required=true |
|
58 protected List<UnknownWSDLExtension> notUnderstoodExtensions = |
|
59 new ArrayList<UnknownWSDLExtension>(); |
|
60 |
|
61 protected AbstractExtensibleImpl(XMLStreamReader xsr) { |
|
62 super(xsr); |
|
63 } |
|
64 |
|
65 protected AbstractExtensibleImpl(String systemId, int lineNumber) { |
|
66 super(systemId, lineNumber); |
|
67 } |
|
68 |
|
69 public final Iterable<WSDLExtension> getExtensions() { |
|
70 return extensions; |
|
71 } |
|
72 |
|
73 public final <T extends WSDLExtension> Iterable<T> getExtensions(Class<T> type) { |
|
74 // TODO: this is a rather stupid implementation |
|
75 List<T> r = new ArrayList<T>(extensions.size()); |
|
76 for (WSDLExtension e : extensions) { |
|
77 if(type.isInstance(e)) |
|
78 r.add(type.cast(e)); |
|
79 } |
|
80 return r; |
|
81 } |
|
82 |
|
83 public <T extends WSDLExtension> T getExtension(Class<T> type) { |
|
84 for (WSDLExtension e : extensions) { |
|
85 if(type.isInstance(e)) |
|
86 return type.cast(e); |
|
87 } |
|
88 return null; |
|
89 } |
|
90 |
|
91 public void addExtension(WSDLExtension ex) { |
|
92 if(ex==null) |
|
93 // I don't trust plugins. So let's always check it, instead of making this an assertion |
|
94 throw new IllegalArgumentException(); |
|
95 extensions.add(ex); |
|
96 } |
|
97 |
|
98 /** |
|
99 * This can be used if a WSDL extension element that has wsdl:required=true |
|
100 * is not understood |
|
101 * @param extnEl |
|
102 * @param locator |
|
103 */ |
|
104 public void addNotUnderstoodExtension(QName extnEl, Locator locator) { |
|
105 notUnderstoodExtensions.add(new UnknownWSDLExtension(extnEl, locator)); |
|
106 } |
|
107 |
|
108 protected static class UnknownWSDLExtension implements WSDLExtension, WSDLObject { |
|
109 private final QName extnEl; |
|
110 private final Locator locator; |
|
111 public UnknownWSDLExtension(QName extnEl, Locator locator) { |
|
112 this.extnEl = extnEl; |
|
113 this.locator = locator; |
|
114 } |
|
115 public QName getName() { |
|
116 return extnEl; |
|
117 } |
|
118 @NotNull public Locator getLocation() { |
|
119 return locator; |
|
120 } |
|
121 public String toString(){ |
|
122 return extnEl + " "+ UtilMessages.UTIL_LOCATION( locator.getLineNumber(), locator.getSystemId()); |
|
123 } |
|
124 } |
|
125 |
|
126 /** |
|
127 * This method should be called after freezing the WSDLModel |
|
128 * @return true if all wsdl required extensions on Port and Binding are understood |
|
129 */ |
|
130 public boolean areRequiredExtensionsUnderstood() { |
|
131 if (notUnderstoodExtensions.size() != 0) { |
|
132 StringBuilder buf = new StringBuilder("Unknown WSDL extensibility elements:"); |
|
133 for (UnknownWSDLExtension extn : notUnderstoodExtensions) |
|
134 buf.append('\n').append(extn.toString()); |
|
135 throw new WebServiceException(buf.toString()); |
|
136 } |
|
137 return true; |
|
138 } |
|
139 } |