C++ Client API Reference for Oracle Coherence
14c (14.1.2.0.0)

F79659-03

coherence/lang/Method.hpp

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