001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.axi.datatype;
043:
044: import java.util.ArrayList;
045: import java.util.Collections;
046: import java.util.List;
047: import org.netbeans.modules.xml.axi.datatype.Datatype.Facet;
048: import org.netbeans.modules.xml.schema.model.Whitespace;
049:
050: /**
051: *
052: * @author Ayub Khan
053: */
054: public class StringBase extends Datatype {
055:
056: static List<Facet> applicableFacets;
057:
058: private Datatype.Kind kind;
059:
060: private String name;
061:
062: private boolean hasFacets;
063:
064: private boolean isList;
065:
066: private List<Integer> lengths;
067:
068: private List<Integer> minLengths;
069:
070: private List<Integer> maxLengths;
071:
072: private List<String> patterns;
073:
074: private List<String> enumerations;
075:
076: private List<Whitespace.Treatment> whitespaces;
077:
078: /** Creates a new instance of TypeBase */
079: public StringBase(Kind kind) {
080: this .kind = kind;
081: }
082:
083: public Kind getKind() {
084: return kind;
085: }
086:
087: public synchronized List<Facet> getApplicableFacets() {
088: if (applicableFacets == null) {
089: List<Facet> facets = new ArrayList<Facet>();
090: facets.add(Facet.LENGTH);
091: facets.add(Facet.MINLENGTH);
092: facets.add(Facet.MAXLENGTH);
093: facets.add(Facet.PATTERN);
094: facets.add(Facet.ENUMERATION);
095: facets.add(Facet.WHITESPACE);
096: applicableFacets = Collections.unmodifiableList(facets);
097: }
098: return applicableFacets;
099: }
100:
101: public boolean hasFacets() {
102: return hasFacets;
103: }
104:
105: public boolean isList() {
106: return isList;
107: }
108:
109: public void setIsList(boolean isList) {
110: this .isList = isList;
111: }
112:
113: /*
114: * returns length (this corresponds to the value of length facet in schema)
115: *
116: * @return length
117: */
118: public List<Integer> getLengths() {
119: return lengths;
120: }
121:
122: /*
123: * returns minimum length value (this corresponds to the value of minlength facet in schema)
124: *
125: * @return minLength
126: */
127: public List<Integer> getMinLengths() {
128: return minLengths;
129: }
130:
131: /*
132: * returns maximum length value (this corresponds to the value of maxlength facet in schema)
133: *
134: * @return maxLength
135: */
136: public List<Integer> getMaxLengths() {
137: return maxLengths;
138: }
139:
140: /*
141: * returns pattern value (this corresponds to the value of pattern facet in schema)
142: *
143: * @return pattern
144: */
145: public List<String> getPatterns() {
146: return patterns;
147: }
148:
149: /*
150: * returns enumeration values (this corresponds to the values of enumeration facets in schema)
151: *
152: * @return enumeration
153: */
154: public List<String> getEnumerations() {
155: return enumerations;
156: }
157:
158: /*
159: * returns whitespace value (this corresponds to the value of whitespace facet in schema)
160: *
161: * @return whitespaces
162: */
163: public List<Whitespace.Treatment> getWhiteSpaces() {
164: return whitespaces;
165: }
166:
167: /*
168: * set length (this corresponds to the value of length facet in schema)
169: *
170: * @param length
171: */
172: public void addLength(int length) {
173: if (lengths == null) {
174: lengths = new ArrayList<Integer>(1);
175: hasFacets = true;
176: }
177: this .lengths.add(new Integer(length));
178: }
179:
180: /*
181: * set minimum length value (this corresponds to the value of minlength facet in schema)
182: *
183: * @param minLength
184: */
185: public void addMinLength(int minLength) {
186: if (minLengths == null) {
187: minLengths = new ArrayList<Integer>(1);
188: hasFacets = true;
189: }
190: this .minLengths.add(new Integer(minLength));
191: }
192:
193: /*
194: * set maximum length value (this corresponds to the value of maxlength facet in schema)
195: *
196: * @param maxLength
197: */
198: public void addMaxLength(int maxLength) {
199: if (maxLengths == null) {
200: maxLengths = new ArrayList<Integer>(1);
201: hasFacets = true;
202: }
203: this .maxLengths.add(new Integer(maxLength));
204: }
205:
206: /*
207: * set pattern value (this corresponds to the value of pattern facet in schema)
208: *
209: * @param pattern
210: */
211: public void addPattern(String pattern) {
212: if (patterns == null) {
213: patterns = new ArrayList<String>(1);
214: hasFacets = true;
215: }
216: this .patterns.add(pattern);
217: }
218:
219: /*
220: * returns enumeration values (this corresponds to the values of enumeration facets in schema)
221: *
222: * @param enumeration
223: */
224: public void addEnumeration(String enumeration) {
225: if (enumerations == null) {
226: enumerations = new ArrayList<String>(1);
227: hasFacets = true;
228: }
229: this .enumerations.add(enumeration);
230: }
231:
232: /*
233: * set whitespace value (this corresponds to the value of whitespace facet in schema)
234: *
235: * @param whitespace
236: */
237: public void addWhitespace(Whitespace.Treatment whitespace) {
238: if (whitespaces == null) {
239: whitespaces = new ArrayList<Whitespace.Treatment>(1);
240: hasFacets = true;
241: }
242: this .whitespaces.add(whitespace);
243: }
244:
245: /*
246: * remove length (this corresponds to the value of length facet in schema)
247: *
248: * @param length
249: */
250: public void removeLength(Number length) {
251: if (lengths != null)
252: lengths.remove(length);
253: }
254:
255: /*
256: * set minimum length value (this corresponds to the value of minlength facet in schema)
257: *
258: * @param minLength
259: */
260: public void removeMinLength(Number minLength) {
261: if (minLengths != null)
262: minLengths.remove(minLength);
263: }
264:
265: /*
266: * set maximum length value (this corresponds to the value of maxlength facet in schema)
267: *
268: * @param maxLength
269: */
270: public void removeMaxLength(Number maxLength) {
271: if (maxLengths != null)
272: maxLengths.remove(maxLength);
273: }
274:
275: /*
276: * set pattern value (this corresponds to the value of pattern facet in schema)
277: *
278: * @param pattern
279: */
280: public void removePattern(String pattern) {
281: if (patterns != null)
282: patterns.remove(pattern);
283: }
284:
285: /*
286: * returns enumeration values (this corresponds to the values of enumeration facets in schema)
287: *
288: * @param enumeration
289: */
290: public void removeEnumeration(String enumeration) {
291: if (enumerations != null)
292: enumerations.remove(enumeration);
293: }
294:
295: /*
296: * set whitespace value (this corresponds to the value of whitespace facet in schema)
297: *
298: * @param whitespace
299: */
300: public void removeWhitespace(Whitespace.Treatment whitespace) {
301: if (whitespaces != null)
302: whitespaces.remove(whitespace);
303: }
304: }
|