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.KeyedReference; 22 import org.apache.juddi.datatype.Name; 23 import org.apache.juddi.datatype.RegistryObject; 24 import org.apache.juddi.datatype.TModelBag; 25 import org.apache.juddi.datatype.TModelKey; 26 import org.apache.juddi.datatype.request.FindQualifier; 27 import org.apache.juddi.datatype.request.FindQualifiers; 28 import org.apache.juddi.datatype.request.FindService; 29 import org.apache.juddi.util.xml.XMLUtils; 30 import org.w3c.dom.Element ; 31 32 41 public class FindServiceHandler extends AbstractHandler 42 { 43 public static final String TAG_NAME = "find_service"; 44 45 private HandlerMaker maker = null; 46 47 protected FindServiceHandler(HandlerMaker maker) 48 { 49 this.maker = maker; 50 } 51 52 public RegistryObject unmarshal(Element element) 53 { 54 FindService obj = new FindService(); 55 Vector nodeList = null; 56 AbstractHandler handler = null; 57 58 String businessKey = element.getAttribute("businessKey"); 60 if ((businessKey != null && (businessKey.trim().length() > 0))) 61 obj.setBusinessKey(businessKey); 62 63 String generic = element.getAttribute("generic"); 64 if ((generic != null && (generic.trim().length() > 0))) 65 obj.setGeneric(generic); 66 67 String maxRows = element.getAttribute("maxRows"); 68 if ((maxRows != null) && (maxRows.length() > 0)) 69 obj.setMaxRows(maxRows); 70 71 74 nodeList = XMLUtils.getChildElementsByTagName(element,NameHandler.TAG_NAME); 76 for (int i=0; i<nodeList.size(); i++) 77 { 78 handler = maker.lookup(NameHandler.TAG_NAME); 79 Name name = (Name )handler.unmarshal((Element )nodeList.elementAt(i)); 80 if (name != null) 81 obj.addName(name); 82 } 83 84 nodeList = XMLUtils.getChildElementsByTagName(element,FindQualifiersHandler.TAG_NAME); 85 if (nodeList.size() > 0) 86 { 87 handler = maker.lookup(FindQualifiersHandler.TAG_NAME); 88 obj.setFindQualifiers((FindQualifiers)handler.unmarshal((Element )nodeList.elementAt(0))); 89 } 90 91 nodeList = XMLUtils.getChildElementsByTagName(element,TModelBagHandler.TAG_NAME); 92 if (nodeList.size() > 0) 93 { 94 handler = maker.lookup(TModelBagHandler.TAG_NAME); 95 obj.setTModelBag((TModelBag)handler.unmarshal((Element )nodeList.elementAt(0))); 96 } 97 98 nodeList = XMLUtils.getChildElementsByTagName(element,CategoryBagHandler.TAG_NAME); 99 if (nodeList.size() > 0) 100 { 101 handler = maker.lookup(CategoryBagHandler.TAG_NAME); 102 obj.setCategoryBag((CategoryBag)handler.unmarshal((Element )nodeList.elementAt(0))); 103 } 104 105 return obj; 106 } 107 108 public void marshal(RegistryObject object,Element parent) 109 { 110 FindService request = (FindService)object; 111 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 112 AbstractHandler handler = null; 113 114 String key = request.getBusinessKey(); 115 if (key != null) 116 element.setAttribute("businessKey",key); 117 118 String generic = request.getGeneric(); 119 if (generic != null) 120 element.setAttribute("generic",generic); 121 122 int maxRows = request.getMaxRows(); 123 if (maxRows > 0) 124 element.setAttribute("maxRows",String.valueOf(maxRows)); 125 126 FindQualifiers qualifiers = request.getFindQualifiers(); 127 if ((qualifiers != null) && (qualifiers.size() > 0)) 128 { 129 handler = maker.lookup(FindQualifiersHandler.TAG_NAME); 130 handler.marshal(qualifiers,element); 131 } 132 133 Vector nameVector = request.getNameVector(); 134 if ((nameVector!=null) && (nameVector.size() > 0)) 135 { 136 handler = maker.lookup(NameHandler.TAG_NAME); 137 for (int i=0; i < nameVector.size(); i++) 138 handler.marshal((Name)nameVector.elementAt(i),element); 139 } 140 141 CategoryBag catBag = request.getCategoryBag(); 142 if (catBag != null) 143 { 144 handler = maker.lookup(CategoryBagHandler.TAG_NAME); 145 handler.marshal(catBag,element); 146 } 147 148 TModelBag tModBag = request.getTModelBag(); 149 if (tModBag != null) 150 { 151 handler = maker.lookup(TModelBagHandler.TAG_NAME); 152 handler.marshal(tModBag,element); 153 } 154 155 parent.appendChild(element); 156 } 157 158 159 160 161 162 163 164 public static void main(String args[]) 165 throws Exception 166 { 167 HandlerMaker maker = HandlerMaker.getInstance(); 168 AbstractHandler handler = maker.lookup(FindServiceHandler.TAG_NAME); 169 170 Element parent = XMLUtils.newRootElement(); 171 Element child = null; 172 173 CategoryBag catBag = new CategoryBag(); 174 catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue")); 175 catBag.addKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","catBagKeyName2","catBagKeyValue2")); 176 177 TModelBag tModBag = new TModelBag(); 178 tModBag.addTModelKey("uuid:35d9793b-9911-4b85-9f0e-5d4c65b4f253"); 179 tModBag.addTModelKey(new TModelKey("uuid:c5ab113f-0d6b-4247-b3c4-8c012726acd8")); 180 181 FindService request = new FindService(); 182 request.addName(new Name("serviceNm")); 183 request.addName(new Name("serviceNm2","en")); 184 request.addFindQualifier(new FindQualifier(FindQualifier.SORT_BY_DATE_ASC)); 185 request.addFindQualifier(new FindQualifier(FindQualifier.AND_ALL_KEYS)); 186 request.setMaxRows(50); 187 request.setBusinessKey("fd36dbce-bc3e-468b-8346-5374975a0843"); 188 request.setTModelBag(tModBag); 189 request.setCategoryBag(catBag); 190 191 System.out.println(); 192 193 RegistryObject regObject = request; 194 handler.marshal(regObject,parent); 195 child = (Element )parent.getFirstChild(); 196 parent.removeChild(child); 197 XMLUtils.writeXML(child,System.out); 198 199 System.out.println(); 200 201 regObject = handler.unmarshal(child); 202 handler.marshal(regObject,parent); 203 child = (Element )parent.getFirstChild(); 204 parent.removeChild(child); 205 XMLUtils.writeXML(child,System.out); 206 } 207 } | Popular Tags |