FileDocCategorySizeDatePackage
DelegatingSettings.javaAPI DocExample3999Mon Jul 23 13:26:54 BST 2007org.apache.struts2.config

DelegatingSettings

public class DelegatingSettings extends Settings
DelegatingSettings stores an internal list of {@link Settings} objects to update settings or retrieve settings values.

Each time a Settings method is called (get, set, list, and so forth), this class goes through the list of Settings objects and calls that method for each delegate, withholding any exception until all delegates have been called.

Fields Summary
Settings[]
delegates
The Settings objects.
Constructors Summary
public DelegatingSettings(Settings[] delegates)
Creates a new DelegatingSettings object utilizing the list of {@link Settings} objects.

param
delegates The Settings objects to use as delegates

        this.delegates = delegates;
    
Methods Summary
public java.lang.StringgetImpl(java.lang.String name)


        IllegalArgumentException e = null;

        for (Settings delegate : delegates) {
            try {
                return delegate.getImpl(name);  // Throws exception if not found
            } catch (IllegalArgumentException ex) {
                e = ex;

                // Try next delegate
            }
        }

        throw e;
    
public booleanisSetImpl(java.lang.String aName)

        for (Settings delegate : delegates) {
            if (delegate.isSetImpl(aName)) {
                return true;
            }
        }

        return false;
    
public java.util.IteratorlistImpl()

        boolean workedAtAll = false;

        Set<Object> settingList = new HashSet<Object>();
        UnsupportedOperationException e = null;

        for (Settings delegate : delegates) {
            try {
                Iterator list = delegate.listImpl();

                while (list.hasNext()) {
                    settingList.add(list.next());
                }

                workedAtAll = true;
            } catch (UnsupportedOperationException ex) {
                e = ex;

                // Try next delegate
            }
        }

        if (!workedAtAll) {
            throw (e == null) ? new UnsupportedOperationException() : e;
        } else {
            return settingList.iterator();
        }
    
public voidsetImpl(java.lang.String name, java.lang.String value)

        IllegalArgumentException e = null;

        for (Settings delegate : delegates) {
            try {
                delegate.getImpl(name); // Throws exception if not found
                delegate.setImpl(name, value); // Found it
                return; // Done
            } catch (IllegalArgumentException ex) {
                e = ex;

                // Try next delegate
            }
        }

        throw e;