对于org.springframework.util.Assert源码感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解springautowired源码,并且为您提供关于Java-Class
对于org.springframework.util.Assert源码感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解spring autowired源码,并且为您提供关于Java-Class-C:org.springframework.util.Assert、org.springframework.beans.PropertyAccessorUtils的实例源码、org.springframework.boot.cli.compiler.AstUtils的实例源码、org.springframework.boot.cli.util.Log的实例源码的宝贵知识。
本文目录一览:- org.springframework.util.Assert源码(spring autowired源码)
- Java-Class-C:org.springframework.util.Assert
- org.springframework.beans.PropertyAccessorUtils的实例源码
- org.springframework.boot.cli.compiler.AstUtils的实例源码
- org.springframework.boot.cli.util.Log的实例源码
org.springframework.util.Assert源码(spring autowired源码)
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.springframework.util;
import java.util.Collection;
import java.util.Map;
/**
* Assertion utility class that assists in validating arguments.
* Useful for identifying programmer errors early and clearly at runtime.
*
* <p>For example, if the contract of a public method states it does not
* allow {@code null} arguments, Assert can be used to validate that
* contract. Doing this clearly indicates a contract violation when it
* occurs and protects the class''s invariants.
*
* <p>Typically used to validate method arguments rather than configuration
* properties, to check for cases that are usually programmer errors rather than
* configuration errors. In contrast to config initialization code, there is
* usally no point in falling back to defaults in such methods.
*
* <p>This class is similar to JUnit''s assertion library. If an argument value is
* deemed invalid, an {@link IllegalArgumentException} is thrown (typically).
* For example:
*
* <pre>
* Assert.notNull(clazz, "The class must not be null");
* Assert.isTrue(i > 0, "The value must be greater than zero");</pre>
*
* Mainly for internal use within the framework; consider Jakarta''s Commons Lang
* >= 2.0 for a more comprehensive suite of assertion utilities.
*
* @author Keith Donald
* @author Juergen Hoeller
* @author Colin Sampaleanu
* @author Rob Harrop
* @since 1.1.2
*/
public abstract class Assert {
/**
* Assert a boolean expression, throwing {@code IllegalArgumentException}
* if the test result is {@code false}.
* <pre>Assert.isTrue(i > 0, "The value must be greater than zero");</pre>
* @param expression a boolean expression
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if expression is {@code false}
*/
public static void isTrue(boolean expression, String message) {
if (!expression) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert a boolean expression, throwing {@code IllegalArgumentException}
* if the test result is {@code false}.
* <pre>Assert.isTrue(i > 0);</pre>
* @param expression a boolean expression
* @throws IllegalArgumentException if expression is {@code false}
*/
public static void isTrue(boolean expression) {
isTrue(expression, "[Assertion failed] - this expression must be true");
}
/**
* Assert that an object is {@code null} .
* <pre>Assert.isNull(value, "The value must be null");</pre>
* @param object the object to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the object is not {@code null}
*/
public static void isNull(Object object, String message) {
if (object != null) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that an object is {@code null} .
* <pre>Assert.isNull(value);</pre>
* @param object the object to check
* @throws IllegalArgumentException if the object is not {@code null}
*/
public static void isNull(Object object) {
isNull(object, "[Assertion failed] - the object argument must be null");
}
/**
* Assert that an object is not {@code null} .
* <pre>Assert.notNull(clazz, "The class must not be null");</pre>
* @param object the object to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the object is {@code null}
*/
public static void notNull(Object object, String message) {
if (object == null) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that an object is not {@code null} .
* <pre>Assert.notNull(clazz);</pre>
* @param object the object to check
* @throws IllegalArgumentException if the object is {@code null}
*/
public static void notNull(Object object) {
notNull(object, "[Assertion failed] - this argument is required; it must not be null");
}
/**
* Assert that the given String is not empty; that is,
* it must not be {@code null} and not the empty String.
* <pre>Assert.hasLength(name, "Name must not be empty");</pre>
* @param text the String to check
* @param message the exception message to use if the assertion fails
* @see StringUtils#hasLength
*/
public static void hasLength(String text, String message) {
if (!StringUtils.hasLength(text)) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that the given String is not empty; that is,
* it must not be {@code null} and not the empty String.
* <pre>Assert.hasLength(name);</pre>
* @param text the String to check
* @see StringUtils#hasLength
*/
public static void hasLength(String text) {
hasLength(text,
"[Assertion failed] - this String argument must have length; it must not be null or empty");
}
/**
* Assert that the given String has valid text content; that is, it must not
* be {@code null} and must contain at least one non-whitespace character.
* <pre>Assert.hasText(name, "''name'' must not be empty");</pre>
* @param text the String to check
* @param message the exception message to use if the assertion fails
* @see StringUtils#hasText
*/
public static void hasText(String text, String message) {
if (!StringUtils.hasText(text)) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that the given String has valid text content; that is, it must not
* be {@code null} and must contain at least one non-whitespace character.
* <pre>Assert.hasText(name, "''name'' must not be empty");</pre>
* @param text the String to check
* @see StringUtils#hasText
*/
public static void hasText(String text) {
hasText(text,
"[Assertion failed] - this String argument must have text; it must not be null, empty, or blank");
}
/**
* Assert that the given text does not contain the given substring.
* <pre>Assert.doesNotContain(name, "rod", "Name must not contain ''rod''");</pre>
* @param textToSearch the text to search
* @param substring the substring to find within the text
* @param message the exception message to use if the assertion fails
*/
public static void doesNotContain(String textToSearch, String substring, String message) {
if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) &&
textToSearch.contains(substring)) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that the given text does not contain the given substring.
* <pre>Assert.doesNotContain(name, "rod");</pre>
* @param textToSearch the text to search
* @param substring the substring to find within the text
*/
public static void doesNotContain(String textToSearch, String substring) {
doesNotContain(textToSearch, substring,
"[Assertion failed] - this String argument must not contain the substring [" + substring + "]");
}
/**
* Assert that an array has elements; that is, it must not be
* {@code null} and must have at least one element.
* <pre>Assert.notEmpty(array, "The array must have elements");</pre>
* @param array the array to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the object array is {@code null} or has no elements
*/
public static void notEmpty(Object[] array, String message) {
if (ObjectUtils.isEmpty(array)) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that an array has elements; that is, it must not be
* {@code null} and must have at least one element.
* <pre>Assert.notEmpty(array);</pre>
* @param array the array to check
* @throws IllegalArgumentException if the object array is {@code null} or has no elements
*/
public static void notEmpty(Object[] array) {
notEmpty(array, "[Assertion failed] - this array must not be empty: it must contain at least 1 element");
}
/**
* Assert that an array has no null elements.
* Note: Does not complain if the array is empty!
* <pre>Assert.noNullElements(array, "The array must have non-null elements");</pre>
* @param array the array to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the object array contains a {@code null} element
*/
public static void noNullElements(Object[] array, String message) {
if (array != null) {
for (Object element : array) {
if (element == null) {
throw new IllegalArgumentException(message);
}
}
}
}
/**
* Assert that an array has no null elements.
* Note: Does not complain if the array is empty!
* <pre>Assert.noNullElements(array);</pre>
* @param array the array to check
* @throws IllegalArgumentException if the object array contains a {@code null} element
*/
public static void noNullElements(Object[] array) {
noNullElements(array, "[Assertion failed] - this array must not contain any null elements");
}
/**
* Assert that a collection has elements; that is, it must not be
* {@code null} and must have at least one element.
* <pre>Assert.notEmpty(collection, "Collection must have elements");</pre>
* @param collection the collection to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the collection is {@code null} or has no elements
*/
public static void notEmpty(Collection<?> collection, String message) {
if (CollectionUtils.isEmpty(collection)) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that a collection has elements; that is, it must not be
* {@code null} and must have at least one element.
* <pre>Assert.notEmpty(collection, "Collection must have elements");</pre>
* @param collection the collection to check
* @throws IllegalArgumentException if the collection is {@code null} or has no elements
*/
public static void notEmpty(Collection<?> collection) {
notEmpty(collection,
"[Assertion failed] - this collection must not be empty: it must contain at least 1 element");
}
/**
* Assert that a Map has entries; that is, it must not be {@code null}
* and must have at least one entry.
* <pre>Assert.notEmpty(map, "Map must have entries");</pre>
* @param map the map to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the map is {@code null} or has no entries
*/
public static void notEmpty(Map<?, ?> map, String message) {
if (CollectionUtils.isEmpty(map)) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that a Map has entries; that is, it must not be {@code null}
* and must have at least one entry.
* <pre>Assert.notEmpty(map);</pre>
* @param map the map to check
* @throws IllegalArgumentException if the map is {@code null} or has no entries
*/
public static void notEmpty(Map<?, ?> map) {
notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry");
}
/**
* Assert that the provided object is an instance of the provided class.
* <pre>Assert.instanceOf(Foo.class, foo);</pre>
* @param clazz the required class
* @param obj the object to check
* @throws IllegalArgumentException if the object is not an instance of clazz
* @see Class#isInstance
*/
public static void isInstanceOf(Class<?> clazz, Object obj) {
isInstanceOf(clazz, obj, "");
}
/**
* Assert that the provided object is an instance of the provided class.
* <pre>Assert.instanceOf(Foo.class, foo);</pre>
* @param type the type to check against
* @param obj the object to check
* @param message a message which will be prepended to the message produced by
* the function itself, and which may be used to provide context. It should
* normally end in a ": " or ". " so that the function generate message looks
* ok when prepended to it.
* @throws IllegalArgumentException if the object is not an instance of clazz
* @see Class#isInstance
*/
public static void isInstanceOf(Class<?> type, Object obj, String message) {
notNull(type, "Type to check against must not be null");
if (!type.isInstance(obj)) {
throw new IllegalArgumentException(
(StringUtils.hasLength(message) ? message + " " : "") +
"Object of class [" + (obj != null ? obj.getClass().getName() : "null") +
"] must be an instance of " + type);
}
}
/**
* Assert that {@code superType.isAssignableFrom(subType)} is {@code true}.
* <pre>Assert.isAssignable(Number.class, myClass);</pre>
* @param superType the super type to check
* @param subType the sub type to check
* @throws IllegalArgumentException if the classes are not assignable
*/
public static void isAssignable(Class<?> superType, Class<?> subType) {
isAssignable(superType, subType, "");
}
/**
* Assert that {@code superType.isAssignableFrom(subType)} is {@code true}.
* <pre>Assert.isAssignable(Number.class, myClass);</pre>
* @param superType the super type to check against
* @param subType the sub type to check
* @param message a message which will be prepended to the message produced by
* the function itself, and which may be used to provide context. It should
* normally end in a ": " or ". " so that the function generate message looks
* ok when prepended to it.
* @throws IllegalArgumentException if the classes are not assignable
*/
public static void isAssignable(Class<?> superType, Class<?> subType, String message) {
notNull(superType, "Type to check against must not be null");
if (subType == null || !superType.isAssignableFrom(subType)) {
throw new IllegalArgumentException(message + subType + " is not assignable to " + superType);
}
}
/**
* Assert a boolean expression, throwing {@code IllegalStateException}
* if the test result is {@code false}. Call isTrue if you wish to
* throw IllegalArgumentException on an assertion failure.
* <pre>Assert.state(id == null, "The id property must not already be initialized");</pre>
* @param expression a boolean expression
* @param message the exception message to use if the assertion fails
* @throws IllegalStateException if expression is {@code false}
*/
public static void state(boolean expression, String message) {
if (!expression) {
throw new IllegalStateException(message);
}
}
/**
* Assert a boolean expression, throwing {@link IllegalStateException}
* if the test result is {@code false}.
* <p>Call {@link #isTrue(boolean)} if you wish to
* throw {@link IllegalArgumentException} on an assertion failure.
* <pre>Assert.state(id == null);</pre>
* @param expression a boolean expression
* @throws IllegalStateException if the supplied expression is {@code false}
*/
public static void state(boolean expression) {
state(expression, "[Assertion failed] - this state invariant must be true");
}
}
Java-Class-C:org.springframework.util.Assert
ylbtech-Java-Class-C:org.springframework.util.Assert |
/*
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.util;
import java.util.Collection;
import java.util.Map;
import java.util.function.Supplier;
import org.springframework.lang.Nullable;
/**
* Assertion utility class that assists in validating arguments.
*
* <p>Useful for identifying programmer errors early and clearly at runtime.
*
* <p>For example, if the contract of a public method states it does not
* allow {@code null} arguments, {@code Assert} can be used to validate that
* contract. Doing this clearly indicates a contract violation when it
* occurs and protects the class''s invariants.
*
* <p>Typically used to validate method arguments rather than configuration
* properties, to check for cases that are usually programmer errors rather
* than configuration errors. In contrast to configuration initialization
* code, there is usually no point in falling back to defaults in such methods.
*
* <p>This class is similar to JUnit''s assertion library. If an argument value is
* deemed invalid, an {@link IllegalArgumentException} is thrown (typically).
* For example:
*
* <pre>
* Assert.notNull(clazz, "The class must not be null");
* Assert.isTrue(i > 0, "The value must be greater than zero");</pre>
*
* <p>Mainly for internal use within the framework; consider
* <a href="http://commons.apache.org/proper/commons-lang/">Apache''s Commons Lang</a>
* for a more comprehensive suite of {@code String} utilities.
*
* @author Keith Donald
* @author Juergen Hoeller
* @author Sam Brannen
* @author Colin Sampaleanu
* @author Rob Harrop
* @since 1.1.2
*/
public abstract class Assert {
/**
* Assert a boolean expression, throwing an {@code IllegalStateException}
* if the expression evaluates to {@code false}.
* <p>Call {@link #isTrue} if you wish to throw an {@code IllegalArgumentException}
* on an assertion failure.
* <pre>Assert.state(id == null, "The id property must not already be initialized");</pre>
* @param expression a boolean expression
* @param message the exception message to use if the assertion fails
* @throws IllegalStateException if {@code expression} is {@code false}
*/
public static void state(boolean expression, String message) {
if (!expression) {
throw new IllegalStateException(message);
}
}
/**
* Assert a boolean expression, throwing an {@code IllegalStateException}
* if the expression evaluates to {@code false}.
* <p>Call {@link #isTrue} if you wish to throw an {@code IllegalArgumentException}
* on an assertion failure.
* <pre>
* Assert.state(id == null,
* () -> "ID for " + entity.getName() + " must not already be initialized");
* </pre>
* @param expression a boolean expression
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails
* @throws IllegalStateException if {@code expression} is {@code false}
* @since 5.0
*/
public static void state(boolean expression, Supplier<String> messageSupplier) {
if (!expression) {
throw new IllegalStateException(nullSafeGet(messageSupplier));
}
}
/**
* Assert a boolean expression, throwing an {@code IllegalStateException}
* if the expression evaluates to {@code false}.
* @deprecated as of 4.3.7, in favor of {@link #state(boolean, String)}
*/
@Deprecated
public static void state(boolean expression) {
state(expression, "[Assertion failed] - this state invariant must be true");
}
/**
* Assert a boolean expression, throwing an {@code IllegalArgumentException}
* if the expression evaluates to {@code false}.
* <pre>Assert.isTrue(i > 0, "The value must be greater than zero");</pre>
* @param expression a boolean expression
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if {@code expression} is {@code false}
*/
public static void isTrue(boolean expression, String message) {
if (!expression) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert a boolean expression, throwing an {@code IllegalArgumentException}
* if the expression evaluates to {@code false}.
* <pre>
* Assert.isTrue(i > 0, () -> "The value ''" + i + "'' must be greater than zero");
* </pre>
* @param expression a boolean expression
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails
* @throws IllegalArgumentException if {@code expression} is {@code false}
* @since 5.0
*/
public static void isTrue(boolean expression, Supplier<String> messageSupplier) {
if (!expression) {
throw new IllegalArgumentException(nullSafeGet(messageSupplier));
}
}
/**
* Assert a boolean expression, throwing an {@code IllegalArgumentException}
* if the expression evaluates to {@code false}.
* @deprecated as of 4.3.7, in favor of {@link #isTrue(boolean, String)}
*/
@Deprecated
public static void isTrue(boolean expression) {
isTrue(expression, "[Assertion failed] - this expression must be true");
}
/**
* Assert that an object is {@code null}.
* <pre>Assert.isNull(value, "The value must be null");</pre>
* @param object the object to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the object is not {@code null}
*/
public static void isNull(@Nullable Object object, String message) {
if (object != null) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that an object is {@code null}.
* <pre>
* Assert.isNull(value, () -> "The value ''" + value + "'' must be null");
* </pre>
* @param object the object to check
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails
* @throws IllegalArgumentException if the object is not {@code null}
* @since 5.0
*/
public static void isNull(@Nullable Object object, Supplier<String> messageSupplier) {
if (object != null) {
throw new IllegalArgumentException(nullSafeGet(messageSupplier));
}
}
/**
* Assert that an object is {@code null}.
* @deprecated as of 4.3.7, in favor of {@link #isNull(Object, String)}
*/
@Deprecated
public static void isNull(@Nullable Object object) {
isNull(object, "[Assertion failed] - the object argument must be null");
}
/**
* Assert that an object is not {@code null}.
* <pre>Assert.notNull(clazz, "The class must not be null");</pre>
* @param object the object to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the object is {@code null}
*/
public static void notNull(@Nullable Object object, String message) {
if (object == null) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that an object is not {@code null}.
* <pre>
* Assert.notNull(clazz, () -> "The class ''" + clazz.getName() + "'' must not be null");
* </pre>
* @param object the object to check
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails
* @throws IllegalArgumentException if the object is {@code null}
* @since 5.0
*/
public static void notNull(@Nullable Object object, Supplier<String> messageSupplier) {
if (object == null) {
throw new IllegalArgumentException(nullSafeGet(messageSupplier));
}
}
/**
* Assert that an object is not {@code null}.
* @deprecated as of 4.3.7, in favor of {@link #notNull(Object, String)}
*/
@Deprecated
public static void notNull(@Nullable Object object) {
notNull(object, "[Assertion failed] - this argument is required; it must not be null");
}
/**
* Assert that the given String is not empty; that is,
* it must not be {@code null} and not the empty String.
* <pre>Assert.hasLength(name, "Name must not be empty");</pre>
* @param text the String to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the text is empty
* @see StringUtils#hasLength
*/
public static void hasLength(@Nullable String text, String message) {
if (!StringUtils.hasLength(text)) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that the given String is not empty; that is,
* it must not be {@code null} and not the empty String.
* <pre>
* Assert.hasLength(name, () -> "Name for account ''" + account.getId() + "'' must not be empty");
* </pre>
* @param text the String to check
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails
* @throws IllegalArgumentException if the text is empty
* @since 5.0
* @see StringUtils#hasLength
*/
public static void hasLength(@Nullable String text, Supplier<String> messageSupplier) {
if (!StringUtils.hasLength(text)) {
throw new IllegalArgumentException(nullSafeGet(messageSupplier));
}
}
/**
* Assert that the given String is not empty; that is,
* it must not be {@code null} and not the empty String.
* @deprecated as of 4.3.7, in favor of {@link #hasLength(String, String)}
*/
@Deprecated
public static void hasLength(@Nullable String text) {
hasLength(text,
"[Assertion failed] - this String argument must have length; it must not be null or empty");
}
/**
* Assert that the given String contains valid text content; that is, it must not
* be {@code null} and must contain at least one non-whitespace character.
* <pre>Assert.hasText(name, "''name'' must not be empty");</pre>
* @param text the String to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the text does not contain valid text content
* @see StringUtils#hasText
*/
public static void hasText(@Nullable String text, String message) {
if (!StringUtils.hasText(text)) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that the given String contains valid text content; that is, it must not
* be {@code null} and must contain at least one non-whitespace character.
* <pre>
* Assert.hasText(name, () -> "Name for account ''" + account.getId() + "'' must not be empty");
* </pre>
* @param text the String to check
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails
* @throws IllegalArgumentException if the text does not contain valid text content
* @since 5.0
* @see StringUtils#hasText
*/
public static void hasText(@Nullable String text, Supplier<String> messageSupplier) {
if (!StringUtils.hasText(text)) {
throw new IllegalArgumentException(nullSafeGet(messageSupplier));
}
}
/**
* Assert that the given String contains valid text content; that is, it must not
* be {@code null} and must contain at least one non-whitespace character.
* @deprecated as of 4.3.7, in favor of {@link #hasText(String, String)}
*/
@Deprecated
public static void hasText(@Nullable String text) {
hasText(text,
"[Assertion failed] - this String argument must have text; it must not be null, empty, or blank");
}
/**
* Assert that the given text does not contain the given substring.
* <pre>Assert.doesNotContain(name, "rod", "Name must not contain ''rod''");</pre>
* @param textToSearch the text to search
* @param substring the substring to find within the text
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the text contains the substring
*/
public static void doesNotContain(@Nullable String textToSearch, String substring, String message) {
if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) &&
textToSearch.contains(substring)) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that the given text does not contain the given substring.
* <pre>
* Assert.doesNotContain(name, forbidden, () -> "Name must not contain ''" + forbidden + "''");
* </pre>
* @param textToSearch the text to search
* @param substring the substring to find within the text
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails
* @throws IllegalArgumentException if the text contains the substring
* @since 5.0
*/
public static void doesNotContain(@Nullable String textToSearch, String substring, Supplier<String> messageSupplier) {
if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) &&
textToSearch.contains(substring)) {
throw new IllegalArgumentException(nullSafeGet(messageSupplier));
}
}
/**
* Assert that the given text does not contain the given substring.
* @deprecated as of 4.3.7, in favor of {@link #doesNotContain(String, String, String)}
*/
@Deprecated
public static void doesNotContain(@Nullable String textToSearch, String substring) {
doesNotContain(textToSearch, substring,
() -> "[Assertion failed] - this String argument must not contain the substring [" + substring + "]");
}
/**
* Assert that an array contains elements; that is, it must not be
* {@code null} and must contain at least one element.
* <pre>Assert.notEmpty(array, "The array must contain elements");</pre>
* @param array the array to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the object array is {@code null} or contains no elements
*/
public static void notEmpty(@Nullable Object[] array, String message) {
if (ObjectUtils.isEmpty(array)) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that an array contains elements; that is, it must not be
* {@code null} and must contain at least one element.
* <pre>
* Assert.notEmpty(array, () -> "The " + arrayType + " array must contain elements");
* </pre>
* @param array the array to check
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails
* @throws IllegalArgumentException if the object array is {@code null} or contains no elements
* @since 5.0
*/
public static void notEmpty(@Nullable Object[] array, Supplier<String> messageSupplier) {
if (ObjectUtils.isEmpty(array)) {
throw new IllegalArgumentException(nullSafeGet(messageSupplier));
}
}
/**
* Assert that an array contains elements; that is, it must not be
* {@code null} and must contain at least one element.
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Object[], String)}
*/
@Deprecated
public static void notEmpty(@Nullable Object[] array) {
notEmpty(array, "[Assertion failed] - this array must not be empty: it must contain at least 1 element");
}
/**
* Assert that an array contains no {@code null} elements.
* <p>Note: Does not complain if the array is empty!
* <pre>Assert.noNullElements(array, "The array must contain non-null elements");</pre>
* @param array the array to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the object array contains a {@code null} element
*/
public static void noNullElements(@Nullable Object[] array, String message) {
if (array != null) {
for (Object element : array) {
if (element == null) {
throw new IllegalArgumentException(message);
}
}
}
}
/**
* Assert that an array contains no {@code null} elements.
* <p>Note: Does not complain if the array is empty!
* <pre>
* Assert.noNullElements(array, () -> "The " + arrayType + " array must contain non-null elements");
* </pre>
* @param array the array to check
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails
* @throws IllegalArgumentException if the object array contains a {@code null} element
* @since 5.0
*/
public static void noNullElements(@Nullable Object[] array, Supplier<String> messageSupplier) {
if (array != null) {
for (Object element : array) {
if (element == null) {
throw new IllegalArgumentException(nullSafeGet(messageSupplier));
}
}
}
}
/**
* Assert that an array contains no {@code null} elements.
* @deprecated as of 4.3.7, in favor of {@link #noNullElements(Object[], String)}
*/
@Deprecated
public static void noNullElements(@Nullable Object[] array) {
noNullElements(array, "[Assertion failed] - this array must not contain any null elements");
}
/**
* Assert that a collection contains elements; that is, it must not be
* {@code null} and must contain at least one element.
* <pre>Assert.notEmpty(collection, "Collection must contain elements");</pre>
* @param collection the collection to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the collection is {@code null} or
* contains no elements
*/
public static void notEmpty(@Nullable Collection<?> collection, String message) {
if (CollectionUtils.isEmpty(collection)) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that a collection contains elements; that is, it must not be
* {@code null} and must contain at least one element.
* <pre>
* Assert.notEmpty(collection, () -> "The " + collectionType + " collection must contain elements");
* </pre>
* @param collection the collection to check
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails
* @throws IllegalArgumentException if the collection is {@code null} or
* contains no elements
* @since 5.0
*/
public static void notEmpty(@Nullable Collection<?> collection, Supplier<String> messageSupplier) {
if (CollectionUtils.isEmpty(collection)) {
throw new IllegalArgumentException(nullSafeGet(messageSupplier));
}
}
/**
* Assert that a collection contains elements; that is, it must not be
* {@code null} and must contain at least one element.
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Collection, String)}
*/
@Deprecated
public static void notEmpty(@Nullable Collection<?> collection) {
notEmpty(collection,
"[Assertion failed] - this collection must not be empty: it must contain at least 1 element");
}
/**
* Assert that a Map contains entries; that is, it must not be {@code null}
* and must contain at least one entry.
* <pre>Assert.notEmpty(map, "Map must contain entries");</pre>
* @param map the map to check
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the map is {@code null} or contains no entries
*/
public static void notEmpty(@Nullable Map<?, ?> map, String message) {
if (CollectionUtils.isEmpty(map)) {
throw new IllegalArgumentException(message);
}
}
/**
* Assert that a Map contains entries; that is, it must not be {@code null}
* and must contain at least one entry.
* <pre>
* Assert.notEmpty(map, () -> "The " + mapType + " map must contain entries");
* </pre>
* @param map the map to check
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails
* @throws IllegalArgumentException if the map is {@code null} or contains no entries
* @since 5.0
*/
public static void notEmpty(@Nullable Map<?, ?> map, Supplier<String> messageSupplier) {
if (CollectionUtils.isEmpty(map)) {
throw new IllegalArgumentException(nullSafeGet(messageSupplier));
}
}
/**
* Assert that a Map contains entries; that is, it must not be {@code null}
* and must contain at least one entry.
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Map, String)}
*/
@Deprecated
public static void notEmpty(@Nullable Map<?, ?> map) {
notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry");
}
/**
* Assert that the provided object is an instance of the provided class.
* <pre>Assert.instanceOf(Foo.class, foo, "Foo expected");</pre>
* @param type the type to check against
* @param obj the object to check
* @param message a message which will be prepended to provide further context.
* If it is empty or ends in ":" or ";" or "," or ".", a full exception message
* will be appended. If it ends in a space, the name of the offending object''s
* type will be appended. In any other case, a ":" with a space and the name
* of the offending object''s type will be appended.
* @throws IllegalArgumentException if the object is not an instance of type
*/
public static void isInstanceOf(Class<?> type, @Nullable Object obj, String message) {
notNull(type, "Type to check against must not be null");
if (!type.isInstance(obj)) {
instanceCheckFailed(type, obj, message);
}
}
/**
* Assert that the provided object is an instance of the provided class.
* <pre>
* Assert.instanceOf(Foo.class, foo, () -> "Processing " + Foo.class.getSimpleName() + ":");
* </pre>
* @param type the type to check against
* @param obj the object to check
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails. See {@link #isInstanceOf(Class, Object, String)} for details.
* @throws IllegalArgumentException if the object is not an instance of type
* @since 5.0
*/
public static void isInstanceOf(Class<?> type, @Nullable Object obj, Supplier<String> messageSupplier) {
notNull(type, "Type to check against must not be null");
if (!type.isInstance(obj)) {
instanceCheckFailed(type, obj, nullSafeGet(messageSupplier));
}
}
/**
* Assert that the provided object is an instance of the provided class.
* <pre>Assert.instanceOf(Foo.class, foo);</pre>
* @param type the type to check against
* @param obj the object to check
* @throws IllegalArgumentException if the object is not an instance of type
*/
public static void isInstanceOf(Class<?> type, @Nullable Object obj) {
isInstanceOf(type, obj, "");
}
/**
* Assert that {@code superType.isAssignableFrom(subType)} is {@code true}.
* <pre>Assert.isAssignable(Number.class, myClass, "Number expected");</pre>
* @param superType the super type to check against
* @param subType the sub type to check
* @param message a message which will be prepended to provide further context.
* If it is empty or ends in ":" or ";" or "," or ".", a full exception message
* will be appended. If it ends in a space, the name of the offending sub type
* will be appended. In any other case, a ":" with a space and the name of the
* offending sub type will be appended.
* @throws IllegalArgumentException if the classes are not assignable
*/
public static void isAssignable(Class<?> superType, @Nullable Class<?> subType, String message) {
notNull(superType, "Super type to check against must not be null");
if (subType == null || !superType.isAssignableFrom(subType)) {
assignableCheckFailed(superType, subType, message);
}
}
/**
* Assert that {@code superType.isAssignableFrom(subType)} is {@code true}.
* <pre>
* Assert.isAssignable(Number.class, myClass, () -> "Processing " + myAttributeName + ":");
* </pre>
* @param superType the super type to check against
* @param subType the sub type to check
* @param messageSupplier a supplier for the exception message to use if the
* assertion fails. See {@link #isAssignable(Class, Class, String)} for details.
* @throws IllegalArgumentException if the classes are not assignable
* @since 5.0
*/
public static void isAssignable(Class<?> superType, @Nullable Class<?> subType, Supplier<String> messageSupplier) {
notNull(superType, "Super type to check against must not be null");
if (subType == null || !superType.isAssignableFrom(subType)) {
assignableCheckFailed(superType, subType, nullSafeGet(messageSupplier));
}
}
/**
* Assert that {@code superType.isAssignableFrom(subType)} is {@code true}.
* <pre>Assert.isAssignable(Number.class, myClass);</pre>
* @param superType the super type to check
* @param subType the sub type to check
* @throws IllegalArgumentException if the classes are not assignable
*/
public static void isAssignable(Class<?> superType, Class<?> subType) {
isAssignable(superType, subType, "");
}
private static void instanceCheckFailed(Class<?> type, @Nullable Object obj, @Nullable String msg) {
String className = (obj != null ? obj.getClass().getName() : "null");
String result = "";
boolean defaultMessage = true;
if (StringUtils.hasLength(msg)) {
if (endsWithSeparator(msg)) {
result = msg + " ";
}
else {
result = messageWithTypeName(msg, className);
defaultMessage = false;
}
}
if (defaultMessage) {
result = result + ("Object of class [" + className + "] must be an instance of " + type);
}
throw new IllegalArgumentException(result);
}
private static void assignableCheckFailed(Class<?> superType, @Nullable Class<?> subType, @Nullable String msg) {
String result = "";
boolean defaultMessage = true;
if (StringUtils.hasLength(msg)) {
if (endsWithSeparator(msg)) {
result = msg + " ";
}
else {
result = messageWithTypeName(msg, subType);
defaultMessage = false;
}
}
if (defaultMessage) {
result = result + (subType + " is not assignable to " + superType);
}
throw new IllegalArgumentException(result);
}
private static boolean endsWithSeparator(String msg) {
return (msg.endsWith(":") || msg.endsWith(";") || msg.endsWith(",") || msg.endsWith("."));
}
private static String messageWithTypeName(String msg, @Nullable Object typeName) {
return msg + (msg.endsWith(" ") ? "" : ": ") + typeName;
}
@Nullable
private static String nullSafeGet(@Nullable Supplier<String> messageSupplier) {
return (messageSupplier != null ? messageSupplier.get() : null);
}
}

出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
org.springframework.beans.PropertyAccessorUtils的实例源码
/** * Overridden to copy property editor registration to the new bean wrapper. * * <p>This is necessary because spring only copies over the editors when a new bean wrapper is * created. The wrapper is then cached and use for subsequent calls. But the get calls Could bring in * new custom editors we need to copy.</p> * * {@inheritDoc} */ @Override protected BeanWrapperImpl getBeanWrapperForPropertyPath(String propertyPath) { BeanWrapperImpl beanWrapper = super.getBeanWrapperForPropertyPath(propertyPath); PropertyTokenHolder tokens = getPropertyNametokens(propertyPath); String canonicalName = tokens.canonicalName; int pos = PropertyAccessorUtils.getFirstnestedPropertySeparatorIndex(canonicalName); if (pos != -1) { canonicalName = canonicalName.substring(0,pos); } copyCustomEditorsTo(beanWrapper,canonicalName); return beanWrapper; }
/** * Set the parent for bi-directional relationships when adding a line to a collection. * * @param model the view data * @param collectionPath the path to the collection being linked * @param addedindex the index of the added line * @return whether the linked line needs further processing */ protected boolean linkAddedLine(Object model,String collectionPath,int addedindex) { int lastSepIndex = PropertyAccessorUtils.getLastnestedPropertySeparatorIndex(collectionPath); if (lastSepIndex != -1) { String collectionParentPath = collectionPath.substring(0,lastSepIndex); Object parent = ObjectPropertyUtils.getPropertyValue(model,collectionParentPath); if (parent != null && getDataObjectService().supports(parent.getClass())) { DataObjectWrapper<?> wrappedParent = getDataObjectService().wrap(parent); String collectionName = collectionPath.substring(lastSepIndex + 1); wrappedParent.linkChanges(Sets.newHashSet(collectionName + "[" + addedindex + "]")); } // check if its edit line in dialog line action,and if it is we want to set the collection as // the dialog's parent and do not want further processing of the dialog object if (collectionParentPath.equalsIgnoreCase(UifPropertyPaths.DIALOG_DATA_OBJECT)) { ((UifFormBase) model).setDialogDataObject(parent); return false; } } return true; }
@Override public Map<String,String> getInquiryParameters(Object dataObject,List<String> keys,String propertyName) { Map<String,String> inquiryParameters = new HashMap<String,String>(); org.kuali.rice.krad.data.Metadata.DataObjectRelationship dataObjectRelationship = null; DataObjectMetadata objectMetadata = KRADServiceLocator.getDataObjectService().getMetadataRepository().getMetadata(dataObject.getClass()); if (objectMetadata != null) { dataObjectRelationship = objectMetadata.getRelationshipByLastAttributeInRelationship(propertyName); } for (String keyName : keys) { String keyConversion = keyName; if (dataObjectRelationship != null) { keyConversion = dataObjectRelationship.getParentAttributeNameRelatedtochildAttributeName(keyName); } else if (PropertyAccessorUtils.isnestedOrIndexedProperty(propertyName)) { String nestedAttributePrefix = KRADUtils.getnestedAttributePrefix(propertyName); keyConversion = nestedAttributePrefix + "." + keyName; } inquiryParameters.put(keyConversion,keyName); } return inquiryParameters; }
/** * Gets the property type for a property name. * * @param objectMetadata the Metadata object. * @param propertyName the name of the property. * @return the property type for a property name. */ private Class<?> getPropertyTypeChild(DataObjectMetadata objectMetadata,String propertyName){ if(PropertyAccessorUtils.isnestedOrIndexedProperty(propertyName)){ String attributePrefix = StringUtils.substringBefore(propertyName,"."); String attributeName = StringUtils.substringAfter(propertyName,"."); if(StringUtils.isNotBlank(attributePrefix) && StringUtils.isNotBlank(attributeName) && objectMetadata!= null){ Class<?> propertyType = traverseRelationship(objectMetadata,attributePrefix,attributeName); if(propertyType != null){ return propertyType; } } } return getPropertyType(propertyName); }
/** * Gets the property type for a property name in a relationship. * * @param objectMetadata the Metadata object. * @param attributePrefix the prefix of the property that indicated it was in a relationship. * @param attributeName the name of the property. * @return the property type for a property name. */ private Class<?> traverseRelationship(DataObjectMetadata objectMetadata,String attributePrefix,String attributeName){ DataObjectRelationship rd = objectMetadata.getRelationship(attributePrefix); if(rd != null){ DataObjectMetadata relatedobjectMetadata = dataObjectService.getMetadataRepository().getMetadata(rd.getRelatedType()); if(relatedobjectMetadata != null){ if(PropertyAccessorUtils.isnestedOrIndexedProperty(attributeName)){ return getPropertyTypeChild(relatedobjectMetadata,attributeName); } else{ if(relatedobjectMetadata.getAttribute(attributeName) == null && relatedobjectMetadata.getRelationship(attributeName)!=null){ DataObjectRelationship relationship = relatedobjectMetadata.getRelationship(attributeName); return relationship.getRelatedType(); } return relatedobjectMetadata.getAttribute(attributeName).getDataType().getType(); } } } return null; }
/** * Gets indexes that have been modified. * * <p> * Returns a set of indexes which have been modified in the given collection. If the returned set contains * {@link java.lang.Integer#MAX_VALUE} then it means that it should be treated as if all items in the collection * have been modified. * </p> * * @return indexes which have been modified in the given collection */ private Set<Integer> extractModifiedindicies(DataObjectCollection collectionMetadata,Map<String,Set<String>> decomposedpaths) { String relationshipName = collectionMetadata.getName(); Set<Integer> modifiedindicies = Sets.newHashSet(); // if it contains *exactly* the collection relationship name,then indicate that all items modified if (decomposedpaths.containsKey(relationshipName)) { modifiedindicies.add(Integer.valueOf(Integer.MAX_VALUE)); } for (String propertyName : decomposedpaths.keySet()) { if (relationshipName.equals(PropertyAccessorUtils.getPropertyName(relationshipName))) { Integer index = extractIndex(propertyName); if (index != null) { modifiedindicies.add(index); } } } return modifiedindicies; }
@Override public Map<String,String>(); Class<?> objectClass = ObjectUtils.materializeClassForProxiedobject(dataObject); org.kuali.rice.krad.bo.DataObjectRelationship relationship = dataObjectMetaDataService.getDataObjectRelationship(dataObject,objectClass,propertyName,"",true,false,true); for (String keyName : keys) { String keyConversion = keyName; if (relationship != null) { keyConversion = relationship.getParentAttributeForChildAttribute(keyName); } else if (PropertyAccessorUtils.isnestedOrIndexedProperty(propertyName)) { String nestedAttributePrefix = KRADUtils.getnestedAttributePrefix(propertyName); keyConversion = nestedAttributePrefix + "." + keyName; } inquiryParameters.put(keyConversion,keyName); } return inquiryParameters; }
private boolean isPersonProperty(Object bo,String propertyName) { try { if (PropertyAccessorUtils.isnestedOrIndexedProperty( propertyName ) // is a nested property && !StringUtils.contains(propertyName,"add.") ) {// exclude add line properties (due to path parsing problems in PropertyUtils.getPropertyType) int lastIndex = PropertyAccessorUtils.getLastnestedPropertySeparatorIndex(propertyName); String propertyTypeName = lastIndex != -1 ? StringUtils.substring(propertyName,lastIndex) : StringUtils.EMPTY; Class<?> type = PropertyUtils.getPropertyType(bo,propertyTypeName); // property type indicates a Person object if ( type != null ) { return Person.class.isAssignableFrom(type); } LOG.warn( "Unable to determine type of nested property: " + bo.getClass().getName() + " / " + propertyName ); } } catch (Exception ex) { if ( LOG.isDebugEnabled() ) { LOG.debug("Unable to determine if property on " + bo.getClass().getName() + " to a person object: " + propertyName,ex ); } } return false; }
/** * Overridden to copy property editor registration to the new bean wrapper. * * <p>This is necessary because spring only copies over the editors when a new bean wrapper is * created. The wrapper is then cached and use for subsequent calls. But the get calls Could bring in * new custom editors we need to copy.</p> * * {@inheritDoc} */ @Override protected BeanWrapperImpl getBeanWrapperForPropertyPath(String propertyPath) { BeanWrapperImpl beanWrapper = super.getBeanWrapperForPropertyPath(propertyPath); PropertyTokenHolder tokens = getPropertyNametokens(propertyPath); String canonicalName = tokens.canonicalName; int pos = PropertyAccessorUtils.getFirstnestedPropertySeparatorIndex(canonicalName); if (pos != -1) { canonicalName = canonicalName.substring(0,canonicalName); return beanWrapper; }
/** * Set the parent for bi-directional relationships when adding a line to a collection. * * @param model the view data * @param collectionPath the path to the collection being linked * @param addedindex the index of the added line * @return whether the linked line needs further processing */ protected boolean linkAddedLine(Object model,and if it is we want to set the collection as // the dialog's parent and do not want further processing of the dialog object if (collectionParentPath.equalsIgnoreCase(UifPropertyPaths.DIALOG_DATA_OBJECT)) { ((UifFormBase) model).setDialogDataObject(parent); return false; } } return true; }
@Override public Map<String,keyName); } return inquiryParameters; }
/** * Gets the property type for a property name. * * @param objectMetadata the Metadata object. * @param propertyName the name of the property. * @return the property type for a property name. */ private Class<?> getPropertyTypeChild(DataObjectMetadata objectMetadata,attributeName); if(propertyType != null){ return propertyType; } } } return getPropertyType(propertyName); }
/** * Gets the property type for a property name in a relationship. * * @param objectMetadata the Metadata object. * @param attributePrefix the prefix of the property that indicated it was in a relationship. * @param attributeName the name of the property. * @return the property type for a property name. */ private Class<?> traverseRelationship(DataObjectMetadata objectMetadata,attributeName); } else{ if(relatedobjectMetadata.getAttribute(attributeName) == null && relatedobjectMetadata.getRelationship(attributeName)!=null){ DataObjectRelationship relationship = relatedobjectMetadata.getRelationship(attributeName); return relationship.getRelatedType(); } return relatedobjectMetadata.getAttribute(attributeName).getDataType().getType(); } } } return null; }
/** * Gets indexes that have been modified. * * <p> * Returns a set of indexes which have been modified in the given collection. If the returned set contains * {@link java.lang.Integer#MAX_VALUE} then it means that it should be treated as if all items in the collection * have been modified. * </p> * * @return indexes which have been modified in the given collection */ private Set<Integer> extractModifiedindicies(DataObjectCollection collectionMetadata,then indicate that all items modified if (decomposedpaths.containsKey(relationshipName)) { modifiedindicies.add(Integer.valueOf(Integer.MAX_VALUE)); } for (String propertyName : decomposedpaths.keySet()) { if (relationshipName.equals(PropertyAccessorUtils.getPropertyName(relationshipName))) { Integer index = extractIndex(propertyName); if (index != null) { modifiedindicies.add(index); } } } return modifiedindicies; }
@Override public Map<String,keyName); } return inquiryParameters; }
private boolean isPersonProperty(Object bo,ex ); } } return false; }
@Override protected BeanWrapperImpl getBeanWrapperForPropertyPath(String propertyPath) { BeanWrapperImpl beanWrapper = super.getBeanWrapperForPropertyPath(propertyPath); PropertyTokenHolder tokens = getPropertyNametokens(propertyPath); String canonicalName = tokens.canonicalName; int pos = PropertyAccessorUtils.getFirstnestedPropertySeparatorIndex(canonicalName); if (pos != -1) { canonicalName = canonicalName.substring(0,canonicalName); return beanWrapper; }
/** * Check the given property values against the allowed fields,* removing values for fields that are not allowed. * @param mpvs the property values to be bound (can be modified) * @see #getAllowedFields * @see #isAllowed(String) */ protected void checkAllowedFields(MutablePropertyValues mpvs) { PropertyValue[] pvs = mpvs.getPropertyValues(); for (PropertyValue pv : pvs) { String field = PropertyAccessorUtils.canonicalPropertyName(pv.getName()); if (!isAllowed(field)) { mpvs.removePropertyValue(pv); getBindingResult().recordSuppressedField(field); if (logger.isDebugEnabled()) { logger.debug("Field [" + field + "] has been removed from PropertyValues " + "and will not be bound,because it has not been found in the list of allowed fields"); } } } }
/** * Check the given property values against the allowed fields,because it has not been found in the list of allowed fields"); } } } }
/** * Check the given property values against the allowed fields,because it has not been found in the list of allowed fields"); } } } }
/** * Check the given property values against the allowed fields,because it has not been found in the list of allowed fields"); } } } }
/** * {@inheritDoc} */ @Override public void refreshReferences(String referencesToRefresh) { Object model = ViewLifecycle.getModel(); for (String reference : StringUtils.split(referencesToRefresh,KRADConstants.REFERENCES_TO_REFRESH_SEParaTOR)) { if (StringUtils.isBlank(reference)) { continue; } //Todo: handle add line if (PropertyAccessorUtils.isnestedOrIndexedProperty(reference)) { String parentPath = KRADUtils.getnestedAttributePrefix(reference); Object parentObject = ObjectPropertyUtils.getPropertyValue(model,parentPath); String referenceObjectName = KRADUtils.getnestedAttributePrimitive(reference); if (parentObject == null) { LOG.warn("Unable to refresh references for " + referencesToRefresh + ". Object not found in model. nothing refreshed."); continue; } refreshReference(parentObject,referenceObjectName); } else { refreshReference(model,reference); } } }
/** * @see org.kuali.rice.krad.service.DictionaryValidationService#validateReferenceExistsAndisActive(java.lang.Object * dataObject,* String,String,String) */ @Override public boolean validateReferenceExistsAndisActive(Object dataObject,String referenceName,String attributetoHighlightOnFail,String displayFieldName) { // if we're dealing with a nested attribute,we need to resolve down to the BO where the primitive attribute is located // this is primarily to deal with the case of a defaultExistenceCheck that uses an "extension",i.e referenceName // would be extension.attributeName if (PropertyAccessorUtils.isnestedOrIndexedProperty(referenceName)) { String nestedAttributePrefix = KRADUtils.getnestedAttributePrefix(referenceName); String nestedAttributePrimitive = KRADUtils.getnestedAttributePrimitive(referenceName); Object nestedobject = KradDataServiceLocator.getDataObjectService().wrap(dataObject) .getPropertyValueNullSafe(nestedAttributePrefix); return validateReferenceExistsAndisActive(nestedobject,nestedAttributePrimitive,attributetoHighlightOnFail,displayFieldName); } boolean hasReferences = validateFkFieldsPopulated(dataObject,referenceName); boolean referenceExists = hasReferences && validateReferenceExists(dataObject,referenceName); boolean canIncludeActiveReference = referenceExists && (!(dataObject instanceof Inactivatable) || ((Inactivatable) dataObject).isActive()); boolean referenceActive = canIncludeActiveReference && validateReferenceIsActive(dataObject,referenceName); if(hasReferences && !referenceExists) { GlobalVariables.getMessageMap().putError(attributetoHighlightOnFail,RiceKeyConstants.ERROR_EXISTENCE,displayFieldName); return false; } else if(canIncludeActiveReference && !referenceActive) { GlobalVariables.getMessageMap().putError(attributetoHighlightOnFail,RiceKeyConstants.ERROR_INACTIVE,displayFieldName); return false; } return true; }
@Override /** * Recursively calls getPropertyTypeChild if nested property to allow it to properly look it up */ public Class<?> getPropertyType(Object object,String propertyName) { DataObjectWrapper<?> wrappedobject = dataObjectService.wrap(object); if (PropertyAccessorUtils.isnestedOrIndexedProperty(propertyName)) { return wrappedobject.getPropertyTypeNullSafe(wrappedobject.getWrappedClass(),propertyName); } return wrappedobject.getPropertyType(propertyName); }
/** * Recursively navigate to return a BeanWrapper for the nested property path. * * @param propertyPath * property property path,which may be nested * @return a BeanWrapper for the target bean */ PropertyDescriptor getPropertyDescriptorForPropertyPath(String propertyPath,Class<?> propertyType) { int pos = PropertyAccessorUtils.getFirstnestedPropertySeparatorIndex(propertyPath); // Handle nested properties recursively. if (pos > -1) { String nestedProperty = propertyPath.substring(0,pos); String nestedpath = propertyPath.substring(pos + 1); PropertyDescriptor propertyDescriptor = BeanUtils.getPropertyDescriptor(propertyType,nestedProperty); // BeanWrapperImpl nestedBw = getnestedBeanWrapper(nestedProperty); return getPropertyDescriptorForPropertyPath(nestedpath,propertyDescriptor.getPropertyType()); } else { return BeanUtils.getPropertyDescriptor(propertyType,propertyPath); } }
/** * Check the given property values against the allowed fields,because it has not been found in the list of allowed fields"); } } } }
/** * Actually set the nested path. * Delegated to by setnestedpath and pushnestedpath. * <p/> * Note: Not yet kNown what to use the path for. Possibly if the Asset has * second class Asset contained inside it. * * @param nestedpath Path */ protected void doSetnestedpath(String nestedpath) { if (nestedpath == null) { nestedpath = ""; } nestedpath = PropertyAccessorUtils.canonicalPropertyName(nestedpath); if (nestedpath.length() > 0 && !nestedpath.endsWith(nesTED_PATH_SEParaTOR)) { nestedpath += nesTED_PATH_SEParaTOR; } this.nestedpath = nestedpath; }
/** * Transform the given field into its full path,* regarding the nested path of this instance. * * @param field a {@link java.lang.String} object. * @return {@link java.lang.String} object. */ protected String fixedField(String field) { if (StringUtils.hasLength(field)) { return getnestedpath() + PropertyAccessorUtils.canonicalPropertyName(field); } else { String path = getnestedpath(); return (path.endsWith(org.springframework.validation.Errors.nesTED_PATH_SEParaTOR) ? path.substring(0,path.length() - nesTED_PATH_SEParaTOR.length()) : path); } }
/** * {@inheritDoc} */ @Override public void refreshReferences(String referencesToRefresh) { Object model = ViewLifecycle.getModel(); for (String reference : StringUtils.split(referencesToRefresh,reference); } } }
/** * @see org.kuali.rice.krad.service.DictionaryValidationService#validateReferenceExistsAndisActive(java.lang.Object * dataObject,displayFieldName); return false; } return true; }
@Override /** * Recursively calls getPropertyTypeChild if nested property to allow it to properly look it up */ public Class<?> getPropertyType(Object object,propertyName); } return wrappedobject.getPropertyType(propertyName); }
/** * <p>Constructor for PropertyPath.</p> * * @param nestedpath a {@link java.lang.String} object. */ public PropertyPath(String nestedpath) { String canonicalPath = PropertyAccessorUtils.canonicalPropertyName(nestedpath); int lastIndex = PropertyAccessorUtils.getLastnestedPropertySeparatorIndex(canonicalPath); if (lastIndex < 0) { propertyName = PropertyAccessorUtils.getPropertyName(canonicalPath); key = computeKey(canonicalPath); } else { parent = new PropertyPath(canonicalPath.substring(0,lastIndex)); String lastProperty = canonicalPath.substring(lastIndex+1); propertyName = PropertyAccessorUtils.getPropertyName(lastProperty); key = computeKey(lastProperty); } }
/** * <p>Constructor for PropertyPath.</p> * * @param nestedpath a {@link java.lang.String} object. */ public PropertyPath(String nestedpath) { String canonicalPath = PropertyAccessorUtils.canonicalPropertyName(nestedpath); int lastIndex = PropertyAccessorUtils.getLastnestedPropertySeparatorIndex(canonicalPath); if (lastIndex < 0) { propertyName = PropertyAccessorUtils.getPropertyName(canonicalPath); key = computeKey(canonicalPath); } else { parent = new PropertyPath(canonicalPath.substring(0,lastIndex)); String lastProperty = canonicalPath.substring(lastIndex+1); propertyName = PropertyAccessorUtils.getPropertyName(lastProperty); key = computeKey(lastProperty); } }
/** * Returns the canonical property name. * @see org.springframework.beans.PropertyAccessorUtils#canonicalPropertyName */ @Override protected String canonicalFieldName(String field) { return PropertyAccessorUtils.canonicalPropertyName(field); }
/** * Returns the canonical property name. * @see org.springframework.beans.PropertyAccessorUtils#canonicalPropertyName */ @Override protected String canonicalFieldName(String field) { return PropertyAccessorUtils.canonicalPropertyName(field); }
/** * Returns the canonical property name. * @see org.springframework.beans.PropertyAccessorUtils#canonicalPropertyName */ @Override protected String canonicalFieldName(String field) { return PropertyAccessorUtils.canonicalPropertyName(field); }
/** * Returns the canonical property name. * @see org.springframework.beans.PropertyAccessorUtils#canonicalPropertyName */ @Override protected String canonicalFieldName(String field) { return PropertyAccessorUtils.canonicalPropertyName(field); }
/** * Returns the canonical property name. * @see org.springframework.beans.PropertyAccessorUtils#canonicalPropertyName */ @Override protected String canonicalFieldName(String field) { return PropertyAccessorUtils.canonicalPropertyName(field); }
/** * Register fields that are required for each binding process. * <p>If one of the specified fields is not contained in the list of * incoming property values,a corresponding "missing field" error * will be created,with error code "required" (by the default * binding error processor). * @param requiredFields array of field names * @see #setBindingErrorProcessor * @see DefaultBindingErrorProcessor#MISSING_FIELD_ERROR_CODE */ public void setrequiredFields(String... requiredFields) { this.requiredFields = PropertyAccessorUtils.canonicalPropertyNames(requiredFields); if (logger.isDebugEnabled()) { logger.debug("DataBinder requires binding of required fields [" + StringUtils.arrayToCommaDelimitedString(requiredFields) + "]"); } }
/** * Register fields that are required for each binding process. * <p>If one of the specified fields is not contained in the list of * incoming property values,with error code "required" (by the default * binding error processor). * @param requiredFields array of field names * @see #setBindingErrorProcessor * @see DefaultBindingErrorProcessor#MISSING_FIELD_ERROR_CODE */ public void setrequiredFields(String... requiredFields) { this.requiredFields = PropertyAccessorUtils.canonicalPropertyNames(requiredFields); if (logger.isDebugEnabled()) { logger.debug("DataBinder requires binding of required fields [" + StringUtils.arrayToCommaDelimitedString(requiredFields) + "]"); } }
org.springframework.boot.cli.compiler.AstUtils的实例源码
@Override public void apply(GroovyClassLoader loader,GroovyCompilerConfiguration configuration,GeneratorContext generatorContext,SourceUnit source,ClassNode classNode) throws CompilationFailedException { if (!AstUtils.hasAtLeastOneAnnotation(classNode,"RunWith")) { AnnotationNode runWith = new AnnotationNode(ClassHelper.make("RunWith")); runWith.addMember("value",new ClassExpression(ClassHelper.make("springrunner"))); classNode.addAnnotation(runWith); } }
@Override public void apply(GroovyClassLoader loader,new ClassExpression(ClassHelper.make("springrunner"))); classNode.addAnnotation(runWith); } }
@Override public void apply(GroovyClassLoader loader,"RunWith")) { AnnotationNode runwith = new AnnotationNode(ClassHelper.make("RunWith")); runwith.addMember("value",new ClassExpression(ClassHelper.make("SpringJUnit4ClassRunner"))); classNode.addAnnotation(runwith); } }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"Test"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableWebSecurity","EnableGlobalMethodSecurity"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableBatchProcessing"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableRabbit") || AstUtils.hasAtLeastOneAnnotation(classNode,"EnableRabbitMessaging"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableIntegration") || AstUtils.hasAtLeastOneAnnotation(classNode,"MessageEndpoint"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneFieldOrMethod(classNode,"Twitter"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableGroovyTemplates"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"Controller","RestController","EnableWebMvc"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.subclasses(classNode,"Specification"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneFieldOrMethod(classNode,"Facebook"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableJms") || AstUtils.hasAtLeastOneAnnotation(classNode,"EnableJmsMessaging"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableRetry","Retryable","Recover"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableTransactionManagement"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneFieldOrMethod(classNode,"LinkedIn"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableAuthorizationServer","EnableResourceServer","Enableoauth2client","EnableOAuth2Sso"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneFieldOrMethod(classNode,"JdbcTemplate","NamedParameterJdbcTemplate","DataSource"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableReactor") || AstUtils.hasAtLeastOneFieldOrMethod(classNode,"EventBus"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableCaching"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"SpringApplicationConfiguration"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableDeviceResolver"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableWebSocket","EnableWebSocketMessagebroker"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"Test"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableGlobalMethodSecurity"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableBatchProcessing"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableRabbitMessaging"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"MessageEndpoint"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneFieldOrMethod(classNode,"Twitter"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableGroovyTemplates"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableWebMvc"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.subclasses(classNode,"Specification"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneFieldOrMethod(classNode,"Facebook"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableJmsMessaging"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"Recover"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableTransactionManagement"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneFieldOrMethod(classNode,"LinkedIn"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneAnnotation(classNode,"EnableOAuth2Sso"); }
@Override public boolean matches(ClassNode classNode) { return AstUtils.hasAtLeastOneFieldOrMethod(classNode,"DataSource"); }
org.springframework.boot.cli.util.Log的实例源码
public void generateProject(ProjectGenerationRequest request,boolean force) throws IOException { ProjectGenerationResponse response = this.initializrService.generate(request); String fileName = (request.getoutput() != null ? request.getoutput() : response.getFileName()); if (shouldExtract(request,response)) { if (isZipArchive(response)) { extractProject(response,request.getoutput(),force); return; } else { Log.info("Could not extract '" + response.getContentType() + "'"); // Use value from the server since we can't extract it fileName = response.getFileName(); } } if (fileName == null) { throw new ReportableException( "Could not save the project,the server did not set a preferred " + "file name and no location was set. Specify the output location " + "for the project."); } writeProject(response,fileName,force); }
private void extractProject(ProjectGenerationResponse entity,String output,boolean overwrite) throws IOException { File outputFolder = (output != null ? new File(output) : new File(System.getProperty("user.dir"))); if (!outputFolder.exists()) { outputFolder.mkdirs(); } ZipInputStream zipStream = new ZipInputStream( new ByteArrayInputStream(entity.getContent())); try { extractFromStream(zipStream,overwrite,outputFolder); fixExecutableFlag(outputFolder,"mvnw"); fixExecutableFlag(outputFolder,"gradlew"); Log.info("Project extracted to '" + outputFolder.getAbsolutePath() + "'"); } finally { zipStream.close(); } }
private void writeProject(ProjectGenerationResponse entity,boolean overwrite) throws IOException { File outputFile = new File(output); if (outputFile.exists()) { if (!overwrite) { throw new ReportableException("File '" + outputFile.getName() + "' already exists. Use --force if you want to " + "overwrite or specify an alternate location."); } if (!outputFile.delete()) { throw new ReportableException( "Failed to delete existing file " + outputFile.getPath()); } } FilecopyUtils.copy(entity.getContent(),outputFile); Log.info("Content saved to '" + output + "'"); }
@Override @SuppressWarnings("unchecked") protected ExitStatus run(OptionSet options) throws Exception { List<String> args = (List<String>) options.nonoptionArguments(); try { if (options.has(this.allOption)) { if (!args.isEmpty()) { throw new IllegalArgumentException( "Please use --all without specifying any dependencies"); } new Installer(options,this).uninstallAll(); } if (args.isEmpty()) { throw new IllegalArgumentException( "Please specify at least one dependency,in the form group:artifact:version,to uninstall"); } new Installer(options,this).uninstall(args); } catch (Exception ex) { String message = ex.getMessage(); Log.error(message != null ? message : ex.getClass().toString()); } return ExitStatus.OK; }
public void generateProject(ProjectGenerationRequest request,force); }
private void extractProject(ProjectGenerationResponse entity,"gradlew"); Log.info("Project extracted to '" + outputFolder.getAbsolutePath() + "'"); } finally { zipStream.close(); } }
private void writeProject(ProjectGenerationResponse entity,outputFile); Log.info("Content saved to '" + output + "'"); }
@Override @SuppressWarnings("unchecked") protected ExitStatus run(OptionSet options) throws Exception { List<String> args = (List<String>) options.nonoptionArguments(); try { if (options.has(this.allOption)) { if (!args.isEmpty()) { throw new IllegalArgumentException( "Please use --all without specifying any dependencies"); } new Installer(options,this).uninstall(args); } catch (Exception ex) { String message = ex.getMessage(); Log.error(message != null ? message : ex.getClass().toString()); } return ExitStatus.OK; }
public void generateProject(ProjectGenerationRequest request,force); }
private void extractProject(ProjectGenerationResponse entity,outputFolder); Log.info("Project extracted to '" + outputFolder.getAbsolutePath() + "'"); } finally { zipStream.close(); } }
private void writeProject(ProjectGenerationResponse entity,outputFile); Log.info("Content saved to '" + output + "'"); }
@Override @SuppressWarnings("unchecked") protected ExitStatus run(OptionSet options) throws Exception { List<String> args = (List<String>) options.nonoptionArguments(); try { if (options.has(this.allOption)) { if (!args.isEmpty()) { throw new IllegalArgumentException( "Please use --all without specifying any dependencies"); } new Installer(options,this).uninstall(args); } catch (Exception ex) { String message = ex.getMessage(); Log.error(message != null ? message : ex.getClass().toString()); } return ExitStatus.OK; }
/** * Generate a project based on the specified {@link ProjectGenerationRequest}. * @param request the generation request * @return an entity defining the project * @throws IOException if generation fails */ public ProjectGenerationResponse generate(ProjectGenerationRequest request) throws IOException { Log.info("Using service at " + request.getServiceUrl()); InitializrServiceMetadata Metadata = loadMetadata(request.getServiceUrl()); URI url = request.generateUrl(Metadata); CloseableHttpResponse httpResponse = executeProjectGenerationRequest(url); httpentity httpentity = httpResponse.getEntity(); validateResponse(httpResponse,request.getServiceUrl()); return createResponse(httpResponse,httpentity); }
@Override @SuppressWarnings("unchecked") protected ExitStatus run(OptionSet options) throws Exception { List<String> args = (List<String>) options.nonoptionArguments(); Assert.notEmpty(args,"Please specify at least one " + "dependency,to install"); try { new Installer(options,this).install(args); } catch (Exception ex) { String message = ex.getMessage(); Log.error(message != null ? message : ex.getClass().toString()); } return ExitStatus.OK; }
public void install(List<String> artifactIdentifiers) throws Exception { File libDirectory = getDefaultLibDirectory(); libDirectory.mkdirs(); Log.info("Installing into: " + libDirectory); List<File> artifactFiles = this.dependencyResolver.resolve(artifactIdentifiers); for (File artifactFile : artifactFiles) { int installCount = getInstallCount(artifactFile); if (installCount == 0) { FilecopyUtils.copy(artifactFile,new File(libDirectory,artifactFile.getName())); } setInstallCount(artifactFile,installCount + 1); } saveInstallCounts(); }
public void uninstall(List<String> artifactIdentifiers) throws Exception { File libDirectory = getDefaultLibDirectory(); Log.info("Uninstalling from: " + libDirectory); List<File> artifactFiles = this.dependencyResolver.resolve(artifactIdentifiers); for (File artifactFile : artifactFiles) { int installCount = getInstallCount(artifactFile); if (installCount <= 1) { new File(libDirectory,artifactFile.getName()).delete(); } setInstallCount(artifactFile,installCount - 1); } saveInstallCounts(); }
public void uninstallAll() throws Exception { File libDirectory = getDefaultLibDirectory(); Log.info("Uninstalling from: " + libDirectory); for (String name : this.installCounts.stringPropertyNames()) { new File(libDirectory,name).delete(); } this.installCounts.clear(); saveInstallCounts(); }
private void showCommandHints(String starting) { for (Command command : this.commandRunner) { if (isHintMatch(command,starting)) { Log.info(command.getName() + " " + command.getDescription()); } } }
private void showCommandOptionHints(String commandName,List<String> specifiedArguments,String starting) { Command command = this.commandRunner.findCommand(commandName); if (command != null) { for (OptionHelp help : command.getoptionsHelp()) { if (!alreadyUsed(help,specifiedArguments)) { for (String option : help.getoptions()) { if (option.startsWith(starting)) { Log.info(option + " " + help.getUsageHelp()); } } } } } }
@Override public ExitStatus run(String... args) throws Exception { if (args.length == 0) { throw new NoHelpCommandArgumentsException(); } String commandName = args[0]; for (Command command : this.commandRunner) { if (command.getName().equals(commandName)) { Log.info(this.commandRunner.getName() + command.getName() + " - " + command.getDescription()); Log.info(""); if (command.getUsageHelp() != null) { Log.info("usage: " + this.commandRunner.getName() + command.getName() + " " + command.getUsageHelp()); Log.info(""); } if (command.getHelp() != null) { Log.info(command.getHelp()); } Collection<HelpExample> examples = command.getExamples(); if (examples != null) { Log.info(examples.size() == 1 ? "example:" : "examples:"); Log.info(""); for (HelpExample example : examples) { Log.info(" " + example.getDescription() + ":"); Log.info(" $ " + example.getExample()); Log.info(""); } Log.info(""); } return ExitStatus.OK; } } throw new NoSuchCommandException(commandName); }
public MavenSettings readSettings() { Settings settings = loadSettings(); SettingsDecryptionResult decrypted = decryptSettings(settings); if (!decrypted.getProblems().isEmpty()) { Log.error( "Maven settings decryption Failed. Some Maven repositories may be inaccessible"); // Continue - the encrypted credentials may not be used } return new MavenSettings(settings,decrypted); }
/** * Generate a project based on the specified {@link ProjectGenerationRequest}. * @param request the generation request * @return an entity defining the project * @throws IOException if generation fails */ public ProjectGenerationResponse generate(ProjectGenerationRequest request) throws IOException { Log.info("Using service at " + request.getServiceUrl()); InitializrServiceMetadata Metadata = loadMetadata(request.getServiceUrl()); URI url = request.generateUrl(Metadata); CloseableHttpResponse httpResponse = executeProjectGenerationRequest(url); httpentity httpentity = httpResponse.getEntity(); validateResponse(httpResponse,httpentity); }
@Override @SuppressWarnings("unchecked") protected ExitStatus run(OptionSet options) throws Exception { List<String> args = (List<String>) options.nonoptionArguments(); Assert.notEmpty(args,this).install(args); } catch (Exception ex) { String message = ex.getMessage(); Log.error(message != null ? message : ex.getClass().toString()); } return ExitStatus.OK; }
public void install(List<String> artifactIdentifiers) throws Exception { File libDirectory = getDefaultLibDirectory(); libDirectory.mkdirs(); Log.info("Installing into: " + libDirectory); List<File> artifactFiles = this.dependencyResolver.resolve(artifactIdentifiers); for (File artifactFile : artifactFiles) { int installCount = getInstallCount(artifactFile); if (installCount == 0) { FilecopyUtils.copy(artifactFile,installCount + 1); } saveInstallCounts(); }
public void uninstall(List<String> artifactIdentifiers) throws Exception { File libDirectory = getDefaultLibDirectory(); Log.info("Uninstalling from: " + libDirectory); List<File> artifactFiles = this.dependencyResolver.resolve(artifactIdentifiers); for (File artifactFile : artifactFiles) { int installCount = getInstallCount(artifactFile); if (installCount <= 1) { new File(libDirectory,installCount - 1); } saveInstallCounts(); }
public void uninstallAll() throws Exception { File libDirectory = getDefaultLibDirectory(); Log.info("Uninstalling from: " + libDirectory); for (String name : this.installCounts.stringPropertyNames()) { new File(libDirectory,name).delete(); } this.installCounts.clear(); saveInstallCounts(); }
private void showCommandHints(String starting) { for (Command command : this.commandRunner) { if (isHintMatch(command,starting)) { Log.info(command.getName() + " " + command.getDescription()); } } }
private void showCommandOptionHints(String commandName,specifiedArguments)) { for (String option : help.getoptions()) { if (option.startsWith(starting)) { Log.info(option + " " + help.getUsageHelp()); } } } } } }
@Override public ExitStatus run(String... args) throws Exception { if (args.length == 0) { throw new NoHelpCommandArgumentsException(); } String commandName = args[0]; for (Command command : this.commandRunner) { if (command.getName().equals(commandName)) { Log.info(this.commandRunner.getName() + command.getName() + " - " + command.getDescription()); Log.info(""); if (command.getUsageHelp() != null) { Log.info("usage: " + this.commandRunner.getName() + command.getName() + " " + command.getUsageHelp()); Log.info(""); } if (command.getHelp() != null) { Log.info(command.getHelp()); } Collection<HelpExample> examples = command.getExamples(); if (examples != null) { Log.info(examples.size() == 1 ? "example:" : "examples:"); Log.info(""); for (HelpExample example : examples) { Log.info(" " + example.getDescription() + ":"); Log.info(" $ " + example.getExample()); Log.info(""); } Log.info(""); } return ExitStatus.OK; } } throw new NoSuchCommandException(commandName); }
public MavenSettings readSettings() { Settings settings = loadSettings(); SettingsDecryptionResult decrypted = decryptSettings(settings); if (!decrypted.getProblems().isEmpty()) { Log.error( "Maven settings decryption Failed. Some Maven repositories may be inaccessible"); // Continue - the encrypted credentials may not be used } return new MavenSettings(settings,decrypted); }
/** * Generate a project based on the specified {@link ProjectGenerationRequest}. * @param request the generation request * @return an entity defining the project * @throws IOException if generation fails */ public ProjectGenerationResponse generate(ProjectGenerationRequest request) throws IOException { Log.info("Using service at " + request.getServiceUrl()); InitializrServiceMetadata Metadata = loadMetadata(request.getServiceUrl()); URI url = request.generateUrl(Metadata); CloseableHttpResponse httpResponse = executeProjectGenerationRequest(url); httpentity httpentity = httpResponse.getEntity(); validateResponse(httpResponse,httpentity); }
@Override @SuppressWarnings("unchecked") protected ExitStatus run(OptionSet options) throws Exception { List<String> args = (List<String>) options.nonoptionArguments(); Assert.notEmpty(args,this).install(args); } catch (Exception ex) { String message = ex.getMessage(); Log.error(message != null ? message : ex.getClass().toString()); } return ExitStatus.OK; }
public void install(List<String> artifactIdentifiers) throws Exception { File libDirectory = getDefaultLibDirectory(); libDirectory.mkdirs(); Log.info("Installing into: " + libDirectory); List<File> artifactFiles = this.dependencyResolver.resolve(artifactIdentifiers); for (File artifactFile : artifactFiles) { int installCount = getInstallCount(artifactFile); if (installCount == 0) { FilecopyUtils.copy(artifactFile,installCount + 1); } saveInstallCounts(); }
public void uninstall(List<String> artifactIdentifiers) throws Exception { File libDirectory = getDefaultLibDirectory(); Log.info("Uninstalling from: " + libDirectory); List<File> artifactFiles = this.dependencyResolver.resolve(artifactIdentifiers); for (File artifactFile : artifactFiles) { int installCount = getInstallCount(artifactFile); if (installCount <= 1) { new File(libDirectory,installCount - 1); } saveInstallCounts(); }
public void uninstallAll() throws Exception { File libDirectory = getDefaultLibDirectory(); Log.info("Uninstalling from: " + libDirectory); for (String name : this.installCounts.stringPropertyNames()) { new File(libDirectory,name).delete(); } this.installCounts.clear(); saveInstallCounts(); }
private void showCommandHints(String starting) { for (Command command : this.commandRunner) { if (isHintMatch(command,starting)) { Log.info(command.getName() + " " + command.getDescription()); } } }
private void showCommandOptionHints(String commandName,specifiedArguments)) { for (String option : help.getoptions()) { if (option.startsWith(starting)) { Log.info(option + " " + help.getUsageHelp()); } } } } } }
@Override public ExitStatus run(String... args) throws Exception { if (args.length == 0) { throw new NoHelpCommandArgumentsException(); } String commandName = args[0]; for (Command command : this.commandRunner) { if (command.getName().equals(commandName)) { Log.info(this.commandRunner.getName() + command.getName() + " - " + command.getDescription()); Log.info(""); if (command.getUsageHelp() != null) { Log.info("usage: " + this.commandRunner.getName() + command.getName() + " " + command.getUsageHelp()); Log.info(""); } if (command.getHelp() != null) { Log.info(command.getHelp()); } Collection<HelpExample> examples = command.getExamples(); if (examples != null) { Log.info(examples.size() == 1 ? "example:" : "examples:"); Log.info(""); for (HelpExample example : examples) { Log.info(" " + example.getDescription() + ":"); Log.info(" $ " + example.getExample()); Log.info(""); } Log.info(""); } return ExitStatus.OK; } } throw new NoSuchCommandException(commandName); }
public MavenSettings readSettings() { Settings settings = loadSettings(); SettingsDecryptionResult decrypted = decryptSettings(settings); if (!decrypted.getProblems().isEmpty()) { Log.error( "Maven settings decryption Failed. Some Maven repositories may be inaccessible"); // Continue - the encrypted credentials may not be used } return new MavenSettings(settings,decrypted); }
public MavenSettings readSettings() { Settings settings = loadSettings(); SettingsDecryptionResult decrypted = decryptSettings(settings); if (!decrypted.getProblems().isEmpty()) { Log.error( "Maven settings decryption Failed. Some Maven repositories may be inaccessible"); // Continue - the encrypted credentials may not be used } if(Boolean.getBoolean("mavenSettings.offline")) { settings.setoffline(true); } return new MavenSettings(settings,decrypted); }
关于org.springframework.util.Assert源码和spring autowired源码的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Java-Class-C:org.springframework.util.Assert、org.springframework.beans.PropertyAccessorUtils的实例源码、org.springframework.boot.cli.compiler.AstUtils的实例源码、org.springframework.boot.cli.util.Log的实例源码等相关内容,可以在本站寻找。
本文标签: