Package org.apache.avalon.framework.component

Examples of org.apache.avalon.framework.component.ComponentException


            store = (Store)componentManager.
                lookup( "org.apache.avalon.cornerstone.services.store.Store" );
        } catch (Exception e) {
            final String message = "Failed to retrieve Store component:" + e.getMessage();
            getLogger().error( message, e );
            throw new ComponentException( message, e );
        }
    }
View Full Code Here


            if( getLogger().isErrorEnabled() )
            {
                getLogger().error( message );
            }

            throw new ComponentException( message );
        }

        ComponentHandler handler = (ComponentHandler)m_componentHandlers.get( hint );

        // Retrieve the instance of the requested component
        if( null == handler )
        {
            final String message = getName()
                + ": ComponentSelector could not find the component for hint [" + hint + "]";
            if( getLogger().isDebugEnabled() )
            {
                getLogger().debug( message );
            }
            throw new ComponentException( hint.toString(), message );
        }

        Component component = null;

        try
        {
            component = handler.get();
        }
        catch( final ComponentException ce )
        {
            //rethrow
            throw ce;
        }
        catch( final Exception e )
        {
            final String message = getName()
                + ": ComponentSelector could not access the Component for hint [" + hint + "]";

            if( getLogger().isDebugEnabled() )
            {
                getLogger().debug( message, e );
            }
            throw new ComponentException( hint.toString(), message, e );
        }

        if( null == component )
        {
            final String message = getName()
                + ": ComponentSelector could not find the component for hint [" + hint + "]";
            if( getLogger().isDebugEnabled() )
            {
                getLogger().debug( message );
            }
            throw new ComponentException( hint.toString(), message );
        }

        m_componentMapping.put( component, handler );
        return component;
    }
View Full Code Here

                              final Configuration configuration )
        throws ComponentException
    {
        if( m_initialized )
        {
            throw new ComponentException( hint.toString(),
                "Cannot add components to an initialized ComponentSelector", null );
        }

        try
        {
            final ComponentHandler handler = getComponentHandler( m_rolename,
                                                                  component,
                                                                  configuration,
                                                                  m_componentManager,
                                                                  m_context,
                                                                  m_roles,
                                                                  m_logkit );

            handler.setLogger( getLogkitLogger() );
            handler.enableLogging( getLogger() );
            handler.initialize();
            m_componentHandlers.put( hint, handler );

            if( getLogger().isDebugEnabled() )
            {
                getLogger().debug(
                    "Adding " + component.getName() + " for hint [" + hint.toString() + "]" );
            }
        }
        catch( final Exception e )
        {
            final String message =
                "Could not set up Component for hint [ " + hint + "]";
            if( getLogger().isErrorEnabled() )
            {
                getLogger().error( message, e );
            }

            throw new ComponentException( hint.toString(), message, e );
        }
    }
View Full Code Here

     * @see org.apache.cocoon.components.ParentAware#setParentInformation(org.apache.avalon.framework.component.ComponentManager, java.lang.String)
     */
    public void setParentLocator(ComponentLocator locator)
    throws ComponentException {
        if (this.parentSelector != null) {
            throw new ComponentException(null, "Parent selector is already set");
        }
        this.parentLocator = locator;
        this.parentSelector = (ExtendedComponentSelector) locator.lookup();
    }
View Full Code Here

     */
    public Bundle select(String[] directories, String name, Locale locale)
            throws ComponentException {
        Bundle bundle = _select(directories, 0, name, locale);
        if (bundle == null) {
            throw new ComponentException(name, "Unable to locate resource: " + name);
        }
        return bundle;
    }
View Full Code Here

        this.manager = manager;

        try {
            this.classManager = (ClassLoaderManager) manager.lookup(ClassLoaderManager.ROLE);
        } catch (ComponentException cme) {
            throw new ComponentException(ClassLoaderManager.ROLE, "GeneratorSelector", cme);
        }

        try {
            this.classManager.addDirectory((File) this.m_context.get(Constants.CONTEXT_WORK_DIR));
        } catch (Exception e) {
            throw new ComponentException(ROLE, "Could not add repository to ClassLoaderManager", e);
        }
    }
View Full Code Here

    public Component select(Object hint) throws ComponentException {

        ComponentHandler handler = (ComponentHandler) this.componentHandlers.get(hint);
        if (handler == null) {
            throw new ComponentException(ROLE, "Could not find component for hint: " + hint);
        }

        try {
            Component component = handler.get();
            componentMapping.put(component, handler);
            return component;
        } catch (Exception ce) {
            if (getLogger().isDebugEnabled())
                getLogger().debug("Could not access component for hint: " + hint, ce);
            throw new ComponentException(ROLE, "Could not access component for hint: " + hint, ce);
        }
    }
View Full Code Here

        try {
            this.preparedPattern = matcher.preparePattern(this.pattern);

        } catch(PatternException pe) {
            String msg = "Invalid pattern '" + this.pattern + "' for matcher at " + this.getLocation();
            throw new ComponentException(null, msg, pe);

        } finally {
            if (this.threadSafeMatcher == null) {
                selector.release(matcher);
            }
View Full Code Here

        throws ComponentException
    {
        final Object component = m_application.getBlock( role );
        if( null == component )
        {
            throw new ComponentException( role, "Could not find component" );
        }
        return (Component)component;
    }
View Full Code Here

            if( getLogger().isErrorEnabled() )
            {
                getLogger().error( message );
            }
            throw new ComponentException( role, message );
        }

        ComponentHandler handler = (ComponentHandler)m_componentHandlers.get( role );

        // Retrieve the instance of the requested component
        if( null == handler )
        {
            if( m_parentManager != null )
            {
                try
                {
                    return m_parentManager.lookup( role );
                }
                catch( Exception e )
                {
                    if( getLogger().isWarnEnabled() )
                    {
                        final String message =
                            "ComponentLocator exception from parent CM during lookup.";
                        getLogger().warn( message, e );
                    }
                    // ignore.  If the exception is thrown, we try to
                    // create the component next
                }
            }

            if( null != m_roles )
            {
                final String className = m_roles.getDefaultClassNameForRole( role );

                if( null != className )
                {
                    if( getLogger().isDebugEnabled() )
                    {
                        getLogger().debug( "Could not find ComponentHandler, attempting to create "
                            + "one for role [" + role + "]" );
                    }

                    try
                    {
                        final Class componentClass = m_loader.loadClass( className );

                        final Configuration configuration = new DefaultConfiguration( "", "-" );

                        handler = getComponentHandler( role,
                                                       componentClass,
                                                       configuration,
                                                       m_context,
                                                       m_roles,
                                                       m_logkit );

                        handler.setLogger( getLogkitLogger() );
                        handler.enableLogging( getLogger() );
                        handler.initialize();
                    }
                    catch( final Exception e )
                    {
                        final String message = "Could not find component";
                        if( getLogger().isDebugEnabled() )
                        {
                            getLogger().debug( message + " for role: " + role, e );
                        }
                        throw new ComponentException( role, message, e );
                    }

                    m_componentHandlers.put( role, handler );
                }
            }
            else
            {
                getLogger().debug( "Component requested without a RoleManager set.\n"
                    + "That means setRoleManager() was not called during initialization." );
            }
        }

        if( null == handler )
        {
            final String message = "Could not find component";
            if( getLogger().isDebugEnabled() )
            {
                getLogger().debug( message + " for role: " + role );
            }
            throw new ComponentException( role, message );
        }

        Component component = null;

        try
        {
            component = handler.get();
        }
        catch( final IllegalStateException ise )
        {
            try
            {
                handler.initialize();
                component = handler.get();
            }
            catch( final ComponentException ce )
            {
                // Rethrow instead of wrapping a ComponentException with another one
                throw ce;
            }
            catch( final Exception e )
            {
                final String message = "Could not access the Component";
                if( getLogger().isDebugEnabled() )
                {
                    getLogger().debug( message + " for role [" + role + "]", e );
                }

                throw new ComponentException( role, message, e );
            }
        }
        catch( final Exception e )
        {
            final String message = "Could not access the Component";
            if( getLogger().isDebugEnabled() )
            {
                getLogger().debug( message + " for role [" + role + "]", e );
            }

            throw new ComponentException( role, message, e );
        }

        // Add a mapping between the component and its handler.
        //  In the case of a ThreadSafeComponentHandler, the same component will be mapped
        //  multiple times but because each put will overwrite the last, this is not a
View Full Code Here

TOP

Related Classes of org.apache.avalon.framework.component.ComponentException

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.