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.response.ErrInfo;
20  import org.apache.juddi.util.xml.XMLUtils;
21  import org.w3c.dom.Element;
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 TAG_NAME = "errInfo";
31  
32    protected ErrInfoHandler(HandlerMaker maker)
33    {
34    }
35  
36    public RegistryObject unmarshal(Element element)
37    {
38      ErrInfo obj = new ErrInfo();
39  
40      // Attributes
41      obj.setErrCode(element.getAttribute("errCode"));
42  
43      // Text Node Value
44      obj.setErrMsg(XMLUtils.getText(element));
45  
46      // Child Elements
47      // {none}
48  
49      return obj;
50    }
51  
52    public void marshal(RegistryObject object,Element parent)
53    {
54      ErrInfo errInfo = (ErrInfo)object;
55      String generic = getGeneric(null);
56      String namespace = getUDDINamespace(generic);
57      Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
58  
59      String errCode = errInfo.getErrCode();
60      if (errCode != null)
61        element.setAttribute("errCode",errCode);
62  
63      String lineValue = errInfo.getErrMsg();
64      if (lineValue != null)
65        element.appendChild(parent.getOwnerDocument().createTextNode(lineValue));
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(ErrInfoHandler.TAG_NAME);
81      Element parent = XMLUtils.newRootElement();
82      Element child = null;
83  
84      ErrInfo errInfo = new ErrInfo();
85      errInfo.setErrCode("E_accountLimitExceeded");
86      errInfo.setErrMsg("Authentication token information has timed out.");
87  
88      System.out.println();
89  
90      RegistryObject regObject = errInfo;
91      handler.marshal(regObject,parent);
92      child = (Element)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)parent.getFirstChild();
101     parent.removeChild(child);
102     XMLUtils.writeXML(child,System.out);
103 
104     System.out.println();
105   }
106 }