KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > handler > BusinessServiceHandler


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.handler;
17
18 import java.util.Vector JavaDoc;
19
20 import org.apache.juddi.datatype.CategoryBag;
21 import org.apache.juddi.datatype.Description;
22 import org.apache.juddi.datatype.KeyedReference;
23 import org.apache.juddi.datatype.Name;
24 import org.apache.juddi.datatype.OverviewDoc;
25 import org.apache.juddi.datatype.RegistryObject;
26 import org.apache.juddi.datatype.binding.AccessPoint;
27 import org.apache.juddi.datatype.binding.BindingTemplate;
28 import org.apache.juddi.datatype.binding.BindingTemplates;
29 import org.apache.juddi.datatype.binding.HostingRedirector;
30 import org.apache.juddi.datatype.binding.InstanceDetails;
31 import org.apache.juddi.datatype.binding.TModelInstanceDetails;
32 import org.apache.juddi.datatype.binding.TModelInstanceInfo;
33 import org.apache.juddi.datatype.service.BusinessService;
34 import org.apache.juddi.util.xml.XMLUtils;
35 import org.w3c.dom.Element JavaDoc;
36
37 /**
38  * BusinessServiceHandler
39  *
40  * @author Steve Viens (sviens@apache.org)
41  */

42 public class BusinessServiceHandler extends AbstractHandler
43 {
44   public static final String JavaDoc TAG_NAME = "businessService";
45
46   private HandlerMaker maker = null;
47
48   protected BusinessServiceHandler(HandlerMaker maker)
49   {
50     this.maker = maker;
51   }
52
53   public RegistryObject unmarshal(Element JavaDoc element)
54   {
55     BusinessService obj = new BusinessService();
56     Vector JavaDoc nodeList = null;
57     AbstractHandler handler = null;
58
59     // Attributes
60
obj.setBusinessKey(element.getAttribute("businessKey"));
61     obj.setServiceKey(element.getAttribute("serviceKey"));
62
63     // Text Node Value
64
// {none}
65

66     // Child Elements
67
nodeList = XMLUtils.getChildElementsByTagName(element,NameHandler.TAG_NAME);
68     for (int i=0; i<nodeList.size(); i++)
69     {
70       handler = maker.lookup(NameHandler.TAG_NAME);
71       Name name = (Name )handler.unmarshal((Element JavaDoc)nodeList.elementAt(i));
72       if (name != null)
73         obj.addName(name);
74     }
75
76     nodeList = XMLUtils.getChildElementsByTagName(element,DescriptionHandler.TAG_NAME);
77     for (int i=0; i<nodeList.size(); i++)
78     {
79       handler = maker.lookup(DescriptionHandler.TAG_NAME);
80       Description descr = (Description)handler.unmarshal((Element JavaDoc)nodeList.elementAt(i));
81       if (descr != null)
82         obj.addDescription(descr);
83     }
84
85     nodeList = XMLUtils.getChildElementsByTagName(element,BindingTemplatesHandler.TAG_NAME);
86     if (nodeList.size() > 0)
87     {
88       handler = maker.lookup(BindingTemplatesHandler.TAG_NAME);
89       obj.setBindingTemplates((BindingTemplates)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
90     }
91
92     nodeList = XMLUtils.getChildElementsByTagName(element,CategoryBagHandler.TAG_NAME);
93     if (nodeList.size() > 0)
94     {
95       handler = maker.lookup(CategoryBagHandler.TAG_NAME);
96       obj.setCategoryBag((CategoryBag)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
97     }
98
99     return obj;
100   }
101
102   public void marshal(RegistryObject object,Element JavaDoc parent)
103   {
104     BusinessService service = (BusinessService)object;
105     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
106     AbstractHandler handler = null;
107
108     String JavaDoc serviceKey = service.getServiceKey();
109     if (serviceKey != null)
110       element.setAttribute("serviceKey",serviceKey);
111     else
112       element.setAttribute("serviceKey","");
113
114     String JavaDoc businessKey = service.getBusinessKey();
115     if (businessKey != null)
116       element.setAttribute("businessKey",businessKey);
117
118     Vector JavaDoc nameVector = service.getNameVector();
119     if ((nameVector!=null) && (nameVector.size() > 0))
120     {
121       handler = maker.lookup(NameHandler.TAG_NAME);
122       for (int i=0; i < nameVector.size(); i++)
123         handler.marshal((Name)nameVector.elementAt(i),element);
124     }
125
126     Vector JavaDoc descrVector = service.getDescriptionVector();
127     if ((descrVector!=null) && (descrVector.size() > 0))
128     {
129       handler = maker.lookup(DescriptionHandler.TAG_NAME);
130       for (int i=0; i < descrVector.size(); i++)
131         handler.marshal((Description)descrVector.elementAt(i),element);
132     }
133
134     BindingTemplates bindings = service.getBindingTemplates();
135     if (bindings != null)
136     {
137       handler = maker.lookup(BindingTemplatesHandler.TAG_NAME);
138       handler.marshal(bindings,element);
139     }
140
141     CategoryBag categoryBag = service.getCategoryBag();
142     if ((categoryBag != null) && (categoryBag.getKeyedReferenceVector() != null) && (!categoryBag.getKeyedReferenceVector().isEmpty()))
143     {
144       handler = maker.lookup(CategoryBagHandler.TAG_NAME);
145       handler.marshal(categoryBag,element);
146     }
147
148     parent.appendChild(element);
149   }
150
151
152   /***************************************************************************/
153   /***************************** TEST DRIVER *********************************/
154   /***************************************************************************/
155
156
157   public static void main(String JavaDoc args[])
158     throws Exception JavaDoc
159   {
160     HandlerMaker maker = HandlerMaker.getInstance();
161     AbstractHandler handler = maker.lookup(BusinessServiceHandler.TAG_NAME);
162     Element JavaDoc parent = XMLUtils.newRootElement();
163     Element JavaDoc child = null;
164
165     OverviewDoc overDoc = new OverviewDoc();
166     overDoc.setOverviewURL("http://www.sviens.com/service.html");
167     overDoc.addDescription(new Description("over-doc Descr"));
168     overDoc.addDescription(new Description("over-doc Descr Two","en"));
169
170     InstanceDetails instDetails = new InstanceDetails();
171     instDetails.addDescription(new Description("body-isa-wunder"));
172     instDetails.addDescription(new Description("sweetchild-o-mine","it"));
173     instDetails.setInstanceParms("inst-det parameters");
174     instDetails.setOverviewDoc(overDoc);
175
176     TModelInstanceInfo tModInstInfo = new TModelInstanceInfo();
177     tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9");
178     tModInstInfo.addDescription(new Description("tMod-Inst-Info"));
179     tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es"));
180     tModInstInfo.setInstanceDetails(instDetails);
181
182     TModelInstanceDetails tModInstDet = new TModelInstanceDetails();
183     tModInstDet.addTModelInstanceInfo(tModInstInfo);
184
185     BindingTemplate binding = new BindingTemplate();
186     binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a");
187     binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31");
188     binding.addDescription(new Description("whatever"));
189     binding.addDescription(new Description("whatever too","fr"));
190     binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0"));
191     binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl"));
192     binding.setTModelInstanceDetails(tModInstDet);
193
194     BindingTemplates bindings = new BindingTemplates();
195     bindings.addBindingTemplate(binding);
196
197     CategoryBag catBag = new CategoryBag();
198     catBag.addKeyedReference(new KeyedReference("keyName","keyValue"));
199     catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","keyName2","keyValue2"));
200
201     BusinessService service = new BusinessService();
202     service.setServiceKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f");
203     service.setBusinessKey("b8cc7266-9eed-4675-b621-34697f252a77");
204     service.setBindingTemplates(bindings);
205     service.setCategoryBag(catBag);
206     service.addName(new Name("serviceNm"));
207     service.addName(new Name("serviceNm2","en"));
208     service.addDescription(new Description("service whatever"));
209     service.addDescription(new Description("service whatever too","it"));
210
211     System.out.println();
212
213     RegistryObject regObject = service;
214     handler.marshal(regObject,parent);
215     child = (Element JavaDoc)parent.getFirstChild();
216     parent.removeChild(child);
217     XMLUtils.writeXML(child,System.out);
218
219     System.out.println();
220
221     regObject = handler.unmarshal(child);
222     handler.marshal(regObject,parent);
223     child = (Element JavaDoc)parent.getFirstChild();
224     parent.removeChild(child);
225     XMLUtils.writeXML(child,System.out);
226
227     System.out.println();
228
229
230 // String xml =
231
// "<businessService businessKey=\"34D599999999-4444-4444-4444-88888888\" " +
232
// "serviceKey=\"34D599999999-4444-4444-4444-88888888\">\n" +
233
// "<name>fred</name>\n" +
234
// "<description>desc one</description>" +
235
// "<bindingTemplates>\n" +
236
// "<bindingTemplate bindingKey=\"34D599999999-4444-4444-4444-33333333\">" +
237
// " serviceKey=\"34D599999999-4444-4444-4444-22222222\">\n" +
238
// "<description>whatever</description>" +
239
// "<description>whatever too</description>" +
240
// "<hostingRedirector bindingKey=\"999999999999-4444-4444-4444-88888888\"></hostingRedirector>" +
241
// "<tModelInstanceDetails>\n" +
242
// "<tModelInstanceInfo tModelKey=\"uuid:34D599999999-4444-5555-4444-88888888\">\n" +
243
// "<description>GR Proprietary XML purchase order</description>\n" +
244
// "<description> d1 </description>\n" +
245
// "</tModelInstanceInfo>\n" +
246
// "<tModelInstanceInfo tModelKey=\"uuid:34D599999999-4444-4444-4444-88888888\">\n" +
247
// "<description>Fred Proprietary XML purchase order</description>\n" +
248
// "<description> d2 </description>\n" +
249
// "</tModelInstanceInfo>\n" +
250
// "</tModelInstanceDetails>\n" +
251
// "</bindingTemplate>\n" +
252
// "</bindingTemplates>\n" +
253
// "<categoryBag>\n" +
254
// "<keyedReference tModelKey=\"uuid:999999999999-4444-4444-4444-88888888\"\n" +
255
// "keyName=\"name\" keyValue=\"value\"></keyedReference>\n" +
256
// "<keyedReference tModelKey=\"uuid:119999999999-4444-4444-4444-88888888\"\n" +
257
// "keyName=\"name of key\" keyValue=\"val\"></keyedReference>\n" +
258
// "</categoryBag>\n" +
259
// "</businessService>\n";
260
}
261 }
Popular Tags