1 /**
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Intalio, Inc. For written permission,
18 * please contact info@exolab.org.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Intalio, Inc. Exolab is a registered
23 * trademark of Intalio, Inc.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2000 (C) Intalio, Inc. All Rights Reserved.
42 *
43 * $Id$
44 */
45
46
47 package org.exolab.castor.xml.schema;
48
49 import java.util.Enumeration;
50
51 /**
52 * An XML Schema Attribute Group Definition
53 * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
54 * @version $Revision$ $Date: 2006-04-14 04:14:43 -0600 (Fri, 14 Apr 2006) $
55 **/
56 public final class AttributeGroupReference extends AttributeGroup {
57 /** SerialVersionUID */
58 private static final long serialVersionUID = -6283626049554689747L;
59
60 /**
61 * Error message for a null argument
62 **/
63 private static String NULL_ARGUMENT
64 = "A null argument was passed to the constructor of " +
65 "AttributeGroupReference";
66
67 /**
68 * The Schema to which this AttributeDecl belongs
69 **/
70 private Schema _schema = null;
71
72 private String _reference = null;
73
74 /**
75 * Creates a new AttributeGroup definition
76 * @param schema the Schema that this AttributeGroup
77 * belongs to.
78 **/
79 public AttributeGroupReference(Schema schema, String reference) {
80 if (schema == null) {
81 String err = NULL_ARGUMENT + "; 'schema' must not be null.";
82 throw new IllegalArgumentException(err);
83 }
84 if (reference == null) {
85 String err = NULL_ARGUMENT + "; 'reference' must not be null.";
86 throw new IllegalArgumentException(err);
87 }
88 _schema = schema;
89 _reference = reference;
90 } //-- AttributeGroup
91
92 /**
93 * Returns the anyAttribute set in this attribute group if any.
94 * @return the anyAttribute set in this attribute group if any.
95 */
96 public Wildcard getAnyAttribute() {
97 return resolveReference().getAnyAttribute();
98 }
99
100
101 /**
102 * Gets the name of the attribute group this class refers to.
103 */
104 public String getReference() { return _reference; }
105
106 /**
107 * Resolves the attribute group reference
108 * @return the attribute group defined at the schema level that is refered to by this class.
109 */
110 public AttributeGroup resolveReference() {
111 AttributeGroup attrGroup = null;
112 //--check if there is no definition in the
113 //--master schema
114 if (_schema.getMasterSchema() != null) {
115 attrGroup = _schema.getMasterSchema().getAttributeGroup(_reference);
116 }
117
118 if (attrGroup == null)
119 attrGroup = _schema.getAttributeGroup(_reference);
120
121 if (attrGroup == null) {
122 throw new IllegalStateException("Invalid AttributeGroupReference");
123 }
124 return attrGroup;
125 }
126
127 /**
128 * Returns the AttributeDecl associated with the given name
129 * @return the AttributeDecl associated with the given name, or
130 * null if no AttributeDecl with the given name was found.
131 **/
132 public AttributeDecl getAttribute(String name) {
133 return resolveReference().getAttribute(name);
134
135 } //-- getAttribute
136
137
138 /**
139 * Returns an enumeration of the AttributeDecls and AttributeGroups
140 * of this AttributeGroup
141 *
142 * @return an Enumeration of the AttributeDecls and AttributeGroups
143 * of this AttributeGroup
144 **/
145 public Enumeration getAttributes() {
146 return resolveReference().getAttributes();
147 } //-- getAttributes
148
149 /**
150 * Returns true if this AttributeGroup does not contain any
151 * AttributeDecls or any non-empty AttributeGroups
152 *
153 * @return true if this AttributeGroup does not contain any
154 * AttributeDecls or any non-empty AttributeGroups
155 **/
156 public boolean isEmpty() {
157 return resolveReference().isEmpty();
158
159 } //-- isEmpty
160
161 } //-- AttributeGroupReference