use of aQute.bnd.annotation.xml.XMLAttribute in project bnd by bndtools.
the class ExtensionDef method addAttributes.
// non-matching attributes have already been removed
public void addAttributes(Tag tag, Namespaces namespaces) {
if (namespaces != null) {
for (Map.Entry<XMLAttribute, Annotation> entry : attributes.entrySet()) {
String prefix = namespaces.getPrefix(entry.getKey().namespace());
Annotation a = entry.getValue();
Map<String, String> props = finder.getDefaults(a);
for (String key : entry.getValue().keySet()) {
Object obj = entry.getValue().get(key);
String value;
if (obj.getClass().isArray()) {
StringBuilder sb = new StringBuilder();
String sep = "";
for (int i = 0; i < Array.getLength(obj); i++) {
Object el = Array.get(obj, i);
sb.append(sep).append(String.valueOf(el));
sep = " ";
}
value = sb.toString();
} else {
value = String.valueOf(obj);
}
props.put(key, value);
}
String[] mapping = entry.getKey().mapping();
for (Map.Entry<String, String> prop : props.entrySet()) {
String key = prop.getKey();
if (mapping != null && mapping.length > 0) {
String match = key + "=";
for (String map : mapping) {
if (map.startsWith(match))
key = map.substring(match.length());
}
}
tag.addAttribute(prefix + ":" + key, prop.getValue());
}
}
}
}
Aggregations