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.Description; 22 import org.apache.juddi.datatype.OverviewDoc; 23 import org.apache.juddi.datatype.RegistryObject; 24 import org.apache.juddi.datatype.binding.AccessPoint; 25 import org.apache.juddi.datatype.binding.BindingTemplate; 26 import org.apache.juddi.datatype.binding.HostingRedirector; 27 import org.apache.juddi.datatype.binding.InstanceDetails; 28 import org.apache.juddi.datatype.binding.TModelInstanceDetails; 29 import org.apache.juddi.datatype.binding.TModelInstanceInfo; 30 import org.apache.juddi.datatype.response.BindingDetail; 31 import org.apache.juddi.util.xml.XMLUtils; 32 import org.w3c.dom.Element ; 33 34 40 public class BindingDetailHandler extends AbstractHandler 41 { 42 public static final String TAG_NAME = "bindingDetail"; 43 44 private HandlerMaker maker = null; 45 46 protected BindingDetailHandler(HandlerMaker maker) 47 { 48 this.maker = maker; 49 } 50 51 public RegistryObject unmarshal(Element element) 52 { 53 BindingDetail obj = new BindingDetail(); 54 Vector nodeList = null; 55 AbstractHandler handler = null; 56 57 61 obj.setGeneric(element.getAttribute("generic")); 63 obj.setOperator(element.getAttribute("operator")); 64 65 69 String truncValue = element.getAttribute("truncated"); 70 if (truncValue != null) 71 obj.setTruncated(truncValue.equalsIgnoreCase("true")); 72 73 76 nodeList = XMLUtils.getChildElementsByTagName(element,BindingTemplateHandler.TAG_NAME); 78 for (int i=0; i<nodeList.size(); i++) 79 { 80 handler = maker.lookup(BindingTemplateHandler.TAG_NAME); 81 obj.addBindingTemplate((BindingTemplate)handler.unmarshal((Element )nodeList.elementAt(i))); 82 } 83 84 return obj; 85 } 86 87 public void marshal(RegistryObject object,Element parent) 88 { 89 BindingDetail detail = (BindingDetail)object; 90 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 91 AbstractHandler handler = null; 92 93 String generic = detail.getGeneric(); 94 if ((generic != null) && (generic.trim().length() > 0)) 95 { 96 element.setAttribute("generic",generic); 97 98 if (generic.equals(IRegistry.UDDI_V1_GENERIC)) 99 element.setAttribute("xmlns",IRegistry.UDDI_V1_NAMESPACE); 100 else if (generic.equals(IRegistry.UDDI_V2_GENERIC)) 101 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 102 else if (generic.equals(IRegistry.UDDI_V3_GENERIC)) 103 element.setAttribute("xmlns",IRegistry.UDDI_V3_NAMESPACE); 104 } 105 else { 107 element.setAttribute("generic",IRegistry.UDDI_V2_GENERIC); 108 element.setAttribute("xmlns",IRegistry.UDDI_V2_NAMESPACE); 109 } 110 111 String operator = detail.getOperator(); 112 if (operator != null) 113 element.setAttribute("operator",operator); 114 else 115 element.setAttribute("operator",""); 116 117 boolean truncated = detail.isTruncated(); 118 if (truncated) 119 element.setAttribute("truncated","true"); 120 121 Vector vector = detail.getBindingTemplateVector(); 122 if ((vector!=null) && (vector.size() > 0)) 123 { 124 handler = maker.lookup(BindingTemplateHandler.TAG_NAME); 125 for (int i=0; i < vector.size(); i++) 126 handler.marshal((BindingTemplate)vector.elementAt(i),element); 127 } 128 129 parent.appendChild(element); 130 } 131 132 133 134 135 136 137 138 public static void main(String args[]) 139 throws Exception 140 { 141 HandlerMaker maker = HandlerMaker.getInstance(); 142 AbstractHandler handler = maker.lookup(BindingDetailHandler.TAG_NAME); 143 Element parent = XMLUtils.newRootElement(); 144 Element child = null; 145 146 OverviewDoc overDoc = new OverviewDoc(); 147 overDoc.setOverviewURL("http://www.sviens.com/service.html"); 148 overDoc.addDescription(new Description("over-doc Descr")); 149 overDoc.addDescription(new Description("over-doc Descr Two","en")); 150 151 InstanceDetails instDetails = new InstanceDetails(); 152 instDetails.addDescription(new Description("body-isa-wunder")); 153 instDetails.addDescription(new Description("sweetchild-o-mine","it")); 154 instDetails.setInstanceParms("inst-det parameters"); 155 instDetails.setOverviewDoc(overDoc); 156 157 TModelInstanceInfo tModInstInfo = new TModelInstanceInfo(); 158 tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9"); 159 tModInstInfo.addDescription(new Description("tMod-Inst-Info")); 160 tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es")); 161 tModInstInfo.setInstanceDetails(instDetails); 162 163 TModelInstanceDetails tModInstDet = new TModelInstanceDetails(); 164 tModInstDet.addTModelInstanceInfo(tModInstInfo); 165 166 BindingTemplate binding = new BindingTemplate(); 167 binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a"); 168 binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31"); 169 binding.addDescription(new Description("whatever")); 170 binding.addDescription(new Description("whatever too","fr")); 171 binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0")); 172 binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl")); 173 binding.setTModelInstanceDetails(tModInstDet); 174 175 BindingDetail detail = new BindingDetail(); 176 detail.setGeneric("2.0"); 177 detail.setOperator("jUDDI.org"); 178 detail.setTruncated(true); 179 detail.addBindingTemplate(binding); 180 detail.addBindingTemplate(binding); 181 182 System.out.println(); 183 184 RegistryObject regObject = detail; 185 handler.marshal(regObject,parent); 186 child = (Element )parent.getFirstChild(); 187 parent.removeChild(child); 188 XMLUtils.writeXML(child,System.out); 189 190 System.out.println(); 191 192 regObject = handler.unmarshal(child); 193 handler.marshal(regObject,parent); 194 child = (Element )parent.getFirstChild(); 195 parent.removeChild(child); 196 XMLUtils.writeXML(child,System.out); 197 198 System.out.println(); 199 } 200 } | Popular Tags |