KickJava   Java API By Example, From Geeks To Geeks.

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


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.parser.impl.LocSAXException;
20 import org.apache.ws.jaxme.xs.xml.*;
21 import org.xml.sax.SAXException JavaDoc;
22
23
24 /** <p>Implementation of <code>xs:attribute</code>, following
25  * this specification:
26  * <pre>
27  * &lt;xs:complexType name="attribute"&gt;
28  * &lt;xs:complexContent&gt;
29  * &lt;xs:extension base="xs:annotated"&gt;
30  * &lt;xs:sequence&gt;
31  * &lt;xs:element name="simpleType" minOccurs="0" type="xs:localSimpleType"/&gt;
32  * &lt;/xs:sequence&gt;
33  * &lt;xs:attributeGroup ref="xs:defRef"/&gt;
34  * &lt;xs:attribute name="type" type="xs:QName"/&gt;
35  * &lt;xs:attribute name="use" use="optional" default="optional"&gt;
36  * &lt;xs:simpleType&gt;
37  * &lt;xs:restriction base="xs:NMTOKEN"&gt;
38  * &lt;xs:enumeration value="prohibited"/&gt;
39  * &lt;xs:enumeration value="optional"/&gt;
40  * &lt;xs:enumeration value="required"/&gt;
41  * &lt;/xs:restriction&gt;
42  * &lt;/xs:simpleType&gt;
43  * &lt;/xs:attribute&gt;
44  * &lt;xs:attribute name="default" type="xs:string"/&gt;
45  * &lt;xs:attribute name="fixed" type="xs:string"/&gt;
46  * &lt;xs:attribute name="form" type="xs:formChoice"/&gt;
47  * &lt;/xs:extension&gt;
48  * &lt;/xs:complexContent&gt;
49  * &lt;/xs:complexType&gt;
50  * </pre></p>
51  *
52  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
53  */

54 public class XsTAttributeImpl extends XsTAnnotatedImpl implements XsTAttribute {
55   private XsTLocalSimpleType simpleType;
56   private XsQName type;
57   private Use use = OPTIONAL;
58   private String JavaDoc defaultValue;
59   private String JavaDoc fixedValue;
60   private XsFormChoice form;
61   private XsNCName name;
62   private XsQName ref;
63
64   protected XsTAttributeImpl(XsObject pParent) {
65     super(pParent);
66   }
67
68   public XsTLocalSimpleType createSimpleType() {
69     if (simpleType != null) {
70       throw new IllegalStateException JavaDoc("Multiple 'simpleType' child elements are forbidden.");
71     }
72     if (type != null) {
73       throw new IllegalStateException JavaDoc("The 'type' attribute and the 'simpleType' child element are mutually exclusive.");
74     }
75     return simpleType = getObjectFactory(). newXsTLocalSimpleType(this);
76   }
77
78   public XsTLocalSimpleType getSimpleType() {
79     return simpleType;
80   }
81
82   public void setType(XsQName pType) {
83     if (simpleType != null) {
84       throw new IllegalStateException JavaDoc("The 'type' attribute and the 'simpleType' child element are mutually exclusive.");
85     }
86     type = pType;
87   }
88
89   public void setType(String JavaDoc pType) throws SAXException {
90     setType(asXsQName(pType));
91   }
92
93   public XsQName getType() {
94     return type;
95   }
96
97   public void setUse(Use pUse) {
98     use = pUse;
99   }
100
101   public Use getUse() {
102     return use;
103   }
104
105   public void setDefault(String JavaDoc pDefault) {
106     defaultValue = pDefault;
107   }
108
109   public String JavaDoc getDefault() {
110     return defaultValue;
111   }
112
113   public void setFixed(String JavaDoc pFixed) {
114     fixedValue = pFixed;
115   }
116
117   public String JavaDoc getFixed() {
118     return fixedValue;
119   }
120
121   public void setForm(XsFormChoice pForm) throws SAXException {
122     if (isGlobal() && pForm != null) {
123       throw new LocSAXException("The 'form' attribute is valid for local attributes only.",
124                                  getLocator());
125     }
126     form = pForm;
127   }
128
129   public XsFormChoice getForm() {
130     return form;
131   }
132
133   public void setName(XsNCName pName) {
134     name = pName;
135   }
136
137   public XsNCName getName() {
138     return name;
139   }
140
141   public void setRef(XsQName pRef) {
142     ref = pRef;
143   }
144
145   public void setRef(String JavaDoc pRef) throws SAXException {
146     setRef(asXsQName(pRef));
147   }
148
149   public XsQName getRef() {
150     return ref;
151   }
152
153   public boolean isGlobal() { return isTopLevelObject(); }
154 }
155
Popular Tags