<commit_before>/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *  
 *    http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License. 
 *  
 */
package org.apache.directory.server.core.configuration;


import java.io.Serializable;
import java.util.Hashtable;

import org.apache.directory.server.core.DirectoryService;


/**
 * A configuration that provides required, optional, or default properties
 * to configure {@link DirectoryService}.
 *
 * @author <a href="mailto:<EMAIL>">Apache Directory Project</a>
 * @version $Rev$, $Date$
 */
public abstract class Configuration implements Cloneable, Serializable
{
    /**
     * A JNDI environment key that configuration instance is put on. 
     */
    public static final String JNDI_KEY = Configuration.class.getName();

    /**
     * The default ID of {@link DirectoryService} that is used
     * when no instance ID is specified. 
     */
    public static final String DEFAULT_INSTANCE_ID = "default";


    /**
     * Gets {@link Configuration} instance from the specified JNDI environment
     * {@link Hashtable}.
     * 
     * @throws ConfigurationException if the specified environment doesn't
     *                                contain the configuration instance.
     */
    public static Configuration toConfiguration( Hashtable jndiEnvironment )
    {
        Object value = jndiEnvironment.get( JNDI_KEY );
        if ( value == null || !( value instanceof Configuration ) )
        {
            throw new ConfigurationException( "Not an ApacheDS configuration: " + value );
        }

        return ( Configuration ) value;
    }

    private String instanceId = DEFAULT_INSTANCE_ID;


    /**
     * Creates a new instance.
     */
    protected Configuration()
    {
    }


    /**
     * Returns the ID of {@link DirectoryService} instance to configure.
     */
    public String getInstanceId()
    {
        return instanceId;
    }


    /**<commit_msg>Fix for DIRSERVER-291: If configuration object is missing in env to startup server a default StartupConfiguration can be presumed.<commit_after>/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *  
 *    http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License. 
 *  
 */
package org.apache.directory.server.core.configuration;


import java.io.Serializable;
import java.util.Hashtable;

import org.apache.directory.server.core.DirectoryService;


/**
 * A configuration that provides required, optional, or default properties
 * to configure {@link DirectoryService}.
 *
 * @author <a href="mailto:<EMAIL>">Apache Directory Project</a>
 * @version $Rev$, $Date$
 */
public abstract class Configuration implements Cloneable, Serializable
{
    /**
     * A JNDI environment key that configuration instance is put on. 
     */
    public static final String JNDI_KEY = Configuration.class.getName();

    /**
     * The default ID of {@link DirectoryService} that is used
     * when no instance ID is specified. 
     */
    public static final String DEFAULT_INSTANCE_ID = "default";


    /**
     * Gets {@link Configuration} instance from the specified JNDI environment
     * {@link Hashtable}.  If a configuration instance is not present the default
     * StartupConfiguration is returned and injected into the environment.
     * 
     * @throws ConfigurationException if the specified environment doesn't
     *                                contain the proper configuration instance.
     */
    public static Configuration toConfiguration( Hashtable jndiEnvironment )
    {
        Object value = jndiEnvironment.get( JNDI_KEY );
        
        if ( value == null )
        {
            MutableStartupConfiguration msc = new MutableStartupConfiguration();
            jndiEnvironment.put( JNDI_KEY, msc );
            return msc;
        }
        
        if ( !( value instanceof Configuration ) )
        {
            throw new ConfigurationException( "Not an ApacheDS configuration: " + value );
        }

        return ( Configuration ) value;
    }

    private String instanceId = DEFAULT_INSTANCE_ID;


    /**
     * Creates a new instance.
     */
    protected Configuration()
    {
    }


    /**
     * Returns the ID of {@link DirectoryService} instance to configure.
     */
    public String getInstanceId()
    {
        return instanceId;
    }


    /**
{'fraction_non_alphanumeric': 0.07801047120418848, 'fraction_numerical': 0.0019197207678883072, 'mean_word_length': 2.758032786885246, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4157893', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1418, 'n_words': 564}