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: ChoiceValues.java,v 1.3 2008/06/25 05:44:03 qcheng Exp $
026 *
027 */
028
029package com.sun.identity.sm;
030
031import java.util.Map;
032import org.w3c.dom.Node;
033
034/**
035 * The abstract class <code>ChoiceValues</code> provides a mechanism for
036 * services to provide choice values for attributes dynamically instead of being
037 * statically defined in the service XML file stored in the directory.
038 * <p>
039 * An implementation of this class must be specified in the service
040 * configuration XML file in the definition of the respective attribute schema.
041 * Instead of providing the choice values in the XML configuration file, the
042 * class name must be specified within the XML node
043 * <code>ChoiceValuesClassName</code>.
044 *
045 * @supported.all.api
046 */
047public abstract class ChoiceValues {
048
049    /**
050     * Abstract method that must be implemented by a class extending this class,
051     * and should return the choice values and their corresponding I18N key, for
052     * the attribute.
053     * 
054     * @return choice values for the attribute as a <code>java.util.Map</code>.
055     *         Key being the choice and the value being the I18N key
056     */
057    public abstract Map getChoiceValues();
058
059    /**
060     * Returns the choice values for attribute for the given environment
061     * parameters. The default implementation calls the interface
062     * <code>getChoiceValues</code> without the parameter. A class extending
063     * this class can override this method to return the choice values and their
064     * corresponding I18N key, for the attribute.
065     * 
066     * @param envParams
067     *            environment parameters
068     * @return choice values for the attribute as a <code>java.util.Map</code>.
069     *         Key being the choice and the value being the I18N key
070     */
071    public Map getChoiceValues(Map envParams) {
072        return (getChoiceValues());
073    }
074
075    /**
076     * Returns the name of the attribute for which the choice values will be
077     * returned.
078     * 
079     * @return the name of attribute for which the choice values are returned
080     */
081    public final String getAttributeName() {
082        return (attributeSchema.getName());
083    }
084
085    /**
086     * Returns the configured key-value pairs for the class in the service's
087     * configuration file
088     * 
089     * @return key-value pairs configured for this class in the service schema
090     *         XML file
091     */
092    public final Map getConfiguredKeyValues() {
093        return (keyValues);
094    }
095
096    /**
097     * Returns the XML <code>AttributeSchema</code> node associated with this
098     * attribute
099     * 
100     * @return XML node of <code>AttributeSchema</code>
101     */
102    public final Node getAttributeSchemaNode() {
103        return (parentNode);
104    }
105
106    /**
107     * Set the <code>AttributeSchema</code> for which the choice values are
108     * being obtained
109     */
110    final void setAttributeSchema(AttributeSchemaImpl as) {
111        attributeSchema = as;
112    }
113
114    /**
115     * Sets the key-values pairs configured for this object
116     */
117    final void setKeyValues(Node node) {
118        keyValues = CreateServiceConfig.getAttributeValuePairs(node);
119    }
120
121    /**
122     * Sets the <code>AttributeSchema</code> node of the XML schema
123     */
124    final void setParentNode(Node n) {
125        parentNode = n;
126    }
127
128    // Pointer to AttributeSchema, key-value pairs and parent node
129    AttributeSchemaImpl attributeSchema;
130
131    Map keyValues;
132
133    Node parentNode;
134}