/** * Installs the listener for the auto save mechanism if it is not yet * active. */ private void installAutoSaveListener() { if (autoSaveListener == null) { autoSaveListener = new AutoSaveListener(this); addEventListener(ConfigurationEvent.ANY, autoSaveListener); autoSaveListener.updateFileHandler(getFileHandler()); } }
/** * {@inheritDoc} This implementation checks whether an auto-safe operation * should be performed. This is the case if the event indicates that an * update of the configuration has been performed and currently no load * operation is in progress. */ @Override public void onEvent(final ConfigurationEvent event) { if (autoSaveRequired(event)) { try { builder.save(); } catch (final ConfigurationException ce) { log.warn("Auto save failed!", ce); } } }
/** * Checks whether an auto save operation has to be performed based on the * passed in event and the current state of this object. * * @param event the configuration change event * @return <b>true</b> if a save operation should be performed, <b>false</b> * otherwise */ private boolean autoSaveRequired(final ConfigurationEvent event) { return !event.isBeforeUpdate() && !inLoadOperation(); } }
/** * Removes the listener for the auto save mechanism if it is currently * active. */ private void removeAutoSaveListener() { if (autoSaveListener != null) { removeEventListener(ConfigurationEvent.ANY, autoSaveListener); autoSaveListener.updateFileHandler(null); autoSaveListener = null; } }
/** * {@inheritDoc} This implementation deals with the creation and * initialization of a {@code FileHandler} associated with the new result * object. */ @Override protected void initResultInstance(final T obj) throws ConfigurationException { super.initResultInstance(obj); final FileHandler srcHandler = (currentFileHandler != null && !resetParameters) ? currentFileHandler : fetchFileHandlerFromParameters(); currentFileHandler = new FileHandler(obj, srcHandler); if (autoSaveListener != null) { autoSaveListener.updateFileHandler(currentFileHandler); } initFileHandler(currentFileHandler); resetParameters = false; }