KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
32
33 import org.jibx.binding.util.StringArray;
34 import org.jibx.runtime.IUnmarshallingContext;
35 import org.jibx.runtime.JiBXException;
36
37 /**
38  * Model component for <b>mapping</b> element of binding definition.
39  *
40  * @author Dennis M. Sosnoski
41  * @version 1.0
42  */

43  
44 public class MappingElement extends TemplateElementBase
45 {
46     /** Enumeration of allowed attribute names */
47     public static final StringArray s_allowedAttributes =
48         new StringArray(new String JavaDoc[] { "abstract", "class", "extends" },
49         new StringArray(NameAttributes.s_allowedAttributes,
50         ContainerElementBase.s_allowedAttributes));
51     // TODO: move "mapping" to TemplateElementBase in 2.0
52

53     /** Abstract mapping flag. */
54     private boolean m_isAbstract;
55     
56     /** Name attributes information for nesting. */
57     private NameAttributes m_nameAttrs;
58     
59     /** Name of mapped class extended by this mapping. */
60     private String JavaDoc m_extendsName;
61
62     /** Mapping extended by this mapping. */
63     private MappingElement m_extendsMapping;
64     
65     /**
66      * Default constructor.
67      */

68     public MappingElement() {
69         super(MAPPING_ELEMENT);
70         m_nameAttrs = new NameAttributes();
71         m_children = new ArrayList JavaDoc();
72     }
73     
74     /**
75      * Check for abstract mapping.
76      *
77      * @return <code>true</code> if abstract, <code>false</code> if not
78      */

79     public boolean isAbstract() {
80         return m_isAbstract;
81     }
82     
83     /**
84      * Set abstract mapping.
85      *
86      * @param abs <code>true</code> if abstract, <code>false</code> if not
87      */

88     public void setAbstract(boolean abs) {
89         m_isAbstract = abs;
90     }
91     
92     /**
93      * Set name of mapped class extended by this one.
94      *
95      * @param name
96      */

97     public void setExtendsName(String JavaDoc name) {
98         m_extendsName = name;
99     }
100
101     /**
102      * Get name of mapped class extended by this one.
103      *
104      * @return
105      */

106     public String JavaDoc getExtendsName() {
107         return m_extendsName;
108     }
109
110     /**
111      * Get mapping extended by this one.
112      *
113      * @return mapping extended by this one
114      */

115     public MappingElement getExtendsMapping() {
116         return m_extendsMapping;
117     }
118     
119     /* (non-Javadoc)
120      * @see org.jibx.binding.model.TemplateElementBase#isDefaultTemplate()
121      */

122     public boolean isDefaultTemplate() {
123         // mapping is always the default
124
return true;
125     }
126     
127     //
128
// Name attribute delegate methods
129

130     /**
131      * Get name.
132      *
133      * @return name text
134      */

135     public String JavaDoc getName() {
136         return m_nameAttrs.getName();
137     }
138     
139     /**
140      * Set name.
141      *
142      * @param name text for name
143      */

144     public void setName(String JavaDoc name) {
145         m_nameAttrs.setName(name);
146     }
147
148     /**
149      * Get specified namespace URI.
150      *
151      * @return namespace URI (<code>null</code> if not set)
152      */

153     public String JavaDoc getUri() {
154         return m_nameAttrs.getUri();
155     }
156
157     /**
158      * Set namespace URI.
159      *
160      * @param uri namespace URI (<code>null</code> if not set)
161      */

162     public void setUri(String JavaDoc uri) {
163         m_nameAttrs.setUri(uri);
164     }
165
166     /**
167      * Get specified namespace prefix.
168      *
169      * @return namespace prefix (<code>null</code> if not set)
170      */

171     public String JavaDoc getPrefix() {
172         return m_nameAttrs.getPrefix();
173     }
174
175     /**
176      * Set namespace prefix.
177      *
178      * @param prefix namespace prefix (<code>null</code> if not set)
179      */

180     public void setPrefix(String JavaDoc prefix) {
181         m_nameAttrs.setPrefix(prefix);
182     }
183     
184     /**
185      * Get effective namespace information. This call is only meaningful after
186      * validation.
187      *
188      * @return effective namespace information
189      */

190     public NamespaceElement getNamespace() {
191         return m_nameAttrs.getNamespace();
192     }
193     
194     //
195
// Validation methods
196

197     /**
198      * Make sure all attributes are defined.
199      *
200      * @param uctx unmarshalling context
201      * @exception JiBXException on unmarshalling error
202      */

203     private void preSet(IUnmarshallingContext uctx) throws JiBXException {
204         validateAttributes(uctx, s_allowedAttributes);
205     }
206     
207     /* (non-Javadoc)
208      * @see org.jibx.binding.model.ElementBase#prevalidate(org.jibx.binding.model.ValidationContext)
209      */

210     public void prevalidate(ValidationContext vctx) {
211         m_nameAttrs.prevalidate(vctx);
212         super.prevalidate(vctx);
213     }
214     
215     /* (non-Javadoc)
216      * @see org.jibx.binding.model.ElementBase#validate(org.jibx.binding.model.ValidationContext)
217      */

218     public void validate(ValidationContext vctx) {
219         m_nameAttrs.validate(vctx);
220         super.validate(vctx);
221     }
222 }
Popular Tags