001/*
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: DefaultValues.java,v 1.3 2008/06/25 05:44:03 qcheng Exp $
026 *
027 * Portions Copyrighted 2016 ForgeRock AS.
028 */
029
030package com.sun.identity.sm;
031
032import java.util.Map;
033import java.util.Set;
034import org.w3c.dom.Node;
035
036/**
037 * The abstract class <code>DefaultValues</code> provides a mechanism for
038 * services to obtain their default values dynamically instead of being
039 * statically defined in the service XML file stored in the directory.
040 * <p>
041 * An implementation of this class must be specified in the service
042 * configuration XML file in the definition of the respective attribute schema.
043 * Instead of providing the default values in the XML configuration file, the
044 * class name must be specified within the XML node
045 * <code>DefaultValuesClassName</code>.
046 *
047 * @supported.all.api
048 */
049public abstract class DefaultValues {
050
051    /**
052     * Abstract method that must be implemented by a class extending this
053     * interface, and should return the default values for the attribute.
054     * 
055     * @return defaults values for the attribute as a <code>java.util.Set</code>
056     */
057    public abstract Set<String> getDefaultValues();
058
059    /**
060     * Returns a Set of default values for the attribute, given the environment
061     * parameters. The default implementation calls the interface
062     * <code>getDefaultValues()</code> which takes no parameters. The class
063     * extending this class can override this method to take advantage of the
064     * additional environment parameters.
065     * 
066     * @return defaults values for the attribute as a <code>java.util.Set</code>
067     */
068    public Set<String> getDefaultValues(Map envParams) {
069        return (getDefaultValues());
070    }
071
072    /**
073     * Returns the name of the attribute for which the default values will be
074     * returned.
075     * 
076     * @return the name of attribute for which the default values are returned
077     */
078    public final String getAttributeName() {
079        return (attributeSchema.getName());
080    }
081
082    /**
083     * Returns the configured key-value pairs for the class in the service's
084     * configuration file
085     * 
086     * @return key-value pairs configured for this class in the service schema
087     *         XML file
088     */
089    public final Map<String, Set<String>> getConfiguredKeyValues() {
090        return (keyValues);
091    }
092
093    /**
094     * Returns the XML <code>AttributeSchema</code> node associated with this
095     * attribute
096     * 
097     * @return XML node of <code>AttributeSchema</code>
098     */
099    public final Node getAttributeSchemaNode() {
100        return (parentNode);
101    }
102
103    /**
104     * Set the <code>AttributeSchema</code> for which the default values are
105     * being obtained
106     */
107    final void setAttributeSchema(AttributeSchemaImpl as) {
108        attributeSchema = as;
109    }
110
111    /**
112     * Sets the key-values pairs configured for this object
113     */
114    final void setKeyValues(Node node) {
115        keyValues = CreateServiceConfig.getAttributeValuePairs(node);
116    }
117
118    /**
119     * Sets the <code>AttributeSchema</code> node of the XML schema
120     */
121    final void setParentNode(Node n) {
122        parentNode = n;
123    }
124
125    // Pointer to AttributeSchema, key-value pairs and parent node
126    AttributeSchemaImpl attributeSchema;
127
128    Map<String, Set<String>> keyValues;
129
130    Node parentNode;
131}