Commit 180cf5bd authored by Valérie Maquil's avatar Valérie Maquil

added possibilities to bootstrao from attributes instead of nodes

parent fa9f11a3
......@@ -109,6 +109,8 @@ public class EquationSystemBuilder {
*/
private boolean hasDependencyCycle(Element equation) {
String equationName = equation.getChildText(Externalization.NAME_ELEMENT);
if (Strings.isNullOrEmpty(equationName))
equationName = equation.getAttributeValue(Externalization.NAME_ELEMENT);
boolean dependencyCycle = false;
for (String parameter : equationParameters.get(equationName)) {
......@@ -148,7 +150,11 @@ public class EquationSystemBuilder {
for (Element output : outputElements) {
String name = output.getChildText(Externalization.NAME_ELEMENT);
if (Strings.isNullOrEmpty(name))
name = output.getAttributeValue(Externalization.NAME_ELEMENT);
String unit = output.getChildText(Externalization.UNIT_ELEMENT);
if (Strings.isNullOrEmpty(unit))
unit = output.getAttributeValue(Externalization.UNIT_ELEMENT);
if (Strings.isNullOrEmpty(name)) {
throw new EquationSystemException("For each output the name needs to be defined!"); //$NON-NLS-1$
......@@ -182,12 +188,19 @@ public class EquationSystemBuilder {
private void addParameterDependencies(Element equation) {
String equationName = equation.getChildText(Externalization.NAME_ELEMENT);
if (Strings.isNullOrEmpty(equationName))
equationName = equation.getAttributeValue(Externalization.NAME_ELEMENT);
List<Element> parameters = equation.getChild(Externalization.PARAMETERS_ELEMENT).getChildren(Externalization.PARAMETER_ELEMENT);
List<String> _equationParameters = new ArrayList<String>();
for (Element parameter : parameters) {
String parameterName = parameter.getChildText(Externalization.NAME_ELEMENT);
if (Strings.isNullOrEmpty(parameterName))
parameterName = parameter.getAttributeValue(Externalization.NAME_ELEMENT);
String parameterUnit = parameter.getChildText(Externalization.UNIT_ELEMENT);
if (Strings.isNullOrEmpty(parameterUnit))
parameterUnit = parameter.getAttributeValue(Externalization.UNIT_ELEMENT);
_equationParameters.add(parameterName);
if (parameterDependencies.containsKey(parameterName)) {
......@@ -232,12 +245,22 @@ public class EquationSystemBuilder {
private void addResultDependencies(Element equation) {
String equationName = equation.getChildText(Externalization.NAME_ELEMENT);
if (Strings.isNullOrEmpty(equationName))
equationName = equation.getAttributeValue(Externalization.NAME_ELEMENT);
List<Element> results = equation.getChild(Externalization.RESULTS_ELEMENT).getChildren(Externalization.RESULT_ELEMENT);
List<String> _equationResults = new ArrayList<String>();
for (Element result : results) {
String resultName = result.getChildText(Externalization.NAME_ELEMENT);
if (Strings.isNullOrEmpty(resultName))
resultName = result.getAttributeValue(Externalization.NAME_ELEMENT);
String resultUnit = result.getChildText(Externalization.UNIT_ELEMENT);
if (Strings.isNullOrEmpty(resultUnit))
resultUnit = result.getAttributeValue(Externalization.UNIT_ELEMENT);
_equationResults.add(resultName);
if (resultDependencies.containsKey(resultName)) {
......@@ -278,7 +301,9 @@ public class EquationSystemBuilder {
if (!periodic) {
if (hasDependencyCycle(equation)) {
String equationName = equation.getChildText(Externalization.NAME_ELEMENT);
throw new EquationSystemException("Dependency Cylce detected for equation " + equationName); //$NON-NLS-1$
if (Strings.isNullOrEmpty(equationName))
equationName = equation.getAttributeValue(Externalization.NAME_ELEMENT);
throw new EquationSystemException("Dependency Cycle detected for equation " + equationName); //$NON-NLS-1$
}
}
}
......@@ -287,6 +312,9 @@ public class EquationSystemBuilder {
private void createEquations(Element equation) throws EquationSystemException {
String equationName = equation.getChildText(Externalization.NAME_ELEMENT);
if (Strings.isNullOrEmpty(equationName))
equationName = equation.getAttributeValue(Externalization.NAME_ELEMENT);
LinkedHashSet<Variable> equationInputs = new LinkedHashSet<>();
LinkedHashSet<Variable> equationOutputs = new LinkedHashSet<>();
boolean lockToNesting = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment