private void attemptImplementationLoad() { if ( implementationClass == null && getImplementation() != null && getRealm() != null ) { try { implementationClass = (Class<? extends T>) getRealm().loadClass( getImplementation() ); Thread.currentThread(); } catch ( Throwable ignored ) { Thread.currentThread(); } } }
realm.loadClass( descriptor.getImplementation() );
/** * Merges override and target, where target is updated with override. * @param override {@link ComponentDescriptor} * @param target {@link ComponentDescriptor}. */ public static void merge( ComponentDescriptor<?> override, ComponentDescriptor<?> target ) { if ( override.getImplementation() != null ) { target.setImplementation( override.getImplementation() ); } mergeRequirements( override, target ); mergeConfiguration( override, target ); // TODO: other getters/setters. }
public ComponentDescriptorBeanModule( final ClassSpace space, final List<ComponentDescriptor<?>> descriptors ) { this.space = space; for ( int i = 0, size = descriptors.size(); i < size; i++ ) { final ComponentDescriptor<?> cd = descriptors.get( i ); final Component component = newComponent( cd ); final String factory = cd.getComponentFactory(); if ( null == factory || "java".equals( factory ) ) { try { componentMap.put( component, new LoadedClass<Object>( cd.getImplementationClass() ) ); } catch ( final TypeNotPresentException e ) { componentMap.put( component, space.deferLoadClass( cd.getImplementation() ) ); } } else { componentMap.put( component, new DeferredFactoryClass( cd, factory ) ); } final List<ComponentRequirement> requirements = cd.getRequirements(); if ( !requirements.isEmpty() ) { metadataMap.put( cd.getImplementation(), new ComponentMetadata( space, requirements ) ); } } }
/** * Returns a human-friendly key, suitable for display. * * @return a human-friendly key */ public String getHumanReadableKey() { StringBuilder key = new StringBuilder(); key.append( "role: '" ).append( getRole() ).append( "'" ); key.append( ", implementation: '" ).append( getImplementation() ).append( "'" ); if ( roleHint != null ) { key.append( ", role hint: '" ).append( getRoleHint() ).append( "'" ); } if ( alias != null ) { key.append( ", alias: '" ).append( getAlias() ).append( "'" ); } return key.toString(); }
String implementation = componentDescriptor.getImplementation();
public String getName() { return cd.getImplementation(); }
+ "in object of type " + componentDescriptor.getImplementation() + " because the requirement " + requirement + " was missing)", e);
public AntScriptInvoker( ComponentDescriptor descriptor, ClassLoader loader) throws IOException, ComponentInstantiationException { this.invokerClassLoader = loader; this.descriptor = descriptor; String impl = descriptor.getImplementation(); int colon = impl.indexOf( ":" ); if ( colon > -1 ){ this.resourceName = impl.substring( 0, colon ); this.target = impl.substring( colon + 1 ); } else{ this.resourceName = impl; } scriptResource = resourceName; }
protected Field getFieldByName( Object component, String fieldName, ComponentDescriptor componentDescriptor ) throws CompositionException { Field field; try { field = ReflectionUtils.getFieldByNameIncludingSuperclasses( fieldName, component.getClass() ); } catch( NoClassDefFoundError e ) { throw new CompositionException( "Embedded NoClassDefFoundError while looking up " + Field.class.getName() + " for: " + fieldName + " in: " + componentDescriptor.getImplementation(), e ); } if ( field == null ) { StringBuffer msg = new StringBuffer( "Component Composition failed. No field of name: '" ); msg.append( fieldName ); msg.append( "' exists in component: " ); msg.append( componentDescriptor.getHumanReadableKey() ); throw new CompositionException( msg.toString() ); } return field; }
protected URL getScriptLocation( ComponentDescriptor componentDescriptor, ClassRealm classRealm ) { String impl = componentDescriptor.getImplementation(); if ( !impl.startsWith( "/" ) ) { impl = "/" + impl; } URL scriptLocation = classRealm.getResource( impl ); if(scriptLocation == null) { System.out.println("Cannot find: " + impl + " in classpath:"); for ( int i = 0; i < classRealm.getConstituents().length; i++ ) { URL constituent = classRealm.getConstituents()[i]; System.out.println("[" + i + "] " + constituent); } } return scriptLocation; }
/** * Merges override and target, where target is updated with override. */ public static void merge( ComponentDescriptor override, ComponentDescriptor target ) { if ( override.getImplementation() != null ) { target.setImplementation( override.getImplementation() ); } mergeRequirements( override.getRequirements(), target.getRequirements() ); mergeConfiguration( override, target ); // TODO: other getters/setters. }
public Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm classRealm, PlexusContainer container ) throws ComponentInstantiationException { ClassLoader currentContextLoader = Thread.currentThread().getContextClassLoader(); try { ClassLoader cl = classRealm.getClassLoader(); Class loader = classRealm.loadClass("clojure.plexus.factory.ClojureLoader"); Method m = loader.getDeclaredMethod("instantiate",String.class); Thread.currentThread().setContextClassLoader(cl); Object obj=m.invoke(loader,componentDescriptor.getImplementation()); return obj; } catch ( Exception e ) { classRealm.display(); throw new ComponentInstantiationException( "Failed to extract Clojure component for: " + componentDescriptor.getHumanReadableKey(), e ); } finally { Thread.currentThread() .setContextClassLoader(currentContextLoader); } }
public boolean canCreate(Type expectedType) { if (!autoMatch) { return true; } ClassRealm realm = (ClassRealm) Thread.currentThread().getContextClassLoader(); Class propertyType = toClass(expectedType); // Never auto match array, map or collection if (propertyType.isArray() || Map.class.isAssignableFrom(propertyType) || Collection.class.isAssignableFrom(propertyType) || requirement instanceof ComponentRequirementList) { return false; } // if the type to be created is an instance of the expceted type, return true try { ComponentDescriptor descriptor = ((MutablePlexusContainer) container).getComponentRepository().getComponentDescriptor(requirement.getRole(), requirement.getRoleHint(), realm); String typeName = descriptor.getImplementation(); Class actualClass = realm.loadClass(typeName); if (RecipeHelper.isAssignable(expectedType, actualClass)) { return true; } } catch (Exception e) { } return false; }
public Object newInstance(final ComponentDescriptor component, final ClassRealm realm, final PlexusContainer container) throws ComponentInstantiationException { assert component != null; assert realm != null; try { Provider provider = providerManager.select(); ClassFactory factory = (ClassFactory) provider.feature(ClassFactory.KEY).create(); ClassLoader classLoader = realm.getClassLoader(); Class type = factory.create(component.getImplementation(), classLoader); return type.newInstance(); } catch (Exception e) { throw new ComponentInstantiationException("Failed to create Groovy component: " + e, e); } } }
String implementation = componentDescriptor.getImplementation();
private void writeComponents( XMLWriter w, List componentDescriptors ) throws ComponentDescriptorCreatorException, PlexusConfigurationException { w.startElement( "components" ); for ( Iterator i = componentDescriptors.iterator(); i.hasNext(); ) { w.startElement( "component" ); ComponentDescriptor cd = (ComponentDescriptor) i.next(); element( w, "role", cd.getRole() ); element( w, "role-hint", cd.getRoleHint() ); element( w, "implementation", cd.getImplementation() ); element( w, "instantiation-strategy", cd.getInstantiationStrategy() ); element( w, "lifecycle-handler", cd.getLifecycleHandler() ); writeRequirements( w, cd.getRequirements() ); writeConfiguration( w, cd.getConfiguration() ); w.endElement(); } w.endElement(); }
@SuppressWarnings("unchecked") private <T> ComponentDescriptor<T> createXWikiComponentDescriptor( org.codehaus.plexus.component.repository.ComponentDescriptor pcd) { DefaultComponentDescriptor<T> descriptor = null; if (pcd != null) { descriptor = new DefaultComponentDescriptor<T>(); descriptor.setImplementation((Class< ? extends T>) loadClass(pcd.getImplementation())); descriptor.setRoleHint(pcd.getRoleHint()); descriptor.setRole((Class<T>) loadClass(pcd.getRole())); if ("per-lookup".equals(pcd.getInstantiationStrategy())) { descriptor.setInstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP); } else { descriptor.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON); } // Copy dependencies for (ComponentRequirement requirement : (List<ComponentRequirement>) pcd.getRequirements()) { DefaultComponentDependency dependency = new DefaultComponentDependency(); dependency.setRole(loadClass(requirement.getRole())); dependency.setRoleHint(requirement.getRoleHint()); dependency.setMappingType(loadClass(requirement.getFieldMappingType())); dependency.setName(requirement.getFieldName()); // TODO: Handle specific hints when we move to a more recent Plexus version. // See createPlexusComponentDescriptor descriptor.addComponentDependency(dependency); } } return descriptor; }
element( w, "implementation", cd.getImplementation() );
public ObjectRecipe createObjectRecipe(ComponentDescriptor descriptor, ClassRealm realm) throws ComponentInstantiationException, PlexusConfigurationException { String typeName = descriptor.getImplementation(); String factoryMethod = null; String[] constructorArgNames = null;