Search in sources :

Example 1 with Property

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

the class AnnotationClassParser method buildPropertyMetadata.

@SuppressWarnings("unchecked")
private static <T> PropertyMetadata<T> buildPropertyMetadata(Method propertyMethod, Class<T> type) {
    String propertyName = getPropertyName(propertyMethod.getName());
    PropertyMetadata<?> propertyMetadata;
    if (type.isArray() && type.getComponentType().isAnnotation()) {
        ConfigurationMetadata nestedConfigMetadata = buildConfigurationMetadata_Nested(type.getComponentType(), propertyName, true);
        propertyMetadata = new PropertyMetadata<>(propertyName, ConfigurationMetadata[].class).configurationMetadata(nestedConfigMetadata);
    } else if (type.isAnnotation()) {
        ConfigurationMetadata nestedConfigMetadata = buildConfigurationMetadata_Nested(type, propertyName, false);
        propertyMetadata = new PropertyMetadata<>(propertyName, ConfigurationMetadata.class).configurationMetadata(nestedConfigMetadata);
    } else {
        propertyMetadata = new PropertyMetadata<>(propertyName, type).defaultValue((T) propertyMethod.getDefaultValue());
    }
    Property propertyAnnotation = propertyMethod.getAnnotation(Property.class);
    if (propertyAnnotation != null) {
        propertyMetadata.label(emptyToNull(propertyAnnotation.label())).description(emptyToNull(propertyAnnotation.description())).properties(propsArrayToMap(propertyAnnotation.property())).order(propertyAnnotation.order());
    } else {
        Map<String, String> emptyMap = Collections.emptyMap();
        propertyMetadata.properties(emptyMap);
    }
    return (PropertyMetadata) propertyMetadata;
}
Also used : PropertyMetadata(org.apache.sling.caconfig.spi.metadata.PropertyMetadata) Property(org.apache.sling.caconfig.annotation.Property) ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata)

Aggregations

Property (org.apache.sling.caconfig.annotation.Property)1 ConfigurationMetadata (org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata)1 PropertyMetadata (org.apache.sling.caconfig.spi.metadata.PropertyMetadata)1