00001 /* 00002 * FilterTrigger.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_FILTER_TRIGGER_HPP 00017 #define COH_FILTER_TRIGGER_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/Filter.hpp" 00025 #include "coherence/util/MapTrigger.hpp" 00026 00027 COH_OPEN_NAMESPACE3(coherence,util,filter) 00028 00029 using coherence::io::pof::PofReader; 00030 using coherence::io::pof::PofWriter; 00031 using coherence::io::pof::PortableObject; 00032 00033 00034 /** 00035 * A generic Filter-based MapTrigger implementation. If an evaluation of the 00036 * coherence::util::MapTrigger::Entry object representing a pending 00037 * change fails (returns false), then one of the following actions is taken: 00038 * <ul> 00039 * <li> action_rollback - an IllegalArgumentException is thrown by the 00040 * trigger to reject the operation that would result in this change 00041 * (default); 00042 * <li> action_ignore - the change is ignored and the Entry's value is reset 00043 * to the original value returned by the 00044 * coherence::util::MapTrigger::Entry#getOriginalValue() method; 00045 * <li> action_remove - the entry is removed from the underlying backing map 00046 * using the coherence::util::InvocableMap::Entry#remove(bool) call. 00047 * </ul> 00048 * 00049 * Note: This trigger never prevents entries from being removed. 00050 * 00051 * @author djl 2008.05.22 00052 */ 00053 class COH_EXPORT FilterTrigger 00054 : public class_spec<FilterTrigger, 00055 extends<Object>, 00056 implements<PortableObject, MapTrigger> > 00057 { 00058 friend class factory<FilterTrigger>; 00059 00060 // ----- constructors --------------------------------------------------- 00061 00062 protected: 00063 /** 00064 * Default constructor (necessary for the PortableObject interface). 00065 */ 00066 FilterTrigger(); 00067 00068 /** 00069 * Construct a FilterTrigger based on the specified Filter object and 00070 * the action constant. 00071 * 00072 * @param vFilter the underlying Filter 00073 * @param nAction one of the ACTION_* constants, default is action_rollback 00074 */ 00075 FilterTrigger(Filter::View vFilter, int32_t nAction = action_rollback); 00076 00077 00078 // ----- MapTrigger interface ------------------------------------------- 00079 00080 public: 00081 /** 00082 * {@inheritDoc} 00083 */ 00084 virtual void process(MapTrigger::Entry::Handle vEntry); 00085 00086 00087 // ----- PortableObject interface --------------------------------------- 00088 00089 public: 00090 /** 00091 * {@inheritDoc} 00092 */ 00093 virtual void readExternal(PofReader::Handle hIn); 00094 00095 /** 00096 * {@inheritDoc} 00097 */ 00098 virtual void writeExternal(PofWriter::Handle hOut) const; 00099 00100 00101 // ----- Object interface ----------------------------------------------- 00102 00103 public: 00104 /** 00105 * Compare the FilterTrigger with another object to determine 00106 * equality. Two FilterTrigger objects are considered equal iff the 00107 * wrapped filters and action codes are equal. 00108 * 00109 * @return true iff this FilterTrigger and the passed object are 00110 * equivalent FilterTrigger objects 00111 */ 00112 virtual bool equals(Object::View v) const; 00113 00114 /** 00115 * {@inheritDoc} 00116 */ 00117 virtual size32_t hashCode() const; 00118 00119 /** 00120 * {@inheritDoc} 00121 */ 00122 virtual TypedHandle<const String> toString() const; 00123 00124 00125 // ----- data member accessors ------------------------------------------ 00126 00127 public: 00128 /** 00129 * Obtain the underlying Filter. 00130 * 00131 * @return the underlying Filter object 00132 */ 00133 virtual Filter::View getFilter() const; 00134 00135 /** 00136 * Obtain the action code for this FilterTrigger. 00137 * 00138 * @return one of the ACTION_* constants 00139 */ 00140 virtual int32_t getAction() const; 00141 00142 00143 // ----- constants ------------------------------------------------------ 00144 00145 public: 00146 /** 00147 * Evaluation failure results in an IllegalArgumentException thrown 00148 * by the trigger. 00149 */ 00150 static const int32_t action_rollback = 0; 00151 00152 /** 00153 * Evaluation failure results in restoring the original Entry's value. 00154 */ 00155 static const int32_t action_ignore = 1; 00156 00157 /** 00158 * Evaluation failure results in a removal of the entry. 00159 */ 00160 static const int32_t action_remove = 2; 00161 00162 00163 // ----- data members --------------------------------------------------- 00164 00165 protected: 00166 /** 00167 * The underlying filter. 00168 */ 00169 FinalView<Filter> f_vFilter; 00170 00171 /** 00172 * The action code. 00173 */ 00174 int32_t m_nAction; 00175 }; 00176 00177 COH_CLOSE_NAMESPACE3 00178 00179 #endif // COH_FILTER_TRIGGER_HPP