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.IdentifierBag; 23 import org.apache.juddi.datatype.KeyedReference; 24 import org.apache.juddi.datatype.OverviewDoc; 25 import org.apache.juddi.datatype.RegistryObject; 26 import org.apache.juddi.datatype.UploadRegister; 27 import org.apache.juddi.datatype.request.AuthInfo; 28 import org.apache.juddi.datatype.request.SaveTModel; 29 import org.apache.juddi.datatype.tmodel.TModel; 30 import org.apache.juddi.util.xml.XMLUtils; 31 import org.w3c.dom.Element ; 32 33 36 public class SaveTModelHandler extends AbstractHandler 37 { 38 public static final String TAG_NAME = "save_tModel"; 39 40 private HandlerMaker maker = null; 41 42 protected SaveTModelHandler(HandlerMaker maker) 43 { 44 this.maker = maker; 45 } 46 47 public RegistryObject unmarshal(Element element) 48 { 49 SaveTModel obj = new SaveTModel(); 50 Vector nodeList = null; 51 AbstractHandler handler = null; 52 53 String generic = element.getAttribute("generic"); 55 if ((generic != null && (generic.trim().length() > 0))) 56 obj.setGeneric(generic); 57 58 61 nodeList = XMLUtils.getChildElementsByTagName(element,AuthInfoHandler.TAG_NAME); 63 if (nodeList.size() > 0) 64 { 65 handler = maker.lookup(AuthInfoHandler.TAG_NAME); 66 obj.setAuthInfo((AuthInfo)handler.unmarshal((Element )nodeList.elementAt(0))); 67 } 68 69 nodeList = XMLUtils.getChildElementsByTagName(element,TModelHandler.TAG_NAME); 70 for (int i=0; i<nodeList.size(); i++) 71 { 72 handler = maker.lookup(TModelHandler.TAG_NAME); 73 obj.addTModel((TModel)handler.unmarshal((Element )nodeList.elementAt(i))); 74 } 75 76 nodeList = XMLUtils.getChildElementsByTagName(element,UploadRegisterHandler.TAG_NAME); 77 for (int i=0; i<nodeList.size(); i++) 78 { 79 handler = maker.lookup(UploadRegisterHandler.TAG_NAME); 80 obj.addUploadRegister((UploadRegister)handler.unmarshal((Element )nodeList.elementAt(i))); 81 } 82 83 return obj; 84 } 85 86 public void marshal(RegistryObject object,Element parent) 87 { 88 SaveTModel request = (SaveTModel)object; 89 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 90 AbstractHandler handler = null; 91 92 String generic = request.getGeneric(); 93 if (generic != null) 94 element.setAttribute("generic",generic); 95 96 AuthInfo authInfo = request.getAuthInfo(); 97 if (authInfo != null) 98 { 99 handler = maker.lookup(AuthInfoHandler.TAG_NAME); 100 handler.marshal(authInfo,element); 101 } 102 103 Vector tModelVector = request.getTModelVector(); 104 if ((tModelVector!=null) && (tModelVector.size() > 0)) 105 { 106 handler = maker.lookup(TModelHandler.TAG_NAME); 107 for (int i=0; i<tModelVector.size(); i++) 108 handler.marshal((TModel)tModelVector.elementAt(i),element); 109 } 110 111 Vector urVector = request.getUploadRegisterVector(); 112 if ((urVector!=null) && (urVector.size() > 0)) 113 { 114 handler = maker.lookup(UploadRegisterHandler.TAG_NAME); 115 for (int i=0; i<urVector.size(); i++) 116 handler.marshal((UploadRegister)urVector.elementAt(i),element); 117 } 118 119 parent.appendChild(element); 120 } 121 122 123 124 125 126 127 128 public static void main(String args[]) 129 throws Exception 130 { 131 HandlerMaker maker = HandlerMaker.getInstance(); 132 AbstractHandler handler = maker.lookup(SaveTModelHandler.TAG_NAME); 133 134 Element parent = XMLUtils.newRootElement(); 135 Element child = null; 136 137 AuthInfo authInfo = new AuthInfo(); 138 authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726"); 139 140 OverviewDoc overDoc = new OverviewDoc(); 141 overDoc.setOverviewURL("http://www.sviens.com/service.html"); 142 overDoc.addDescription(new Description("over-doc Descr")); 143 overDoc.addDescription(new Description("over-doc Descr Two","en")); 144 145 CategoryBag catBag = new CategoryBag(); 146 catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue")); 147 catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","catBagKeyName2","catBagKeyValue2")); 148 149 IdentifierBag idBag = new IdentifierBag(); 150 idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue")); 151 idBag.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2")); 152 153 TModel tModel = new TModel(); 154 tModel.setTModelKey("uuid:269855db-62eb-4862-8e5a-1b06f2753038"); 155 tModel.setOperator("jUDDI"); 156 tModel.setAuthorizedName("Steve Viens"); 157 tModel.setName("jUDDI TModel"); 158 tModel.addDescription(new Description("tModel whatever")); 159 tModel.addDescription(new Description("tModel whatever too","fr")); 160 tModel.setCategoryBag(catBag); 161 tModel.setIdentifierBag(idBag); 162 tModel.setOverviewDoc(overDoc); 163 164 SaveTModel request = new SaveTModel(); 165 request.setAuthInfo(authInfo); 166 request.addTModel(tModel); 167 request.addTModel(tModel); 168 request.addUploadRegister(new UploadRegister("http://www.juddi.org/businessEntity.xml")); 169 request.addUploadRegister(new UploadRegister("http://www.sourceforge.net/businessService.xml")); 170 request.addUploadRegister(new UploadRegister("http://www.uddi.org/bindingTemplate.xml")); 171 172 System.out.println(); 173 174 RegistryObject regObject = request; 175 handler.marshal(regObject,parent); 176 child = (Element )parent.getFirstChild(); 177 parent.removeChild(child); 178 XMLUtils.writeXML(child,System.out); 179 180 System.out.println(); 181 182 regObject = handler.unmarshal(child); 183 handler.marshal(regObject,parent); 184 child = (Element )parent.getFirstChild(); 185 parent.removeChild(child); 186 XMLUtils.writeXML(child,System.out); 187 } 188 } | Popular Tags |