00001 /* 00002 * ReflectionExtractor.hpp 00003 * 00004 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. 00005 * 00006 * Oracle is a registered trademarks of Oracle Corporation and/or its 00007 * affiliates. 00008 * 00009 * This software is the confidential and proprietary information of Oracle 00010 * Corporation. You shall not disclose such confidential and proprietary 00011 * information and shall use it only in accordance with the terms of the 00012 * license agreement you entered into with Oracle. 00013 * 00014 * This notice may not be removed or altered. 00015 */ 00016 #ifndef COH_REFLECTION_EXTRACTOR_HPP 00017 #define COH_REFLECTION_EXTRACTOR_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/io/pof/PofReader.hpp" 00022 #include "coherence/io/pof/PofWriter.hpp" 00023 #include "coherence/util/extractor/AbstractExtractor.hpp" 00024 00025 COH_OPEN_NAMESPACE3(coherence,util,extractor) 00026 00027 using coherence::io::pof::PofReader; 00028 using coherence::io::pof::PofWriter; 00029 00030 00031 /** 00032 * Reflection-based ValueExtractor implementation. 00033 * 00034 * Local execution of a ReflectionExtractor is dependent upon target class and 00035 * method having been registered with the SystemClassLoader. For cases where 00036 * the registration has not been performed or is not possible locally executable 00037 * C++ extractors may either be custom built, or auto-generated using the 00038 * TypedExtractor<>. 00039 * 00040 * @author djl/mf 2008.03.06 00041 * 00042 * @see ChainedExtractor 00043 * @see TypedExtractor 00044 * @see Method 00045 */ 00046 class COH_EXPORT ReflectionExtractor 00047 : public cloneable_spec<ReflectionExtractor, 00048 extends<AbstractExtractor> > 00049 { 00050 friend class factory<ReflectionExtractor>; 00051 00052 // ----- constructors --------------------------------------------------- 00053 00054 protected: 00055 /** 00056 * Construct an empty ReflectionExtractor 00057 * (necessary for the PortableObject interface). 00058 */ 00059 ReflectionExtractor(); 00060 00061 /** 00062 * Construct a ReflectionExtractor based on a method name, optional 00063 * parameters and the entry extraction target. 00064 * 00065 * @param vsMethod the name of the method to invoke via reflection 00066 * @param vaParam the array of arguments to be used in the method 00067 * invocation; may be NULL 00068 * @param nTarget one of the {@link #value} or {@link #key} values 00069 * 00070 * @since Coherence 3.5 00071 */ 00072 ReflectionExtractor(String::View vsMethod, 00073 ObjectArray::View vaParam = NULL, int32_t nTarget = value); 00074 00075 /** 00076 * Copy constructor. 00077 */ 00078 ReflectionExtractor(const ReflectionExtractor& that); 00079 00080 00081 // ----- ValueExtractor interface --------------------------------------- 00082 00083 public: 00084 /** 00085 * {@inheritDoc} 00086 */ 00087 virtual Object::Holder extract(Object::Holder ohTarget) const; 00088 00089 00090 // ----- PortableObject interface --------------------------------------- 00091 00092 public: 00093 /** 00094 * {@inheritDoc} 00095 */ 00096 virtual void readExternal(PofReader::Handle hIn); 00097 00098 /** 00099 * {@inheritDoc} 00100 */ 00101 virtual void writeExternal(PofWriter::Handle hOut) const; 00102 00103 00104 // ----- Object interface ----------------------------------------------- 00105 00106 public: 00107 /** 00108 * {@inheritDoc} 00109 */ 00110 virtual bool equals(Object::View v) const; 00111 00112 /** 00113 * {@inheritDoc} 00114 */ 00115 virtual size32_t hashCode() const; 00116 00117 /** 00118 * {@inheritDoc} 00119 */ 00120 virtual TypedHandle<const String> toString() const; 00121 00122 00123 // ----- data member accessors ------------------------------------------ 00124 00125 public: 00126 /** 00127 * Determine the name of the method that this extractor is configured 00128 * to invoke. 00129 * 00130 * @return the name of the method to invoke using reflection 00131 */ 00132 virtual String::View getMethodName() const; 00133 00134 /** 00135 * Return the array of arguments used to invoke the method. 00136 * 00137 * @return the array of arguments used to invoke the method 00138 */ 00139 virtual ObjectArray::View getParameters() const; 00140 00141 00142 // ----- data members --------------------------------------------------- 00143 00144 protected: 00145 /** 00146 * The name of the method to invoke. 00147 */ 00148 FinalView<String> f_vsMethod; 00149 00150 /** 00151 * The parameter array. 00152 */ 00153 FinalView<ObjectArray> f_vaParam; 00154 00155 /** 00156 * The resolved Method. 00157 */ 00158 mutable MemberView<Method> m_vMethod; 00159 }; 00160 00161 COH_CLOSE_NAMESPACE3 00162 00163 #endif // COH_REFLECTION_EXTRACTOR_HPP