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 legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008 Sun Microsystems, Inc. 025 * Portions Copyright 2015 ForgeRock AS. 026 */ 027package org.opends.server.admin; 028 029 030 031import java.util.ArrayList; 032import java.util.Arrays; 033import 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 */ 045public 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 /** {@inheritDoc} */ 073 public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) { 074 return v.visitDefined(this, p); 075 } 076 077 /** 078 * Get a copy of the default values. 079 * 080 * @return Returns a newly allocated collection containing a copy of the 081 * default values. 082 */ 083 public Collection<String> getDefaultValues() { 084 return new ArrayList<>(values); 085 } 086}