1 16 package org.apache.juddi.handler; 17 18 import java.util.Vector ; 19 20 import org.apache.juddi.datatype.RegistryObject; 21 import org.apache.juddi.datatype.publisher.Publisher; 22 import org.apache.juddi.util.xml.XMLUtils; 23 import org.w3c.dom.Element ; 24 25 31 public class PublisherHandler extends AbstractHandler 32 { 33 public static final String TAG_NAME = "publisher"; 34 35 private HandlerMaker maker = null; 36 37 protected PublisherHandler(HandlerMaker maker) 38 { 39 this.maker = maker; 40 } 41 42 public RegistryObject unmarshal(Element element) 43 { 44 Publisher obj = new Publisher(); 45 Vector nodeList = null; 46 AbstractHandler handler = null; 47 48 obj.setPublisherID(element.getAttribute("publisherID")); 50 obj.setName(element.getAttribute("publisherName")); 51 52 String admin = element.getAttribute("admin"); 53 if ((admin != null) && (admin.length() > 0)) 54 obj.setAdminValue(admin); 55 else 56 obj.setAdmin(false); 57 58 String enabled = element.getAttribute("enabled"); 59 if ((enabled != null) && (enabled.length() > 0)) 60 obj.setEnabledValue(enabled); 61 else 62 obj.setAdmin(false); 63 64 String emailAddress = element.getAttribute("emailAddress"); 65 if ((emailAddress != null) && (emailAddress.length() > 0)) 66 obj.setEmailAddress(emailAddress); 67 68 71 74 return obj; 75 } 76 77 public void marshal(RegistryObject object,Element parent) 78 { 79 Publisher publisher = (Publisher)object; 80 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 81 AbstractHandler handler = null; 82 83 String publisherID = publisher.getPublisherID(); 85 if ((publisherID != null) && (publisherID.length() > 0)) 86 element.setAttribute("publisherID",publisherID); 87 else 88 element.setAttribute("publisherID",""); 89 90 String publisherName = publisher.getName(); 91 if ((publisherName != null) && (publisherName.length() > 0)) 92 element.setAttribute("publisherName",publisherName); 93 else 94 element.setAttribute("publisherName",""); 95 96 element.setAttribute("admin",String.valueOf(publisher.isAdmin())); 97 element.setAttribute("enabled",String.valueOf(publisher.isEnabled())); 98 99 String emailAddress = publisher.getEmailAddress(); 100 if ((emailAddress != null) && (emailAddress.length() > 0)) 101 element.setAttribute("emailAddress",emailAddress); 102 103 106 109 parent.appendChild(element); 110 } 111 112 113 114 115 116 117 118 public static void main(String args[]) 119 throws Exception 120 { 121 HandlerMaker maker = HandlerMaker.getInstance(); 122 AbstractHandler handler = maker.lookup(PublisherHandler.TAG_NAME); 123 Element parent = XMLUtils.newRootElement(); 124 Element child = null; 125 126 Publisher publisher = new Publisher(); 127 publisher.setPublisherID("bcrosby"); 128 publisher.setName("Bing Crosby"); 129 publisher.setEmailAddress("bcrosby@juddi.org"); 130 publisher.setAdmin(true); 131 publisher.setEnabled(true); 132 133 System.out.println(); 134 135 RegistryObject regObject = publisher; 136 handler.marshal(regObject,parent); 137 child = (Element )parent.getFirstChild(); 138 parent.removeChild(child); 139 XMLUtils.writeXML(child,System.out); 140 141 System.out.println(); 142 143 regObject = handler.unmarshal(child); 144 handler.marshal(regObject,parent); 145 child = (Element )parent.getFirstChild(); 146 parent.removeChild(child); 147 XMLUtils.writeXML(child,System.out); 148 } 149 } | Popular Tags |