KickJava   Java API By Example, From Geeks To Geeks.

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


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.datatype.service.BusinessServices;
35 import org.apache.juddi.util.xml.XMLUtils;
36 import org.w3c.dom.Element JavaDoc;
37
38 /**
39  * "Knows about the creation and populating of BusinessServices objects.
40  * Returns BusinessServices."
41  *
42  * @author Steve Viens (sviens@apache.org)
43  */

44 public class BusinessServicesHandler extends AbstractHandler
45 {
46   public static final String JavaDoc TAG_NAME = "businessServices";
47
48   private HandlerMaker maker = null;
49
50   protected BusinessServicesHandler(HandlerMaker maker)
51   {
52     this.maker = maker;
53   }
54
55   public RegistryObject unmarshal(Element JavaDoc element)
56   {
57     BusinessServices obj = new BusinessServices();
58     Vector JavaDoc nodeList = null;
59     AbstractHandler handler = null;
60
61     // Attributes
62
// {none}
63

64     // Text Node Value
65
// {none}
66

67     // Child Elements
68
nodeList = XMLUtils.getChildElementsByTagName(element,BusinessServiceHandler.TAG_NAME);
69     for (int i=0; i<nodeList.size(); i++)
70     {
71       handler = maker.lookup(BusinessServiceHandler.TAG_NAME);
72       obj.addBusinessService((BusinessService)handler.unmarshal((Element JavaDoc)nodeList.elementAt(i)));
73     }
74
75     return obj;
76   }
77
78   public void marshal(RegistryObject object,Element JavaDoc parent)
79   {
80     BusinessServices services = (BusinessServices)object;
81     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
82     AbstractHandler handler = null;
83
84     Vector JavaDoc serviceVector = services.getBusinessServiceVector();
85     if ((serviceVector!=null) && (serviceVector.size() > 0))
86     {
87       handler = maker.lookup(BusinessServiceHandler.TAG_NAME);
88       for (int i=0; i < serviceVector.size(); i++)
89         handler.marshal((BusinessService)serviceVector.elementAt(i),element);
90     }
91
92     parent.appendChild(element);
93   }
94
95
96   /***************************************************************************/
97   /***************************** TEST DRIVER *********************************/
98   /***************************************************************************/
99
100
101   public static void main(String JavaDoc args[])
102     throws Exception JavaDoc
103   {
104     HandlerMaker maker = HandlerMaker.getInstance();
105     AbstractHandler handler = maker.lookup(BusinessServicesHandler.TAG_NAME);
106     Element JavaDoc parent = XMLUtils.newRootElement();
107     Element JavaDoc child = null;
108
109     OverviewDoc overDoc = new OverviewDoc();
110     overDoc.setOverviewURL("http://www.sviens.com/service.html");
111     overDoc.addDescription(new Description("over-doc Descr"));
112     overDoc.addDescription(new Description("over-doc Descr Two","en"));
113
114     InstanceDetails instDetails = new InstanceDetails();
115     instDetails.addDescription(new Description("body-isa-wunder"));
116     instDetails.addDescription(new Description("sweetchild-o-mine","it"));
117     instDetails.setInstanceParms("inst-det parameters");
118     instDetails.setOverviewDoc(overDoc);
119
120     TModelInstanceInfo tModInstInfo = new TModelInstanceInfo();
121     tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9");
122     tModInstInfo.addDescription(new Description("tMod-Inst-Info"));
123     tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es"));
124     tModInstInfo.setInstanceDetails(instDetails);
125
126     TModelInstanceDetails tModInstDet = new TModelInstanceDetails();
127     tModInstDet.addTModelInstanceInfo(tModInstInfo);
128
129     BindingTemplate binding = new BindingTemplate();
130     binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a");
131     binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31");
132     binding.addDescription(new Description("whatever"));
133     binding.addDescription(new Description("whatever too","fr"));
134     binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0"));
135     binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl"));
136     binding.setTModelInstanceDetails(tModInstDet);
137
138     BindingTemplates bindings = new BindingTemplates();
139     bindings.addBindingTemplate(binding);
140
141     CategoryBag catBag = new CategoryBag();
142     catBag.addKeyedReference(new KeyedReference("keyName","keyValue"));
143     catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","keyName2","keyValue2"));
144
145     BusinessService service = new BusinessService();
146     service.setServiceKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f");
147     service.setBusinessKey("b8cc7266-9eed-4675-b621-34697f252a77");
148     service.setBindingTemplates(bindings);
149     service.setCategoryBag(catBag);
150     service.addName(new Name("serviceNm"));
151     service.addName(new Name("serviceNm2","en"));
152     service.addDescription(new Description("service whatever"));
153     service.addDescription(new Description("service whatever too","it"));
154
155     BusinessServices services = new BusinessServices();
156     services.addBusinessService(service);
157     services.addBusinessService(service);
158
159     System.out.println();
160
161     RegistryObject regObject = services;
162     handler.marshal(regObject,parent);
163     child = (Element JavaDoc)parent.getFirstChild();
164     parent.removeChild(child);
165     XMLUtils.writeXML(child,System.out);
166
167     System.out.println();
168
169     regObject = handler.unmarshal(child);
170     handler.marshal(regObject,parent);
171     child = (Element JavaDoc)parent.getFirstChild();
172     parent.removeChild(child);
173     XMLUtils.writeXML(child,System.out);
174
175     System.out.println();
176   }
177 }
Popular Tags