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 abstract class BinaryBase extends Datatype {
055:
056: static List<Facet> applicableFacets;
057:
058: private Datatype.Kind kind;
059:
060: protected boolean hasFacets;
061:
062: private boolean isList;
063:
064: private List<Integer> lengths;
065:
066: private List<Integer> minLengths;
067:
068: private List<Integer> maxLengths;
069:
070: private List<String> patterns;
071:
072: protected List<String> enumerations;
073:
074: private List<Whitespace.Treatment> whitespaces;
075:
076: /** Creates a new instance of TypeBase */
077: public BinaryBase(Kind kind) {
078: this .kind = kind;
079: }
080:
081: public Kind getKind() {
082: return kind;
083: }
084:
085: public synchronized List<Facet> getApplicableFacets() {
086: if (applicableFacets == null) {
087: List<Facet> facets = new ArrayList<Facet>();
088: facets.add(Facet.LENGTH);
089: facets.add(Facet.MINLENGTH);
090: facets.add(Facet.MAXLENGTH);
091: facets.add(Facet.PATTERN);
092: facets.add(Facet.ENUMERATION);
093: facets.add(Facet.WHITESPACE);
094: applicableFacets = Collections.unmodifiableList(facets);
095: }
096: return applicableFacets;
097: }
098:
099: public boolean hasFacets() {
100: return hasFacets;
101: }
102:
103: public boolean isList() {
104: return isList;
105: }
106:
107: public void setIsList(boolean isList) {
108: this .isList = isList;
109: }
110:
111: /*
112: * returns length (this corresponds to the value of length facet in schema)
113: *
114: * @return length
115: */
116: public List<Integer> getLengths() {
117: return lengths;
118: }
119:
120: /*
121: * returns minimum length value (this corresponds to the value of minlength facet in schema)
122: *
123: * @return minLength
124: */
125: public List<Integer> getMinLengths() {
126: return minLengths;
127: }
128:
129: /*
130: * returns maximum length value (this corresponds to the value of maxlength facet in schema)
131: *
132: * @return maxLength
133: */
134: public List<Integer> getMaxLengths() {
135: return maxLengths;
136: }
137:
138: /*
139: * returns pattern value (this corresponds to the value of pattern facet in schema)
140: *
141: * @return pattern
142: */
143: public List<String> getPatterns() {
144: return patterns;
145: }
146:
147: /*
148: * returns enumeration values (this corresponds to the values of enumeration facets in schema)
149: *
150: * @return enumeration
151: */
152: public List<String> getEnumerations() {
153: return enumerations;
154: }
155:
156: /*
157: * returns whitespace value (this corresponds to the value of whitespace facet in schema)
158: *
159: * @return whitespaces
160: */
161: public List<Whitespace.Treatment> getWhiteSpaces() {
162: return whitespaces;
163: }
164:
165: /*
166: * set length (this corresponds to the value of length facet in schema)
167: *
168: * @param length
169: */
170: public void addLength(int length) {
171: if (lengths == null) {
172: lengths = new ArrayList<Integer>(1);
173: hasFacets = true;
174: }
175: this .lengths.add(new Integer(length));
176: }
177:
178: /*
179: * set minimum length value (this corresponds to the value of minlength facet in schema)
180: *
181: * @param minLength
182: */
183: public void addMinLength(int minLength) {
184: if (minLengths == null) {
185: minLengths = new ArrayList<Integer>(1);
186: hasFacets = true;
187: }
188: this .minLengths.add(new Integer(minLength));
189: }
190:
191: /*
192: * set maximum length value (this corresponds to the value of maxlength facet in schema)
193: *
194: * @param maxLength
195: */
196: public void addMaxLength(int maxLength) {
197: if (maxLengths == null) {
198: maxLengths = new ArrayList<Integer>(1);
199: hasFacets = true;
200: }
201: this .maxLengths.add(new Integer(maxLength));
202: }
203:
204: /*
205: * set pattern value (this corresponds to the value of pattern facet in schema)
206: *
207: * @param pattern
208: */
209: public void addPattern(String pattern) {
210: if (patterns == null) {
211: patterns = new ArrayList<String>(1);
212: hasFacets = true;
213: }
214: this .patterns.add(pattern);
215: }
216:
217: /*
218: * returns enumeration values (this corresponds to the values of enumeration facets in schema)
219: *
220: * @param enumeration
221: */
222: public void addEnumeration(String enumeration) {
223: if (enumerations == null) {
224: enumerations = new ArrayList<String>(1);
225: hasFacets = true;
226: }
227: this .enumerations.add(enumeration);
228: }
229:
230: /*
231: * set whitespace value (this corresponds to the value of whitespace facet in schema)
232: *
233: * @param whitespace
234: */
235: public void addWhitespace(Whitespace.Treatment whitespace) {
236: if (whitespaces == null) {
237: whitespaces = new ArrayList<Whitespace.Treatment>(1);
238: hasFacets = true;
239: }
240: this .whitespaces.add(whitespace);
241: }
242:
243: /*
244: * remove length (this corresponds to the value of length facet in schema)
245: *
246: * @param length
247: */
248: public void removeLength(Number length) {
249: if (lengths != null)
250: lengths.remove(length);
251: }
252:
253: /*
254: * remove minimum length value (this corresponds to the value of minlength facet in schema)
255: *
256: * @param minLength
257: */
258: public void removeMinLength(Number minLength) {
259: if (minLengths != null)
260: minLengths.remove(minLength);
261: }
262:
263: /*
264: * set maximum length value (this corresponds to the value of maxlength facet in schema)
265: *
266: * @param maxLength
267: */
268: public void removeMaxLength(Number maxLength) {
269: if (maxLengths != null)
270: maxLengths.remove(maxLength);
271: }
272:
273: /*
274: * set pattern value (this corresponds to the value of pattern facet in schema)
275: *
276: * @param pattern
277: */
278: public void removePattern(String pattern) {
279: if (patterns != null)
280: patterns.remove(pattern);
281: }
282:
283: /*
284: * remove enumeration values (this corresponds to the values of enumeration facets in schema)
285: *
286: * @param enumeration
287: */
288: public void removeEnumeration(String enumeration) {
289: if (enumerations != null)
290: enumerations.remove(enumeration);
291: }
292:
293: /*
294: * set whitespace value (this corresponds to the value of whitespace facet in schema)
295: *
296: * @param whitespace
297: */
298: public void removeWhitespace(Whitespace.Treatment whitespace) {
299: if (whitespaces != null)
300: whitespaces.remove(whitespace);
301: }
302: }
|