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.IdentifierBag; 22 import org.apache.juddi.datatype.KeyedReference; 23 import org.apache.juddi.datatype.Name; 24 import org.apache.juddi.datatype.RegistryObject; 25 import org.apache.juddi.datatype.request.FindQualifier; 26 import org.apache.juddi.datatype.request.FindQualifiers; 27 import org.apache.juddi.datatype.request.FindTModel; 28 import org.apache.juddi.util.xml.XMLUtils; 29 import org.w3c.dom.Element ; 30 31 40 public class FindTModelHandler extends AbstractHandler 41 { 42 public static final String TAG_NAME = "find_tModel"; 43 44 private HandlerMaker maker = null; 45 46 protected FindTModelHandler(HandlerMaker maker) 47 { 48 this.maker = maker; 49 } 50 51 public RegistryObject unmarshal(Element element) 52 { 53 FindTModel obj = new FindTModel(); 54 Vector nodeList = null; 55 AbstractHandler handler = null; 56 57 String generic = element.getAttribute("generic"); 59 if ((generic != null && (generic.trim().length() > 0))) 60 obj.setGeneric(generic); 61 62 String maxRows = element.getAttribute("maxRows"); 63 if ((maxRows != null) && (maxRows.length() > 0)) 64 obj.setMaxRows(maxRows); 65 66 69 nodeList = XMLUtils.getChildElementsByTagName(element,NameHandler.TAG_NAME); 71 if (nodeList.size() > 0) 72 { 73 handler = maker.lookup(NameHandler.TAG_NAME); 74 Name name = (Name )handler.unmarshal((Element )nodeList.elementAt(0)); 75 if (name != null) 76 obj.setName(name); 77 } 78 79 nodeList = XMLUtils.getChildElementsByTagName(element,FindQualifiersHandler.TAG_NAME); 80 if (nodeList.size() > 0) 81 { 82 handler = maker.lookup(FindQualifiersHandler.TAG_NAME); 83 obj.setFindQualifiers((FindQualifiers)handler.unmarshal((Element )nodeList.elementAt(0))); 84 } 85 86 nodeList = XMLUtils.getChildElementsByTagName(element,IdentifierBagHandler.TAG_NAME); 87 if (nodeList.size() > 0) 88 { 89 handler = maker.lookup(IdentifierBagHandler.TAG_NAME); 90 obj.setIdentifierBag((IdentifierBag)handler.unmarshal((Element )nodeList.elementAt(0))); 91 } 92 93 nodeList = XMLUtils.getChildElementsByTagName(element,CategoryBagHandler.TAG_NAME); 94 if (nodeList.size() > 0) 95 { 96 handler = maker.lookup(CategoryBagHandler.TAG_NAME); 97 obj.setCategoryBag((CategoryBag)handler.unmarshal((Element )nodeList.elementAt(0))); 98 } 99 100 return obj; 101 } 102 103 public void marshal(RegistryObject object,Element parent) 104 { 105 FindTModel request = (FindTModel)object; 106 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 107 AbstractHandler handler = null; 108 109 String generic = request.getGeneric(); 110 if (generic != null) 111 element.setAttribute("generic",generic); 112 113 int maxRows = request.getMaxRows(); 114 if (maxRows > 0) 115 element.setAttribute("maxRows",String.valueOf(maxRows)); 116 117 FindQualifiers qualifiers = request.getFindQualifiers(); 118 if ((qualifiers != null) && (qualifiers.size() > 0)) 119 { 120 handler = maker.lookup(FindQualifiersHandler.TAG_NAME); 121 handler.marshal(qualifiers,element); 122 } 123 124 Name name = request.getName(); 125 if (name != null) 126 { 127 handler = maker.lookup(NameHandler.TAG_NAME); 128 handler.marshal(name,element); 129 } 130 131 IdentifierBag idBag = request.getIdentifierBag(); 132 if (idBag != null) 133 { 134 handler = maker.lookup(IdentifierBagHandler.TAG_NAME); 135 handler.marshal(idBag,element); 136 } 137 138 CategoryBag catBag = request.getCategoryBag(); 139 if (catBag != null) 140 { 141 handler = maker.lookup(CategoryBagHandler.TAG_NAME); 142 handler.marshal(catBag,element); 143 } 144 145 parent.appendChild(element); 146 } 147 148 149 150 151 152 153 154 public static void main(String args[]) 155 throws Exception 156 { 157 HandlerMaker maker = HandlerMaker.getInstance(); 158 AbstractHandler handler = maker.lookup(FindTModelHandler.TAG_NAME); 159 160 Element parent = XMLUtils.newRootElement(); 161 Element child = null; 162 163 IdentifierBag idBag = new IdentifierBag(); 164 idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagKeyValue")); 165 idBag.addKeyedReference(new KeyedReference("uuid:3860b975-9e0c-4cec-bad6-87dfe00e3864","idBagKeyName2","idBagKeyValue2")); 166 167 CategoryBag catBag = new CategoryBag(); 168 catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue")); 169 catBag.addKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","catBagKeyName2","catBagKeyValue2")); 170 171 FindTModel request = new FindTModel(); 172 request.setName(new Name("serviceNm2","en")); 173 request.addFindQualifier(new FindQualifier(FindQualifier.SORT_BY_DATE_ASC)); 174 request.addFindQualifier(new FindQualifier(FindQualifier.AND_ALL_KEYS)); 175 request.setMaxRows(37); 176 request.setIdentifierBag(idBag); 177 request.setCategoryBag(catBag); 178 179 System.out.println(); 180 181 RegistryObject regObject = request; 182 handler.marshal(regObject,parent); 183 child = (Element )parent.getFirstChild(); 184 parent.removeChild(child); 185 XMLUtils.writeXML(child,System.out); 186 187 System.out.println(); 188 189 regObject = handler.unmarshal(child); 190 handler.marshal(regObject,parent); 191 child = (Element )parent.getFirstChild(); 192 parent.removeChild(child); 193 XMLUtils.writeXML(child,System.out); 194 } 195 } | Popular Tags |