Package org.apache.avalon.framework.service

Examples of org.apache.avalon.framework.service.ServiceException


{
    private static final String MESSAGE = "Could not return a reference to the Component";

    public Object lookup( String role ) throws ServiceException
    {
        throw new ServiceException(role, MESSAGE);
    }
View Full Code Here


        }

        if ( !( result instanceof ComponentHandler ) )
        {
            final String message = "Invalid entry in component manager";
            throw new ServiceException( role, message );
        }

        try
        {
            final ComponentHandler handler = (ComponentHandler) result;
            final Object component = handler.get();

            m_used.put( new ComponentKey( component ), handler );
            return component;
        }
        catch ( final ServiceException ce )
        {
            throw ce; // rethrow
        }
        catch ( final Exception e )
        {
            final String message =
                "Could not return a reference to the Component";
            throw new ServiceException( role, message, e );
        }
    }
View Full Code Here

        }
        catch ( final Exception e )
        {
            final String name = m_key + "/" + hint.toString();
            final String message = "Could not return a reference to the Component";
            throw new ServiceException( name, message, e );
        }
    }
View Full Code Here

            (ComponentHandler) m_container.get( m_key, hint );
        if ( null == handler )
        {
            final String message =
                "The hint does not exist in the ComponentSelector";
            throw new ServiceException( m_key + "/" + hint.toString(),
                message );
        }
        return handler;
    }
View Full Code Here

                {
                    proxy.setType( DefaultInstrumentManager.INSTRUMENT_TYPE_VALUE );
                }
                else
                {
                    throw new ServiceException( fullInstrumentName, "Encountered an unknown "
                        + "Instrument type for the Instrument with key, "
                        + fullInstrumentName + ": " + instrument.getClass().getName() );
                }

                // Mark the instrument proxy as registered.
                proxy.setRegistered();
               
                // Store a reference to the proxy in the Instrument.
                ( (AbstractInstrument)instrument ).setInstrumentProxy( proxy );

                instrumentableProxy.addInstrumentProxy( proxy );
            }
            else
            {
                // Register the existing proxy with the Instrument.  Make sure that the
                //  type didn't change on us.
                if( instrument instanceof CounterInstrument )
                {
                    switch( proxy.getType() )
                    {
                        case DefaultInstrumentManager.INSTRUMENT_TYPE_COUNTER:
                            // Type is the same.
                            // Store a reference to the proxy in the Instrument.
                            ( (AbstractInstrument)instrument ).setInstrumentProxy( proxy );
                            break;

                        case DefaultInstrumentManager.INSTRUMENT_TYPE_NONE:
                            // Not yet set.  Created in configuration.
                            proxy.setType( DefaultInstrumentManager.INSTRUMENT_TYPE_COUNTER );

                            // Store a reference to the proxy in the Instrument.
                            ( (AbstractInstrument)instrument ).setInstrumentProxy( proxy );
                            break;

                        default:
                            throw new ServiceException( instrumentName,
                                "Instruments of more than one type are assigned to name: "
                                + instrumentName );
                    }
                }
                else if( instrument instanceof ValueInstrument )
                {
                    switch( proxy.getType() )
                    {
                        case DefaultInstrumentManager.INSTRUMENT_TYPE_VALUE:
                            // Type is the same.
                            // Store a reference to the proxy in the Instrument.
                            ( (AbstractInstrument)instrument ).setInstrumentProxy( proxy );
                            break;

                        case DefaultInstrumentManager.INSTRUMENT_TYPE_NONE:
                            // Not yet set.  Created in configuration.
                            proxy.setType( DefaultInstrumentManager.INSTRUMENT_TYPE_VALUE );

                            // Store a reference to the proxy in the Instrument.
                            ( (AbstractInstrument)instrument ).setInstrumentProxy( proxy );
                            break;

                        default:
                            throw new ServiceException( instrumentName,
                                "Instruments of more than one type are assigned to name: "
                                + instrumentName );
                    }
                }
                else
                {
                    throw new ServiceException( instrumentName, "Encountered an unknown Instrument "
                        + "type for the Instrument with name, " + instrumentName + ": "
                        + instrument.getClass().getName() );
                }
               
                // Mark the instrument proxy as registered.
                proxy.setRegistered();
            }
        }

        // Loop over the child Instrumentables published by this Instrumentable
        Instrumentable[] children = instrumentable.getChildInstrumentables();
        for ( int i = 0; i < children.length; i++ )
        {
            Instrumentable child = children[i];
           
            // Make sure that the child instrumentable name is set.
            String childName = child.getInstrumentableName();
            if( childName == null )
            {
                String msg = "The getInstrumentableName() method of a child Instrumentable of " +
                    instrumentableName + " returned null.  Child class: " +
                    child.getClass().getName();
                getLogger().debug( msg );
                throw new ServiceException( instrumentable.getClass().getName(), msg );
            }
           
            String fullChildName = instrumentableName + "." + childName;
           
            getLogger().debug( "Registering Child Instrumentable: " + fullChildName );
View Full Code Here

            {
                return m_component;
            }
        }

        throw new ServiceException( m_key, "Unexpected key/hint combo" );
    }
View Full Code Here

                        m_constructorArguments[i] = component;
                        m_serviceManager.release(component);
                    }
                    catch (Exception e)
                    {
                        throw new ServiceException("ComponentFactory",
                                         "Unknown parameter type for constructor of component: " + current, e);
                    }
                }
            }
View Full Code Here

    public void initialize(ComponentHandler handler)
    throws Exception
    {
        if ( this.initialized )
        {
            throw new ServiceException(this.toString(), "Handable component is already initialized.");
        }
        if ( handler == null )
        {
            throw new ServiceException(this.toString(), "Handler is required.");
        }
        this.handler = handler;
        this.initialized = true;
    }
View Full Code Here

        }

        if ( !( result instanceof ComponentHandler ) )
        {
            final String message = "Invalid entry in component manager";
            throw new ServiceException( role, message );
        }

        try
        {
            final ComponentHandler handler = (ComponentHandler) result;
            final Object component = handler.get();

            // we only have to keep track of components that don't implement
            // the ReleasableComponent interface
            if ( !(component instanceof ReleasableComponent) )
            {
                m_used.put( new ComponentKey( component ), handler );
            }
            return component;
        }
        catch ( final ServiceException ce )
        {
            throw ce; // rethrow
        }
        catch ( final Exception e )
        {
            final String message =
                "Could not return a reference to the Component";
            throw new ServiceException( role, message, e );
        }
    }
View Full Code Here

        }
        catch ( final Exception e )
        {
            final String name = m_key + "/" + String.valueOf(hint);
            final String message = "Could not return a reference to the Component";
            throw new ServiceException( name, message, e );
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.avalon.framework.service.ServiceException

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.