public void updated(Dictionary settings) throws ConfigurationException { // if non-null settings come in, we have to instantiate the service and // apply these settings ((ServiceImpl) m_service).initService(); Object service = m_service.getService(); Dictionary oldSettings = null; synchronized (this) { oldSettings = m_settings; } if (oldSettings == null && settings == null) { // CM has started but our configuration is not still present in the CM database: ignore return; } if (service != null) { String callback = (m_callback == null) ? "updated" : m_callback; Method m; try { m = service.getClass().getDeclaredMethod(callback, new Class[] {Dictionary.class}); // if exception is thrown here, what does that mean for the // state of this dependency? how smart do we want to be?? // it's okay like this, if the new settings contain errors, we // remain in the state we were, assuming that any error causes // the "old" configuration to stay in effect. // CM will log any thrown exceptions. m.invoke(service, new Object[] {settings}); } catch (InvocationTargetException e) { // The component has thrown an exception during it's callback invocation. if (e.getTargetException() instanceof ConfigurationException) { // the callback threw an OSGi ConfigurationException: just re-throw it. throw (ConfigurationException) e.getTargetException(); } else { // wrap the callback exception into a ConfigurationException. throw new ConfigurationException( null, "Service " + m_service + " with " + this.toString() + " could not be updated", e.getTargetException()); } } catch (Throwable t) { // wrap any other exception as a ConfigurationException. throw new ConfigurationException( null, "Service " + m_service + " with " + this.toString() + " could not be updated", t); } } else { m_logger.log( Logger.LOG_ERROR, "Service " + m_service + " with configuration dependency " + this + " could not be instantiated."); return; } // If these settings did not cause a configuration exception, we determine if they have // caused the dependency state to change synchronized (this) { m_settings = settings; } if ((oldSettings == null) && (settings != null)) { m_service.dependencyAvailable(this); } if ((oldSettings != null) && (settings == null)) { m_service.dependencyUnavailable(this); } if ((oldSettings != null) && (settings != null)) { m_service.dependencyChanged(this); } }