cd.setName(cad.getStringValue("name", classDescription.getDescribedClass().getName())); cd.setConfigurationPolicy(ComponentConfigurationPolicy.OPTIONAL);
cd.setName(cad.getStringValue("name", classDescription.getDescribedClass().getName())); cd.setConfigurationPolicy(ComponentConfigurationPolicy.OPTIONAL);
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; }
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; } }
final ComponentContainer component = components.remove(0); innerList.add(component); final int pos = component.getClassDescription().getDescribedClass().getName().indexOf('$'); final String baseClassName; if ( pos == -1 ) { baseClassName = component.getClassDescription().getDescribedClass().getName(); } else { baseClassName = component.getClassDescription().getDescribedClass().getName().substring(0, pos); while ( i.hasNext() ) { final ComponentContainer cc = i.next(); if ( cc.getClassDescription().getDescribedClass().getName().startsWith(baseClassPrefix) ) { innerList.add(cc); i.remove();
/** * 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); } } }
/** * Write the xml for an Implementation. * * @param implementation * @param contentHandler * @throws SAXException */ private static void generateImplementationXML(final ComponentContainer component, final ContentHandler contentHandler, final int indent) throws SAXException { final AttributesImpl ai = new AttributesImpl(); IOUtils.addAttribute(ai, IMPLEMENTATION_ATTR_CLASS, component.getClassDescription().getDescribedClass().getName()); IOUtils.indent(contentHandler, indent); contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.IMPLEMENTATION, ComponentDescriptorIO.IMPLEMENTATION_QNAME, ai); contentHandler.endElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.IMPLEMENTATION, ComponentDescriptorIO.IMPLEMENTATION_QNAME); IOUtils.newline(contentHandler); }
/** * 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; }
/** * 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); } } }
/** * Validate the service and its interfaces * If errors occur a message is added to the issues list, * warnings can be added to the warnings list. */ private void validateService(final ServiceDescription service) throws SCRDescriptorException { for (final String interfaceName : service.getInterfaces()) { if (this.container.getClassDescription().getDescribedClass().isInterface()) { this.logError(service, "Must be declared in a Java class - not an interface"); } else { try { final Class<?> interfaceClass = project.getClassLoader().loadClass(interfaceName); if (!interfaceClass.isAssignableFrom(this.container.getClassDescription().getDescribedClass())) { // interface not implemented this.logError(service, "Class must implement provided interface " + interfaceName); } } catch (final ClassNotFoundException cnfe) { throw new SCRDescriptorException("Unable to load interface class.", cnfe); } } } }
final Method[] methods = container.getClassDescription().getDescribedClass().getDeclaredMethods(); int i = 0; while (i < methods.length) {
final Method[] methods = this.container.getClassDescription().getDescribedClass().getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { if (methodName.equals(methods[i].getName())) {
&& ref.getField().getDeclaringClass().getName().equals(container.getClassDescription().getDescribedClass().getName()) && (ref.getCardinality() == ReferenceCardinality.OPTIONAL_UNARY || ref.getCardinality() == ReferenceCardinality.MANDATORY_UNARY)) { this.logger.debug("Generating bind and unbind method for " + name + " in " + container.getClassDescription().getDescribedClass().getName()); } else if ( createBind ) { this.logger.debug("Generating bind method for " + name + " in " + container.getClassDescription().getDescribedClass().getName()); } else { this.logger.debug("Generating unbind method for " + name + " in " + container.getClassDescription().getDescribedClass().getName()); ClassModifier.addMethods(container.getClassDescription().getDescribedClass().getName(), name, type,
if (!Modifier.isPublic(this.container.getClassDescription().getDescribedClass().getModifiers())) { this.logError(component, "Class must be public: " + this.container.getClassDescription().getDescribedClass().getName()); if (Modifier.isAbstract(this.container.getClassDescription().getDescribedClass().getModifiers()) || this.container.getClassDescription().getDescribedClass().isInterface()) { this.logError(component, "Class must be concrete class (not abstract or interface) : " + this.container.getClassDescription().getDescribedClass().getName()); Constructor<?>[] constructors = this.container.getClassDescription().getDescribedClass().getDeclaredConstructors(); for (int i = 0; constructors != null && i < constructors.length; i++) { this.logError(component, "Class must have public default constructor: " + this.container.getClassDescription().getDescribedClass().getName()); this.logError(component, "Component must not be a ServiceFactory, if immediate and/or component factory: " + this.container.getClassDescription().getDescribedClass().getName()); "Component must not be immediate if component factory: " + this.container.getClassDescription().getDescribedClass().getName());
final String name = pd.getName(); if ( org.osgi.framework.Constants.SERVICE_ID.equals(name) ) { 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() );
String nameOfAnnotatedClass = classDescription.getDescribedClass().getName();
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 { current = this.scanner.getDescription(current.getDescribedClass().getSuperclass()); } catch ( final SCRDescriptorFailureException sde) { this.logger.debug(sde.getMessage(), sde);