Search in sources :

Example 1 with XMLAttribute

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());
            }
        }
    }
}
Also used : XMLAttribute(aQute.bnd.annotation.xml.XMLAttribute) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Annotation(aQute.bnd.osgi.Annotation)

Aggregations

XMLAttribute (aQute.bnd.annotation.xml.XMLAttribute)1 Annotation (aQute.bnd.osgi.Annotation)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1