private void addPolicySetToDevice(PolicySet policySet,
DefaultDevice device) {
Iterator entries = policySet.entries();
while (entries.hasNext()) {
PolicyEntry entry = (PolicyEntry) entries.next();
Iterator fields = entry.fields();
Iterator values = entry.values();
if (fields.hasNext()) {
// it has fields, so this is a structure entry.
// NOTE: schema says each field can contain multiple values but
// this is not used so is not implemented.
while (fields.hasNext()) {
PolicyField field = (PolicyField) fields.next();
String name = entry.getName() + "." + field.getName();
device.setPolicyValue(name, field.getValue());
}
} else if (values.hasNext()) {
// it has values, so it is a simple entry which may have
// multiple values.
String value = (String) values.next();
StringBuffer buffer = new StringBuffer(value);
while (values.hasNext()) {
value = (String) values.next();
buffer.append(",");
buffer.append(value);
}
device.setPolicyValue(entry.getName(), buffer.toString());
} else {
// no values at all, for backwards compatibility with the
// old JDOM accessor we add it with no value. Not sure if we
// really should?
device.setPolicyValue(entry.getName(), "");
}
}
}