Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option In directory sc8-pr-cvs1:/tmp/cvs-serv25799/src/com/babeldoc/core/option Modified Files: ConfigData.java ConfigInfo.java ConfigOption.java IConfigData.java IConfigInfo.java Added Files: IConfigDataContainer.java Log Message: Updates and rationalization for the gui --- NEW FILE: IConfigDataContainer.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/IConfigDataContainer.java,v 1.1 2003/09/13 03:33:43 triphop Exp $ * $DateTime$ * $Author: triphop $ * */ package com.babeldoc.core.option; /** * Interface to classes that manage configuration data objects * * @author bmcdonald * @version 1.1 */ public interface IConfigDataContainer { /** * @return get the configuration data */ public IConfigData getConfigData(); /** * Set the configuration data for this object * * @param configData the configuration data */ public void setConfigData(IConfigData configData); } Index: ConfigData.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/ConfigData.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ConfigData.java 15 Aug 2003 00:25:29 -0000 1.3 --- ConfigData.java 13 Sep 2003 03:33:42 -0000 1.4 *************** *** 232,240 **** children = new HashMap(); } ! this.children.put(configData.getName(), configData); } /** * Convert to a string * --- 232,252 ---- children = new HashMap(); } ! // System.out.println(this.getName()+" adding child: "+configData.getName()+" = "+configData.getValue()); this.children.put(configData.getName(), configData); } /** + * remove the named child from the list of children of this + * configuation data object + * + * @param configData child to remove + */ + public void removeChild(IConfigData configData) { + if(configData!=null) { + this.children.remove(configData.getName()); + } + } + + /** * Convert to a string * *************** *** 347,350 **** --- 359,414 ---- } return data; + } + + + /** + * Extract the configuration data from the data object and place in the config + * object ready to be persisted. + * + * @param config + * @param data + * @return filled config object + */ + public static IConfig getConfigFromData(IConfig config, IConfigData data) { + Stack names = new Stack(); + getConfigFromData(data.getName(), config, data, names); + + return config; + } + + /** + * Extract the configuration data from the data object and place in the config + * object ready to be persisted. + * + * @param stageName the name of the stage + * @param config the configuration data to fill + * @param data the configuration data object + */ + protected static void getConfigFromData(String stageName, IConfig config, IConfigData data, Stack names) { + if(data.getNumberChildren()>0) { + Set children = data.getChildrenNameSet(); + for (Iterator iterator = children.iterator(); iterator.hasNext();) { + String s = (String) iterator.next(); + IConfigData child = data.getChild(s); + names.add(child.getName()); + getConfigFromData(stageName, config, child, names); + } + } else { + System.out.println("Data: "+data); + StringBuffer sb = new StringBuffer(stageName+"."); + for (Iterator iterator = names.iterator(); iterator.hasNext();) { + String s = (String) iterator.next(); + sb.append(s); + if(iterator.hasNext()) { + sb.append("."); + } + } + String key = sb.toString(); + String value = (data.getValue()==null)?" ":data.getValue(); + + System.out.println("Key found: "+key+" = "+value); + config.setString(key, value); + names.clear(); + } } Index: ConfigInfo.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/ConfigInfo.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ConfigInfo.java 12 Sep 2003 00:54:04 -0000 1.12 --- ConfigInfo.java 13 Sep 2003 03:33:43 -0000 1.13 *************** *** 72,75 **** --- 72,77 ---- import org.apache.commons.lang.NumberUtils; + import org.apache.commons.lang.builder.ToStringBuilder; + import org.apache.commons.collections.SequencedHashMap; *************** *** 135,138 **** --- 137,141 ---- public ConfigOption getOption(String optionName) { if (options == null) { + // System.out.println("Making the options"); getOptions(); } *************** *** 237,252 **** */ public int getIntValue(String path) { ! return NumberUtils.stringToInt((String)getValue(path), 0); } /** ! * Get the option value in the path of options as a boolean true/false. The path is ! * specificed like a file path: /option/suboption/etc * ! * @param path ! * @return value */ public boolean getBooleanValue(String path) { ! return "true".equalsIgnoreCase(getStrValue(path)); } --- 240,255 ---- */ public int getIntValue(String path) { ! return NumberUtils.stringToInt(getStrValue(path), 0); } /** ! * Get the option value for the configuration data object poitned ! * as by the path * ! * @param path to the object of interest ! * @return */ public boolean getBooleanValue(String path) { ! return Boolean.valueOf(getStrValue(path)).booleanValue(); } *************** *** 284,288 **** if (options == null) { //put general component options ! options = new HashMap(); Collection generalOptions = getGeneralOptions(); --- 287,294 ---- if (options == null) { //put general component options ! // Please note that if a Sequenced hash map is not used, ! // then the gui utilites fail because they expect the ! // options sorted in the order they are added. ! options = new SequencedHashMap(); Collection generalOptions = getGeneralOptions(); *************** *** 319,328 **** /** ! * Add an option to the list options. * * @param option */ public void addOption(ConfigOption option) { options.put(option.getName(), option); } --- 325,340 ---- /** ! * Add an option to the list options. Also links the parent data container ! * up and down links. * * @param option */ public void addOption(ConfigOption option) { + // System.out.println("Adding option: "+option.getName()); options.put(option.getName(), option); + + // Now link up the configuration data + option.setParentDataContainer(this); // Do this first + getConfigData().addChild(option.getConfigData()); // This relies on parent having been set } *************** *** 337,349 **** /** ! * Return String representation of ConfigInfo object * ! * @return DOCUMENT ME! */ public String toString() { ! return "Description=" + this.getDescription() + "\nOptions:" + ! this.getOptions(); } /** * Initialize the options. --- 349,364 ---- /** ! * Convert to a string * ! * @return */ public String toString() { ! return new ToStringBuilder(this).append("name", getName()). ! append("description", getDescription()). ! append("options", getOptions()). ! append("data", getConfigData()).toString(); } + /** * Initialize the options. *************** *** 359,375 **** */ public void applyConfigData(IConfigData data) { this.setConfigData(data); for (Iterator iterator = data.getChildrenNameSet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); ! IConfigData option = data.getChild(key); ConfigOption configoption = this.getOption(key); // If the options are not found for this data, create an option. if (configoption == null) { ! configoption = createDynamicOption(option, key); this.addOption(configoption); } ! applyConfigValue(option, configoption); } } --- 374,395 ---- */ public void applyConfigData(IConfigData data) { + + // Get the options first this needs to be done right here + // because this DOES interfere with the data applications + this.getOptions(); + this.setConfigData(data); for (Iterator iterator = data.getChildrenNameSet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); ! IConfigData child = data.getChild(key); ConfigOption configoption = this.getOption(key); // If the options are not found for this data, create an option. if (configoption == null) { ! configoption = createDynamicOption(data, key); this.addOption(configoption); } ! applyConfigValue(child, configoption); } } *************** *** 433,441 **** /** ! * Get the configuration data that has been set on this object * * @return */ ! protected IConfigData getConfigData() { return configData; } --- 453,466 ---- /** ! * Get the configuration data that has been set on this object. If nothing set, ! * then a configuration data object is created. * * @return */ ! public IConfigData getConfigData() { ! if(configData==null) { ! // System.out.println("Creating new config data"); ! configData = new ConfigData(this.getName()); ! } return configData; } *************** *** 446,451 **** * @param configData */ ! protected void setConfigData(IConfigData configData) { this.configData = configData; } } --- 471,492 ---- * @param configData */ ! public void setConfigData(IConfigData configData) { this.configData = configData; + } + + /** + * Set the name (actually on the configuration data object) + * + * @param name + */ + public void setName(String name) { + this.getConfigData().setName(name); + } + + /** + * @return get the name from the configuration data object + */ + public String getName() { + return this.getConfigData().getName(); } } Index: ConfigOption.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/ConfigOption.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ConfigOption.java 29 Aug 2003 01:19:06 -0000 1.14 --- ConfigOption.java 13 Sep 2003 03:33:43 -0000 1.15 *************** *** 66,69 **** --- 66,71 ---- package com.babeldoc.core.option; + import com.babeldoc.core.Named; + import java.io.Serializable; *************** *** 73,94 **** /** * This class represents single config option. It is used thoughout babeldoc. A configuration ! * option is linked to a configuration data object. The option has a default value, a type, and a * number of other attributes. It also may contain a number of suboptions. * * @author bmcdonald * @version 1.0 */ ! public class ConfigOption implements Serializable { ! private ArrayList dependentOn; ! private ArrayList exclusiveTo; private IConfigOptionType type; private Map suboptions; ! private IConfigData data; private String defaultValue; private String description; ! private String name; private boolean mandatory; private boolean mutable; /** * Construct a config option object --- 75,122 ---- /** * This class represents single config option. It is used thoughout babeldoc. A configuration ! * option is linked to a configuration configData object. The option has a default value, a type, and a * number of other attributes. It also may contain a number of suboptions. * + * The underlying storage of the value of the configuration option is in + * the configuration data object. This object is stored analogously to the + * option as a tree of objects. + * * @author bmcdonald * @version 1.0 */ ! public class ConfigOption ! extends Named ! implements Serializable, IConfigDataContainer { ! ! /** Array of options that this option depends on */ ! private Collection dependentOn; ! ! /** Options that this option is exclusive to */ ! private Collection exclusiveTo; ! ! /** The type of this option */ private IConfigOptionType type; + + /** The suboptions of this option */ private Map suboptions; ! ! /** The configuration data */ ! private IConfigData configData; ! ! /** The default value */ private String defaultValue; + + /** The description of this option */ private String description; ! ! /** Is this a required options */ private boolean mandatory; + + /** Can this option be changed */ private boolean mutable; + /** The containing object - can be another option or a IConfigInfo */ + private IConfigDataContainer parentDataContainer; + /** * Construct a config option object *************** *** 102,106 **** public ConfigOption(String name, IConfigOptionType type, String defaultValue, boolean mandatory, String description) { ! this.name = name; this.type = type; this.defaultValue = defaultValue; --- 130,134 ---- public ConfigOption(String name, IConfigOptionType type, String defaultValue, boolean mandatory, String description) { ! super(name); this.type = type; this.defaultValue = defaultValue; *************** *** 122,126 **** */ public ConfigOption(String name, IConfigOptionType type, String description) { ! this.name = name; this.type = type; this.description = description; --- 150,154 ---- */ public ConfigOption(String name, IConfigOptionType type, String description) { ! super(name); this.type = type; this.description = description; *************** *** 135,141 **** /** ! * TODO: DOCUMENT ME! ! * ! * @return DOCUMENT ME! */ public boolean isComplex() { --- 163,167 ---- /** ! * @return Value of the complex flag */ public boolean isComplex() { *************** *** 186,190 **** * @return Options that this option must have */ ! public ArrayList getDependentOn() { return dependentOn; } --- 212,216 ---- * @return Options that this option must have */ ! public Collection getDependentOn() { return dependentOn; } *************** *** 222,226 **** * @return comments */ ! public ArrayList getExclusiveTo() { return exclusiveTo; } --- 248,252 ---- * @return comments */ ! public Collection getExclusiveTo() { return exclusiveTo; } *************** *** 263,284 **** /** - * Set the name - * - * @param newName - */ - public void setName(String newName) { - name = newName; - } - - /** - * Get the name - * - * @return - */ - public String getName() { - return name; - } - - /** * Get the number of suboptions in this config option * --- 289,292 ---- *************** *** 286,293 **** */ public int getNumberSuboptions() { ! if (suboptions == null) { return 0; } else { ! return suboptions.size(); } } --- 294,301 ---- */ public int getNumberSuboptions() { ! if (getSuboptions() == null) { return 0; } else { ! return getSuboptions().size(); } } *************** *** 301,308 **** */ public ConfigOption getSuboption(String name) { ! if (suboptions == null) { return null; } else { ! return (ConfigOption) suboptions.get(name); } } --- 309,316 ---- */ public ConfigOption getSuboption(String name) { ! if (getSuboptions() == null) { return null; } else { ! return (ConfigOption) getSuboptions().get(name); } } *************** *** 314,321 **** */ public Set getSuboptionNames() { ! if (suboptions == null) { return null; } else { ! return suboptions.keySet(); } } --- 322,329 ---- */ public Set getSuboptionNames() { ! if (getSuboptions() == null) { return null; } else { ! return getSuboptions().keySet(); } } *************** *** 340,344 **** /** ! * Apply the configuration data to this configuration information * object. This is package private - should only really be called * from the applyConfigData method. --- 348,352 ---- /** ! * Apply the configuration configData to this configuration information * object. This is package private - should only really be called * from the applyConfigData method. *************** *** 346,351 **** * @param data */ ! void setConfigData(IConfigData data) { ! this.data = data; } --- 354,360 ---- * @param data */ ! public void setConfigData(IConfigData data) { ! // System.out.println("Setting: "+getName()+" = "+data.getValue()); ! this.configData = data; } *************** *** 357,363 **** */ protected void protectedSetValue(Object value) { ! if(data!=null) { ! this.data.setValue(value.toString()); ! } } --- 366,370 ---- */ protected void protectedSetValue(Object value) { ! this.getConfigData().setValue(value.toString()); } *************** *** 373,376 **** --- 380,384 ---- throw new MutableConfigValueException("Cant change this value"); } else { + // System.out.println("Setting: "+getName()+" to value: "+value); protectedSetValue(value); } *************** *** 384,392 **** */ public Object getValue() { ! if (data != null) { ! return data.getValue(); ! } else { ! return getDefaultValue(); ! } } --- 392,396 ---- */ public Object getValue() { ! return getConfigData().getValue(); } *************** *** 398,403 **** */ public boolean isValid() { ! if(suboptions!=null) { ! for (Iterator iterator = suboptions.keySet().iterator(); iterator.hasNext();) { String name = (String) iterator.next(); ConfigOption subOption = getSuboption(name); --- 402,407 ---- */ public boolean isValid() { ! if(getSuboptions()!=null) { ! for (Iterator iterator = getSuboptions().keySet().iterator(); iterator.hasNext();) { String name = (String) iterator.next(); ConfigOption subOption = getSuboption(name); *************** *** 418,442 **** /** ! * Add a suboption to this option. * * @param suboption */ public void addSuboption(ConfigOption suboption) { ! if (suboptions == null) { suboptions = new HashMap(); } ! // System.out.println(getName()+" just had suboption added: "+suboption.getName()); ! suboptions.put(suboption.getName(), suboption); } /** ! * Remove the named option from the suboptions * * @param name */ public void removeSuboption(String name) { ! if (suboptions != null) { ! suboptions.remove(name); } } --- 422,454 ---- /** ! * Add a suboption to this option. This also connects the configuration data ! * objects together so that the parent child relationshipt is also maintained ! * in that structure. * * @param suboption */ public void addSuboption(ConfigOption suboption) { ! if (getSuboptions() == null) { suboptions = new HashMap(); } ! // Add to the collection ! getSuboptions().put(suboption.getName(), suboption); ! ! // Now connect the IConfigData objects together ! suboption.setParentDataContainer(this); // Do this first ! getConfigData().addChild(suboption.getConfigData()); // This relies on parent set } /** ! * Remove the named option from the suboptions and remove the configuration ! * data linkage too. * * @param name */ public void removeSuboption(String name) { ! if (getSuboptions() != null) { ! getConfigData().removeChild(getSuboption(name).getConfigData()); ! getSuboptions().remove(name); } } *************** *** 459,465 **** } ! return "Option='" + name + "' type='" + type + "' Description='" + description + "' Default value='" + defaultValue + "' Allowed Values=" + allowed+" value='"+getValue()+"'"; } } --- 471,521 ---- } ! return "Option='" + getName() + "' type='" + type + "' Description='" + description + "' Default value='" + defaultValue + "' Allowed Values=" + allowed+" value='"+getValue()+"'"; + } + + + /** + * Get the configuration data for this configuration option. if the + * configdata does not exists, create it and then set the value of the configuratio + * to the default. + * + * @return + */ + public IConfigData getConfigData() { + if(configData==null) { + // System.out.println("Config data is null, setting"); + configData = new ConfigData(this.getName()); + getParentDataContainer().getConfigData().addChild(configData); + configData.setValue(this.defaultValue); + } + + return configData; + } + + /** + * @return get the suboptions + */ + protected Map getSuboptions() { + return suboptions; + } + + /** + * Parent data container + * + * @return + */ + public IConfigDataContainer getParentDataContainer() { + return parentDataContainer; + } + + /** + * parent data container + * + * @param parentDataContainer + */ + public void setParentDataContainer(IConfigDataContainer parentDataContainer) { + this.parentDataContainer = parentDataContainer; } } Index: IConfigData.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/IConfigData.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IConfigData.java 12 Aug 2003 23:44:43 -0000 1.1 --- IConfigData.java 13 Sep 2003 03:33:43 -0000 1.2 *************** *** 127,130 **** --- 127,137 ---- /** + * remove the named child from the list of children of this + * configuation data object + * + * @param configData child to remove + */ + void removeChild(IConfigData configData); + /** * Get the value of the child object * Index: IConfigInfo.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/option/IConfigInfo.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** IConfigInfo.java 12 Sep 2003 00:59:15 -0000 1.8 --- IConfigInfo.java 13 Sep 2003 03:33:43 -0000 1.9 *************** *** 66,69 **** --- 66,71 ---- package com.babeldoc.core.option; + import com.babeldoc.core.INamed; + import java.io.Serializable; *************** *** 78,82 **** */ public interface IConfigInfo ! extends Serializable { /** * Return description of this worker --- 80,84 ---- */ public interface IConfigInfo ! extends Serializable, IConfigDataContainer, INamed { /** * Return description of this worker *************** *** 173,181 **** /** ! * Get the option value in the path of options as a boolean true/false. The path is ! * specificed like a file path: /option/suboption/etc * ! * @param path ! * @return value */ public boolean getBooleanValue(String path); --- 175,183 ---- /** ! * Get the option value for the configuration data object poitned ! * as by the path * ! * @param path to the object of interest ! * @return */ public boolean getBooleanValue(String path); |