KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > message > CommentImpl


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.message;
18
19 import org.w3c.dom.Comment JavaDoc;
20 import org.w3c.dom.DOMException JavaDoc;
21
22 import javax.xml.soap.Text JavaDoc;
23
24 /**
25  * Most of methods are inherited from TEXT, defined for its Interface Marker
26  * only
27  *
28  * @author Heejune Ahn (cityboy@tmax.co.kr)
29  */

30
31 public class CommentImpl
32     extends org.apache.axis.message.Text
33     implements Text, Comment JavaDoc {
34
35     public CommentImpl(String JavaDoc text) {
36         super(text);
37     }
38     
39     public boolean isComment() {
40         return true;
41     }
42
43     public org.w3c.dom.Text JavaDoc splitText(int offset) throws DOMException JavaDoc {
44         int length = textRep.getLength();
45         // take the first part, and save the second part for new Text
46
// length check and exception will be thrown here, no need to
47
// duplicated check
48
String JavaDoc tailData = textRep.substringData(offset, length);
49         textRep.deleteData(offset, length);
50
51         // insert the first part again as a new node
52
Text tailText = new CommentImpl(tailData);
53         org.w3c.dom.Node JavaDoc myParent = (org.w3c.dom.Node JavaDoc) getParentNode();
54         if (myParent != null) {
55             org.w3c.dom.NodeList JavaDoc brothers =
56                 (org.w3c.dom.NodeList JavaDoc) myParent.getChildNodes();
57             for (int i = 0; i < brothers.getLength(); i++) {
58                 if (brothers.item(i).equals(this)) {
59                     myParent.insertBefore(tailText, this);
60                     return tailText;
61                 }
62             }
63         }
64         return tailText;
65     }
66
67 }
68
Popular Tags