public Object invoke()

in src/main/java/org/apache/sling/caconfig/impl/ConfigurationProxy.java [97:142]


        public Object invoke(Object proxy, Method method, Object[] args) {
            String propName = AnnotationClassParser.getPropertyName(method.getName());

            // check for nested configuration classes
            Class<?> targetType = method.getReturnType();
            Class<?> componentType = method.getReturnType();
            boolean isArray = targetType.isArray();
            if (isArray) {
                componentType = targetType.getComponentType();
            }
            if (componentType.isAnnotation()) {
                if (isArray) {
                    Collection<?> listItems = childResolver.getChildren(propName, componentType);
                    return listItems.toArray((Object[]) Array.newInstance(componentType, listItems.size()));
                } else {
                    return childResolver.getChild(propName, componentType);
                }
            }

            // validate type
            if (!isValidType(componentType)) {
                throw new ConfigurationResolveException("Unsupported type " + componentType.getName() + " in "
                        + method.getDeclaringClass() + "#" + method.getName());
            }

            // detect default value
            Object defaultValue = method.getDefaultValue();
            if (defaultValue == null) {
                if (isArray) {
                    defaultValue = Array.newInstance(componentType, 0);
                } else if (targetType.isPrimitive()) {
                    // get default value for primitive data type (use hack via array)
                    defaultValue = Array.get(Array.newInstance(targetType, 1), 0);
                }
            }

            // get value from valuemap with given type/default value
            ValueMap props = ResourceUtil.getValueMap(resource);
            Object value;
            if (defaultValue != null) {
                value = props.get(propName, defaultValue);
            } else {
                value = props.get(propName, targetType);
            }
            return value;
        }