Search in sources :

Example 1 with Scalar

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()));
    }
}
Also used : ModelObject(com.att.cdp.openstack.heat.model.ModelObject) UnmarshallException(com.att.cdp.openstack.exception.UnmarshallException) Scalar(com.att.cdp.openstack.heat.model.Scalar)

Example 2 with Scalar

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()));
    }
}
Also used : ModelObject(com.att.cdp.openstack.heat.model.ModelObject) ArrayList(java.util.ArrayList) List(java.util.List) UnmarshallException(com.att.cdp.openstack.exception.UnmarshallException) HashMap(java.util.HashMap) Map(java.util.Map) Scalar(com.att.cdp.openstack.heat.model.Scalar)

Aggregations

UnmarshallException (com.att.cdp.openstack.exception.UnmarshallException)2 ModelObject (com.att.cdp.openstack.heat.model.ModelObject)2 Scalar (com.att.cdp.openstack.heat.model.Scalar)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1