KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > xml > impl > XsEDocumentationImpl


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.xs.xml.impl;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import javax.xml.XMLConstants JavaDoc;
23 import javax.xml.parsers.ParserConfigurationException JavaDoc;
24
25 import org.apache.ws.jaxme.xs.XSParser;
26 import org.apache.ws.jaxme.xs.parser.DOMBuilder;
27 import org.apache.ws.jaxme.xs.xml.*;
28 import org.xml.sax.ContentHandler JavaDoc;
29 import org.xml.sax.SAXException JavaDoc;
30
31
32 /** <p>Implementation of <code>xs:documentation</code>, as specified
33  * by the following:
34  * <pre>
35  * &lt;xs:element name="documentation" id="documentation"&gt;
36  * &lt;xs:annotation&gt;
37  * &lt;xs:documentation source="http://www.w3.org/TR/xmlschema-1/#element-documentation"/&gt;
38  * &lt;/xs:annotation&gt;
39  * &lt;xs:complexType mixed="true"&gt;
40  * &lt;xs:sequence minOccurs="0" maxOccurs="unbounded"&gt;
41  * &lt;xs:any processContents="lax"/&gt;
42  * &lt;/xs:sequence&gt;
43  * &lt;xs:attribute name="source" type="xs:anyURI"/&gt;
44  * &lt;xs:attribute ref="xml:lang"/&gt;
45  * &lt;/xs:complexType&gt;
46  * &lt;/xs:element&gt;
47  * </pre></p>
48  *
49  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
50  */

51 public class XsEDocumentationImpl extends XsObjectImpl implements XsEDocumentation {
52     private XmlLang lang;
53     private XsAnyURI source;
54     private List JavaDoc childs = new ArrayList JavaDoc();
55     private boolean isSimple;
56
57     protected XsEDocumentationImpl(XsObject pParent) {
58         super(pParent);
59     }
60
61     protected void addChild(Object JavaDoc pObject) {
62         childs.add(pObject);
63     }
64
65     public void setLang(XmlLang pLang) {
66         lang = pLang;
67     }
68     
69     public XmlLang getLang() {
70         return lang;
71     }
72     
73     public void setSource(XsAnyURI pSource) {
74         source = pSource;
75     }
76     
77     public XsAnyURI getSource() {
78         return source;
79     }
80     
81     public void addText(String JavaDoc pText) {
82         childs.add(pText);
83     }
84     
85     public String JavaDoc getText() {
86         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
87         for (int i = 0; i < childs.size(); i++) {
88             Object JavaDoc o = childs.get(i);
89             if (o instanceof String JavaDoc) {
90                 sb.append(o);
91             }
92         }
93         return sb.toString();
94     }
95
96     public boolean isTextOnly() {
97         for (int i = 0; i < childs.size(); i++) {
98             if (!(childs.get(i) instanceof String JavaDoc)) {
99                 return false;
100             }
101         }
102         return true;
103     }
104
105     public Object JavaDoc[] getChilds() {
106         return childs.toArray();
107     }
108
109     public boolean setAttribute(String JavaDoc pQName, String JavaDoc pNamespaceURI, String JavaDoc pLocalName, String JavaDoc pValue) {
110         if (XMLConstants.XML_NS_URI.equals(pNamespaceURI) && "lang".equals(pLocalName)) {
111             setLang(new XmlLang(pValue));
112             return true;
113         } else {
114             return false;
115         }
116     }
117     
118     public ContentHandler JavaDoc getChildHandler(String JavaDoc pQName, String JavaDoc pNamespaceURI, String JavaDoc pLocalName)
119             throws SAXException JavaDoc {
120         isSimple = false;
121         try {
122             DOMBuilder db = new DOMBuilder();
123             addChild(db.getDocument());
124             return db;
125         } catch (ParserConfigurationException JavaDoc e) {
126             throw new SAXException JavaDoc(e);
127         }
128     }
129 }
130
Popular Tags