Search in sources :

Example 1 with ServiceController

use of org.apache.felix.ipojo.handlers.providedservice.ProvidedService.ServiceController in project felix by apache.

the class ProvidedServiceHandler method onSet.

/**
 * Setter Callback Method.
 * Check if the modified field is a property to update the value.
 * @param pojo : the pojo object on which the field is accessed
 * @param fieldName : field name
 * @param value : new value
 * @see org.apache.felix.ipojo.FieldInterceptor#onSet(Object, String, Object)
 */
public void onSet(Object pojo, String fieldName, Object value) {
    // Verify that the field name correspond to a dependency
    for (ProvidedService svc : m_providedServices) {
        boolean update = false;
        // Retrieve a copy of the properties.
        final Property[] properties = svc.getProperties();
        for (Property prop : properties) {
            if (fieldName.equals(prop.getField()) && !prop.getValue().equals(value)) {
                // it is the associated property
                prop.setValue(value);
                update = true;
            }
        }
        if (update) {
            svc.update();
        }
        ServiceController ctrl = svc.getController(fieldName);
        if (ctrl != null) {
            if (value instanceof Boolean) {
                ctrl.setValue((Boolean) value);
            } else {
                warn("Boolean value expected for the service controller " + fieldName);
            }
        }
    }
// Else do nothing
}
Also used : ServiceController(org.apache.felix.ipojo.handlers.providedservice.ProvidedService.ServiceController) Property(org.apache.felix.ipojo.util.Property)

Aggregations

ServiceController (org.apache.felix.ipojo.handlers.providedservice.ProvidedService.ServiceController)1 Property (org.apache.felix.ipojo.util.Property)1