001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 * Portions Copyright 2016 ForgeRock AS.
016 */
017package org.forgerock.opendj.config;
018
019import java.util.Locale;
020
021import org.forgerock.i18n.LocalizableMessage;
022
023/**
024 * A default behavior provider which indicates special behavior. It should be
025 * used by properties which have a default behavior which cannot be directly
026 * represented using real values of the property. For example, a property
027 * containing a set of user names might default to "all users" when no values
028 * are provided. This meaning cannot be represented using a finite set of
029 * values.
030 *
031 * @param <T>
032 *            The type of values represented by this provider.
033 */
034public final class AliasDefaultBehaviorProvider<T> extends DefaultBehaviorProvider<T> {
035
036    /** The managed object definition associated with this default behavior. */
037    private final AbstractManagedObjectDefinition<?, ?> definition;
038
039    /** The name of the property definition associated with this default behavior. */
040    private final String propertyName;
041
042    /**
043     * Create an alias default behavior provider.
044     *
045     * @param d
046     *            The managed object definition associated with this default
047     *            behavior.
048     * @param propertyName
049     *            The name of the property definition associated with this
050     *            default behavior.
051     */
052    public AliasDefaultBehaviorProvider(AbstractManagedObjectDefinition<?, ?> d, String propertyName) {
053        this.definition = d;
054        this.propertyName = propertyName;
055    }
056
057    @Override
058    public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) {
059        return v.visitAlias(this, p);
060    }
061
062    /**
063     * Gets the synopsis of this alias default behavior in the default locale.
064     *
065     * @return Returns the synopsis of this alias default behavior in the
066     *         default locale.
067     */
068    public final LocalizableMessage getSynopsis() {
069        return getSynopsis(Locale.getDefault());
070    }
071
072    /**
073     * Gets the synopsis of this alias default behavior in the specified locale.
074     *
075     * @param locale
076     *            The locale.
077     * @return Returns the synopsis of this alias default behavior in the
078     *         specified locale.
079     */
080    public final LocalizableMessage getSynopsis(Locale locale) {
081        ManagedObjectDefinitionI18NResource resource = ManagedObjectDefinitionI18NResource.getInstance();
082        String property = "property." + propertyName + ".default-behavior.alias.synopsis";
083        return resource.getMessage(definition, property, locale);
084    }
085
086}