All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Alachisoft.NCache.Common.RPCFramework.DotNetRPC.TargetObject Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
package Alachisoft.NCache.Common.RPCFramework.DotNetRPC;

import Alachisoft.NCache.Common.RPCFramework.IRPCTargetObject;
import Alachisoft.NCache.Common.RPCFramework.ITargetMethod;
import Alachisoft.NCache.Common.RPCFramework.TargetMethodAttribute;

import java.lang.annotation.Annotation;

public class TargetObject implements IRPCTargetObject {

    private Target _target;

    public TargetObject(Target targetObject) {
        _target = targetObject;
    }

    public final Target GetTargetObject() {
        return _target;
    }

    public final ITargetMethod GetMethod(String methodName, int overload) {
        ITargetMethod targetMethod = null;
        if (_target != null) {
            java.lang.reflect.Method[] members = _target.getClass().getMethods();//GetMethods(BindingFlags.Instance | BindingFlags.Public);

            for (int i = 0; i < members.length; i++) {
                java.lang.reflect.Method member = members[i];

                Annotation[] customAttributes = member.getDeclaredAnnotations();
                ;//member.GetCustomAttributes(TargetMethodAttribute.class, true);

                if (customAttributes != null && customAttributes.length > 0) {
                    TargetMethodAttribute targetMethodAttribute = (TargetMethodAttribute) ((customAttributes[0] instanceof TargetMethodAttribute) ? customAttributes[0] : null);

                    if (targetMethodAttribute.privateMethod().equals(methodName) && targetMethodAttribute.privateOverload() == overload) {
                        targetMethod = new TargetMethod(_target, member, targetMethodAttribute.privateMethod(), targetMethodAttribute.privateOverload());
                    }
                }
            }
        }
        return targetMethod;
    }

    public final ITargetMethod[] GetAllMethods() {
        java.util.ArrayList methods = new java.util.ArrayList();
        if (_target != null) {
            java.lang.reflect.Method[] members = _target.getClass().getMethods(/*BindingFlags.Instance | BindingFlags.Public*/);

            for (int i = 0; i < members.length; i++) {
                java.lang.reflect.Method member = members[i];

                Annotation[] customAttributes = member.getDeclaredAnnotations();//member.GetCustomAttributes(TargetMethodAttribute.class, true);

                if (customAttributes != null && customAttributes.length > 0) {
                    TargetMethodAttribute targetMethodAttribute = (TargetMethodAttribute) ((customAttributes[0] instanceof TargetMethodAttribute) ? customAttributes[0] : null);
                    if (targetMethodAttribute != null) {
                        TargetMethod targetMethod = new TargetMethod(_target, member, targetMethodAttribute.privateMethod(), targetMethodAttribute.privateOverload());
                        methods.add(targetMethod);
                    }
                }
            }
        }
        return methods.toArray(new ITargetMethod[0]);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy