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
028/**
029 * A default behavior provider which retrieves default values from a managed
030 * object in an absolute location. It should be used by properties which inherit
031 * their default value(s) from properties held in an other managed object.
032 *
033 * @param <T>
034 *            The type of values represented by this provider.
035 */
036public final class AbsoluteInheritedDefaultBehaviorProvider<T> extends DefaultBehaviorProvider<T> {
037
038    /** The absolute path to the managed object containing the property. */
039    private ManagedObjectPath<?, ?> path;
040
041    /**
042     * The string representation of the managed object path specifying
043     * the absolute location of the managed object.
044     */
045    private final String pathString;
046
047    /** The name of the property containing the inherited default values. */
048    private final String propertyName;
049
050    /**
051     * Create an absolute inherited default behavior provider associated with
052     * the managed object at the specified absolute location.
053     *
054     * @param pathString
055     *            The string representation of the managed object path
056     *            specifying the absolute location of the managed object.
057     * @param propertyName
058     *            The name of the property containing the inherited default
059     *            values.
060     */
061    public AbsoluteInheritedDefaultBehaviorProvider(String pathString, String propertyName) {
062        this.pathString = pathString;
063        this.propertyName = propertyName;
064    }
065
066    /** {@inheritDoc} */
067    public <R, P> R accept(DefaultBehaviorProviderVisitor<T, R, P> v, P p) {
068        return v.visitAbsoluteInherited(this, p);
069    }
070
071    /**
072     * Get the definition of the parent managed object containing the inherited
073     * default values.
074     *
075     * @return Returns the definition of the parent managed object containing
076     *         the inherited default values.
077     */
078    public AbstractManagedObjectDefinition<?, ?> getManagedObjectDefinition() {
079        return path.getManagedObjectDefinition();
080    }
081
082    /**
083     * Get the absolute path of the managed object containing the property which
084     * has the default values.
085     *
086     * @return Returns the absolute path of the managed object containing the
087     *         property which has the default values.
088     */
089    public ManagedObjectPath<?, ?> getManagedObjectPath() {
090        return path;
091    }
092
093    /**
094     * Gets the name of the property containing the inherited default values.
095     *
096     * @return Returns the name of the property containing the inherited default
097     *         values.
098     */
099    public String getPropertyName() {
100        return propertyName;
101    }
102
103    /** {@inheritDoc} */
104    @Override
105    protected void initialize() throws Exception {
106        // Decode the path.
107        path = ManagedObjectPath.valueOf(pathString);
108    }
109
110}