1 /** 2 * Redistribution and use of this software and associated documentation 3 * ("Software"), with or without modification, are permitted provided 4 * that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain copyright 7 * statements and notices. Redistributions must also contain a 8 * copy of this document. 9 * 10 * 2. Redistributions in binary form must reproduce the 11 * above copyright notice, this list of conditions and the 12 * following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 14 * 15 * 3. The name "Exolab" must not be used to endorse or promote 16 * products derived from this Software without prior written 17 * permission of Intalio, Inc. For written permission, 18 * please contact info@exolab.org. 19 * 20 * 4. Products derived from this Software may not be called "Exolab" 21 * nor may "Exolab" appear in their names without prior written 22 * permission of Intalio, Inc. Exolab is a registered 23 * trademark of Intalio, Inc. 24 * 25 * 5. Due credit should be given to the Exolab Project 26 * (http://www.exolab.org/). 27 * 28 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 39 * OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Copyright 1999-2000 (C) Intalio, Inc. All Rights Reserved. 42 * 43 * $Id$ 44 */ 45 46 package org.exolab.castor.xml.schema; 47 48 49 import java.util.StringTokenizer; 50 51 /** 52 * A class to represent the values of the XML Schema block property 53 * 54 * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a> 55 * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ 56 **/ 57 public final class FinalList { 58 59 /** 60 * The #all value 61 **/ 62 public static final String ALL = "#all"; 63 64 /** 65 * The extension value 66 **/ 67 public static final String EXTENSION = "extension"; 68 69 /** 70 * The restriction value 71 **/ 72 public static final String RESTRICTION = "restriction"; 73 74 75 private boolean _all = false; 76 77 /** 78 * Flag for blocking extensions 79 **/ 80 private boolean _extension = false; 81 82 /** 83 * Flag for blocking restrictions 84 **/ 85 private boolean _restriction = false; 86 87 /** 88 * Creates a new default FinalList. Nothing is flagged 89 * as being final. 90 **/ 91 public FinalList() { 92 super(); 93 } //-- FinalList 94 95 /** 96 * Creates a new FinalList using the given list of values. 97 * 98 * @param listOfValues the list of final values 99 * @exception IllegalArgumentException if the list of values contains 100 * something other than "#all", "extension", "restriction". 101 **/ 102 public FinalList(String listOfValues) { 103 104 super(); 105 106 if (listOfValues != null) { 107 parseValues(listOfValues); 108 } 109 110 } //-- FinalList 111 112 /** 113 * Returns true if the FinalList contains "#all". 114 * 115 * @return true if the FinalList contains "#all". 116 **/ 117 public boolean hasAll() { 118 return _all; 119 } //-- hasAll 120 121 /** 122 * Returns true if extension is contained within this FinalList. 123 * 124 * @return true if extension is contained within this FinalList. 125 **/ 126 public boolean hasExtension() { 127 return _extension; 128 } //-- hasExtension 129 130 /** 131 * Returns true if restriction is contained within this FinalList. 132 * 133 * @return true if restriction is contained within this FinalList. 134 **/ 135 public boolean hasRestriction() { 136 return _restriction; 137 } //-- hasRestriction 138 139 /** 140 * Returns the String representation of this FinalList. 141 * 142 * @return the String representation of this FinalList. 143 **/ 144 public String toString() { 145 if (_all) return ALL; 146 147 StringBuffer value = new StringBuffer(); 148 if (_extension) { 149 value.append(EXTENSION); 150 } 151 if (_restriction) { 152 if (value.length() > 0) { 153 value.append(' '); 154 } 155 value.append(RESTRICTION); 156 } 157 return value.toString(); 158 } //-- toString 159 160 //-------------------/ 161 //- Private Methods -/ 162 //-------------------/ 163 164 /** 165 * Parses the given values and sets the appropriate flags for this 166 * FinalList. 167 * 168 * @param values the list of Final values. 169 **/ 170 private void parseValues(String values) { 171 172 if (ALL.equals(values)) { 173 _all = true; 174 return; 175 } 176 177 StringTokenizer tokenizer = new StringTokenizer(values); 178 179 while (tokenizer.hasMoreTokens()) { 180 String value = tokenizer.nextToken(); 181 182 if (EXTENSION.equals(value)) { 183 _extension = true; 184 } 185 else if (RESTRICTION.equals(value)) { 186 _restriction = true; 187 } 188 else { 189 String err = "invalid final list: " + values; 190 throw new IllegalArgumentException(err); 191 } 192 } 193 194 } //-- parseValues 195 196 } //-- class: FinalList