KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.ws.jaxme.xs.XSParser;
20 import org.apache.ws.jaxme.xs.xml.*;
21 import org.xml.sax.Attributes JavaDoc;
22 import org.xml.sax.SAXException JavaDoc;
23 import org.xml.sax.helpers.AttributesImpl JavaDoc;
24
25
26 /** <p>A common base type for most of the schema elements.
27  * Implements the following specification:
28  * <pre>
29  * &lt;xs:complexType name="openAttrs">
30  * &lt;xs:annotation>
31  * &lt;xs:documentation>
32  * This type is extended by almost all schema types
33  * to allow attributes from other namespaces to be
34  * added to user schemas.
35  * &lt;/xs:documentation>
36  * &lt;/xs:annotation>
37  * &lt;xs:complexContent>
38  * &lt;xs:restriction base="xs:anyType">
39  * &lt;xs:anyAttribute namespace="##other" processContents="lax"/>
40  * &lt;/xs:restriction>
41  * &lt;/xs:complexContent>
42  * &lt;/xs:complexType&gt;
43  * </pre>
44  *
45  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
46  */

47 public class XsTOpenAttrsImpl extends XsObjectImpl implements XsTOpenAttrs {
48   private AttributesImpl JavaDoc attributes = new AttributesImpl JavaDoc();
49
50   protected XsTOpenAttrsImpl(XsObject pParent) {
51     super(pParent);
52   }
53
54   public Attributes JavaDoc getOpenAttributes() {
55     return attributes;
56   }
57
58   /** <p>This method receives all the attributes, including those from the
59    * XML schema namespace. The method refuses to handle the attribute, if
60    * it has the XML schema namespace by returning the value false. Otherwise,
61    * the attribute is added to the list returned by {@link #getOpenAttributes()}
62    * and the value true is returned.</p>
63    */

64   public boolean setAttribute(String JavaDoc pQName, String JavaDoc pNamespaceURI, String JavaDoc pLocalName, String JavaDoc pValue)
65       throws SAXException JavaDoc {
66     if (pNamespaceURI == null || "".equals(pNamespaceURI)) {
67       return false;
68     } else if (XSParser.XML_SCHEMA_URI.equals(pNamespaceURI)) {
69       throw new IllegalStateException JavaDoc("Unknown attribute in " + getClass().getName() + ": " + pQName);
70     }
71     attributes.addAttribute(pNamespaceURI, pLocalName, pQName, "CDATA", pValue);
72     return true;
73   }
74 }
75
Popular Tags