This project has retired. For details please refer to its
Attic page.
TckCommon xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.v2.tck;
17
18 import java.util.List;
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.uddi.api_v2.BindingTemplates;
22 import org.uddi.api_v2.BusinessEntity;
23 import org.uddi.api_v2.BusinessInfos;
24 import org.uddi.api_v2.BusinessList;
25 import org.uddi.api_v2.CategoryBag;
26 import org.uddi.api_v2.Contacts;
27 import org.uddi.api_v2.DeleteBusiness;
28 import org.uddi.api_v2.Description;
29 import org.uddi.api_v2.FindBusiness;
30 import org.uddi.api_v2.FindQualifiers;
31 import org.uddi.api_v2.FindService;
32 import org.uddi.api_v2.FindTModel;
33 import org.uddi.api_v2.KeyedReference;
34 import org.uddi.api_v2.Name;
35 import org.uddi.api_v2.ServiceInfos;
36 import org.uddi.api_v2.ServiceList;
37 import org.uddi.api_v2.TModelList;
38 import org.uddi.v2_service.*;
39
40
41
42
43
44
45
46 public class TckCommon {
47
48 private static Log logger = LogFactory.getLog(TckCommon.class);
49
50
51
52
53
54
55
56
57 public static String CatBagToString(CategoryBag categoryBag) {
58 StringBuilder sb = new StringBuilder();
59 if (categoryBag == null) {
60 return "no data";
61 }
62 for (int i = 0; i < categoryBag.getKeyedReference().size(); i++) {
63 sb.append(KeyedReferenceToString(categoryBag.getKeyedReference().get(i)));
64 }
65 return sb.toString();
66 }
67
68 public static String KeyedReferenceToString(KeyedReference item) {
69 StringBuilder sb = new StringBuilder();
70 sb.append("Key Ref: Name=").
71 append(item.getKeyName()).
72 append(" Value=").
73 append(item.getKeyValue()).
74 append(" tModel=").
75 append(item.getTModelKey()).
76 append(System.getProperty("line.separator"));
77 return sb.toString();
78 }
79
80 public static void PrintContacts(Contacts contacts) {
81 if (contacts == null) {
82 return;
83 }
84 for (int i = 0; i < contacts.getContact().size(); i++) {
85 System.out.println("Contact " + i + " type:" + contacts.getContact().get(i).getUseType());
86
87 System.out.println("Name: " + contacts.getContact().get(i).getPersonName());
88
89 for (int k = 0; k < contacts.getContact().get(i).getEmail().size(); k++) {
90 System.out.println("Email: " + contacts.getContact().get(i).getEmail().get(k).getValue());
91 }
92 for (int k = 0; k < contacts.getContact().get(i).getAddress().size(); k++) {
93 System.out.println("Address sort code " + contacts.getContact().get(i).getAddress().get(k).getSortCode());
94 System.out.println("Address use type " + contacts.getContact().get(i).getAddress().get(k).getUseType());
95 System.out.println("Address tmodel key " + contacts.getContact().get(i).getAddress().get(k).getTModelKey());
96 for (int x = 0; x < contacts.getContact().get(i).getAddress().get(k).getAddressLine().size(); x++) {
97 System.out.println("Address line value " + contacts.getContact().get(i).getAddress().get(k).getAddressLine().get(x).getValue());
98 System.out.println("Address line key name " + contacts.getContact().get(i).getAddress().get(k).getAddressLine().get(x).getKeyName());
99 System.out.println("Address line key value " + contacts.getContact().get(i).getAddress().get(k).getAddressLine().get(x).getKeyValue());
100 }
101 }
102 for (int k = 0; k < contacts.getContact().get(i).getDescription().size(); k++) {
103 System.out.println("Desc: " + contacts.getContact().get(i).getDescription().get(k).getValue());
104 }
105 for (int k = 0; k < contacts.getContact().get(i).getPhone().size(); k++) {
106 System.out.println("Phone: " + contacts.getContact().get(i).getPhone().get(k).getValue());
107 }
108 }
109
110 }
111
112
113
114
115
116
117
118 public static void PrintBindingTemplates(BindingTemplates bindingTemplates) {
119 if (bindingTemplates == null) {
120 return;
121 }
122 for (int i = 0; i < bindingTemplates.getBindingTemplate().size(); i++) {
123 System.out.println("Binding Key: " + bindingTemplates.getBindingTemplate().get(i).getBindingKey());
124
125 if (bindingTemplates.getBindingTemplate().get(i).getAccessPoint() != null) {
126 System.out.println("Access Point: " + bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getValue() + " type " + bindingTemplates.getBindingTemplate().get(i).getAccessPoint().getURLType().value());
127 }
128
129 if (bindingTemplates.getBindingTemplate().get(i).getHostingRedirector() != null) {
130 System.out.println("Hosting Redirection: " + bindingTemplates.getBindingTemplate().get(i).getHostingRedirector().getBindingKey());
131 }
132 }
133 }
134
135 public static void PrintBusinessInfo(BusinessInfos businessInfos) {
136 if (businessInfos == null) {
137 System.out.println("No data returned");
138 } else {
139 for (int i = 0; i < businessInfos.getBusinessInfo().size(); i++) {
140 System.out.println("===============================================");
141 System.out.println("Business Key: " + businessInfos.getBusinessInfo().get(i).getBusinessKey());
142 System.out.println("Name: " + ListToString(businessInfos.getBusinessInfo().get(i).getName()));
143
144 System.out.println("Name: " + ListToDescString(businessInfos.getBusinessInfo().get(i).getDescription()));
145 System.out.println("Services:");
146 PrintServiceInfo(businessInfos.getBusinessInfo().get(i).getServiceInfos());
147 }
148 }
149 }
150
151 public static String ListToString(List<Name> name) {
152 StringBuilder sb = new StringBuilder();
153 for (int i = 0; i < name.size(); i++) {
154 sb.append(name.get(i).getValue()).append(" ");
155 }
156 return sb.toString();
157 }
158
159 public static String ListToDescString(List<Description> name) {
160 StringBuilder sb = new StringBuilder();
161 for (int i = 0; i < name.size(); i++) {
162 sb.append(name.get(i).getValue()).append(" ");
163 }
164 return sb.toString();
165 }
166
167 public static void PrintServiceInfo(ServiceInfos serviceInfos) {
168 for (int i = 0; i < serviceInfos.getServiceInfo().size(); i++) {
169 System.out.println("-------------------------------------------");
170 System.out.println("Service Key: " + serviceInfos.getServiceInfo().get(i).getServiceKey());
171 System.out.println("Owning Business Key: " + serviceInfos.getServiceInfo().get(i).getBusinessKey());
172 System.out.println("Name: " + ListToString(serviceInfos.getServiceInfo().get(i).getName()));
173 }
174 }
175
176 public static void PrintBusinessDetails(List<BusinessEntity> businessDetail) {
177
178
179 for (int i = 0; i < businessDetail.size(); i++) {
180 System.out.println("Business Detail - key: " + businessDetail.get(i).getBusinessKey());
181 System.out.println("Name: " + ListToString(businessDetail.get(i).getName()));
182 System.out.println("CategoryBag: " + CatBagToString(businessDetail.get(i).getCategoryBag()));
183 PrintContacts(businessDetail.get(i).getContacts());
184 }
185 }
186
187
188
189
190
191
192
193
194
195 public static void DeleteBusiness(String key, String authInfo, Publish publish) {
196 if (key == null) {
197 return;
198 }
199 try {
200 DeleteBusiness db = new DeleteBusiness();
201 db.setGeneric("2.0");
202 db.setAuthInfo(authInfo);
203 db.getBusinessKey().add(key);
204 publish.deleteBusiness(db);
205 } catch (Exception ex) {
206 logger.warn("failed to delete business " + key + " " + ex.getMessage());
207 logger.debug("failed to delete business " + key + " " + ex.getMessage(), ex);
208 }
209 }
210
211
212
213
214
215
216 public static boolean isDebug() {
217 boolean serialize = false;
218 try {
219 if (System.getProperty("debug") != null
220 && System.getProperty("debug").equalsIgnoreCase("true")) {
221 serialize = true;
222 }
223 } catch (Exception ex) {
224 }
225 return serialize;
226 }
227
228
229 public static String DumpAllServices(String authinfo, Inquire inquiry) {
230 StringBuilder sb = new StringBuilder();
231 FindService fs = new FindService();
232
233
234
235 fs.getName().add(new Name("%", null));
236 try {
237 ServiceList findService = inquiry.findService(fs);
238 if (findService.getServiceInfos() == null) {
239 return ("NO SERVICES RETURNED!");
240 } else {
241 for (int i = 0; i < findService.getServiceInfos().getServiceInfo().size(); i++) {
242 sb.append(findService.getServiceInfos().getServiceInfo().get(i).getName().get(0).getValue()).append(" lang=").append(findService.getServiceInfos().getServiceInfo().get(i).getName().get(0).getLang()).append(" ").append(findService.getServiceInfos().getServiceInfo().get(i).getServiceKey()).append(" ").append(findService.getServiceInfos().getServiceInfo().get(i).getBusinessKey()).append(
243 System.getProperty("line.separator"));
244 }
245 }
246 } catch (Exception ex) {
247 sb.append(ex.getMessage());
248 }
249 return sb.toString();
250 }
251
252
253 public static String DumpAllTModels(String authinfo, Inquire inquriy) {
254 StringBuilder sb = new StringBuilder();
255 FindTModel fs = new FindTModel();
256
257
258
259 fs.setName(new Name("%", null));
260 fs.setGeneric("2.0");
261 try {
262 TModelList findService = inquriy.findTModel(fs);
263 if (findService.getTModelInfos()== null) {
264 return ("NO TMODELS RETURNED!");
265 } else {
266 for (int i = 0; i < findService.getTModelInfos().getTModelInfo().size(); i++) {
267 sb.append(findService.getTModelInfos().getTModelInfo().get(i).getName().getValue()).
268 append(" lang=").append(findService.getTModelInfos().getTModelInfo().get(i).getName().getLang()).
269 append(" ").append(findService.getTModelInfos().getTModelInfo().get(i).getTModelKey())
270 .append(System.getProperty("line.separator"));
271 }
272 }
273 } catch (Exception ex) {
274 return ex.getMessage();
275 }
276 return sb.toString();
277 }
278 public static String DumpAllBusinesses(String authinfo, Inquire inquriy) {
279 StringBuilder sb = new StringBuilder();
280 FindBusiness fs = new FindBusiness();
281
282
283
284 fs.getName().add(new Name("%", null));
285 fs.setGeneric("2.0");
286 try {
287 BusinessList findService = inquriy.findBusiness(fs);
288 if (findService.getBusinessInfos() == null) {
289 return ("NO BUSINESSES RETURNED!");
290 } else {
291 for (int i = 0; i < findService.getBusinessInfos().getBusinessInfo().size(); i++) {
292 sb.append(findService.getBusinessInfos().getBusinessInfo().get(i).getName().get(0).getValue()).
293 append(" lang=").append(findService.getBusinessInfos().getBusinessInfo().get(i).getName().get(0).getLang()).
294 append(" ").append(findService.getBusinessInfos().getBusinessInfo().get(i).getBusinessKey())
295 .append(System.getProperty("line.separator"));
296 }
297 }
298 } catch (Exception ex) {
299 return ex.getMessage();
300 }
301 return sb.toString();
302 }
303
304 }