KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_lib > deployment > xml > AbsElement


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
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 1any 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: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: AbsElement.java,v 1.3 2004/05/10 12:04:39 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_lib.deployment.xml;
28
29 /**
30  * This class defines the implementation of the interface Element.
31  * These elements are used by Digester during the xml parsing.
32  * @author Florent Benoit
33  */

34 public abstract class AbsElement implements Element {
35
36
37     /**
38      * Represents this element by it's XML description.
39      * @param indent use this indent for prexifing XML representation.
40      * @return the XML description of this object.
41      */

42     public abstract String JavaDoc toXML(int indent);
43
44
45     /**
46      * Represents this element by it's XML description.
47      * Use a default indent set to 0.
48      * @return the XML description of this object.
49      */

50     public String JavaDoc toXML() {
51         return toXML(0);
52     }
53
54     /**
55      * Return the representation of this element.
56      * Use the XML representation of the object for the toString() method.
57      * @return the XML description of this object.
58      */

59     public String JavaDoc toString() {
60         return toXML();
61     }
62
63
64     /**
65      * Return indent spaces.
66      * @param indent number of indentation.
67      * @return the indent space string.
68      */

69     protected String JavaDoc indent(int indent) {
70         String JavaDoc txt = "";
71         for (int i = 0; i < indent; i++) {
72             txt += " ";
73         }
74         return txt;
75     }
76
77     /**
78      * Return the xml representation of the specified value with the root-element xmlTag
79      * @param value String value to represent in XML
80      * @param xmlTag tag of the root-element
81      * @param indent indent to use
82      * @return xml representation of the specified value
83      */

84     protected String JavaDoc xmlElement(String JavaDoc value, String JavaDoc xmlTag, int indent) {
85         if (value == null) {
86             return "";
87         }
88
89         // else
90

91         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
92         sb.append(indent(indent));
93         sb.append("<");
94         sb.append(xmlTag);
95         sb.append(">");
96         sb.append(value);
97         sb.append("</");
98         sb.append(xmlTag);
99         sb.append(">\n");
100         return sb.toString();
101     }
102
103     /**
104      * Return the xml representation of the specified attribute value
105      * @param value String value to represent in XML
106      * @param xmlTag tag of the attribute
107      * @return xml representation of the specified value
108      */

109     protected String JavaDoc xmlAttribute(String JavaDoc value, String JavaDoc xmlTag) {
110         if (value == null) {
111             return "";
112         }
113
114         // else
115

116         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
117         sb.append(" ");
118         sb.append(xmlTag);
119         sb.append("=\"");
120         sb.append(value);
121         sb.append("\"");
122         return sb.toString();
123     }
124
125 }
126
Popular Tags