KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jibx > binding > def > IComponent


1 /*
2 Copyright (c) 2003, 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.def;
30
31 import org.jibx.binding.classes.ContextMethodBuilder;
32 import org.jibx.runtime.JiBXException;
33
34 /**
35  * Child component (attribute or content) interface definition. This interface
36  * provides the basic hooks for generating code from the binding definition.
37  *
38  * @author Dennis M. Sosnoski
39  * @version 1.0
40  */

41
42 public interface IComponent
43 {
44     /**
45      * Check if component is an optional item.
46      *
47      * @return <code>true</code> if optional, <code>false</code> if required
48      */

49
50     public boolean isOptional();
51     
52     /**
53      * Check if component defines one or more attribute values of the
54      * containing element.
55      *
56      * @return <code>true</code> if one or more attribute values defined for
57      * containing element, <code>false</code> if not
58      */

59
60     public boolean hasAttribute();
61     
62     /**
63      * Generate code to test for attribute present. This generates code that
64      * tests if a child is present as determined by attributes of the containing
65      * start tag. It leaves the result of the test (zero if missing, nonzero if
66      * present) on the stack. This call is only valid if this component has one
67      * or more attributes for the containing element.
68      *
69      * @param mb method builder
70      * @throws JiBXException if configuration error
71      */

72
73     public void genAttrPresentTest(ContextMethodBuilder mb)
74         throws JiBXException;
75     
76     /**
77      * Generate attribute unmarshalling code. This is called within the code
78      * generation for the unmarshaller of the class associated with the
79      * containing element. It needs to generate the necessary code for handling
80      * the unmarshalling operation, leaving the unmarshalled object
81      * reference on the stack.
82      *
83      * @param mb method builder
84      * @throws JiBXException if error in configuration
85      */

86
87     public void genAttributeUnmarshal(ContextMethodBuilder mb)
88         throws JiBXException;
89
90     /**
91      * Generate attribute marshalling code. This is called within the code
92      * generation for the marshaller of the class associated with the
93      * containing element. It needs to generate the necessary code for handling
94      * the marshalling operation, consuming the marshalled object
95      * reference from the stack.
96      *
97      * @param mb method builder
98      * @throws JiBXException if error in configuration
99      */

100
101     public void genAttributeMarshal(ContextMethodBuilder mb)
102         throws JiBXException;
103
104     /**
105      * Check if component defines one or more elements or text values as
106      * children of the containing element. This method is only valid after the
107      * call to {@link setLinkages}.
108      *
109      * @return <code>true</code> if one or more content values defined
110      * for containing element, <code>false</code> if not
111      */

112
113     public boolean hasContent();
114     
115     /**
116      * Generate code to test for content present. This generates code that
117      * tests if a required element is present, leaving the result of the test
118      * (zero if missing, nonzero if present) on the stack. This call is only
119      * valid if this component has one or more content components for the
120      * containing element.
121      *
122      * @param mb method builder
123      * @throws JiBXException if configuration error
124      */

125
126     public void genContentPresentTest(ContextMethodBuilder mb)
127         throws JiBXException;
128
129     /**
130      * Generate element or text unmarshalling code. This is called within the
131      * code generation for the unmarshaller of the class associated with the
132      * containing element. It needs to generate the necessary code for
133      * handling the unmarshalling operation, leaving the unmarshalled object
134      * reference on the stack.
135      *
136      * @param mb method builder
137      * @throws JiBXException if error in configuration
138      */

139
140     public void genContentUnmarshal(ContextMethodBuilder mb)
141         throws JiBXException;
142
143     /**
144      * Generate element or text marshalling code. This is called within the
145      * code generation for the marshaller of the class associated with the
146      * containing element. It needs to generate the necessary code for
147      * handling the marshalling operation, consuming the marshalled object
148      * reference from the stack.
149      *
150      * @param mb method builder
151      * @throws JiBXException if error in configuration
152      */

153
154     public void genContentMarshal(ContextMethodBuilder mb) throws JiBXException;
155
156     /**
157      * Generate code to create new instance of object. This is called within the
158      * code generation for the unmarshaller of the class associated with the
159      * containing element. It needs to generate the necessary code for creating
160      * an instance of the object to be unmarshalled, leaving the object
161      * reference on the stack.
162      *
163      * @param mb method builder
164      * @throws JiBXException if error in configuration
165      */

166
167     public void genNewInstance(ContextMethodBuilder mb) throws JiBXException;
168     
169     /**
170      * Get type expected by component.
171      *
172      * @return fully qualified class name of expected type
173      */

174
175     public String JavaDoc getType();
176     
177     /**
178      * Check if component defines an ID value for instances of context object.
179      *
180      * @return <code>true</code> if ID value defined for instances,
181      * <code>false</code> if not
182      */

183
184     public boolean hasId();
185
186     /**
187      * Generate code to load ID value of instance to stack. The generated code
188      * should assume that the top of the stack is the reference for the
189      * containing object. It must consume this and leave the actual ID value
190      * on the stack (as a <code>String</code>).
191      *
192      * @param mb method builder
193      * @throws JiBXException if configuration error
194      */

195
196     public void genLoadId(ContextMethodBuilder mb) throws JiBXException;
197     
198     /**
199      * Check sequence of content values. Validates the sequence of content
200      * items, ensuring that text values only occur immediately following a
201      * required element value (or the start tag for the enclosing element).
202      *
203      * @param text allow text value flag from last component
204      * @return allow text value as next content component flag
205      * @throws JiBXException if error in configuration
206      */

207
208     public boolean checkContentSequence(boolean text) throws JiBXException;
209     
210     /**
211      * Establish and validate linkages between binding components. This is
212      * called after the basic binding structures have been set up. All linkages
213      * between components must be resolved by this method, in order to prevent
214      * problems due to the order of definitions between components. This implies
215      * that each component must in turn call the same method for each child
216      * component. None of the other method calls defined by this interface are
217      * valid until after this call.
218      *
219      * @throws JiBXException if error in configuration
220      */

221
222     public void setLinkages() throws JiBXException;
223     
224     // DEBUG
225
public void print(int depth);
226 }
227
Popular Tags