Package jodd.bean

Class BeanUtilBean

  • All Implemented Interfaces:
    BeanUtil

    public class BeanUtilBean
    extends java.lang.Object
    implements BeanUtil
    Instantiable version of BeanUtil.
    • Constructor Summary

      Constructors 
      Constructor Description
      BeanUtilBean()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.Object arrayForcedGet​(jodd.bean.BeanProperty bp, java.lang.Object array, int index)
      Returns the element of an array forced.
      protected void arrayForcedSet​(jodd.bean.BeanProperty bp, java.lang.Object array, int index, java.lang.Object value)
      Sets the array element forced.
      protected java.lang.Object convertIndexToMapKey​(Getter getter, java.lang.Object index)
      Converts Map index to key type.
      protected java.lang.Object convertToCollection​(java.lang.Object value, java.lang.Class destinationType, java.lang.Class componentType)
      Converter to collection.
      protected java.lang.Object convertType​(java.lang.Object value, java.lang.Class type)
      Converts object to destination type.
      protected java.lang.Object createBeanProperty​(jodd.bean.BeanProperty bp)
      Creates new instance for current property name through its setter.
      BeanUtilBean declared​(boolean declared)
      Sets the declared flag.
      protected java.lang.Object ensureArraySize​(jodd.bean.BeanProperty bp, java.lang.Object array, java.lang.Class componentType, int index)  
      protected void ensureListSize​(java.util.List list, int size)  
      protected java.lang.Class extractGenericComponentType​(Getter getter)
      Extracts generic component type of a property.
      protected java.lang.String extractIndex​(jodd.bean.BeanProperty bp)
      Extract index string from non-nested property name.
      java.lang.String extractThisReference​(java.lang.String propertyName)
      Extract the first name of this reference.
      protected java.lang.Class extractType​(jodd.bean.BeanProperty bp)
      Extracts type of current property.
      BeanUtilBean forced​(boolean forced)
      Sets the forced flag.
      <T> T getIndexProperty​(java.lang.Object bean, java.lang.String property, int index)
      Returns value of indexed property.
      protected java.lang.Object getIndexProperty​(jodd.bean.BeanProperty bp)
      Get non-nested property value: either simple or indexed property.
      <T> T getProperty​(java.lang.Object bean, java.lang.String name)
      Returns value of bean's property.
      java.lang.Class<?> getPropertyType​(java.lang.Object bean, java.lang.String name)
      Returns property type.
      <T> T getSimpleProperty​(java.lang.Object bean, java.lang.String property)
      Reads simple property.
      protected java.lang.Object getSimpleProperty​(jodd.bean.BeanProperty bp)  
      protected boolean hasIndexProperty​(jodd.bean.BeanProperty bp)  
      boolean hasProperty​(java.lang.Object bean, java.lang.String name)
      Returns true if bean has a property.
      boolean hasRootProperty​(java.lang.Object bean, java.lang.String name)
      Returns true if bean has only a root property.
      boolean hasSimpleProperty​(java.lang.Object bean, java.lang.String property)
      Returns true if simple property exist.
      protected boolean hasSimpleProperty​(jodd.bean.BeanProperty bp)  
      protected int indexOfDot​(java.lang.String name)
      Finds the very first next dot.
      protected java.lang.Object invokeSetter​(Setter setter, jodd.bean.BeanProperty bp, java.lang.Object value)
      Invokes setter, but first converts type to match the setter type.
      protected int parseInt​(java.lang.String indexString, jodd.bean.BeanProperty bp)  
      protected boolean resolveExistingNestedProperties​(jodd.bean.BeanProperty bp)  
      protected void resolveNestedProperties​(jodd.bean.BeanProperty bp)
      Resolves nested property name to the very last indexed property.
      void setIndexProperty​(java.lang.Object bean, java.lang.String property, int index, java.lang.Object value)
      Sets indexed property.
      protected void setIndexProperty​(jodd.bean.BeanProperty bp, java.lang.Object value)
      Sets indexed or regular properties (no nested!).
      void setIntrospector​(ClassIntrospector introspector)
      Sets introspector implementation.
      void setProperty​(java.lang.Object bean, java.lang.String name, java.lang.Object value)
      Sets Java Bean property.
      void setSimpleProperty​(java.lang.Object bean, java.lang.String property, java.lang.Object value)
      Sets simple property.
      protected void setSimpleProperty​(jodd.bean.BeanProperty bp, java.lang.Object value)
      Sets a value of simple property.
      void setTypeConverterManager​(TypeConverterManager typeConverterManager)
      Sets type converter manager implementation.
      BeanUtilBean silent​(boolean silent)
      Sets the silent flag.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • isDeclared

        protected boolean isDeclared
      • isForced

        protected boolean isForced
      • isSilent

        protected boolean isSilent
    • Constructor Detail

      • BeanUtilBean

        public BeanUtilBean()
    • Method Detail

      • declared

        public BeanUtilBean declared​(boolean declared)
        Sets the declared flag.
      • forced

        public BeanUtilBean forced​(boolean forced)
        Sets the forced flag.
      • silent

        public BeanUtilBean silent​(boolean silent)
        Sets the silent flag.
      • resolveNestedProperties

        protected void resolveNestedProperties​(jodd.bean.BeanProperty bp)
        Resolves nested property name to the very last indexed property. If forced, null or non-existing properties will be created.
      • resolveExistingNestedProperties

        protected boolean resolveExistingNestedProperties​(jodd.bean.BeanProperty bp)
      • hasSimpleProperty

        public boolean hasSimpleProperty​(java.lang.Object bean,
                                         java.lang.String property)
        Description copied from interface: BeanUtil
        Returns true if simple property exist.
        Specified by:
        hasSimpleProperty in interface BeanUtil
      • hasSimpleProperty

        protected boolean hasSimpleProperty​(jodd.bean.BeanProperty bp)
      • getSimpleProperty

        public <T> T getSimpleProperty​(java.lang.Object bean,
                                       java.lang.String property)
        Description copied from interface: BeanUtil
        Reads simple property.
        Specified by:
        getSimpleProperty in interface BeanUtil
      • getSimpleProperty

        protected java.lang.Object getSimpleProperty​(jodd.bean.BeanProperty bp)
      • setSimpleProperty

        public void setSimpleProperty​(java.lang.Object bean,
                                      java.lang.String property,
                                      java.lang.Object value)
        Description copied from interface: BeanUtil
        Sets simple property.
        Specified by:
        setSimpleProperty in interface BeanUtil
      • setSimpleProperty

        protected void setSimpleProperty​(jodd.bean.BeanProperty bp,
                                         java.lang.Object value)
        Sets a value of simple property.
      • hasIndexProperty

        protected boolean hasIndexProperty​(jodd.bean.BeanProperty bp)
      • getIndexProperty

        public <T> T getIndexProperty​(java.lang.Object bean,
                                      java.lang.String property,
                                      int index)
        Description copied from interface: BeanUtil
        Returns value of indexed property.
        Specified by:
        getIndexProperty in interface BeanUtil
      • getIndexProperty

        protected java.lang.Object getIndexProperty​(jodd.bean.BeanProperty bp)
        Get non-nested property value: either simple or indexed property. If forced, missing bean will be created if possible.
      • setIndexProperty

        public void setIndexProperty​(java.lang.Object bean,
                                     java.lang.String property,
                                     int index,
                                     java.lang.Object value)
        Description copied from interface: BeanUtil
        Sets indexed property.
        Specified by:
        setIndexProperty in interface BeanUtil
      • setIndexProperty

        protected void setIndexProperty​(jodd.bean.BeanProperty bp,
                                        java.lang.Object value)
        Sets indexed or regular properties (no nested!).
      • setProperty

        public void setProperty​(java.lang.Object bean,
                                java.lang.String name,
                                java.lang.Object value)
        Description copied from interface: BeanUtil
        Sets Java Bean property.
        Specified by:
        setProperty in interface BeanUtil
        Parameters:
        bean - Java POJO bean or a Map
        name - property name
        value - property value
      • getProperty

        public <T> T getProperty​(java.lang.Object bean,
                                 java.lang.String name)
        Returns value of bean's property.
        Specified by:
        getProperty in interface BeanUtil
      • hasProperty

        public boolean hasProperty​(java.lang.Object bean,
                                   java.lang.String name)
        Description copied from interface: BeanUtil
        Returns true if bean has a property.
        Specified by:
        hasProperty in interface BeanUtil
      • hasRootProperty

        public boolean hasRootProperty​(java.lang.Object bean,
                                       java.lang.String name)
        Description copied from interface: BeanUtil
        Returns true if bean has only a root property. If yes, this means that property may be injected into the bean. If not, bean does not contain the property.
        Specified by:
        hasRootProperty in interface BeanUtil
      • getPropertyType

        public java.lang.Class<?> getPropertyType​(java.lang.Object bean,
                                                  java.lang.String name)
        Description copied from interface: BeanUtil
        Returns property type.
        Specified by:
        getPropertyType in interface BeanUtil
      • extractThisReference

        public java.lang.String extractThisReference​(java.lang.String propertyName)
        Extract the first name of this reference.
        Specified by:
        extractThisReference in interface BeanUtil
      • convertType

        protected java.lang.Object convertType​(java.lang.Object value,
                                               java.lang.Class type)
        Converts object to destination type. Invoked before the value is set into destination. Throws TypeConversionException if conversion fails.
      • convertToCollection

        protected java.lang.Object convertToCollection​(java.lang.Object value,
                                                       java.lang.Class destinationType,
                                                       java.lang.Class componentType)
        Converter to collection.
      • invokeSetter

        protected java.lang.Object invokeSetter​(Setter setter,
                                                jodd.bean.BeanProperty bp,
                                                java.lang.Object value)
        Invokes setter, but first converts type to match the setter type.
      • arrayForcedGet

        protected java.lang.Object arrayForcedGet​(jodd.bean.BeanProperty bp,
                                                  java.lang.Object array,
                                                  int index)
        Returns the element of an array forced. If value is null, it will be instantiated. If not the last part of indexed bean property, array will be expanded to the index if necessary.
      • arrayForcedSet

        protected void arrayForcedSet​(jodd.bean.BeanProperty bp,
                                      java.lang.Object array,
                                      int index,
                                      java.lang.Object value)
        Sets the array element forced. If index is greater then arrays length, array will be expanded to the index. If speed is critical, it is better to allocate an array with proper size before using this method.
      • ensureArraySize

        protected java.lang.Object ensureArraySize​(jodd.bean.BeanProperty bp,
                                                   java.lang.Object array,
                                                   java.lang.Class componentType,
                                                   int index)
      • ensureListSize

        protected void ensureListSize​(java.util.List list,
                                      int size)
      • indexOfDot

        protected int indexOfDot​(java.lang.String name)
        Finds the very first next dot. Ignores dots between index brackets. Returns -1 when dot is not found.
      • extractIndex

        protected java.lang.String extractIndex​(jodd.bean.BeanProperty bp)
        Extract index string from non-nested property name. If index is found, it is stripped from bean property name. If no index is found, it returns null.
      • parseInt

        protected int parseInt​(java.lang.String indexString,
                               jodd.bean.BeanProperty bp)
      • createBeanProperty

        protected java.lang.Object createBeanProperty​(jodd.bean.BeanProperty bp)
        Creates new instance for current property name through its setter. It uses default constructor!
      • extractGenericComponentType

        protected java.lang.Class extractGenericComponentType​(Getter getter)
        Extracts generic component type of a property. Returns Object.class when property does not have component.
      • convertIndexToMapKey

        protected java.lang.Object convertIndexToMapKey​(Getter getter,
                                                        java.lang.Object index)
        Converts Map index to key type. If conversion fails, original value will be returned.
      • extractType

        protected java.lang.Class extractType​(jodd.bean.BeanProperty bp)
        Extracts type of current property.