1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.xmlrpc;
16  
17  import com.liferay.portal.kernel.util.StringBundler;
18  import com.liferay.portal.kernel.xmlrpc.Fault;
19  import com.liferay.portal.kernel.xmlrpc.XmlRpcException;
20  
21  /**
22   * <a href="FaultImpl.java.html"><b><i>View Source</i></b></a>
23   *
24   * @author Alexander Chow
25   * @author Brian Wing Shun Chan
26   */
27  public class FaultImpl implements Fault {
28  
29      public FaultImpl(int code, String description) {
30          _code = code;
31          _description = description;
32      }
33  
34      public int getCode() {
35          return _code;
36      }
37  
38      public String getDescription() {
39          return _description;
40      }
41  
42      public String toString() {
43          return "XML-RPC fault " + _code + " " + _description;
44      }
45  
46      public String toXml() throws XmlRpcException {
47          StringBundler sb = new StringBundler(17);
48  
49          sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
50  
51          sb.append("<methodResponse>");
52          sb.append("<fault>");
53          sb.append("<value>");
54          sb.append("<struct>");
55          sb.append("<member>");
56          sb.append("<name>faultCode</name>");
57          sb.append(XmlRpcParser.wrapValue(_code));
58          sb.append("</member>");
59          sb.append("<member>");
60          sb.append("<name>faultString</name>");
61          sb.append(XmlRpcParser.wrapValue(_description));
62          sb.append("</member>");
63          sb.append("</struct>");
64          sb.append("</value>");
65          sb.append("</fault>");
66          sb.append("</methodResponse>");
67  
68          return sb.toString();
69      }
70  
71      private int _code;
72      private String _description;
73  
74  }