00001 /* 00002 * UserTypeWriter.hpp 00003 * 00004 * Copyright (c) 2000, 2019, 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_WRITER_HPP 00017 #define COH_USER_TYPE_WRITER_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include "coherence/io/WriteBuffer.hpp" 00022 #include "coherence/io/pof/PofBufferWriter.hpp" 00023 #include "coherence/io/pof/PofContext.hpp" 00024 #include "coherence/io/pof/WritingPofHandler.hpp" 00025 #include "coherence/util/Binary.hpp" 00026 00027 COH_OPEN_NAMESPACE3(coherence,io,pof) 00028 00029 using coherence::io::WriteBuffer; 00030 using coherence::util::Binary; 00031 00032 00033 /** 00034 * The UserTypeWriter implementation is a contextually-aware PofWriter whose 00035 * purpose is to write the properties of a value of a specified user type. The 00036 * "contextual awareness" refers to the fact that the UserTypeWriter maintains 00037 * state about the type identifier, the PofWriter's property index position 00038 * within the user type value, and a PofContext that may differ from the 00039 * PofContext that provided the PofSerializer which is using this 00040 * UserTypeWriter to serialize a user type. 00041 * 00042 * @author jh 2008.04.11 00043 */ 00044 class COH_EXPORT UserTypeWriter 00045 : public class_spec<UserTypeWriter, 00046 extends<PofBufferWriter> > 00047 { 00048 friend class factory<UserTypeWriter>; 00049 friend class PofBufferWriter; 00050 00051 // ----- constructors --------------------------------------------------- 00052 00053 public: 00054 /** 00055 * Construct a UserTypeWriter for writing the property values of a 00056 * user type. 00057 * 00058 * @param hOut the BufferOutput object to write to; must not be 00059 * NULL 00060 * @param vCtx the PofContext to use for writing the user type 00061 * property values within the user type that this 00062 * writer will be writing 00063 * @param nTypeId the type identifier of the user type; must be 00064 * non-negative 00065 * @param iProp the index of the user type being written 00066 */ 00067 UserTypeWriter(WriteBuffer::BufferOutput::Handle hOut, 00068 PofContext::View vCtx, int32_t nTypeId, int32_t iProp); 00069 00070 /** 00071 * Construct a UserTypeWriter for writing the property values of a 00072 * user type. 00073 * 00074 * @param hParent the containing PofBufferWriter 00075 * @param hOut the BufferOutput object to write to; must not be 00076 * null 00077 * @param vCtx the PofContext to use for writing the user type 00078 * property values within the user type that this 00079 * writer will be writing 00080 * @param nTypeId the type identifier of the user type; must be 00081 * non-negative 00082 * @param iProp the index of the user type being written 00083 */ 00084 UserTypeWriter(PofBufferWriter::Handle hParent, 00085 WriteBuffer::BufferOutput::Handle hOut, 00086 PofContext::View vCtx, int32_t nTypeId, int32_t iProp); 00087 00088 /** 00089 * Construct a UserTypeWriter for writing the property values of a 00090 * user type. 00091 * 00092 * @param hHandler the WritingPofHandler used to write user type data 00093 * (except for the user type id itself, which is 00094 * passed as a constructor argument) 00095 * @param vCtx the PofContext to use for writing the user type 00096 * property values within the user type that this 00097 * writer will be writing 00098 * @param nTypeId the type identifier of the user type; must be 00099 * non-negative 00100 * @param iProp the index of the user type being written 00101 */ 00102 UserTypeWriter(WritingPofHandler::Handle hHandler, 00103 PofContext::View vCtx, int32_t nTypeId, int32_t iProp); 00104 00105 /** 00106 * Construct a UserTypeWriter for writing the property values of a 00107 * user type. 00108 * 00109 * @param hParent the containing PofBufferWriter 00110 * @param hHandle the WritingPofHandler used to write user type data 00111 * (except for the user type id itself, which is 00112 * passed as a constructor argument) 00113 * @param vCtx the PofContext to use for writing the user type 00114 * property values within the user type that this 00115 * writer will be writing 00116 * @param nTypeId the type identifier of the user type; must be 00117 * non-negative 00118 * @param iProp the index of the user type being written 00119 * @param nId the identity of the object to encode, or -1 if the 00120 * identity shouldn't be encoded in the POF stream 00121 */ 00122 UserTypeWriter(PofBufferWriter::Handle hParent, 00123 WritingPofHandler::Handle hHandler, 00124 PofContext::View vCtx, int nTypeId, int iProp, int nId=-1); 00125 00126 00127 // ----- PofWriter interface -------------------------------------------- 00128 00129 public: 00130 /** 00131 * {@inheritDoc} 00132 */ 00133 virtual void writeObject(int32_t iProp, Object::View v); 00134 00135 /** 00136 * {@inheritDoc} 00137 */ 00138 virtual int32_t getUserTypeId() const; 00139 00140 /** 00141 * {@inheritDoc} 00142 */ 00143 virtual int32_t getVersionId() const; 00144 00145 /** 00146 * {@inheritDoc} 00147 */ 00148 virtual void setVersionId(int32_t nVersionId); 00149 00150 /** 00151 * {@inheritDoc} 00152 */ 00153 virtual PofWriter::Handle createNestedPofWriter(int32_t iProp); 00154 00155 /** 00156 * {@inheritDoc} 00157 */ 00158 virtual PofWriter::Handle createNestedPofWriter(int32_t iProp, int32_t nTypeId); 00159 00160 /** 00161 * {@inheritDoc} 00162 */ 00163 virtual void writeRemainder(Binary::View vBinProps); 00164 00165 00166 // ----- internal methods ----------------------------------------------- 00167 00168 protected: 00169 /** 00170 * {@inheritDoc} 00171 */ 00172 virtual PofBufferWriter::Handle getParentWriter(); 00173 00174 /** 00175 * {@inheritDoc} 00176 */ 00177 virtual PofBufferWriter::View getParentWriter() const; 00178 00179 /** 00180 * {@inheritDoc} 00181 */ 00182 virtual void beginProperty(int32_t iProp); 00183 00184 /** 00185 * {@inheritDoc} 00186 */ 00187 virtual void endProperty(int32_t iProp); 00188 00189 /** 00190 * Notify the UserTypeWriter that it is being "closed". This 00191 * notification allows the UserTypeWriter to write any remaining data 00192 * that it has pending to write. 00193 */ 00194 virtual void closeNested(); 00195 00196 /** 00197 * Write out the type and version identifiers of the user type to the 00198 * POF stream, if they haven't already been written. 00199 * 00200 * @throws IOException on I/O error 00201 */ 00202 virtual void writeUserTypeInfo(); 00203 00204 /** 00205 * {@inheritDoc} 00206 */ 00207 virtual bool isEvolvable(); 00208 00209 00210 // ----- accessors ------------------------------------------------------ 00211 00212 public: 00213 /** 00214 * {@inheritDoc} 00215 */ 00216 virtual void enableReference(); 00217 00218 00219 // ----- data members --------------------------------------------------- 00220 00221 protected: 00222 /** 00223 * The parent (ie containing) PofBufferWriter. 00224 */ 00225 FinalHandle<PofBufferWriter> f_hWriterParent; 00226 00227 /** 00228 * The type identifier of the user type that is being written. 00229 */ 00230 const int32_t m_nTypeId; 00231 00232 /** 00233 * The version identifier of the user type that is being written. 00234 */ 00235 int32_t m_nVersionId; 00236 00237 /** 00238 * The index of the user type being written. 00239 */ 00240 const int32_t m_iProp; 00241 00242 /** 00243 * The identity of the object to encode, or -1 if the identity 00244 * shouldn't be encoded in the POF stream 00245 */ 00246 int32_t m_nId; 00247 00248 /** 00249 * The index of the last property written to the POF stream or -1 if 00250 * the first property has yet to be written. 00251 */ 00252 int32_t m_iPrevProp; 00253 00254 /** 00255 * True iff the type and version identifier of the user type was 00256 * written to the POF stream. 00257 */ 00258 bool m_fUserTypeBegin; 00259 00260 /** 00261 * True iff the user type was written to the POF stream. 00262 */ 00263 bool m_fUserTypeEnd; 00264 00265 /** 00266 * The Complex value that corresponds to the user type that is being 00267 * written. 00268 */ 00269 MemberHandle<WritingPofHandler::Complex> m_hComplex; 00270 00271 /** 00272 * The ID of the Complex value that corresponds to the user type that is being 00273 * written. 00274 */ 00275 size64_t m_nComplexId; 00276 00277 /** 00278 * The currently open nested writer, if any. 00279 */ 00280 MemberHandle<UserTypeWriter> m_hWriterNested; 00281 }; 00282 00283 COH_CLOSE_NAMESPACE3 00284 00285 #endif // COH_USER_TYPE_WRITER_HPP