001    /*
002     * CDDL HEADER START
003     *
004     * The contents of this file are subject to the terms of the
005     * Common Development and Distribution License, Version 1.0 only
006     * (the "License").  You may not use this file except in compliance
007     * with the License.
008     *
009     * You can obtain a copy of the license at
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.admin;
028    
029    
030    
031    import java.util.ArrayList;
032    import java.util.Arrays;
033    import java.util.Collection;
034    
035    
036    
037    /**
038     * A default behavior provider which represents a well-defined set of default
039     * values. It should be used by properties which have default value(s) which are
040     * valid value(s) according to the constraints of the property's definition.
041     *
042     * @param <T>
043     *          The type of values represented by this provider.
044     */
045    public final class DefinedDefaultBehaviorProvider<T> extends
046        DefaultBehaviorProvider<T> {
047    
048      // The collection of default values.
049      private final Collection<String> values;
050    
051    
052    
053      /**
054       * Create a new defined default behavior provider associated with the
055       * specified list of values.
056       *
057       * @param values
058       *          The list of values (must be non-<code>null</code> and not
059       *          empty) in their string representation.
060       * @throws IllegalArgumentException
061       *           If the list of values was <code>null</code> or empty.
062       */
063      public DefinedDefaultBehaviorProvider(String... values)
064          throws IllegalArgumentException {
065        if (values == null || values.length == 0) {
066          throw new IllegalArgumentException(
067              "Null or empty list of default values");
068        }
069        this.values = Arrays.asList(values);
070      }
071    
072    
073    
074      /**
075       * {@inheritDoc}
076       */
077      public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) {
078        return v.visitDefined(this, p);
079      }
080    
081    
082    
083      /**
084       * Get a copy of the default values.
085       *
086       * @return Returns a newly allocated collection containing a copy of the
087       *         default values.
088       */
089      public Collection<String> getDefaultValues() {
090        return new ArrayList<String>(values);
091      }
092    
093    }