Class ReflectionExtractor<T,​E>

    • Field Detail

      • m_sMethod

        protected String m_sMethod
        The name of the method to invoke.
      • m_aoParam

        protected Object[] m_aoParam
        The parameter array.
    • Constructor Detail

      • ReflectionExtractor

        public ReflectionExtractor()
        Default constructor (necessary for the ExternalizableLite interface).
      • ReflectionExtractor

        public ReflectionExtractor​(String sMethod)
        Construct a ReflectionExtractor based on a method name.
        Parameters:
        sMethod - the name of the method to invoke via reflection
      • ReflectionExtractor

        public ReflectionExtractor​(String sMethod,
                                   Object[] aoParam)
        Construct a ReflectionExtractor based on a method name and optional parameters.
        Parameters:
        sMethod - the name of the method to invoke via reflection
        aoParam - the array of arguments to be used in the method invocation; may be null
        Since:
        Coherence 3.3
      • ReflectionExtractor

        public ReflectionExtractor​(String sMethod,
                                   Object[] aoParam,
                                   int nTarget)
        Construct a ReflectionExtractor based on a method name, optional parameters and the entry extraction target.
        Parameters:
        sMethod - the name of the method to invoke via reflection
        aoParam - the array of arguments to be used in the method invocation; may be null
        nTarget - one of the AbstractExtractor.VALUE or AbstractExtractor.KEY values
        Since:
        Coherence 3.5
    • Method Detail

      • extract

        public E extract​(T oTarget)
        Extract from target using reflection.

        Specified by:
        extract in interface ValueExtractor<T,​E>
        Overrides:
        extract in class AbstractExtractor<T,​E>
        Parameters:
        oTarget - the target
        Returns:
        value extracted from target
      • getCanonicalName

        public String getCanonicalName()
        Description copied from interface: ValueExtractor
        Return the canonical name for this extractor.

        A canonical name uniquely identifies what is to be extracted, but not how it is to be extracted. Thus two different extractor implementations with the same non-null canonical name are considered to be equal, and should reflect this in their implementations of hashCode and equals.

        Canonical names for properties are designated by their property name in camel case, for instance a Java Bean with method getFooBar would have a property named fooBar, and would have fooBar as its canonical name.

        Canonical names for zero-arg method invocations are the method name followed by ().

        Dots in a canonical name delimit one or more property/method accesses represented by a chaining ValueExtractor such as ChainedExtractor or PofExtractor(Class, PofNavigator, String).

        There is currently no canonical name format for methods which take parameters and as such they must return a canonical name of null.

        Specified by:
        getCanonicalName in interface CanonicallyNamed
        Specified by:
        getCanonicalName in interface ValueExtractor<T,​E>
        Overrides:
        getCanonicalName in class AbstractExtractor<T,​E>
        Returns:
        the extractor's canonical name, or null
      • equals

        public boolean equals​(Object o)
        Compare the ReflectionExtractor with another object to determine equality.

        AbstractExtractor.equals(Object) contract takes precedence when applicable, falling back to implementation specific equals.

        Two ReflectionExtractor objects, re1 and re2 are considered equal iff re1.extract(o) equals re2.extract(o) for all values of o.

        Specified by:
        equals in interface Comparator<T>
        Specified by:
        equals in interface ValueExtractor<T,​E>
        Overrides:
        equals in class AbstractExtractor<T,​E>
        Parameters:
        o - the reference object with which to compare
        Returns:
        true iff this ReflectionExtractor and the passed object are equivalent
      • hashCode

        public int hashCode()
        HashCode value is hashCode of non-null canonical name; otherwise, it is the hashCode of sName passed to {#link ReflectionExtractor(String)}.
        Specified by:
        hashCode in interface ValueExtractor<T,​E>
        Overrides:
        hashCode in class AbstractExtractor<T,​E>
        Returns:
        an integer hash value for this ReflectionExtractor object
      • toString

        public String toString()
        Provide a human-readable description of this ReflectionExtractor object.
        Overrides:
        toString in class Object
        Returns:
        a human-readable description of this ReflectionExtractor object
      • getMethodName

        public String getMethodName()
        Determine the name of the method that this extractor is configured to invoke.
        Returns:
        method name, property name or key
      • getParameters

        public Object[] getParameters()
        Return the array of arguments used to invoke the method.
        Returns:
        the array of arguments used to invoke the method
      • computeCanonicalName

        protected String computeCanonicalName​(String sName,
                                              Object[] aoParam)
        Compute the canonical name for this extractor.

        Steps to compute canonical name from a provided name:

        1. If parameter aoParam has one or more parameters, the canonical name is null.
        2. if name begins with a JavaBean accessor prefixes CanonicalNames.VALUE_EXTRACTOR_BEAN_ACCESSOR_PREFIXES "get" or "is, it is a property. The canonical name is formed by removing that prefix and converting the first letter to lowercase.
        3. Otherwise, sName is consider a no-arg method and its canonical form is the sName with a suffix of "()" appended.
        The following examples are properties that resolve to the canonical name foo:
        • getFoo
        • getfoo
        • isFoo
        • isfoo
        A No-arg method name "aMethod" has a canonical name of "aMethod()".

        Parameters:
        sName - a method name unless it starts with "get" or "is", then treated as a property
        aoParam - optional parameters
        Returns:
        canonical name of sName if it exist; otherwise, null
        Since:
        12.2.1.4
      • readExternal

        public void readExternal​(DataInput in)
                          throws IOException
        Restore the contents of this object by loading the object's state from the passed DataInput object.
        Specified by:
        readExternal in interface ExternalizableLite
        Parameters:
        in - the DataInput stream to read data from in order to restore the state of this object
        Throws:
        IOException - if an I/O exception occurs
        NotActiveException - if the object is not in its initial state, and therefore cannot be deserialized into
      • writeExternal

        public void writeExternal​(DataOutput out)
                           throws IOException
        Save the contents of this object by storing the object's state into the passed DataOutput object.
        Specified by:
        writeExternal in interface ExternalizableLite
        Parameters:
        out - the DataOutput stream to write the state of this object to
        Throws:
        IOException - if an I/O exception occurs
      • readExternal

        public void readExternal​(PofReader in)
                          throws IOException
        Restore the contents of a user type instance by reading its state using the specified PofReader object.
        Specified by:
        readExternal in interface PortableObject
        Parameters:
        in - the PofReader from which to read the object's state
        Throws:
        IOException - if an I/O error occurs
      • writeExternal

        public void writeExternal​(PofWriter out)
                           throws IOException
        Save the contents of a POF user type instance by writing its state using the specified PofWriter object.
        Specified by:
        writeExternal in interface PortableObject
        Parameters:
        out - the PofWriter to which to write the object's state
        Throws:
        IOException - if an I/O error occurs