Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2006, David Peterson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of "randombits.org" nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.servicerocket.confluence.randombits.storage;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* This implementation of Storage allows several other concrete storage
* instances to be chained together so that if one source does not contain the
* specified value, the next will be queried and so on.
*
*
* A chained storage instance will be writable if any of the contained
* Storage instances is writable. The first writable storage in the list will be
* where any saved values are put.
*
*
* @author David Peterson
*/
public class ChainedStorage extends AbstractStorage implements Aliasable {
private static final Accessor BOOLEAN_ACCESSOR = new Accessor() {
public Boolean get( Storage store, String name ) {
return store.getBoolean( name, null );
}
public void set( Storage store, String name, Boolean value ) {
store.setBoolean( name, value );
}
};
private static final Accessor DATE_ACCESSOR = new Accessor() {
public Date get( Storage store, String name ) {
return store.getDate( name, null );
}
public void set( Storage store, String name, Date value ) {
store.setDate( name, value );
}
};
private static final Accessor DOUBLE_ACCESSOR = new Accessor() {
public Double get( Storage store, String name ) {
return store.getDouble( name, null );
}
public void set( Storage store, String name, Double value ) {
store.setDouble( name, value );
}
};
private static final Accessor INTEGER_ACCESSOR = new Accessor() {
public Integer get( Storage store, String name ) {
return store.getInteger( name, null );
}
public void set( Storage store, String name, Integer value ) {
store.setInteger( name, value );
}
};
private static final Accessor LONG_ACCESSOR = new Accessor() {
public Long get( Storage store, String name ) {
return store.getLong( name, null );
}
public void set( Storage store, String name, Long value ) {
store.setLong( name, value );
}
};
private static final Accessor NUMBER_ACCESSOR = new Accessor() {
public Number get( Storage store, String name ) {
return store.getNumber( name, null );
}
public void set( Storage store, String name, Number value ) {
// Do nothing - there is no 'setNumber' method.
}
};
private static final Accessor> OBJECT_LIST_ACCESSOR = new Accessor>() {
public List get( Storage store, String name ) {
return store.getObjectList( name, null );
}
public void set( Storage store, String name, List value ) {
store.setObjectList( name, value );
}
};
private static final Accessor STRING_ACCESSOR = new Accessor() {
public String get( Storage store, String name ) {
return store.getString( name, null );
}
public void set( Storage store, String name, String value ) {
store.setString( name, value );
}
};
private static final Accessor STRING_ARRAY_ACCESSOR = new Accessor() {
public String[] get( Storage store, String name ) {
return store.getStringArray( name, null );
}
public void set( Storage store, String name, String[] value ) {
store.setStringArray( name, value );
}
};
private static final Accessor