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.Name; 25 import org.apache.juddi.datatype.OverviewDoc; 26 import org.apache.juddi.datatype.RegistryObject; 27 import org.apache.juddi.datatype.tmodel.TModel; 28 import org.apache.juddi.util.xml.XMLUtils; 29 import org.w3c.dom.Element ; 30 31 37 public class TModelHandler extends AbstractHandler 38 { 39 public static final String TAG_NAME = "tModel"; 40 41 private HandlerMaker maker = null; 42 43 protected TModelHandler(HandlerMaker maker) 44 { 45 this.maker = maker; 46 } 47 48 public RegistryObject unmarshal(Element element) 49 { 50 TModel obj = new TModel(); 51 Vector nodeList = null; 52 AbstractHandler handler = null; 53 54 obj.setTModelKey(element.getAttribute("tModelKey")); 56 obj.setOperator(element.getAttribute("operator")); 57 obj.setAuthorizedName(element.getAttribute("authorizedName")); 58 59 62 nodeList = XMLUtils.getChildElementsByTagName(element,NameHandler.TAG_NAME); 64 if (nodeList.size() > 0) 65 { 66 handler = maker.lookup(NameHandler.TAG_NAME); 67 Name name = (Name )handler.unmarshal((Element )nodeList.elementAt(0)); 68 if (name != null) 69 obj.setName(name); 70 } 71 72 nodeList = XMLUtils.getChildElementsByTagName(element,DescriptionHandler.TAG_NAME); 73 for (int i=0; i<nodeList.size(); i++) 74 { 75 handler = maker.lookup(DescriptionHandler.TAG_NAME); 76 Description descr = (Description)handler.unmarshal((Element )nodeList.elementAt(i)); 77 if (descr != null) 78 obj.addDescription(descr); 79 } 80 81 nodeList = XMLUtils.getChildElementsByTagName(element,OverviewDocHandler.TAG_NAME); 82 if (nodeList.size() > 0) 83 { 84 handler = maker.lookup(OverviewDocHandler.TAG_NAME); 85 obj.setOverviewDoc((OverviewDoc)handler.unmarshal((Element )nodeList.elementAt(0))); 86 } 87 88 nodeList = XMLUtils.getChildElementsByTagName(element,IdentifierBagHandler.TAG_NAME); 89 if (nodeList.size() > 0) 90 { 91 handler = maker.lookup(IdentifierBagHandler.TAG_NAME); 92 obj.setIdentifierBag((IdentifierBag)handler.unmarshal((Element )nodeList.elementAt(0))); 93 } 94 95 nodeList = XMLUtils.getChildElementsByTagName(element,CategoryBagHandler.TAG_NAME); 96 if (nodeList.size() > 0) 97 { 98 handler = maker.lookup(CategoryBagHandler.TAG_NAME); 99 obj.setCategoryBag((CategoryBag)handler.unmarshal((Element )nodeList.elementAt(0))); 100 } 101 102 return obj; 103 } 104 105 public void marshal(RegistryObject object,Element parent) 106 { 107 TModel tModel = (TModel)object; 108 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 109 AbstractHandler handler = null; 110 111 String tModelKey = tModel.getTModelKey(); 112 if (tModelKey != null) 113 element.setAttribute("tModelKey",tModelKey); 114 else 115 element.setAttribute("tModelKey",""); 116 117 String operator = tModel.getOperator(); 118 if (operator != null) 119 element.setAttribute("operator",operator); 120 121 String authName = tModel.getAuthorizedName(); 122 if (authName != null) 123 element.setAttribute("authorizedName",authName); 124 125 String name = tModel.getName(); 126 if (name != null) 127 { 128 handler = maker.lookup(NameHandler.TAG_NAME); 129 handler.marshal(new Name(name),element); 130 } 131 132 Vector descrVector = tModel.getDescriptionVector(); 133 if ((descrVector!=null) && (descrVector.size() > 0)) 134 { 135 handler = maker.lookup(DescriptionHandler.TAG_NAME); 136 for (int i=0; i < descrVector.size(); i++) 137 handler.marshal((Description)descrVector.elementAt(i),element); 138 } 139 140 OverviewDoc overDoc = tModel.getOverviewDoc(); 141 if (overDoc != null) 142 { 143 handler = maker.lookup(OverviewDocHandler.TAG_NAME); 144 handler.marshal(overDoc,element); 145 } 146 147 IdentifierBag identifierBag = tModel.getIdentifierBag(); 148 if ((identifierBag != null) && (identifierBag.getKeyedReferenceVector() != null) && (!identifierBag.getKeyedReferenceVector().isEmpty())) 149 { 150 handler = maker.lookup(IdentifierBagHandler.TAG_NAME); 151 handler.marshal(identifierBag,element); 152 } 153 154 CategoryBag categoryBag = tModel.getCategoryBag(); 155 if ((categoryBag != null) && (categoryBag.getKeyedReferenceVector() != null) && (!categoryBag.getKeyedReferenceVector().isEmpty())) 156 { 157 handler = maker.lookup(CategoryBagHandler.TAG_NAME); 158 handler.marshal(categoryBag,element); 159 } 160 161 parent.appendChild(element); 162 } 163 164 165 166 167 168 169 170 public static void main(String args[]) 171 throws Exception 172 { 173 HandlerMaker maker = HandlerMaker.getInstance(); 174 AbstractHandler handler = maker.lookup(TModelHandler.TAG_NAME); 175 176 Element parent = XMLUtils.newRootElement(); 177 Element child = null; 178 179 OverviewDoc overDoc = new OverviewDoc(); 180 overDoc.setOverviewURL("http://www.sviens.com/service.html"); 181 overDoc.addDescription(new Description("over-doc Descr")); 182 overDoc.addDescription(new Description("over-doc Descr Two","en")); 183 184 CategoryBag catBag = new CategoryBag(); 185 catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue")); 186 catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","catBagKeyName2","catBagKeyValue2")); 187 188 IdentifierBag idBag = new IdentifierBag(); 189 idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue")); 190 idBag.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2")); 191 192 TModel tModel = new TModel(); 193 tModel.setTModelKey("uuid:269855db-62eb-4862-8e5a-1b06f2753038"); 194 tModel.setOperator("jUDDI"); 195 tModel.setAuthorizedName("Steve Viens"); 196 tModel.setName("jUDDI TModel"); 197 tModel.addDescription(new Description("tModel whatever")); 198 tModel.addDescription(new Description("tModel whatever too","fr")); 199 tModel.setCategoryBag(catBag); 200 tModel.setIdentifierBag(idBag); 201 tModel.setOverviewDoc(overDoc); 202 203 System.out.println(); 204 205 RegistryObject regObject = tModel; 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 } | Popular Tags |