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