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.RegistryObject; 23 import org.apache.juddi.datatype.TModelBag; 24 import org.apache.juddi.datatype.TModelKey; 25 import org.apache.juddi.datatype.request.FindBinding; 26 import org.apache.juddi.datatype.request.FindQualifier; 27 import org.apache.juddi.datatype.request.FindQualifiers; 28 import org.apache.juddi.util.xml.XMLUtils; 29 import org.w3c.dom.Element ; 30 31 32 41 public class FindBindingHandler extends AbstractHandler 42 { 43 public static final String TAG_NAME = "find_binding"; 44 45 private HandlerMaker maker = null; 46 47 protected FindBindingHandler(HandlerMaker maker) 48 { 49 this.maker = maker; 50 } 51 52 public RegistryObject unmarshal(Element element) 53 { 54 FindBinding obj = new FindBinding(); 55 Vector nodeList = null; 56 AbstractHandler handler = null; 57 58 String serviceKey = element.getAttribute("serviceKey"); 60 if ((serviceKey != null && (serviceKey.trim().length() > 0))) 61 obj.setServiceKey(serviceKey); 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.trim().length() > 0)) 69 obj.setMaxRows(maxRows); 70 71 74 nodeList = XMLUtils.getChildElementsByTagName(element,FindQualifiersHandler.TAG_NAME); 76 if (nodeList.size() > 0) 77 { 78 handler = maker.lookup(FindQualifiersHandler.TAG_NAME); 79 obj.setFindQualifiers((FindQualifiers)handler.unmarshal((Element )nodeList.elementAt(0))); 80 } 81 82 nodeList = XMLUtils.getChildElementsByTagName(element,TModelBagHandler.TAG_NAME); 83 if (nodeList.size() > 0) 84 { 85 handler = maker.lookup(TModelBagHandler.TAG_NAME); 86 obj.setTModelBag((TModelBag)handler.unmarshal((Element )nodeList.elementAt(0))); 87 } 88 89 nodeList = XMLUtils.getChildElementsByTagName(element,CategoryBagHandler.TAG_NAME); 90 if (nodeList.size() > 0) 91 { 92 handler = maker.lookup(CategoryBagHandler.TAG_NAME); 93 obj.setCategoryBag((CategoryBag)handler.unmarshal((Element )nodeList.elementAt(0))); 94 } 95 96 return obj; 97 } 98 99 public void marshal(RegistryObject object,Element parent) 100 { 101 FindBinding request = (FindBinding)object; 102 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 103 AbstractHandler handler = null; 104 105 String key = request.getServiceKey(); 106 if (key != null) 107 element.setAttribute("serviceKey",key); 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 CategoryBag catBag = request.getCategoryBag(); 125 if (catBag != null) 126 { 127 handler = maker.lookup(CategoryBagHandler.TAG_NAME); 128 handler.marshal(catBag,element); 129 } 130 131 TModelBag bag = request.getTModelBag(); 132 if (bag != null) 133 { 134 handler = maker.lookup(TModelBagHandler.TAG_NAME); 135 handler.marshal(bag,element); 136 } 137 138 parent.appendChild(element); 139 } 140 141 142 143 144 145 146 147 public static void main(String args[]) 148 throws Exception 149 { 150 HandlerMaker maker = HandlerMaker.getInstance(); 151 AbstractHandler handler = maker.lookup(FindBindingHandler.TAG_NAME); 152 153 Element parent = XMLUtils.newRootElement(); 154 Element child = null; 155 156 CategoryBag catBag = new CategoryBag(); 157 catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue")); 158 catBag.addKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","catBagKeyName2","catBagKeyValue2")); 159 160 TModelBag bag = new TModelBag(); 161 bag.addTModelKey("uuid:35d9793b-9911-4b85-9f0e-5d4c65b4f253"); 162 bag.addTModelKey(new TModelKey("uuid:c5ab113f-0d6b-4247-b3c4-8c012726acd8")); 163 164 FindBinding request = new FindBinding(); 165 request.addFindQualifier(new FindQualifier(FindQualifier.SORT_BY_DATE_ASC)); 166 request.addFindQualifier(new FindQualifier(FindQualifier.AND_ALL_KEYS)); 167 request.setMaxRows(50); 168 request.setServiceKey("fd36dbce-bc3e-468b-8346-5374975a0843"); 169 request.setTModelBag(bag); 170 request.setCategoryBag(catBag); 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 |