KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > datatype > BinaryBase


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.axi.datatype;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.modules.xml.axi.datatype.Datatype.Facet;
26 import org.netbeans.modules.xml.schema.model.Whitespace;
27
28 /**
29  *
30  * @author Ayub Khan
31  */

32 public abstract class BinaryBase extends Datatype {
33     
34     static List JavaDoc<Facet> applicableFacets;
35     
36     private Datatype.Kind kind;
37     
38     protected boolean hasFacets;
39     
40     private boolean isList;
41     
42     private List JavaDoc<Integer JavaDoc> lengths;
43     
44     private List JavaDoc<Integer JavaDoc> minLengths;
45     
46     private List JavaDoc<Integer JavaDoc> maxLengths;
47     
48     private List JavaDoc<String JavaDoc> patterns;
49     
50     protected List JavaDoc<String JavaDoc> enumerations;
51     
52     private List JavaDoc<Whitespace.Treatment> whitespaces;
53     
54     
55     /** Creates a new instance of TypeBase */
56     public BinaryBase(Kind kind) {
57         this.kind = kind;
58     }
59     
60     public Kind getKind() {
61         return kind;
62     }
63     
64     public synchronized List JavaDoc<Facet> getApplicableFacets() {
65         if(applicableFacets == null) {
66             List JavaDoc<Facet> facets = new ArrayList JavaDoc<Facet>();
67             facets.add(Facet.LENGTH);
68             facets.add(Facet.MINLENGTH);
69             facets.add(Facet.MAXLENGTH);
70             facets.add(Facet.PATTERN);
71             facets.add(Facet.ENUMERATION);
72             facets.add(Facet.WHITESPACE);
73             applicableFacets = Collections.unmodifiableList(facets);
74         }
75         return applicableFacets;
76     }
77     
78     public boolean hasFacets() {
79         return hasFacets;
80     }
81     
82     public boolean isList() {
83         return isList;
84     }
85     
86     public void setIsList(boolean isList) {
87         this.isList = isList;
88     }
89     
90     /*
91      * returns length (this corresponds to the value of length facet in schema)
92      *
93      * @return length
94      */

95     public List JavaDoc<Integer JavaDoc> getLengths() {
96         return lengths;
97     }
98     
99     /*
100      * returns minimum length value (this corresponds to the value of minlength facet in schema)
101      *
102      * @return minLength
103      */

104     public List JavaDoc<Integer JavaDoc> getMinLengths() {
105         return minLengths;
106     }
107     
108     /*
109      * returns maximum length value (this corresponds to the value of maxlength facet in schema)
110      *
111      * @return maxLength
112      */

113     public List JavaDoc<Integer JavaDoc> getMaxLengths() {
114         return maxLengths;
115     }
116     
117     /*
118      * returns pattern value (this corresponds to the value of pattern facet in schema)
119      *
120      * @return pattern
121      */

122     public List JavaDoc<String JavaDoc> getPatterns() {
123         return patterns;
124     }
125     
126     /*
127      * returns enumeration values (this corresponds to the values of enumeration facets in schema)
128      *
129      * @return enumeration
130      */

131     public List JavaDoc<String JavaDoc> getEnumerations() {
132         return enumerations;
133     }
134     
135     /*
136      * returns whitespace value (this corresponds to the value of whitespace facet in schema)
137      *
138      * @return whitespaces
139      */

140     public List JavaDoc<Whitespace.Treatment> getWhiteSpaces() {
141         return whitespaces;
142     }
143     
144     /*
145      * set length (this corresponds to the value of length facet in schema)
146      *
147      * @param length
148      */

149     public void addLength(int length) {
150         if(lengths == null) {
151             lengths = new ArrayList JavaDoc<Integer JavaDoc>(1);
152             hasFacets = true;
153         }
154         this.lengths.add(new Integer JavaDoc(length));
155     }
156     
157     /*
158      * set minimum length value (this corresponds to the value of minlength facet in schema)
159      *
160      * @param minLength
161      */

162     public void addMinLength(int minLength) {
163         if(minLengths == null) {
164             minLengths = new ArrayList JavaDoc<Integer JavaDoc>(1);
165             hasFacets = true;
166         }
167         this.minLengths.add(new Integer JavaDoc(minLength));
168     }
169     
170     /*
171      * set maximum length value (this corresponds to the value of maxlength facet in schema)
172      *
173      * @param maxLength
174      */

175     public void addMaxLength(int maxLength) {
176         if(maxLengths == null) {
177             maxLengths = new ArrayList JavaDoc<Integer JavaDoc>(1);
178             hasFacets = true;
179         }
180         this.maxLengths.add(new Integer JavaDoc(maxLength));
181     }
182     
183     /*
184      * set pattern value (this corresponds to the value of pattern facet in schema)
185      *
186      * @param pattern
187      */

188     public void addPattern(String JavaDoc pattern) {
189         if(patterns == null) {
190             patterns = new ArrayList JavaDoc<String JavaDoc>(1);
191             hasFacets = true;
192         }
193         this.patterns.add(pattern);
194     }
195     
196     /*
197      * returns enumeration values (this corresponds to the values of enumeration facets in schema)
198      *
199      * @param enumeration
200      */

201     public void addEnumeration(String JavaDoc enumeration) {
202         if(enumerations == null) {
203             enumerations = new ArrayList JavaDoc<String JavaDoc>(1);
204             hasFacets = true;
205         }
206         this.enumerations.add(enumeration);
207     }
208     
209     /*
210      * set whitespace value (this corresponds to the value of whitespace facet in schema)
211      *
212      * @param whitespace
213      */

214     public void addWhitespace(Whitespace.Treatment whitespace) {
215         if(whitespaces == null) {
216             whitespaces = new ArrayList JavaDoc<Whitespace.Treatment>(1);
217             hasFacets = true;
218         }
219         this.whitespaces.add(whitespace);
220     }
221     
222     /*
223      * remove length (this corresponds to the value of length facet in schema)
224      *
225      * @param length
226      */

227     public void removeLength(Number JavaDoc length) {
228         if(lengths != null)
229             lengths.remove(length);
230     }
231     
232     /*
233      * remove minimum length value (this corresponds to the value of minlength facet in schema)
234      *
235      * @param minLength
236      */

237     public void removeMinLength(Number JavaDoc minLength) {
238         if(minLengths != null)
239             minLengths.remove(minLength);
240     }
241     
242     /*
243      * set maximum length value (this corresponds to the value of maxlength facet in schema)
244      *
245      * @param maxLength
246      */

247     public void removeMaxLength(Number JavaDoc maxLength) {
248         if(maxLengths != null)
249             maxLengths.remove(maxLength);
250     }
251     
252     /*
253      * set pattern value (this corresponds to the value of pattern facet in schema)
254      *
255      * @param pattern
256      */

257     public void removePattern(String JavaDoc pattern) {
258         if(patterns != null)
259             patterns.remove(pattern);
260     }
261     
262     /*
263      * remove enumeration values (this corresponds to the values of enumeration facets in schema)
264      *
265      * @param enumeration
266      */

267     public void removeEnumeration(String JavaDoc enumeration) {
268         if(enumerations != null)
269             enumerations.remove(enumeration);
270     }
271     
272     /*
273      * set whitespace value (this corresponds to the value of whitespace facet in schema)
274      *
275      * @param whitespace
276      */

277     public void removeWhitespace(Whitespace.Treatment whitespace) {
278         if(whitespaces != null)
279             whitespaces.remove(whitespace);
280     }
281 }
282
Popular Tags