1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.datatype.Description; 21 import org.apache.juddi.datatype.OverviewDoc; 22 import org.apache.juddi.datatype.RegistryObject; 23 import org.apache.juddi.datatype.binding.AccessPoint; 24 import org.apache.juddi.datatype.binding.BindingTemplate; 25 import org.apache.juddi.datatype.binding.HostingRedirector; 26 import org.apache.juddi.datatype.binding.InstanceDetails; 27 import org.apache.juddi.datatype.binding.TModelInstanceDetails; 28 import org.apache.juddi.datatype.binding.TModelInstanceInfo; 29 import org.apache.juddi.util.xml.XMLUtils; 30 import org.w3c.dom.Element ; 31 32 36 public class BindingTemplateHandler extends AbstractHandler 37 { 38 public static final String TAG_NAME = "bindingTemplate"; 39 40 private HandlerMaker maker = null; 41 42 protected BindingTemplateHandler(HandlerMaker maker) 43 { 44 this.maker = maker; 45 } 46 47 public RegistryObject unmarshal(Element element) 48 { 49 BindingTemplate obj = new BindingTemplate(); 50 Vector nodeList = null; 51 AbstractHandler handler = null; 52 53 obj.setServiceKey(element.getAttribute("serviceKey")); 55 obj.setBindingKey(element.getAttribute("bindingKey")); 56 57 60 nodeList = XMLUtils.getChildElementsByTagName(element,DescriptionHandler.TAG_NAME); 62 for (int i=0; i<nodeList.size(); i++) 63 { 64 handler = maker.lookup(DescriptionHandler.TAG_NAME); 65 Description descr = (Description)handler.unmarshal((Element )nodeList.elementAt(i)); 66 if (descr != null) 67 obj.addDescription(descr); 68 } 69 70 nodeList = XMLUtils.getChildElementsByTagName(element,AccessPointHandler.TAG_NAME); 71 if (nodeList.size() > 0) 72 { 73 handler = maker.lookup(AccessPointHandler.TAG_NAME); 74 obj.setAccessPoint((AccessPoint)handler.unmarshal((Element )nodeList.elementAt(0))); 75 } 76 77 nodeList = XMLUtils.getChildElementsByTagName(element,HostingRedirectorHandler.TAG_NAME); 78 if (nodeList.size() > 0) 79 { 80 handler = maker.lookup(HostingRedirectorHandler.TAG_NAME); 81 obj.setHostingRedirector((HostingRedirector)handler.unmarshal((Element )nodeList.elementAt(0))); 82 } 83 84 nodeList = XMLUtils.getChildElementsByTagName(element,TModelInstanceDetailsHandler.TAG_NAME); 85 if (nodeList.size() > 0) 86 { 87 handler = maker.lookup(TModelInstanceDetailsHandler.TAG_NAME); 88 obj.setTModelInstanceDetails((TModelInstanceDetails)handler.unmarshal((Element )nodeList.elementAt(0))); 89 } 90 91 99 return obj; 100 } 101 102 public void marshal(RegistryObject object,Element parent) 103 { 104 BindingTemplate binding = (BindingTemplate)object; 105 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 106 AbstractHandler handler = null; 107 108 String bindingKey = binding.getBindingKey(); 109 if (bindingKey != null) 110 element.setAttribute("bindingKey",bindingKey); 111 else 112 element.setAttribute("bindingKey",""); 113 114 String serviceKey = binding.getServiceKey(); 115 if (serviceKey != null) 116 element.setAttribute("serviceKey",serviceKey); 117 118 Vector descrVector = binding.getDescriptionVector(); 119 if ((descrVector!=null) && (descrVector.size() > 0)) 120 { 121 handler = maker.lookup(DescriptionHandler.TAG_NAME); 122 for (int i=0; i < descrVector.size(); i++) 123 handler.marshal((Description)descrVector.elementAt(i),element); 124 } 125 126 AccessPoint accessPoint = binding.getAccessPoint(); 127 if (accessPoint != null) 128 { 129 handler = maker.lookup(AccessPointHandler.TAG_NAME); 130 handler.marshal(accessPoint,element); 131 } 132 else { 134 HostingRedirector redirector = binding.getHostingRedirector(); 135 if (redirector != null) 136 { 137 handler = maker.lookup(HostingRedirectorHandler.TAG_NAME); 138 handler.marshal(redirector,element); 139 } 140 } 141 142 TModelInstanceDetails tModInstDet = binding.getTModelInstanceDetails(); 143 if (tModInstDet != null) 144 { 145 handler = maker.lookup(TModelInstanceDetailsHandler.TAG_NAME); 146 handler.marshal(tModInstDet,element); 147 } 148 149 157 parent.appendChild(element); 158 } 159 160 161 162 163 164 165 166 public static void main(String args[]) 167 throws Exception 168 { 169 HandlerMaker maker = HandlerMaker.getInstance(); 170 AbstractHandler handler = maker.lookup(BindingTemplateHandler.TAG_NAME); 171 Element parent = XMLUtils.newRootElement(); 172 Element child = null; 173 174 OverviewDoc overDoc = new OverviewDoc(); 175 overDoc.setOverviewURL("http://www.sviens.com/service.html"); 176 overDoc.addDescription(new Description("over-doc Descr")); 177 overDoc.addDescription(new Description("over-doc Descr Two","en")); 178 179 InstanceDetails instDetails = new InstanceDetails(); 180 instDetails.addDescription(new Description("body-isa-wunder")); 181 instDetails.addDescription(new Description("sweetchild-o-mine","it")); 182 instDetails.setInstanceParms("inst-det parameters"); 183 instDetails.setOverviewDoc(overDoc); 184 185 TModelInstanceInfo tModInstInfo = new TModelInstanceInfo(); 186 tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9"); 187 tModInstInfo.addDescription(new Description("tMod-Inst-Info")); 188 tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es")); 189 tModInstInfo.setInstanceDetails(instDetails); 190 191 TModelInstanceDetails tModInstDet = new TModelInstanceDetails(); 192 tModInstDet.addTModelInstanceInfo(tModInstInfo); 193 194 BindingTemplate binding = new BindingTemplate(); 195 binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a"); 196 binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31"); 197 binding.addDescription(new Description("whatever")); 198 binding.addDescription(new Description("whatever too","fr")); 199 binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0")); 200 binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl")); 201 binding.setTModelInstanceDetails(tModInstDet); 202 203 System.out.println(); 204 205 RegistryObject regObject = binding; 206 handler.marshal(regObject,parent); 207 child = (Element )parent.getFirstChild(); 208 parent.removeChild(child); 209 XMLUtils.writeXML(child,System.out); 210 211 System.out.println(); 212 213 regObject = handler.unmarshal(child); 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 } | Popular Tags |