} else {
// Customized policy
try {
custom = getInstanceManager().getContext().getBundle().loadClass(strategy);
if (!CreationStrategy.class.isAssignableFrom(custom)) {
throw new ConfigurationException("The custom creation policy class " + custom.getName() + " does not implement " + CreationStrategy.class.getName());
}
} catch (ClassNotFoundException e) {
throw new ConfigurationException("The custom creation policy class " + strategy + " cannot be loaded ", e);
}
}
}
// Then create the provided service
ProvidedService svc = new ProvidedService(this, serviceSpecifications, factory, custom, configuration);
// Post-Registration callback
String post = providedService.getAttribute("post-registration");
if (post != null) {
Callback cb = new Callback(post, new Class[]{ServiceReference.class}, false, getInstanceManager());
svc.setPostRegistrationCallback(cb);
}
post = providedService.getAttribute("post-unregistration");
if (post != null) {
// TODO Can we really send the service reference here ?
Callback cb = new Callback(post, new Class[]{ServiceReference.class}, false, getInstanceManager());
svc.setPostUnregistrationCallback(cb);
}
Element[] props = providedService.getElements("Property");
if (props != null) {
//Property[] properties = new Property[props.length];
Property[] properties = new Property[props.length];
for (int j = 0; j < props.length; j++) {
String name = props[j].getAttribute("name");
String value = props[j].getAttribute("value");
String type = props[j].getAttribute("type");
String field = props[j].getAttribute("field");
Property prop = new Property(name, field, null, value, type, getInstanceManager(), this);
properties[j] = prop;
// Check if the instance configuration has a value for this property
Object object = configuration.get(prop.getName());
if (object != null) {
prop.setValue(object);
}
if (field != null) {
getInstanceManager().register(new FieldMetadata(field, type), this);
// Cannot register the property as the interception is necessary
// to deal with registration update.
}
}
// Attach to properties to the provided service
svc.setProperties(properties);
}
Element[] controllers = providedService.getElements("Controller");
if (controllers != null) {
for (Element controller : controllers) {
String field = controller.getAttribute("field");
if (field == null) {
throw new ConfigurationException("The field attribute of a controller is mandatory");
}
String v = controller.getAttribute("value");
boolean value = !(v != null && v.equalsIgnoreCase("false"));
String s = controller.getAttribute("specification");
if (s == null) {
s = "ALL";
}
svc.setController(field, value, s);
getInstanceManager().register(new FieldMetadata(field, "boolean"), this);
}
}
if (checkProvidedService(svc)) {
m_providedServices.add(svc);
} else {
StringBuilder itfs = new StringBuilder();
for (String serviceSpecification : serviceSpecifications) {
itfs.append(' ');
itfs.append(serviceSpecification);
}
throw new ConfigurationException("The provided service" + itfs + " is not valid");
}
// Initialize the description.
m_description = new ProvidedServiceHandlerDescription(this, getProvidedServices());