KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > encoding > TextSerializationContext


1 /*
2  * Copyright 2001-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.axis.encoding;
18
19 import java.io.IOException JavaDoc;
20 import java.io.Writer JavaDoc;
21
22 import javax.xml.namespace.QName JavaDoc;
23
24 import org.apache.axis.MessageContext;
25 import org.apache.axis.utils.Messages;
26
27 import org.w3c.dom.Element JavaDoc;
28
29 import org.xml.sax.Attributes JavaDoc;
30
31 /**
32  * For internal use only. Used to get the first text node of an element.
33  *
34  * @author Jarek Gawor (gawor@apache.org)
35  */

36 public class TextSerializationContext extends SerializationContext {
37
38     private boolean ignore = false;
39     private int depth = 0;
40
41     public TextSerializationContext(Writer JavaDoc writer)
42     {
43         super(writer);
44         startOfDocument = false; // prevent XML decl for text
45
}
46
47     public TextSerializationContext(Writer JavaDoc writer, MessageContext msgContext)
48     {
49         super(writer, msgContext);
50         startOfDocument = false; // prevent XML decl for text
51
}
52
53     public void serialize(QName JavaDoc elemQName,
54                           Attributes JavaDoc attributes,
55                           Object JavaDoc value,
56                           QName JavaDoc xmlType,
57                           Boolean JavaDoc sendNull,
58                           Boolean JavaDoc sendType)
59         throws IOException JavaDoc
60     {
61         throw new IOException JavaDoc(Messages.getMessage("notImplemented00",
62                                                   "serialize"));
63     }
64
65     public void writeDOMElement(Element JavaDoc el)
66         throws IOException JavaDoc
67     {
68         throw new IOException JavaDoc(Messages.getMessage("notImplemented00",
69                                                   "writeDOMElement"));
70     }
71
72     public void startElement(QName JavaDoc qName, Attributes JavaDoc attributes)
73         throws IOException JavaDoc
74     {
75         depth++;
76         if (depth == 2) {
77             this.ignore = true;
78         }
79     }
80
81     public void endElement()
82         throws IOException JavaDoc
83     {
84         depth--;
85         ignore = true;
86     }
87
88     public void writeChars(char [] p1, int p2, int p3)
89         throws IOException JavaDoc
90     {
91         if (!this.ignore) {
92             super.writeChars(p1, p2, p3);
93         }
94     }
95
96     public void writeString(String JavaDoc string)
97         throws IOException JavaDoc
98     {
99         if (!this.ignore) {
100             super.writeString(string);
101         }
102     }
103
104 }
105
Popular Tags