Package org.apache.avalon.framework.configuration

Examples of org.apache.avalon.framework.configuration.ConfigurationException


        final DelegateEntry entry = (DelegateEntry)m_delegates.get( schemaType );
        if( entry == null )
        {
            final String msg = "Invalid schema type: " + schemaType +
                ". Validator only supports: " + m_supportedTypes;
            throw new ConfigurationException( msg );
        }

        return entry.getValidatorFactory().createValidator( schemaType, schema );
    }
View Full Code Here


            return result;
        }
        catch( final VerifierConfigurationException e )
        {
            final String message = "Unable to verify configuration";
            throw new ConfigurationException( message, e );
        }
        catch( final SAXException e )
        {
            final String message = "Unable to parse configuration";
            throw new ConfigurationException( message, e );
        }
        catch( final IllegalStateException e )
        {
            final String message = "Unable to parse configuration";
            throw new ConfigurationException( message, e );
        }
    }
View Full Code Here

        {
            contextClass = loader.loadClass( contextClassName );
        }
        catch( ClassNotFoundException cnfe )
        {
            throw new ConfigurationException(
                "Could not find context class " + contextClassName, cnfe );
        }

        Map map = new Hashtable();
        Context context = null;
        try
        {
            Constructor constructor = contextClass.getConstructor(
                new Class[]{Map.class, Context.class} );
            context = (Context)constructor.newInstance( new Object[]{map, parent} );
        }
        catch( Throwable e )
        {
            throw new ConfigurationException(
                "Unexpected exception while creating custom context form "
                + contextClassName, e );
        }

        final Configuration[] entrys = config.getChildren( "entry" );

        for( int i = 0; i < entrys.length; i++ )
        {
            final String className = entrys[ i ].getAttribute(
                "type", "java.lang.String" );
            final String paramName = entrys[ i ].getAttribute(
                "name", null );

            if( paramName == null )
            {
                throw new ConfigurationException(
                    "missing name for context-entry" );
            }

            try
            {
                Class[] params;
                Object[] values;
                Configuration entry = entrys[ i ];

                if( entry.getAttribute( "value", null ) != null )
                {
                    // Single argument String-constructor
                    params = new Class[ 1 ];
                    params[ 0 ] = Class.forName( "java.lang.String" );
                    Class[] consObjects = {Class.forName( "java.lang.String" )};
                    Constructor cons = params[ 0 ].getConstructor( consObjects );
                    values = new Object[ 1 ];
                    Object[] consValues = {
                        getContextValue( map, entry.getAttribute( "value" ) )
                    };
                    values[ 0 ] = cons.newInstance( consValues );

                    if( log != null )
                    {
                        log.debug( "add context-attr '" + paramName
                                   + "' class '" + className
                                   + "' with value '" + consValues[ 0 ] + "'" );
                    }
                }
                else
                {
                    // Multiple argument constructor
                    Configuration[] entryChilds = entry.getChildren( "parameter" );

                    params = new Class[ entryChilds.length ];
                    values = new Object[ entryChilds.length ];

                    if( log != null )
                    {
                        log.debug( "add context-attr '" + paramName
                                   + "' class '" + className + "' with "
                                   + entryChilds.length + " values" );
                    }

                    for( int p = 0; p < entryChilds.length; p++ )
                    {
                        String paramClassName = entryChilds[ p ].getAttribute(
                            "type", "java.lang.String" );
                        String paramValue = entryChilds[ p ].getAttribute( "value", null );

                        if( paramValue == null )
                        {
                            if( log != null )
                            {
                                log.debug( "value" + ( p + 1 ) + ": class '"
                                           + paramClassName + "' no value" );
                            }
                        }
                        else
                        {
                            paramValue = getContextValue( map, paramValue );
                            if( log != null )
                            {
                                log.debug( "value" + ( p + 1 ) + ": class '"
                                           + paramClassName + "' value '" + paramValue + "'" );
                            }
                        }

                        try
                        {
                            params[ p ] = loader.loadClass( paramClassName );

                            if( paramValue == null )
                            {
                                values[ p ] = params[ p ].newInstance();
                            }
                            else
                            {
                                Class[] consObjects = {Class.forName( "java.lang.String" )};
                                Constructor cons = params[ p ].getConstructor( consObjects );
                                Object[] consValues = {paramValue};
                                values[ p ] = cons.newInstance( consValues );
                            }
                        }
                        catch( ClassNotFoundException e )
                        {
                            // Class not found
                            // -> perhaps a primitve class?
                            if( paramClassName.equals( "int" ) )
                            {
                                params[ p ] = int.class;
                                values[ p ] = new Integer( paramValue );
                            }
                            else if( paramClassName.equals( "short" ) )
                            {
                                params[ p ] = short.class;
                                values[ p ] = new Short( paramValue );
                            }
                            else if( paramClassName.equals( "long" ) )
                            {
                                params[ p ] = long.class;
                                values[ p ] = new Long( paramValue );
                            }
                            else if( paramClassName.equals( "byte" ) )
                            {
                                params[ p ] = byte.class;
                                values[ p ] = new Byte( paramValue );
                            }
                            else if( paramClassName.equals( "double" ) )
                            {
                                params[ p ] = double.class;
                                values[ p ] = new Double( paramValue );
                            }
                            else if( paramClassName.equals( "float" ) )
                            {
                                params[ p ] = float.class;
                                values[ p ] = new Float( paramValue );
                            }
                            else if( paramClassName.equals( "char" ) )
                            {
                                params[ p ] = char.class;
                                values[ p ] = new Character( paramValue.charAt( 0 ) );
                            }
                            else if( paramClassName.equals( "boolean" ) )
                            {
                                params[ p ] = boolean.class;
                                values[ p ] = new Boolean( paramValue );
                            }
                            else
                            {
                                throw new ConfigurationException(
                                    "incorrect type '" + paramClassName
                                    + "' for context-attribute '" + paramName + "'", e );
                            }
                        }
                    }
                }

                Class paramClass;
                try
                {
                    paramClass = loader.loadClass( className );
                }
                catch( final ClassNotFoundException e )
                {
                    throw new ConfigurationException(
                        "incorrect type '" + className
                        + "' for context-attribute '" + paramName + "'",
                        e );
                }

                Object paramInstance;

                if( params.length > 0 )
                {
                    // using param contructor
                    Constructor cons = paramClass.getConstructor( params );
                    paramInstance = cons.newInstance( values );
                }
                else
                {
                    // using default constructor
                    paramInstance = paramClass.newInstance();
                }

                map.put( paramName, paramInstance );
            }
            catch( ConfigurationException e )
            {
                throw e;
            }
            catch( Exception e )
            {
                throw new ConfigurationException(
                    "Error add context-attribute '" + paramName
                    + "' from Configuration", e );
            }
        }
        return context;
View Full Code Here

            int k = rawValue.indexOf( '}', j );
            final String ctxName = rawValue.substring( j + 2, k );
            final Object ctx = map.get( ctxName );
            if( ctx == null )
            {
                throw new ConfigurationException(
                    "missing entry '" + ctxName + "' in Context" );
            }
            result.append( ctx.toString() );
            i = k + 1;
        }
View Full Code Here

        if( ( null == m_schemaLanguage && null == m_verifierFactoryClass )
            || ( null != m_schemaLanguage && null != m_verifierFactoryClass ) )
        {
            final String msg = "Must specify either schema-language or verifier-factory-class";

            throw new ConfigurationException( msg );
        }
    }
View Full Code Here

        if( !m_schemaType.equals( schemaType ) )
        {
            final String msg = "Invalid schema type: " + schemaType
                + ". Validator only supports " + m_schemaType;

            throw new ConfigurationException( msg );
        }

        try
        {
            return new JarvConfigurationValidator(
                m_verifierFactory.compileSchema( schema ) );
        }
        catch( VerifierConfigurationException e )
        {
            final String msg = "Unable to create schema";

            throw new ConfigurationException( msg, e );
        }
        catch( SAXParseException e )
        {
            final String msg = "Unable to parse schema [line: " + e.getLineNumber()
                + ", column: " + e.getColumnNumber()
                + ", msg: " + e.getMessage() + "]";

            throw new ConfigurationException( msg, e );
        }
        catch( Exception e )
        {
            final String msg = "Unable to parse schema [url: " + schema
                + ", msg: " + e.getMessage() + "]";

            throw new ConfigurationException( msg, e );
        }
    }
View Full Code Here

            {
                return baseKids[ 0 ];
            }
            else
            {
                throw new ConfigurationException( "Unable to merge configuration item, "
                                                  + "multiple matches on child or base [name: "
                                                  + toMerge.getName() + "]" );
            }
        }
View Full Code Here

                {
                    mergedWith = matches[ 0 ];
                }
                else
                {
                    throw new ConfigurationException( "Multiple children in base with name '"
                                                      + name + "' and attr '" + keyAttr
                                                      + " = " + keyValue + "'" );
                }
            }
View Full Code Here

                    {
                        uniqueAttr = attr;
                    }
                    else
                    {
                        throw new ConfigurationException( "Multiple unique attributes for child "
                                                          + "[name: " + c[ 0 ].getName()
                                                          + ", unique1: " + uniqueAttr
                                                          + ", unique2: " + attr + "]" );
                    }
                }
                else
                {
                    testedAttributes.add( attr );
                }
            }
        }

        if( null == uniqueAttr )
        {
            throw new ConfigurationException( "Unable to find unique attribute for "
                                              + "children of name: " + c[ 0 ].getName() );
        }

        return uniqueAttr;
    }
View Full Code Here

                getLogger().info("No maximum message size is enforced for this server.");
            }
            // How many bytes to read before updating the timer that data is being transfered
            lengthReset = configuration.getChild("lengthReset").getValueAsInteger(lengthReset);
            if (lengthReset <= 0) {
                throw new ConfigurationException("The configured value for the idle timeout reset, " + lengthReset + ", is not valid.");
            }
            if (getLogger().isInfoEnabled()) {
                getLogger().info("The idle timeout will be reset every " + lengthReset + " bytes.");
            }
        } else {
View Full Code Here

TOP

Related Classes of org.apache.avalon.framework.configuration.ConfigurationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.