Package org.apache.avalon.framework.component

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


                              final Configuration configuration )
        throws ComponentException
    {
        if( m_initialized )
        {
            throw new ComponentException( role,
                "Cannot add components to an initialized ComponentLocator" );
        }

        try
        {
            if( getLogger().isDebugEnabled() )
            {
                getLogger().debug( "Attempting to get Handler for role [" + role + "]" );
            }

            final ComponentHandler handler = getComponentHandler( role,
                                                                  component,
                                                                  configuration,
                                                                  m_context,
                                                                  m_roles,
                                                                  m_logkit );

            if( getLogger().isDebugEnabled() )
            {
                getLogger().debug( "Handler type = " + handler.getClass().getName() );
            }

            handler.setLogger( getLogkitLogger() );
            handler.enableLogging( getLogger() );
            m_componentHandlers.put( role, handler );
            m_newComponentHandlers.add( handler );
        }
        catch( final Exception e )
        {
            throw new ComponentException( role, "Could not set up Component.", e );
        }
    }
View Full Code Here


            return this.manager.lookup(roleName);
        }
        catch( Exception e )
        {
            String msg = "Failed to lookup role " + roleName;
            throw new ComponentException(roleName,msg,e);
        }
    }
View Full Code Here

        this.manager = manager;

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

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

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

            this.manager2.addComponentInstance(Selector.ROLE + "Selector", this.modeMapping);
            this.manager2.addComponentInstance(Selector.ROLE + "Selector", this.outputMapping);
        } catch (Exception e) {
            if (getLogger().isDebugEnabled())
                getLogger().error("cannot obtain the Component", e);
            throw new ComponentException("cannot obtain the URLFactory", e);
        }
    }
View Full Code Here

        }

        final Component component = super.lookup( role );
        if ( null != component && component instanceof RequestLifecycleComponent) {
            if ( stack == null || stack.empty() ) {
                throw new ComponentException("ComponentManager has no Environment Stack.");
            }
            final Object[] objects = (Object[]) stack.peek();
            final Map components = (Map)objects[2];
            try {
                if (component instanceof Recomposable) {
                    ((Recomposable) component).recompose(this);
                }
                ((RequestLifecycleComponent) component).setup( (SourceResolver)objects[0],
                                                               (Map)objects[1]);
            } catch (Exception local) {
                throw new ComponentException("Exception during setup of RequestLifecycleComponent with role '"+role+"'", local);
            }
            components.put( role, new Object[] {component, this});
        }
        return component;
    }
View Full Code Here

        throws ComponentException {
        super.compose(componentManager);
        UsersStore usersStore = (UsersStore)componentManager.lookup(UsersStore.ROLE);
        userRepository = usersStore.getRepository("LocalUsers");
        if (userRepository == null) {
            throw new ComponentException("The user repository could not be found.");
        }

        repo = (NNTPRepository)componentManager
            .lookup("org.apache.james.nntpserver.repository.NNTPRepository");
View Full Code Here

            lookup( "org.apache.james.services.MailServer" );
        UsersStore usersStore = (UsersStore)componentManager.
            lookup( "org.apache.james.services.UsersStore" );
        users = usersStore.getRepository("LocalUsers");
        if (users == null) {
            throw new ComponentException("The user repository could not be found.");
        }
    }
View Full Code Here

                lookup( "org.apache.james.services.UsersStore" );
        users = usersStore.getRepository( "LocalUsers" );
        imapHost = ( ImapHost ) componentManager.
                lookup( "org.apache.james.imapserver.ImapHost" );
        if ( users == null ) {
            throw new ComponentException( "The user repository could not be found." );
        }
    }
View Full Code Here

    public synchronized Component select(Object hint) throws ComponentException {
        Configuration repConf = null;
        try {
            repConf = (Configuration) hint;
        } catch (ClassCastException cce) {
            throw new ComponentException(
                "hint is of the wrong type. Must be a Configuration", cce);
        }
        String destination = null;
        String protocol = null;
        try {
            destination = repConf.getAttribute("destinationURL");
            int idx = destination.indexOf(':');
            if ( idx == -1 )
                throw new ComponentException(
                    "destination is malformed. Must be a valid URL: "
                    + destination);
            protocol = destination.substring(0,idx);
        } catch (ConfigurationException ce) {
            throw new ComponentException(
                "Malformed configuration has no destinationURL attribute", ce);
        }

        try
        {
            String type = repConf.getAttribute("type");
            String repID = destination + type;
            MailRepository reply = (MailRepository) repositories.get(repID);
            StringBuffer logBuffer = null;
            if (reply != null) {
                if (getLogger().isDebugEnabled()) {
                    logBuffer =
                        new StringBuffer(128)
                                .append("obtained repository: ")
                                .append(repID)
                                .append(",")
                                .append(reply.getClass());
                    getLogger().debug(logBuffer.toString());
                }
                return (Component)reply;
            } else {
                String key = protocol + type;
                String repClass = (String) classes.get( key );

                if (getLogger().isDebugEnabled()) {
                    logBuffer =
                        new StringBuffer(128)
                                .append("obtained repository: ")
                                .append(repClass)
                                .append(" to handle: ")
                                .append(protocol)
                                .append(",")
                                .append(type);
                    getLogger().debug( logBuffer.toString() );
                }

                // If default values have been set, create a new repository
                // configuration element using the default values
                // and the values in the selector.
                // If no default values, just use the selector.
                Configuration config;
                Configuration defConf = (Configuration)defaultConfigs.get(key);
                if ( defConf == null) {
                    config = repConf;
                }
                else {
                    config = new DefaultConfiguration(repConf.getName(),
                                                      repConf.getLocation());
                    copyConfig(defConf, (DefaultConfiguration)config);
                    copyConfig(repConf, (DefaultConfiguration)config);
                }

                try {
                    reply = (MailRepository) this.getClass().getClassLoader().loadClass(repClass).newInstance();
                    if (reply instanceof LogEnabled) {
                       setupLogger(reply);
                    }
                    if (reply instanceof Contextualizable) {
                        ((Contextualizable) reply).contextualize(context);
                    }
                    if (reply instanceof Composable) {
                        ((Composable) reply).compose( componentManager );
                    }
                    if (reply instanceof Configurable) {
                        ((Configurable) reply).configure(config);
                    }
                    if (reply instanceof Initializable) {
                        ((Initializable) reply).initialize();
                    }
                    repositories.put(repID, reply);
                    if (getLogger().isInfoEnabled()) {
                        logBuffer =
                            new StringBuffer(128)
                                .append("added repository: ")
                                .append(repID)
                                .append("->")
                                .append(repClass);
                        getLogger().info(logBuffer.toString());
                    }
                    return (Component)reply;
                } catch (Exception e) {
                    if (getLogger().isWarnEnabled()) {
                        getLogger().warn( "Exception while creating repository:" +
                                          e.getMessage(), e );
                    }
                    e.printStackTrace();
                    throw new
                        ComponentException("Cannot find or init repository",
                                           e);
                }
            }
        } catch( final ConfigurationException ce ) {
            throw new ComponentException( "Malformed configuration", ce );
        }
    }
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.