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 org.apache.juddi.datatype.RegistryObject;
19  import org.apache.juddi.datatype.request.FindQualifier;
20  import org.apache.juddi.util.xml.XMLUtils;
21  import org.w3c.dom.Element;
22  
23  
24  /***
25   * FindQualifierHandler
26   *
27   * "Knows about the creation and populating of FindQualifier objects.
28   * Returns FindQualifier."
29   *
30   * @author Steve Viens (sviens@apache.org)
31   */
32  public class FindQualifierHandler extends AbstractHandler
33  {
34    public static final String TAG_NAME = "findQualifier";
35  
36    protected FindQualifierHandler(HandlerMaker maker)
37    {
38    }
39  
40    public RegistryObject unmarshal(Element element)
41    {
42      FindQualifier obj = new FindQualifier();
43  
44      // Attributes
45      // {none}
46  
47      // Text Node Value
48      obj.setValue(XMLUtils.getText(element));
49  
50      // Child Elements
51      // {none}
52  
53      return obj;
54    }
55  
56    public void marshal(RegistryObject object,Element parent)
57    {
58      FindQualifier qualifier = (FindQualifier)object;
59      String generic = getGeneric(null);
60      String namespace = getUDDINamespace(generic);
61      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
62  
63      String qValue = qualifier.getValue();
64      if (qValue != null)
65        element.appendChild(parent.getOwnerDocument().createTextNode(qValue));
66  
67      parent.appendChild(element);
68    }
69  
70  
71    /****************************************************************************/
72    /****************************** TEST DRIVER *********************************/
73    /****************************************************************************/
74  
75  
76    public static void main(String args[])
77      throws Exception
78    {
79      HandlerMaker maker = HandlerMaker.getInstance();
80      AbstractHandler handler = maker.lookup(FindQualifierHandler.TAG_NAME);
81  
82      Element parent = XMLUtils.newRootElement();
83      Element child = null;
84  
85      FindQualifier qualifier = new FindQualifier(FindQualifier.SORT_BY_NAME_ASC);
86  
87      System.out.println();
88  
89      RegistryObject regObject = qualifier;
90      handler.marshal(regObject,parent);
91      child = (Element)parent.getFirstChild();
92      parent.removeChild(child);
93      XMLUtils.writeXML(child,System.out);
94  
95      System.out.println();
96  
97      regObject = handler.unmarshal(child);
98      handler.marshal(regObject,parent);
99      child = (Element)parent.getFirstChild();
100     parent.removeChild(child);
101     XMLUtils.writeXML(child,System.out);
102   }
103 }