/** * @todo pico components can have theoretically more then one constructor which is rather stupid * idea */ public Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm classRealm, PlexusContainer container) throws ComponentInstantiationException { try { String implementation = componentDescriptor.getImplementation(); Class implementationClass = classRealm.loadClass(implementation); Constructor constructor = implementationClass.getConstructors()[0]; Class[] parameterTypes = constructor.getParameterTypes(); Object[] params = new Object[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; i++) { Class parameterType = parameterTypes[i]; params[i] = lookupComponent(parameterType, componentDescriptor, container); } Object retValue = constructor.newInstance(params); return retValue; } catch (Exception e) { String msg = "Component " + componentDescriptor.getHumanReadableKey() + " cannot be instantiated"; throw new ComponentInstantiationException(msg, e); } }
private ComponentInstantiationException makeException( ClassRealm componentClassRealm, ComponentDescriptor componentDescriptor, Class implementationClass, Throwable e) { // ---------------------------------------------------------------------- // Display the realm when there is an error, We should probably return a string here so we // can incorporate this into the error message for easy debugging. // ---------------------------------------------------------------------- componentClassRealm.display(); String msg = "Could not instanciate component: " + componentDescriptor.getHumanReadableKey(); return new ComponentInstantiationException(msg, e); }
private void processCoreComponentConfiguration( String role, BasicComponentConfigurator configurator, PlexusConfiguration c) throws ComponentConfigurationException { String implementation = c.getAttribute("implementation", null); if (implementation == null) { String msg = "Core component: '" + role + "' + which is needed by plexus to function properly cannot " + "be instantiated. Implementation attribute was not specified in plexus.conf." + "This is highly irregular, your plexus JAR is most likely corrupt."; throw new ComponentConfigurationException(msg); } ComponentDescriptor componentDescriptor = new ComponentDescriptor(); componentDescriptor.setRole(role); componentDescriptor.setImplementation(implementation); PlexusConfiguration configuration = new XmlPlexusConfiguration("configuration"); configuration.addChild(c); try { configurator.configureComponent(this, configuration, plexusRealm); } catch (ComponentConfigurationException e) { // TODO: don't like rewrapping the same exception, but better than polluting this all through // the config code String message = "Error configuring component: " + componentDescriptor.getHumanReadableKey(); throw new ComponentConfigurationException(message, e); } }