View Javadoc
1 /* 2 * IncludeCfgImpl.java 3 * Created on September 19, 2003 4 * 5 * The Blues Framework - A lightweight application framework 6 * Copyright (C) 2003 Lonnie Pryor 7 * http://blues.lonniepryor.com 8 * 9 * This library is free software; you can redistribute it and/or modify it under the 10 * terms of the GNU Lesser General Public License as published by the Free Software 11 * Foundation; either version 2.1 of the License, or (at your option) any later 12 * version. 13 * 14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY 15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 16 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License along 19 * with this library; if not, write to: 20 * 21 * The Free Software Foundation, Inc. 22 * 59 Temple Place, Suite 330 23 * Boston, MA 02111-1307 USA 24 * 25 */ 26 package com.lonniepryor.blues.cfg; 27 28 import java.util.HashMap; 29 import java.util.Map; 30 31 /*** 32 * Generic implementation of {@link IncludeCfg}. 33 * 34 * @author Lonnie Pryor 35 * @version $Revision: 1.1 $ 36 */ 37 public class IncludeCfgImpl implements IncludeCfg, Verifiable { 38 /*** The name given to the module to include. */ 39 private String name = null; 40 /*** The path to the module configuration. */ 41 private String modulePath = null; 42 /*** The included module. */ 43 private ModuleCfg module = null; 44 /*** The variable refrences set on the included module. */ 45 private final Map variableRefrences = new HashMap(); 46 47 /*** 48 * Creates a new IncludeCfgImpl object. 49 */ 50 public IncludeCfgImpl () { 51 } 52 53 /*** 54 * Sets the name given to the module to include. 55 * 56 * @param name The name given to the module to include. 57 */ 58 public void setName (String name) { 59 this.name = name; 60 } 61 62 /*** 63 * Sets the path to the module configuration. 64 * 65 * @param modulePath The path to the module configuration. 66 */ 67 public void setPath (String modulePath) { 68 this.modulePath = modulePath; 69 } 70 71 /*** 72 * Declares a variable name/refrence pair on this include. 73 * 74 * @param variable The variable configuration. 75 */ 76 public void declareSetVariable (SetVariableCfg variable) { 77 if (variable == null) 78 throw new NullPointerException("Set variable config cannot be null"); 79 if (variableRefrences.containsKey(variable.getName())) 80 throw new IllegalArgumentException( 81 "Cannot set the variable '" + variable.getName() + "' more than once"); 82 variableRefrences.put(variable.getName(), variable.getRef()); 83 } 84 85 /* (non-Javadoc) 86 * @see com.lonniepryor.blues.cfg.Verifiable#verify() 87 */ 88 public void verify () { 89 if (name == null) 90 throw new IllegalStateException("No include name specified"); 91 if (name.length() == 0) 92 throw new IllegalStateException("Empty include name"); 93 if (modulePath == null) 94 throw new IllegalStateException("No include module path specified"); 95 if (modulePath.length() == 0) 96 throw new IllegalStateException("Empty include module path"); 97 } 98 99 /* (non-Javadoc) 100 * @see com.lonniepryor.blues.cfg.IncludeCfg#getName() 101 */ 102 public String getName () { 103 return name; 104 } 105 106 /* (non-Javadoc) 107 * @see com.lonniepryor.blues.cfg.IncludeCfg#getModulePath() 108 */ 109 public String getModulePath () { 110 return modulePath; 111 } 112 113 /* (non-Javadoc) 114 * @see com.lonniepryor.blues.cfg.IncludeCfg#getVariableNames() 115 */ 116 public String[] getVariableNames () { 117 return (String[])variableRefrences.keySet().toArray( 118 new String[variableRefrences.size()]); 119 } 120 121 /* (non-Javadoc) 122 * @see com.lonniepryor.blues.cfg.IncludeCfg#getVariableRefrence(java.lang.String) 123 */ 124 public String getVariableRefrence (String variableName) { 125 return (String)variableRefrences.get(variableName); 126 } 127 128 /* (non-Javadoc) 129 * @see com.lonniepryor.blues.cfg.IncludeCfg#initIncludedModule( 130 * com.lonniepryor.blues.cfg.ModuleCfg) 131 */ 132 public void initIncludedModule (ModuleCfg module) { 133 if (module == null) 134 throw new NullPointerException("Included module cannot be null"); 135 if (this.module != null) 136 throw new IllegalStateException("Included module already initalized"); 137 this.module = module; 138 } 139 140 /* (non-Javadoc) 141 * @see com.lonniepryor.blues.cfg.IncludeCfg#getIncludedModule() 142 */ 143 public ModuleCfg getIncludedModule () { 144 if (module == null) 145 throw new IllegalStateException("Included module not initalized"); 146 return module; 147 } 148 149 /*** 150 * Child element for setting variable refrences. 151 * 152 * @author Lonnie Pryor 153 * @version $Revision: 1.1 $ 154 */ 155 public static class SetVariableCfg implements Verifiable { 156 /*** The name of the variable to set. */ 157 private String name = null; 158 /*** The refrence to set the variable to. */ 159 private String ref = null; 160 161 /*** 162 * Creates a new SetVariableCfg object. 163 */ 164 public SetVariableCfg () { 165 } 166 167 /*** 168 * Sets the name of the variable to set. 169 * 170 * @param name The name of the variable to set. 171 */ 172 public void setName (String name) { 173 this.name = name; 174 } 175 176 /*** 177 * Sets the refrence to set the variable to. 178 * 179 * @param ref The refrence to set the variable to. 180 */ 181 public void setRef (String ref) { 182 this.ref = ref; 183 } 184 185 /* (non-Javadoc) 186 * @see com.lonniepryor.blues.cfg.Verifiable#verify() 187 */ 188 public void verify () { 189 if (name == null) 190 throw new IllegalStateException("No variable name specified"); 191 if (name.length() == 0) 192 throw new IllegalStateException("Empty variable name"); 193 if (ref == null) 194 throw new IllegalStateException("No variable refrence specified"); 195 if (ref.length() == 0) 196 throw new IllegalStateException("Empty variable refrence"); 197 } 198 199 /*** 200 * Returns the name of the variable to set. 201 * 202 * @return The name of the variable to set. 203 */ 204 public String getName () { 205 return name; 206 } 207 208 /*** 209 * Returns the refrence to set the variable to. 210 * 211 * @return The refrence to set the variable to. 212 */ 213 public String getRef () { 214 return ref; 215 } 216 } 217 }

This page was automatically generated by Maven