Search in sources :

Example 1 with Property

use of org.apache.felix.bundlerepository.Property in project aries by apache.

the class OBRCapability method getProperties.

public Property[] getProperties() {
    logger.debug(LOG_ENTRY, "getProperties");
    DataModelHelper helper = repositoryAdmin.getHelper();
    List<Property> properties = new ArrayList<Property>();
    // we then get OBR to parse. This is really convoluted and nasty.
    for (final Map.Entry<String, Object> entry : _props.entrySet()) {
        String propXML = helper.writeProperty(new Property() {

            @Override
            public String getValue() {
                Object value = entry.getValue();
                if (value instanceof String[]) {
                    String newValue = Arrays.toString((String[]) value);
                    value = newValue.substring(1, newValue.length() - 1);
                } else if (value instanceof Collection) {
                    //We can't rely on Collections having a sensible toString() as it isn't
                    //part of the API (although all base Java ones do). We can use an array
                    //to get consistency
                    String newValue = Arrays.toString(((Collection<?>) value).toArray());
                    value = newValue.substring(1, newValue.length() - 1);
                }
                return String.valueOf(value);
            }

            @Override
            public String getType() {
                String name = entry.getKey();
                String type = null;
                if (Constants.VERSION_ATTRIBUTE.equals(name) || (Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name))) {
                    type = "version";
                } else if (Constants.OBJECTCLASS.equals(name) || (Constants.MANDATORY_DIRECTIVE + ":").equals(name) || entry.getValue() instanceof String[] || entry.getValue() instanceof Collection)
                    type = "set";
                return type;
            }

            @Override
            public String getName() {
                return entry.getKey();
            }

            @Override
            public Object getConvertedValue() {
                return null;
            }
        });
        try {
            properties.add(helper.readProperty(propXML));
        } catch (Exception e) {
        // Do nothing and hope it OBR doesn't generate XML it can't parse.
        }
    }
    logger.debug(LOG_EXIT, "getProperties", properties);
    return properties.toArray(new Property[properties.size()]);
}
Also used : ArrayList(java.util.ArrayList) DataModelHelper(org.apache.felix.bundlerepository.DataModelHelper) Collection(java.util.Collection) Property(org.apache.felix.bundlerepository.Property) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Property

use of org.apache.felix.bundlerepository.Property in project aries by apache.

the class RepositoryGeneratorImpl method writeCapability.

/**
   * Write out the capability
   * 
   * @param c capability
   * @param writer buffer writer
   * @throws IOException
   */
private static void writeCapability(Capability c, Document doc, Element resource) throws IOException {
    logger.debug(LOG_ENTRY, "writeCapability", new Object[] { c, doc, resource });
    Element capability = doc.createElement("capability");
    capability.setAttribute("name", c.getName());
    resource.appendChild(capability);
    Property[] props = c.getProperties();
    for (Property entry : props) {
        String name = (String) entry.getName();
        String objectAttrs = entry.getValue();
        String type = (entry.getType() == null) ? getType(name) : entry.getType();
        // remove the beginning " and tailing "
        if (objectAttrs.startsWith("\"") && objectAttrs.endsWith("\""))
            objectAttrs = objectAttrs.substring(1, objectAttrs.length() - 1);
        addProperty(doc, capability, name, objectAttrs, type);
    }
    logger.debug(LOG_EXIT, "writeCapability");
}
Also used : Element(org.w3c.dom.Element) Property(org.apache.felix.bundlerepository.Property)

Aggregations

Property (org.apache.felix.bundlerepository.Property)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DataModelHelper (org.apache.felix.bundlerepository.DataModelHelper)1 Element (org.w3c.dom.Element)1