001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.xmlrpc;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.xmlrpc.Fault;
019    import com.liferay.portal.kernel.xmlrpc.XmlRpcException;
020    
021    /**
022     * @author Alexander Chow
023     * @author Brian Wing Shun Chan
024     */
025    public class FaultImpl implements Fault {
026    
027            public FaultImpl(int code, String description) {
028                    _code = code;
029                    _description = description;
030            }
031    
032            public int getCode() {
033                    return _code;
034            }
035    
036            public String getDescription() {
037                    return _description;
038            }
039    
040            public String toString() {
041                    return "XML-RPC fault " + _code + " " + _description;
042            }
043    
044            public String toXml() throws XmlRpcException {
045                    StringBundler sb = new StringBundler(17);
046    
047                    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
048    
049                    sb.append("<methodResponse>");
050                    sb.append("<fault>");
051                    sb.append("<value>");
052                    sb.append("<struct>");
053                    sb.append("<member>");
054                    sb.append("<name>faultCode</name>");
055                    sb.append(XmlRpcParser.wrapValue(_code));
056                    sb.append("</member>");
057                    sb.append("<member>");
058                    sb.append("<name>faultString</name>");
059                    sb.append(XmlRpcParser.wrapValue(_description));
060                    sb.append("</member>");
061                    sb.append("</struct>");
062                    sb.append("</value>");
063                    sb.append("</fault>");
064                    sb.append("</methodResponse>");
065    
066                    return sb.toString();
067            }
068    
069            private int _code;
070            private String _description;
071    
072    }