KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > zeus > binder > BaseBinder


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.binder;
20
21 import java.io.IOException JavaDoc;
22 import java.util.List JavaDoc;
23
24 // Zeus imports
25
import org.enhydra.zeus.Binder;
26 import org.enhydra.zeus.Source;
27
28 /**
29  * <p>
30  * <code>{@link Binder}</code> provides an interface for all constraint
31  * representations to use. It defines the contract for conversion
32  * between an arbitrary constraint representation (XML Schema, DTD,
33  * Relax schema, etc) to a set of Zeus
34  * <code>{@link org.enhydra.zeus.Binding}</code>s.
35  * </p><p>
36  * This implementation of <code>Binder</code> handles the
37  * basic functionality of dealing with input so that
38  * other implementations don't have to code these methods.
39  * Thus, <code>XXXBinder</code> classes should extend
40  * this class, rather than directly implementing
41  * <code>Binder</code>, and will get this functionality
42  * "for free."
43  * </p>
44  *
45  * @author Brett McLaughlin
46  * @author Maciej Zawadzki
47  * @author Sean Ogle
48  */

49 public abstract class BaseBinder implements Binder {
50
51     /** The <code>{@link Source}</code> to read input from */
52     protected Source source;
53     
54     /** Whether or not simple elements are being collapsed. */
55     protected boolean isCollapsingSimpleElements;
56     
57     /** Whether or not ID attributes are ignored */
58     protected boolean isIgnoringIDAttributes;
59
60     /**
61      * <p>
62      * This constructor takes in a <code>{@link Source}</code>
63      * to read input from and allow generation of the
64      * <code>{@link org.enhydra.zeus.Binding}</code>s from it.
65      * </p>
66      *
67      * @param source <code>Source</code> to read input from.
68      */

69     public BaseBinder(Source source) {
70         this.source = source;
71         this.isCollapsingSimpleElements = false;
72     }
73     
74     /**
75      * <p>
76      * This sets whether or not to "collapse" simple elements. An element is
77      * simple if it only has character-based content, and no attributes. If
78      * these are collapsed, then they are not turned into full-fledged
79      * Java objects (with only a <code>getValue()</code> method), but instead
80      * become properties with primitive return values on their parents. So
81      * an element named "display-name" with only textual content could be
82      * accessed through it's parent object by invoking
83      * <code>getDisplayName()</code> on the parent, instead of
84      * <code>getDisplayName().getValue()</code>. By default, elements are
85      * <i>not</i> collapsed.
86      * </p>
87      *
88      * @param isCollapsingSimpleElements whether or not to collapse simple
89      * elements.
90      */

91     public void setIsCollapsingSimpleElements(
92         boolean isCollapsingSimpleElements) {
93             
94         this.isCollapsingSimpleElements = isCollapsingSimpleElements;
95     }
96         
97     /**
98      * <p>
99      * This will indicate whether simple elements are being collapsed for
100      * this binder. An element is
101      * simple if it only has character-based content, and no attributes. If
102      * these are collapsed, then they are not turned into full-fledged
103      * Java objects (with only a <code>getValue()</code> method), but instead
104      * become properties with primitive return values on their parents. So
105      * an element named "display-name" with only textual content could be
106      * accessed through it's parent object by invoking
107      * <code>getDisplayName()</code> on the parent, instead of
108      * <code>getDisplayName().getValue()</code>. By default, elements are
109      * <i>not</i> collapsed.
110      * </p>
111      *
112      * @return <code>boolean</code> - whether simple elements are being
113      * collapsed.
114      */

115     public boolean isCollapsingSimpleElements() {
116         return isCollapsingSimpleElements;
117     }
118     
119     /**
120      * <p>
121      * This indicates if the <code>id</code> attribute on elements handled by
122      * this <code>Binder</code> should be ignored in determine if an
123      * element is collapsible. If
124      * <code>{@link #isCollapsingSimpleElements}</code> is false, this has
125      * no effect.
126      * </p>
127      *
128      * @param ignoringIDAttributes whether or not to ignore ID attributes.
129      */

130     public void setIsIgnoringIDAttributes(boolean isIgnoringIDAttributes) {
131         this.isIgnoringIDAttributes = isIgnoringIDAttributes;
132     }
133     
134     /**
135      * <p>
136      * This will indicate if the <code>id</code> attribute on elements handled
137      * by this <code>Binder</code> should be ignored in determine if an
138      * element is collapsible. If
139      * <code>{@link #isCollapsingSimpleElements}</code> is false, this has
140      * no effect.
141      * </p>
142      *
143      * @return <code>boolean</code> - whether ID attributes are ignored.
144      */

145     public boolean isIgnoringIDAttributes() {
146         return isIgnoringIDAttributes;
147     }
148
149     /**
150      * <p>
151      * This is integral portion of the <code>Binder</code>. It
152      * is responsible for returning a Zeus representation of
153      * the set of constraints that this binding represents,
154      * resulting from the input representation (which could
155      * be an XML Schema, DTD, Relax schema, etc.).
156      * </p><p>
157      * There is a temptation to implement a lazy-loading mechanism
158      * here, but that should <i>not</i> be done. That's because
159      * the <code>{@link Source}</code> may stay the same but the actual
160      * input (abstracted by the <code>Source</code> may change
161      * "under the covers." So don't implement lazy-loading here!
162      * </p>
163      *
164      * @return <code>List</code> - the resultant
165      * <code>Binding</code>s from conversion of
166      * constraints.
167      * @exception <code>IOException</code> when errors in reading
168      * input occur.
169      */

170     public abstract List JavaDoc getBindings() throws IOException JavaDoc;
171
172 }
173
Popular Tags