KickJava   Java API By Example, From Geeks To Geeks.

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


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 JavaDoc;
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 JavaDoc TAG_NAME = "findQualifier";
35
36   private HandlerMaker maker = null;
37
38   protected FindQualifierHandler(HandlerMaker maker)
39   {
40     this.maker = maker;
41   }
42
43   public RegistryObject unmarshal(Element JavaDoc element)
44   {
45     FindQualifier obj = new FindQualifier();
46
47     // Attributes
48
// {none}
49

50     // Text Node Value
51
obj.setValue(XMLUtils.getText(element));
52
53     // Child Elements
54
// {none}
55

56     return obj;
57   }
58
59   public void marshal(RegistryObject object,Element JavaDoc parent)
60   {
61     FindQualifier qualifier = (FindQualifier)object;
62     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
63
64     String JavaDoc qValue = qualifier.getValue();
65     if (qValue != null)
66       element.appendChild(parent.getOwnerDocument().createTextNode(qValue));
67
68     parent.appendChild(element);
69   }
70
71
72   /***************************************************************************/
73   /***************************** TEST DRIVER *********************************/
74   /***************************************************************************/
75
76
77   public static void main(String JavaDoc args[])
78     throws Exception JavaDoc
79   {
80     HandlerMaker maker = HandlerMaker.getInstance();
81     AbstractHandler handler = maker.lookup(FindQualifierHandler.TAG_NAME);
82
83     Element JavaDoc parent = XMLUtils.newRootElement();
84     Element JavaDoc child = null;
85
86     FindQualifier qualifier = new FindQualifier(FindQualifier.SORT_BY_NAME_ASC);
87
88     System.out.println();
89
90     RegistryObject regObject = qualifier;
91     handler.marshal(regObject,parent);
92     child = (Element JavaDoc)parent.getFirstChild();
93     parent.removeChild(child);
94     XMLUtils.writeXML(child,System.out);
95
96     System.out.println();
97
98     regObject = handler.unmarshal(child);
99     handler.marshal(regObject,parent);
100     child = (Element JavaDoc)parent.getFirstChild();
101     parent.removeChild(child);
102     XMLUtils.writeXML(child,System.out);
103   }
104 }
Popular Tags