Source code: com/mvsteenb/javauitransformer/xmltransformer/components/XmlRootComponent.java
1 package com.mvsteenb.javauitransformer.xmltransformer.components;
2
3 import com.mvsteenb.javauitransformer.xmltransformer.util.XmlTransformerPrintBuffer;
4 import com.mvsteenb.javauitransformer.xmltransformer.util.StringUtil;
5 import com.mvsteenb.javauitransformer.xmltransformer.xmlelements.XmlDataElements;
6 import com.mvsteenb.javauitransformer.xmltransformer.xmlelements.XmlAbstractDataElement;
7 import com.mvsteenb.javauitransformer.xmltransformer.xmlelements.XmlDataElementAttributes;
8
9 import java.awt.*;
10
11 /**
12 * com.mvsteenb.javauitransformer.xmltransformer.components
13 *
14 * <p><b>About</b></p>
15 *
16 * <p>
17 * This class is part of the JavaUITransformer version @build.version@ (build #@build.number@) which was built on @build.date@.
18 * </p>
19 *
20 * <p><b>Description</b></p>
21 *
22 *
23 *
24 * <p><b>Free Software</b></p>
25 *
26 * <p>
27 * Copyright (C) 2003 Mario Van Steenberghe
28 * </p>
29 *
30 * <p>
31 * <small>
32 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
33 * General Public License as published by the Free Software Foundation; either version 2.1 of the License, or
34 * (at your option) any later version. This library is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
36 * PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the
37 * GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc.,
38 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
39 * </small>
40 * </p>
41 *
42 * <p>
43 * <small>
44 * Please contact me at mario.vansteenberghe@pandora.be for more information.
45 * </small>
46 * </p>
47 *
48 * <p><b>Revision History</b></p>
49 *
50 * <p>
51 * Aug 24, 2003 : mvsteenb : Initial Revision
52 * </p>
53 *
54 */
55
56 public abstract class XmlRootComponent extends XmlAbstractDataElement implements XmlComponentInterface {
57
58 private static final String ELEMENT_NAME = "uitransform";
59 private static final String DEBUG_MODE = "on";
60
61 protected Component component = null;
62 protected XmlDataElements dataElements = null;
63 protected int colSpan = 1;
64 protected int rowSpan = 1;
65 protected XmlDataElementAttributes rootAttributes = null;
66
67 /**
68 * Constructor
69 */
70
71 public XmlRootComponent(Component c) {
72 super(ELEMENT_NAME);
73 this.component = c;
74 }
75
76 // ================================================================================================================ //
77 // public methods //
78 // ================================================================================================================ //
79
80 /**
81 * Returns mapped java component
82 */
83
84 public Component getJavaComponent() {
85 return this.component;
86 }
87
88 /**
89 * Returns String representation of component tree
90 * @return component tree string
91 */
92
93 public String toString() {
94 return toString(0);
95 }
96
97 /**
98 * Returns String representation of component tree
99 * @return component tree string
100 */
101
102 public String toString(int indent) {
103 StringBuffer buf = new StringBuffer();
104 StringUtil.indent(indent, buf);
105 buf.append(super.toString()).append("\n");
106 return buf.toString();
107 }
108
109 /**
110 * Retusn xml representation of component
111 */
112
113 public void toXml(XmlTransformerPrintBuffer w) {
114 prepareRootAttributes();
115 addXmlRootOpeningTag(0, w);
116 toXml(2, w);
117 addXmlRootClosingTag(0, w);
118 }
119
120 /**
121 * Returns Xml element name
122 */
123
124 /*
125 public String getElementName() {
126 return getXmlRootElementName();
127 }
128 */
129
130 /**
131 * Returns Xml element name
132 */
133
134 public String getXmlRootElementName() {
135 return ELEMENT_NAME;
136 }
137
138 // ================================================================================================================ //
139 // protected methods //
140 // ================================================================================================================ //
141
142 /**
143 * Prepares attributes - this method should be overridden to prepare the element's attributes.
144 */
145
146 protected abstract void prepareAttributes();
147
148 /**
149 * Adds Xml Opening Tag to buffer
150 */
151
152 protected void addXmlRootOpeningTag(int indent, XmlTransformerPrintBuffer w) {
153 w.println("<?xml version=\"1.0\" encoding=\"" + w.getEncoding() + "\"?>");
154 w.print("<", indent);
155 w.print(getXmlRootElementName());
156 getRootAttributes().toXml(indent, w);
157 w.println(">");
158 }
159
160 /**
161 * Adds xml closing tag to buffer
162 */
163
164 protected void addXmlRootClosingTag(int indent, XmlTransformerPrintBuffer w) {
165 w.print("</", indent);
166 w.print(getXmlRootElementName());
167 w.println(">");
168 }
169
170 /**
171 * Returns root attributes
172 */
173
174 protected XmlDataElementAttributes getRootAttributes() {
175 if (rootAttributes == null)
176 rootAttributes = new XmlDataElementAttributes();
177 return rootAttributes;
178 }
179
180 /**
181 * Prepares root attributes
182 */
183
184 protected void prepareRootAttributes() {
185 getRootAttributes().addAttribute("pageName", "UITransformer");
186 getRootAttributes().addAttribute("debug", DEBUG_MODE);
187 }
188
189 }