KickJava   Java API By Example, From Geeks To Geeks.

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


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.Address;
21 import org.apache.juddi.datatype.AddressLine;
22 import org.apache.juddi.datatype.CategoryBag;
23 import org.apache.juddi.datatype.Description;
24 import org.apache.juddi.datatype.DiscoveryURL;
25 import org.apache.juddi.datatype.DiscoveryURLs;
26 import org.apache.juddi.datatype.Email;
27 import org.apache.juddi.datatype.IdentifierBag;
28 import org.apache.juddi.datatype.KeyedReference;
29 import org.apache.juddi.datatype.Name;
30 import org.apache.juddi.datatype.OverviewDoc;
31 import org.apache.juddi.datatype.Phone;
32 import org.apache.juddi.datatype.RegistryObject;
33 import org.apache.juddi.datatype.binding.AccessPoint;
34 import org.apache.juddi.datatype.binding.BindingTemplate;
35 import org.apache.juddi.datatype.binding.BindingTemplates;
36 import org.apache.juddi.datatype.binding.HostingRedirector;
37 import org.apache.juddi.datatype.binding.InstanceDetails;
38 import org.apache.juddi.datatype.binding.TModelInstanceDetails;
39 import org.apache.juddi.datatype.binding.TModelInstanceInfo;
40 import org.apache.juddi.datatype.business.BusinessEntity;
41 import org.apache.juddi.datatype.business.BusinessEntityExt;
42 import org.apache.juddi.datatype.business.Contact;
43 import org.apache.juddi.datatype.business.Contacts;
44 import org.apache.juddi.datatype.service.BusinessService;
45 import org.apache.juddi.datatype.service.BusinessServices;
46 import org.apache.juddi.util.xml.XMLUtils;
47 import org.w3c.dom.Element JavaDoc;
48
49 /**
50  * BusinessEntityExtHandler
51  *
52  * @author Steve Viens (sviens@apache.org)
53  */

54 public class BusinessEntityExtHandler extends AbstractHandler
55 {
56   public static final String JavaDoc TAG_NAME = "businessEntityExt";
57
58   private HandlerMaker maker = null;
59
60   protected BusinessEntityExtHandler(HandlerMaker maker)
61   {
62     this.maker = maker;
63   }
64
65   public RegistryObject unmarshal(Element JavaDoc element)
66   {
67     BusinessEntityExt obj = new BusinessEntityExt();
68     Vector JavaDoc nodeList = null;
69     AbstractHandler handler = null;
70
71     // Attributes
72

73     // Text Node Value
74
// {none}
75

76     // Child Elements
77
nodeList = XMLUtils.getChildElementsByTagName(element,BusinessEntityHandler.TAG_NAME);
78     if (nodeList.size() > 0)
79     {
80       handler = maker.lookup(BusinessEntityHandler.TAG_NAME);
81       obj.setBusinessEntity((BusinessEntity)handler.unmarshal((Element JavaDoc)nodeList.elementAt(0)));
82     }
83
84     return obj;
85   }
86
87   public void marshal(RegistryObject object,Element JavaDoc parent)
88   {
89     BusinessEntityExt businessExt = (BusinessEntityExt)object;
90     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
91     AbstractHandler handler = null;
92
93     BusinessEntity business = businessExt.getBusinessEntity();
94     if (business != null)
95     {
96       handler = maker.lookup(BusinessEntityHandler.TAG_NAME);
97       handler.marshal(business,element);
98     }
99
100     parent.appendChild(element);
101   }
102
103
104   /***************************************************************************/
105   /***************************** TEST DRIVER *********************************/
106   /***************************************************************************/
107
108
109   public static void main(String JavaDoc args[])
110     throws Exception JavaDoc
111   {
112     HandlerMaker maker = HandlerMaker.getInstance();
113     AbstractHandler handler = maker.lookup(BusinessEntityExtHandler.TAG_NAME);
114     Element JavaDoc parent = XMLUtils.newRootElement();
115     Element JavaDoc child = null;
116
117     OverviewDoc overDoc = new OverviewDoc();
118     overDoc.setOverviewURL("http://www.sviens.com/service.html");
119     overDoc.addDescription(new Description("over-doc Descr"));
120     overDoc.addDescription(new Description("over-doc Descr Two","en"));
121
122     InstanceDetails instDetails = new InstanceDetails();
123     instDetails.addDescription(new Description("body-isa-wunder"));
124     instDetails.addDescription(new Description("sweetchild-o-mine","it"));
125     instDetails.setInstanceParms("inst-det parameters");
126     instDetails.setOverviewDoc(overDoc);
127
128     TModelInstanceInfo tModInstInfo = new TModelInstanceInfo();
129     tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9");
130     tModInstInfo.addDescription(new Description("tMod-Inst-Info"));
131     tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es"));
132     tModInstInfo.setInstanceDetails(instDetails);
133
134     TModelInstanceDetails tModInstDet = new TModelInstanceDetails();
135     tModInstDet.addTModelInstanceInfo(tModInstInfo);
136
137     BindingTemplate binding = new BindingTemplate();
138     binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a");
139     binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31");
140     binding.addDescription(new Description("whatever"));
141     binding.addDescription(new Description("whatever too","fr"));
142     binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0"));
143     binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl"));
144     binding.setTModelInstanceDetails(tModInstDet);
145
146     BindingTemplates bindings = new BindingTemplates();
147     bindings.addBindingTemplate(binding);
148
149     CategoryBag catBag = new CategoryBag();
150     catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue"));
151     catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","catBagKeyName2","catBagKeyValue2"));
152
153     IdentifierBag idBag = new IdentifierBag();
154     idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue"));
155     idBag.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2"));
156
157     DiscoveryURLs discURLs = new DiscoveryURLs();
158     discURLs.addDiscoveryURL(new DiscoveryURL("http","http://www.sviens.com/service.wsdl"));
159     discURLs.addDiscoveryURL(new DiscoveryURL("https","https://www.sviens.com/service.wsdl"));
160     discURLs.addDiscoveryURL(new DiscoveryURL("smtp","servicemngr@sviens.com"));
161
162     Address address = new Address();
163     address.setUseType("myAddressUseType");
164     address.setSortCode("sortThis");
165     address.setTModelKey(null);
166     address.addAddressLine(new AddressLine("AddressLine1","keyNameAttr","keyValueAttr"));
167     address.addAddressLine(new AddressLine("AddressLine2"));
168
169     Contact contact = new Contact();
170     contact.setUseType("myAddressUseType");
171     contact.setPersonNameValue("Bob Whatever");
172     contact.addDescription(new Description("Bob is a big fat jerk"));
173     contact.addDescription(new Description("obBay sIay a igBay atFay erkJay","es"));
174     contact.addEmail(new Email("bob@whatever.com"));
175     contact.addPhone(new Phone("(603)559-1901"));
176     contact.addAddress(address);
177
178     Contacts contacts = new Contacts();
179     contacts.addContact(contact);
180
181     BusinessService service = new BusinessService();
182     service.setServiceKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f");
183     service.setBusinessKey("b8cc7266-9eed-4675-b621-34697f252a77");
184     service.setBindingTemplates(bindings);
185     service.setCategoryBag(catBag);
186     service.addName(new Name("serviceNm"));
187     service.addName(new Name("serviceNm2","en"));
188     service.addDescription(new Description("service whatever"));
189     service.addDescription(new Description("service whatever too","it"));
190
191     BusinessServices services = new BusinessServices();
192     services.addBusinessService(service);
193     services.addBusinessService(service);
194
195     BusinessEntity business = new BusinessEntity();
196     business.setBusinessKey("6c0ac186-d36b-4b81-bd27-066a5fe0fc1f");
197     business.setAuthorizedName("Steve Viens");
198     business.setOperator("jUDDI");
199     business.addName(new Name("businessNm"));
200     business.addName(new Name("businessNm2","en"));
201     business.addDescription(new Description("business whatever"));
202     business.addDescription(new Description("business whatever too","fr"));
203     business.setDiscoveryURLs(discURLs);
204     business.setCategoryBag(catBag);
205     business.setIdentifierBag(idBag);
206     business.setContacts(contacts);
207     business.setBusinessServices(services);
208
209     BusinessEntityExt businessExt = new BusinessEntityExt();
210     businessExt.setBusinessEntity(business);
211
212     System.out.println();
213
214     RegistryObject regObject = businessExt;
215     handler.marshal(regObject,parent);
216     child = (Element JavaDoc)parent.getFirstChild();
217     parent.removeChild(child);
218     XMLUtils.writeXML(child,System.out);
219
220     System.out.println();
221
222     regObject = handler.unmarshal(child);
223     handler.marshal(regObject,parent);
224     child = (Element JavaDoc)parent.getFirstChild();
225     parent.removeChild(child);
226     XMLUtils.writeXML(child,System.out);
227   }
228 }
Popular Tags