/** * Write the xml for a service. * * @param service * @param contentHandler * @throws SAXException */ private static void generateServiceXML( final ServiceDescription service, final ContentHandler contentHandler, final int indent) throws SAXException { final AttributesImpl ai = new AttributesImpl(); IOUtils.addAttribute(ai, SERVICE_ATTR_FACTORY, String.valueOf(service.isServiceFactory())); IOUtils.indent(contentHandler, indent); contentHandler.startElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.SERVICE, ComponentDescriptorIO.SERVICE_QNAME, ai); if (service.getInterfaces() != null && service.getInterfaces().size() > 0) { IOUtils.newline(contentHandler); for (final String interf : service.getInterfaces()) { generateServiceXML(interf, contentHandler, indent+1); } IOUtils.indent(contentHandler, indent); } contentHandler.endElement(INNER_NAMESPACE_URI, ComponentDescriptorIO.SERVICE, ComponentDescriptorIO.SERVICE_QNAME); IOUtils.newline(contentHandler); }
@Override public AbstractDescription clone() { final ServiceDescription cd = new ServiceDescription(this.annotation); cd.setServiceFactory(this.isServiceFactory); for(final String i : this.getInterfaces()) { cd.addInterface(i); } return cd; } }
/** * 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); } } } }
/** * 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); } } }
if (this.container.getServiceDescription().getInterfaces().size() == 0) { this.logError(component, "Service interface information is missing!");
for(final String interfaceName : container.getServiceDescription().getInterfaces()) { try { final Class<?> interfaceClass = project.getClassLoader().loadClass(interfaceName);