1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 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 ; 36 37 42 public class BusinessServiceHandler extends AbstractHandler 43 { 44 public static final String 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 element) 54 { 55 BusinessService obj = new BusinessService(); 56 Vector nodeList = null; 57 AbstractHandler handler = null; 58 59 obj.setBusinessKey(element.getAttribute("businessKey")); 61 obj.setServiceKey(element.getAttribute("serviceKey")); 62 63 66 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 )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 )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 )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 )nodeList.elementAt(0))); 97 } 98 99 return obj; 100 } 101 102 public void marshal(RegistryObject object,Element parent) 103 { 104 BusinessService service = (BusinessService)object; 105 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 106 AbstractHandler handler = null; 107 108 String serviceKey = service.getServiceKey(); 109 if (serviceKey != null) 110 element.setAttribute("serviceKey",serviceKey); 111 else 112 element.setAttribute("serviceKey",""); 113 114 String businessKey = service.getBusinessKey(); 115 if (businessKey != null) 116 element.setAttribute("businessKey",businessKey); 117 118 Vector 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 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 154 155 156 157 public static void main(String args[]) 158 throws Exception 159 { 160 HandlerMaker maker = HandlerMaker.getInstance(); 161 AbstractHandler handler = maker.lookup(BusinessServiceHandler.TAG_NAME); 162 Element parent = XMLUtils.newRootElement(); 163 Element 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 )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 )parent.getFirstChild(); 224 parent.removeChild(child); 225 XMLUtils.writeXML(child,System.out); 226 227 System.out.println(); 228 229 230 } 261 } | Popular Tags |