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 BlockList { 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 * The substitution value 76 **/ 77 public static final String SUBSTITUTION = "substitution"; 78 79 private boolean _all = false; 80 81 /** 82 * Flag for blocking extensions 83 **/ 84 private boolean _extension = false; 85 86 /** 87 * Flag for blocking restrictions 88 **/ 89 private boolean _restriction = false; 90 91 /** 92 * Flag for blocking substitutions 93 **/ 94 private boolean _substitution = false; 95 96 /** 97 * Creates a new default BlockList. Nothing is flagged 98 * as being blocked. 99 **/ 100 public BlockList() { 101 super(); 102 } //-- BlockList 103 104 /** 105 * Creates a new BlockList using the given list of values. 106 * 107 * @param listOfValues the list of block values 108 * @exception IllegalArgumentException if the list of values contains 109 * something other than "extension", "restriction", or "substition". 110 **/ 111 public BlockList(String listOfValues) { 112 113 super(); 114 115 if (listOfValues != null) { 116 parseValues(listOfValues); 117 } 118 119 } //-- listOfValues. 120 121 /** 122 * Returns true if the BlockList contains "#all". 123 * 124 * @return true if the BlockList contains "#all". 125 **/ 126 public boolean hasAll() { 127 return _all; 128 } //-- hasAll 129 130 /** 131 * Returns true if extension is contained within this BlockList. 132 * 133 * @return true if extension is contained within this BlockList. 134 **/ 135 public boolean hasExtension() { 136 return _extension; 137 } //-- hasExtension 138 139 /** 140 * Returns true if restriction is contained within this BlockList. 141 * 142 * @return true if restriction is contained within this BlockList 143 **/ 144 public boolean hasRestriction() { 145 return _restriction; 146 } //-- hasRestriction 147 148 /** 149 * Returns true if substitution is contained within this BlockList. 150 * 151 * @return true if substitution is contained within this BlockList. 152 **/ 153 public boolean hasSubstitution() { 154 return _substitution; 155 } //-- hasSubstitution 156 157 /** 158 * Returns the String representation of this BlockList 159 **/ 160 public String toString() { 161 if (_all) { 162 return ALL; 163 } 164 StringBuffer value = new StringBuffer(); 165 if (_extension) { 166 value.append(EXTENSION); 167 } 168 if (_restriction) { 169 if (value.length() > 0) { 170 value.append(' '); 171 } 172 value.append(RESTRICTION); 173 } 174 if (_substitution) { 175 if (value.length() > 0) { 176 value.append(' '); 177 } 178 value.append(RESTRICTION); 179 } 180 return value.toString(); 181 } //-- toString 182 183 //-------------------/ 184 //- Private Methods -/ 185 //-------------------/ 186 187 /** 188 * Parses the given values and sets the appropriate flags for this 189 * BlockList. 190 * 191 * @param values the list of Block values. 192 **/ 193 private void parseValues(String values) { 194 195 if (ALL.equals(values)) { 196 _all = true; 197 return; 198 } 199 200 StringTokenizer tokenizer = new StringTokenizer(values); 201 202 while (tokenizer.hasMoreTokens()) { 203 String value = tokenizer.nextToken(); 204 205 if (EXTENSION.equals(value)) { 206 _extension = true; 207 } 208 else if (RESTRICTION.equals(value)) { 209 _restriction = true; 210 } 211 else if (SUBSTITUTION.equals(value)) { 212 _substitution = true; 213 } 214 else { 215 String err = "invalid block list: " + values; 216 throw new IllegalArgumentException(err); 217 } 218 } 219 220 } //-- parseValues 221 222 } //-- class: BlockList