<commit_before>package org.codehaus.xfire.aegis.type;

import java.math.BigDecimal;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;

import javax.xml.namespace.QName;

import org.codehaus.xfire.AbstractXFireComponent;
import org.codehaus.xfire.aegis.type.basic.Base64Type;
import org.codehaus.xfire.aegis.type.basic.BigDecimalType;
import org.codehaus.xfire.aegis.type.basic.BooleanType;
import org.codehaus.xfire.aegis.type.basic.CalendarType;
import org.codehaus.xfire.aegis.type.basic.DateTimeType;
import org.codehaus.xfire.aegis.type.basic.DoubleType;
import org.codehaus.xfire.aegis.type.basic.FloatType;
import org.codehaus.xfire.aegis.type.basic.IntType;
import org.codehaus.xfire.aegis.type.basic.LongType;
import org.codehaus.xfire.aegis.type.basic.ShortType;
import org.codehaus.xfire.aegis.type.basic.StringType;
import org.codehaus.xfire.aegis.type.basic.TimeType;
import org.codehaus.xfire.aegis.type.basic.TimestampType;
import org.codehaus.xfire.soap.Soap11;
import org.codehaus.xfire.soap.SoapConstants;
import org.codehaus.xfire.util.ClassLoaderUtils;

/**
 * The default implementation of TypeMappingRegistry.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @since Feb 22, 2004
 */
public class DefaultTypeMappingRegistry
        extends AbstractXFireComponent
        implements TypeMappingRegistry
{
    private static final QName XSD_STRING = new QName(SoapConstants.XSD, "string");
    private static final QName XSD_LONG = new QName(SoapConstants.XSD, "long");
    private static final QName XSD_FLOAT = new QName(SoapConstants.XSD, "float");
    private static final QName XSD_DOUBLE = new QName(SoapConstants.XSD, "double");
    private static final QName XSD_INT = new QName(SoapConstants.XSD, "int");
    private static final QName XSD_SHORT = new QName(SoapConstants.XSD, "short");
    private static final QName XSD_BOOLEAN = new QName(SoapConstants.XSD, "boolean");
    private static final QName XSD_DATETIME = new QName(SoapConstants.XSD, "dateTime");
    private static final QName XSD_TIME = new QName(SoapConstants.XSD, "dateTime");
    private static final QName XSD_BASE64 = new QName(SoapConstants.XSD, "base64Binary");
    private static final QName XSD_DECIMAL = new QName(SoapConstants.XSD, "decimal");

    private static final String ENCODED_NS = Soap11.getInstance().getSoapEncodingStyle();
    private static final QName ENCODED_STRING = new QName(ENCODED_NS, "string");
    private static final QName ENCODED_LONG = new QName(ENCODED_NS, "long");
    private static final QName ENCODED_FLOAT = new QName(ENCODED_NS, "float");
    private static final QName ENCODED_DOUBLE = new QName(ENCODED_NS, "double");
    private static final QName ENCODED_INT = new QName(ENCODED_NS, "int");
    private static final QName ENCODED_SHORT = new QName(ENCODED_NS, "short");
    private static final QName ENCODED_BOOLEAN = new QName(ENCODED_NS, "boolean");
    private static final QName ENCODED_DATETIME = new QName(ENCODED_NS, "dateTime");
    private static final QName ENCODED_BASE64 = new QName(ENCODED_NS, "base64Binary");
    private static final QName ENCODED_DECIMAL = new QName(ENCODED_NS, "decimal");

    private Hashtable registry;

    private TypeMapping defaultTM;

    public DefaultTypeMappingRegistry()
    {
        registry = new Hashtable();
    }

    public DefaultTypeMappingRegistry(boolean createDefault)
    {
        registry = new Hashtable();

        if (createDefault)
        {
            createDefaultMappings();
        }
    }

    public TypeMapping register(String encodingStyleURI, TypeMapping mapping)
    {
        TypeMapping previous = (TypeMapping) registry.get(encodingStyleURI);

        mapping.setEncodingStyleURI(encodingStyleURI);

        registry.put(encodingStyleURI, mapping);

        return previous;
    }

    public void registerDefault(TypeMapping mapping)
    {
        defaultTM = mapping;
    }

    /**
     * @see org.codehaus.xfire.aegis.type.TypeMappingRegistry#getDefaultTypeMapping()
     */
    public TypeMapping getDefaultTypeMapping()
    {
        return defaultTM;
    }

    /**
     * @see org.codehaus.xfire.aegis.type.TypeMappingRegistry#getRegisteredEncodingStyleURIs()
     */
    public String[] getRegisteredEncodingStyleURIs()
    {
        return (String[]) registry.keySet().toArray(new String[0]);
    }

    /**
     * @see org.codehaus.xfire.aegis.type.TypeMappingRegistry#getTypeMapping(java.lang.String)
     */
    public TypeMapping getTypeMapping(String encodingStyleURI)
    {
        return (TypeMapping) registry.get(encodingStyleURI);
    }

    /**
     * @see org.codehaus.xfire.aegis.type.TypeMappingRegistry#createTypeMapping(boolean)
     */
    public TypeMapping createTypeMapping(boolean autoTypes)
    {
        return createTypeMapping(getDefaultTypeMapping(), autoTypes);
    }

    /**
     * @see org.codehaus.xfire.aegis.type.TypeMappingRegistry#createTypeMapping(String, boolean)
     */
    public TypeMapping createTypeMapping(String parentNamespace, boolean autoTypes)
    {
        return createTypeMapping(getTypeMapping(parentNamespace), autoTypes);
    }

    protected TypeMapping createTypeMapping(TypeMapping parent, boolean autoTypes)
    {
        CustomTypeMapping tm = new CustomTypeMapping(parent);
        
        if (autoTypes) tm.setTypeCreator(createTypeCreator());
        
        return tm;
    }

    protected TypeCreator createTypeCreator()
    {
        AbstractTypeCreator xmlCreator = new XMLTypeCreator();
        xmlCreator.setNextCreator(new DefaultTypeCreator());
        try
        {
            String j5TC = "org.codehaus.xfire.aegis.type.java5.Java5TypeCreator";

            Class clazz = ClassLoaderUtils.loadClass(j5TC, getClass());
            
            AbstractTypeCreator j5Creator = (AbstractTypeCreator) clazz.newInstance();
            j5Creator.setNextCreator(xmlCreator);
            return j5Creator;
        }
        catch (Exception e)
        {
            return xmlCreator;<commit_msg>Attempt to make loading on < j5 work with the xfire-all jar.<commit_after>package org.codehaus.xfire.aegis.type;

import java.math.BigDecimal;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;

import javax.xml.namespace.QName;

import org.codehaus.xfire.AbstractXFireComponent;
import org.codehaus.xfire.aegis.type.basic.Base64Type;
import org.codehaus.xfire.aegis.type.basic.BigDecimalType;
import org.codehaus.xfire.aegis.type.basic.BooleanType;
import org.codehaus.xfire.aegis.type.basic.CalendarType;
import org.codehaus.xfire.aegis.type.basic.DateTimeType;
import org.codehaus.xfire.aegis.type.basic.DoubleType;
import org.codehaus.xfire.aegis.type.basic.FloatType;
import org.codehaus.xfire.aegis.type.basic.IntType;
import org.codehaus.xfire.aegis.type.basic.LongType;
import org.codehaus.xfire.aegis.type.basic.ShortType;
import org.codehaus.xfire.aegis.type.basic.StringType;
import org.codehaus.xfire.aegis.type.basic.TimeType;
import org.codehaus.xfire.aegis.type.basic.TimestampType;
import org.codehaus.xfire.soap.Soap11;
import org.codehaus.xfire.soap.SoapConstants;
import org.codehaus.xfire.util.ClassLoaderUtils;

/**
 * The default implementation of TypeMappingRegistry.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @since Feb 22, 2004
 */
public class DefaultTypeMappingRegistry
        extends AbstractXFireComponent
        implements TypeMappingRegistry
{
    private static final QName XSD_STRING = new QName(SoapConstants.XSD, "string");
    private static final QName XSD_LONG = new QName(SoapConstants.XSD, "long");
    private static final QName XSD_FLOAT = new QName(SoapConstants.XSD, "float");
    private static final QName XSD_DOUBLE = new QName(SoapConstants.XSD, "double");
    private static final QName XSD_INT = new QName(SoapConstants.XSD, "int");
    private static final QName XSD_SHORT = new QName(SoapConstants.XSD, "short");
    private static final QName XSD_BOOLEAN = new QName(SoapConstants.XSD, "boolean");
    private static final QName XSD_DATETIME = new QName(SoapConstants.XSD, "dateTime");
    private static final QName XSD_TIME = new QName(SoapConstants.XSD, "dateTime");
    private static final QName XSD_BASE64 = new QName(SoapConstants.XSD, "base64Binary");
    private static final QName XSD_DECIMAL = new QName(SoapConstants.XSD, "decimal");

    private static final String ENCODED_NS = Soap11.getInstance().getSoapEncodingStyle();
    private static final QName ENCODED_STRING = new QName(ENCODED_NS, "string");
    private static final QName ENCODED_LONG = new QName(ENCODED_NS, "long");
    private static final QName ENCODED_FLOAT = new QName(ENCODED_NS, "float");
    private static final QName ENCODED_DOUBLE = new QName(ENCODED_NS, "double");
    private static final QName ENCODED_INT = new QName(ENCODED_NS, "int");
    private static final QName ENCODED_SHORT = new QName(ENCODED_NS, "short");
    private static final QName ENCODED_BOOLEAN = new QName(ENCODED_NS, "boolean");
    private static final QName ENCODED_DATETIME = new QName(ENCODED_NS, "dateTime");
    private static final QName ENCODED_BASE64 = new QName(ENCODED_NS, "base64Binary");
    private static final QName ENCODED_DECIMAL = new QName(ENCODED_NS, "decimal");

    private Hashtable registry;

    private TypeMapping defaultTM;

    public DefaultTypeMappingRegistry()
    {
        registry = new Hashtable();
    }

    public DefaultTypeMappingRegistry(boolean createDefault)
    {
        registry = new Hashtable();

        if (createDefault)
        {
            createDefaultMappings();
        }
    }

    public TypeMapping register(String encodingStyleURI, TypeMapping mapping)
    {
        TypeMapping previous = (TypeMapping) registry.get(encodingStyleURI);

        mapping.setEncodingStyleURI(encodingStyleURI);

        registry.put(encodingStyleURI, mapping);

        return previous;
    }

    public void registerDefault(TypeMapping mapping)
    {
        defaultTM = mapping;
    }

    /**
     * @see org.codehaus.xfire.aegis.type.TypeMappingRegistry#getDefaultTypeMapping()
     */
    public TypeMapping getDefaultTypeMapping()
    {
        return defaultTM;
    }

    /**
     * @see org.codehaus.xfire.aegis.type.TypeMappingRegistry#getRegisteredEncodingStyleURIs()
     */
    public String[] getRegisteredEncodingStyleURIs()
    {
        return (String[]) registry.keySet().toArray(new String[0]);
    }

    /**
     * @see org.codehaus.xfire.aegis.type.TypeMappingRegistry#getTypeMapping(java.lang.String)
     */
    public TypeMapping getTypeMapping(String encodingStyleURI)
    {
        return (TypeMapping) registry.get(encodingStyleURI);
    }

    /**
     * @see org.codehaus.xfire.aegis.type.TypeMappingRegistry#createTypeMapping(boolean)
     */
    public TypeMapping createTypeMapping(boolean autoTypes)
    {
        return createTypeMapping(getDefaultTypeMapping(), autoTypes);
    }

    /**
     * @see org.codehaus.xfire.aegis.type.TypeMappingRegistry#createTypeMapping(String, boolean)
     */
    public TypeMapping createTypeMapping(String parentNamespace, boolean autoTypes)
    {
        return createTypeMapping(getTypeMapping(parentNamespace), autoTypes);
    }

    protected TypeMapping createTypeMapping(TypeMapping parent, boolean autoTypes)
    {
        CustomTypeMapping tm = new CustomTypeMapping(parent);
        
        if (autoTypes) tm.setTypeCreator(createTypeCreator());
        
        return tm;
    }

    protected TypeCreator createTypeCreator()
    {
        AbstractTypeCreator xmlCreator = new XMLTypeCreator();
        xmlCreator.setNextCreator(new DefaultTypeCreator());
        try
        {
            String j5TC = "org.codehaus.xfire.aegis.type.java5.Java5TypeCreator";

            Class clazz = ClassLoaderUtils.loadClass(j5TC, getClass());
            
            AbstractTypeCreator j5Creator = (AbstractTypeCreator) clazz.newInstance();
            j5Creator.setNextCreator(xmlCreator);
            return j5Creator;
        }
        catch (Throwable t)
        {
            return xmlCreator;
{'fraction_non_alphanumeric': 0.09636882904936761, 'fraction_numerical': 0.004651162790697674, 'mean_word_length': 3.7174749807544263, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1223167', 'n_tokens_mistral': 3804, 'n_tokens_neox': 3781, 'n_words': 761}