1 16 package org.apache.juddi.handler; 17 18 import java.util.Date ; 19 import java.util.Vector ; 20 21 import org.apache.juddi.datatype.BindingKey; 22 import org.apache.juddi.datatype.RegistryObject; 23 import org.apache.juddi.datatype.subscription.Subscription; 24 import org.apache.juddi.datatype.subscription.SubscriptionFilter; 25 import org.apache.juddi.util.xml.XMLUtils; 26 import org.w3c.dom.Element ; 27 28 34 public class SubscriptionHandler extends AbstractHandler 35 { 36 public static final String TAG_NAME = "subscription"; 37 38 private HandlerMaker maker = null; 39 40 protected SubscriptionHandler(HandlerMaker maker) 41 { 42 this.maker = maker; 43 } 44 45 public RegistryObject unmarshal(Element element) 46 { 47 49 Subscription obj = new Subscription(); 50 Vector nodeList = null; 51 AbstractHandler handler = null; 52 53 obj.setSubscriptionKey(element.getAttribute("subscriptionKey")); 55 56 59 61 return obj; 62 } 63 64 public void marshal(RegistryObject object,Element parent) 65 { 66 Subscription subscription = (Subscription)object; 67 Element element = parent.getOwnerDocument().createElementNS(null,TAG_NAME); 68 AbstractHandler handler = null; 69 70 String subscriptionKey = subscription.getSubscriptionKey(); 71 if (subscriptionKey != null) 72 element.setAttribute("subscriptionKey",subscriptionKey); 73 74 76 parent.appendChild(element); 77 } 78 79 80 81 82 83 84 85 public static void main(String args[]) 86 throws Exception 87 { 88 HandlerMaker maker = HandlerMaker.getInstance(); 89 AbstractHandler handler = maker.lookup(SubscriptionHandler.TAG_NAME); 90 91 Element parent = XMLUtils.newRootElement(); 92 Element child = null; 93 94 Subscription subscription = new Subscription(); 95 subscription.setSubscriptionKey("uuid:269855db-62eb-4862-8e5a-1b06f2753038"); 96 subscription.setBindingKey(new BindingKey("")); 97 subscription.setBrief(true); 98 subscription.setExpiresAfter(new Date ()); 99 subscription.setMaxEntities(100); 100 subscription.setNotificationInterval(""); 101 subscription.setSubscriptionFilter(new SubscriptionFilter()); 102 103 System.out.println(); 104 105 RegistryObject regObject = subscription; 106 handler.marshal(regObject,parent); 107 child = (Element )parent.getFirstChild(); 108 parent.removeChild(child); 109 XMLUtils.writeXML(child,System.out); 110 111 System.out.println(); 112 113 regObject = handler.unmarshal(child); 114 handler.marshal(regObject,parent); 115 child = (Element )parent.getFirstChild(); 116 parent.removeChild(child); 117 XMLUtils.writeXML(child,System.out); 118 } 119 } | Popular Tags |