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