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