Oracle Coherence for C++ API
Release 3.7.1.0

E22845-01

coherence/io/pof/SimplePofContext.hpp

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