Java Code Examples for org.apache.commons.lang3.ObjectUtils#NULL

The following examples show how to use org.apache.commons.lang3.ObjectUtils#NULL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BindingsInjector.java    From sling-org-apache-sling-models-impl with Apache License 2.0 5 votes vote down vote up
@Override
public Object getValue(@NotNull Object adaptable, String name, @NotNull Type type, @NotNull AnnotatedElement element,
        @NotNull DisposalCallbackRegistry callbackRegistry) {
    if (adaptable == ObjectUtils.NULL) {
        return null;
    }
    SlingBindings bindings = getBindings(adaptable);
    if (bindings == null) {
        return null;
    }
    return bindings.get(name);
}
 
Example 2
Source File: ValueMapInjector.java    From sling-org-apache-sling-models-impl with Apache License 2.0 4 votes vote down vote up
@Override
public Object getValue(@NotNull Object adaptable, String name, @NotNull Type type, @NotNull AnnotatedElement element,
        @NotNull DisposalCallbackRegistry callbackRegistry) {
    if (adaptable == ObjectUtils.NULL) {
        return null;
    }
    ValueMap map = getValueMap(adaptable);
    if (map == null) {
        return null;
    } else if (type instanceof Class<?>) {
        Class<?> clazz = (Class<?>) type;
        try {
            return map.get(name, clazz);
        } catch (ClassCastException e) {
            // handle case of primitive/wrapper arrays
            if (clazz.isArray()) {
                Class<?> componentType = clazz.getComponentType();
                if (componentType.isPrimitive()) {
                    Class<?> wrapper = ClassUtils.primitiveToWrapper(componentType);
                    if (wrapper != componentType) {
                        Object wrapperArray = map.get(name, Array.newInstance(wrapper, 0).getClass());
                        if (wrapperArray != null) {
                            return unwrapArray(wrapperArray, componentType);
                        }
                    }
                } else {
                    Class<?> primitiveType = ClassUtils.wrapperToPrimitive(componentType);
                    if (primitiveType != componentType) {
                        Object primitiveArray = map.get(name, Array.newInstance(primitiveType, 0).getClass());
                        if (primitiveArray != null) {
                            return wrapArray(primitiveArray, componentType);
                        }
                    }
                }
            }
            return null;
        }
    } else if (type instanceof ParameterizedType) {
        // list support
        ParameterizedType pType = (ParameterizedType) type;
        if (pType.getActualTypeArguments().length != 1) {
            return null;
        }
        Class<?> collectionType = (Class<?>) pType.getRawType();
        if (!(collectionType.equals(Collection.class) || collectionType.equals(List.class))) {
            return null;
        }

        Class<?> itemType = (Class<?>) pType.getActualTypeArguments()[0];
        Object array = map.get(name, Array.newInstance(itemType, 0).getClass());
        if (array == null) {
            return null;

        }

        return Arrays.asList((Object[]) array);
    } else {
        log.debug("ValueMapInjector doesn't support non-class types {}", type);
        return null;
    }
}
 
Example 3
Source File: ValueMapInjector.java    From sling-org-apache-sling-models-impl with Apache License 2.0 4 votes vote down vote up
@Override
public Object prepareValue(final Object adaptable) {
    Object prepared = getValueMap(adaptable);
    return prepared != null ? prepared : ObjectUtils.NULL;
}
 
Example 4
Source File: BindingsInjector.java    From sling-org-apache-sling-models-impl with Apache License 2.0 4 votes vote down vote up
@Override
public Object prepareValue(Object adaptable) {
    Object prepared = getBindings(adaptable);
    return prepared != null ? prepared : ObjectUtils.NULL;
}