Oracle Coherence for C++ API
Release 3.6.0.0

E15728-01

coherence/io/pof/SimplePofContext.hpp

00001 /*
00002 * SimplePofContext.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_SIMPLE_POF_CONTEXT_HPP
00017 #define COH_SIMPLE_POF_CONTEXT_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/io/ReadBuffer.hpp"
00022 #include "coherence/io/WriteBuffer.hpp"
00023 #include "coherence/io/pof/PofContext.hpp"
00024 #include "coherence/io/pof/PofSerializer.hpp"
00025 #include "coherence/io/pof/PortableObjectSerializer.hpp"
00026 #include "coherence/io/pof/TypedSerializer.hpp"
00027 #include "coherence/util/LongArray.hpp"
00028 #include "coherence/util/Map.hpp"
00029 #include "coherence/util/ThreadGate.hpp"
00030 
00031 COH_OPEN_NAMESPACE3(coherence,io,pof)
00032 
00033 using coherence::io::ReadBuffer;
00034 using coherence::io::WriteBuffer;
00035 using coherence::util::LongArray;
00036 using coherence::util::Map;
00037 using coherence::util::ThreadGate;
00038 
00039 
00040 /**
00041 * Basic PofContext implementation.
00042 *
00043 * @author gm  2008.10.24
00044 *
00045 * @see PortableObjectSerializer
00046 */
00047 class COH_EXPORT SimplePofContext
00048     : public class_spec<SimplePofContext,
00049         extends<Object>,
00050         implements<PofContext> >
00051     {
00052     friend class factory<SimplePofContext>;
00053 
00054     // ----- constructors ---------------------------------------------------
00055 
00056     protected:
00057         /**
00058         * @internal
00059         */
00060         SimplePofContext();
00061 
00062 
00063     // ----- SimplePofContext interface -------------------------------------
00064 
00065     public:
00066         /**
00067         * Associate a user type with a type identifier and
00068         * {@link PofSerializer}.
00069         *
00070         * @param nTypeId      the type identifier of the specified user type;
00071         *                     must be greater or equal to 0
00072         * @param vClass       the user type to register with this PofContext;
00073         *                     must not be NULL
00074         * @param vSerializer  the PofSerializer that will be used to
00075         *                     serialize and deserialize objects of the
00076         *                     specified class; must not be NULL
00077         *
00078         * @throws coherence::lang::IllegalArgumentException on invalid type
00079         *         identifer, class, or PofSerializer
00080         */
00081         virtual void registerUserType(int32_t nTypeId, Class::View vClass,
00082                 PofSerializer::View vSerializer);
00083 
00084         /**
00085         * Unregister a user type previously registered using the specified
00086         * type identifier.
00087         *
00088         * @param nTypeId  the type identifier of the user type to unregister
00089         *
00090         * @throws coherence::lang::IllegalArgumentException  if the specified
00091         *         user type identifier is unknown to this PofContext
00092         */
00093         virtual void unregisterUserType(int32_t nTypeId);
00094 
00095 
00096     // ----- PofContext interface -------------------------------------------
00097 
00098     public:
00099         /**
00100         * {@inheritDoc}
00101         */
00102         virtual PofSerializer::View getPofSerializer(int32_t nTypeId) const;
00103 
00104         /**
00105         * {@inheritDoc}
00106         */
00107         virtual int32_t getUserTypeIdentifier(Object::View v) const;
00108 
00109         /**
00110         * {@inheritDoc}
00111         */
00112         virtual int32_t getUserTypeIdentifier(Class::View vClass) const;
00113 
00114         /**
00115         * {@inheritDoc}
00116         */
00117         virtual int32_t getUserTypeIdentifier(String::View vsClass) const;
00118 
00119         /**
00120         * {@inheritDoc}
00121         */
00122         virtual String::View getClassName(int32_t nTypeId) const;
00123 
00124         /**
00125         * {@inheritDoc}
00126         */
00127         virtual Class::View getClass(int32_t nTypeId) const;
00128 
00129         /**
00130         * {@inheritDoc}
00131         */
00132         virtual bool isUserType(Object::View v) const;
00133 
00134         /**
00135         * {@inheritDoc}
00136         */
00137         virtual bool isUserType(Class::View vClass) const;
00138 
00139         /**
00140         * {@inheritDoc}
00141         */
00142         virtual bool isUserType(String::View vsClass) const;
00143 
00144 
00145     // ----- Serializer interface -------------------------------------------
00146 
00147     public:
00148         /**
00149         * {@inheritDoc}
00150         */
00151         virtual void serialize(WriteBuffer::BufferOutput::Handle hOut,
00152                 Object::View v) const;
00153 
00154         /**
00155         * {@inheritDoc}
00156         */
00157         virtual Object::Holder deserialize(
00158                 ReadBuffer::BufferInput::Handle hIn) const;
00159 
00160 
00161     // ----- Object interface -----------------------------------------------
00162 
00163     public:
00164         /**
00165         * {@inheritDoc}
00166         */
00167         virtual void toStream(std::ostream& out) const;
00168 
00169 
00170     // ----- internal methods -----------------------------------------------
00171 
00172     protected:
00173         /**
00174         * Ensure that the given user type identifier is valid.
00175         *
00176         * @param nTypeId  the user type identifier to validate
00177         *
00178         * @throws coherence::lang::IllegalArgumentException if the given user
00179         *         type identifier is negative
00180         */
00181         virtual void validateTypeId(int32_t nTypeId) const;
00182 
00183 
00184     // ----- data members ---------------------------------------------------
00185 
00186     protected:
00187         /**
00188         * A LongArray of user types, indexed by type identifier.
00189         */
00190         FinalHandle<LongArray> m_hlaClass;
00191 
00192         /**
00193         * A LongArray of PofSerializer objects, indexed by type identifier.
00194         */
00195         FinalHandle<LongArray> m_hlaSerializer;
00196 
00197         /**
00198         * A Map that contains mappings from a registered class name to type
00199         * identifier.
00200         */
00201         FinalHandle<Map> m_hMapClassName;
00202 
00203         /**
00204         * ThreadGate used to synchronize access to this PofContext.
00205         */
00206         mutable FinalHandle<ThreadGate> m_hGate;
00207     };
00208 
00209 COH_CLOSE_NAMESPACE3
00210 
00211 #endif // COH_SIMPLE_POF_CONTEXT_HPP
Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.