KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > jms > admin > XmlSerializer


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Florent Benoit, Benoit Pelletier
22  */

23
24 package org.objectweb.joram.client.jms.admin;
25
26 /**
27  * This class defines the methods for serializing an object to XML
28  */

29 public class XmlSerializer {
30
31
32     /**
33      * Return indent spaces.
34      * @param indent number of indentation.
35      * @return the indent space string.
36      */

37     public static String JavaDoc indent(int indent) {
38         String JavaDoc txt = "";
39         for (int i = 0; i < indent; i++) {
40             txt += " ";
41         }
42         return txt;
43     }
44
45     /**
46      * Return the xml representation of the specified value with the root-element xmlTag
47      * @param value String value to represent in XML
48      * @param xmlTag tag of the root-element
49      * @param indent indent to use
50      * @return xml representation of the specified value
51      */

52     public static String JavaDoc xmlElement(String JavaDoc value, String JavaDoc xmlTag, int indent) {
53         if (value == null) {
54             return "";
55         }
56
57         // else
58

59         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
60         sb.append(indent(indent));
61         sb.append("<");
62         sb.append(xmlTag);
63         sb.append(">");
64         sb.append(value);
65         sb.append("</");
66         sb.append(xmlTag);
67         sb.append(">\n");
68         return sb.toString();
69     }
70
71     /**
72      * Return the xml representation of the specified attribute value
73      * @param value String value to represent in XML
74      * @param xmlTag tag of the attribute
75      * @return xml representation of the specified value
76      */

77     public static String JavaDoc xmlAttribute(String JavaDoc value, String JavaDoc xmlTag) {
78         if (value == null) {
79             return "";
80         }
81
82         // else
83

84         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
85         sb.append(" ");
86         sb.append(xmlTag);
87         sb.append("=\"");
88         sb.append(value);
89         sb.append("\"");
90         return sb.toString();
91     }
92
93 }
94
Popular Tags