protected void loadComponentsOnStart() throws PlexusConfigurationException, ComponentLookupException { PlexusConfiguration[] loadOnStartComponents = configuration.getChild("load-on-start").getChildren("component"); getLogger().debug("Found " + loadOnStartComponents.length + " components to load on start"); for (int i = 0; i < loadOnStartComponents.length; i++) { String role = loadOnStartComponents[i].getChild("role").getValue(null); String roleHint = loadOnStartComponents[i].getChild("role-hint").getValue(); if (role == null) { throw new PlexusConfigurationException("Missing 'role' element from load-on-start."); } if (roleHint == null) { getLogger().info("Loading on start [role]: " + "[" + role + "]"); lookup(role); } else if (roleHint.equals("*")) { getLogger().info("Loading on start all components with [role]: " + "[" + role + "]"); lookupList(role); } else { getLogger().info("Loading on start [role,roleHint]: " + "[" + role + "," + roleHint + "]"); lookup(role, roleHint); } } }
protected void initializePhases() throws PlexusContainerException { PlexusConfiguration initializationConfiguration = configuration.getChild("container-initialization"); ContainerInitializationContext initializationContext = new ContainerInitializationContext(this, classWorld, containerRealm, configuration); // PLXAPI: I think we might only ever need one of these so maybe we can create it with a // constructor // and store it. ComponentConfigurator c = new BasicComponentConfigurator(); try { c.configureComponent(this, initializationConfiguration, containerRealm); } catch (ComponentConfigurationException e) { throw new PlexusContainerException( "Error setting container initialization initializationPhases.", e); } for (Iterator iterator = initializationPhases.iterator(); iterator.hasNext(); ) { ContainerInitializationPhase phase = (ContainerInitializationPhase) iterator.next(); try { phase.execute(initializationContext); } catch (ContainerInitializationException e) { throw new PlexusContainerException("Error initializaing container in " + phase + ".", e); } } }
// TODO: Do not swallow exception public void initializeResources() throws PlexusConfigurationException { PlexusConfiguration[] resourceConfigs = configuration.getChild("resources").getChildren(); for (int i = 0; i < resourceConfigs.length; ++i) { try { String name = resourceConfigs[i].getName(); if (name.equals("jar-repository")) { addJarRepository(new File(resourceConfigs[i].getValue())); } else if (name.equals("directory")) { File directory = new File(resourceConfigs[i].getValue()); if (directory.exists() && directory.isDirectory()) { plexusRealm.addConstituent(directory.toURL()); } } else { getLogger().warn("Unknown resource type: " + name); } } catch (MalformedURLException e) { getLogger() .error( "Error configuring resource: " + resourceConfigs[i].getName() + "=" + resourceConfigs[i].getValue(), e); } } }
public void processConfiguration( ConverterLookup converterLookup, Object object, ClassLoader classLoader, PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator) throws ComponentConfigurationException { int items = configuration.getChildCount(); for (int i = 0; i < items; i++) { PlexusConfiguration childConfiguration = configuration.getChild(i); String elementName = childConfiguration.getName(); ComponentValueSetter valueSetter = new ComponentValueSetter(fromXML(elementName), object, converterLookup); valueSetter.configure(childConfiguration, classLoader, expressionEvaluator); /* Object value = valueSetter.getConverter().fromConfiguration( converterLookup, childConfiguration, valueSetter.getValueType(), object.getClass(), classLoader, expressionEvaluator ); if ( value != null ) { valueSetter.setValue( value ); } */ } }
/** * Process any additional component configuration files that have been specified. The specified * directory is scanned recursively so configurations can be within nested directories to help * with component organization. */ private void processConfigurationsDirectory() throws PlexusConfigurationException { String s = configuration.getChild("configurations-directory").getValue(null); if (s != null) { PlexusConfiguration componentsConfiguration = configuration.getChild("components"); File configurationsDirectory = new File(s); if (configurationsDirectory.exists() && configurationsDirectory.isDirectory()) { List componentConfigurationFiles; try { componentConfigurationFiles = FileUtils.getFiles(configurationsDirectory, "**/*.conf", "**/*.xml"); } catch (IOException e) { throw new PlexusConfigurationException("Unable to locate configuration files", e); } for (Iterator i = componentConfigurationFiles.iterator(); i.hasNext(); ) { File componentConfigurationFile = (File) i.next(); Reader reader = null; try { reader = ReaderFactory.newXmlReader(componentConfigurationFile); PlexusConfiguration componentConfiguration = PlexusTools.buildConfiguration( componentConfigurationFile.getAbsolutePath(), getInterpolationConfigurationReader(reader)); componentsConfiguration.addChild(componentConfiguration.getChild("components")); } catch (FileNotFoundException e) { throw new PlexusConfigurationException( "File " + componentConfigurationFile + " disappeared before processing", e); } catch (IOException e) { throw new PlexusConfigurationException( "IO error while reading " + componentConfigurationFile, e); } finally { IOUtil.close(reader); } } } } }
private void initializeCoreComponents() throws ComponentConfigurationException, ComponentRepositoryException, ContextException { BasicComponentConfigurator configurator = new BasicComponentConfigurator(); PlexusConfiguration c = configuration.getChild("component-repository"); processCoreComponentConfiguration("component-repository", configurator, c); componentRepository.configure(configuration); componentRepository.setClassRealm(plexusRealm); componentRepository.initialize(); // Lifecycle handler manager c = configuration.getChild("lifecycle-handler-manager"); processCoreComponentConfiguration("lifecycle-handler-manager", configurator, c); lifecycleHandlerManager.initialize(); // Component manager manager c = configuration.getChild("component-manager-manager"); processCoreComponentConfiguration("component-manager-manager", configurator, c); componentManagerManager.setLifecycleHandlerManager(lifecycleHandlerManager); // Component discoverer manager c = configuration.getChild("component-discoverer-manager"); processCoreComponentConfiguration("component-discoverer-manager", configurator, c); componentDiscovererManager.initialize(); // Component factory manager c = configuration.getChild("component-factory-manager"); processCoreComponentConfiguration("component-factory-manager", configurator, c); if (componentFactoryManager instanceof Contextualizable) { Context context = getContext(); context.put(PlexusConstants.PLEXUS_KEY, this); ((Contextualizable) componentFactoryManager).contextualize(getContext()); } // Component factory manager c = configuration.getChild("component-composer-manager"); processCoreComponentConfiguration("component-composer-manager", configurator, c); }
private void initializeSystemProperties() throws PlexusConfigurationException { PlexusConfiguration[] systemProperties = configuration.getChild("system-properties").getChildren("property"); for (int i = 0; i < systemProperties.length; ++i) { String name = systemProperties[i].getAttribute("name"); String value = systemProperties[i].getAttribute("value"); if (name == null) { throw new PlexusConfigurationException("Missing 'name' attribute in 'property' tag. "); } if (value == null) { throw new PlexusConfigurationException("Missing 'value' attribute in 'property' tag. "); } System.getProperties().setProperty(name, value); getLogger().info("Setting system property: [ " + name + ", " + value + " ]"); } }
public static ComponentSetDescriptor buildComponentSet(PlexusConfiguration c) throws Exception { ComponentSetDescriptor csd = new ComponentSetDescriptor(); // ---------------------------------------------------------------------- // Components // ---------------------------------------------------------------------- PlexusConfiguration[] components = c.getChild("components").getChildren("component"); for (int i = 0; i < components.length; i++) { PlexusConfiguration component = components[i]; csd.addComponentDescriptor(buildComponentDescriptor(component)); } // ---------------------------------------------------------------------- // Dependencies // ---------------------------------------------------------------------- PlexusConfiguration[] dependencies = c.getChild("dependencies").getChildren("dependency"); for (int i = 0; i < dependencies.length; i++) { PlexusConfiguration d = dependencies[i]; ComponentDependency cd = new ComponentDependency(); cd.setArtifactId(d.getChild("artifact-id").getValue()); cd.setGroupId(d.getChild("group-id").getValue()); cd.setType(d.getChild("type").getValue()); cd.setVersion(d.getChild("version").getValue()); csd.addDependency(cd); } return csd; }
public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, ConfigurationListener listener) throws ComponentConfigurationException { Object retValue = fromExpression(configuration, expressionEvaluator, type); if (retValue != null) { return retValue; } Class implementation = getClassForImplementationHint(null, configuration, classLoader); if (implementation != null) { retValue = instantiateObject(implementation); } else { // we can have 2 cases here: // - provided collection class which is not abstract // like Vector, ArrayList, HashSet - so we will just instantantiate it // - we have an abtract class so we have to use default collection type int modifiers = type.getModifiers(); if (Modifier.isAbstract(modifiers)) { retValue = getDefaultCollection(type); } else { try { retValue = type.newInstance(); } catch (IllegalAccessException e) { String msg = "An attempt to convert configuration entry " + configuration.getName() + "' into " + type + " object failed: " + e.getMessage(); throw new ComponentConfigurationException(msg, e); } catch (InstantiationException e) { String msg = "An attempt to convert configuration entry " + configuration.getName() + "' into " + type + " object failed: " + e.getMessage(); throw new ComponentConfigurationException(msg, e); } } } // now we have collection and we have to add some objects to it for (int i = 0; i < configuration.getChildCount(); i++) { PlexusConfiguration c = configuration.getChild(i); Class childType = getImplementationClass(null, baseType, c, classLoader); ConfigurationConverter converter = converterLookup.lookupConverterForType(childType); Object object = converter.fromConfiguration( converterLookup, c, childType, baseType, classLoader, expressionEvaluator, listener); Collection collection = (Collection) retValue; collection.add(object); } return retValue; }
public static ComponentDescriptor buildComponentDescriptor(PlexusConfiguration configuration) throws Exception { ComponentDescriptor cd = new ComponentDescriptor(); cd.setRole(configuration.getChild("role").getValue()); cd.setRoleHint(configuration.getChild("role-hint").getValue()); cd.setImplementation(configuration.getChild("implementation").getValue()); cd.setVersion(configuration.getChild("version").getValue()); cd.setComponentType(configuration.getChild("component-type").getValue()); cd.setInstantiationStrategy(configuration.getChild("instantiation-strategy").getValue()); cd.setLifecycleHandler(configuration.getChild("lifecycle-handler").getValue()); cd.setComponentProfile(configuration.getChild("component-profile").getValue()); cd.setComponentComposer(configuration.getChild("component-composer").getValue()); cd.setComponentFactory(configuration.getChild("component-factory").getValue()); cd.setDescription(configuration.getChild("description").getValue()); cd.setAlias(configuration.getChild("alias").getValue()); String s = configuration.getChild("isolated-realm").getValue(); if (s != null) { cd.setIsolatedRealm(s.equals("true") ? true : false); } // ---------------------------------------------------------------------- // Here we want to look for directives for inlining external // configurations. we probably want to take them from files or URLs. // ---------------------------------------------------------------------- cd.setConfiguration(configuration.getChild("configuration")); // ---------------------------------------------------------------------- // Requirements // ---------------------------------------------------------------------- PlexusConfiguration[] requirements = configuration.getChild("requirements").getChildren("requirement"); for (int i = 0; i < requirements.length; i++) { PlexusConfiguration requirement = requirements[i]; ComponentRequirement cr = new ComponentRequirement(); cr.setRole(requirement.getChild("role").getValue()); cr.setRoleHint(requirement.getChild("role-hint").getValue()); cr.setFieldName(requirement.getChild("field-name").getValue()); cd.addRequirement(cr); } return cd; }
public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type, Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator) throws ComponentConfigurationException { Object retValue = fromExpression(configuration, expressionEvaluator, type); if (retValue != null) { return retValue; } Class implementation = getClassForImplementationHint(null, configuration, classLoader); if (implementation != null) { retValue = instantiateObject(implementation); } else { // we can have 2 cases here: // - provided collection class which is not abstract // like Vector, ArrayList, HashSet - so we will just instantantiate it // - we have an abtract class so we have to use default collection type int modifiers = type.getModifiers(); if (Modifier.isAbstract(modifiers)) { retValue = getDefaultCollection(type); } else { try { retValue = type.newInstance(); } catch (IllegalAccessException e) { String msg = "An attempt to convert configuration entry " + configuration.getName() + "' into " + type + " object failed: " + e.getMessage(); throw new ComponentConfigurationException(msg, e); } catch (InstantiationException e) { String msg = "An attempt to convert configuration entry " + configuration.getName() + "' into " + type + " object failed: " + e.getMessage(); throw new ComponentConfigurationException(msg, e); } } } // now we have collection and we have to add some objects to it for (int i = 0; i < configuration.getChildCount(); i++) { PlexusConfiguration c = configuration.getChild(i); // Object o = null; String configEntry = c.getName(); String name = StringUtils.capitalizeFirstLetter(fromXML(configEntry)); Class childType = getClassForImplementationHint(null, c, classLoader); if (childType == null) { // Some classloaders don't create Package objects for classes // so we have to resort to slicing up the class name String baseTypeName = baseType.getName(); int lastDot = baseTypeName.lastIndexOf('.'); String className; if (lastDot == -1) { className = name; } else { String basePackage = baseTypeName.substring(0, lastDot); className = basePackage + "." + name; } childType = loadClass(className, classLoader); } ConfigurationConverter converter = converterLookup.lookupConverterForType(childType); Object object = converter.fromConfiguration( converterLookup, c, childType, baseType, classLoader, expressionEvaluator); Collection collection = (Collection) retValue; collection.add(object); } return retValue; }