Oracle Coherence for C++ API
Release 3.7.1.0

E22845-01

coherence/io/pof/SystemPofContext.hpp

00001 /*
00002 * SystemPofContext.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_SYSTEM_POF_CONTEXT_HPP
00017 #define COH_SYSTEM_POF_CONTEXT_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/io/pof/PofAnnotationSerializer.hpp"
00022 #include "coherence/io/pof/PortableObjectSerializer.hpp"
00023 #include "coherence/io/pof/SimplePofContext.hpp"
00024 #include "coherence/io/pof/TypedSerializer.hpp"
00025 
00026 COH_OPEN_NAMESPACE3(coherence,io,pof)
00027 
00028 
00029 /**
00030 * System-wide PofContext implementation that allows POF user types to
00031 * be registered programatically.
00032 *
00033 * @author jh  2008.02.21
00034 */
00035 class COH_EXPORT SystemPofContext
00036     : public class_spec<SystemPofContext,
00037         extends<SimplePofContext> >
00038     {
00039     friend class factory<SystemPofContext>;
00040 
00041     // ----- constructors ---------------------------------------------------
00042 
00043     protected:
00044         /**
00045         * @internal
00046         */
00047         using this_spec::create;
00048 
00049     private:
00050         /**
00051         * @internal
00052         */
00053         SystemPofContext();
00054 
00055 
00056     public:
00057         /**
00058         * Return the SystemPofContext singleton instance.
00059         *
00060         * @return the global SystemPofContext
00061         */
00062         static Handle getInstance();
00063 
00064         /**
00065         * Executable entrypoint for the SystemPofContext class.
00066         *
00067         * Print the POF registrations.
00068         *
00069         * @param vasArg  a list of libraries to load, and print their
00070         *                registered classes.
00071         */
00072         static void main(ObjectArray::View vasArg);
00073     };
00074 
00075 
00076 // ----- helper macros ------------------------------------------------------
00077 
00078 /**
00079 * Register a PofSerializer with the system PofContext. The call will also
00080 * register the class with the SystemClassLoader.
00081 *
00082 * @param POF_TYPE_ID     the POF type identifier
00083 * @param CLASS           the associated class to register
00084 * @param POF_SERIALIZER  the PofSerializer instance to register
00085 */
00086 #define COH_REGISTER_POF_SERIALIZER(POF_TYPE_ID, CLASS, POF_SERIALIZER) \
00087     COH_STATIC_INIT(coherence::io::pof::SystemPofContext::getInstance()-> \
00088         registerUserType(POF_TYPE_ID, \
00089             coherence::lang::SystemClassLoader::getInstance()-> \
00090             registerClass(CLASS), POF_SERIALIZER))
00091 
00092 
00093 /**
00094 * Register a PortableObject implementation only with the system PofContext.
00095 * The class must have already been registered with the SystemClassLoader.
00096 *
00097 * @param POF_TYPE_ID  the POF type identifier
00098 * @param TYPE         the class type to register
00099 */
00100 #define COH_REGISTER_ONLY_PORTABLE_CLASS(POF_TYPE_ID, TYPE) \
00101     COH_STATIC_INIT_EX(1, coherence::io::pof::SystemPofContext::getInstance()-> \
00102         registerUserType(POF_TYPE_ID, s_coh_static_class_##TYPE, \
00103         coherence::io::pof::PortableObjectSerializer::create(POF_TYPE_ID)))
00104 
00105 /**
00106 * Register a PortableObject implementation with the system ClassLoader and
00107 * PofContext.
00108 *
00109 * @param POF_TYPE_ID  the POF type identifier
00110 * @param TYPE         the class type to register
00111 */
00112 #define COH_REGISTER_PORTABLE_CLASS(POF_TYPE_ID, TYPE) \
00113     COH_REGISTER_TYPED_CLASS(TYPE); \
00114     COH_REGISTER_ONLY_PORTABLE_CLASS(POF_TYPE_ID, TYPE)
00115 
00116 /**
00117 * Register a Managed object implementation with the system ClassLoader and
00118 * PofContext.
00119 *
00120 * @param POF_TYPE_ID  the POF type identifier
00121 * @param TYPE         the class type to register
00122 */
00123 #define COH_REGISTER_MANAGED_CLASS(POF_TYPE_ID, TYPE) \
00124     COH_REGISTER_NAMED_CLASS(TYPE, \
00125         coherence::lang::TypedClass<coherence::lang::Managed<TYPE > >::create()); \
00126     COH_STATIC_INIT_EX(1, coherence::io::pof::SystemPofContext::getInstance()-> \
00127         registerUserType(POF_TYPE_ID, s_coh_static_class_##TYPE, \
00128         coherence::io::pof::TypedSerializer<coherence::lang::Managed<TYPE > >::create()))
00129 
00130 
00131 /**
00132 * Register an annotated class with the system ClassLoader and PofContext. The
00133 * Class (TYPE) must be registered with the SystemClassLoader, which is
00134 * assumed based on this being a pre-requisite to adding annotations, and have
00135 * a coherence::io::pof::Portable annotation present.
00136 *
00137 * @param POF_TYPE_ID  the POF type identifier
00138 * @param TYPE         the class type to register
00139 */
00140 #define COH_REGISTER_POF_ANNOTATED_CLASS(POF_TYPE_ID, TYPE)                 \
00141     COH_STATIC_INIT(coherence::io::pof::SystemPofContext::getInstance()->   \
00142         registerUserType(POF_TYPE_ID,                                       \
00143             coherence::lang::SystemClassLoader::getInstance()->             \
00144             loadByType(typeid(TYPE)),                                       \
00145             coherence::io::pof::PofAnnotationSerializer::create(POF_TYPE_ID,\
00146                        coherence::lang::SystemClassLoader::getInstance()->  \
00147                            loadByType(typeid(TYPE)))))                      \
00148 
00149 /**
00150 * Register an annotated class with the system ClassLoader and PofContext. The
00151 * Class (TYPE) must be registered with the SystemClassLoader, which is
00152 * assumed based on this being a pre-requisite to adding annotations, and have
00153 * a coherence::io::pof::Portable annotation present. This macro additionally
00154 * suggests to the serializer to determine portable property indexes.
00155 *
00156 * @param POF_TYPE_ID  the POF type identifier
00157 * @param TYPE         the class type to register
00158 */
00159 #define COH_REGISTER_POF_ANNOTATED_CLASS_AI(POF_TYPE_ID, TYPE)              \
00160     COH_STATIC_INIT(coherence::io::pof::SystemPofContext::getInstance()->   \
00161         registerUserType(POF_TYPE_ID,                                       \
00162             coherence::lang::SystemClassLoader::getInstance()->             \
00163             loadByType(typeid(TYPE)),                                       \
00164             coherence::io::pof::PofAnnotationSerializer::create(POF_TYPE_ID,\
00165                        coherence::lang::SystemClassLoader::getInstance()->  \
00166                            loadByType(typeid(TYPE)), true)))                \
00167 
00168 COH_CLOSE_NAMESPACE3
00169 
00170 #endif // COH_SYSTEM_POF_CONTEXT_HPP
Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.