package com.ydl.js_module.manager

import com.ydl.js_module.listener.JSInterfaceImpl
import com.ydl.js_module.util.RouterParamsUrls

/**
 * @author yuanWai
 * @描述:路由反射调用
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/12/5
 */
class RouterAnalysis private constructor() {

    /**
     * 单例
     */
    companion object {
        val instance: RouterAnalysis by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            RouterAnalysis() }
    }

    private var mIJSInterface : JSInterfaceImpl? = null

    fun routerInvoke(paramsUrls : RouterParamsUrls){
        try {
            getJSInterface().javaClass.getMethod(paramsUrls.getMethod(),  String::class.java)
                    .invoke(getJSInterface(), paramsUrls.getParams())
        } catch (e: Exception) {

        }
    }

    private fun getJSInterface() : JSInterfaceImpl{
        if (null == mIJSInterface){
            mIJSInterface = JSInterfaceImpl()
        }
        return mIJSInterface!!
    }
}