KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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