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.CategoryBag; 22 import org.apache.juddi.datatype.Description; 23 import org.apache.juddi.datatype.KeyedReference; 24 import org.apache.juddi.datatype.Name; 25 import org.apache.juddi.datatype.OverviewDoc; 26 import org.apache.juddi.datatype.RegistryObject; 27 import org.apache.juddi.datatype.binding.AccessPoint; 28 import org.apache.juddi.datatype.binding.BindingTemplate; 29 import org.apache.juddi.datatype.binding.BindingTemplates; 30 import org.apache.juddi.datatype.binding.HostingRedirector; 31 import org.apache.juddi.datatype.binding.InstanceDetails; 32 import org.apache.juddi.datatype.binding.TModelInstanceDetails; 33 import org.apache.juddi.datatype.binding.TModelInstanceInfo; 34 import org.apache.juddi.datatype.response.ServiceDetail; 35 import org.apache.juddi.datatype.service.BusinessService; 36 import org.apache.juddi.util.xml.XMLUtils; 37 import org.w3c.dom.Element ; 38 39 45 public class ServiceDetailHandler extends AbstractHandler 46 { 47 public static final String TAG_NAME = "serviceDetail"; 48 49 private HandlerMaker maker = null; 50 51 protected ServiceDetailHandler(HandlerMaker maker) 52 { 53 this.maker = maker; 54 } 55 56 public RegistryObject unmarshal(Element element) 57 { 58 ServiceDetail obj = new ServiceDetail(); 59 Vector nodeList = null; 60 AbstractHandler handler = null; 61 62 66 obj.setGeneric(element.getAttribute("generic")); 68 obj.setOperator(element.getAttribute("operator")); 69 70 74 String truncValue = element.getAttribute("truncated"); 75 if (truncValue != null) 76 obj.setTruncated(truncValue.equalsIgnoreCase("true")); 77 78 81 nodeList = XMLUtils.getChildElementsByTagName(element,BusinessServiceHandler.TAG_NAME); 83 for (int i=0; i<nodeList.size(); i++) 84 { 85 handler = maker.lookup(BusinessServiceHandler.TAG_NAME); 86 obj.addBusinessService((BusinessService)handler.unmarshal((Element )nodeList.elementAt(i))); 87 } 88 89 return obj; 90 } 91 92 public void marshal(RegistryObject object,Element parent) 93 { 94 ServiceDetail detail = (ServiceDetail)object; 95 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 96 AbstractHandler handler = null; 97 98 String generic = detail.getGeneric(); 99 if ((generic != null) && (generic.trim().length() > 0)) 100 { 101 element.setAttribute("generic",generic); 102 103 if (generic.equals(IRegistry.UDDI_V1_GENERIC)) 104 element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE); 105 else if (generic.equals(IRegistry.UDDI_V2_GENERIC)) 106 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 107 else if (generic.equals(IRegistry.UDDI_V3_GENERIC)) 108 element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE); 109 } 110 else { 112 element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC); 113 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 114 } 115 116 String operator = detail.getOperator(); 117 if (operator != null) 118 element.setAttribute("operator",operator); 119 else 120 element.setAttribute("operator",""); 121 122 boolean truncated = detail.isTruncated(); 123 if (truncated) 124 element.setAttribute("truncated","true"); 125 126 Vector vector = detail.getBusinessServiceVector(); 127 if ((vector!=null) && (vector.size() > 0)) 128 { 129 handler = maker.lookup(BusinessServiceHandler.TAG_NAME); 130 for (int i=0; i < vector.size(); i++) 131 handler.marshal((BusinessService)vector.elementAt(i),element); 132 } 133 134 parent.appendChild(element); 135 } 136 137 138 139 140 141 142 143 public static void main(String args[]) 144 throws Exception 145 { 146 HandlerMaker maker = HandlerMaker.getInstance(); 147 AbstractHandler handler = maker.lookup(ServiceDetailHandler.TAG_NAME); 148 149 Element parent = XMLUtils.newRootElement(); 150 Element child = null; 151 152 OverviewDoc overDoc = new OverviewDoc(); 153 overDoc.setOverviewURL("http://www.sviens.com/service.html"); 154 overDoc.addDescription(new Description("over-doc Descr")); 155 overDoc.addDescription(new Description("over-doc Descr Two","en")); 156 157 InstanceDetails instDetails = new InstanceDetails(); 158 instDetails.addDescription(new Description("body-isa-wunder")); 159 instDetails.addDescription(new Description("sweetchild-o-mine","it")); 160 instDetails.setInstanceParms("inst-det parameters"); 161 instDetails.setOverviewDoc(overDoc); 162 163 TModelInstanceInfo tModInstInfo = new TModelInstanceInfo(); 164 tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9"); 165 tModInstInfo.addDescription(new Description("tMod-Inst-Info")); 166 tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es")); 167 tModInstInfo.setInstanceDetails(instDetails); 168 169 TModelInstanceDetails tModInstDet = new TModelInstanceDetails(); 170 tModInstDet.addTModelInstanceInfo(tModInstInfo); 171 172 BindingTemplate binding = new BindingTemplate(); 173 binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a"); 174 binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31"); 175 binding.addDescription(new Description("whatever")); 176 binding.addDescription(new Description("whatever too","fr")); 177 binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0")); 178 binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl")); 179 binding.setTModelInstanceDetails(tModInstDet); 180 181 BindingTemplates bindings = new BindingTemplates(); 182 bindings.addBindingTemplate(binding); 183 184 CategoryBag catBag = new CategoryBag(); 185 catBag.addKeyedReference(new KeyedReference("keyName","keyValue")); 186 catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","keyName2","keyValue2")); 187 188 BusinessService service = new BusinessService(); 189 service.setServiceKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f"); 190 service.setBusinessKey("b8cc7266-9eed-4675-b621-34697f252a77"); 191 service.setBindingTemplates(bindings); 192 service.setCategoryBag(catBag); 193 service.addName(new Name("serviceNm")); 194 service.addName(new Name("serviceNm2","en")); 195 service.addDescription(new Description("service whatever")); 196 service.addDescription(new Description("service whatever too","it")); 197 198 ServiceDetail detail = new ServiceDetail(); 199 detail.setTruncated(false); 202 detail.addBusinessService(service); 203 detail.addBusinessService(service); 204 205 System.out.println(); 206 207 RegistryObject regObject = detail; 208 handler.marshal(regObject,parent); 209 child = (Element )parent.getFirstChild(); 210 parent.removeChild(child); 211 XMLUtils.writeXML(child,System.out); 212 213 System.out.println(); 214 215 regObject = handler.unmarshal(child); 216 handler.marshal(regObject,parent); 217 child = (Element )parent.getFirstChild(); 218 parent.removeChild(child); 219 XMLUtils.writeXML(child,System.out); 220 221 System.out.println(); 222 } 223 } | Popular Tags |