Search in sources :

Example 1 with Invoker

use of com.taobao.weex.bridge.Invoker in project weex-example by KalicyZhou.

the class WXComponent method updateProperties.

public void updateProperties(Map<String, Object> props) {
    if (props == null || mHost == null) {
        return;
    }
    for (Map.Entry<String, Object> entry : props.entrySet()) {
        String key = entry.getKey();
        Object param = entry.getValue();
        String value = WXUtils.getString(param, null);
        if (TextUtils.isEmpty(value)) {
            param = convertEmptyProperty(key, value);
        }
        if (!setProperty(key, param)) {
            if (mHolder == null) {
                return;
            }
            Invoker invoker = mHolder.getPropertyInvoker(key);
            if (invoker != null) {
                try {
                    Type[] paramClazzs = invoker.getParameterTypes();
                    if (paramClazzs.length != 1) {
                        WXLogUtils.e("[WXComponent] setX method only one parameter:" + invoker);
                        return;
                    }
                    param = WXReflectionUtils.parseArgument(paramClazzs[0], param);
                    invoker.invoke(this, param);
                } catch (Exception e) {
                    WXLogUtils.e("[WXComponent] updateProperties :" + "class:" + getClass() + "method:" + invoker.toString() + " function " + WXLogUtils.getStackTrace(e));
                }
            }
        }
    }
    readyToRender();
}
Also used : Type(java.lang.reflect.Type) WXGestureType(com.taobao.weex.ui.view.gesture.WXGestureType) Invoker(com.taobao.weex.bridge.Invoker) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) IWXObject(com.taobao.weex.common.IWXObject) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) Map(java.util.Map) HashMap(java.util.HashMap) WXRuntimeException(com.taobao.weex.common.WXRuntimeException)

Example 2 with Invoker

use of com.taobao.weex.bridge.Invoker in project weex-example by KalicyZhou.

the class TypeModuleFactory method generateMethodMap.

private void generateMethodMap() {
    if (WXEnvironment.isApkDebugable()) {
        WXLogUtils.d(TAG, "extractMethodNames:" + mClazz.getSimpleName());
    }
    HashMap<String, Invoker> methodMap = new HashMap<>();
    try {
        for (Method method : mClazz.getMethods()) {
            // iterates all the annotations available in the method
            for (Annotation anno : method.getDeclaredAnnotations()) {
                if (anno != null) {
                    if (anno instanceof JSMethod) {
                        JSMethod methodAnnotation = (JSMethod) anno;
                        String name = JSMethod.NOT_SET.equals(methodAnnotation.alias()) ? method.getName() : methodAnnotation.alias();
                        methodMap.put(name, new MethodInvoker(method, methodAnnotation.uiThread()));
                        break;
                    } else if (anno instanceof WXModuleAnno) {
                        WXModuleAnno methodAnnotation = (WXModuleAnno) anno;
                        methodMap.put(method.getName(), new MethodInvoker(method, methodAnnotation.runOnUIThread()));
                        break;
                    }
                }
            }
        }
    } catch (Throwable e) {
        WXLogUtils.e("[WXModuleManager] extractMethodNames:", e);
    }
    mMethodMap = methodMap;
}
Also used : MethodInvoker(com.taobao.weex.bridge.MethodInvoker) Invoker(com.taobao.weex.bridge.Invoker) HashMap(java.util.HashMap) JSMethod(com.taobao.weex.annotation.JSMethod) Method(java.lang.reflect.Method) JSMethod(com.taobao.weex.annotation.JSMethod) Annotation(java.lang.annotation.Annotation) MethodInvoker(com.taobao.weex.bridge.MethodInvoker)

Example 3 with Invoker

use of com.taobao.weex.bridge.Invoker in project incubator-weex by apache.

the class ConfigModuleFactory method generateMethodMap.

private void generateMethodMap() {
    if (WXEnvironment.isApkDebugable()) {
        WXLogUtils.d(TAG, "extractMethodNames:" + mClazz.getSimpleName());
    }
    HashMap<String, Invoker> methodMap = new HashMap<>();
    try {
        for (Method method : mClazz.getMethods()) {
            // iterates all the annotations available in the method
            for (Annotation anno : method.getDeclaredAnnotations()) {
                if (anno != null) {
                    if (anno instanceof JSMethod) {
                        JSMethod methodAnnotation = (JSMethod) anno;
                        String name = JSMethod.NOT_SET.equals(methodAnnotation.alias()) ? method.getName() : methodAnnotation.alias();
                        methodMap.put(name, new MethodInvoker(method, methodAnnotation.uiThread()));
                        break;
                    } else if (anno instanceof WXModuleAnno) {
                        WXModuleAnno methodAnnotation = (WXModuleAnno) anno;
                        methodMap.put(method.getName(), new MethodInvoker(method, methodAnnotation.runOnUIThread()));
                        break;
                    }
                }
            }
        }
    } catch (Throwable e) {
        WXLogUtils.e("[WXModuleManager] extractMethodNames:", e);
    }
    mMethodMap = methodMap;
}
Also used : WXModuleAnno(com.taobao.weex.common.WXModuleAnno) MethodInvoker(com.taobao.weex.bridge.MethodInvoker) Invoker(com.taobao.weex.bridge.Invoker) HashMap(java.util.HashMap) JSMethod(com.taobao.weex.annotation.JSMethod) Method(java.lang.reflect.Method) JSMethod(com.taobao.weex.annotation.JSMethod) Annotation(java.lang.annotation.Annotation) MethodInvoker(com.taobao.weex.bridge.MethodInvoker)

Example 4 with Invoker

use of com.taobao.weex.bridge.Invoker in project incubator-weex by apache.

the class TypeModuleFactory method generateMethodMap.

private void generateMethodMap() {
    if (WXEnvironment.isApkDebugable()) {
        WXLogUtils.d(TAG, "extractMethodNames:" + mClazz.getSimpleName());
    }
    HashMap<String, Invoker> methodMap = new HashMap<>();
    try {
        for (Method method : mClazz.getMethods()) {
            // iterates all the annotations available in the method
            for (Annotation anno : method.getDeclaredAnnotations()) {
                if (anno != null) {
                    if (anno instanceof JSMethod) {
                        JSMethod methodAnnotation = (JSMethod) anno;
                        String name = JSMethod.NOT_SET.equals(methodAnnotation.alias()) ? method.getName() : methodAnnotation.alias();
                        methodMap.put(name, new MethodInvoker(method, methodAnnotation.uiThread()));
                        break;
                    } else if (anno instanceof WXModuleAnno) {
                        WXModuleAnno methodAnnotation = (WXModuleAnno) anno;
                        methodMap.put(method.getName(), new MethodInvoker(method, methodAnnotation.runOnUIThread()));
                        break;
                    }
                }
            }
        }
    } catch (Throwable e) {
        WXLogUtils.e("[WXModuleManager] extractMethodNames:", e);
    }
    mMethodMap = methodMap;
}
Also used : MethodInvoker(com.taobao.weex.bridge.MethodInvoker) Invoker(com.taobao.weex.bridge.Invoker) HashMap(java.util.HashMap) JSMethod(com.taobao.weex.annotation.JSMethod) Method(java.lang.reflect.Method) JSMethod(com.taobao.weex.annotation.JSMethod) Annotation(java.lang.annotation.Annotation) MethodInvoker(com.taobao.weex.bridge.MethodInvoker)

Example 5 with Invoker

use of com.taobao.weex.bridge.Invoker in project weex-example by KalicyZhou.

the class SimpleComponentHolder method getMethods.

static Pair<Map<String, Invoker>, Map<String, Invoker>> getMethods(Class clz) {
    Map<String, Invoker> methods = new HashMap<>();
    Map<String, Invoker> mInvokers = new HashMap<>();
    Annotation[] annotations;
    Annotation anno;
    try {
        for (Method method : clz.getMethods()) {
            try {
                annotations = method.getDeclaredAnnotations();
                for (int i = 0, annotationsCount = annotations.length; i < annotationsCount; ++i) {
                    anno = annotations[i];
                    if (anno == null) {
                        continue;
                    }
                    if (anno instanceof WXComponentProp) {
                        String name = ((WXComponentProp) anno).name();
                        methods.put(name, new MethodInvoker(method, true));
                        break;
                    } else if (anno instanceof JSMethod) {
                        JSMethod methodAnno = (JSMethod) anno;
                        String name = methodAnno.alias();
                        if (JSMethod.NOT_SET.equals(name)) {
                            name = method.getName();
                        }
                        mInvokers.put(name, new MethodInvoker(method, methodAnno.uiThread()));
                        break;
                    }
                }
            } catch (ArrayIndexOutOfBoundsException | IncompatibleClassChangeError e) {
            //ignore: getDeclaredAnnotations may throw this
            }
        }
    } catch (IndexOutOfBoundsException e) {
        e.printStackTrace();
    //ignore: getMethods may throw this
    }
    return new Pair<>(methods, mInvokers);
}
Also used : HashMap(java.util.HashMap) JSMethod(com.taobao.weex.annotation.JSMethod) Method(java.lang.reflect.Method) JSMethod(com.taobao.weex.annotation.JSMethod) Annotation(java.lang.annotation.Annotation) MethodInvoker(com.taobao.weex.bridge.MethodInvoker) Invoker(com.taobao.weex.bridge.Invoker) WXComponentProp(com.taobao.weex.ui.component.WXComponentProp) MethodInvoker(com.taobao.weex.bridge.MethodInvoker) Pair(android.util.Pair)

Aggregations

Invoker (com.taobao.weex.bridge.Invoker)7 HashMap (java.util.HashMap)7 JSMethod (com.taobao.weex.annotation.JSMethod)5 MethodInvoker (com.taobao.weex.bridge.MethodInvoker)5 Annotation (java.lang.annotation.Annotation)5 Method (java.lang.reflect.Method)5 Pair (android.util.Pair)2 JSONObject (com.alibaba.fastjson.JSONObject)2 IWXObject (com.taobao.weex.common.IWXObject)2 WXRuntimeException (com.taobao.weex.common.WXRuntimeException)2 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)2 WXDomObject (com.taobao.weex.dom.WXDomObject)2 WXComponentProp (com.taobao.weex.ui.component.WXComponentProp)2 WXGestureType (com.taobao.weex.ui.view.gesture.WXGestureType)2 Type (java.lang.reflect.Type)2 Map (java.util.Map)2 WXModuleAnno (com.taobao.weex.common.WXModuleAnno)1 FlatComponent (com.taobao.weex.ui.flat.FlatComponent)1 AndroidViewWidget (com.taobao.weex.ui.flat.widget.AndroidViewWidget)1 ElementType (java.lang.annotation.ElementType)1