/** * Get the value stored under the specified {@code attributeName}, * ensuring that the value is of the {@code expectedType}. * <p>If the {@code expectedType} is an array and the value stored * under the specified {@code attributeName} is a single element of the * component type of the expected array type, the single element will be * wrapped in a single-element array of the appropriate type before * returning it. * @param attributeName the name of the attribute to get; * never {@code null} or empty * @param expectedType the expected type; never {@code null} * @return the value * @throws IllegalArgumentException if the attribute does not exist or * if it is not of the expected type */ @SuppressWarnings("unchecked") private <T> T getRequiredAttribute(String attributeName, Class<T> expectedType) { Assert.hasText(attributeName, "'attributeName' must not be null or empty"); Object value = get(attributeName); assertAttributePresence(attributeName, value); assertNotException(attributeName, value); if (!expectedType.isInstance(value) && expectedType.isArray() && expectedType.getComponentType().isInstance(value)) { Object array = Array.newInstance(expectedType.getComponentType(), 1); Array.set(array, 0, value); value = array; } assertAttributeType(attributeName, value, expectedType); return (T) value; }
/** * Get the value stored under the specified {@code attributeName}, * ensuring that the value is of the {@code expectedType}. * <p>If the {@code expectedType} is an array and the value stored * under the specified {@code attributeName} is a single element of the * component type of the expected array type, the single element will be * wrapped in a single-element array of the appropriate type before * returning it. * @param attributeName the name of the attribute to get; * never {@code null} or empty * @param expectedType the expected type; never {@code null} * @return the value * @throws IllegalArgumentException if the attribute does not exist or * if it is not of the expected type */ @SuppressWarnings("unchecked") private <T> T getRequiredAttribute(String attributeName, Class<T> expectedType) { Assert.hasText(attributeName, "'attributeName' must not be null or empty"); Object value = get(attributeName); assertAttributePresence(attributeName, value); assertNotException(attributeName, value); if (!expectedType.isInstance(value) && expectedType.isArray() && expectedType.getComponentType().isInstance(value)) { Object array = Array.newInstance(expectedType.getComponentType(), 1); Array.set(array, 0, value); value = array; } assertAttributeType(attributeName, value, expectedType); return (T) value; }
/** * Get the value stored under the specified {@code attributeName}, * ensuring that the value is of the {@code expectedType}. * <p>If the {@code expectedType} is an array and the value stored * under the specified {@code attributeName} is a single element of the * component type of the expected array type, the single element will be * wrapped in a single-element array of the appropriate type before * returning it. * @param attributeName the name of the attribute to get; * never {@code null} or empty * @param expectedType the expected type; never {@code null} * @return the value * @throws IllegalArgumentException if the attribute does not exist or * if it is not of the expected type */ @SuppressWarnings("unchecked") private <T> T getRequiredAttribute(String attributeName, Class<T> expectedType) { Assert.hasText(attributeName, "'attributeName' must not be null or empty"); Object value = get(attributeName); assertAttributePresence(attributeName, value); assertNotException(attributeName, value); if (!expectedType.isInstance(value) && expectedType.isArray() && expectedType.getComponentType().isInstance(value)) { Object array = Array.newInstance(expectedType.getComponentType(), 1); Array.set(array, 0, value); value = array; } assertAttributeType(attributeName, value, expectedType); return (T) value; }
/** * Get the value stored under the specified {@code attributeName}, * ensuring that the value is of the {@code expectedType}. * <p>If the {@code expectedType} is an array and the value stored * under the specified {@code attributeName} is a single element of the * component type of the expected array type, the single element will be * wrapped in a single-element array of the appropriate type before * returning it. * @param attributeName the name of the attribute to get; * never {@code null} or empty * @param expectedType the expected type; never {@code null} * @return the value * @throws IllegalArgumentException if the attribute does not exist or * if it is not of the expected type */ @SuppressWarnings("unchecked") private <T> T getRequiredAttribute(String attributeName, Class<T> expectedType) { Assert.hasText(attributeName, "'attributeName' must not be null or empty"); Object value = get(attributeName); assertAttributePresence(attributeName, value); assertNotException(attributeName, value); if (!expectedType.isInstance(value) && expectedType.isArray() && expectedType.getComponentType().isInstance(value)) { Object array = Array.newInstance(expectedType.getComponentType(), 1); Array.set(array, 0, value); value = array; } assertAttributeType(attributeName, value, expectedType); return (T) value; }