001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.java.gen;
031:
032: import com.caucho.bytecode.JClass;
033: import com.caucho.java.JavaWriter;
034: import com.caucho.java.LineMap;
035: import com.caucho.vfs.WriteStream;
036:
037: import java.io.IOException;
038:
039: /**
040: * Wrapper
041: */
042: public class JavaWriterWrapper extends JavaWriter {
043: // Write stream for generating the code
044: private JavaWriter _writer;
045:
046: public JavaWriterWrapper(JavaWriter writer) {
047: super (null);
048:
049: _writer = writer;
050: }
051:
052: /**
053: * Returns the underlying stream.
054: */
055: public WriteStream getWriteStream() {
056: return _writer.getWriteStream();
057: }
058:
059: /**
060: * Returns the destination line.
061: */
062: public int getDestLine() {
063: return _writer.getDestLine();
064: }
065:
066: /**
067: * Sets the line map
068: */
069: public void setLineMap(LineMap lineMap) {
070: _writer.setLineMap(lineMap);
071: }
072:
073: /**
074: * Gets the line map
075: */
076: public LineMap getLineMap() {
077: return _writer.getLineMap();
078: }
079:
080: /**
081: * Sets the source filename and line.
082: *
083: * @param filename the filename of the source file.
084: * @param line the line of the source file.
085: */
086: public void setLocation(String filename, int line)
087: throws IOException {
088: _writer.setLocation(filename, line);
089: }
090:
091: /**
092: * Generates a unique id.
093: */
094: public int generateId() {
095: return _writer.generateId();
096: }
097:
098: /**
099: * Prints a Java escaped string
100: */
101: public void printJavaString(String s) throws IOException {
102: _writer.printJavaString(s);
103: }
104:
105: /**
106: * Prints a Java escaped string surrounded by ", or null if the string is null.
107: */
108: public void printQuotedJavaString(String s) throws IOException {
109: if (s == null)
110: _writer.print("null");
111: else {
112: _writer.print("\"");
113: _writer.printJavaString(s);
114: _writer.print("\"");
115: }
116: }
117:
118: /**
119: * Prints a Java escaped string
120: */
121: public void printJavaChar(char ch) throws IOException {
122: _writer.printJavaChar(ch);
123: }
124:
125: /**
126: * Pushes an indentation depth.
127: */
128: public void pushDepth() throws IOException {
129: _writer.pushDepth();
130: }
131:
132: /**
133: * Pops an indentation depth.
134: */
135: public void popDepth() throws IOException {
136: _writer.popDepth();
137: }
138:
139: /**
140: * Prints a string
141: */
142: public void print(String s) throws IOException {
143: _writer.print(s);
144: }
145:
146: /**
147: * Prints a character.
148: */
149: public void print(char ch) throws IOException {
150: _writer.print(ch);
151: }
152:
153: /**
154: * Prints a boolean.
155: */
156: public void print(boolean b) throws IOException {
157: _writer.print(b);
158: }
159:
160: /**
161: * Prints an integer.
162: */
163: public void print(int i) throws IOException {
164: _writer.print(i);
165: }
166:
167: /**
168: * Prints an long
169: */
170: public void print(long l) throws IOException {
171: _writer.print(l);
172: }
173:
174: /**
175: * Prints an object.
176: */
177: public void print(Object o) throws IOException {
178: _writer.print(o);
179: }
180:
181: /**
182: * Prints a string with a new line
183: */
184: public void println(String s) throws IOException {
185: _writer.println(s);
186: }
187:
188: /**
189: * Prints a boolean with a new line
190: */
191: public void println(boolean v) throws IOException {
192: _writer.println(v);
193: }
194:
195: /**
196: * Prints a character.
197: */
198: public void println(char ch) throws IOException {
199: _writer.println(ch);
200: }
201:
202: /**
203: * Prints an integer with a new line
204: */
205: public void println(int v) throws IOException {
206: _writer.println(v);
207: }
208:
209: /**
210: * Prints an long with a new line
211: */
212: public void println(long v) throws IOException {
213: _writer.println(v);
214: }
215:
216: /**
217: * Prints an object with a new line
218: */
219: public void println(Object v) throws IOException {
220: _writer.println(v);
221: }
222:
223: /**
224: * Prints a newline
225: */
226: public void println() throws IOException {
227: _writer.println();
228: }
229:
230: /**
231: * Prints the Java represention of the class
232: */
233: public void printClass(Class cl) throws IOException {
234: _writer.printClass(cl);
235: }
236:
237: /**
238: * Converts a java primitive type to a Java object.
239: *
240: * @param value the java expression to be converted
241: * @param javaType the type of the converted expression.
242: */
243: public void printJavaTypeToObject(String value, Class javaType)
244: throws IOException {
245: _writer.printJavaTypeToObject(value, javaType);
246: }
247:
248: /**
249: * Converts a java primitive type to a Java object.
250: *
251: * @param value the java expression to be converted
252: * @param javaType the type of the converted expression.
253: */
254: public void printJavaTypeToObject(String value, JClass javaType)
255: throws IOException {
256: _writer.printJavaTypeToObject(value, javaType);
257: }
258:
259: /**
260: * Prints the indentation at the beginning of a line.
261: */
262: public void printIndent() throws IOException {
263: _writer.printIndent();
264: }
265:
266: /**
267: * Returns the error message with proper line number.
268: */
269: public String errorMessage(String message) {
270: return _writer.errorMessage(message);
271: }
272: }
|