This project has retired. For details please refer to its
Attic page.
UDDIRequestsAsXML xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.webconsole.hub;
17
18 import java.io.StringReader;
19 import java.io.StringWriter;
20 import java.util.logging.Level;
21 import java.util.logging.Logger;
22 import javax.xml.XMLConstants;
23 import javax.xml.bind.JAXB;
24 import javax.xml.transform.OutputKeys;
25 import javax.xml.transform.Transformer;
26 import javax.xml.transform.TransformerFactory;
27 import javax.xml.transform.stream.StreamResult;
28 import javax.xml.transform.stream.StreamSource;
29 import org.apache.juddi.v3.client.cryptor.XmlUtils;
30 import org.uddi.api_v3.AddPublisherAssertions;
31 import org.uddi.api_v3.DeleteBinding;
32 import org.uddi.api_v3.DeleteBusiness;
33 import org.uddi.api_v3.DeletePublisherAssertions;
34 import org.uddi.api_v3.DeleteService;
35 import org.uddi.api_v3.DeleteTModel;
36 import org.uddi.api_v3.FindBinding;
37 import org.uddi.api_v3.FindBusiness;
38 import org.uddi.api_v3.FindRelatedBusinesses;
39 import org.uddi.api_v3.FindService;
40 import org.uddi.api_v3.FindTModel;
41 import org.uddi.api_v3.GetAssertionStatusReport;
42 import org.uddi.api_v3.GetBindingDetail;
43 import org.uddi.api_v3.GetBusinessDetail;
44 import org.uddi.api_v3.GetOperationalInfo;
45 import org.uddi.api_v3.GetPublisherAssertions;
46 import org.uddi.api_v3.GetRegisteredInfo;
47 import org.uddi.api_v3.GetServiceDetail;
48 import org.uddi.api_v3.GetTModelDetail;
49 import org.uddi.api_v3.SaveBinding;
50 import org.uddi.api_v3.SaveBusiness;
51 import org.uddi.api_v3.SaveService;
52 import org.uddi.api_v3.SaveTModel;
53 import org.uddi.api_v3.SetPublisherAssertions;
54 import org.uddi.custody_v3.DiscardTransferToken;
55 import org.uddi.custody_v3.GetTransferToken;
56 import org.uddi.custody_v3.TransferEntities;
57 import org.uddi.sub_v3.DeleteSubscription;
58 import org.uddi.sub_v3.GetSubscriptionResults;
59 import org.uddi.sub_v3.GetSubscriptions;
60 import org.uddi.sub_v3.SaveSubscription;
61
62
63
64
65
66
67
68 public class UDDIRequestsAsXML {
69
70 private static String prettyPrintXML(String input) {
71 if (input == null || input.length() == 0) {
72 return "";
73 }
74 try {
75 TransformerFactory transFactory = TransformerFactory.newInstance();
76 transFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
77 transFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
78 Transformer transformer = transFactory.newTransformer();
79
80 transformer.setOutputProperty(OutputKeys.INDENT, "yes");
81 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
82 StreamResult result = new StreamResult(new StringWriter());
83 StreamSource source = new StreamSource(new StringReader(input.trim()));
84 transformer.transform(source, result);
85 String xmlString = result.getWriter().toString();
86 return (xmlString);
87 } catch (Exception ex) {
88 Logger.getLogger(UDDIRequestsAsXML.class.getName()).log(Level.WARNING, null, ex);
89 }
90 return null;
91 }
92
93 public static String getInquiry(String method) {
94 StringWriter sw = new StringWriter();
95 if (method.equalsIgnoreCase("findBinding")) {
96 JAXB.marshal(new FindBinding(), sw);
97 }
98 if (method.equalsIgnoreCase("findBusiness")) {
99 JAXB.marshal(new FindBusiness(), sw);
100 }
101 if (method.equalsIgnoreCase("findService")) {
102 JAXB.marshal(new FindService(), sw);
103 }
104 if (method.equalsIgnoreCase("findRelatedBusines")) {
105 JAXB.marshal(new FindRelatedBusinesses(), sw);
106 }
107 if (method.equalsIgnoreCase("findTModel")) {
108 JAXB.marshal(new FindTModel(), sw);
109 }
110 if (method.equalsIgnoreCase("getBindingDetail")) {
111 JAXB.marshal(new GetBindingDetail(), sw);
112 }
113 if (method.equalsIgnoreCase("getBusinessDetail")) {
114 JAXB.marshal(new GetBusinessDetail(), sw);
115 }
116 if (method.equalsIgnoreCase("getServiceDetail")) {
117 JAXB.marshal(new GetServiceDetail(), sw);
118 }
119 if (method.equalsIgnoreCase("getOperationalInfo")) {
120 JAXB.marshal(new GetOperationalInfo(), sw);
121 }
122 if (method.equalsIgnoreCase("getTModelDetail")) {
123 JAXB.marshal(new GetTModelDetail(), sw);
124 }
125 return prettyPrintXML(sw.toString());
126 }
127
128 public static String getPublish(String method) {
129 StringWriter sw = new StringWriter();
130 if (method.equalsIgnoreCase("addPublisherAssertions")) {
131 JAXB.marshal(new AddPublisherAssertions(), sw);
132 }
133 if (method.equalsIgnoreCase("deleteBinding")) {
134 JAXB.marshal(new DeleteBinding(), sw);
135 }
136 if (method.equalsIgnoreCase("deleteBusiness")) {
137 JAXB.marshal(new DeleteBusiness(), sw);
138 }
139 if (method.equalsIgnoreCase("deletePublisherAssertions")) {
140 JAXB.marshal(new DeletePublisherAssertions(), sw);
141 }
142 if (method.equalsIgnoreCase("deleteService")) {
143 JAXB.marshal(new DeleteService(), sw);
144 }
145 if (method.equalsIgnoreCase("deleteTModel")) {
146 JAXB.marshal(new DeleteTModel(), sw);
147 }
148 if (method.equalsIgnoreCase("getAssertionStatusReport")) {
149 JAXB.marshal(new GetAssertionStatusReport(), sw);
150 }
151 if (method.equalsIgnoreCase("getPublisherAssertions")) {
152 JAXB.marshal(new GetPublisherAssertions(), sw);
153 }
154 if (method.equalsIgnoreCase("getRegisteredInfo")) {
155 JAXB.marshal(new GetRegisteredInfo(), sw);
156 }
157 if (method.equalsIgnoreCase("saveBinding")) {
158 JAXB.marshal(new SaveBinding(), sw);
159 }
160 if (method.equalsIgnoreCase("saveBusiness")) {
161 JAXB.marshal(new SaveBusiness(), sw);
162 }
163 if (method.equalsIgnoreCase("saveTModel")) {
164 JAXB.marshal(new SaveTModel(), sw);
165 }
166 if (method.equalsIgnoreCase("saveService")) {
167 JAXB.marshal(new SaveService(), sw);
168 }
169 if (method.equalsIgnoreCase("setPublisherAssertions")) {
170 JAXB.marshal(new SetPublisherAssertions(), sw);
171 }
172 return prettyPrintXML(sw.toString());
173 }
174
175 public static String getCustody(String method) {
176 StringWriter sw = new StringWriter();
177 if (method.equalsIgnoreCase("discardTransferToken")) {
178 JAXB.marshal(new DiscardTransferToken(), sw);
179 }
180 if (method.equalsIgnoreCase("getTransferToken")) {
181 JAXB.marshal(new GetTransferToken(), sw);
182 }
183 if (method.equalsIgnoreCase("transferEntities")) {
184 JAXB.marshal(new TransferEntities(), sw);
185 }
186 return prettyPrintXML(sw.toString());
187 }
188
189 public static String getSubscription(String method) {
190 StringWriter sw = new StringWriter();
191 if (method.equalsIgnoreCase("deleteSubscription")) {
192 JAXB.marshal(new DeleteSubscription(), sw);
193 }
194 if (method.equalsIgnoreCase("getSubscriptionResults")) {
195 JAXB.marshal(new GetSubscriptionResults(), sw);
196 }
197 if (method.equalsIgnoreCase("getSubscriptions")) {
198 JAXB.marshal(new GetSubscriptions(), sw);
199 }
200 if (method.equalsIgnoreCase("saveSubscription")) {
201 JAXB.marshal(new SaveSubscription(), sw);
202 }
203 return prettyPrintXML(sw.toString());
204 }
205 public static final String custody = "custody";
206 public static final String inquiry = "inquiry";
207 public static final String publish = "publish";
208 public static final String subscription = "subscription";
209
210 public static Object getObject(String service, String method, String content) {
211 if (service.equalsIgnoreCase(inquiry)) {
212 return getObjectInquiry(method, content);
213 }
214 if (service.equalsIgnoreCase(publish)) {
215 return getObjectPublish(method, content);
216 }
217 if (service.equalsIgnoreCase(custody)) {
218 return getObjectCustody(method, content);
219 }
220 if (service.equalsIgnoreCase(subscription)) {
221 return getObjectSubscription(method, content);
222 }
223 return null;
224
225 }
226
227 private static Object getObjectInquiry(String method, String content) {
228 StringReader sr = new StringReader(content);
229 if (method.equalsIgnoreCase("findBinding")) {
230 return JAXBunmarshal(sr, FindBinding.class);
231 }
232 if (method.equalsIgnoreCase("findBusiness")) {
233 return JAXBunmarshal(sr, FindBusiness.class);
234 }
235 if (method.equalsIgnoreCase("findService")) {
236 return JAXBunmarshal(sr, FindService.class);
237 }
238 if (method.equalsIgnoreCase("findRelatedBusines")) {
239 return JAXBunmarshal(sr, FindRelatedBusinesses.class);
240 }
241 if (method.equalsIgnoreCase("findTModel")) {
242 return JAXBunmarshal(sr, FindTModel.class);
243 }
244 if (method.equalsIgnoreCase("getBindingDetail")) {
245 return JAXBunmarshal(sr, GetBindingDetail.class);
246 }
247 if (method.equalsIgnoreCase("getBusinessDetail")) {
248 return JAXBunmarshal(sr, GetBusinessDetail.class);
249 }
250 if (method.equalsIgnoreCase("getServiceDetail")) {
251 return JAXBunmarshal(sr, GetServiceDetail.class);
252 }
253 if (method.equalsIgnoreCase("getOperationalInfo")) {
254 return JAXBunmarshal(sr, GetOperationalInfo.class);
255 }
256 if (method.equalsIgnoreCase("getTModelDetail")) {
257 return JAXBunmarshal(sr, GetTModelDetail.class);
258 }
259 return null;
260 }
261
262 private static Object getObjectPublish(String method, String content) {
263 StringReader sr = new StringReader(content);
264 if (method.equalsIgnoreCase("addPublisherAssertions")) {
265 return JAXBunmarshal(sr, AddPublisherAssertions.class);
266 }
267 if (method.equalsIgnoreCase("deleteBinding")) {
268 return JAXBunmarshal(sr, DeleteBinding.class);
269 }
270 if (method.equalsIgnoreCase("deleteBusiness")) {
271 return JAXBunmarshal(sr, DeleteBusiness.class);
272 }
273 if (method.equalsIgnoreCase("deletePublisherAssertions")) {
274 return JAXBunmarshal(sr, DeletePublisherAssertions.class);
275 }
276 if (method.equalsIgnoreCase("deleteService")) {
277 return JAXBunmarshal(sr, DeleteService.class);
278 }
279 if (method.equalsIgnoreCase("deleteTModel")) {
280 return JAXBunmarshal(sr, DeleteTModel.class);
281 }
282 if (method.equalsIgnoreCase("getAssertionStatusReport")) {
283 return JAXBunmarshal(sr, GetAssertionStatusReport.class);
284 }
285 if (method.equalsIgnoreCase("getPublisherAssertions")) {
286 return JAXBunmarshal(sr, GetPublisherAssertions.class);
287 }
288 if (method.equalsIgnoreCase("getRegisteredInfo")) {
289 return JAXBunmarshal(sr, GetRegisteredInfo.class);
290 }
291 if (method.equalsIgnoreCase("saveBinding")) {
292 return JAXBunmarshal(sr, SaveBinding.class);
293 }
294 if (method.equalsIgnoreCase("saveBusiness")) {
295 return JAXBunmarshal(sr, SaveBusiness.class);
296 }
297 if (method.equalsIgnoreCase("saveTModel")) {
298 return JAXBunmarshal(sr, SaveTModel.class);
299 }
300 if (method.equalsIgnoreCase("saveService")) {
301 return JAXBunmarshal(sr, SaveService.class);
302 }
303 if (method.equalsIgnoreCase("setPublisherAssertions")) {
304 return JAXBunmarshal(sr, SetPublisherAssertions.class);
305 }
306 return null;
307 }
308
309 private static Object JAXBunmarshal(StringReader content, Class clazz) {
310 return XmlUtils.unmarshal(content, clazz);
311 }
312
313 private static Object getObjectCustody(String method, String content) {
314 StringReader sr = new StringReader(content);
315 if (method.equalsIgnoreCase("discardTransferToken")) {
316 return JAXBunmarshal(sr, SetPublisherAssertions.class);
317 }
318 if (method.equalsIgnoreCase("getTransferToken")) {
319 return JAXBunmarshal(sr, SetPublisherAssertions.class);
320 }
321 if (method.equalsIgnoreCase("transferEntities")) {
322 return JAXBunmarshal(sr, SetPublisherAssertions.class);
323 }
324 return null;
325 }
326
327 private static Object getObjectSubscription(String method, String content) {
328 StringReader sr = new StringReader(content);
329 if (method.equalsIgnoreCase("deleteSubscription")) {
330 return JAXBunmarshal(sr, DeleteSubscription.class);
331 }
332 if (method.equalsIgnoreCase("getSubscriptionResults")) {
333 return JAXBunmarshal(sr, GetSubscriptionResults.class);
334 }
335 if (method.equalsIgnoreCase("getSubscriptions")) {
336 return JAXBunmarshal(sr, GetSubscriptions.class);
337 }
338 if (method.equalsIgnoreCase("saveSubscription")) {
339 return JAXBunmarshal(sr, SaveSubscription.class);
340 }
341 return null;
342 }
343 }