Search in sources :

Example 1 with Dependency

use of org.apache.felix.ipojo.handlers.dependency.Dependency in project felix by apache.

the class ProvidedServiceHandler method checkProvidedService.

/**
 * Check the provided service given in argument in the sense that the metadata are consistent.
 * @param svc : the provided service to check.
 * @return true if the provided service is correct
 * @throws ConfigurationException : the checked provided service is not correct.
 */
private boolean checkProvidedService(ProvidedService svc) throws ConfigurationException {
    Set<ClassLoader> classloaders = new LinkedHashSet<ClassLoader>();
    for (int i = 0; i < svc.getServiceSpecifications().length; i++) {
        String specName = svc.getServiceSpecifications()[i];
        // Check service level dependencies
        try {
            Class spec = load(specName, classloaders);
            classloaders.add(spec.getClassLoader());
            Field specField = spec.getField("specification");
            Object specif = specField.get(null);
            if (specif instanceof String) {
                Element specification = ManifestMetadataParser.parse((String) specif);
                Element[] deps = specification.getElements("requires");
                for (int j = 0; deps != null && j < deps.length; j++) {
                    Dependency dep = getAttachedDependency(deps[j]);
                    if (dep != null) {
                        // Fix service-level dependency flag
                        dep.setServiceLevelDependency();
                    }
                    isDependencyCorrect(dep, deps[j]);
                }
            } else {
                throw new ConfigurationException("Service Providing: The specification field of the service specification " + svc.getServiceSpecifications()[i] + " needs to be a String");
            }
        } catch (NoSuchFieldException e) {
        // Ignore it, keep and going.
        } catch (ClassNotFoundException e) {
            throw new ConfigurationException("Service Providing: The service specification " + svc.getServiceSpecifications()[i] + " cannot be loaded", e);
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException("Service Providing: The field 'specification' of the service specification " + svc.getServiceSpecifications()[i] + " is not accessible", e);
        } catch (IllegalAccessException e) {
            throw new ConfigurationException("Service Providing: The field 'specification' of the service specification " + svc.getServiceSpecifications()[i] + " is not accessible", e);
        } catch (ParseException e) {
            throw new ConfigurationException("Service Providing: The field 'specification' of the service specification " + svc.getServiceSpecifications()[i] + " does not contain a valid String", e);
        }
    }
    return true;
}
Also used : Element(org.apache.felix.ipojo.metadata.Element) Dependency(org.apache.felix.ipojo.handlers.dependency.Dependency) Field(java.lang.reflect.Field) ConfigurationException(org.apache.felix.ipojo.ConfigurationException) ParseException(org.apache.felix.ipojo.parser.ParseException)

Aggregations

Field (java.lang.reflect.Field)1 ConfigurationException (org.apache.felix.ipojo.ConfigurationException)1 Dependency (org.apache.felix.ipojo.handlers.dependency.Dependency)1 Element (org.apache.felix.ipojo.metadata.Element)1 ParseException (org.apache.felix.ipojo.parser.ParseException)1