Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option In directory sc8-pr-cvs1:/tmp/cvs-serv651/core/src/com/babeldoc/core/option Modified Files: ConfigData.java ConfigInfo.java ConfigOption.java IConfigInfo.java Added Files: ConfigurationException.java MutableConfigValueException.java Log Message: Config options can now validate and check the mutability flag for setting the value. GUI components now catch the Mutable Exception. --- NEW FILE: ConfigurationException.java --- package com.babeldoc.core.option; /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. * ==================================================================== * * Babeldoc: The Universal Document Processor * * $Header: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/ConfigurationException.java,v 1.1 2003/08/13 22:53:26 triphop Exp $ * $DateTime$ * $Author: triphop $ * */ import com.babeldoc.core.GeneralException; /** * Thrown if a configuration option problem is encountered. * * @author Bmcdonald * @version 1.0 */ public class ConfigurationException extends GeneralException { /** * Constructor * * @param message associated message * @param e nexted exception */ public ConfigurationException(String message, Throwable e) { super(message, e); } /** * Constructor. This is the fatal constructor. * * @param message associated message */ public ConfigurationException(String message) { super(message); } /** * Constructor. This is the fatal constructor. */ public ConfigurationException() { super(); } } --- NEW FILE: MutableConfigValueException.java --- /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. * ==================================================================== * * Babeldoc: The Universal Document Processor * * $Header: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/MutableConfigValueException.java,v 1.1 2003/08/13 22:53:26 triphop Exp $ * $DateTime$ * $Author: triphop $ * */ package com.babeldoc.core.option; import com.babeldoc.core.GeneralException; /** * Thrown if a configuration option is being set that is not mutable.. * * @author Bmcdonald * @version 1.0 */ public class MutableConfigValueException extends ConfigurationException { /** * Constructor * * @param message associated message * @param e nexted exception */ public MutableConfigValueException(String message, Throwable e) { super(message, e); } /** * Constructor. This is the fatal constructor. * * @param message associated message */ public MutableConfigValueException(String message) { super(message); } /** * Constructor. This is the fatal constructor. */ public MutableConfigValueException() { super(); } } Index: ConfigData.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/ConfigData.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ConfigData.java 12 Aug 2003 23:44:43 -0000 1.1 --- ConfigData.java 13 Aug 2003 22:53:26 -0000 1.2 *************** *** 242,247 **** */ public String toString() { ! return new ToStringBuilder(this).append("children", children). ! append("value", value).toString(); } --- 242,248 ---- */ public String toString() { ! return new ToStringBuilder(this).append("name", getName()). ! append("value", value). ! append("children", children).toString(); } Index: ConfigInfo.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/ConfigInfo.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ConfigInfo.java 12 Aug 2003 23:44:43 -0000 1.7 --- ConfigInfo.java 13 Aug 2003 22:53:26 -0000 1.8 *************** *** 163,166 **** --- 163,181 ---- /** + * Get the validity of the configuration information and the data set on it. + * + * @return + */ + public boolean isValid() { + for (Iterator iterator = getOptions().iterator(); iterator.hasNext();) { + ConfigOption configOption = (ConfigOption) iterator.next(); + if(!configOption.isValid()) { + return false; + } + } + return true; + } + + /** * search down a path of config option names until option name is found and * return it. *************** *** 284,288 **** */ private void applyConfigValue(IConfigData data, ConfigOption configoption) { ! configoption.setValue(data.getValue()); if (data.getNumberChildren() > 0) { --- 299,303 ---- */ private void applyConfigValue(IConfigData data, ConfigOption configoption) { ! configoption.protectedSetValue(data.getValue()); if (data.getNumberChildren() > 0) { Index: ConfigOption.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/ConfigOption.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ConfigOption.java 27 Jun 2003 02:19:58 -0000 1.11 --- ConfigOption.java 13 Aug 2003 22:53:26 -0000 1.12 *************** *** 72,77 **** /** ! * This class represents single config option. It is used for gui ! * configuration. * * @author bmcdonald --- 72,76 ---- /** ! * This class represents single config option. It is used thoughout babeldoc. * * @author bmcdonald *************** *** 339,351 **** /** ! * Set the value of the configuration option * * @param value */ ! public void setValue(Object value) { this.value = value; } /** * Get the value for this configuration option. <strong>this method will * return the default value if the value is not set</strong> --- 338,363 ---- /** ! * Set the value of the configuration option - this method has package security ! * and bypasses the checking of the mutability setting. * * @param value */ ! void protectedSetValue(Object value) { this.value = value; } /** + * Set a value + * + * @param value + * @throws MutableConfigValueException if value is not mutable. + */ + public void setValue(Object value) throws MutableConfigValueException { + if(!this.isMutable()) { + throw new MutableConfigValueException("Cant change this value"); + } + } + + /** * Get the value for this configuration option. <strong>this method will * return the default value if the value is not set</strong> *************** *** 360,363 **** --- 372,401 ---- } } + + /** + * Is this value valid? This depends on the type of the option. Check through + * all of the suboptions looking for validity. + * + * @return + */ + public boolean isValid() { + if(suboptions!=null) { + for (Iterator iterator = suboptions.keySet().iterator(); iterator.hasNext();) { + String name = (String) iterator.next(); + ConfigOption subOption = getSuboption(name); + if(!subOption.isValid()) { + return false; + } + } + } + + Object val = getValue(); + if(val==null&&isMandatory()) { + return false; + } else { + return this.getType().isValid(this.getValue()); + } + } + /** Index: IConfigInfo.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/IConfigInfo.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** IConfigInfo.java 12 Aug 2003 23:44:43 -0000 1.5 --- IConfigInfo.java 13 Aug 2003 22:53:26 -0000 1.6 *************** *** 135,137 **** --- 135,144 ---- */ public void applyConfigData(IConfigData data); + + /** + * Get the validity of the configuration information and the data set on it. + * + * @return + */ + boolean isValid(); } |