00001 /* 00002 * Class.hpp 00003 * 00004 * Copyright (c) 2000, 2014, 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_CLASS_HPP 00017 #define COH_CLASS_HPP 00018 00019 #include "coherence/lang/compatibility.hpp" 00020 00021 #include "coherence/lang/abstract_spec.hpp" 00022 #include "coherence/lang/AnnotatedElement.hpp" 00023 #include "coherence/lang/FinalView.hpp" 00024 #include "coherence/lang/FinalHandle.hpp" 00025 #include "coherence/lang/Method.hpp" 00026 #include "coherence/lang/Object.hpp" 00027 #include "coherence/lang/ObjectArray.hpp" 00028 #include "coherence/lang/String.hpp" 00029 00030 #include <ostream> 00031 #include <typeinfo> 00032 00033 COH_OPEN_NAMESPACE2(coherence,lang) 00034 00035 00036 /** 00037 * A Class represents a managed object implementation. 00038 * 00039 * Not all managed classes may have a corresponding Class representation. 00040 * Classes are referred to via their demangled RTTI name, for example 00041 * coherence::lang::Object. 00042 * 00043 * Classes can be loaded by name via a ClassLoader. 00044 * 00045 * @see ClassLoader 00046 * 00047 * @author mf 2008.04.03 00048 */ 00049 class COH_EXPORT Class 00050 : public abstract_spec<Class, 00051 extends<AnnotatedElement> > 00052 { 00053 // ----- constructors --------------------------------------------------- 00054 00055 protected: 00056 /** 00057 * Construct a class based on a C++ type_info. 00058 * 00059 * @param info the type_info for the class represented by this Class. 00060 */ 00061 Class(const std::type_info& info); 00062 00063 private: 00064 /** 00065 * Blocked copy constructor 00066 */ 00067 Class(const Class&); 00068 00069 00070 // ----- Class interface ------------------------------------------------ 00071 00072 public: 00073 /** 00074 * Return the name of the class. 00075 * 00076 * @return the class name 00077 */ 00078 virtual String::View getName() const; 00079 00080 /** 00081 * Create a new instance of the corresponding type. 00082 * 00083 * @param vaParam the object's initialization parameters 00084 * 00085 * @return a new instance of the corresponding type 00086 */ 00087 virtual Object::Handle newInstance(ObjectArray::View vaParam = NULL) const; 00088 00089 /** 00090 * Return the typeinfo for the corresponding type. 00091 * 00092 * @return the typeinfo for the corresponding type 00093 */ 00094 virtual const std::type_info& getTypeInfo() const = 0; 00095 00096 /** 00097 * Return the shallow size for an instance of the class represented 00098 * by this Class. 00099 * 00100 * @return the shallow size of an instance of the represented class. 00101 */ 00102 virtual size32_t getSize() const = 0; 00103 00104 /** 00105 * Return whether the passed in Object is an instance of class represented 00106 * by this Class. 00107 * 00108 * @param v the object to test 00109 * 00110 * @return whether the passed in Object is an instance of class represented 00111 * by this Class. 00112 * 00113 * @since Coherence 3.7 00114 */ 00115 virtual bool isInstance(Object::View v) const = 0; 00116 00117 /** 00118 * Return true if the class represented by this object is the same 00119 * Class or a super class or super interface of the specified class. 00120 * 00121 * @param vClass the class to test 00122 * 00123 * @return true if the specified class "extends" the class represented 00124 * by this object. 00125 */ 00126 virtual bool isAssignableFrom(Class::View vClass) const = 0; 00127 00128 /** 00129 * Register a method with this class. 00130 * 00131 * @param vMethod the method to register 00132 * 00133 * @since Coherence 3.7.1 00134 */ 00135 virtual Class::Handle declare(Method::View vMethod); 00136 00137 /** 00138 * Return the declared method of the specified name and parameters. 00139 * 00140 * The method is supplied with an array of either parameters or 00141 * parameter types expressed as Class::View objects. If non-Class 00142 * objects are provided then this method will search for a Method 00143 * which can accept those parameters directly. If Class objects are 00144 * provided then this method will search for a Method which takes 00145 * the specified type, or a superclass. 00146 * 00147 * @param vsName the method name 00148 * @param vaParams the method parameters or types 00149 * @param nMod the modifiers to match 00150 * @param fThrow false to return NULL rather then throw on failure 00151 * 00152 * @return the Method 00153 * 00154 * @throw NoSuchMethodException if the method is not found and fThrow == true 00155 * 00156 * @since Coherence 3.7.1 00157 */ 00158 virtual Method::View getDeclaredMethod(String::View vsName, 00159 ObjectArray::View vaParams = NULL, int32_t nMod = 0, 00160 bool fThrow = true) const; 00161 00162 /** 00163 * Return an array containing all the Methods declared on this Class. 00164 * 00165 * @return the declared methods 00166 * 00167 * @since Coherence 3.7.1 00168 */ 00169 virtual ObjectArray::View getDeclaredMethods() const; 00170 00171 /** 00172 * Return the method of the specified name and parameters which is 00173 * either declared or inherited by this class. 00174 * 00175 * The method is supplied with an array of either parameters or 00176 * parameter types expressed as Class::View objects. If non-Class 00177 * objects are provided then this method will search for a Method 00178 * which can accept those parameters directly. If Class objects are 00179 * provided then this method will search for a Method which takes 00180 * the specified type, or a superclass. 00181 * 00182 * @param vsName the method name 00183 * @param vaParams the method parameters or types 00184 * @param nMod the modifiers to match 00185 * @param fThrow false to return NULL rather then throw on failure 00186 * 00187 * @return the Method 00188 * 00189 * @throw NoSuchMethodException if the method is not found and fThrow == true 00190 * 00191 * @since Coherence 3.7.1 00192 */ 00193 virtual Method::View getMethod(String::View vsName, 00194 ObjectArray::View vaParams = NULL, int32_t nMod = 0, 00195 bool fThrow = true) const; 00196 00197 /** 00198 * Return an array containing all the Methods declared on and inherited 00199 * by this Class. 00200 * 00201 * @return the declared methods 00202 * 00203 * @since Coherence 3.7.1 00204 */ 00205 virtual ObjectArray::View getMethods() const; 00206 00207 /** 00208 * Return the superclass of this class, or NULL if this class an 00209 * interface or top level class. 00210 * 00211 * @return the superclass 00212 * 00213 * @throws ClassNotFoundException if the superclass is not registered 00214 * 00215 * @since Coherence 3.7.1 00216 */ 00217 virtual Class::View getSuperclass() const = 0; 00218 00219 /** 00220 * Return an array of Class::View objects representing the interfaces 00221 * which the Class directly implements. 00222 * 00223 * Any interfaces not registered with the ClassLoader will be left 00224 * out of the array. 00225 * 00226 * @return the array of Class::Views representing the interfaces 00227 * 00228 * @since Coherence 3.7.1 00229 */ 00230 virtual ObjectArray::View getInterfaces() const = 0; 00231 00232 /** 00233 * Add the specified Annotation to the element. 00234 * 00235 * @param vAnnontation the annotation 00236 * 00237 * @return this object 00238 */ 00239 virtual Class::Handle annotate(Annotation::View vAnnontation); 00240 00241 00242 // ----- AnnotatedElement interface ------------------------------------- 00243 00244 public: 00245 /** 00246 * {@inheritDoc} 00247 */ 00248 virtual AnnotatedElement::View getSuperelement() const; 00249 00250 00251 // ----- Object interface ----------------------------------------------- 00252 00253 public: 00254 /** 00255 * {@inheritDoc} 00256 */ 00257 virtual bool equals(Object::View that) const; 00258 00259 /** 00260 * {@inheritDoc} 00261 */ 00262 virtual size32_t hashCode() const; 00263 00264 00265 // ----- static helpers ------------------------------------------------- 00266 00267 public: 00268 /** 00269 * Return the class name of the supplied Object. 00270 * 00271 * @param v the object instance for which to obtain the class name 00272 * 00273 * @return the class name of the supplied Object 00274 */ 00275 static String::View getClassName(Object::View v); 00276 00277 /** 00278 * Return the type name of the supplied Object. 00279 * 00280 * @param info the type id for which to obtain the type name 00281 * 00282 * @return the type name of the supplied type 00283 */ 00284 static String::View getTypeName(const std::type_info& info); 00285 00286 00287 // ----- data members --------------------------------------------------- 00288 00289 private: 00290 /** 00291 * The class name. 00292 */ 00293 FinalView<String> f_vsName; 00294 00295 /** 00296 * Reference to a Map of method names to a List of Method objects. 00297 */ 00298 MemberHandle<Object> m_hMapMethods; 00299 }; 00300 00301 COH_CLOSE_NAMESPACE2 00302 00303 #endif // COH_CLASS_HPP