001: /*
002: * transformica 2
003: * Code generator
004: * Copyright (C) 2004 Hammurapi Group
005: *
006: * This program 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 of the License, or (at your option) any later version.
010: *
011: * This program 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 USA
019: *
020: * URL: http://www.pavelvlasov.com/pv/content/menu.show@id=products.transformica.html
021: * e-Mail: support@hammurapi.biz
022: */
023: package biz.hammurapi.transformica.helpers;
024:
025: import biz.hammurapi.config.ConfigurationException;
026: import biz.hammurapi.config.Parameterizable;
027: import biz.hammurapi.transformica.BaseContextObject;
028: import biz.hammurapi.transformica.ContextObject;
029: import biz.hammurapi.transformica.TransformicaException;
030:
031: /**
032: * Accumulates string and then sets Ant property to that string
033: * @author Pavel Vlasov
034: * @version $Revision: 1.1 $
035: */
036: public class PropertyBuffer extends BaseContextObject implements
037: Parameterizable, ContextObject {
038: private String propertyName;
039: private StringBuffer buffer = new StringBuffer();
040:
041: public PropertyBuffer() {
042: super ();
043: }
044:
045: public PropertyBuffer(String initialValue) {
046: super ();
047: buffer.append(initialValue);
048: }
049:
050: public boolean setParameter(String name, Object parameter)
051: throws ConfigurationException {
052: if ("property".equals(name)) {
053: propertyName = parameter.toString();
054: } else {
055: throw new ConfigurationException("Parameter " + name
056: + " is not supported by "
057: + this .getClass().getName());
058: }
059: return true;
060: }
061:
062: public void destroy() throws TransformicaException {
063: if (propertyName == null) {
064: throw new TransformicaException("Property name is not set");
065: } else {
066: session.getTask().getProject().setProperty(propertyName,
067: buffer.toString());
068: }
069:
070: super .destroy();
071: }
072:
073: /**
074: * @param b
075: * @return
076: */
077: public synchronized StringBuffer append(boolean b) {
078: session.debug("PropertyBuffer[" + propertyName + "].append("
079: + b + ")");
080: return buffer.append(b);
081: }
082:
083: /**
084: * @param c
085: * @return
086: */
087: public synchronized StringBuffer append(char c) {
088: session.debug("PropertyBuffer[" + propertyName + "].append("
089: + c + ")");
090: return buffer.append(c);
091: }
092:
093: /**
094: * @param str
095: * @return
096: */
097: public synchronized StringBuffer append(char[] str) {
098: session.debug("PropertyBuffer[" + propertyName + "].append("
099: + String.valueOf(str) + ")");
100: return buffer.append(str);
101: }
102:
103: /**
104: * @param str
105: * @param offset
106: * @param len
107: * @return
108: */
109: public synchronized StringBuffer append(char[] str, int offset,
110: int len) {
111: session.debug("PropertyBuffer[" + propertyName + "].append()");
112: return buffer.append(str, offset, len);
113: }
114:
115: /**
116: * @param d
117: * @return
118: */
119: public synchronized StringBuffer append(double d) {
120: session.debug("PropertyBuffer[" + propertyName + "].append("
121: + d + ")");
122: return buffer.append(d);
123: }
124:
125: /**
126: * @param f
127: * @return
128: */
129: public synchronized StringBuffer append(float f) {
130: session.debug("PropertyBuffer[" + propertyName + "].append("
131: + f + ")");
132: return buffer.append(f);
133: }
134:
135: /**
136: * @param i
137: * @return
138: */
139: public synchronized StringBuffer append(int i) {
140: session.debug("PropertyBuffer[" + propertyName + "].append("
141: + i + ")");
142: return buffer.append(i);
143: }
144:
145: /**
146: * @param obj
147: * @return
148: */
149: public synchronized StringBuffer append(Object obj) {
150: session.debug("PropertyBuffer[" + propertyName + "].append("
151: + obj + ")");
152: return buffer.append(obj);
153: }
154:
155: /**
156: * @param str
157: * @return
158: */
159: public synchronized StringBuffer append(String str) {
160: session.debug("PropertyBuffer[" + propertyName + "].append("
161: + str + ")");
162: return buffer.append(str);
163: }
164:
165: /**
166: * @param sb
167: * @return
168: */
169: public synchronized StringBuffer append(StringBuffer sb) {
170: session.debug("PropertyBuffer[" + propertyName + "].append("
171: + sb + ")");
172: return buffer.append(sb);
173: }
174:
175: /**
176: * @param l
177: * @return
178: */
179: public synchronized StringBuffer append(long l) {
180: session.debug("PropertyBuffer[" + propertyName + "].append("
181: + l + ")");
182: return buffer.append(l);
183: }
184:
185: /**
186: * @param offset
187: * @param b
188: * @return
189: */
190: public StringBuffer insert(int offset, boolean b) {
191: session.debug("PropertyBuffer[" + propertyName + "].insert("
192: + offset + "," + b + ")");
193: return buffer.insert(offset, b);
194: }
195:
196: /**
197: * @param offset
198: * @param c
199: * @return
200: */
201: public synchronized StringBuffer insert(int offset, char c) {
202: session.debug("PropertyBuffer[" + propertyName + "].insert("
203: + offset + "," + c + ")");
204: return buffer.insert(offset, c);
205: }
206:
207: /**
208: * @param offset
209: * @param str
210: * @return
211: */
212: public synchronized StringBuffer insert(int offset, char[] str) {
213: session.debug("PropertyBuffer[" + propertyName + "].insert("
214: + offset + "," + String.valueOf(str) + ")");
215: return buffer.insert(offset, str);
216: }
217:
218: /**
219: * @param index
220: * @param str
221: * @param offset
222: * @param len
223: * @return
224: */
225: public synchronized StringBuffer insert(int index, char[] str,
226: int offset, int len) {
227: session.debug("PropertyBuffer[" + propertyName + "].insert("
228: + offset + ",...)");
229: return buffer.insert(index, str, offset, len);
230: }
231:
232: /**
233: * @param offset
234: * @param d
235: * @return
236: */
237: public StringBuffer insert(int offset, double d) {
238: session.debug("PropertyBuffer[" + propertyName + "].insert("
239: + offset + "," + d + ")");
240: return buffer.insert(offset, d);
241: }
242:
243: /**
244: * @param offset
245: * @param f
246: * @return
247: */
248: public StringBuffer insert(int offset, float f) {
249: session.debug("PropertyBuffer[" + propertyName + "].insert("
250: + offset + "," + f + ")");
251: return buffer.insert(offset, f);
252: }
253:
254: /**
255: * @param offset
256: * @param i
257: * @return
258: */
259: public StringBuffer insert(int offset, int i) {
260: session.debug("PropertyBuffer[" + propertyName + "].insert("
261: + offset + "," + i + ")");
262: return buffer.insert(offset, i);
263: }
264:
265: /**
266: * @param offset
267: * @param obj
268: * @return
269: */
270: public synchronized StringBuffer insert(int offset, Object obj) {
271: session.debug("PropertyBuffer[" + propertyName + "].insert("
272: + offset + "," + obj + ")");
273: return buffer.insert(offset, obj);
274: }
275:
276: /**
277: * @param offset
278: * @param str
279: * @return
280: */
281: public synchronized StringBuffer insert(int offset, String str) {
282: session.debug("PropertyBuffer[" + propertyName + "].insert("
283: + offset + "," + str + ")");
284: return buffer.insert(offset, str);
285: }
286:
287: /**
288: * @param offset
289: * @param l
290: * @return
291: */
292: public StringBuffer insert(int offset, long l) {
293: session.debug("PropertyBuffer[" + propertyName + "].insert("
294: + offset + "," + l + ")");
295: return buffer.insert(offset, l);
296: }
297:
298: /**
299: * @return
300: */
301: StringBuffer getBuffer() {
302: return buffer;
303: }
304: }
|