00001 /* 00002 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. 00003 * 00004 * Licensed under the Universal Permissive License v 1.0 as shown at 00005 * http://oss.oracle.com/licenses/upl. 00006 */ 00007 #ifndef COH_ABSTRACT_EXTRACTOR_HPP 00008 #define COH_ABSTRACT_EXTRACTOR_HPP 00009 00010 #include "coherence/lang.ns" 00011 00012 #include "coherence/io/pof/PortableObject.hpp" 00013 #include "coherence/util/MapTrigger.hpp" 00014 #include "coherence/util/QueryMap.hpp" 00015 #include "coherence/util/ValueExtractor.hpp" 00016 #include "coherence/util/comparator/QueryMapComparator.hpp" 00017 00018 COH_OPEN_NAMESPACE3(coherence,util,extractor) 00019 00020 using coherence::io::pof::PortableObject; 00021 using coherence::util::comparator::QueryMapComparator; 00022 00023 00024 /** 00025 * Abstract base for ValueExtractor implementations. It provides common 00026 * functionality that allows any extending extractor to be used as a value 00027 * Comparator. 00028 * 00029 * Starting with Coherence 3.5, when used to extract information that is 00030 * coming from a Map, subclasses have the additional ability to operate 00031 * against the Map::Entry instead of just the value. In other words, like the 00032 * EntryExtractor class, this allows an extractor implementation to 00033 * extract a desired value using all available information on the 00034 * corresponding Map::Entry object and is intended to be used in advanced 00035 * custom scenarios, when application code needs to look at both key and 00036 * value at the same time or can make some very specific assumptions regarding 00037 * to the implementation details of the underlying Entry object. To maintain 00038 * full backwards compatibility, the default behavior remains to extract from 00039 * the Value property of the Map::Entry. 00040 * 00041 * <b>Note:</b> subclasses are responsible for initialization and POF 00042 * serialization of the {@link #m_nTarget} field. 00043 * 00044 * @author djl 2008.03.10 00045 */ 00046 class COH_EXPORT AbstractExtractor 00047 : public abstract_spec<AbstractExtractor, 00048 extends<Object>, 00049 implements<ValueExtractor, QueryMapComparator, PortableObject> > 00050 { 00051 // ----- constructors --------------------------------------------------- 00052 00053 protected: 00054 /** 00055 * @internal 00056 */ 00057 AbstractExtractor(); 00058 00059 00060 // ----- ValueExtractor interface --------------------------------------- 00061 00062 public: 00063 /** 00064 * {@inheritDoc} 00065 */ 00066 virtual Object::Holder extract(Object::Holder ohTarget) const; 00067 00068 00069 // ----- QueryMapComparator interface ----------------------------------- 00070 00071 public: 00072 /** 00073 * {@inheritDoc} 00074 */ 00075 virtual int32_t compareEntries(QueryMap::Entry::View vEntry1, 00076 QueryMap::Entry::View vEntry2) const; 00077 00078 00079 // ----- Comparator interface ------------------------------------------- 00080 00081 public: 00082 /** 00083 * {@inheritDoc} 00084 */ 00085 virtual int32_t compare(Object::View v1, Object::View v2) const; 00086 00087 00088 // ----- subclassing support -------------------------------------------- 00089 00090 public: 00091 /** 00092 * Extract the value from the passed Entry object. The returned value 00093 * should follow the conventions outlined in the {@link #extract} 00094 * method. By overriding this method, an extractor implementation is 00095 * able to extract a desired value using all available information on 00096 * the corresponding Map::Entry object and is intended to be used in 00097 * advanced custom scenarios, when application code needs to look at 00098 * both key and value at the same time or can make some very specific 00099 * assumptions regarding to the implementation details of the 00100 * underlying Entry object. 00101 * 00102 * @param ohEntry an Entry object to extract a desired value from 00103 * 00104 * @return the extracted value 00105 * 00106 * @since Coherence 3.5 00107 */ 00108 virtual Object::Holder extractFromEntry( 00109 Map::Entry::Holder ohEntry) const; 00110 00111 /** 00112 * Extract the value from the "original value" of the passed Entry 00113 * object. This method's conventions are exactly the same as for the 00114 * {@link #extractFromEntry} method. 00115 * 00116 * @param ohEntry an Entry object whose original value should be used 00117 * to extract the desired value from 00118 * 00119 * @return the extracted value or NULL if the original value is not 00120 * present 00121 * 00122 * @since Coherence 3.6 00123 */ 00124 virtual Object::Holder extractOriginalFromEntry( 00125 MapTrigger::Entry::Holder ohEntry) const; 00126 00127 /** 00128 * Return the target of the extractor. 00129 * 00130 * @return the target of the extractor 00131 * 00132 * @since Coherence 12.2.1 00133 */ 00134 virtual int32_t getTarget() const; 00135 00136 00137 // ----- constants ------------------------------------------------------ 00138 00139 public: 00140 /** 00141 * Indicates that the {@link #extractFromEntry} operation should use 00142 * the Entry's value. 00143 * 00144 * @since Coherence 3.5 00145 */ 00146 static const int32_t value = 0; 00147 00148 /** 00149 * Indicates that the {@link #extractFromEntry} operation should use 00150 * the Entry's value. 00151 * 00152 * @since Coherence 3.5 00153 */ 00154 static const int32_t key = 1; 00155 00156 00157 // ----- data members --------------------------------------------------- 00158 00159 protected: 00160 /** 00161 * Specifies which part of the entry should be used by the 00162 * {@link #extractFromEntry} operation. Legal values are {@link #value} 00163 * (default) or {@link #key}. 00164 * 00165 * <b>Note:</b> subclasses are responsible for initialization and POF 00166 * serialization of this field. 00167 * 00168 * @since Coherence 3.5 00169 */ 00170 int32_t m_nTarget; 00171 }; 00172 00173 COH_CLOSE_NAMESPACE3 00174 00175 #endif // COH_ABSTRACT_EXTRACTOR_HPP