KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Iterator JavaDoc;
33
34 import org.jibx.binding.util.StringArray;
35
36 /**
37  * Model component for elements that can contain other component elements.
38  *
39  * @author Dennis M. Sosnoski
40  * @version 1.0
41  */

42  
43 public abstract class NestingElementBase extends ElementBase
44 {
45     /** Enumeration of allowed attribute names */
46     public static final StringArray s_allowedAttributes =
47         new StringArray(new String JavaDoc[] { "value-style" });
48     
49     /** Value style attribute information. */
50     private NestingAttributes m_nestingAttrs;
51     
52     /** Definition context for this nesting (created by validation). */
53     private DefinitionContext m_defContext;
54     
55     /** List of child elements. */
56     private ArrayList JavaDoc m_children;
57     
58     /**
59      * Constructor.
60      *
61      * @param type element type code
62      */

63     protected NestingElementBase(int type) {
64         super(type);
65         m_nestingAttrs = new NestingAttributes();
66         m_children = new ArrayList JavaDoc();
67     }
68     
69     /**
70      * Add child element.
71      * TODO: should be ElementBase argument, but JiBX doesn't allow yet
72      *
73      * @param child element to be added as child of this element
74      */

75     public final void addChild(Object JavaDoc child) {
76         m_children.add(child);
77     }
78     
79     /**
80      * Get list of child elements.
81      *
82      * @return list of child elements, or <code>null</code> if none
83      */

84     public final ArrayList JavaDoc children() {
85         return m_children;
86     }
87     
88     /**
89      * Get iterator for child elements.
90      *
91      * @return iterator for child elements
92      */

93     public final Iterator JavaDoc childIterator() {
94         return m_children.iterator();
95     }
96     
97     /**
98      * Get definition context.
99      *
100      * @return definition context, or <code>null</code> if no definition context
101      * for this element
102      */

103     public final DefinitionContext getDefinitions() {
104         return m_defContext;
105     }
106
107     /**
108      * Set definition context.
109      *
110      * @param ctx definition context to be set
111      */

112     /*package*/ void setDefinitions(DefinitionContext ctx) {
113         m_defContext = ctx;
114     }
115     
116     //
117
// Nesting attribute delegate methods
118

119     /**
120      * Get style name set on this nesting element.
121      *
122      * @return style string value (<code>null</code> if undefined at this level)
123      */

124     public String JavaDoc getStyleName() {
125         return m_nestingAttrs.getStyleName();
126     }
127     
128     /**
129      * Get style value set on this nesting element. This call is only meaningful
130      * after validation.
131      *
132      * @return style value (<code>-1</code> if undefined at this level)
133      */

134     public int getStyle() {
135         return m_nestingAttrs.getStyle();
136     }
137     
138     /**
139      * Set style name on this nesting element.
140      *
141      * @param name style name (<code>null</code> to undefine style at this
142      * level)
143      */

144     public void setStyleName(String JavaDoc name) {
145         m_nestingAttrs.setStyleName(name);
146     }
147     
148     /**
149      * Get default style value for child components. This call is only
150      * meaningful after validation.
151      *
152      * @return default style value for child components (<code>-1</code> if not
153      * defined at this level)
154      */

155     public int getDefaultStyle() {
156         return m_nestingAttrs.getStyle();
157     }
158     
159     /* (non-Javadoc)
160      * @see org.jibx.binding.model.ElementBase#prevalidate(org.jibx.binding.model.ValidationContext)
161      */

162     public void prevalidate(ValidationContext vctx) {
163         m_nestingAttrs.prevalidate(vctx);
164         super.prevalidate(vctx);
165     }
166     
167     /* (non-Javadoc)
168      * @see org.jibx.binding.model.ElementBase#validate(org.jibx.binding.model.ValidationContext)
169      */

170     public void validate(ValidationContext vctx) {
171         m_nestingAttrs.validate(vctx);
172         super.validate(vctx);
173     }
174 }
Popular Tags