KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > handler > SubscriptionHandler


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.handler;
17
18 import java.util.Date JavaDoc;
19 import java.util.Vector JavaDoc;
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 JavaDoc;
27
28 /**
29  * SubscriptionHandler
30  *
31  * @author Steve Viens (sviens@apache.org)
32  * @author Anou Mana (anou_mana@users.sourceforge.net)
33  */

34 public class SubscriptionHandler extends AbstractHandler
35 {
36   public static final String JavaDoc 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 JavaDoc element)
46   {
47     // TODO (UDDI v3) Fill out SubscriptoinHandler.unmarshal()
48

49     Subscription obj = new Subscription();
50     Vector JavaDoc nodeList = null;
51     AbstractHandler handler = null;
52
53     // Attributes
54
obj.setSubscriptionKey(element.getAttribute("subscriptionKey"));
55
56     // Text Node Value
57
// [none]
58

59     // Child Elements
60

61     return obj;
62   }
63
64   public void marshal(RegistryObject object,Element JavaDoc parent)
65   {
66     Subscription subscription = (Subscription)object;
67     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
68     AbstractHandler handler = null;
69
70     String JavaDoc subscriptionKey = subscription.getSubscriptionKey();
71     if (subscriptionKey != null)
72       element.setAttribute("subscriptionKey",subscriptionKey);
73
74     // TODO (UDDI v3) Fill out SubscriptoinHandler.marshal()
75

76     parent.appendChild(element);
77   }
78
79
80   /***************************************************************************/
81   /***************************** TEST DRIVER *********************************/
82   /***************************************************************************/
83
84
85   public static void main(String JavaDoc args[])
86     throws Exception JavaDoc
87   {
88     HandlerMaker maker = HandlerMaker.getInstance();
89     AbstractHandler handler = maker.lookup(SubscriptionHandler.TAG_NAME);
90
91     Element JavaDoc parent = XMLUtils.newRootElement();
92     Element JavaDoc 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 JavaDoc());
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 JavaDoc)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 JavaDoc)parent.getFirstChild();
116     parent.removeChild(child);
117     XMLUtils.writeXML(child,System.out);
118   }
119 }
Popular Tags