00001 /* 00002 * UserTypeReader.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_USER_TYPE_READER_HPP 00017 #define COH_USER_TYPE_READER_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/io/ReadBuffer.hpp" 00022 #include "coherence/io/pof/PofBufferReader.hpp" 00023 #include "coherence/io/pof/PofContext.hpp" 00024 #include "coherence/util/Binary.hpp" 00025 00026 COH_OPEN_NAMESPACE3(coherence,io,pof) 00027 00028 using coherence::io::ReadBuffer; 00029 using coherence::util::Binary; 00030 00031 00032 /** 00033 * The UserTypeReader implementation is a contextually-aware PofReader whose 00034 * purpose is to advance through the properties of a value of a specified user 00035 * type. The "contextual awareness" refers to the fact that the UserTypeReader 00036 * maintains state about the type identifier and version of the user type, the 00037 * parser's property index position within the user type value, and a 00038 * PofContext that may differ from the PofContext that provided the 00039 * PofSerializer which is using this UserTypeReader to parse a user type. 00040 * 00041 * @author jh 2008.04.11 00042 */ 00043 class COH_EXPORT UserTypeReader 00044 : public class_spec<UserTypeReader, 00045 extends<PofBufferReader> > 00046 { 00047 friend class factory<UserTypeReader>; 00048 00049 // ----- constructors --------------------------------------------------- 00050 00051 protected: 00052 /** 00053 * Construct a parser for parsing the property values of a user type. 00054 * 00055 * @param hIn the BufferInput that contains the user type 00056 * data, except for the user type id itself (which 00057 * is passed passed as a constructor argument) 00058 * @param vCtx the PofContext to use for parsing the user type 00059 * property values within the user type that this 00060 * parser will be parsing 00061 * @param nTypeId the type id of the user type 00062 * @param nVersionId the version id of the user type 00063 * 00064 * @throws IOException if an I/O error occurs 00065 */ 00066 UserTypeReader(ReadBuffer::BufferInput::Handle hIn, 00067 PofContext::View vCtx, int32_t nTypeId, int32_t nVersionId); 00068 00069 /** 00070 * Construct a parser for parsing the property values of a user type. 00071 * 00072 * @param hParent the parent (ie the containing) PofBufferReader 00073 * @param hIn the BufferInput that contains the user type 00074 * data, except for the user type id itself (which 00075 * is passed passed as a constructor argument) 00076 * @param vCtx the PofContext to use for parsing the user type 00077 * property values within the user type that this 00078 * parser will be parsing 00079 * @param nTypeId the type id of the user type 00080 * @param nVersionId the version id of the user type 00081 * 00082 * @throws IOException if an I/O error occurs 00083 */ 00084 UserTypeReader(PofBufferReader::Handle hParent, 00085 ReadBuffer::BufferInput::Handle hIn, PofContext::View vCtx, 00086 int32_t nTypeId, int32_t nVersionId); 00087 00088 private: 00089 /** 00090 * Create a nested UserTypeReader, which will be initiated with the 00091 * information found in the nested buffer. 00092 * 00093 * @param hParent the parent (ie the containing) PofBufferReader 00094 * @param hIn the BufferInput that contains the user type data 00095 * @param vCtx the PofContext to use for parsing the user type property 00096 * values within the user type that this parser will be 00097 * parsing 00098 * 00099 * @throws IOException if an I/O error occurs 00100 */ 00101 /** 00102 * @internal 00103 */ 00104 UserTypeReader(PofBufferReader::Handle hParent, 00105 ReadBuffer::BufferInput::Handle hIn, PofContext::View vCtx); 00106 00107 /** 00108 * Construct a parser for parsing a nested property that does not exist. 00109 * In other words, this is a "no-op" user type reader. 00110 * 00111 * @param hParent the parent (ie the containing) PofBufferReader 00112 * @param hIn the BufferInput that contains the user type 00113 * data, except for the user type id itself (which 00114 * is passed passed as a constructor argument) 00115 * @param vCtx the PofContext to use for parsing the user type 00116 * property values within the user type that this 00117 * parser will be parsing 00118 * @param nTypeId the type id of the user type 00119 * 00120 * @throws IOException if an I/O error occurs 00121 */ 00122 /** 00123 * @internal 00124 */ 00125 UserTypeReader(PofBufferReader::Handle hParent, 00126 ReadBuffer::BufferInput::Handle hIn, 00127 PofContext::View vCtx, int32_t nTypeId); 00128 00129 00130 // ----- PofReader interface -------------------------------------------- 00131 00132 public: 00133 /** 00134 * {@inheritDoc} 00135 */ 00136 virtual int32_t getUserTypeId() const; 00137 00138 /** 00139 * {@inheritDoc} 00140 */ 00141 virtual int32_t getVersionId() const; 00142 00143 /** 00144 * {@inheritDoc} 00145 */ 00146 virtual void registerIdentity(Object::Holder oh); 00147 using PofBufferReader::registerIdentity; 00148 00149 /** 00150 * {@inheritDoc} 00151 */ 00152 virtual PofReader::Handle createNestedPofReader(int32_t iProp); 00153 00154 /** 00155 * {@inheritDoc} 00156 */ 00157 virtual Binary::View readRemainder(); 00158 00159 00160 // ----- internal methods ----------------------------------------------- 00161 00162 public: 00163 /** 00164 * Return the index of the next property in the POF stream. 00165 * 00166 * @return the index of the next property in the POF stream, or -1 if 00167 * there are no more properties 00168 * 00169 * @throws IOException if an I/O error occurs 00170 * 00171 * @since Coherence 12.1.3 00172 */ 00173 virtual int32_t getNextPropertyIndex(); 00174 00175 /** 00176 * Return the index of the most recent property read or (if it were 00177 * missing) requested. 00178 * 00179 * @return the index of the most recent property read 00180 * 00181 * @since Coherence 12.1.3 00182 */ 00183 virtual int32_t getPreviousPropertyIndex() const; 00184 00185 protected: 00186 /** 00187 * {@inheritDoc} 00188 */ 00189 virtual bool advanceTo(int32_t iProp); 00190 00191 /** 00192 * {@inheritDoc} 00193 */ 00194 virtual void complete(int32_t iProp); 00195 00196 /** 00197 * Notify the UserTypeReader that it is being "closed". 00198 * 00199 * @throws IOException if an I/O error occurs 00200 */ 00201 virtual void closeNested(); 00202 00203 /** 00204 * {@inheritDoc} 00205 */ 00206 virtual PofBufferReader::Handle getParentParser(); 00207 00208 /** 00209 * {@inheritDoc} 00210 */ 00211 virtual PofBufferReader::View getParentParser() const; 00212 00213 00214 // ----- data members --------------------------------------------------- 00215 00216 protected: 00217 /** 00218 * The parent (ie containing) PofBufferReader. 00219 */ 00220 FinalHandle<PofBufferReader> f_hParent; 00221 00222 /** 00223 * The type identifier of the user type that is being parsed. 00224 */ 00225 int32_t m_nTypeId; 00226 00227 /** 00228 * The version identifier of the user type that is being parsed. 00229 */ 00230 int32_t m_nVersionId; 00231 00232 /** 00233 * Most recent property read or (if it were missing) requested. This 00234 * is used to determine if the client is attempting to read properties 00235 * in the wrong order. 00236 */ 00237 int32_t m_iPrevProp; 00238 00239 /** 00240 * The index of the next property in the POF stream. 00241 */ 00242 int32_t m_iNextProp; 00243 00244 /** 00245 * The offset of the index of the next property to read. 00246 */ 00247 size32_t m_ofNextProp; 00248 00249 /** 00250 * The currently open nested reader, if any. 00251 */ 00252 MemberHandle<UserTypeReader> m_hReaderNested; 00253 00254 /** 00255 * The property index of the property from which the currently open 00256 * nested reader is reading from. 00257 */ 00258 int32_t m_iNestedProp; 00259 }; 00260 00261 COH_CLOSE_NAMESPACE3 00262 00263 #endif // COH_USER_TYPE_READER_HPP