1
2
3
4
5
6
7
8 package it.imolinfo.jbi4ejb.jbi.wsdl;
9
10 import it.imolinfo.jbi4ejb.Logger;
11 import it.imolinfo.jbi4ejb.LoggerFactory;
12
13 import java.util.Iterator;
14 import java.util.List;
15
16 import javax.wsdl.Binding;
17 import javax.wsdl.Definition;
18 import javax.wsdl.Port;
19 import javax.wsdl.PortType;
20 import javax.wsdl.Service;
21 import javax.wsdl.extensions.ExtensibilityElement;
22 import javax.xml.namespace.QName;
23
24
25
26
27
28
29 public final class Jbi4EjbExtensionUtils {
30
31
32 private static final Logger LOG = LoggerFactory
33 .getLogger(Jbi4EjbExtensionUtils.class);
34
35
36
37
38 private Jbi4EjbExtensionUtils() {}
39
40
41
42
43
44
45
46
47
48
49
50 public static Binding getBinding(final Definition def,
51 final String serviceName, final String endpointName) {
52 final Service svc = def.getService(QName.valueOf(serviceName));
53
54 if (svc == null) {
55 return null;
56 }
57
58 final Port port = svc.getPort(endpointName);
59
60 if (port == null) {
61 return null;
62 } else {
63 return port.getBinding();
64 }
65 }
66
67
68
69
70
71
72
73
74
75
76 public static PortType getPortType(final Definition def,
77 final String serviceName, final String endpointName) {
78 final Service svc = def.getService(QName.valueOf(serviceName));
79
80 if (svc == null) {
81 return null;
82 }
83
84 final Port port = svc.getPort(QName.valueOf(endpointName)
85 .getLocalPart());
86
87 Binding binding = null;
88 if (port == null) {
89 return null;
90 } else {
91 binding = port.getBinding();
92 }
93 PortType portType = null;
94 if (binding != null) {
95 portType = binding.getPortType();
96 }
97 return portType;
98 }
99
100
101
102
103
104
105
106
107 @SuppressWarnings("unchecked")
108 public static Jbi4EjbTypes getEjbTypes(final Definition def) {
109
110 Jbi4EjbTypes ejbTypes = null;
111
112 List extElems = def.getExtensibilityElements();
113
114 Iterator extIter = null;
115 if (extElems != null) {
116 extIter = extElems.iterator();
117 }
118
119 while ((extIter != null) && extIter.hasNext() && (ejbTypes == null)) {
120 final ExtensibilityElement ee = (ExtensibilityElement) extIter
121 .next();
122 LOG.debug("Inspecting: " + ee);
123 if (Jbi4EjbTypes.class.isInstance(ee)) {
124 ejbTypes = (Jbi4EjbTypes) ee;
125 LOG.debug("Found a Jbi4EjbTypes instance: " + ejbTypes.getTypesSerialVersionUIDs());
126 }
127 }
128 if (ejbTypes == null) {
129 LOG.debug("No jbi4EjbTypes instance found, returning an empty one");
130 ejbTypes = new Jbi4EjbTypes();
131 }
132 return ejbTypes;
133 }
134
135
136
137
138
139
140
141
142
143
144 @SuppressWarnings("unchecked")
145 public static Jbi4EjbBinding getEjbBinding(final Definition def,
146 final String serviceName, final String endpointName) {
147 Jbi4EjbBinding ejbBinding = null;
148 final Binding binding = getBinding(def, serviceName, endpointName);
149
150 if (binding != null) {
151 final List extElems = binding.getExtensibilityElements();
152
153 Iterator extIter = null;
154 if (extElems != null) {
155 extIter = extElems.iterator();
156 }
157
158 while ((extIter != null) && extIter.hasNext() &&
159 (ejbBinding == null)) {
160 final ExtensibilityElement ee = (ExtensibilityElement) extIter
161 .next();
162
163 if (Jbi4EjbBinding.class.isInstance(ee)) {
164 ejbBinding = (Jbi4EjbBinding) ee;
165 }
166 }
167 }
168
169 return ejbBinding;
170 }
171
172
173
174
175
176
177
178
179
180
181 @SuppressWarnings("unchecked")
182 public static Jbi4EjbAddress getEjbAddress(final Definition def,
183 final String serviceName, final String endpointName) {
184 Jbi4EjbAddress address = null;
185 final Service svc = def.getService(QName.valueOf(serviceName));
186
187 if (svc == null) {
188 return null;
189 }
190
191 final Port port = svc.getPort(QName.valueOf(endpointName)
192 .getLocalPart());
193
194 if (port != null) {
195 final List extElems = port.getExtensibilityElements();
196
197 Iterator extIter = null;
198
199 if (extElems != null) {
200 extIter = extElems.iterator();
201 }
202
203 while ((extIter != null) && extIter.hasNext() && (address == null)) {
204 final ExtensibilityElement ee = (ExtensibilityElement) extIter
205 .next();
206
207 if (Jbi4EjbAddress.class.isInstance(ee)) {
208 address = (Jbi4EjbAddress) ee;
209 }
210 }
211 }
212 return address;
213 }
214
215 }