Oracle Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.1.2)

E26041-01

coherence/lang/SystemClassLoader.hpp

00001 /*
00002 * SystemClassLoader.hpp
00003 *
00004 * Copyright (c) 2000, 2013, 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_CLASS_LOADER_HPP
00017 #define COH_SYSTEM_CLASS_LOADER_HPP
00018 
00019 #include "coherence/lang/compatibility.hpp"
00020 
00021 #include "coherence/lang/Class.hpp"
00022 #include "coherence/lang/ClassLoader.hpp"
00023 #include "coherence/lang/FinalHandle.hpp"
00024 #include "coherence/lang/ObjectArray.hpp"
00025 #include "coherence/lang/System.hpp"
00026 
00027 COH_OPEN_NAMESPACE2(coherence,lang)
00028 
00029 
00030 /**
00031 * SystemClassLoader is a ClassLoader implementation based on registration
00032 * only.  That is it does not "load" any classes, it only knows about those
00033 * which have been registered with it.
00034 *
00035 * @author mf  2008.04.03
00036 */
00037 class COH_EXPORT SystemClassLoader
00038     : public class_spec<SystemClassLoader,
00039         extends<Object>,
00040         implements<ClassLoader> >
00041     {
00042     friend class factory<SystemClassLoader>;
00043 
00044     // ----- constructors ---------------------------------------------------
00045 
00046     protected:
00047         /**
00048         * @internal
00049         */
00050         using this_spec::create;
00051 
00052     private:
00053         /**
00054         * @internal
00055         */
00056         SystemClassLoader();
00057 
00058 
00059     // ----- SystemClassLoader interface ------------------------------------
00060 
00061     public:
00062         /**
00063         * Register a class with the SystemClassLoader.
00064         *
00065         * @param vClass the Class to register
00066         *
00067         * @return the registered class
00068         *
00069         * @throws IllegalArgumentException if a Class of the same name has
00070         *         already been registered
00071         */
00072         virtual Class::View registerClass(Class::View vClass);
00073 
00074 
00075     // ----- ClassLoader interface ------------------------------------------
00076 
00077     public:
00078         /**
00079         * {@inheritDoc}
00080         */
00081         virtual Class::View loadByName(String::View vsName) const;
00082 
00083         /**
00084         * {@inheritDoc}
00085         */
00086         virtual Class::View loadByType(const std::type_info& info) const;
00087 
00088         /**
00089         * @return NULL
00090         */
00091         virtual ClassLoader::Handle getParent() const;
00092 
00093 
00094     // ----- Object interface -----------------------------------------------
00095 
00096     public:
00097         /**
00098         * {@inheritDoc}
00099         */
00100         void toStream(std::ostream& out) const;
00101 
00102 
00103     // ----- static methods -------------------------------------------------
00104 
00105     public:
00106         /**
00107         * Return the SystemClassLoader singleton.
00108         *
00109         * @return the SystemClassLoader
00110         */
00111         static SystemClassLoader::Handle getInstance();
00112 
00113         /**
00114         * Executable entrypoint for the SystemClassLoader class.
00115         *
00116         * Print the loaded classes.
00117         *
00118         * @param vasArg  a list of libraries to load, and print their
00119         *                registered classes.
00120         */
00121         static void main(ObjectArray::View vasArg);
00122     };
00123 
00124 COH_CLOSE_NAMESPACE2
00125 
00126 
00127 // ----- helper macros ------------------------------------------------------
00128 
00129 #include "coherence/lang/TypedClass.hpp"
00130 #include "coherence/lang/TypedExecutableClass.hpp"
00131 
00132 
00133 /**
00134 * Register a Class with the system class loader.
00135 *
00136 * @param CLASS the Class object to register
00137 */
00138 #define COH_REGISTER_CLASS(CLASS) \
00139     COH_STATIC_INIT(coherence::lang::SystemClassLoader::getInstance()-> \
00140             registerClass(CLASS))
00141 
00142 /**
00143  * Register a Class with the system class loader, and make it locally
00144  * referenceable within this file by the specified name.
00145  */
00146 #define COH_REGISTER_NAMED_CLASS(NAME, CLASS) \
00147         static coherence::lang::FinalHandle<coherence::lang::Class> s_coh_static_class_##NAME \
00148             (coherence::lang::System::common(), CLASS); \
00149         COH_REGISTER_CLASS(s_coh_static_class_##NAME)
00150 
00151 /**
00152 * Register a TypedClass with the system class loader.
00153 *
00154 * @param TYPE the class type to register, i.e. coherence::lang::Object
00155 */
00156 #define COH_REGISTER_TYPED_CLASS(TYPE) \
00157     COH_REGISTER_NAMED_CLASS(TYPE, coherence::lang::TypedClass<TYPE >::create())
00158 
00159 /**
00160 * Register a TypedExecutableClass with the system class loader.
00161 *
00162 * @param TYPE the class type to register, i.e. coherence::lang::Object
00163 */
00164 #define COH_REGISTER_EXECUTABLE_CLASS(TYPE) \
00165     COH_REGISTER_NAMED_CLASS(TYPE, (coherence::lang::TypedExecutableClass<TYPE, \
00166             coherence::lang::TypedClass<TYPE > >::create()))
00167 
00168 /**
00169  * Register a method on a locally registered class.
00170  *
00171  * This macro is only available in the context of the file which registered
00172  * the specified class.  The class must have been registered either by its
00173  * type or explicitly via COH_REGISTER_NAMED_CLASS.
00174  *
00175  * @param NAME    the type of the locally defined class
00176  * @param METHOD  the method to add
00177  */
00178 #define COH_REGISTER_METHOD(NAME, METHOD) \
00179     COH_STATIC_INIT(s_coh_static_class_##NAME->declare(METHOD))
00180 
00181 #endif // COH_SYSTEM_CLASS_LOADER_HPP
Copyright © 2000, 2013, Oracle and/or its affiliates. All rights reserved.