public synchronized void commitChanges() throws ConfigurationException { if ( isThisDirty() ) { try { checkValidationResponse( doValidateChanges( getChangedConfiguration() ) ); } catch ( ConfigurationException e ) { rollbackChanges(); throw e; } // nice, isn't it? copyObject( getChangedConfiguration(), getOriginalConfiguration() ); copyTransients( getChangedConfiguration(), getOriginalConfiguration() ); setChangedConfiguration( null ); } }
public void rollbackChanges() { if ( isThisDirty() ) { setChangedConfiguration( null ); } }
public void validateChanges() throws ConfigurationException { if ( isThisDirty() ) { checkValidationResponse( doValidateChanges( getChangedConfiguration() ) ); } }
public Object getConfiguration( boolean forWrite ) { if ( forWrite ) { synchronized ( this ) { if ( getOriginalConfiguration() != null && getChangedConfiguration() == null ) { // copy it final Object copy = copyObject( getOriginalConfiguration(), null ); copyTransients( getOriginalConfiguration(), copy ); setChangedConfiguration( copy ); } } return getChangedConfiguration(); } else { return getOriginalConfiguration(); } }
public boolean isDirty() { return isThisDirty(); }
protected boolean isThisDirty() { return getChangedConfiguration() != null; }
@SuppressWarnings( "unchecked" ) protected Object copyObject( Object source, Object target ) { if ( source == null && target == null ) { return null; } else if ( source instanceof Collection<?> && target != null ) { // one exception is config object is actually a list, we need to keep the same instance ( (Collection) target ).clear(); ( (Collection) target ).addAll( (Collection) source ); return target; } else if ( target == null ) { // "clean" deep copy return getXStream().fromXML( getXStream().toXML( source ) ); } else { // "overlay" actually return getXStream().fromXML( getXStream().toXML( source ), target ); } }
@Override public void commitChanges() throws ConfigurationException { super.commitChanges(); if ( getExternalConfiguration() != null ) { getExternalConfiguration().commitChanges(); } }
@Override public void rollbackChanges() { super.rollbackChanges(); if ( getExternalConfiguration() != null ) { getExternalConfiguration().rollbackChanges(); } }