001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or 1any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: JLinkedList.java 4718 2004-05-10 12:06:09Z sauthieg $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas_lib.deployment.xml;
026:
027: import java.util.Iterator;
028: import java.util.LinkedList;
029:
030: /**
031: * This class defines a linked list with the ability to display its content in XML.
032: * @author Florent Benoit
033: */
034: public class JLinkedList extends LinkedList {
035:
036: /**
037: * Tag of the root element
038: */
039: private String tag = null;
040:
041: /**
042: * Constructor with a specified tag
043: * @param tag of the root element (use for xml representation)
044: */
045: public JLinkedList(String tag) {
046: super ();
047: this .tag = tag;
048: }
049:
050: /**
051: * Represents this element by it's XML description.
052: * Use a default indent set to 0.
053: * @return the XML description of this object.
054: */
055: public String toXML() {
056: return toXML(0);
057: }
058:
059: /**
060: * Return the representation of this element.
061: * Use the XML representation of the object for the toString() method.
062: * @return the XML description of this object.
063: */
064: public String toString() {
065: return toXML();
066: }
067:
068: /**
069: * Return indent spaces.
070: * @param indent number of indentation.
071: * @return the indent space string.
072: */
073: private String indent(int indent) {
074: String txt = "";
075: for (int i = 0; i < indent; i++) {
076: txt += " ";
077: }
078: return txt;
079: }
080:
081: /**
082: * Represents this element by it's XML description.
083: * @param indent use this indent for prexifing XML representation.
084: * @return the XML description of this object.
085: */
086: public String toXML(int indent) {
087: StringBuffer sb = new StringBuffer();
088: // Only if there are elements
089: if (this .size() > 0) {
090: for (Iterator i = this .iterator(); i.hasNext();) {
091: Object o = i.next();
092: // Element or String ?
093: if (o instanceof Element) {
094: sb.append(((Element) o).toXML(indent));
095: } else {
096: sb.append(indent(indent));
097: sb.append("<");
098: sb.append(tag);
099: sb.append(">");
100: sb.append(o);
101: sb.append("</");
102: sb.append(tag);
103: sb.append(">\n");
104: }
105: }
106: }
107: return sb.toString();
108: }
109:
110: }
|