00001 /* 00002 * ExtractorEventTransformer.hpp 00003 * 00004 * Copyright (c) 2000, 2010, 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_EXTRACTOR_EVENT_TRANSFORMER_HPP 00017 #define COH_EXTRACTOR_EVENT_TRANSFORMER_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/io/pof/PortableObject.hpp" 00024 #include "coherence/util/MapEvent.hpp" 00025 #include "coherence/util/MapEventTransformer.hpp" 00026 #include "coherence/util/ValueExtractor.hpp" 00027 00028 COH_OPEN_NAMESPACE3(coherence,util,transformer) 00029 00030 using coherence::io::pof::PofReader; 00031 using coherence::io::pof::PofWriter; 00032 using coherence::io::pof::PortableObject; 00033 00034 00035 /** 00036 * ExtractorEventTransformer is a special purpose MapEventTransformer 00037 * implementation that transforms emitted events, extracting one or more 00038 * properties from either the OldValue or the NewValue. This transformation 00039 * will generally result in the change of the values' data type. 00040 * <p/> 00041 * Example: the following code will register a listener to receive events only 00042 * if the value of the AccountBalance property changes. The transformed 00043 * event's NewValue will be a List containing the LastTransactionTime and 00044 * AccountBalance properties. The OldValue will always be null. 00045 * <pre> 00046 * Filter::View vFilter = 00047 * ValueChangeEventFilter::create("getAccountBalance"); 00048 * ValueExtractor::View vExtractor = 00049 * MultiExtractor::create(MultiExtractor::createExtractors( 00050 * "getLastTransactionTime,getAccountBalance")); 00051 * MapEventTransformer::Handle hTransformer = 00052 * ExtractorEventTransformer::create(NULL, vExtractor); 00053 * 00054 * cache->addMapListener(listener, 00055 * MapEventTransformerFilter::create(vFilter, hTransformer), false); 00056 * </pre> 00057 * 00058 * @author djl 2008.06.17 00059 */ 00060 class COH_EXPORT ExtractorEventTransformer 00061 : public class_spec<ExtractorEventTransformer, 00062 extends<Object>, 00063 implements<PortableObject, MapEventTransformer> > 00064 { 00065 friend class factory<ExtractorEventTransformer>; 00066 00067 // ----- constructors --------------------------------------------------- 00068 00069 protected: 00070 /** 00071 * Default constructor (necessary for the PortableObject interface). 00072 */ 00073 ExtractorEventTransformer(); 00074 00075 /** 00076 * Construct a ExtractorEventTransformer that transforms MapEvent 00077 * values based on the specified extractor. 00078 * 00079 * Note: The specified extractor will be applied to both old and new 00080 * values. 00081 * 00082 * @param vExtractor ValueExtractor to extract MapEvent values 00083 */ 00084 ExtractorEventTransformer(ValueExtractor::View vExtractor); 00085 00086 /** 00087 * Construct a ExtractorEventTransformer that transforms MapEvent 00088 * values based on the specified extractors. Passing null indicates 00089 * that the corresponding values should be skipped completely. 00090 * 00091 * @param vExtractorOld extractor to extract the OldValue property(s) 00092 * @param vExtractorNew extractor to extract the NewValue property(s) 00093 */ 00094 ExtractorEventTransformer(ValueExtractor::View vExtractorOld, 00095 ValueExtractor::View vExtractorNew); 00096 00097 00098 // ----- MapEventTransformer interface ---------------------------------- 00099 00100 public: 00101 /** 00102 * {@inheritDoc} 00103 */ 00104 virtual MapEvent::Handle transform(MapEvent::Handle hEvent) const; 00105 00106 00107 // ----- PortableObject interface --------------------------------------- 00108 00109 public: 00110 /** 00111 * {@inheritDoc} 00112 */ 00113 virtual void readExternal(PofReader::Handle hIn); 00114 00115 /** 00116 * {@inheritDoc} 00117 */ 00118 virtual void writeExternal(PofWriter::Handle hOut) const; 00119 00120 00121 // ----- Object interface ----------------------------------------------- 00122 00123 public: 00124 /** 00125 * {@inheritDoc} 00126 */ 00127 virtual bool equals(Object::View v) const; 00128 00129 /** 00130 * {@inheritDoc} 00131 */ 00132 virtual size32_t hashCode() const; 00133 00134 /** 00135 * {@inheritDoc} 00136 */ 00137 virtual void toStream(std::ostream& out) const; 00138 00139 00140 // ----- data member accessors ------------------------------------------ 00141 00142 public: 00143 /** 00144 * Return a ValueExtractor used to transfrom the event's OldValue. 00145 * 00146 * @return an extractor from the OldValue 00147 */ 00148 virtual ValueExtractor::View getOldValueExtractor() const; 00149 00150 /** 00151 * Return a ValueExtractor used to transfrom the event's NewValue. 00152 * 00153 * @return an extractor from the NewValue 00154 */ 00155 virtual ValueExtractor::View getNewValueExtractor() const; 00156 00157 00158 // ----- data members --------------------------------------------------- 00159 00160 private: 00161 /** 00162 * The OldValueExtractor. 00163 */ 00164 MemberView<ValueExtractor> m_vExtractorOld; 00165 00166 /** 00167 * The NewValueExtractor. 00168 */ 00169 MemberView<ValueExtractor> m_vExtractorNew; 00170 }; 00171 00172 COH_CLOSE_NAMESPACE3 00173 00174 #endif // COH_EXTRACTOR_EVENT_TRANSFORMER_HPP