KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > js > WriterTarget


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.js;
18
19 import java.io.IOException JavaDoc;
20 import java.io.Writer JavaDoc;
21
22 /** <p>An IndentationTarget writing into a given Writer.</p>
23  *
24  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
25  * @version $Id: WriterTarget.java,v 1.2 2004/02/16 23:39:55 jochen Exp $
26  */

27 public class WriterTarget implements IndentationTarget {
28   public static final String JavaDoc INDENTATION_STRING = " ";
29   public static final String JavaDoc LINE_SEPARATOR = "\n";
30   private Writer JavaDoc target;
31   private String JavaDoc indentationString;
32   private String JavaDoc lineSeparator;
33
34   public WriterTarget() {}
35
36   public WriterTarget(Writer JavaDoc pTarget) {
37     target = pTarget;
38   }
39
40   public void setTarget(Writer JavaDoc pTarget) {
41     target = pTarget;
42   }
43
44   public Writer JavaDoc getTarget() {
45     return target;
46   }
47
48   public void setIndentationString(String JavaDoc pIndentationString) {
49     indentationString = pIndentationString;
50   }
51
52   public String JavaDoc getIndentationString() {
53     return indentationString == null ? INDENTATION_STRING : indentationString;
54   }
55
56   public void setLineSeparator(String JavaDoc pLineSeparator) {
57     lineSeparator = pLineSeparator;
58   }
59
60   public String JavaDoc getLineSeparator() {
61     return lineSeparator == null ? LINE_SEPARATOR : lineSeparator;
62   }
63
64   public boolean isInterface() {
65     return false;
66   }
67
68   public void indent(int pLevel) throws IOException JavaDoc {
69     for (int i = 0; i < pLevel; i++) {
70       target.write(getIndentationString());
71     }
72   }
73
74   public String JavaDoc asString(JavaQName pQName) {
75     return pQName.toString();
76   }
77
78   public void write(String JavaDoc pValue) throws IOException JavaDoc {
79     target.write(pValue);
80   }
81
82   public void write() throws IOException JavaDoc {
83     target.write(getLineSeparator());
84   }
85 }
86
Popular Tags