Package org.codehaus.plexus.component.repository.exception

Examples of org.codehaus.plexus.component.repository.exception.ComponentRepositoryException


        {
            componentDescriptor = PlexusTools.buildComponentDescriptor( configuration );
        }
        catch ( PlexusConfigurationException e )
        {
            throw new ComponentRepositoryException( "Cannot unmarshall component descriptor:", e );
        }

        addComponentDescriptor( componentDescriptor );
    }
View Full Code Here


        {
            validateComponentDescriptor( componentDescriptor );
        }
        catch ( ComponentImplementationNotFoundException e )
        {
            throw new ComponentRepositoryException( "Component descriptor validation failed: ", e );
        }

        String role = componentDescriptor.getRole();

        String roleHint = componentDescriptor.getRoleHint();

        if ( roleHint != null )
        {
            if ( componentDescriptors.containsKey( role ) )
            {
                ComponentDescriptor desc = (ComponentDescriptor) componentDescriptors.get( role );
                if ( desc.getRoleHint() == null )
                {
                    String message = "Component descriptor " + componentDescriptor.getHumanReadableKey() +
                        " has a hint, but there are other implementations that don't";
                    throw new ComponentRepositoryException( message );
                }
            }

            Map map = (Map) componentDescriptorMaps.get( role );

            if ( map == null )
            {
                map = new HashMap();

                componentDescriptorMaps.put( role, map );
            }

            map.put( roleHint, componentDescriptor );
        }
        else
        {
            if ( componentDescriptorMaps.containsKey( role ) )
            {
                String message = "Component descriptor " + componentDescriptor.getHumanReadableKey() +
                    " has no hint, but there are other implementations that do";
                throw new ComponentRepositoryException( message );
            }
            else if ( componentDescriptors.containsKey( role ) )
            {
                if ( !componentDescriptors.get( role ).equals( componentDescriptor ) )
                {
                    String message = "Component role " + role +
                        " is already in the repository and different to attempted addition of " +
                        componentDescriptor.getHumanReadableKey();
                    throw new ComponentRepositoryException( message );
                }
            }
        }

        try
        {
            compositionResolver.addComponentDescriptor( componentDescriptor );
        }
        catch ( CompositionException e )
        {
            throw new ComponentRepositoryException( e.getMessage(), e );
        }

        componentDescriptors.put( componentDescriptor.getComponentKey(), componentDescriptor );
       
        // We need to be able to lookup by role only (in non-collection situations), even when the
View Full Code Here

    public <T> void addComponentDescriptor( ComponentDescriptor<T> componentDescriptor ) throws ComponentRepositoryException
    {
        if ( disposed.get() )
        {
            throw new ComponentRepositoryException("ComponentRegistry has been disposed", componentDescriptor);
        }

        // verify the descriptor matches the role hint and type
        verifyComponentDescriptor( componentDescriptor );

        // Get the ComponentManagerFactory
        String instantiationStrategy = componentDescriptor.getInstantiationStrategy();
        if ( instantiationStrategy == null )
        {
            instantiationStrategy = DEFAULT_INSTANTIATION_STRATEGY;
        }
        ComponentManagerFactory componentManagerFactory = componentManagerFactories.get( instantiationStrategy );
        if ( componentManagerFactory == null )
        {
            throw new ComponentRepositoryException( "Unsupported instantiation strategy: " + instantiationStrategy,
                componentDescriptor );
        }

        // Get the LifecycleHandler
        LifecycleHandler lifecycleHandler;
        try
        {
            lifecycleHandler = lifecycleHandlerManager.getLifecycleHandler( componentDescriptor.getLifecycleHandler() );
        }
        catch ( UndefinedLifecycleHandlerException e )
        {
            throw new ComponentRepositoryException( "Undefined lifecycle handler: " + componentDescriptor.getLifecycleHandler(),
                componentDescriptor );
        }

        // Create the ComponentManager
        ComponentManager<T> componentManager = componentManagerFactory.createComponentManager( container,
View Full Code Here

    public <T> void addComponent( T instance, Class<?> type, String roleHint, ClassRealm realm ) throws ComponentRepositoryException
    {
        if ( disposed.get() )
        {
            throw new ComponentRepositoryException("ComponentRegistry has been disposed", type, roleHint, realm);
        }

        StaticComponentManager<T> componentManager = new StaticComponentManager<T>( container, instance, type, roleHint, realm );

        // verify descriptor is consistent
View Full Code Here

    private <T> void verifyComponentDescriptor( ComponentDescriptor<T> descriptor ) throws ComponentRepositoryException
    {
        ClassLoader classLoader = descriptor.getRealm();
        if ( classLoader == null)
        {
            throw new ComponentRepositoryException( "ComponentDescriptor realm is null", descriptor);
        }

        Class<?> implementationClass = descriptor.getImplementationClass();
        if (implementationClass.equals( Object.class ))
        {
            throw new ComponentRepositoryException( "ComponentDescriptor implementation class could not be loaded", descriptor);
        }

        String role = descriptor.getRole();
        if (role == null)
        {
            throw new ComponentRepositoryException( "ComponentDescriptor role is null", descriptor);
        }

        Class<?> roleClass;
        try
        {
            roleClass = classLoader.loadClass( role );
        }
        catch ( ClassNotFoundException e )
        {
            throw new ComponentRepositoryException( "ComponentDescriptor role class can not be loaded", descriptor);
        }

        if (!roleClass.isAssignableFrom( implementationClass ))
        {
            throw new ComponentRepositoryException( "ComponentDescriptor implementation class does not implement the role class:" +
                " implementationClass=" + implementationClass.getName() + " roleClass=" + roleClass.getName(),
                descriptor);
        }
    }
View Full Code Here

        {
            compositionResolver.addComponentDescriptor( componentDescriptor );
        }
        catch ( CompositionException e )
        {
            throw new ComponentRepositoryException( e.getMessage(), e );
        }
    }
View Full Code Here

        {
            componentDescriptor = PlexusTools.buildComponentDescriptor( configuration );
        }
        catch ( PlexusConfigurationException e )
        {
            throw new ComponentRepositoryException( "Cannot unmarshall component descriptor:", e );
        }

        componentDescriptor.setRealmId( classRealm.getId() );

        addComponentDescriptor( componentDescriptor );
View Full Code Here

        {
            validateComponentDescriptor( componentDescriptor );
        }
        catch ( ComponentImplementationNotFoundException e )
        {
            throw new ComponentRepositoryException( "Component descriptor validation failed: ", e );
        }

        Map maps = componentRealmDescriptorMaps.getRealmMap( componentDescriptor.getRealmId() );

        String role = componentDescriptor.getRole();

        String roleHint = componentDescriptor.getRoleHint();

        Map map = (Map) maps.get( role );

        if ( map == null )
        {
            map = new HashMap();

            maps.put( role, map );
        }

        map.put( roleHint, componentDescriptor );

        try
        {
            compositionResolver.addComponentDescriptor( componentDescriptor );
        }
        catch ( CompositionException e )
        {
            throw new ComponentRepositoryException( e.getMessage(), e );
        }
    }
View Full Code Here

TOP

Related Classes of org.codehaus.plexus.component.repository.exception.ComponentRepositoryException

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.