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.BindingTemplates; 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.util.xml.XMLUtils; 31 import org.w3c.dom.Element ; 32 33 36 public class BindingTemplatesHandler extends AbstractHandler 37 { 38 public static final String TAG_NAME = "bindingTemplates"; 39 40 private HandlerMaker maker = null; 41 42 protected BindingTemplatesHandler(HandlerMaker maker) 43 { 44 this.maker = maker; 45 } 46 47 public RegistryObject unmarshal(Element element) 48 { 49 BindingTemplates obj = new BindingTemplates(); 50 Vector nodeList = null; 51 AbstractHandler handler = null; 52 53 56 59 nodeList = XMLUtils.getChildElementsByTagName(element,BindingTemplateHandler.TAG_NAME); 61 for (int i=0; i<nodeList.size(); i++) 62 { 63 handler = maker.lookup(BindingTemplateHandler.TAG_NAME); 64 obj.addBindingTemplate((BindingTemplate)handler.unmarshal((Element )nodeList.elementAt(i))); 65 } 66 67 return obj; 68 } 69 70 public void marshal(RegistryObject object,Element parent) 71 { 72 BindingTemplates bindings = (BindingTemplates)object; 73 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 74 AbstractHandler handler = null; 75 76 Vector bindingVector = bindings.getBindingTemplateVector(); 77 if ((bindingVector!=null) && (bindingVector.size() > 0)) 78 { 79 handler = maker.lookup(BindingTemplateHandler.TAG_NAME); 80 for (int i=0; i < bindingVector.size(); i++) 81 handler.marshal((BindingTemplate)bindingVector.elementAt(i),element); 82 } 83 84 parent.appendChild(element); 85 } 86 87 88 89 90 91 92 93 public static void main(String args[]) 94 throws Exception 95 { 96 HandlerMaker maker = HandlerMaker.getInstance(); 97 AbstractHandler handler = maker.lookup(BindingTemplateHandler.TAG_NAME); 98 Element parent = XMLUtils.newRootElement(); 99 Element child = null; 100 101 OverviewDoc overDoc = new OverviewDoc(); 102 overDoc.setOverviewURL("http://www.sviens.com/service.html"); 103 overDoc.addDescription(new Description("over-doc Descr")); 104 overDoc.addDescription(new Description("over-doc Descr Two","en")); 105 106 InstanceDetails instDetails = new InstanceDetails(); 107 instDetails.addDescription(new Description("body-isa-wunder")); 108 instDetails.addDescription(new Description("sweetchild-o-mine","it")); 109 instDetails.setInstanceParms("inst-det parameters"); 110 instDetails.setOverviewDoc(overDoc); 111 112 TModelInstanceInfo tModInstInfo = new TModelInstanceInfo(); 113 tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9"); 114 tModInstInfo.addDescription(new Description("tMod-Inst-Info")); 115 tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es")); 116 tModInstInfo.setInstanceDetails(instDetails); 117 118 TModelInstanceDetails tModInstDet = new TModelInstanceDetails(); 119 tModInstDet.addTModelInstanceInfo(tModInstInfo); 120 121 BindingTemplate binding = new BindingTemplate(); 122 binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a"); 123 binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31"); 124 binding.addDescription(new Description("whatever")); 125 binding.addDescription(new Description("whatever too","fr")); 126 binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0")); 127 binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl")); 128 binding.setTModelInstanceDetails(tModInstDet); 129 130 BindingTemplates bindings = new BindingTemplates(); 131 bindings.addBindingTemplate(binding); 132 bindings.addBindingTemplate(binding); 133 134 System.out.println(); 135 136 RegistryObject regObject = bindings; 137 handler.marshal(regObject,parent); 138 child = (Element )parent.getFirstChild(); 139 parent.removeChild(child); 140 XMLUtils.writeXML(child,System.out); 141 142 System.out.println(); 143 144 regObject = handler.unmarshal(child); 145 handler.marshal(regObject,parent); 146 child = (Element )parent.getFirstChild(); 147 parent.removeChild(child); 148 XMLUtils.writeXML(child,System.out); 149 150 System.out.println(); 151 } 152 } | Popular Tags |