Class ClassMeta<T>
- Type Parameters:
T- The class type of the wrapped class.
- All Implemented Interfaces:
Comparable<ClassInfo>,Type,Annotatable
Class object that provides cached information about that class.
Instances of this class can be created through the BeanContext.getClassMeta(Class) method.
The BeanContext class will cache and reuse instances of this class except for the following class types:
- Arrays
- Maps with non-Object key/values.
- Collections with non-Object key/values.
This class is tied to the BeanContext class because it's that class that makes the determination of what is
a bean.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionbooleancanCreateNewBean(Object outer) Returnstrue if this class can be instantiated as a bean.booleanReturnstrue if this class has a no-arg constructor or invocation handler.booleancanCreateNewInstance(Object outer) Returnstrue if this class has a no-arg constructor or invocation handler.booleanReturnstrue if this class can call thenewInstanceFromString(Object, String)method.booleanprotected ObjectSwap<?,?> protected ObjectSwap<?,?> findUnswap(Class<?> c) <A extends Annotation>
ClassMeta<T>forEachAnnotation(Class<A> type, Predicate<A> filter, Consumer<A> action) Performs an action on all matching annotations of the specified type defined on this class or parent classes/interfaces in parent-to-child order.ClassMeta<?>getArg(int index) Returns the argument metadata at the specified index if this is an args metadata object.getArgs()Returns the argument types of this meta.Returns theBeanContextthat created this object.Returns the bean dictionary name associated with this class.Returns theBeanMetaassociated with this class.Returns the bean registry for this class.BuilderSwap<T,?> getBuilderSwap(BeanSession session) Returns the builder swap associated with this class.protected ObjectSwap<?,?> getChildObjectSwapForSwap(Class<?> normalClass) Returns theObjectSwapwhere the specified class is the same/subclass of the normal class of one of the child POJO swaps associated with this class.protected ObjectSwap<?,?> getChildObjectSwapForUnswap(Class<?> swapClass) Returns theObjectSwapwhere the specified class is the same/subclass of the swap class of one of the child POJO swaps associated with this class.ClassMeta<?>For array andCollectiontypes, returns the class type of the components of the array orCollection.getExample(BeanSession session, JsonParserSession jpSession) Returns the example of this class.getFromMutater(Class<I> c) Returns the transform for this class for creating instances from other object types.getImplClassConstructor(Visibility conVis) Returns the no-arg constructor for this class based on theMarshalled.implClass()value.Returns the transform for this class for creating instances from an InputStream.ClassMeta<?>ForMaptypes, returns the class type of the keys of theMap.Returns the method or field annotated with@NameProperty.Returns the reason why this class is not a bean, ornull if it is a bean.Optional<?>If this is anOptional, returns an empty optional.Returns the method or field annotated with@ParentProperty.<T2> Optional<T2>getProperty(String name, Function<ClassMeta<?>, T2> function) Returns a lazily-computed, cached property value for thisClassMetainstance.Returns the interface proxy invocation handler for this class.Returns the transform for this class for creating instances from a Reader.ClassMeta<?>getSerializedClassMeta(BeanSession session) Returns the serialized (swapped) form of this class if there is anObjectSwapassociated with it.Returns the transform for this class for creating instances from a String.ObjectSwap<T,?> getSwap(BeanSession session) Returns theObjectSwapassociated with this class that's the best match for the specified session.getToMutater(Class<O> c) Returns the transform for this class for creating instances from other object types.ClassMeta<?>ForMaptypes, returns the class type of the values of theMap.protected booleanReturnstrue if this class or any child classes has aObjectSwapassociated with it.booleanReturnstrue if this class has a transform associated with it that allows it to be created from an InputStream.booleanhasMutaterFrom(Class<?> c) Returnstrue if this class can be instantiated from the specified type.booleanhasMutaterFrom(ClassMeta<?> c) Returnstrue if this class can be instantiated from the specified type.booleanhasMutaterTo(Class<?> c) Returnstrue if this class can be transformed to the specified type.booleanhasMutaterTo(ClassMeta<?> c) Returnstrue if this class can be transformed to the specified type.booleanReturnstrue if this class has a transform associated with it that allows it to be created from a Reader.booleanReturnstrue if this class has a transform associated with it that allows it to be created from a String.booleanisArgs()Returnstrue if this metadata represents an array of argument types.booleanisBean()Returnstrue if this class is a bean.booleanReturnstrue if this class is a subclass ofBeanMap.booleanReturnstrue if this class is aBoolean.booleanReturnstrue if this class is.byte []booleanReturnstrue if this class is aCalendar.booleanisChar()Returnstrue if this class is aCharacter.booleanReturnstrue if this class is a subclass ofCharSequence.booleanReturnstrue if this class is a subclass ofCollection.booleanbooleanisDate()Returnstrue if this class is aDate.booleanbooleanbooleanbooleanReturnstrue if this class implementsDelegate, meaning it's a representation of some other object.booleanisDouble()booleanisFloat()booleanReturnstrue if this class is anInputStream.booleanbooleanisList()Returnstrue if this class extends fromList.booleanisLong()booleanisMap()Returnstrue if this class is a subclass ofMap.booleanReturnstrue if this class is a subclass ofMapor it's a bean.booleanisMethod()Returnstrue if this class isMethod.booleanReturnstrue if instance of this object can benull .booleanisNumber()Returnstrue if this class is a subclass ofNumber.booleanisObject()Returnstrue if this class isObject.booleanReturnstrue if this class is a subclass ofOptional.booleanisReader()Returnstrue if this class is aReader.booleanisSet()Returnstrue if this class extends fromSet.booleanisShort()booleanisString()Returnstrue if this class is aString.booleanReturnstrue if this class is aTemporal.booleanisUri()mutateFrom(Object o) Transforms the specified object into an instance of this class.<O> OTransforms the specified object into an instance of this class.<O> OTransforms the specified object into an instance of this class.Create a new instance of the main class of this declared type.newInstance(Object outer) Same asnewInstance()except for instantiating non-static member classes.newInstanceFromString(Object outer, String arg) Create a new instance of the main class of this declared type from aString input.booleanSimilar toequals(Object)except primitive and Object types that are similar are considered the same.toString()toString(boolean simple) Same astoString()except use simple class names.Converts the specified object to a string.protected StringBuildertoString(StringBuilder sb, boolean simple) Appends this object as a readable string to the specified string builder.Methods inherited from class org.apache.juneau.commons.reflect.ClassInfoTyped
getPrimitiveDefault, innerMethods inherited from class org.apache.juneau.commons.reflect.ClassInfo
appendNameFormatted, arrayType, asSubclass, canAcceptArg, cast, compareTo, componentType, descriptorString, getAllFields, getAllMethods, getAllMethodsTopDown, getAllParents, getAnnotatableType, getAnnotatedInterfaces, getAnnotatedSuperclass, getAnnotations, getAnnotations, getClassLoader, getComponentType, getDeclaredAnnotations, getDeclaredConstructor, getDeclaredConstructors, getDeclaredField, getDeclaredFields, getDeclaredInterfaces, getDeclaredMemberClasses, getDeclaredMethod, getDeclaredMethods, getDeclaringClass, getDimensions, getEnclosingClass, getEnclosingConstructor, getEnclosingMethod, getGenericInterfaces, getGenericSuperclass, getInterfaces, getLabel, getMemberClasses, getMethod, getModule, getName, getNameCanonical, getNameFormatted, getNameFull, getNameReadable, getNames, getNameShort, getNameSimple, getNestHost, getNestMembers, getNoArgConstructor, getPackage, getPackageAnnotation, getParameterType, getParents, getParentsAndInterfaces, getPermittedSubclasses, getPrimitiveForWrapper, getPrimitiveWrapper, getProtectionDomain, getPublicConstructor, getPublicConstructors, getPublicField, getPublicFields, getPublicMethod, getPublicMethods, getRecordComponents, getRepeatedAnnotationMethod, getResource, getResourceAsStream, getSigners, getSuperclass, getTypeParameters, getWrapperIfPrimitive, hasAnnotation, hashCode, hasPackage, hasPrimitiveWrapper, innerType, is, is, is, isAnnotation, isAnonymousClass, isAny, isAny, isAny, isAny, isAny, isArray, isChildOf, isChildOf, isChildOf, isChildOfAny, isClass, isCollectionOrArray, isDeprecated, isEnum, isInstance, isLocalClass, isMemberClass, isNestmateOf, isNonStaticMemberClass, isNotDeprecated, isNotLocalClass, isNotMemberClass, isNotNonStaticMemberClass, isNotPrimitive, isNotVoid, isParentOf, isParentOf, isParentOf, isParentOfLenient, isParentOfLenient, isParentOfLenient, isPrimitive, isRecord, isRepeatedAnnotation, isRuntimeException, isSealed, isStrictChildOf, isSynthetic, isVisible, isVoid, of, of, of, of, ofProxy, unwrapMethods inherited from class org.apache.juneau.commons.reflect.ElementInfo
ai, getModifiers, isAbstract, isAll, isAny, isFinal, isInterface, isNative, isNotAbstract, isNotFinal, isNotInterface, isNotNative, isNotPrivate, isNotProtected, isNotPublic, isNotStatic, isNotSynchronized, isNotTransient, isNotVolatile, isPrivate, isProtected, isPublic, isStatic, isSynchronized, isTransient, isVolatileMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.reflect.Type
getTypeName
-
Method Details
-
findSwap
-
findUnswap
-
canCreateNewBean
Returnstrue if this class can be instantiated as a bean. Returnsfalse if this is a non-static member class and the outer object does not match the class type of the defining class.- Parameters:
outer- The outer class object for non-static member classes. Can benull for non-member or static classes.- Returns:
true if a new instance of this bean can be created within the context of the specified outer object.
-
canCreateNewInstance
Returnstrue if this class has a no-arg constructor or invocation handler.- Returns:
true if a new instance of this class can be constructed.
-
canCreateNewInstance
Returnstrue if this class has a no-arg constructor or invocation handler. Returnsfalse if this is a non-static member class and the outer object does not match the class type of the defining class.- Parameters:
outer- The outer class object for non-static member classes. Can benull for non-member or static classes.- Returns:
true if a new instance of this class can be created within the context of the specified outer object.
-
canCreateNewInstanceFromString
Returnstrue if this class can call thenewInstanceFromString(Object, String)method.- Parameters:
outer- The outer class object for non-static member classes. Can benull for non-member or static classes.- Returns:
true if this class has a no-arg constructor or invocation handler.
-
equals
-
forEachAnnotation
public <A extends Annotation> ClassMeta<T> forEachAnnotation(Class<A> type, Predicate<A> filter, Consumer<A> action) Performs an action on all matching annotations of the specified type defined on this class or parent classes/interfaces in parent-to-child order.- Type Parameters:
A- The annotation type to look for.- Parameters:
type- The annotation to search for.filter- A predicate to apply to the entries to determine if action should be performed. Can benull .action- An action to perform on the entry.- Returns:
- This object.
-
getArg
Returns the argument metadata at the specified index if this is an args metadata object.- Parameters:
index- The argument index.- Returns:
- The The argument metadata. Never
null . - Throws:
BeanRuntimeException- If this metadata object is not a list of arguments, or the index is out of range.
-
getArgs
Returns the argument types of this meta.- Returns:
- The argument types of this meta, or
null if this isn't an array of argument types.
-
getBeanContext
Returns theBeanContextthat created this object.- Returns:
- The bean context.
-
getBeanMeta
Returns theBeanMetaassociated with this class.- Returns:
- The
BeanMetaassociated with this class, ornull if there is no bean meta associated with this class.
-
getBeanRegistry
Returns the bean registry for this class.This bean registry contains names specified in the
@Bean(dictionary)annotation defined on the class, regardless of whether the class is an actual bean. This allows interfaces to define subclasses with type names.This is a shortcut for calling getBeanMeta().getBeanRegistry().
- Returns:
- The bean registry for this class, or
null if no bean registry is associated with it.
-
getBuilderSwap
Returns the builder swap associated with this class.- Parameters:
session- The current bean session.- Returns:
- The builder swap associated with this class, or
null if it doesn't exist.
-
getBeanDictionaryName
Returns the bean dictionary name associated with this class.The lexical name is defined by
@Bean(typeName).- Returns:
- The type name associated with this bean class, or
null if there is no type name defined or this isn't a bean.
-
getElementType
For array andCollectiontypes, returns the class type of the components of the array orCollection.- Returns:
- The element class type, or
null if this class is not an array or Collection.
-
getExample
Returns the example of this class.- Parameters:
session- The bean session.
Required because the example method may take it in as a parameter.jpSession- The JSON parser for parsing examples into POJOs.- Returns:
- The serialized class type, or this object if no swap is associated with the class.
-
getFromMutater
Returns the transform for this class for creating instances from other object types.- Type Parameters:
I- The transform-from class.- Parameters:
c- The transform-from class.- Returns:
- The transform, or
null if no such transform exists.
-
getImplClassConstructor
Returns the no-arg constructor for this class based on theMarshalled.implClass()value.- Parameters:
conVis- The constructor visibility.- Returns:
- The no-arg constructor for this class, or
null if it does not exist.
-
getInputStreamMutater
Returns the transform for this class for creating instances from an InputStream.- Returns:
- The transform, or
null if no such transform exists.
-
getKeyType
ForMaptypes, returns the class type of the keys of theMap.- Returns:
- The key class type, or
null if this class is not a Map.
-
getNameProperty
Returns the method or field annotated with@NameProperty.- Returns:
- The method or field annotated with
@NamePropertyornull if method does not exist.
-
getNotABeanReason
Returns the reason why this class is not a bean, ornull if it is a bean.- Returns:
- The reason why this class is not a bean, or
null if it is a bean.
-
getOptionalDefault
If this is anOptional, returns an empty optional.Note that if this is a nested optional, will recursively create empty optionals.
- Returns:
- An empty optional, or
null if this isn't an optional.
-
getParentProperty
Returns the method or field annotated with@ParentProperty.- Returns:
- The method or field annotated with
@ParentPropertyornull if method does not exist.
-
getProperty
Returns a lazily-computed, cached property value for thisClassMetainstance.This method provides a memoization mechanism for expensive computations. The property value is computed on the first call using the provided function, then cached for subsequent calls with the same property name.
The function is only invoked once per property name per
ClassMetainstance. Subsequent calls with the same name will return the cached value without re-invoking the function.Thread Safety:
This method is thread-safe. If multiple threads call this method simultaneously with the same property name, the function may be invoked multiple times, but only one result will be cached and returned.
Usage:
// Compute and cache an expensive property Optional<String>computedValue = classMeta.getProperty ("expensiveProperty" , cm -> {// Expensive computation that only runs once return performExpensiveComputation(cm); });// Subsequent calls return cached value Optional<String>cached = classMeta.getProperty ("expensiveProperty" , cm -> {// This function is NOT called again return performExpensiveComputation(cm); });- Type Parameters:
T2- The type of the property value.- Parameters:
name- The unique name identifying this property. Used as the cache key.function- The function that computes the property value. Receives thisClassMetainstance as input. Only invoked if the property hasn't been computed yet. Can returnnull .- Returns:
- An
Optionalcontaining the property value if the function returned a non-null value, otherwise an emptyOptional. Nevernull .
-
getProxyInvocationHandler
Returns the interface proxy invocation handler for this class.- Returns:
- The interface proxy invocation handler, or
null if it does not exist.
-
getReaderMutater
Returns the transform for this class for creating instances from a Reader.- Returns:
- The transform, or
null if no such transform exists.
-
getSerializedClassMeta
Returns the serialized (swapped) form of this class if there is anObjectSwapassociated with it.- Parameters:
session- The bean session.
Required because the swap used may depend on the media type being serialized or parsed.- Returns:
- The serialized class type, or this object if no swap is associated with the class.
-
getStringMutater
Returns the transform for this class for creating instances from a String.- Returns:
- The transform, or
null if no such transform exists.
-
getSwap
Returns theObjectSwapassociated with this class that's the best match for the specified session.- Parameters:
session- The current bean session.
If multiple swaps are associated with a class, only the first one with a matching media type will be returned.- Returns:
- The
ObjectSwapassociated with this class, ornull if there are no POJO swaps associated with this class.
-
getToMutater
Returns the transform for this class for creating instances from other object types.- Type Parameters:
O- The transform-to class.- Parameters:
c- The transform-from class.- Returns:
- The transform, or
null if no such transform exists.
-
getValueType
ForMaptypes, returns the class type of the values of theMap.- Returns:
- The value class type, or
null if this class is not a Map.
-
hasInputStreamMutater
Returnstrue if this class has a transform associated with it that allows it to be created from an InputStream.- Returns:
true if this class has a transform associated with it that allows it to be created from an InputStream.
-
hasMutaterFrom
Returnstrue if this class can be instantiated from the specified type.- Parameters:
c- The class type to convert from.- Returns:
true if this class can be instantiated from the specified type.
-
hasMutaterFrom
Returnstrue if this class can be instantiated from the specified type.- Parameters:
c- The class type to convert from.- Returns:
true if this class can be instantiated from the specified type.
-
hasMutaterTo
Returnstrue if this class can be transformed to the specified type.- Parameters:
c- The class type to convert from.- Returns:
true if this class can be transformed to the specified type.
-
hasMutaterTo
Returnstrue if this class can be transformed to the specified type.- Parameters:
c- The class type to convert from.- Returns:
true if this class can be transformed to the specified type.
-
hasReaderMutater
Returnstrue if this class has a transform associated with it that allows it to be created from a Reader.- Returns:
true if this class has a transform associated with it that allows it to be created from a Reader.
-
hasStringMutater
Returnstrue if this class has a transform associated with it that allows it to be created from a String.- Returns:
true if this class has a transform associated with it that allows it to be created from a String.
-
isArgs
Returnstrue if this metadata represents an array of argument types.- Returns:
true if this metadata represents an array of argument types.
-
isBean
Returnstrue if this class is a bean.- Returns:
true if this class is a bean.
-
isBeanMap
Returnstrue if this class is a subclass ofBeanMap.- Returns:
true if this class is a subclass ofBeanMap.
-
isBoolean
Returnstrue if this class is aBoolean.- Returns:
true if this class is aBoolean.
-
isByteArray
Returnstrue if this class is.byte []- Returns:
true if this class is.byte []
-
isCalendar
Returnstrue if this class is aCalendar.- Returns:
true if this class is aCalendar.
-
isChar
Returnstrue if this class is aCharacter.- Returns:
true if this class is aCharacter.
-
isCharSequence
Returnstrue if this class is a subclass ofCharSequence.- Returns:
true if this class is a subclass ofCharSequence.
-
isCollection
Returnstrue if this class is a subclass ofCollection.- Returns:
true if this class is a subclass ofCollection.
-
isCollectionOrArrayOrOptional
- Returns:
true if this class is a subclass ofCollectionor is an array orOptional.
-
isDate
Returnstrue if this class is aDate.- Returns:
true if this class is aDate.
-
isDateOrCalendar
-
isDateOrCalendarOrTemporal
-
isDecimal
-
isDelegate
Returnstrue if this class implementsDelegate, meaning it's a representation of some other object.- Returns:
true if this class implementsDelegate.
-
isDouble
- Returns:
true if this class is eitherDoubleordouble .
-
isFloat
- Returns:
true if this class is eitherFloatorfloat .
-
isInputStream
Returnstrue if this class is anInputStream.- Returns:
true if this class is anInputStream.
-
isInteger
- Returns:
true if this class is eitherIntegerorint .
-
isList
Returnstrue if this class extends fromList.- Returns:
true if this class extends fromList.
-
isLong
- Returns:
true if this class is eitherLongorlong .
-
isMap
Returnstrue if this class is a subclass ofMap.- Returns:
true if this class is a subclass ofMap.
-
isMapOrBean
Returnstrue if this class is a subclass ofMapor it's a bean.- Returns:
true if this class is a subclass ofMapor it's a bean.
-
isMethod
Returnstrue if this class isMethod.- Returns:
true if this class isMethod.
-
isNullable
Returnstrue if instance of this object can benull .Objects can be
null , but primitives cannot, except for chars which can be represented by(.char )0- Returns:
true if instance of this class can be null.
-
isNumber
Returnstrue if this class is a subclass ofNumber.- Returns:
true if this class is a subclass ofNumber.
-
isObject
Returnstrue if this class isObject.- Returns:
true if this class isObject.
-
isOptional
Returnstrue if this class is a subclass ofOptional.- Returns:
true if this class is a subclass ofOptional.
-
isReader
Returnstrue if this class is aReader.- Returns:
true if this class is aReader.
-
isSet
Returnstrue if this class extends fromSet.- Returns:
true if this class extends fromSet.
-
isShort
- Returns:
true if this class is eitherShortorshort .
-
isString
Returnstrue if this class is aString.- Returns:
true if this class is aString.
-
isTemporal
Returnstrue if this class is aTemporal.- Returns:
true if this class is aTemporal.
-
isUri
-
mutateFrom
Transforms the specified object into an instance of this class.- Parameters:
o- The object to transform.- Returns:
- The transformed object.
-
mutateTo
Transforms the specified object into an instance of this class.- Type Parameters:
O- The transform-to class.- Parameters:
o- The object to transform.c- The class- Returns:
- The transformed object.
-
mutateTo
Transforms the specified object into an instance of this class.- Type Parameters:
O- The transform-to class.- Parameters:
o- The object to transform.c- The class- Returns:
- The transformed object.
-
newInstance
Create a new instance of the main class of this declared type.- Overrides:
newInstancein classClassInfo- Returns:
- A new instance of the object, or
null if there is no no-arg constructor on the object. - Throws:
ExecutableException- Exception occurred on invoked constructor/method/field.
-
newInstance
Same asnewInstance()except for instantiating non-static member classes.- Parameters:
outer- The instance of the owning object of the member class instance. Can benull if instantiating a non-member or static class.- Returns:
- A new instance of the object, or
null if there is no no-arg constructor on the object. - Throws:
ExecutableException- Exception occurred on invoked constructor/method/field.
-
newInstanceFromString
Create a new instance of the main class of this declared type from aString input.In order to use this method, the class must have one of the following methods:
public static T valueOf(String in);public static T fromString(String in);public T(String in);
- Parameters:
outer- The outer class object for non-static member classes. Can benull for non-member or static classes.arg- The input argument value.- Returns:
- A new instance of the object, or
null if there is no string constructor on the object. - Throws:
ExecutableException- Exception occurred on invoked constructor/method/field.
-
same
Similar toequals(Object)except primitive and Object types that are similar are considered the same. (e.g.boolean ==Boolean ).- Parameters:
cm- The class meta to compare to.- Returns:
true if the specified class-meta is equivalent to this one.
-
toString
-
toString
Same astoString()except use simple class names.- Parameters:
simple- Print simple class names only (no package).- Returns:
- A new string.
-
toString
Converts the specified object to a string.- Parameters:
t- The object to convert.- Returns:
- The object converted to a string, or
null if the object was null.
-
getChildObjectSwapForSwap
Returns theObjectSwapwhere the specified class is the same/subclass of the normal class of one of the child POJO swaps associated with this class.- Parameters:
normalClass- The normal class being resolved.- Returns:
- The resolved
ObjectSwapornull if none were found.
-
getChildObjectSwapForUnswap
Returns theObjectSwapwhere the specified class is the same/subclass of the swap class of one of the child POJO swaps associated with this class.- Parameters:
swapClass- The swap class being resolved.- Returns:
- The resolved
ObjectSwapornull if none were found.
-
hasChildSwaps
Returnstrue if this class or any child classes has aObjectSwapassociated with it.Used when transforming bean properties to prevent having to look up transforms if we know for certain that no transforms are associated with a bean property.
- Returns:
true if this class or any child classes has aObjectSwapassociated with it.
-
toString
Appends this object as a readable string to the specified string builder.- Parameters:
sb- The string builder to append this object to.simple- Print simple class names only (no package).- Returns:
- The passed-in string builder.
-