Search in sources :

Example 1 with Configuration

use of org.apache.sling.caconfig.annotation.Configuration in project sling by apache.

the class AnnotationClassParser method buildConfigurationMetadata.

/**
     * Build configuration metadata by parsing the given annotation interface class and it's configuration annotations.
     * @param clazz Configuration annotation class
     * @return Configuration metadata
     */
public static ConfigurationMetadata buildConfigurationMetadata(Class<?> clazz) {
    Configuration configAnnotation = clazz.getAnnotation(Configuration.class);
    if (configAnnotation == null) {
        throw new IllegalArgumentException("Class has not @Configuration annotation: " + clazz.getName());
    }
    // configuration metadata and property metadata
    String configName = getConfigurationName(clazz, configAnnotation);
    ConfigurationMetadata configMetadata = new ConfigurationMetadata(configName, buildConfigurationMetadata_PropertyMetadata(clazz), configAnnotation.collection()).label(emptyToNull(configAnnotation.label())).description(emptyToNull(configAnnotation.description())).properties(propsArrayToMap(configAnnotation.property()));
    return configMetadata;
}
Also used : Configuration(org.apache.sling.caconfig.annotation.Configuration) ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata)

Example 2 with Configuration

use of org.apache.sling.caconfig.annotation.Configuration in project sling by apache.

the class ConfigurationMetadataUtil method getConfigurationClassesForPackages.

/**
     * Get configuration classes in list of packages (and subpackages), and cache result in static map.
     * @param packageNames Package names
     * @return List of classes
     */
public static Collection<Class> getConfigurationClassesForPackages(String packageNames) {
    List<Class> classes = CONFIGURATION_CLASSES_FOR_PACKAGES.get(packageNames);
    if (classes == null) {
        classes = new ArrayList<Class>();
        String[] packageNameArray = StringUtils.split(packageNames, ",");
        // add "." to each package name because it's a prefix, not a package name
        Object[] prefixArray = new Object[packageNameArray.length];
        for (int i = 0; i < packageNameArray.length; i++) {
            prefixArray[i] = packageNameArray[i] + ".";
        }
        Reflections reflections = new Reflections(prefixArray);
        classes.addAll(reflections.getTypesAnnotatedWith(Configuration.class));
        CONFIGURATION_CLASSES_FOR_PACKAGES.putIfAbsent(packageNames, classes);
    }
    return classes;
}
Also used : Configuration(org.apache.sling.caconfig.annotation.Configuration) Reflections(org.reflections.Reflections)

Aggregations

Configuration (org.apache.sling.caconfig.annotation.Configuration)2 ConfigurationMetadata (org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata)1 Reflections (org.reflections.Reflections)1