use of com.att.cdp.openstack.heat.model.Scalar in project AJSC by att.
the class Unmarshaller method unmarshallList.
/**
* Unmarshalls a list of data into the model object provided
*
* @param model
* The model object to contain the unmarshalled data
* @param list
* The list of data to be unmarshalled
* @throws UnmarshallException
* If the map does not match the model object
*/
private <T extends ModelObject> void unmarshallList(T model, List<Object> list) throws UnmarshallException {
if (model instanceof Scalar) {
Scalar scalar = (Scalar) model;
StringBuffer buffer = new StringBuffer();
for (Object value : list) {
buffer.append(value.toString());
buffer.append(',');
}
if (buffer.length() > 0) {
buffer.delete(buffer.length() - 1, buffer.length());
}
scalar.setValue(buffer.toString());
} else {
throw new UnmarshallException(String.format("Expecting scalar, but found %s", model.getClass().getSimpleName()));
}
}
use of com.att.cdp.openstack.heat.model.Scalar in project AJSC by att.
the class Unmarshaller method unmarshallObject.
/**
* Unmarshalls a non-map and non-list (i.e., vector or scalar object) into the model object
*
* @param model
* The model object to contain the unmarshalled data
* @param data
* The scalar object to be unmarshalled
* @throws UnmarshallException
* If the map does not match the model object
*/
private <T extends ModelObject> void unmarshallObject(T model, Object data) throws UnmarshallException {
if (model instanceof Scalar) {
Scalar scalar = (Scalar) model;
if (data instanceof Map) {
Map<String, Object> values = (Map<String, Object>) data;
String function = (String) values.keySet().toArray()[0];
scalar.setFunction(function);
Object args = values.get(function);
List<String> arguments = scalar.getArguments();
if (arguments == null) {
arguments = new ArrayList<String>();
scalar.setArguments(arguments);
}
if (args instanceof String) {
arguments.add((String) args);
} else if (args instanceof List) {
for (Object element : (List) args) {
arguments.add(element.toString());
}
}
} else {
scalar.setValue(data.toString());
}
} else {
throw new UnmarshallException(String.format("Expecting scalar, but found %s", model.getClass().getSimpleName()));
}
}
Aggregations