use of com.taobao.weex.dom.WXDomModule in project weex-example by KalicyZhou.
the class WXModuleManager method callModuleMethod.
static Object callModuleMethod(final String instanceId, String moduleStr, String methodStr, JSONArray args) {
ModuleFactory factory = sModuleFactoryMap.get(moduleStr);
if (factory == null) {
WXLogUtils.e("[WXModuleManager] module factory not found.");
return null;
}
final WXModule wxModule = findModule(instanceId, moduleStr, factory);
if (wxModule == null) {
return null;
}
WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
wxModule.mWXSDKInstance = instance;
final Invoker invoker = factory.getMethodInvoker(methodStr);
try {
return instance.getNativeInvokeHelper().invoke(wxModule, invoker, args);
} catch (Exception e) {
WXLogUtils.e("callModuleMethod >>> invoke module:" + moduleStr + ", method:" + methodStr + " failed. ", e);
return null;
} finally {
if (wxModule instanceof WXDomModule || wxModule instanceof WXTimerModule) {
wxModule.mWXSDKInstance = null;
}
}
}
use of com.taobao.weex.dom.WXDomModule in project weex-example by KalicyZhou.
the class WXBridgeManager method callNativeModule.
public Object callNativeModule(String instanceId, String module, String method, JSONArray arguments, Object options) {
if (WXEnvironment.isApkDebugable()) {
mLodBuilder.append("[WXBridgeManager] callNativeModule >>>> instanceId:").append(instanceId).append(", module:").append(module).append(", method:").append(method).append(", arguments:").append(arguments);
WXLogUtils.d(mLodBuilder.substring(0));
mLodBuilder.setLength(0);
}
try {
if (WXDomModule.WXDOM.equals(module)) {
WXDomModule dom = getDomModule(instanceId);
return dom.callDomMethod(method, arguments);
} else {
return WXModuleManager.callModuleMethod(instanceId, module, method, arguments);
}
} catch (Exception e) {
WXLogUtils.e("[WXBridgeManager] callNative exception: ", e);
commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE, "[WXBridgeManager] callNativeModule exception " + e.getCause());
}
return null;
}
use of com.taobao.weex.dom.WXDomModule in project weex-example by KalicyZhou.
the class WXBridgeManager method callNative.
/**
* Dispatch the native task to be executed.
*
* @param instanceId {@link WXSDKInstance#mInstanceId}
* @param tasks tasks to be executed
* @param callback next tick id
*/
public int callNative(String instanceId, String tasks, String callback) {
if (TextUtils.isEmpty(tasks)) {
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.e("[WXBridgeManager] callNative: call Native tasks is null");
}
commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE, "[WXBridgeManager] callNative: call Native tasks is null");
return IWXBridge.INSTANCE_RENDERING_ERROR;
}
if (WXEnvironment.isApkDebugable()) {
mLodBuilder.append("[WXBridgeManager] callNative >>>> instanceId:").append(instanceId).append(", tasks:").append(tasks).append(", callback:").append(callback);
WXLogUtils.d(mLodBuilder.substring(0));
mLodBuilder.setLength(0);
}
if (mDestroyedInstanceId != null && mDestroyedInstanceId.contains(instanceId)) {
return IWXBridge.DESTROY_INSTANCE;
}
long start = System.currentTimeMillis();
JSONArray array = JSON.parseArray(tasks);
if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
WXSDKManager.getInstance().getSDKInstance(instanceId).jsonParseTime(System.currentTimeMillis() - start);
}
int size = array.size();
if (size > 0) {
try {
JSONObject task;
for (int i = 0; i < size; ++i) {
task = (JSONObject) array.get(i);
if (task != null && WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
Object target = task.get(MODULE);
if (target != null) {
if (WXDomModule.WXDOM.equals(target)) {
WXDomModule dom = getDomModule(instanceId);
dom.callDomMethod(task);
} else {
WXModuleManager.callModuleMethod(instanceId, (String) target, (String) task.get(METHOD), (JSONArray) task.get(ARGS));
}
} else if (task.get(COMPONENT) != null) {
//call component
WXDomModule dom = getDomModule(instanceId);
dom.invokeMethod((String) task.get(REF), (String) task.get(METHOD), (JSONArray) task.get(ARGS));
} else {
throw new IllegalArgumentException("unknown callNative");
}
}
}
} catch (Exception e) {
WXLogUtils.e("[WXBridgeManager] callNative exception: ", e);
commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE, "[WXBridgeManager] callNative exception " + e.getCause());
}
}
if (UNDEFINED.equals(callback) || NON_CALLBACK.equals(callback)) {
return IWXBridge.INSTANCE_RENDERING_ERROR;
}
// get next tick
getNextTick(instanceId, callback);
return IWXBridge.INSTANCE_RENDERING;
}
use of com.taobao.weex.dom.WXDomModule in project weex-example by KalicyZhou.
the class WXBridgeManager method callAddElement.
public int callAddElement(String instanceId, String ref, String dom, String index, String callback) {
if (WXEnvironment.isApkDebugable()) {
mLodBuilder.append("[WXBridgeManager] callNative::callAddElement >>>> instanceId:").append(instanceId).append(", ref:").append(ref).append(", dom:").append(dom).append(", callback:").append(callback);
WXLogUtils.d(mLodBuilder.substring(0));
mLodBuilder.setLength(0);
}
if (mDestroyedInstanceId != null && mDestroyedInstanceId.contains(instanceId)) {
return IWXBridge.DESTROY_INSTANCE;
}
if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
long start = System.currentTimeMillis();
JSONObject domObject = JSON.parseObject(dom);
if (WXSDKManager.getInstance().getSDKInstance(instanceId) != null) {
WXSDKManager.getInstance().getSDKInstance(instanceId).jsonParseTime(System.currentTimeMillis() - start);
}
WXDomModule domModule = getDomModule(instanceId);
domModule.addElement(ref, domObject, Integer.parseInt(index));
}
if (UNDEFINED.equals(callback) || NON_CALLBACK.equals(callback)) {
return IWXBridge.INSTANCE_RENDERING_ERROR;
}
// get next tick
getNextTick(instanceId, callback);
return IWXBridge.INSTANCE_RENDERING;
}
use of com.taobao.weex.dom.WXDomModule in project weex-example by KalicyZhou.
the class WXBridgeManager method callNativeComponent.
public Object callNativeComponent(String instanceId, String componentRef, String method, JSONArray arguments, Object options) {
if (WXEnvironment.isApkDebugable()) {
mLodBuilder.append("[WXBridgeManager] callNativeComponent >>>> instanceId:").append(instanceId).append(", componentRef:").append(componentRef).append(", method:").append(method).append(", arguments:").append(arguments);
WXLogUtils.d(mLodBuilder.substring(0));
mLodBuilder.setLength(0);
}
try {
WXDomModule dom = getDomModule(instanceId);
dom.invokeMethod(componentRef, method, arguments);
} catch (Exception e) {
WXLogUtils.e("[WXBridgeManager] callNative exception: ", e);
commitJSBridgeAlarmMonitor(instanceId, WXErrorCode.WX_ERR_INVOKE_NATIVE, "[WXBridgeManager] callNativeModule exception " + e.getCause());
}
return null;
}
Aggregations