587
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.helium.core.ant.types;
|
|
19 |
|
628
|
20 |
import java.util.ArrayList;
|
588
|
21 |
import java.util.Collection;
|
587
|
22 |
import java.util.HashMap;
|
|
23 |
import java.util.List;
|
588
|
24 |
|
628
|
25 |
import org.apache.tools.ant.BuildException;
|
|
26 |
import org.apache.tools.ant.types.DataType;
|
|
27 |
|
588
|
28 |
import com.nokia.helium.core.ant.MappedVariable;
|
|
29 |
import com.nokia.helium.core.ant.Variable;
|
|
30 |
import com.nokia.helium.core.ant.VariableMap;
|
|
31 |
|
587
|
32 |
/**
|
|
33 |
* Helper class to store the variable set (list of variables
|
|
34 |
* with name / value pair)
|
|
35 |
* @ant.type name="argSet" category="Core"
|
|
36 |
*/
|
588
|
37 |
public class VariableSet extends DataType implements Variable, VariableMap {
|
587
|
38 |
|
588
|
39 |
private List<Variable> variables = new ArrayList<Variable>();
|
587
|
40 |
|
|
41 |
/**
|
|
42 |
* Creates an empty variable element and adds
|
|
43 |
* it to the variables list
|
|
44 |
* @return empty Variable pair
|
|
45 |
*/
|
|
46 |
public VariableSet createArgSet() {
|
588
|
47 |
VariableSet variableSet = new VariableSet();
|
|
48 |
variables.add(variableSet);
|
|
49 |
return variableSet;
|
587
|
50 |
}
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Creates an empty variable element and adds
|
|
54 |
* it to the variables list
|
|
55 |
* @return empty Variable pair
|
|
56 |
*/
|
|
57 |
public Variable createArg() {
|
588
|
58 |
Variable variable = new VariableImpl();
|
|
59 |
variables.add(variable);
|
|
60 |
return variable;
|
587
|
61 |
}
|
588
|
62 |
|
587
|
63 |
/**
|
|
64 |
* Add a given variable to the list
|
|
65 |
* @param var variable to add
|
|
66 |
*/
|
588
|
67 |
public void add(Variable variable) {
|
|
68 |
variables.add(variable);
|
587
|
69 |
}
|
|
70 |
|
|
71 |
/**
|
|
72 |
* Helper function to get the list of variables defined for this set.
|
|
73 |
* @return variable list for this set.
|
|
74 |
*/
|
|
75 |
public List<Variable> getVariablesList() {
|
|
76 |
return variables;
|
|
77 |
}
|
|
78 |
|
588
|
79 |
/**
|
|
80 |
* Get the list of nested VariableSet.
|
|
81 |
* @return the list of VariableSet.
|
|
82 |
*/
|
587
|
83 |
public List<VariableSet> getVariableSets() {
|
588
|
84 |
List<VariableSet> variableSets = new ArrayList<VariableSet>();
|
|
85 |
for (Variable variable : variables) {
|
|
86 |
if (variable instanceof VariableSet) {
|
|
87 |
variableSets.add((VariableSet)variable);
|
|
88 |
}
|
|
89 |
}
|
|
90 |
return variableSets;
|
587
|
91 |
}
|
588
|
92 |
|
587
|
93 |
/**
|
|
94 |
* Returns the list of variables available in the VariableSet
|
|
95 |
* @return variable list
|
|
96 |
*/
|
588
|
97 |
public HashMap<String, MappedVariable> getVariablesMap() {
|
|
98 |
if (this.isReference()) {
|
|
99 |
Object varSetObject = this.getRefid().getReferencedObject();
|
587
|
100 |
if (varSetObject != null && varSetObject instanceof VariableSet) {
|
588
|
101 |
return ((VariableSet)varSetObject).getVariablesMap();
|
|
102 |
} else {
|
|
103 |
throw new BuildException("The '" + this.getRefid().getRefId() + "' reference is not referencing a VariableSet");
|
587
|
104 |
}
|
588
|
105 |
} else {
|
|
106 |
HashMap<String, MappedVariable> allVariables = new HashMap<String, MappedVariable>();
|
|
107 |
for (Variable variable : variables) {
|
|
108 |
if (variable instanceof MappedVariable) {
|
|
109 |
allVariables.put(((MappedVariable)variable).getName(), (MappedVariable)variable);
|
628
|
110 |
} else if (variable instanceof VariableSet) {
|
588
|
111 |
allVariables.putAll(((VariableSet)variable).getVariablesMap());
|
628
|
112 |
}
|
588
|
113 |
}
|
|
114 |
return allVariables;
|
587
|
115 |
}
|
588
|
116 |
}
|
|
117 |
|
|
118 |
/**
|
|
119 |
* {@inheritDoc}
|
|
120 |
*/
|
|
121 |
@Override
|
|
122 |
public String getParameter() {
|
|
123 |
return getParameter("=");
|
|
124 |
}
|
|
125 |
|
|
126 |
/**
|
|
127 |
* {@inheritDoc}
|
|
128 |
*/
|
|
129 |
@Override
|
|
130 |
public String getParameter(String separator) {
|
|
131 |
if (this.isReference()) {
|
|
132 |
Object varSetObject = this.getRefid().getReferencedObject();
|
|
133 |
if (varSetObject != null && varSetObject instanceof VariableSet) {
|
|
134 |
return ((VariableSet)varSetObject).getParameter(separator);
|
|
135 |
} else {
|
|
136 |
throw new BuildException("The '" + this.getRefid().getRefId() + "' reference is not referencing a VariableSet");
|
587
|
137 |
}
|
588
|
138 |
} else {
|
|
139 |
String parameter = "";
|
|
140 |
for (Variable variable : variables) {
|
|
141 |
|
|
142 |
parameter += " " + variable.getParameter(separator);
|
|
143 |
}
|
|
144 |
return parameter;
|
587
|
145 |
}
|
|
146 |
}
|
588
|
147 |
|
|
148 |
/**
|
|
149 |
* {@inheritDoc}
|
|
150 |
*/
|
|
151 |
@Override
|
|
152 |
public Collection<MappedVariable> getVariables() {
|
|
153 |
return this.getVariablesMap().values();
|
|
154 |
}
|
|
155 |
|
|
156 |
|
587
|
157 |
} |