\r
\r
public static Variable getVariable(Configuration configuration, String name) {\r
+ if (name == null || name.isEmpty()) {\r
+ return null;\r
+ }\r
+ \r
+ // this function seems to be used with both whitespaced and\r
+ // underscored versions of the variable name\r
+ String[] components = name.replace('_', ' ').split("\\.");\r
+ \r
Configuration conf = configuration;\r
- // This function seems to be used with both whitespaced and\r
- // underscored versions of the variable name.\r
- String whitespacedName = name.replace('_', ' ');\r
- String[] components = whitespacedName.split("\\.");\r
-\r
- for(String component : components) {\r
-\r
- Configuration newConf = null;\r
-\r
- for(IElement element : conf.getElements()) {\r
- if(element instanceof Variable) {\r
- Variable variable = (Variable) element;\r
- if(variable.getName().equals(component)) {\r
- return variable;\r
- }\r
- } else if(element instanceof Module) {\r
- Module m = (Module)element;\r
- if(m.getName().equals(component)) {\r
- newConf = m.getType().getConfiguration();\r
- }\r
+ \r
+ for (int i = 0; i < components.length-1; i++) {\r
+ Module module = findModule(conf, components[i]);\r
+ if (module == null) {\r
+ // requested module could not be found\r
+ return null;\r
+ }\r
+ conf = module.getType().getConfiguration();\r
+ }\r
+ \r
+ return findVariable(conf, components[components.length-1]);\r
+ }\r
+ \r
+ private static Module findModule(Configuration conf, String name) {\r
+ for (IElement element : conf.getElements()) {\r
+ if (element instanceof Module) {\r
+ Module module = (Module)element;\r
+ if (module.getName().equals(name)) {\r
+ return module;\r
+ }\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ private static Variable findVariable(Configuration conf, String name) {\r
+ for (IElement element : conf.getElements()) {\r
+ if (element instanceof Variable) {\r
+ Variable variable = (Variable)element;\r
+ if (variable.getName().equals(name)) {\r
+ return variable;\r
}\r
}\r
-\r
- // If variable or configuration has not been found, return null\r
- if(newConf == null)\r
- return null;\r
}\r
-\r
return null;\r
}\r
\r