00001 /* 00002 * Class.hpp 00003 * 00004 * Copyright (c) 2000, 2017, 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 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 * Returns the simple name of the underlying class as given in the 00082 * source code. 00083 * 00084 * If a simple name cannot be determined, the full name from 00085 * getName() will be returned. 00086 * 00087 * @return the simple name of the underlying class 00088 * 00089 * @since 12.2.1.3 00090 */ 00091 virtual String::View getSimpleName() const; 00092 00093 /** 00094 * Create a new instance of the corresponding type. 00095 * 00096 * @param vaParam the object's initialization parameters 00097 * 00098 * @return a new instance of the corresponding type 00099 */ 00100 virtual Object::Handle newInstance(ObjectArray::View vaParam = NULL) const; 00101 00102 /** 00103 * Return the typeinfo for the corresponding type. 00104 * 00105 * @return the typeinfo for the corresponding type 00106 */ 00107 virtual const std::type_info& getTypeInfo() const = 0; 00108 00109 /** 00110 * Return the shallow size for an instance of the class represented 00111 * by this Class. 00112 * 00113 * @return the shallow size of an instance of the represented class. 00114 */ 00115 virtual size32_t getSize() const = 0; 00116 00117 /** 00118 * Return whether the passed in Object is an instance of class represented 00119 * by this Class. 00120 * 00121 * @param v the object to test 00122 * 00123 * @return whether the passed in Object is an instance of class represented 00124 * by this Class. 00125 * 00126 * @since Coherence 3.7 00127 */ 00128 virtual bool isInstance(Object::View v) const = 0; 00129 00130 /** 00131 * Return true if the class represented by this object is the same 00132 * Class or a super class or super interface of the specified class. 00133 * 00134 * @param vClass the class to test 00135 * 00136 * @return true if the specified class "extends" the class represented 00137 * by this object. 00138 */ 00139 virtual bool isAssignableFrom(Class::View vClass) const = 0; 00140 00141 /** 00142 * Register a method with this class. 00143 * 00144 * @param vMethod the method to register 00145 * 00146 * @since Coherence 3.7.1 00147 */ 00148 virtual Class::Handle declare(Method::View vMethod); 00149 00150 /** 00151 * Return the declared method of the specified name and parameters. 00152 * 00153 * The method is supplied with an array of either parameters or 00154 * parameter types expressed as Class::View objects. If non-Class 00155 * objects are provided then this method will search for a Method 00156 * which can accept those parameters directly. If Class objects are 00157 * provided then this method will search for a Method which takes 00158 * the specified type, or a superclass. 00159 * 00160 * @param vsName the method name 00161 * @param vaParams the method parameters or types 00162 * @param nMod the modifiers to match 00163 * @param fThrow false to return NULL rather then throw on failure 00164 * 00165 * @return the Method 00166 * 00167 * @throw NoSuchMethodException if the method is not found and fThrow == true 00168 * 00169 * @since Coherence 3.7.1 00170 */ 00171 virtual Method::View getDeclaredMethod(String::View vsName, 00172 ObjectArray::View vaParams = NULL, int32_t nMod = 0, 00173 bool fThrow = true) const; 00174 00175 /** 00176 * Return an array containing all the Methods declared on this Class. 00177 * 00178 * @return the declared methods 00179 * 00180 * @since Coherence 3.7.1 00181 */ 00182 virtual ObjectArray::View getDeclaredMethods() const; 00183 00184 /** 00185 * Return the method of the specified name and parameters which is 00186 * either declared or inherited by this class. 00187 * 00188 * The method is supplied with an array of either parameters or 00189 * parameter types expressed as Class::View objects. If non-Class 00190 * objects are provided then this method will search for a Method 00191 * which can accept those parameters directly. If Class objects are 00192 * provided then this method will search for a Method which takes 00193 * the specified type, or a superclass. 00194 * 00195 * @param vsName the method name 00196 * @param vaParams the method parameters or types 00197 * @param nMod the modifiers to match 00198 * @param fThrow false to return NULL rather then throw on failure 00199 * 00200 * @return the Method 00201 * 00202 * @throw NoSuchMethodException if the method is not found and fThrow == true 00203 * 00204 * @since Coherence 3.7.1 00205 */ 00206 virtual Method::View getMethod(String::View vsName, 00207 ObjectArray::View vaParams = NULL, int32_t nMod = 0, 00208 bool fThrow = true) const; 00209 00210 /** 00211 * Return an array containing all the Methods declared on and inherited 00212 * by this Class. 00213 * 00214 * @return the declared methods 00215 * 00216 * @since Coherence 3.7.1 00217 */ 00218 virtual ObjectArray::View getMethods() const; 00219 00220 /** 00221 * Return the superclass of this class, or NULL if this class an 00222 * interface or top level class. 00223 * 00224 * @return the superclass 00225 * 00226 * @throws ClassNotFoundException if the superclass is not registered 00227 * 00228 * @since Coherence 3.7.1 00229 */ 00230 virtual Class::View getSuperclass() const = 0; 00231 00232 /** 00233 * Return an array of Class::View objects representing the interfaces 00234 * which the Class directly implements. 00235 * 00236 * Any interfaces not registered with the ClassLoader will be left 00237 * out of the array. 00238 * 00239 * @return the array of Class::Views representing the interfaces 00240 * 00241 * @since Coherence 3.7.1 00242 */ 00243 virtual ObjectArray::View getInterfaces() const = 0; 00244 00245 /** 00246 * Add the specified Annotation to the element. 00247 * 00248 * @param vAnnontation the annotation 00249 * 00250 * @return this object 00251 */ 00252 virtual Class::Handle annotate(Annotation::View vAnnontation); 00253 00254 00255 // ----- AnnotatedElement interface ------------------------------------- 00256 00257 public: 00258 /** 00259 * {@inheritDoc} 00260 */ 00261 virtual AnnotatedElement::View getSuperelement() const; 00262 00263 00264 // ----- Object interface ----------------------------------------------- 00265 00266 public: 00267 /** 00268 * {@inheritDoc} 00269 */ 00270 virtual bool equals(Object::View that) const; 00271 00272 /** 00273 * {@inheritDoc} 00274 */ 00275 virtual size32_t hashCode() const; 00276 00277 00278 // ----- static helpers ------------------------------------------------- 00279 00280 public: 00281 /** 00282 * Return the class name of the supplied Object. 00283 * 00284 * @param v the object instance for which to obtain the class name 00285 * 00286 * @return the class name of the supplied Object 00287 */ 00288 static String::View getClassName(Object::View v); 00289 00290 /** 00291 * Returns the simple name of the underlying class of the 00292 * supplied Object as given in the code. 00293 * 00294 * If a simple name cannot be determined, the full name from 00295 * getClassName() will be returned. 00296 * 00297 * @param v the object instance for which to obtain the name 00298 * 00299 * @return the simple name of the underlying class 00300 * 00301 * @since 12.2.1.3 00302 */ 00303 static String::View getSimpleClassName(Object::View v); 00304 00305 /** 00306 * Returns the std::type_info for the supplied Object. 00307 * 00308 * @param v the object instance for which to obtain the type info 00309 * 00310 * @return the std::type_info for the supplied Object 00311 * 00312 * @since 12.2.1 00313 */ 00314 static const std::type_info& getTypeInfo(Object::View v); 00315 00316 /** 00317 * Return the type name of the supplied type id. 00318 * 00319 * @param info the type id for which to obtain the type name 00320 * 00321 * @return the type name of the supplied type 00322 */ 00323 static String::View getTypeName(const std::type_info& info); 00324 00325 /** 00326 * Returns the simple name of the underlying class of the 00327 * supplied type as given in the code. 00328 * 00329 * If a simple name cannot be determined, the full name from 00330 * getTypeInfo() will be returned. 00331 * 00332 * @param info the type id for which to obtain the name 00333 * 00334 * @return the simple name of the underlying class 00335 * 00336 * @since 12.2.1.3 00337 */ 00338 static String::View getSimpleTypeName(const std::type_info& info); 00339 00340 /** 00341 * Compare two Objects for type equality. 00342 * 00343 * @param v1 the first Object 00344 * @param v2 the second Object 00345 * 00346 * @return <tt>true</tt> iff v1 and v2 are the same type 00347 * 00348 * @since 12.2.1 00349 */ 00350 static bool typeEquals(Object::View v1, Object::View v2); 00351 00352 00353 // ----- data members --------------------------------------------------- 00354 00355 private: 00356 /** 00357 * The class name. 00358 */ 00359 FinalView<String> f_vsName; 00360 00361 /** 00362 * Reference to a Map of method names to a List of Method objects. 00363 */ 00364 MemberHandle<Object> m_hMapMethods; 00365 }; 00366 00367 COH_CLOSE_NAMESPACE2 00368 00369 #endif // COH_CLASS_HPP