1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.datatype.Name; 21 import org.apache.juddi.datatype.RegistryObject; 22 import org.apache.juddi.datatype.request.FindPublisher; 23 import org.apache.juddi.datatype.request.FindQualifier; 24 import org.apache.juddi.datatype.request.FindQualifiers; 25 import org.apache.juddi.util.xml.XMLUtils; 26 import org.w3c.dom.Element ; 27 28 34 public class FindPublisherHandler extends AbstractHandler 35 { 36 public static final String TAG_NAME = "find_publisher"; 37 38 private HandlerMaker maker = null; 39 40 protected FindPublisherHandler(HandlerMaker maker) 41 { 42 this.maker = maker; 43 } 44 45 public RegistryObject unmarshal(Element element) 46 { 47 FindPublisher obj = new FindPublisher(); 48 Vector nodeList = null; 49 AbstractHandler handler = null; 50 51 String generic = element.getAttribute("generic"); 53 if ((generic != null && (generic.trim().length() > 0))) 54 obj.setGeneric(generic); 55 56 String maxRows = element.getAttribute("maxRows"); 57 if ((maxRows != null) && (maxRows.length() > 0)) 58 obj.setMaxRows(maxRows); 59 60 63 nodeList = XMLUtils.getChildElementsByTagName(element,NameHandler.TAG_NAME); 65 if (nodeList.size() > 0) 66 { 67 handler = maker.lookup(NameHandler.TAG_NAME); 68 Name name = (Name )handler.unmarshal((Element )nodeList.elementAt(0)); 69 if (name != null) 70 obj.setName(name); 71 } 72 73 nodeList = XMLUtils.getChildElementsByTagName(element,FindQualifiersHandler.TAG_NAME); 74 if (nodeList.size() > 0) 75 { 76 handler = maker.lookup(FindQualifiersHandler.TAG_NAME); 77 obj.setFindQualifiers((FindQualifiers)handler.unmarshal((Element )nodeList.elementAt(0))); 78 } 79 80 return obj; 81 } 82 83 public void marshal(RegistryObject object,Element parent) 84 { 85 FindPublisher request = (FindPublisher)object; 86 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 87 AbstractHandler handler = null; 88 89 String generic = request.getGeneric(); 90 if (generic != null) 91 element.setAttribute("generic",generic); 92 93 int maxRows = request.getMaxRows(); 94 if (maxRows > 0) 95 element.setAttribute("maxRows",String.valueOf(maxRows)); 96 97 FindQualifiers qualifiers = request.getFindQualifiers(); 98 if ((qualifiers != null) && (qualifiers.size() > 0)) 99 { 100 handler = maker.lookup(FindQualifiersHandler.TAG_NAME); 101 handler.marshal(qualifiers,element); 102 } 103 104 Name name = request.getName(); 105 if (name != null) 106 { 107 handler = maker.lookup(NameHandler.TAG_NAME); 108 handler.marshal(name,element); 109 } 110 111 parent.appendChild(element); 112 } 113 114 115 116 117 118 119 120 public static void main(String args[]) 121 throws Exception 122 { 123 HandlerMaker maker = HandlerMaker.getInstance(); 124 AbstractHandler handler = maker.lookup(FindPublisherHandler.TAG_NAME); 125 126 Element parent = XMLUtils.newRootElement(); 127 Element child = null; 128 129 FindPublisher request = new FindPublisher(); 130 request.setName(new Name("s","en")); 131 request.addFindQualifier(new FindQualifier(FindQualifier.SORT_BY_NAME_ASC)); 132 request.setMaxRows(50); 133 134 System.out.println(); 135 136 RegistryObject regObject = request; 137 handler.marshal(regObject,parent); 138 child = (Element )parent.getFirstChild(); 139 parent.removeChild(child); 140 XMLUtils.writeXML(child,System.out); 141 142 System.out.println(); 143 144 regObject = handler.unmarshal(child); 145 handler.marshal(regObject,parent); 146 child = (Element )parent.getFirstChild(); 147 parent.removeChild(child); 148 XMLUtils.writeXML(child,System.out); 149 } 150 } | Popular Tags |