Oracle Coherence for C++ API
Release 3.6.1.0
E18813-01

- Main Page
- Namespaces
- Classes
- Files

# coherence/lang/SystemClassLoader.hpp

    00001 /*
    00002 * SystemClassLoader.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_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/ObjectArray.hpp"
    00024 #include "coherence/lang/TypedClass.hpp"
    00025 #include "coherence/lang/TypedExecutableClass.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
    00125 // ----- helper macros ------------------------------------------------------
    00126
    00127 /**
    00128 * Register a Class with the system class loader.
    00129 *
    00130 * @param CLASS the Class object to register
    00131 */
    00132 #define COH_REGISTER_CLASS(CLASS) \
    00133     COH_STATIC_INIT(coherence::lang::SystemClassLoader::getInstance()-> \
    00134             registerClass(CLASS))
    00135
    00136 /**
    00137 * Register a TypedClass with the system class loader.
    00138 *
    00139 * @param TYPE the class type to register, i.e. coherence::lang::Object
    00140 */
    00141 #define COH_REGISTER_TYPED_CLASS(TYPE) \
    00142     COH_REGISTER_CLASS(coherence::lang::TypedClass<TYPE >::create())
    00143
    00144 /**
    00145 * Register a TypedExecutableClass with the system class loader.
    00146 *
    00147 * @param TYPE the class type to register, i.e. coherence::lang::Object
    00148 */
    00149 #define COH_REGISTER_EXECUTABLE_CLASS(TYPE) \
    00150     COH_REGISTER_CLASS((coherence::lang::TypedExecutableClass<TYPE, \
    00151             coherence::lang::TypedClass<TYPE> >::create()))
    00152
    00153 COH_CLOSE_NAMESPACE2
    00154
    00155 #endif // COH_SYSTEM_CLASS_LOADER_HPP

Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.