00001 /* 00002 * UserTypeReader.hpp 00003 * 00004 * Copyright (c) 2000, 2014, 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 public: 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 protected: 00163 /** 00164 * {@inheritDoc} 00165 */ 00166 virtual bool advanceTo(int32_t iProp); 00167 00168 /** 00169 * {@inheritDoc} 00170 */ 00171 virtual void complete(int32_t iProp); 00172 00173 /** 00174 * Notify the UserTypeReader that it is being "closed". 00175 * 00176 * @throws IOException if an I/O error occurs 00177 */ 00178 virtual void closeNested(); 00179 00180 /** 00181 * {@inheritDoc} 00182 */ 00183 virtual PofBufferReader::Handle getParentParser(); 00184 00185 /** 00186 * {@inheritDoc} 00187 */ 00188 virtual PofBufferReader::View getParentParser() const; 00189 00190 00191 // ----- data members --------------------------------------------------- 00192 00193 protected: 00194 /** 00195 * The parent (ie containing) PofBufferReader. 00196 */ 00197 FinalHandle<PofBufferReader> f_hParent; 00198 00199 /** 00200 * The type identifier of the user type that is being parsed. 00201 */ 00202 int32_t m_nTypeId; 00203 00204 /** 00205 * The version identifier of the user type that is being parsed. 00206 */ 00207 int32_t m_nVersionId; 00208 00209 /** 00210 * Most recent property read or (if it were missing) requested. This 00211 * is used to determine if the client is attempting to read properties 00212 * in the wrong order. 00213 */ 00214 int32_t m_iPrevProp; 00215 00216 /** 00217 * The index of the next property in the POF stream. 00218 */ 00219 int32_t m_iNextProp; 00220 00221 /** 00222 * The offset of the index of the next property to read. 00223 */ 00224 size32_t m_ofNextProp; 00225 00226 /** 00227 * The currently open nested reader, if any. 00228 */ 00229 MemberHandle<UserTypeReader> m_hReaderNested; 00230 00231 /** 00232 * The property index of the property from which the currently open 00233 * nested reader is reading from. 00234 */ 00235 int32_t m_iNestedProp; 00236 }; 00237 00238 COH_CLOSE_NAMESPACE3 00239 00240 #endif // COH_USER_TYPE_READER_HPP