KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > zeus > binding > BaseBinding


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  */

19 package org.enhydra.zeus.binding;
20
21 // Zeus imports
22
import org.enhydra.zeus.Binding;
23 import org.enhydra.zeus.InvalidCollectionTypeException;
24 import org.enhydra.zeus.util.ClassUtils;
25 import org.enhydra.zeus.util.NamingUtils;
26
27 /**
28  * <p>
29  * <code>{@link Binding}</code> represents an arbitrary Java construct,
30  * and provides a representation-independent means of showing
31  * how a constraint (presumably from an XML Schema, DTD, Relax
32  * schema, etc.) maps to Java. It provides a layer of representation
33  * between the constraint representation and generated Java.
34  * </p><p>
35  * This implementation of <code>Binding</code> deals with
36  * the basic functionality of all bindings. It leaves specific
37  * binding implementations to deal with only their functionality.
38  * </p>
39  *
40  * @author Brett McLaughlin
41  * @author Sean Ogle
42  */

43 public abstract class BaseBinding {
44     
45     /** The XML name of the binding */
46     protected String JavaDoc xmlName;
47
48     /** The XML namespace URI associated with the XML name of the binding */
49     protected String JavaDoc xmlNamespaceURI;
50
51     /** The XML type of the binding */
52     protected String JavaDoc xmlType;
53
54     /** The XML namespace URI associated with the XML type of the binding */
55     protected String JavaDoc xmlTypeNamespaceURI;
56     
57     /** The XML parent type for this binding */
58     protected String JavaDoc xmlParentType;
59     
60     /** The XML namespace URI for this binding's XML parent type */
61     protected String JavaDoc xmlParentTypeNamespaceURI;
62     
63     /** Whether this is the XML root element */
64     protected boolean isXMLRootElement;
65
66     /** The Java name of the binding */
67     protected String JavaDoc javaName;
68     
69     /** The Java type of the binding */
70     protected String JavaDoc javaType;
71
72     /** The Java name of the binding that is a legal Java identifier. */
73     protected String JavaDoc javaVariableName;
74
75     /** The Java interface package of the binding */
76     protected String JavaDoc javaInterfacePackage;
77     
78     /** The Java implementation package of the binding */
79     protected String JavaDoc javaImplementationPackage;
80     
81     /** The Java Collection class for this binding */
82     protected String JavaDoc javaCollectionClass;
83     
84     /** Whether this binding is Java-serializable */
85     protected boolean isJavaSerializable;
86     
87     /**
88      * <p>
89      * Default constructor.
90      * </p>
91      */

92     public BaseBinding() {
93         isJavaSerializable = true;
94         isXMLRootElement = false;
95         xmlNamespaceURI = "";
96         xmlTypeNamespaceURI = "";
97         xmlParentTypeNamespaceURI = "";
98     }
99
100     /**
101      * <p>
102      * This will return the XML name of the binding. This should
103      * be the actual XML name of the binding as would be seen in an XML
104      * document.
105      * </p>
106      *
107      * @return <code>String</code> - the XML name of the binding.
108      */

109     public String JavaDoc getXMLName() {
110         return xmlName;
111     }
112     /**
113      * <p>
114      * This will set the XML name of the binding.
115      * </p>
116      *
117      * @param xmlName the XML name of the binding.
118      */

119     public void setXMLName(String JavaDoc xmlName) {
120         if (xmlName == null) {
121             throw new IllegalArgumentException JavaDoc("A Binding cannot have a " +
122                 "null XML name.");
123         }
124         
125         this.xmlName = xmlName;
126     }
127     
128     /**
129      * <p>
130      * The will return the XML namespace URI associated with the XML name of
131      * this binding. A value of the empty string indicates that there is no
132      * URI associated with the XML name of this binding.
133      * </p>
134      *
135      * @return <code>String</code> - the XML namespace URI associated with the
136      * XML name of this binding, or an empty string if no namespace URI.
137      */

138     public String JavaDoc getXMLNamespaceURI() {
139         return xmlNamespaceURI;
140     }
141
142     /**
143      * <p>
144      * The will set the XML namespace URI associated with the XML name of
145      * this binding. A value of the empty string indicates that there is no
146      * URI associated with the XML name of this binding.
147      * </p>
148      *
149      * @param xmlNamespaceURI the XML namespace URI
150      */

151     public void setXMLNamespaceURI(String JavaDoc xmlNamespaceURI) {
152         if (xmlNamespaceURI == null) {
153             throw new IllegalArgumentException JavaDoc("A Binding cannot have a " +
154                 "null XML namespace URI. To specify no namespace URI, " +
155                 "use the empty String (\"\")");
156         }
157         
158         this.xmlNamespaceURI = xmlNamespaceURI;
159     }
160     
161     /**
162      * <p>
163      * This will return the XML local name associated with the XML type of this
164      * binding. When using a DTD, the XML type is the same as the XML name.
165      * However, when using an XML Schema, the type may be different from the
166      * name.
167      * </p>
168      *
169      * @return <code>String</code> - the XML local name of the XML type of this
170      * binding.
171      */

172     public String JavaDoc getXMLType() {
173         return xmlType;
174     }
175
176     /**
177      * <p>
178      * This will set the XML local name associated with the XML type of this
179      * binding.
180      * </p>
181      *
182      * @param xmlType the XML type.
183      */

184     public void setXMLType(String JavaDoc xmlType) {
185         if (xmlType == null) {
186             throw new IllegalArgumentException JavaDoc("A Binding cannot have a " +
187                 "null XML type.");
188         }
189         
190         this.xmlType = xmlType;
191     }
192     
193     /**
194      * <p>
195      * The will return the XML namespace URI associated with the XML type of
196      * this binding. A value of the empty string indicates that there is no
197      * URI associated with the XML type of this binding.
198      * </p><p>
199      * While this is not
200      * useful in DTD binding, it allows types like <code>xsd:string</code> to
201      * be distinguished from something like <code>myPrefix:string</code>,
202      * which a user might define.
203      * </p>
204      *
205      * @return <code>String</code> - the XML namespace URI associated with the
206      * XML type of this binding.
207      */

208     public String JavaDoc getXMLTypeNamespaceURI() {
209         return xmlTypeNamespaceURI;
210     }
211
212     /**
213      * <p>
214      * This will set the XML namespace URI associated with the XML type of
215      * this binding. A value of the empty string indicates that there is no
216      * URI associated with the XML type of this binding.
217      * </p>
218      *
219      * @param xmlTypeNamespaceURI the XML type's namespace URI.
220      */

221     public void setXMLTypeNamespaceURI(String JavaDoc xmlTypeNamespaceURI) {
222         if (xmlTypeNamespaceURI == null) {
223             throw new IllegalArgumentException JavaDoc("A Binding cannot have a " +
224                 "null XML type namespace URI. To specify no namespace URI, " +
225                 "use the empty String (\"\")");
226         }
227         
228         this.xmlTypeNamespaceURI = xmlTypeNamespaceURI;
229     }
230     
231     /**
232      * <p>
233      * This will return the XML local name associated with the XML type of this
234      * binding's XML parent. When using a DTD, the XML type is the same as
235      * the XML name. However, when using an XML Schema, the type may be
236      * different from the name.
237      * </p><p>
238      * If there is no parent XML type, such as for the root element of a
239      * document, this value is <code>null</code>.
240      *
241      * @return <code>String</code> - the XML local name of the XML type of this
242      * binding's parent.
243      */

244     public String JavaDoc getXMLParentType() {
245         return xmlParentType;
246     }
247
248     /**
249      * <p>
250      * This will set the XML local name associated with the XML type of this
251      * binding's XML parent.
252      * </p>
253      *
254      * @param xmlParentType the XML type for this binding's parent.
255      */

256     public void setXMLParentType(String JavaDoc xmlParentType) {
257         if (xmlParentType == null) {
258             throw new IllegalArgumentException JavaDoc("A Binding cannot have a " +
259                 "null parent XML type.");
260         }
261         
262         this.xmlParentType = xmlParentType;
263     }
264     
265     /**
266      * <p>
267      * The will return the XML namespace URI associated with the XML type of
268      * this binding's XML parent. A value of the empty string indicates that
269      * there is no URI associated with the XML type of this binding's parent.
270      * </p><p>
271      * While this is not
272      * useful in DTD binding, it allows types like <code>xsd:string</code> to
273      * be distinguished from something like <code>myPrefix:string</code>,
274      * which a user might define.
275      * </p>
276      *
277      * @return <code>String</code> - the XML namespace URI associated with the
278      * XML type of this binding's parent.
279      */

280     public String JavaDoc getXMLParentTypeNamespaceURI() {
281         return xmlParentTypeNamespaceURI;
282     }
283
284     /**
285      * <p>
286      * This will set the XML namespace URI associated with the XML type of
287      * this binding's XML parent. A value of the empty string indicates that
288      * there is no URI associated with the XML type of this binding's parent.
289      * </p>
290      *
291      * @param xmlParentTypeNamespaceURI the XML namespace URI of the
292      * parent type.
293      */

294     public void setXMLParentTypeNamespaceURI(String JavaDoc xmlParentTypeNamespaceURI) {
295         if (xmlParentTypeNamespaceURI == null) {
296             throw new IllegalArgumentException JavaDoc("A Binding cannot have a " +
297                 "null parent XML type namespace URI. To specify no namespace " +
298                 "URI, use the empty String (\"\")");
299         }
300         
301         this.xmlParentTypeNamespaceURI = xmlParentTypeNamespaceURI;
302     }
303     
304     /**
305      * <p>
306      * This sets whether this binding represents an XML element that is
307      * the root element of the document.
308      * </p>
309      *
310      * @param isXMLRootElement whether this is the root element.
311      */

312     public void setIsXMLRootElement(boolean isXMLRootElement) {
313         this.isXMLRootElement = isXMLRootElement;
314     }
315     
316     /**
317      * <p>
318      * This indicates if this binding represents an XML element that is the
319      * root element of the document.
320      * </p>
321      *
322      * @return <code>boolean</code> - whether this is the root element.
323      */

324     public boolean isXMLRootElement() {
325         return isXMLRootElement;
326     }
327
328     /**
329      * <p>
330      * This will return the Java name of the binding. This should
331      * be the valid Java name of the binding, which is most
332      * often a variable name. This is the string used to build the methods
333      * <code>setXXX()</code> and <code>getXXX()</code>. Note that this is
334      * not necessarily the variable name used by the generators, but they
335      * will provide the <code>setXXX()</code> and <code>getXXX()</code>
336      * based on this name.
337      * </p>
338      *
339      * @return <code>String</code> - the Java name of the binding.
340      */

341     public String JavaDoc getJavaName() {
342         return javaName;
343     }
344
345     /**
346      * <p>
347      * The will set the name of the Java variable associated with this binding.
348      * </p>
349      *
350      * @param javaName the new variable name.
351      */

352     public void setJavaName(String JavaDoc javaName) {
353         if (javaName == null) {
354             throw new IllegalArgumentException JavaDoc("A Binding cannot have a " +
355                 "null Java name.");
356         }
357         
358         this.javaName = javaName;
359     }
360     
361     /**
362      * <p>
363      * This will return the Java type associated with the
364      * binding. This is not a fully qualified name for the type. To get the
365      * fully qualified name for the type prepend the value returned from
366      * getJavaPackage() to the value returned by this method (with a "."
367      * inserted in between if the package is not the empty string).
368      * </p>
369      *
370      * @return <code>String</code> - the Java type of the binding.
371      */

372     public String JavaDoc getJavaType() {
373         return javaType;
374     }
375     
376     /**
377      * <p>
378      * This will set the Java type for this binding.
379      * </p>
380      *
381      * @param javaType the Java type for this binding.
382      */

383     public void setJavaType(String JavaDoc javaType) {
384         if (javaType == null) {
385             throw new IllegalArgumentException JavaDoc("A Binding cannot have a " +
386                 "null Java type.");
387         }
388         
389         this.javaType = javaType;
390     }
391
392     /**
393      * <p>
394      * This will return the Java name that can be used for a variable name in
395      * generated code. It is guaranteed to be a legal Java identifier.
396      * </p><p>
397      * To illustrate the difference between the Java name and its variable
398      * name, consider this simple example:
399      * <pre><code>
400      * <!ELEMENT default EMPTY>
401      * </code></pre>
402      * With the above DTD the XML name is "default". However, "default"
403      * is a Java keyword, but <code>setDefault()</code> and
404      * <code>getDefault()</code> are not illegal. So for a typical name
405      * binding, the Java name would be "default" and the variable name
406      * would (could) be "safeDefault". The generated interface would still
407      * contain <code>setDefault()</code> and <code>getDefault()</code>.
408      * </p><p>
409      * Note that it is not necessary for the variable name to always (or even
410      * often) be different from the normal Java name.
411      * </p>
412      *
413      * @return <code>String</code> - the Java variable name.
414      */

415     public String JavaDoc getJavaVariableName() {
416         return javaVariableName;
417     }
418
419     /**
420      * <p>
421      * This will set the Java name that can be used for a variable name in
422      * generated code. This must be a legal Java identifier, and the first
423      * character must not be an upper case letter.
424      * </p>
425      *
426      * @param javaVariableName the name to use for the Java member variable.
427      */

428     public void setJavaVariableName(String JavaDoc javaVariableName) {
429         if (javaVariableName == null) {
430             throw new IllegalArgumentException JavaDoc("A Binding cannot have a " +
431                 "null Java variable name.");
432         }
433         
434         this.javaVariableName = javaVariableName;
435     }
436
437     /**
438      * <p>
439      * This will return the Java package name for this binding's interface
440      * class.
441      * </p>
442      *
443      * @return <code>String</code> - the Java interface package associated with
444      * the binding's Java type.
445      */

446     public String JavaDoc getJavaInterfacePackage() {
447         return javaInterfacePackage;
448     }
449
450     /**
451      * <p>
452      * This will set the Java package for this class's interface.
453      * </p>
454      *
455      * @param javaInterfacePackage the name of the interface package for this
456      * binding.
457      */

458     public void setJavaInterfacePackage(String JavaDoc javaInterfacePackage) {
459         if (javaInterfacePackage == null) {
460             throw new IllegalArgumentException JavaDoc("A Binding cannot have a " +
461                 "null Java interface package name.");
462         }
463         
464         this.javaInterfacePackage = javaInterfacePackage;
465     }
466     
467     /**
468      * <p>
469      * This will return the Java package name for this binding's implementation
470      * class.
471      * </p>
472      *
473      * @return <code>String</code> - the Java implementation package associated
474      * with the binding's Java type.
475      */

476     public String JavaDoc getJavaImplementationPackage() {
477         return javaImplementationPackage;
478     }
479
480     /**
481      * <p>
482      * This will set the Java package for this class's implementation.
483      * </p>
484      *
485      * @param javaImplementationPackage the name of the implementation package
486      * for this binding.
487      */

488     public void setJavaImplementationPackage(String JavaDoc javaImplementationPackage) {
489         if (javaImplementationPackage == null) {
490             throw new IllegalArgumentException JavaDoc("A Binding cannot have a " +
491                 "null implementation package name.");
492         }
493         
494         this.javaImplementationPackage = javaImplementationPackage;
495     }
496     
497     /**
498      * <p>
499      * This will set the Java collection class to use for this binding,
500      * if it is a collection. This will be a fully-qualified Java class,
501      * such as <code>java.util.List</code>.
502      * </p>
503      *
504      * @param javaCollectionClass the collection class for this binding.
505      * @throws <code>InvalidCollectionTypeException</code> - when the supplied
506      * collection class is not a valid collection type.
507      */

508     public void setJavaCollectionClass(String JavaDoc javaCollectionClass)
509         throws InvalidCollectionTypeException {
510         
511         if (javaCollectionClass == null) {
512             throw new IllegalArgumentException JavaDoc("A Binding cannot have a null " +
513                 "Java collection class.");
514         }
515         if (!ClassUtils.isCollectionClass(javaCollectionClass)) {
516             throw new InvalidCollectionTypeException(javaCollectionClass);
517         }
518         
519         this.javaCollectionClass = javaCollectionClass;
520     }
521     
522     /**
523      * <p>
524      * This will return the Java collection class to use for this binding,
525      * if it is a collection. This will be a fully qualified Java class,
526      * such as <code>java.util.List</code>.
527      * </p>
528      *
529      * @return <code>String</code> - the Java collection class for this binding.
530      */

531     public String JavaDoc getJavaCollectionClass() {
532         return javaCollectionClass;
533     }
534     
535     /**
536      * <p>
537      * This will set whether this binding should be a Java-serializable class.
538      * </p>
539      *
540      * @param isJavaSerializable whether this binding should be Java
541      * serializable (true) or not (false).
542      */

543     public void setIsJavaSerializable(boolean isJavaSerializable) {
544         this.isJavaSerializable = isJavaSerializable;
545     }
546     
547     /**
548      * <p>
549      * This will indicate whether this binding is Java-serializable (indicated
550      * by a <code>boolean</code> value of "true"), or not (indicated by a
551      * <code>boolean</code> value of "false").
552      * </p>
553      *
554      * @return <code>boolean</code> - whether this binding is Java-serializable.
555      */

556     public boolean isJavaSerializable() {
557         return isJavaSerializable;
558     }
559 }
560
Popular Tags