View Javadoc

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;
19  
20  import org.apache.juddi.datatype.BindingKey;
21  import org.apache.juddi.datatype.RegistryObject;
22  import org.apache.juddi.datatype.subscription.Subscription;
23  import org.apache.juddi.datatype.subscription.SubscriptionFilter;
24  import org.apache.juddi.util.xml.XMLUtils;
25  import org.w3c.dom.Element;
26  
27  /***
28   * SubscriptionHandler
29   *
30   * @author Steve Viens (sviens@apache.org)
31   * @author Anou Mana (anou_mana@users.sourceforge.net)
32   */
33  public class SubscriptionHandler extends AbstractHandler
34  {
35    public static final String TAG_NAME = "subscription";
36  
37    protected SubscriptionHandler(HandlerMaker maker)
38    {
39    }
40  
41    public RegistryObject unmarshal(Element element)
42    {
43      // TODO (UDDI v3) Fill out SubscriptoinHandler.unmarshal()
44        
45      Subscription obj = new Subscription();
46  
47      // Attributes
48      obj.setSubscriptionKey(element.getAttribute("subscriptionKey"));
49  
50      // Text Node Value
51      // [none]
52  
53      // Child Elements
54  
55      return obj;
56    }
57  
58    public void marshal(RegistryObject object,Element parent)
59    {
60      Subscription subscription = (Subscription)object;
61      String generic = getGeneric(null);
62      String namespace = getUDDINamespace(generic);
63      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
64  
65      String subscriptionKey = subscription.getSubscriptionKey();
66      if (subscriptionKey != null)
67        element.setAttribute("subscriptionKey",subscriptionKey);
68  
69      // TODO (UDDI v3) Fill out SubscriptoinHandler.marshal()
70  
71      parent.appendChild(element);
72    }
73  
74  
75    /****************************************************************************/
76    /****************************** TEST DRIVER *********************************/
77    /****************************************************************************/
78  
79  
80    public static void main(String args[])
81      throws Exception
82    {
83      HandlerMaker maker = HandlerMaker.getInstance();
84      AbstractHandler handler = maker.lookup(SubscriptionHandler.TAG_NAME);
85  
86      Element parent = XMLUtils.newRootElement();
87      Element child = null;
88  
89      Subscription subscription = new Subscription();
90      subscription.setSubscriptionKey("uuid:269855db-62eb-4862-8e5a-1b06f2753038");
91      subscription.setBindingKey(new BindingKey(""));
92      subscription.setBrief(true);
93      subscription.setExpiresAfter(new Date());
94      subscription.setMaxEntities(100);
95      subscription.setNotificationInterval("");
96      subscription.setSubscriptionFilter(new SubscriptionFilter());
97  
98      System.out.println();
99  
100     RegistryObject regObject = subscription;
101     handler.marshal(regObject,parent);
102     child = (Element)parent.getFirstChild();
103     parent.removeChild(child);
104     XMLUtils.writeXML(child,System.out);
105 
106     System.out.println();
107 
108     regObject = handler.unmarshal(child);
109     handler.marshal(regObject,parent);
110     child = (Element)parent.getFirstChild();
111     parent.removeChild(child);
112     XMLUtils.writeXML(child,System.out);
113   }
114 }