public Property[] getProperties()
{
logger.debug(LOG_ENTRY, "getProperties");
DataModelHelper helper = repositoryAdmin.getHelper();
List<Property> properties = new ArrayList<Property>();
// Felix BundleRepository doesn't appear to correctly cope with String[] value properties
// as a result we can't do multi value service properties. OBR doesn't really like implementations
// of its interfaces that it didn't generate, but it is a little weird when it does and doesn't.
// so we create a Property implemenation which we use to generate the OBR xml for a property which
// 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.
}
}