00001 /* 00002 * Method.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_METHOD_HPP 00017 #define COH_METHOD_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/Object.hpp" 00024 #include "coherence/lang/ObjectArray.hpp" 00025 #include "coherence/lang/String.hpp" 00026 #include "coherence/lang/FinalView.hpp" 00027 00028 #include <ostream> 00029 00030 COH_OPEN_NAMESPACE2(coherence,lang) 00031 00032 // ---- forward declarations ------------------------------------------------ 00033 00034 class Class; 00035 00036 00037 /** 00038 * Method represents a method within a managed class. 00039 * 00040 * To be of general use these Methods must also be registered with the 00041 * corresponding Class object during Class registration. Once registered the 00042 * Method can be found at runtime as follows: 00043 * 00044 * @code 00045 * Method::View vMethodName = SystemClassLoader::getInstance() 00046 * ->loadByName("Person")->getMethod("getName"); 00047 * @endcode 00048 * 00049 * And then finally applied: 00050 * 00051 * @code 00052 * Object::View vo = getPersonFromSomewhere(); 00053 * std::cout << vMethodName->invoke(vo) << std::endl; 00054 * @endcode 00055 * 00056 * @author mf 2011.02.24 00057 * 00058 * @since Coherence 3.7.1 00059 * 00060 * @see TypedMethod for registration helpers and examples 00061 */ 00062 class COH_EXPORT Method 00063 : public abstract_spec<Method, 00064 extends<AnnotatedElement> > 00065 { 00066 public: 00067 /** 00068 * Forward declaration of Class::View. 00069 */ 00070 typedef TypedHandle<const Class> ClassView; 00071 00072 00073 // ----- constructors --------------------------------------------------- 00074 00075 protected: 00076 /** 00077 * Construct a Method of the specified name. 00078 */ 00079 Method(String::View vsName); 00080 00081 00082 // ----- Method interface ----------------------------------------------- 00083 00084 public: 00085 /** 00086 * Return the method name. 00087 */ 00088 virtual String::View getName() const; 00089 00090 /** 00091 * Return the method modifiers. 00092 * 00093 * @return the method modifiers 00094 */ 00095 virtual int32_t getModifiers() const = 0; 00096 00097 /** 00098 * Return an array of Class::Views representing the method parameter 00099 * types. 00100 * 00101 * @return the parameter types 00102 */ 00103 virtual ObjectArray::View getParameterTypes() const = 0; 00104 00105 /** 00106 * Return the Class::View representing the method's return type, or 00107 * NULL for void. 00108 * 00109 * @return the return type 00110 */ 00111 virtual ClassView getReturnType() const = 0; 00112 00113 /** 00114 * Return the Class::View representing the class in which the method 00115 * is declared. 00116 * 00117 * @return the declaring class 00118 */ 00119 virtual ClassView getDeclaringClass() const = 0; 00120 00121 /** 00122 * Execute the method. 00123 * 00124 * @param oh the object on which to invoke the method 00125 * @param vaArgs the parameters, or NULL if the method takes none. 00126 * 00127 * @return the method return value, or NULL if the method has a void return 00128 */ 00129 virtual Object::Holder invoke(Object::Holder oh, ObjectArray::View vaArgs = NULL) const = 0; 00130 00131 /** 00132 * Add the specified Annotation to the element. 00133 * 00134 * @param vAnnontation the annotation 00135 * 00136 * @return this object 00137 */ 00138 virtual Method::Handle annotate(Annotation::View vAnnontation); 00139 00140 00141 // ----- Object interface ----------------------------------------------- 00142 00143 public: 00144 /** 00145 * {@inheritDoc} 00146 */ 00147 virtual void toStream(std::ostream& out) const; 00148 00149 /** 00150 * {@inheritDoc} 00151 */ 00152 virtual bool equals(Object::View vThat) const; 00153 00154 /** 00155 * {@inheritDoc} 00156 */ 00157 virtual size32_t hashCode() const; 00158 00159 00160 // ----- enum: Modifier ------------------------------------------------- 00161 00162 public: 00163 /** 00164 * Modifier defines the various reflectable Method modifiers. 00165 */ 00166 typedef enum 00167 { 00168 /** 00169 * modifier_instance indicates that the method is an instance method. 00170 */ 00171 modifier_instance = 1, 00172 00173 /** 00174 * modifier_static indicates that the method is static. 00175 */ 00176 modifier_static = 2, 00177 00178 /** 00179 * modifier_mutable indicates that the method is non-const. 00180 */ 00181 modifier_mutable = 4, 00182 00183 /** 00184 * modifier_const indicates that the method is const. 00185 */ 00186 modifier_const = 8 00187 } Modifier; 00188 00189 00190 // ----- data members --------------------------------------------------- 00191 00192 protected: 00193 /** 00194 * The Method name. 00195 */ 00196 FinalView<String> f_vsName; 00197 }; 00198 00199 COH_CLOSE_NAMESPACE2 00200 00201 #endif // COH_METHOD_HPP