KickJava   Java API By Example, From Geeks To Geeks.

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


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.response.ErrInfo;
20 import org.apache.juddi.util.xml.XMLUtils;
21 import org.w3c.dom.Element JavaDoc;
22
23 /**
24  * ErrInfoHandler
25  *
26  * @author Steve Viens (sviens@apache.org)
27  */

28 public class ErrInfoHandler extends AbstractHandler
29 {
30   public static final String JavaDoc TAG_NAME = "errInfo";
31
32   private HandlerMaker maker = null;
33
34   protected ErrInfoHandler(HandlerMaker maker)
35   {
36     this.maker = maker;
37   }
38
39   public RegistryObject unmarshal(Element JavaDoc element)
40   {
41     ErrInfo obj = new ErrInfo();
42
43     // Attributes
44
obj.setErrCode(element.getAttribute("errCode"));
45
46     // Text Node Value
47
obj.setErrMsg(XMLUtils.getText(element));
48
49     // Child Elements
50
// {none}
51

52     return obj;
53   }
54
55   public void marshal(RegistryObject object,Element JavaDoc parent)
56   {
57     ErrInfo errInfo = (ErrInfo)object;
58     Element JavaDoc element = parent.getOwnerDocument().createElementNS(null,TAG_NAME);
59
60     String JavaDoc errCode = errInfo.getErrCode();
61     if (errCode != null)
62       element.setAttribute("errCode",errCode);
63
64     String JavaDoc lineValue = errInfo.getErrMsg();
65     if (lineValue != null)
66       element.appendChild(parent.getOwnerDocument().createTextNode(lineValue));
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(ErrInfoHandler.TAG_NAME);
82     Element JavaDoc parent = XMLUtils.newRootElement();
83     Element JavaDoc child = null;
84
85     ErrInfo errInfo = new ErrInfo();
86     errInfo.setErrCode("E_accountLimitExceeded");
87     errInfo.setErrMsg("Authentication token information has timed out.");
88
89     System.out.println();
90
91     RegistryObject regObject = errInfo;
92     handler.marshal(regObject,parent);
93     child = (Element JavaDoc)parent.getFirstChild();
94     parent.removeChild(child);
95     XMLUtils.writeXML(child,System.out);
96
97     System.out.println();
98
99     regObject = handler.unmarshal(child);
100     handler.marshal(regObject,parent);
101     child = (Element JavaDoc)parent.getFirstChild();
102     parent.removeChild(child);
103     XMLUtils.writeXML(child,System.out);
104
105     System.out.println();
106   }
107 }
Popular Tags