1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.IRegistry; 21 import org.apache.juddi.datatype.Address; 22 import org.apache.juddi.datatype.AddressLine; 23 import org.apache.juddi.datatype.CategoryBag; 24 import org.apache.juddi.datatype.Description; 25 import org.apache.juddi.datatype.DiscoveryURL; 26 import org.apache.juddi.datatype.DiscoveryURLs; 27 import org.apache.juddi.datatype.Email; 28 import org.apache.juddi.datatype.IdentifierBag; 29 import org.apache.juddi.datatype.KeyedReference; 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.Contact; 42 import org.apache.juddi.datatype.business.Contacts; 43 import org.apache.juddi.datatype.response.BusinessDetail; 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 ; 48 49 55 public class BusinessDetailHandler extends AbstractHandler 56 { 57 public static final String TAG_NAME = "businessDetail"; 58 59 private HandlerMaker maker = null; 60 61 protected BusinessDetailHandler(HandlerMaker maker) 62 { 63 this.maker = maker; 64 } 65 66 public RegistryObject unmarshal(Element element) 67 { 68 BusinessDetail obj = new BusinessDetail(); 69 Vector nodeList = null; 70 AbstractHandler handler = null; 71 72 76 obj.setGeneric(element.getAttribute("generic")); 78 obj.setOperator(element.getAttribute("operator")); 79 80 84 String truncValue = element.getAttribute("truncated"); 85 if (truncValue != null) 86 obj.setTruncated(truncValue.equalsIgnoreCase("true")); 87 88 91 nodeList = XMLUtils.getChildElementsByTagName(element,BusinessEntityHandler.TAG_NAME); 93 for (int i=0; i<nodeList.size(); i++) 94 { 95 handler = maker.lookup(BusinessEntityHandler.TAG_NAME); 96 obj.addBusinessEntity((BusinessEntity)handler.unmarshal((Element )nodeList.elementAt(i))); 97 } 98 99 return obj; 100 } 101 102 public void marshal(RegistryObject object,Element parent) 103 { 104 BusinessDetail detail = (BusinessDetail)object; 105 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 106 AbstractHandler handler = null; 107 108 String generic = detail.getGeneric(); 109 if ((generic != null) && (generic.trim().length() > 0)) 110 { 111 element.setAttribute("generic",generic); 112 113 if (generic.equals(IRegistry.UDDI_V1_GENERIC)) 114 element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE); 115 else if (generic.equals(IRegistry.UDDI_V2_GENERIC)) 116 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 117 else if (generic.equals(IRegistry.UDDI_V3_GENERIC)) 118 element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE); 119 } 120 else { 122 element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC); 123 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 124 } 125 126 String operator = detail.getOperator(); 127 if (operator != null) 128 element.setAttribute("operator",operator); 129 else 130 element.setAttribute("operator",""); 131 132 boolean truncated = detail.isTruncated(); 133 if (truncated) 134 element.setAttribute("truncated","true"); 135 136 Vector vector = detail.getBusinessEntityVector(); 137 if ((vector!=null) && (vector.size() > 0)) 138 { 139 handler = maker.lookup(BusinessEntityHandler.TAG_NAME); 140 for (int i=0; i < vector.size(); i++) 141 handler.marshal((BusinessEntity)vector.elementAt(i),element); 142 } 143 144 parent.appendChild(element); 145 } 146 147 148 149 150 151 152 153 public static void main(String args[]) 154 throws Exception 155 { 156 HandlerMaker maker = HandlerMaker.getInstance(); 157 AbstractHandler handler = maker.lookup(BusinessEntityHandler.TAG_NAME); 158 Element parent = XMLUtils.newRootElement(); 159 Element child = null; 160 161 OverviewDoc overDoc = new OverviewDoc(); 162 overDoc.setOverviewURL("http://www.sviens.com/service.html"); 163 overDoc.addDescription(new Description("over-doc Descr")); 164 overDoc.addDescription(new Description("over-doc Descr Two","en")); 165 166 InstanceDetails instDetails = new InstanceDetails(); 167 instDetails.addDescription(new Description("body-isa-wunder")); 168 instDetails.addDescription(new Description("sweetchild-o-mine","it")); 169 instDetails.setInstanceParms("inst-det parameters"); 170 instDetails.setOverviewDoc(overDoc); 171 172 TModelInstanceInfo tModInstInfo = new TModelInstanceInfo(); 173 tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9"); 174 tModInstInfo.addDescription(new Description("tMod-Inst-Info")); 175 tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es")); 176 tModInstInfo.setInstanceDetails(instDetails); 177 178 TModelInstanceDetails tModInstDet = new TModelInstanceDetails(); 179 tModInstDet.addTModelInstanceInfo(tModInstInfo); 180 181 BindingTemplate binding = new BindingTemplate(); 182 binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a"); 183 binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31"); 184 binding.addDescription(new Description("whatever")); 185 binding.addDescription(new Description("whatever too","fr")); 186 binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0")); 187 binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl")); 188 binding.setTModelInstanceDetails(tModInstDet); 189 190 BindingTemplates bindings = new BindingTemplates(); 191 bindings.addBindingTemplate(binding); 192 193 CategoryBag catBag = new CategoryBag(); 194 catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue")); 195 catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","catBagKeyName2","catBagKeyValue2")); 196 197 IdentifierBag idBag = new IdentifierBag(); 198 idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue")); 199 idBag.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2")); 200 201 DiscoveryURLs discURLs = new DiscoveryURLs(); 202 discURLs.addDiscoveryURL(new DiscoveryURL("http","http://www.sviens.com/service.wsdl")); 203 discURLs.addDiscoveryURL(new DiscoveryURL("https","https://www.sviens.com/service.wsdl")); 204 discURLs.addDiscoveryURL(new DiscoveryURL("smtp","servicemngr@sviens.com")); 205 206 Address address = new Address(); 207 address.setUseType("myAddressUseType"); 208 address.setSortCode("sortThis"); 209 address.setTModelKey(null); 210 address.addAddressLine(new AddressLine("AddressLine1","keyNameAttr","keyValueAttr")); 211 address.addAddressLine(new AddressLine("AddressLine2")); 212 213 Contact contact = new Contact(); 214 contact.setUseType("myAddressUseType"); 215 contact.setPersonNameValue("Bob Whatever"); 216 contact.addDescription(new Description("Bob is a big fat jerk")); 217 contact.addDescription(new Description("obBay sIay a igBay atFay erkJay","es")); 218 contact.addEmail(new Email("bob@whatever.com")); 219 contact.addPhone(new Phone("(603)559-1901")); 220 contact.addAddress(address); 221 222 Contacts contacts = new Contacts(); 223 contacts.addContact(contact); 224 225 BusinessService service = new BusinessService(); 226 service.setServiceKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f"); 227 service.setBusinessKey("b8cc7266-9eed-4675-b621-34697f252a77"); 228 service.setBindingTemplates(bindings); 229 service.setCategoryBag(catBag); 230 service.addName(new org.apache.juddi.datatype.Name("serviceNm")); 231 service.addName(new org.apache.juddi.datatype.Name("serviceNm2","en")); 232 service.addDescription(new Description("service whatever")); 233 service.addDescription(new Description("service whatever too","it")); 234 235 BusinessServices services = new BusinessServices(); 236 services.addBusinessService(service); 237 services.addBusinessService(service); 238 239 BusinessEntity business = new BusinessEntity(); 240 business.setBusinessKey("6c0ac186-d36b-4b81-bd27-066a5fe0fc1f"); 241 business.setAuthorizedName("Steve Viens"); 242 business.setOperator("jUDDI"); 243 business.addName(new org.apache.juddi.datatype.Name("businessNm")); 244 business.addName(new org.apache.juddi.datatype.Name("businessNm2","en")); 245 business.addDescription(new Description("business whatever")); 246 business.addDescription(new Description("business whatever too","fr")); 247 business.setDiscoveryURLs(discURLs); 248 business.setCategoryBag(catBag); 249 business.setIdentifierBag(idBag); 250 business.setContacts(contacts); 251 business.setBusinessServices(services); 252 253 BusinessDetail detail = new BusinessDetail(); 254 detail.setGeneric("2.0"); 255 detail.setOperator("jUDDI.org"); 256 detail.setTruncated(false); 257 detail.addBusinessEntity(business); 258 detail.addBusinessEntity(business); 259 260 System.out.println(); 261 262 RegistryObject regObject = detail; 263 handler.marshal(regObject,parent); 264 child = (Element )parent.getFirstChild(); 265 parent.removeChild(child); 266 XMLUtils.writeXML(child,System.out); 267 268 System.out.println(); 269 270 regObject = handler.unmarshal(child); 271 handler.marshal(regObject,parent); 272 child = (Element )parent.getFirstChild(); 273 parent.removeChild(child); 274 XMLUtils.writeXML(child,System.out); 275 } 276 }
| Popular Tags
|