KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jibx > binding > model > NameAttributes


1 /*
2 Copyright (c) 2004-2005, Dennis M. Sosnoski
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8  * Redistributions of source code must retain the above copyright notice, this
9    list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice,
11    this list of conditions and the following disclaimer in the documentation
12    and/or other materials provided with the distribution.
13  * Neither the name of JiBX nor the names of its contributors may be used
14    to endorse or promote products derived from this software without specific
15    prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */

28
29 package org.jibx.binding.model;
30
31 import org.jibx.binding.util.StringArray;
32
33
34 /**
35  * Model component for <b>name</b> attribute group in binding definition.
36  *
37  * @author Dennis M. Sosnoski
38  * @version 1.0
39  */

40  
41 public class NameAttributes extends AttributeBase
42 {
43     /** Enumeration of allowed attribute names */
44     public static final StringArray s_allowedAttributes =
45         new StringArray(new String JavaDoc[] { "name", "ns" });
46     // TODO: add "prefix" to set for 2.0
47

48     /** Name text. */
49     private String JavaDoc m_name;
50     
51     /** Namespace URI. */
52     private String JavaDoc m_uri;
53     
54     /** Namespace prefix. */
55     private String JavaDoc m_prefix;
56     
57     /** Name represents an attribute flag. */
58     private boolean m_isAttribute;
59     
60     /** Namespace definition used by this name. */
61     private NamespaceElement m_namespace;
62     
63     /**
64      * Default constructor.
65      */

66     public NameAttributes() {}
67     
68     /**
69      * Set flag for an attribute name. This information is necessary for
70      * resolving the namespace definition to be used with a name, but has to be
71      * determined by the element owning this attribute group. It must be set (if
72      * different from the default of <code>false</code>) prior to validation.
73      *
74      * @param isattr flag for name represents an attribute
75      */

76     public void setIsAttribute(boolean isattr) {
77         m_isAttribute = isattr;
78     }
79     
80     /**
81      * Get flag for an attribute name.
82      *
83      * @return <code>true</code> if an attribute, <code>false</code> if an
84      * element
85      */

86     public boolean isAttribute() {
87         return m_isAttribute;
88     }
89     
90     /**
91      * Get name.
92      *
93      * @return name text
94      */

95     public String JavaDoc getName() {
96         return m_name;
97     }
98     
99     /**
100      * Set name.
101      *
102      * @param name text for name
103      */

104     public void setName(String JavaDoc name) {
105         m_name = name;
106     }
107     
108     /**
109      * Get specified namespace URI.
110      *
111      * @return namespace URI (<code>null</code> if not set)
112      */

113     public String JavaDoc getUri() {
114         return m_uri;
115     }
116     
117     /**
118      * Set namespace URI.
119      *
120      * @param uri namespace URI (<code>null</code> if not set)
121      */

122     public void setUri(String JavaDoc uri) {
123         m_uri = uri;
124     }
125     
126     /**
127      * Get specified namespace prefix.
128      *
129      * @return namespace prefix (<code>null</code> if not set)
130      */

131     public String JavaDoc getPrefix() {
132         return m_uri;
133     }
134     
135     /**
136      * Set namespace prefix.
137      *
138      * @param prefix namespace prefix (<code>null</code> if not set)
139      */

140     public void setPrefix(String JavaDoc prefix) {
141         m_prefix = prefix;
142     }
143     
144     /**
145      * Get effective namespace definition. This call can only be used after
146      * validation.
147      *
148      * @return definition for namespace used by this name
149      */

150     public NamespaceElement getNamespace() {
151         return m_namespace;
152     }
153     
154     //
155
// Overrides of base class methods
156

157     /* (non-Javadoc)
158      * @see org.jibx.binding.model.AttributeBase#validate(org.jibx.binding.model.ValidationContext)
159      */

160     public void validate(ValidationContext vctx) {
161         if (m_name != null) {
162             DefinitionContext dctx = vctx.getDefinitions();
163             if (m_isAttribute) {
164                 m_namespace = dctx.getAttributeNamespace(this);
165             } else {
166                 m_namespace = dctx.getElementNamespace(this);
167             }
168         }
169         super.validate(vctx);
170     }
171 }
Popular Tags