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