KickJava   Java API By Example, From Geeks To Geeks.

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


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.XsAGDefRef;
21 import org.apache.ws.jaxme.xs.xml.XsNCName;
22 import org.apache.ws.jaxme.xs.xml.XsObject;
23 import org.apache.ws.jaxme.xs.xml.XsQName;
24 import org.xml.sax.SAXException JavaDoc;
25
26
27 /** <p>Implementation of the attribute group <code>xs:defRef</code>,
28  * as specified by the following:
29  * <pre>
30  * &lt;xs:attributeGroup name="defRef"&gt;
31  * &lt;xs:annotation&gt;
32  * &lt;xs:documentation&gt;
33  * for element, group and attributeGroup,
34  * which both define and reference
35  * &lt;/xs:documentation&gt;
36  * &lt;/xs:annotation&gt;
37  * &lt;xs:attribute name="name" type="xs:NCName"/&gt;
38  * &lt;xs:attribute name="ref" type="xs:QName"/&gt;
39  * &lt;/xs:attributeGroup&gt;
40  * </pre></p>
41  * <p><em>Implementation note:</em> The 'name' and 'ref' attributes
42  * are mutually exclusive.</p>
43  *
44  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
45  */

46 public class XsAGDefRefImpl implements XsAGDefRef {
47     private final XsObject owner;
48     private XsNCName name;
49     private XsQName ref;
50
51     /** <p>Creates a new instance with the given parent object.</p>
52      */

53     public XsAGDefRefImpl(XsObject pOwner) {
54         owner = pOwner;
55     }
56
57     public void setName(XsNCName pName) {
58         if (ref != null) {
59             throw new IllegalStateException JavaDoc("The 'name' and 'ref' attributes are mutually exclusive.");
60         }
61         name = pName;
62     }
63     
64     public XsNCName getName() {
65         return name;
66     }
67     
68     public void setRef(XsQName pRef) {
69         if (name != null) {
70             throw new IllegalStateException JavaDoc("The 'name' and 'ref' attributes are mutually exclusive.");
71         }
72         ref = pRef;
73     }
74
75     public void setRef(String JavaDoc pRef) throws SAXException {
76         setRef(((XsObjectImpl) owner).asXsQName(pRef));
77     }
78     
79     public XsQName getRef() {
80         return ref;
81     }
82     
83     public void validate() throws SAXException {
84         if (name == null && ref == null) {
85             throw new LocSAXException("You must set either of the attributes 'name' or 'ref'.", owner.getLocator());
86         }
87     }
88 }
89
Popular Tags