⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmpropparse.java

📁 类javaScript脚本解释器
💻 JAVA
字号:
package MultiScriptParse.Parse;

import java.util.*;
import java.lang.reflect.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */
class PropParseElement extends NamedObj {

  public Object LinkJObj;

  public PropParseElement(char[] Name, int NameStartPos, int Namelength, Object o) {
    super(Name, NameStartPos, Namelength);
    LinkJObj = o;
  }

  public PropParseElement(String Name, Object o) {
    super(Name);
    LinkJObj = o;
  }
}

public class JMPropParse extends JMObject {

  private NamedObjArrayList ObjList = new NamedObjArrayList();

  private PropParseElement ppe;

  private JMParseParamsParse ParseParamsParse;

  public JMPropParse() {
  }

  public JMPropParse(JMParse Owner) {
    super(Owner);
  }

  public boolean AddObjectLink(char[] Name, int NameStartPos, int Namelength, Object o) {
    return ObjList.SortAddElement(new PropParseElement(Name, NameStartPos, Namelength, o));

  }

  public boolean AddObjectLink(String Name, Object o) {
    return ObjList.SortAddElement(new PropParseElement(Name, o));
  }

  public void setParseParamsParse(JMParseParamsParse ParseParamsParse) {
    this.ParseParamsParse = ParseParamsParse;
  }

  //PropString 是除对象字符串外的不带“.”的字符串
  public Object FindObject(String Name) throws JMParseException
  {
    Object oo;
    oo = ObjList.SortFindElement(Name);
    if (oo != null) {
      ppe = (PropParseElement)oo;
      return ((PropParseElement) ppe).LinkJObj;
    }
    if (JMParse.GlobVarList.FindVariable(Name))
      return JMParse.GlobVarList.GetJustFindVar().Value;
    if (JMParse.LocalVarList.FindVariable(Name))
      return JMParse.LocalVarList.GetJustFindVar().Value;
    throw new JMParseException(new StringBuffer().append("不能识别的对象名").append(Name).toString());
  }

  protected Object ParseObject(Object toParse, char[] PropString)
      throws JMParseException
  {
    StringBuffer key = new StringBuffer(25);
    int symbolType = 0;
    /**
     * 1 表示为数字类型常量  2 表示为字符串常量开始  3 表示字符串常量结束 4 逻辑型常量
     * 5 不确定的标志符 6 函数 7 对象方法
     */
    Method toExec;
    String Name;
    Class[] ParamType = null;
    Object[] Param = null;

    char ckey = PropString[++JMParse.CurrPos];//跳过'.'符

    //取出函数名
    while(ckey != 0) {

      if (ckey == '(') break;

      if ( (ckey > 47) && (ckey < 58)) {
        if (symbolType == 0)
          throw new JMParseException(new StringBuffer("不正确的标志符表示法 ").append(key).toString());
        key.append(ckey);
        ckey = PropString[++JMParse.CurrPos];
        continue;
      }

      if ( (ckey == 95) || (ckey > 64 && ckey < 91) ||
          (ckey > 96 && ckey < 123)) {
        if (symbolType == 0) symbolType = 5;
        key.append(ckey);
        ckey = PropString[++JMParse.CurrPos];
        continue;
      }

      key.append(ckey);
      throw new JMParseException(new StringBuffer("\"(\"符号期盼 ").append(key).toString());
    }

    Name = key.toString();
    if (toParse == null)
      throw new JMParseException(new StringBuffer(50).append(Name).
                                    append("方法的宿主对象为空不能调用").toString());

    key = key.delete(0, key.length());



    //当所调用的函数有参数时,分别解释函数参数
    Param = ParseParamsParse.ParseParams(PropString).toArray();
    ParamType = new Class[Param.length];

    for (int i = 0; i < Param.length; i++) {
      if (Param[i].getClass().getName() == "java.lang.Boolean"){
        ParamType[i] = Boolean.TYPE;
        continue;
      }
      if (Param[i].getClass().getName() == "java.lang.Integer"){
        ParamType[i] = Integer.TYPE;
        continue;
      }
      if (Param[i].getClass().getName() == "java.lang.StringBuffer"){
        ParamType[i] = Name.getClass();
        Param[i] = Param[i].toString();
        continue;
      }
      if (Param[i] != null) ParamType[i] = Param[i].getClass();
    }

    //查找指定对象的指定方法并执行,如果有返回值返回方法返回的对象
    if (toParse != null) {
      try{
        toExec = toParse.getClass().getMethod(Name, ParamType);
        if (toExec.getReturnType() != null) return toExec.invoke(toParse, Param);
      } catch (NoSuchMethodException e){
        throw new JMParseException(new StringBuffer("不能识别的对象方法").append(e.getMessage()).toString());
      } catch (SecurityException e) {
        throw new JMParseException(e.getMessage());
      } catch (IllegalAccessException e) {
        throw new JMParseException(e.getMessage());
      } catch (IllegalArgumentException e) {
        throw new JMParseException(e.getMessage());
      } catch (InvocationTargetException e) {
        throw new JMParseException(e.getMessage());
      }
    }

    return null;
  }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -