1 /*
2 * Copyright 2006 Assaf Arkin, Keith Visco, Ralf Joachim
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.exolab.castor.xml;
17
18 import java.util.List;
19
20 import org.exolab.castor.mapping.FieldDescriptor;
21 import org.exolab.castor.xml.util.XMLFieldDescriptorImpl;
22
23 /**
24 * XML field descriptor. Wraps {@link FieldDescriptor} and adds
25 * XML-related information, type conversion, and so on.
26 *
27 * @author <a href="mailto:arkin AT intalio DOT com">Assaf Arkin</a>
28 * @author <a href="mailto:keith AT kvisco DOT com">Keith Visco</a>
29 * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
30 * @version $Revision$ $Date: 2004-09-17 00:47:41 -0600 (Fri, 17 Sep 2004) $
31 */
32 public interface XMLFieldDescriptor extends FieldDescriptor {
33 /** The xml:space property. */
34 String PROPERTY_XML_SPACE = "xml:space";
35
36 /** The xml:lang property. */
37 String PROPERTY_XML_LANG = "xml:lang";
38
39 /**
40 * Returns the index within the constructor argument array where the value
41 * of this field should be. A value less than zero indicates that the value
42 * of this field is set via a normal setter method and not via the
43 * constructor.
44 * <p>
45 * Note: This only applies to attribute mapped fields at this time.
46 *
47 * @return the index within the constructor argument array for this field.
48 * @see #isConstructorArgument()
49 */
50 int getConstructorArgumentIndex();
51
52 /**
53 * Returns true if the value of the field represented by this descriptor
54 * should be set via the constructor of the containing class. This is only
55 * valid for attribute mapped fields.
56 *
57 * @return true if the value of the field represented by this descriptor
58 * should be set via the constructor of the containing class.
59 */
60 boolean isConstructorArgument();
61
62 /**
63 * Returns the "relative" XML path for the field being described.
64 * <p>
65 * In most cases, this will be null. However sometimes a field may be mapped
66 * to a nested element. In which case the value returned by this method
67 * should be the nested element name. If more than one level of nesting is
68 * needed each nested element name should be separated by by a path
69 * separator (forward slash '/').
70 * <p>
71 * The location path name is "relative" to the parent Class. The name of the
72 * parent must not be included in the path.
73 * <p>
74 * For example, give the following two classes:
75 * <pre>
76 * class Root {
77 * Bar bar;
78 * }
79 *
80 * class Bar {
81 * String value;
82 * }
83 * </pre>
84 *
85 * And the following XML:
86 *
87 * <pre>
88 * <root>
89 * <foo>
90 * <bar> value of bar </bar>
91 * </foo>
92 * </root>
93 * </pre>
94 *
95 * Since <foo> has no associated class, the path for 'bar' would be: "foo"
96 *
97 * @return The "relative" XML path for the field being described.
98 */
99 String getLocationPath();
100
101 /**
102 * Return the "suggested" namespace prefix to use when marshaling as XML.
103 *
104 * @return the "suggested" namespace prefix.
105 */
106 String getNameSpacePrefix();
107
108 /**
109 * Returns the namespace URI to be used when marshaling and unmarshaling as
110 * XML.
111 *
112 * @return the namespace URI.
113 */
114 String getNameSpaceURI();
115
116 /**
117 * Returns the node type of the field being described. The {@link NodeType}
118 * represents the type of node that the field will be marshaled into XML as.
119 *
120 * @return the {@link NodeType} of the Field being described.
121 */
122 NodeType getNodeType();
123
124 /**
125 * Returns the value property with the given name or null if no such
126 * property exists. This method is useful for future evolutions of this
127 * interface as well as for user-defined extensions. See class declared
128 * properties for built-in properties.
129 *
130 * @param propertyName the name of the property whose value should be
131 * returned.
132 *
133 * @return the value of the property, or null.
134 */
135 String getXMLProperty(String propertyName);
136
137 /**
138 * Returns the XML Schema type of the XML field being described.
139 *
140 * @return the XML Schema type of the XML field being described.
141 */
142 String getSchemaType();
143
144 /**
145 * Returns a specific validator for the field described by this descriptor.
146 * A null value may be returned if no specific validator exists.
147 *
148 * @return the field validator for the described field
149 */
150 FieldValidator getValidator();
151
152 /**
153 * Returns the XML Name for the field being described.
154 *
155 * @return the XML name.
156 */
157 String getXMLName();
158
159 /**
160 * Returns true if the field described by this descriptor is a container
161 * field. A container is a field that is not a first-class object,
162 * and should therefore have no XML representation.
163 *
164 * @return true if the field is a container
165 */
166 boolean isContainer();
167
168 /**
169 * Returns the incremental flag which when true indicates that this member
170 * may be safely added before the unmarshaler is finished unmarshaling it.
171 *
172 * @return true if the Object can safely be added before the unmarshaler is
173 * finished unmarshaling the Object.
174 */
175 boolean isIncremental();
176
177 /**
178 * Returns true if the field described by this descriptor is Map or
179 * Hashtable. If this method returns true, it must also return true for any
180 * call to {@link #isMultivalued}.
181 *
182 * @return true if the field described by this desciptor is a Map or
183 * Hashtable, otherwise false.
184 */
185 boolean isMapped();
186
187 /**
188 * Returns true if the field described by this descriptor can contain more
189 * than one value.
190 *
191 * @return true if the field described by this descriptor can contain more
192 * than one value
193 */
194 boolean isMultivalued();
195
196 /**
197 * Returns true if the field described by this descriptor may be nillable. A
198 * nillable field is one that may have empty content and still be valid.
199 * Please see the XML Schema 1.0 Recommendation for more information on
200 * nillable.
201 *
202 * @return true if the field may be nillable.
203 */
204 boolean isNillable();
205
206 /**
207 * Returns true if the field described by this descriptor is a reference
208 * (ie. IDREF) to another object in the "Object Model" (e.g., XML tree).
209 *
210 * @return true if the field described by this descriptor is a reference to
211 * another object in the "Object Model"
212 */
213 boolean isReference();
214
215 /**
216 * Returns true if this descriptor can be used to handle elements or
217 * attributes with the given XML name. By default this method simply
218 * compares the given XML name with the internal XML name. This method can
219 * be overridden to provide more complex matching.
220 *
221 * @param xmlName the XML name to compare
222 * @return true if this descriptor can be used to handle elements or
223 * attributes with the given XML name.
224 */
225 boolean matches(String xmlName);
226
227 /**
228 * Returns true if this descriptor can be used to handle elements or
229 * attributes with the given XML name. By default this method simply
230 * compares the given XML name with the internal XML name. This method can
231 * be overridden to provide more complex matching.
232 *
233 * @param xmlName the XML name to compare
234 * @param namespace the namespace URI
235 *
236 * @return true if this descriptor can be used to handle elements or
237 * attributes with the given XML name.
238 */
239 boolean matches(String xmlName, String namespace);
240
241 /**
242 * Returns the possible substitution groups for this class.
243 * @return the possible substitution groups for this class.
244 */
245 List<String> getSubstitutes();
246
247 /**
248 * Sets the possible substitution groups for this class.
249 * @param substitutes Possible substitution groups for this class.
250 */
251 void setSubstitutes(List<String> substitutes);
252
253 /**
254 * Sets whether the field described by this {@link XMLFieldDescriptorImpl} is
255 * created as a result of a <xs:list> definition.
256 * @param derivedFromXSList A boolean value, true or false.
257 */
258 void setDerivedFromXSList(boolean derivedFromXSList);
259
260 /**
261 * Indicates whether the field described by this {@link XMLFieldDescriptorImpl} is
262 * created as a result of a <xs:list> definition.
263 * @param derivedFromXSList Trueif the field described by this {@link XMLFieldDescriptorImpl} is
264 * created as a result of a <xs:list> definition.
265 .
266 */
267 boolean isDerivedFromXSList();
268
269 /**
270 * Returns the component type of this {@link XMLFieldDescriptor} instance, if
271 * the field described represents a collection of values.
272 * @return The collection's component type.
273 * @see XMLFieldDescriptor#getSchemaType()
274 */
275 String getComponentType();
276
277
278 }