1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.datatype.BusinessKey; 21 import org.apache.juddi.datatype.KeyedReference; 22 import org.apache.juddi.datatype.RegistryObject; 23 import org.apache.juddi.datatype.request.FindQualifier; 24 import org.apache.juddi.datatype.request.FindQualifiers; 25 import org.apache.juddi.datatype.request.FindRelatedBusinesses; 26 import org.apache.juddi.util.xml.XMLUtils; 27 import org.w3c.dom.Element ; 28 29 33 public class FindRelatedBusinessesHandler extends AbstractHandler 34 { 35 public static final String TAG_NAME = "find_relatedBusinesses"; 36 37 private HandlerMaker maker = null; 38 39 protected FindRelatedBusinessesHandler(HandlerMaker maker) 40 { 41 this.maker = maker; 42 } 43 44 public RegistryObject unmarshal(Element element) 45 { 46 FindRelatedBusinesses obj = new FindRelatedBusinesses(); 47 Vector nodeList = null; 48 AbstractHandler handler = null; 49 50 String generic = element.getAttribute("generic"); 52 if ((generic != null && (generic.trim().length() > 0))) 53 obj.setGeneric(generic); 54 55 String maxRows = element.getAttribute("maxRows"); 56 if ((maxRows != null) && (maxRows.length() > 0)) 57 obj.setMaxRows(maxRows); 58 59 62 nodeList = XMLUtils.getChildElementsByTagName(element,BusinessKeyHandler.TAG_NAME); 64 if (nodeList.size() > 0) 65 { 66 handler = maker.lookup(BusinessKeyHandler.TAG_NAME); 67 obj.setBusinessKey((BusinessKey)handler.unmarshal((Element )nodeList.elementAt(0))); 68 } 69 70 nodeList = XMLUtils.getChildElementsByTagName(element,FindQualifiersHandler.TAG_NAME); 71 if (nodeList.size() > 0) 72 { 73 handler = maker.lookup(FindQualifiersHandler.TAG_NAME); 74 obj.setFindQualifiers((FindQualifiers)handler.unmarshal((Element )nodeList.elementAt(0))); 75 } 76 77 nodeList = XMLUtils.getChildElementsByTagName(element,KeyedReferenceHandler.TAG_NAME); 78 if (nodeList.size() > 0) 79 { 80 handler = maker.lookup(KeyedReferenceHandler.TAG_NAME); 81 obj.setKeyedReference((KeyedReference)handler.unmarshal((Element )nodeList.elementAt(0))); 82 } 83 84 return obj; 85 } 86 87 public void marshal(RegistryObject object,Element parent) 88 { 89 FindRelatedBusinesses request = (FindRelatedBusinesses)object; 90 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 91 AbstractHandler handler = null; 92 93 String generic = request.getGeneric(); 94 if (generic != null) 95 element.setAttribute("generic",generic); 96 97 int maxRows = request.getMaxRows(); 98 if (maxRows > 0) 99 element.setAttribute("maxRows",String.valueOf(maxRows)); 100 101 FindQualifiers qualifiers = request.getFindQualifiers(); 102 if ((qualifiers != null) && (qualifiers.size() > 0)) 103 { 104 handler = maker.lookup(FindQualifiersHandler.TAG_NAME); 105 handler.marshal(qualifiers,element); 106 } 107 108 BusinessKey businessKey = new BusinessKey(request.getBusinessKey()); 109 if (businessKey != null) 110 { 111 handler = maker.lookup(BusinessKeyHandler.TAG_NAME); 112 handler.marshal(businessKey,element); 113 } 114 115 KeyedReference keyedRef = request.getKeyedReference(); 116 if (keyedRef != null) 117 { 118 handler = maker.lookup(KeyedReferenceHandler.TAG_NAME); 119 handler.marshal(keyedRef,element); 120 } 121 122 parent.appendChild(element); 123 } 124 125 126 127 128 129 130 131 public static void main(String args[]) 132 throws Exception 133 { 134 HandlerMaker maker = HandlerMaker.getInstance(); 135 AbstractHandler handler = maker.lookup(FindRelatedBusinessesHandler.TAG_NAME); 136 137 Element parent = XMLUtils.newRootElement(); 138 Element child = null; 139 140 FindRelatedBusinesses request = new FindRelatedBusinesses(); 141 request.setBusinessKey("10ad2903-932f-49fe-aaed-bf80d0ed50f0"); 142 request.addFindQualifier(new FindQualifier(FindQualifier.SORT_BY_DATE_ASC)); 143 request.addFindQualifier(new FindQualifier(FindQualifier.AND_ALL_KEYS)); 144 request.setMaxRows(43); 145 request.setKeyedReference(new KeyedReference("uuid:8ff45356-acde-4a4c-86bf-f953611d20c6","catBagKeyName2","catBagKeyValue2")); 146 147 System.out.println(); 148 149 RegistryObject regObject = request; 150 handler.marshal(regObject,parent); 151 child = (Element )parent.getFirstChild(); 152 parent.removeChild(child); 153 XMLUtils.writeXML(child,System.out); 154 155 System.out.println(); 156 157 regObject = handler.unmarshal(child); 158 handler.marshal(regObject,parent); 159 child = (Element )parent.getFirstChild(); 160 parent.removeChild(child); 161 XMLUtils.writeXML(child,System.out); 162 } 163 } | Popular Tags |