cd.setName(cad.getStringValue("name", classDescription.getDescribedClass().getName())); cd.setConfigurationPolicy(ComponentConfigurationPolicy.OPTIONAL); classDescription.add(cd); final ServiceDescription sd = new ServiceDescription(cad); sd.addInterface("javax.servlet.Servlet"); classDescription.add(sd);
describedClass.add(createComponent(cad, scannedClass)); final List<ComponentDescription> componentDescs = describedClass.getDescriptions(ComponentDescription.class); ComponentDescription found = null; if (!componentDescs.isEmpty()) { describedClass.add(createService(allServiceTags, scannedClass));
private static Method getMethod(final ClassDescription cd, final String name, final Class<?>[] sig) { Class<?> checkClass = cd.getDescribedClass(); while ( checkClass != null ) { try { return checkClass.getDeclaredMethod(name, sig); } catch (final SecurityException e) { // ignore } catch (final NoSuchMethodException e) { // ignore } checkClass = checkClass.getSuperclass(); } return null; }
/** * Generates a property descriptor of type {@link PropertyType#String} */ private void generateStringPropertyDescriptor(final ClassAnnotation cad, final ClassDescription classDescription, final boolean metatype, String annotationName, String propertyDescriptorName) { final String[] values = (String[]) cad.getValue(annotationName); if (values == null) { return; } final PropertyDescription pd = new PropertyDescription(cad); pd.setName(propertyDescriptorName); pd.setMultiValue(values); pd.setType(PropertyType.String); if (metatype) { pd.setPrivate(true); } classDescription.add(pd); }
final ComponentContainer component, final MetatypeContainer ocd) { for(final PropertyDescription pd : current.getDescriptions(PropertyDescription.class)) { iLog.addError("Class " + current.getDescribedClass().getName() + " is declaring " + "the protected property 'service.id'.", current.getSource() ); continue; + current.getDescribedClass().getName() + " is set as private. " + "This is redundant as no metatype will be generated.", current.getSource() );
throws SCRDescriptorException { final ComponentDescription component = new ComponentDescription(cad); describedClass.add(component); describedClass.add(serviceDesc); final List<PropertyDescription> existingProps = describedClass.getDescriptions(PropertyDescription.class); PropertyDescription found = null; for(final PropertyDescription current : existingProps) { describedClass.add(pd); pd.setName(key); pd.setValue(value); throw new SCRDescriptorException("Multi value property '" + key + "' has different types: " + found.getType() + " & " + propType, describedClass.getSource()); if ( spec == null ) { throw new SCRDescriptorException("Unknown xmlns attribute value: " + cad.getValue("xmlns"), describedClass.getSource());
/** * Test a newly found property */ private boolean testProperty(final ClassDescription current, final Map<String, PropertyDescription> allProperties, final PropertyDescription newProperty, final boolean isInspectedClass ) { final String propName = newProperty.getName(); if ( !StringUtils.isEmpty(propName) ) { if ( allProperties.containsKey(propName) ) { // if the current class is the class we are currently inspecting, we // have found a duplicate definition if ( isInspectedClass ) { iLog.addError("Duplicate definition for property " + propName + " in class " + current.getDescribedClass().getName(), current.getSource() ); } return false; } allProperties.put(propName, newProperty); } else { // no name - generate a unique one allProperties.put(UUID.randomUUID().toString(), newProperty); } return true; }
public ClassDescription clone() { final ClassDescription cd = new ClassDescription(this.describedClass, this.source); for(final AbstractDescription ad : this.descriptions) { cd.add(ad.clone()); } return cd; } }
final IssueLog iLog) throws SCRDescriptorException { final ComponentDescription componentDesc = desc.getDescription(ComponentDescription.class); } else { iLog.addWarning( "Component factory " + componentDesc.getName() + " should not set metatype factory pid.", desc.getSource() ); if ( componentDesc.getLabel() != null && componentDesc.getLabel().trim().length() > 0 ) { iLog.addWarning(" Component " + componentDesc.getName() + " has set a label. However metatype is set to false. This label is ignored.", desc.getSource()); desc.getSource()); boolean inherit; do { final ComponentDescription cd = current.getDescription(ComponentDescription.class); inherit = (cd == null ? true : cd.isInherit()); if ( current != desc ) { iLog.addWarning(" Component " + componentDesc.getName() + " is using the " + "deprecated inheritance feature and inherits from " + current.getDescribedClass().getName() + ". This feature will be removed in future versions.", desc.getSource()); if ( !inherit || current.getDescribedClass().getSuperclass() == null ) { current = null; } else { try {
/** * Get the first description of that type * @param descType The description class * @return THe first description or <code>null</code> */ public <T extends AbstractDescription> T getDescription(final Class<T> descType) { final List<T> result = this.getDescriptions(descType); if ( result.size() > 0 ) { return result.get(0); } return null; }
/** * Parses the descriptors read from the given input stream. This method may * be called by the {@link #getComponentDescriptors()} method to parse the * descriptors gathered in an implementation dependent way. * * @throws SCRDescriptorException If an error occurs reading the * descriptors from the stream. */ private void readServiceComponentDescriptor( final InputStream file, final String location ) throws SCRDescriptorException { final List<ClassDescription> list = ComponentDescriptorIO.read( file, this.project.getClassLoader(), iLog, location ); if ( list != null ) { for(final ClassDescription cd : list) { final String name; if ( cd.getDescribedClass() == null ) { name = cd.getDescription(ComponentDescription.class).getName(); } else { name = cd.getDescribedClass().getName(); } loadedDependencies.put(name, cd); } } }
if ( desc != null ) { this.allDescriptions.put(annotatedClass.getName(), desc); if ( desc.getDescriptions(ComponentDescription.class).size() > 0) { result.add(desc); log.debug("Found component description " + desc + " in " + annotatedClass.getName()); } else { if ( desc.getDescription(PropertyDescription.class) != null || desc.getDescription(ReferenceDescription.class) != null || desc.getDescription(ServiceDescription.class) != null ) { iLog.addWarning("Class '" + src.getClassName() + "' contains SCR annotations, but not a " + "@Component (or equivalent) annotation. Therefore no component descriptor is created for this " + this.allDescriptions.put(annotatedClass.getName(), new ClassDescription(annotatedClass, GENERATED));
final List<ComponentContainer> processedContainers = new ArrayList<ComponentContainer>(); for (final ClassDescription desc : scannedDescriptions) { this.logger.debug("Processing component class " + desc.getSource()); result.addProcessedSourceFile(desc.getSource()); if (desc.getDescriptions(ComponentDescription.class).size() > 1) { iLog.addError("Class has more than one component definition." + " Check the annotations and merge the definitions to a single definition.", desc.getSource()); } else { final ComponentContainer container = this.createComponent(desc, iLog); desc.getSource()); } else { specVersion = container.getComponentDescription().getSpecVersion();
/** * Get a description for the class */ public ClassDescription getDescription(final Class<?> clazz) throws SCRDescriptorException, SCRDescriptorFailureException { final String name = clazz.getName(); // we don't need to scan classes in the java. or javax. package namespace if ( name.startsWith("java.") || name.startsWith("javax.") ) { return null; } ClassDescription result = this.allDescriptions.get(name); if ( result == null ) { // use scanner first result = this.processClass(clazz, GENERATED); if ( result == null ) { // now check loaded dependencies result = this.getComponentDescriptors().get(name); } // not found, create dummy if ( result == null ) { result = new ClassDescription(clazz, GENERATED); } // and cache allDescriptions.put(name, result); } return result.clone(); }
/** * Create a new scanner. */ public ClassScanner(final Log log, final IssueLog iLog, final Project project, final AnnotationProcessor aProcessor) { // create map for all descriptions and dummy entry for Object this.allDescriptions = new HashMap<String, ClassDescription>(); allDescriptions.put(Object.class.getName(), new ClassDescription(Object.class, GENERATED)); this.log = log; this.iLog = iLog; this.project = project; this.aProcessor = aProcessor; }
/** * Process service directives */ private void processServices(final ClassDescription current, final ComponentContainer component) { final ServiceDescription serviceDesc = current.getDescription(ServiceDescription.class); if ( serviceDesc != null ) { ServiceDescription service = component.getServiceDescription(); if ( service == null ) { service = new ServiceDescription(serviceDesc.getAnnotation()); service.setServiceFactory(false); component.setServiceDescription(service); } if ( serviceDesc.isServiceFactory() ) { service.setServiceFactory(true); } for(final String className : serviceDesc.getInterfaces()) { service.addInterface(className); } } }
private boolean hasMethod(final ClassDescription classDescription, final String name) { final Method[] allMethods = classDescription.getDescribedClass().getDeclaredMethods(); for(final Method m : allMethods) { if ( m.getName().equals(name) ) { return true; } } return false; } }
describedClass.add(prop);
/** * Test a newly found reference */ private void testReference(final ClassDescription current, final Map<String, ReferenceDescription> allReferences, final ReferenceDescription newReference, final boolean isInspectedClass ) { String refName = newReference.getName(); if ( refName == null) { refName = newReference.getInterfaceName(); } if ( refName != null ) { if ( allReferences.containsKey( refName ) ) { // if the current class is the class we are currently inspecting, we // have found a duplicate definition if ( isInspectedClass ) { iLog.addError("Duplicate definition for reference " + refName + " in class " + current.getDescribedClass().getName(), current.getSource() ); } } else { allReferences.put(refName, newReference); } } else { // no name - generate a unique one allReferences.put(UUID.randomUUID().toString(), newReference); } } }
this.currentClass = new ClassDescription(cl, "classpath:" + className); this.currentClass.add(this.currentComponent); this.components.add(this.currentClass);