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