public class InternalUtils extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static Mapper<java.lang.Class,AnnotationProvider> |
CLASS_TO_AP_MAPPER |
static Mapper<ObjectCreator,java.lang.Object> |
CREATE_OBJECT |
static Mapper<java.lang.reflect.Method,AnnotationProvider> |
METHOD_TO_AP_MAPPER |
static boolean |
SERVICE_CLASS_RELOADING_ENABLED |
Constructor and Description |
---|
InternalUtils() |
Modifier and Type | Method and Description |
---|---|
static <K,V> void |
addToMapList(java.util.Map<K,java.util.List<V>> map,
K key,
V value)
Adds a value to a specially organized map where the values are lists of objects.
|
static java.lang.String |
asString(java.lang.reflect.Method method)
Converts a method to a user presentable string consisting of the containing class name, the method name, and the
short form of the parameter list (the class name of each parameter type, shorn of the package name portion).
|
static java.lang.String |
asString(java.lang.reflect.Method method,
PlasticProxyFactory proxyFactory)
Converts a method to a user presentable string using a
PlasticProxyFactory to obtain a Location
(where possible). |
static ObjectCreator[] |
calculateParameters(ObjectLocator locator,
InjectionResources resources,
java.lang.Class[] parameterTypes,
java.lang.reflect.Type[] genericTypes,
java.lang.annotation.Annotation[][] parameterAnnotations,
OperationTracker tracker) |
static ObjectCreator[] |
calculateParametersForMethod(java.lang.reflect.Method method,
ObjectLocator locator,
InjectionResources resources,
OperationTracker tracker) |
static java.lang.String |
capitalize(java.lang.String input)
Capitalizes a string, converting the first character to uppercase.
|
static void |
close(java.io.Closeable stream) |
static boolean |
containsSymbols(java.lang.String input)
Return true if the input string contains the marker for symbols that must be expanded.
|
static <T> ObjectCreator<T> |
createConstructorConstructionPlan(OperationTracker tracker,
ObjectLocator locator,
InjectionResources resources,
org.slf4j.Logger logger,
java.lang.String description,
java.lang.reflect.Constructor<T> constructor) |
static <T> ObjectCreator<T> |
createMethodInvocationPlan(OperationTracker tracker,
ObjectLocator locator,
InjectionResources resources,
org.slf4j.Logger logger,
java.lang.String description,
java.lang.Object instance,
java.lang.reflect.Method method) |
static java.lang.String |
defaultLabel(java.lang.String id,
Messages messages,
java.lang.String propertyExpression)
Looks for a label within the messages based on the id.
|
static java.lang.String |
extractIdFromPropertyExpression(java.lang.String expression)
Used to convert a property expression into a key that can be used to locate various resources (Blocks, messages,
etc.).
|
static <T extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.annotation.Annotation[] annotations,
java.lang.Class<T> annotationClass)
Finds a specific annotation type within an array of annotations.
|
static java.lang.reflect.Constructor |
findAutobuildConstructor(java.lang.Class clazz)
Searches a class for the "best" constructor, the public constructor with the most parameters.
|
static java.lang.reflect.Method |
findMethod(java.lang.Class containingClass,
java.lang.String methodName,
java.lang.Class... parameterTypes) |
static <K,V> V |
get(java.util.Map<K,V> map,
K key)
Gets a value from a map (which may be null).
|
static java.lang.String |
getServiceId(java.lang.reflect.AnnotatedElement annotated)
Extracts the service id from the passed annotated element.
|
static void |
injectIntoFields(java.lang.Object object,
ObjectLocator locator,
InjectionResources resources,
OperationTracker tracker)
Injects into the fields (of all visibilities) when the
Inject or
InjectService annotations are present. |
static boolean |
isBlank(java.lang.String input)
Returns true if the input is null, or is a zero length string (excluding leading/trailing whitespace).
|
static boolean |
isEmptyCollection(java.lang.Object input)
Returns true if the input is an empty collection.
|
static boolean |
isLocalFile(java.lang.Class clazz)
Determines if the indicated class is stored as a locally accessible file
(and not, typically, as a file inside a JAR).
|
static boolean |
isNonBlank(java.lang.String input) |
static boolean |
isStatic(java.lang.reflect.Method method)
Returns true if the method provided is a static method.
|
static java.lang.String |
join(java.util.List elements)
Joins together some number of elements to form a comma separated list.
|
static java.lang.String |
join(java.util.List elements,
java.lang.String separator)
Joins together some number of elements.
|
static java.lang.String |
joinSorted(java.util.Collection elements)
Creates a sorted copy of the provided elements, then turns that into a comma separated list.
|
static <K,V> java.util.Set<K> |
keys(java.util.Map<K,V> map) |
static java.lang.String |
lastTerm(java.lang.String input)
Searches the string for the final period ('.') character and returns everything after that.
|
static Location |
locationOf(java.lang.Object location)
|
static <T extends java.lang.Comparable<T>> |
matchAndSort(java.util.Collection<? extends T> collection,
Predicate<T> predicate) |
static long |
nextUUID()
Generates a unique value for the current execution of the application.
|
static java.lang.Object[] |
realizeObjects(ObjectCreator[] creators) |
static java.lang.String |
replace(java.lang.String input,
java.util.regex.Pattern pattern,
java.lang.String replacement) |
static <T> java.util.Iterator<T> |
reverseIterator(java.util.List<T> list) |
static int |
size(java.util.Collection collection) |
static int |
size(java.lang.Object[] array)
Returns the size of an object array, or null if the array is empty.
|
static java.util.List<java.lang.String> |
sortedKeys(java.util.Map map)
Extracts the string keys from a map and returns them in sorted order.
|
static java.lang.String |
stripMemberName(java.lang.String memberName)
Strips leading "_" and "$" and trailing "_" from the name.
|
static AdvisorDef2 |
toAdvisorDef2(AdvisorDef advisor) |
static AnnotationProvider |
toAnnotationProvider(java.lang.Class element) |
static AnnotationProvider |
toAnnotationProvider(java.lang.reflect.Method element) |
static ContributionDef2 |
toContributionDef2(ContributionDef contribution) |
static ContributionDef3 |
toContributionDef3(ContributionDef contribution) |
static DecoratorDef2 |
toDecoratorDef2(DecoratorDef decorator) |
static java.util.List<java.lang.String> |
toList(java.util.Enumeration e)
Converts an enumeration (of Strings) into a sorted list of Strings.
|
static <S,T> Mapper<S,T> |
toMapper(Coercion<S,T> coercion)
|
static java.lang.String |
toMessage(java.lang.Throwable exception)
Deprecated.
Deprecated in 5.4; use
ExceptionUtils.toMessage(Throwable) instead. |
static ModuleDef2 |
toModuleDef2(ModuleDef md) |
static ServiceDef2 |
toServiceDef2(ServiceDef sd) |
static ServiceDef3 |
toServiceDef3(ServiceDef sd) |
static ServiceLifecycle2 |
toServiceLifecycle2(ServiceLifecycle lifecycle) |
static java.lang.String |
toUserPresentable(java.lang.String id)
Capitalizes the string, and inserts a space before each upper case character (or sequence of upper case
characters).
|
static void |
validateConstructorForAutobuild(java.lang.reflect.Constructor constructor) |
static void |
validateMarkerAnnotation(java.lang.Class markerClass)
Validates that the marker annotation class had a retention policy of runtime.
|
static void |
validateMarkerAnnotations(java.lang.Class[] markerClasses) |
public static final boolean SERVICE_CLASS_RELOADING_ENABLED
public static final Mapper<java.lang.Class,AnnotationProvider> CLASS_TO_AP_MAPPER
public static final Mapper<java.lang.reflect.Method,AnnotationProvider> METHOD_TO_AP_MAPPER
public static final Mapper<ObjectCreator,java.lang.Object> CREATE_OBJECT
public InternalUtils()
public static java.lang.String asString(java.lang.reflect.Method method, PlasticProxyFactory proxyFactory)
PlasticProxyFactory
to obtain a Location
(where possible). asString(Method)
is used under the covers, to present a detailed, but not excessive,
description of the class, method and parameters.method
- method to convert to a stringproxyFactory
- used to obtain the Location
public static java.lang.String asString(java.lang.reflect.Method method)
method
- public static int size(java.lang.Object[] array)
public static int size(java.util.Collection collection)
public static java.lang.String stripMemberName(java.lang.String memberName)
public static java.util.List<java.lang.String> toList(java.util.Enumeration e)
public static <T extends java.lang.annotation.Annotation> T findAnnotation(java.lang.annotation.Annotation[] annotations, java.lang.Class<T> annotationClass)
T
- annotations
- to searchannotationClass
- to matchpublic static ObjectCreator[] calculateParametersForMethod(java.lang.reflect.Method method, ObjectLocator locator, InjectionResources resources, OperationTracker tracker)
public static ObjectCreator[] calculateParameters(ObjectLocator locator, InjectionResources resources, java.lang.Class[] parameterTypes, java.lang.reflect.Type[] genericTypes, java.lang.annotation.Annotation[][] parameterAnnotations, OperationTracker tracker)
public static void injectIntoFields(java.lang.Object object, ObjectLocator locator, InjectionResources resources, OperationTracker tracker)
Inject
or
InjectService
annotations are present.object
- to be initializedlocator
- used to resolve external dependenciesresources
- provides injection resources for fieldstracker
- track operationspublic static java.lang.String join(java.util.List elements)
public static java.lang.String join(java.util.List elements, java.lang.String separator)
elements
- objects to be joined togetherseparator
- used between elements when joiningpublic static java.lang.String joinSorted(java.util.Collection elements)
public static boolean isBlank(java.lang.String input)
public static boolean isEmptyCollection(java.lang.Object input)
public static boolean isNonBlank(java.lang.String input)
public static java.lang.String capitalize(java.lang.String input)
public static Location locationOf(java.lang.Object location)
public static <K,V> java.util.Set<K> keys(java.util.Map<K,V> map)
public static <K,V> V get(java.util.Map<K,V> map, K key)
K
- V
- map
- the map to extract from (may be null)key
- public static boolean isStatic(java.lang.reflect.Method method)
public static <T> java.util.Iterator<T> reverseIterator(java.util.List<T> list)
public static boolean containsSymbols(java.lang.String input)
public static java.lang.String lastTerm(java.lang.String input)
public static java.lang.reflect.Constructor findAutobuildConstructor(java.lang.Class clazz)
Inject
, it will be used (no check for multiple such
constructors is made, only at most a single constructor should have the annotation).clazz
- to search for a constructor forpublic static <K,V> void addToMapList(java.util.Map<K,java.util.List<V>> map, K key, V value)
K
- the type of keyV
- the type of the listmap
- to store value intokey
- for which a value is addedvalue
- to addpublic static void validateMarkerAnnotation(java.lang.Class markerClass)
markerClass
- the marker annotation classpublic static void validateMarkerAnnotations(java.lang.Class[] markerClasses)
public static void close(java.io.Closeable stream)
public static java.lang.String toMessage(java.lang.Throwable exception)
ExceptionUtils.toMessage(Throwable)
instead.exception
- to extract message frompublic static void validateConstructorForAutobuild(java.lang.reflect.Constructor constructor)
public static AnnotationProvider toAnnotationProvider(java.lang.Class element)
public static final java.lang.reflect.Method findMethod(java.lang.Class containingClass, java.lang.String methodName, java.lang.Class... parameterTypes)
public static ServiceDef3 toServiceDef3(ServiceDef sd)
public static ServiceDef2 toServiceDef2(ServiceDef sd)
public static ModuleDef2 toModuleDef2(ModuleDef md)
public static ServiceLifecycle2 toServiceLifecycle2(ServiceLifecycle lifecycle)
public static <T extends java.lang.Comparable<T>> java.util.List<T> matchAndSort(java.util.Collection<? extends T> collection, Predicate<T> predicate)
public static ContributionDef2 toContributionDef2(ContributionDef contribution)
public static ContributionDef3 toContributionDef3(ContributionDef contribution)
public static AdvisorDef2 toAdvisorDef2(AdvisorDef advisor)
public static DecoratorDef2 toDecoratorDef2(DecoratorDef decorator)
public static boolean isLocalFile(java.lang.Class clazz)
public static long nextUUID()
public static java.lang.String getServiceId(java.lang.reflect.AnnotatedElement annotated)
ServiceId
annotation is checked.
If present, its value is returned. Otherwise Named
annotation is checked. If present, its value is
returned.
If neither of the annotations is present, null
value is returnedannotated
- annotated element to get annotations frompublic static AnnotationProvider toAnnotationProvider(java.lang.reflect.Method element)
public static <T> ObjectCreator<T> createConstructorConstructionPlan(OperationTracker tracker, ObjectLocator locator, InjectionResources resources, org.slf4j.Logger logger, java.lang.String description, java.lang.reflect.Constructor<T> constructor)
public static <T> ObjectCreator<T> createMethodInvocationPlan(OperationTracker tracker, ObjectLocator locator, InjectionResources resources, org.slf4j.Logger logger, java.lang.String description, java.lang.Object instance, java.lang.reflect.Method method)
public static java.lang.Object[] realizeObjects(ObjectCreator[] creators)
public static java.util.List<java.lang.String> sortedKeys(java.util.Map map)
map
- the map to extract keys from (may be null)public static java.lang.String toUserPresentable(java.lang.String id)
public static java.lang.String extractIdFromPropertyExpression(java.lang.String expression)
expression
- a property expressionpublic static java.lang.String defaultLabel(java.lang.String id, Messages messages, java.lang.String propertyExpression)
public static java.lang.String replace(java.lang.String input, java.util.regex.Pattern pattern, java.lang.String replacement)
${project.version} - Copyright © 2003-2015 The Apache Software Foundation.