From: Erik V. <ev...@us...> - 2009-10-30 22:44:37
|
Update of /cvsroot/rails/18xx/rails/util In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv11565/rails/util Modified Files: Tag.java Log Message: More rationalising of static method usage Index: Tag.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/util/Tag.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Tag.java 30 Aug 2009 18:13:48 -0000 1.10 --- Tag.java 30 Oct 2009 21:53:04 -0000 1.11 *************** *** 11,15 **** import org.xml.sax.SAXException; ! import rails.game.*; /** --- 11,16 ---- import org.xml.sax.SAXException; ! import rails.game.ConfigurationException; ! import rails.game.GameOption; /** *************** *** 31,34 **** --- 32,38 ---- private boolean parsing = false; + /** A reference to the current game chosen options */ + private Map<String, String> gameOptions = null; + protected static Logger log = Logger.getLogger(Tag.class.getPackage().getName()); *************** *** 38,41 **** --- 42,54 ---- } + public Tag (Element element, Map<String, String> gameOptions) { + this (element); + this.gameOptions = gameOptions; + } + + public void setGameOptions (Map<String, String> gameOptions) { + this.gameOptions = gameOptions; + } + public Map<String, List<Tag>> getChildren() throws ConfigurationException { *************** *** 79,85 **** } } ! public boolean hasChild (String tagName) throws ConfigurationException { ! return getChildren ("AllowsMultipleBasesOfOneCompany") != null; } --- 92,98 ---- } } ! public boolean hasChild (String tagName) throws ConfigurationException { ! return getChildren ("AllowsMultipleBasesOfOneCompany") != null; } *************** *** 140,144 **** if (!parsed) parse(element); ! String value = attributes.get(name); if (value == null) return defaultValue; --- 153,157 ---- if (!parsed) parse(element); ! String value = attributes.get(name); if (value == null) return defaultValue; *************** *** 279,291 **** // Check if the option has been chosen; if not, skip the // rest ! String optionValue = Game.getGameOption(name); if (optionValue == null) { ! // throw new ConfigurationException ("GameOption ! // "+name+"="+value+" but no assigned value found"); ! log.warn("GameOption " + name + "=" + value + " but no assigned value found"); // Take the default value ! optionValue = GameOption.getByName(name).getDefaultValue(); } if (optionValue.equalsIgnoreCase(value)) { --- 292,308 ---- // Check if the option has been chosen; if not, skip the // rest ! if (gameOptions == null) { ! throw new ConfigurationException ( ! "No GameOptions available in tag "+element.getNodeName()); ! } ! ! String optionValue = gameOptions.get(name); if (optionValue == null) { ! log.warn("GameOption " + name + "=" + value + " but no assigned value found"); // Take the default value ! optionValue = GameOption.getByName(name).getDefaultValue(); + } if (optionValue.equalsIgnoreCase(value)) { *************** *** 296,300 **** children.put(childTagName, new ArrayList<Tag>()); } ! children.get(childTagName).add(new Tag(childElement)); } } else if (childNode.getNodeType() == Node.TEXT_NODE) { --- 313,317 ---- children.put(childTagName, new ArrayList<Tag>()); } ! children.get(childTagName).add(new Tag(childElement, gameOptions)); } } else if (childNode.getNodeType() == Node.TEXT_NODE) { |