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.request.AuthInfo; 34 import org.apache.juddi.datatype.request.SaveService; 35 import org.apache.juddi.datatype.service.BusinessService; 36 import org.apache.juddi.util.xml.XMLUtils; 37 import org.w3c.dom.Element ; 38 39 42 public class SaveServiceHandler extends AbstractHandler 43 { 44 public static final String TAG_NAME = "save_service"; 45 46 private HandlerMaker maker = null; 47 48 protected SaveServiceHandler(HandlerMaker maker) 49 { 50 this.maker = maker; 51 } 52 53 public RegistryObject unmarshal(Element element) 54 { 55 SaveService obj = new SaveService(); 56 Vector nodeList = null; 57 AbstractHandler handler = null; 58 59 String generic = element.getAttribute("generic"); 61 if ((generic != null && (generic.trim().length() > 0))) 62 obj.setGeneric(generic); 63 64 67 nodeList = XMLUtils.getChildElementsByTagName(element,AuthInfoHandler.TAG_NAME); 69 if (nodeList.size() > 0) 70 { 71 handler = maker.lookup(AuthInfoHandler.TAG_NAME); 72 obj.setAuthInfo((AuthInfo)handler.unmarshal((Element )nodeList.elementAt(0))); 73 } 74 75 nodeList = XMLUtils.getChildElementsByTagName(element,BusinessServiceHandler.TAG_NAME); 76 for (int i=0; i<nodeList.size(); i++) 77 { 78 handler = maker.lookup(BusinessServiceHandler.TAG_NAME); 79 obj.addBusinessService((BusinessService)handler.unmarshal((Element )nodeList.elementAt(i))); 80 } 81 82 return obj; 83 } 84 85 public void marshal(RegistryObject object,Element parent) 86 { 87 SaveService request = (SaveService)object; 88 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 89 AbstractHandler handler = null; 90 91 String generic = request.getGeneric(); 92 if (generic != null) 93 element.setAttribute("generic",generic); 94 95 AuthInfo authInfo = request.getAuthInfo(); 96 if (authInfo != null) 97 { 98 handler = maker.lookup(AuthInfoHandler.TAG_NAME); 99 handler.marshal(authInfo,element); 100 } 101 102 Vector vector = request.getBusinessServiceVector(); 103 if ((vector!=null) && (vector.size() > 0)) 104 { 105 handler = maker.lookup(BusinessServiceHandler.TAG_NAME); 106 for (int i=0; i<vector.size(); i++) 107 handler.marshal((BusinessService)vector.elementAt(i),element); 108 } 109 110 parent.appendChild(element); 111 } 112 113 114 115 116 117 118 119 public static void main(String args[]) 120 throws Exception 121 { 122 HandlerMaker maker = HandlerMaker.getInstance(); 123 AbstractHandler handler = maker.lookup(SaveServiceHandler.TAG_NAME); 124 125 Element parent = XMLUtils.newRootElement(); 126 Element child = null; 127 128 AuthInfo authInfo = new AuthInfo(); 129 authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726"); 130 131 OverviewDoc overDoc = new OverviewDoc(); 132 overDoc.setOverviewURL("http://www.sviens.com/service.html"); 133 overDoc.addDescription(new Description("over-doc Descr")); 134 overDoc.addDescription(new Description("over-doc Descr Two","en")); 135 136 InstanceDetails instDetails = new InstanceDetails(); 137 instDetails.addDescription(new Description("body-isa-wunder")); 138 instDetails.addDescription(new Description("sweetchild-o-mine","it")); 139 instDetails.setInstanceParms("inst-det parameters"); 140 instDetails.setOverviewDoc(overDoc); 141 142 TModelInstanceInfo tModInstInfo = new TModelInstanceInfo(); 143 tModInstInfo.setTModelKey("uuid:ae0f9fd4-287f-40c9-be91-df47a7c72fd9"); 144 tModInstInfo.addDescription(new Description("tMod-Inst-Info")); 145 tModInstInfo.addDescription(new Description("tMod-Inst-Info too","es")); 146 tModInstInfo.setInstanceDetails(instDetails); 147 148 TModelInstanceDetails tModInstDet = new TModelInstanceDetails(); 149 tModInstDet.addTModelInstanceInfo(tModInstInfo); 150 151 BindingTemplate binding = new BindingTemplate(); 152 binding.setBindingKey("c9613c3c-fe55-4f34-a3da-b3167afbca4a"); 153 binding.setServiceKey("997a55bc-563d-4c04-8a94-781604870d31"); 154 binding.addDescription(new Description("whatever")); 155 binding.addDescription(new Description("whatever too","fr")); 156 binding.setHostingRedirector(new HostingRedirector("92658289-0bd7-443c-8948-0bb4460b44c0")); 157 binding.setAccessPoint(new AccessPoint(AccessPoint.HTTP,"http://www.sviens.com/service.wsdl")); 158 binding.setTModelInstanceDetails(tModInstDet); 159 160 BindingTemplates bindings = new BindingTemplates(); 161 bindings.addBindingTemplate(binding); 162 163 CategoryBag catBag = new CategoryBag(); 164 catBag.addKeyedReference(new KeyedReference("keyName","keyValue")); 165 catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","keyName2","keyValue2")); 166 167 BusinessService service = new BusinessService(); 168 service.setServiceKey("fe8af00d-3a2c-4e05-b7ca-95a1259aad4f"); 169 service.setBusinessKey("b8cc7266-9eed-4675-b621-34697f252a77"); 170 service.setBindingTemplates(bindings); 171 service.setCategoryBag(catBag); 172 service.addName(new Name("serviceNm")); 173 service.addName(new Name("serviceNm2","en")); 174 service.addDescription(new Description("service whatever")); 175 service.addDescription(new Description("service whatever too","it")); 176 177 SaveService request = new SaveService(); 178 request.setAuthInfo(authInfo); 179 request.addBusinessService(service); 180 request.addBusinessService(service); 181 182 System.out.println(); 183 184 RegistryObject regObject = request; 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 } 199 200 201 | Popular Tags |