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 */
026package org.forgerock.opendj.config;
027
028import java.util.Locale;
029
030import org.forgerock.i18n.LocalizableMessage;
031
032/**
033 * A default behavior provider which indicates special behavior. It should be
034 * used by properties which have a default behavior which cannot be directly
035 * represented using real values of the property. For example, a property
036 * containing a set of user names might default to "all users" when no values
037 * are provided. This meaning cannot be represented using a finite set of
038 * values.
039 *
040 * @param <T>
041 *            The type of values represented by this provider.
042 */
043public final class AliasDefaultBehaviorProvider<T> extends DefaultBehaviorProvider<T> {
044
045    /**
046     * The managed object definition associated with this default
047     * behavior.
048     */
049    private final AbstractManagedObjectDefinition<?, ?> definition;
050
051    /**
052     * The name of the property definition associated with this default
053     * behavior.
054     */
055    private final String propertyName;
056
057    /**
058     * Create an alias default behavior provider.
059     *
060     * @param d
061     *            The managed object definition associated with this default
062     *            behavior.
063     * @param propertyName
064     *            The name of the property definition associated with this
065     *            default behavior.
066     */
067    public AliasDefaultBehaviorProvider(AbstractManagedObjectDefinition<?, ?> d, String propertyName) {
068        this.definition = d;
069        this.propertyName = propertyName;
070    }
071
072    /** {@inheritDoc} */
073    public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) {
074        return v.visitAlias(this, p);
075    }
076
077    /**
078     * Gets the synopsis of this alias default behavior in the default locale.
079     *
080     * @return Returns the synopsis of this alias default behavior in the
081     *         default locale.
082     */
083    public final LocalizableMessage getSynopsis() {
084        return getSynopsis(Locale.getDefault());
085    }
086
087    /**
088     * Gets the synopsis of this alias default behavior in the specified locale.
089     *
090     * @param locale
091     *            The locale.
092     * @return Returns the synopsis of this alias default behavior in the
093     *         specified locale.
094     */
095    public final LocalizableMessage getSynopsis(Locale locale) {
096        ManagedObjectDefinitionI18NResource resource = ManagedObjectDefinitionI18NResource.getInstance();
097        String property = "property." + propertyName + ".default-behavior.alias.synopsis";
098        return resource.getMessage(definition, property, locale);
099    }
100
101}