} 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.getMessage());
}
}
}
// Then create the provided service
ProvidedService svc = new ProvidedService(this, serviceSpecifications, factory, custom, configuration);
// Post-Registration callback
String post = providedServices[i].getAttribute("post-registration");
if (post != null) {
Callback cb = new Callback(post, new Class[] {ServiceReference.class}, false, getInstanceManager());
svc.setPostRegistrationCallback(cb);
}
post = providedServices[i].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 = providedServices[i].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 = providedServices[i].getElements("Controller");
if (controllers != null) {
for (int k = 0; k < controllers.length; k++) {
String field = controllers[k].getAttribute("field");
if (field == null) {
throw new ConfigurationException("The field attribute of a controller is mandatory");
}
String v = controllers[k].getAttribute("value");
boolean value = ! (v != null && v.equalsIgnoreCase("false"));
String s = controllers[k].getAttribute("specification");
if (s == null) {
s ="ALL";
}
svc.setController(field, value, s);
getInstanceManager().register(new FieldMetadata(field, "boolean"), this);
}
}
if (checkProvidedService(svc)) {
addProvidedService(svc);
} else {
StringBuffer itfs = new StringBuffer();
for (int j = 0; j < serviceSpecifications.length; j++) {
itfs.append(' ');
itfs.append(serviceSpecifications[j]);
}
throw new ConfigurationException("The provided service" + itfs + " is not valid");
}
// Initialize the description.
m_description = new ProvidedServiceHandlerDescription(this, m_providedServices);