Class BeanRegistry

java.lang.Object
org.apache.juneau.marshall.BeanRegistry
All Implemented Interfaces:
BeanRegistryLookup

public class BeanRegistry extends Object implements BeanRegistryLookup
A lookup table for resolving bean types by name.

In a nutshell, provides a simple mapping of bean class objects to identifying names.

Class names are defined through the @Marshalled(typeName) annotation.

The dictionary is used by the framework in the following ways:

  • If a class type cannot be inferred through reflection during parsing, then a helper "_type" is added to the serialized output using the name defined for that class in this dictionary. This helps determine the real class at parse time.
  • The dictionary name is used as element names when serialized to XML.
  • Method Details

    • getClassMeta

      public ClassMeta<?> getClassMeta(String typeName)
      Gets the class metadata for the specified bean type name.
      Parameters:
      typeName - The bean type name as defined by @Marshalled(typeName). Can include multi-dimensional array type names (e.g. "X^^").
      Can be null (returns null).
      Returns:
      The class metadata for the bean, or null if the registry is empty, the type name is null, or no matching entry was found.
    • getTypeName

      public String getTypeName(ClassMeta<?> c)
      Given the specified class, return the dictionary name for it.
      Parameters:
      c - The class to lookup in this registry. Can be null (returns null).
      Returns:
      The dictionary name for the specified class in this registry, or null if not found.
    • getTypeName

      public String getTypeName(Class<?> c)
      Given the specified raw class, return the dictionary name for it.

      Variant of getTypeName(ClassMeta) that takes the raw Class directly so callers in the bean-modeling layer (which is being decoupled from ClassMeta) can perform a polymorphic-dispatch lookup without holding a ClassMeta reference.

      Specified by:
      getTypeName in interface BeanRegistryLookup
      Parameters:
      c - The class to lookup in this registry. Can be null (returns null).
      Returns:
      The dictionary name for the specified class in this registry, or null if not found.
    • hasName

      public boolean hasName(String typeName)
      Returns true if this dictionary has an entry for the specified type name.
      Specified by:
      hasName in interface BeanRegistryLookup
      Parameters:
      typeName - The bean type name. Can be null (returns false).
      Returns:
      true if this dictionary has an entry for the specified type name.
    • properties

    • toString

      public String toString()
      Overrides:
      toString in class Object