Java 类org.mozilla.javascript.annotations.JSStaticFunction 实例源码

项目:NewKakaoBot    文件:ScriptUtil.java   
@JSStaticFunction
public static void parseToHtml(final String url, final String option, final Function func) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            Document document = null;
            try {
                document = Jsoup.connect(url).get();
                Elements element = document.select(option);

                func.call(context, scope, scope, new Object[] { element.html(), null });
            } catch (IOException e) {
                try {
                    func.call(context, scope, scope, new Object[] { null, e});
                } catch (Exception err) {}
            }
        }
    }).start();
}
项目:NewKakaoBot    文件:ScriptUtil.java   
@JSStaticFunction
public static void parseToText(final String url, final String option, final Function func) throws IOException {
    new Thread(new Runnable() {
        @Override
        public void run() {
            Document document = null;
            try {
                document = Jsoup.connect(url).get();
                Elements element = document.select(option);

                func.call(context, scope, scope, new Object[] { element.text(), null });
            } catch (IOException e) {
                try {
                    func.call(context, scope, scope, new Object[] { null, e });
                } catch (Exception err) {}
            }
        }
    }).start();
}
项目:KakaoBot    文件:JSKakaoTalk.java   
@JSStaticFunction
public static Object getContext() {
    Context jsContext = KakaoTalkListener.getJsEngines()[0].getContext();
    ScriptableObject scope = KakaoTalkListener.getJsEngines()[0].getScope();

    return jsContext.javaToJS(MainActivity.getContext(), scope);
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#addArchiveToClassPath(Path, Configuration)} and
 * {@link DistributedCache#addArchiveToClassPath(Path, Configuration, org.apache.hadoop.fs.FileSystem)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 */
@JSStaticFunction
public static void addArchiveToClassPath(final Context ctx, final Scriptable thisObj, final Object[] args,
                                         final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;

    if (args.length < 2) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!(arg1 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_MUST_BE_CONF);
    }

    final Configuration conf = ((ConfigurationWrap)arg1).getConf();
    final Path path = new Path(URI.create(arg0.toString()));

    try {
        DistributedCache.addArchiveToClassPath(path, conf, path.getFileSystem(conf));
    } catch (IOException e) {
        throw Utils.makeError(ctx, thisObj, e.getMessage());
    }
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#addCacheFile(URI, Configuration)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 */
@JSStaticFunction
public static void addCacheFile(final Context ctx, final Scriptable thisObj, final Object[] args,
                                final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;

    if (args.length < 2) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!(arg1 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_MUST_BE_CONF);
    }

    DistributedCache.addCacheFile(URI.create(arg0.toString()), ((ConfigurationWrap)arg1).getConf());
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#addLocalFiles(Configuration, String)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 */
@JSStaticFunction
public static void addLocalFiles(final Context ctx, final Scriptable thisObj, final Object[] args,
                                 final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;

    if (args.length < 2) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!(arg0 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
    }

    DistributedCache.addLocalFiles(((ConfigurationWrap)arg0).getConf(), arg1.toString());
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#createSymlink(Configuration)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 */
@JSStaticFunction
public static void createSymlink(final Context ctx, final Scriptable thisObj, final Object[] args,
                                 final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;

    if (args.length < 1) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!(arg0 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
    }

    DistributedCache.createSymlink(((ConfigurationWrap)arg0).getConf());
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#getArchiveClassPaths(Configuration)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 *
 * @return array of archive class paths
 */
@JSStaticFunction
public static Object getArchiveClassPaths(final Context ctx, final Scriptable thisObj, final Object[] args,
                                          final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;

    if (args.length < 1) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!(arg0 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
    }

    final Configuration conf = ((ConfigurationWrap)arg0).getConf();
    final Path[] archiveClassPaths = DistributedCache.getArchiveClassPaths(conf);
    final List<String> pathStrings = new ArrayList<>();

    if (archiveClassPaths != null) {
        for (final Path path : archiveClassPaths) {
            pathStrings.add(path.toUri().toString());
        }
    }

    return JavaScriptUtils.asArray(thisObj, pathStrings);
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#getFileClassPaths(Configuration)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 *
 * @return array of file class paths
 */
@JSStaticFunction
public static Object getFileClassPaths(final Context ctx, final Scriptable thisObj, final Object[] args,
                                       final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;

    if (args.length < 1) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!(arg0 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
    }

    final Configuration conf = ((ConfigurationWrap)arg0).getConf();
    final Path[] fileClassPaths = DistributedCache.getFileClassPaths(conf);
    final List<String> pathStrings = new ArrayList<>();

    if (fileClassPaths != null) {
        for (final Path path : fileClassPaths) {
            pathStrings.add(path.toUri().toString());
        }
    }

    return JavaScriptUtils.asArray(thisObj, pathStrings);
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#getFileTimestamps(Configuration)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 *
 * @return array of file timestamps
 */
@JSStaticFunction
public static Object getFileTimestamps(final Context ctx, final Scriptable thisObj, final Object[] args,
                                       final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;

    if (args.length < 1) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!(arg0 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
    }

    return JavaScriptUtils.asArray(thisObj, DistributedCache.getFileTimestamps(
            ((ConfigurationWrap)arg0).getConf()));
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#getSymlink(Configuration)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 *
 * @return whether or not symlinks are to be created
 */
@JSStaticFunction
public static Object getSymlink(final Context ctx, final Scriptable thisObj, final Object[] args,
                                final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;

    if (args.length < 1) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!(arg0 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
    }

    return DistributedCache.getSymlink(((ConfigurationWrap)arg0).getConf());
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#setArchiveTimestamps(Configuration, String)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 */
@JSStaticFunction
public static void setArchiveTimestamps(final Context ctx, final Scriptable thisObj, final Object[] args,
                                        final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;

    if (args.length < 2) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!(arg0 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
    }

    DistributedCache.setArchiveTimestamps(((ConfigurationWrap)arg0).getConf(), arg1.toString());
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#setLocalArchives(Configuration, String)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 */
@JSStaticFunction
public static void setLocalArchives(final Context ctx, final Scriptable thisObj, final Object[] args,
                                    final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;

    if (args.length < 2) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!(arg0 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
    }

    DistributedCache.setLocalArchives(((ConfigurationWrap)arg0).getConf(), arg1.toString());
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#setLocalFiles(Configuration, String)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 */
@JSStaticFunction
public static void setLocalFiles(final Context ctx, final Scriptable thisObj, final Object[] args,
                                 final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;

    if (args.length < 2) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!(arg0 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
    }

    DistributedCache.setLocalFiles(((ConfigurationWrap)arg0).getConf(), arg1.toString());
}
项目:HL4A    文件:ScriptableObject.java   
private static String getPropertyName(String methodName,
                                      String prefix,
                                      Annotation annotation) {
    if (prefix != null) {
        return methodName.substring(prefix.length());
    }
    String propName = null;
    if (annotation instanceof JSGetter) {
        propName = ((JSGetter) annotation).value();
        if (propName == null || propName.length() == 0) {
            if (methodName.length() > 1 && (methodName.startsWith("取") || methodName.startsWith("get"))) {
                propName = methodName.substring(3);
                if (Character.isUpperCase(propName.charAt(0))) {
                    if (propName.length() == 1) {
                        propName = propName.toLowerCase();
                    } else if (!Character.isUpperCase(propName.charAt(1))){
                        propName = Character.toLowerCase(propName.charAt(0))
                                + propName.substring(1);
                    }
                }
            }
        }
    } else if (annotation instanceof JSFunction) {
        propName = ((JSFunction) annotation).value();
    } else if (annotation instanceof JSStaticFunction) {
        propName = ((JSStaticFunction) annotation).value();
    }
    if (propName == null || propName.length() == 0) {
        propName = methodName;
    }
    return propName;
}
项目:NewKakaoBot    文件:ScriptUtil.java   
@JSStaticFunction
public static void delay(final Function func, final int ms) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(ms);
                func.call(context, scope, scope, new Object[] { true });
            } catch (InterruptedException e) {
                func.call(context, scope, scope, new Object[] { false });
            }
        }
    }).start();
}
项目:NewKakaoBot    文件:ScriptBot.java   
@JSStaticFunction
public static void send(String room, final String message) {
    try {
        KakaoTalkListener.send(room, message);
    } catch(IllegalArgumentException err) {
        if(KakaoManager.getInstance().isForeground) {
            MainActivity.UIThread(new Runnable() {
                @Override
                public void run() {
                    MainActivity.adapter.addBotChat(message);
                }
            });
        }
    }
}
项目:NewKakaoBot    文件:ScriptBot.java   
@JSStaticFunction
public static void initData(String key, String value) {
    Object data = FileManager.getInstance().readData(DATA, key);
    if(data == null) {
        FileManager.getInstance().saveData(DATA, key, value);
    }
}
项目:whackpad    文件:ScriptableObject.java   
private static String getPropertyName(String methodName,
                                      String prefix,
                                      Annotation annotation) {
    if (prefix != null) {
        return methodName.substring(prefix.length());
    }
    String propName = null;
    if (annotation instanceof JSGetter) {
        propName = ((JSGetter) annotation).value();
        if (propName == null || propName.length() == 0) {
            if (methodName.length() > 3 && methodName.startsWith("get")) {
                propName = methodName.substring(3);
                if (Character.isUpperCase(propName.charAt(0))) {
                    if (propName.length() == 1) {
                        propName = propName.toLowerCase();
                    } else if (!Character.isUpperCase(propName.charAt(1))){
                        propName = Character.toLowerCase(propName.charAt(0))
                                + propName.substring(1);
                    }
                }
            }
        }
    } else if (annotation instanceof JSFunction) {
        propName = ((JSFunction) annotation).value();
    } else if (annotation instanceof JSStaticFunction) {
        propName = ((JSStaticFunction) annotation).value();
    }
    if (propName == null || propName.length() == 0) {
        propName = methodName;
    }
    return propName;
}
项目:KakaoBot    文件:JSKakaoTalk.java   
@JSStaticFunction
public static void send(String room, String message) {
    if (message == null) {
        KakaoTalkListener.Session[] sessions = KakaoTalkListener.getSessions().toArray(new KakaoTalkListener.Session[0]);
        KakaoTalkListener.send(sessions[sessions.length - 1].room, message);
    } else {
        KakaoTalkListener.send(room, message);
    }
}
项目:KakaoBot    文件:JSUtil.java   
@JSStaticFunction
public static void saveData(String key, ScriptableObject data) {
    SharedPreferences preference = context.getSharedPreferences("script_data", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preference.edit();
    editor.putString(key, data.toString());
    editor.commit();
}
项目:KakaoBot    文件:JSUtil.java   
@JSStaticFunction
public static ScriptableObject readData(String key) {
    JSScriptEngine engine = KakaoTalkListener.getJsEngines()[0];

    SharedPreferences preference = context.getSharedPreferences("script_data", Context.MODE_PRIVATE);
    return (ScriptableObject) engine.getContext().javaToJS(preference.getString(key, ""), engine.getScope());
}
项目:TaleCraft    文件:ScriptableObject.java   
private static String getPropertyName(String methodName,
                                      String prefix,
                                      Annotation annotation) {
    if (prefix != null) {
        return methodName.substring(prefix.length());
    }
    String propName = null;
    if (annotation instanceof JSGetter) {
        propName = ((JSGetter) annotation).value();
        if (propName == null || propName.length() == 0) {
            if (methodName.length() > 3 && methodName.startsWith("get")) {
                propName = methodName.substring(3);
                if (Character.isUpperCase(propName.charAt(0))) {
                    if (propName.length() == 1) {
                        propName = propName.toLowerCase();
                    } else if (!Character.isUpperCase(propName.charAt(1))){
                        propName = Character.toLowerCase(propName.charAt(0))
                                + propName.substring(1);
                    }
                }
            }
        }
    } else if (annotation instanceof JSFunction) {
        propName = ((JSFunction) annotation).value();
    } else if (annotation instanceof JSStaticFunction) {
        propName = ((JSStaticFunction) annotation).value();
    }
    if (propName == null || propName.length() == 0) {
        propName = methodName;
    }
    return propName;
}
项目:code404    文件:ScriptableObject.java   
private static String getPropertyName(String methodName,
                                      String prefix,
                                      Annotation annotation) {
    if (prefix != null) {
        return methodName.substring(prefix.length());
    }
    String propName = null;
    if (annotation instanceof JSGetter) {
        propName = ((JSGetter) annotation).value();
        if (propName == null || propName.length() == 0) {
            if (methodName.length() > 3 && methodName.startsWith("get")) {
                propName = methodName.substring(3);
                if (Character.isUpperCase(propName.charAt(0))) {
                    if (propName.length() == 1) {
                        propName = propName.toLowerCase();
                    } else if (!Character.isUpperCase(propName.charAt(1))){
                        propName = Character.toLowerCase(propName.charAt(0))
                                + propName.substring(1);
                    }
                }
            }
        }
    } else if (annotation instanceof JSFunction) {
        propName = ((JSFunction) annotation).value();
    } else if (annotation instanceof JSStaticFunction) {
        propName = ((JSStaticFunction) annotation).value();
    }
    if (propName == null || propName.length() == 0) {
        propName = methodName;
    }
    return propName;
}
项目:rhino-jscover    文件:ScriptableObject.java   
private static String getPropertyName(String methodName,
                                      String prefix,
                                      Annotation annotation) {
    if (prefix != null) {
        return methodName.substring(prefix.length());
    }
    String propName = null;
    if (annotation instanceof JSGetter) {
        propName = ((JSGetter) annotation).value();
        if (propName == null || propName.length() == 0) {
            if (methodName.length() > 3 && methodName.startsWith("get")) {
                propName = methodName.substring(3);
                if (Character.isUpperCase(propName.charAt(0))) {
                    if (propName.length() == 1) {
                        propName = propName.toLowerCase();
                    } else if (!Character.isUpperCase(propName.charAt(1))){
                        propName = Character.toLowerCase(propName.charAt(0))
                                + propName.substring(1);
                    }
                }
            }
        }
    } else if (annotation instanceof JSFunction) {
        propName = ((JSFunction) annotation).value();
    } else if (annotation instanceof JSStaticFunction) {
        propName = ((JSStaticFunction) annotation).value();
    }
    if (propName == null || propName.length() == 0) {
        propName = methodName;
    }
    return propName;
}
项目:LoboEvolution    文件:ScriptableObject.java   
private static String getPropertyName(String methodName,
                                      String prefix,
                                      Annotation annotation) {
    if (prefix != null) {
        return methodName.substring(prefix.length());
    }
    String propName = null;
    if (annotation instanceof JSGetter) {
        propName = ((JSGetter) annotation).value();
        if (propName == null || propName.length() == 0) {
            if (methodName.length() > 3 && methodName.startsWith("get")) {
                propName = methodName.substring(3);
                if (Character.isUpperCase(propName.charAt(0))) {
                    if (propName.length() == 1) {
                        propName = propName.toLowerCase();
                    } else if (!Character.isUpperCase(propName.charAt(1))){
                        propName = Character.toLowerCase(propName.charAt(0))
                                + propName.substring(1);
                    }
                }
            }
        }
    } else if (annotation instanceof JSFunction) {
        propName = ((JSFunction) annotation).value();
    } else if (annotation instanceof JSStaticFunction) {
        propName = ((JSStaticFunction) annotation).value();
    }
    if (propName == null || propName.length() == 0) {
        propName = methodName;
    }
    return propName;
}
项目:astor    文件:ScriptableObject.java   
private static String getPropertyName(String methodName,
                                      String prefix,
                                      Annotation annotation) {
    if (prefix != null) {
        return methodName.substring(prefix.length());
    }
    String propName = null;
    if (annotation instanceof JSGetter) {
        propName = ((JSGetter) annotation).value();
        if (propName == null || propName.length() == 0) {
            if (methodName.length() > 3 && methodName.startsWith("get")) {
                propName = methodName.substring(3);
                if (Character.isUpperCase(propName.charAt(0))) {
                    if (propName.length() == 1) {
                        propName = propName.toLowerCase();
                    } else if (!Character.isUpperCase(propName.charAt(1))){
                        propName = Character.toLowerCase(propName.charAt(0))
                                + propName.substring(1);
                    }
                }
            }
        }
    } else if (annotation instanceof JSFunction) {
        propName = ((JSFunction) annotation).value();
    } else if (annotation instanceof JSStaticFunction) {
        propName = ((JSStaticFunction) annotation).value();
    }
    if (propName == null || propName.length() == 0) {
        propName = methodName;
    }
    return propName;
}
项目:android-js    文件:ScriptableObject.java   
private static String getPropertyName(String methodName,
                                      String prefix,
                                      Annotation annotation) {
    if (prefix != null) {
        return methodName.substring(prefix.length());
    }
    String propName = null;
    if (annotation instanceof JSGetter) {
        propName = ((JSGetter) annotation).value();
        if (propName == null || propName.length() == 0) {
            if (methodName.length() > 3 && methodName.startsWith("get")) {
                propName = methodName.substring(3);
                if (Character.isUpperCase(propName.charAt(0))) {
                    if (propName.length() == 1) {
                        propName = propName.toLowerCase();
                    } else if (!Character.isUpperCase(propName.charAt(1))){
                        propName = Character.toLowerCase(propName.charAt(0))
                                + propName.substring(1);
                    }
                }
            }
        }
    } else if (annotation instanceof JSFunction) {
        propName = ((JSFunction) annotation).value();
    } else if (annotation instanceof JSStaticFunction) {
        propName = ((JSStaticFunction) annotation).value();
    }
    if (propName == null || propName.length() == 0) {
        propName = methodName;
    }
    return propName;
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#checkURIs(URI[], URI[])}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 *
 * @return whether or not the uris are without conflict or issue
 */
@JSStaticFunction
public static boolean checkURIs(final Context ctx, final Scriptable thisObj, final Object[] args,
                                final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;

    if (args.length < 2) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!(arg0 instanceof NativeArray)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_ARRAY);
    } else if (!(arg1 instanceof NativeArray)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_MUST_BE_ARRAY);
    }

    final NativeArray jsFileUris = (NativeArray)arg0;
    final NativeArray jsArchiveUris = (NativeArray)arg1;
    final URI[] fileUris = new URI[(int)jsFileUris.getLength()];
    final URI[] archiveUris = new URI[(int)jsArchiveUris.getLength()];

    for (int i = 0; i < fileUris.length; i++) {
        fileUris[i] = URI.create(jsFileUris.get(i).toString());
    }

    for (int i = 0; i < archiveUris.length; i++) {
        archiveUris[i] = URI.create(jsArchiveUris.get(i).toString());
    }

    return DistributedCache.checkURIs(fileUris, archiveUris);
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#createAllSymlink(Configuration, File, File)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 */
@JSStaticFunction
public static void createAllSymlink(final Context ctx, final Scriptable thisObj, final Object[] args,
                                    final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;
    final Object arg2 = args.length >= 3 ? args[2] : Undefined.instance;

    if (args.length < 3) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.THREE_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg2)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.THIRD_ARG_REQUIRED);
    } else if (!(arg0 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
    }

    try {
        DistributedCache.createAllSymlink(((ConfigurationWrap)arg0).getConf(),
                                          new File(arg1.toString()),
                                          new File(arg2.toString()));
    } catch (IOException e) {
        throw Utils.makeError(ctx, thisObj, e.getMessage());
    }
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#getCacheArchives(Configuration)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 *
 * @return array of cache archive paths
 */
@JSStaticFunction
public static Object getCacheArchives(final Context ctx, final Scriptable thisObj, final Object[] args,
                                      final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;

    if (args.length < 1) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!(arg0 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
    }

    final Configuration conf = ((ConfigurationWrap)arg0).getConf();
    URI[] cacheArchives;

    try {
        cacheArchives = DistributedCache.getCacheArchives(conf);
    } catch (IOException e) {
        throw Utils.makeError(ctx, thisObj, e.getMessage());
    }

    final List<String> cacheArchiveStrs = new ArrayList<>();

    if (cacheArchives != null) {
        for (final URI uri : cacheArchives) {
            cacheArchiveStrs.add(uri.toString());
        }
    }

    return JavaScriptUtils.asArray(thisObj, cacheArchiveStrs);
}
项目:lembos    文件:DistributedCacheWrap.java   
/**
 * Java wrapper for {@link DistributedCache#setCacheFiles(URI[], Configuration)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 */
@JSStaticFunction
public static void setCacheFiles(final Context ctx, final Scriptable thisObj, final Object[] args,
                                 final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;

    if (args.length < 2) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!(arg0 instanceof NativeArray)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_ARRAY);
    } else if (!(arg1 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_MUST_BE_CONF);
    }

    final NativeArray jsFileUris = (NativeArray)arg0;
    final URI[] fileUris = new URI[(int)jsFileUris.getLength()];

    for (int i = 0; i < fileUris.length; i++) {
        fileUris[i] = URI.create(jsFileUris.get(i).toString());
    }

    DistributedCache.setCacheFiles(fileUris, ((ConfigurationWrap)arg1).getConf());
}
项目:lembos    文件:ConfigurationWrap.java   
/**
 * Wraps {@link Configuration#addDefaultResource(String)}.
 *
 * @param ctx the JavaScript context (unused)
 * @param thisObj the 'this' object of the caller
 * @param args the arguments for the call
 * @param func the function called (unused)
 */
@JSStaticFunction
public static void addDefaultResource(final Context ctx, final Scriptable thisObj, final Object[] args,
                                      final Function func) {
    if (args.length == 0 || !JavaScriptUtils.isDefined(args[0])) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED);
    }

    Configuration.addDefaultResource(args[0].toString());
}
项目:lembos    文件:FileInputFormatHelper.java   
/**
 * Java wrapper for {@link FileInputFormat#setMinInputSplitSize(Job, long)}.
 *
 * @param clazz the class to invoke the method of
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 */
@JSStaticFunction
public static void setMinInputSplitSize(final Class<?> clazz, final Context ctx, final Scriptable thisObj,
                                        final Object[] args) {
    validateClass(clazz, ctx, thisObj);

    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;

    if (args.length < 2) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!(arg0 instanceof JobWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_JOB);
    } else if (!(arg1 instanceof Number)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_ARG_MUST_BE_NUM);
    }

    try {
        ReflectionUtils.invokeStatic(clazz, "setMinInputSplitSize", new Class<?>[] {
                Job.class, long.class
        }, new Object[] {
                ((JobWrap)arg0).getJob(), JavaScriptUtils.fromNumber(arg1).longValue()
        });
    } catch (Exception e) {
        e.printStackTrace();
        throw Utils.makeError(ctx, thisObj, e.getMessage());
    }
}
项目:NewKakaoBot    文件:ScriptBot.java   
@JSStaticFunction
public static void saveData(String key, String value) {
    FileManager.getInstance().saveData(DATA, key, value);
}
项目:NewKakaoBot    文件:ScriptBot.java   
@JSStaticFunction
public static Object readData(String key) {
    return FileManager.getInstance().readData(DATA, key);
}
项目:NewKakaoBot    文件:ScriptBot.java   
@JSStaticFunction
public static void removeData(String key) {
    FileManager.getInstance().removeData(DATA, key);
}
项目:NewKakaoBot    文件:ScriptBot.java   
@JSStaticFunction
public static Object getDataList() {
    return FileManager.getInstance().readToJson(DATA);
}
项目:NewKakaoBot    文件:ScriptBot.java   
@JSStaticFunction
public static Object getContext() {
    return MainActivity.context;
}
项目:rhino-android    文件:DefineClassTest.java   
@JSStaticFunction
public static Object staticFunction() {
    return "staticFunction";
}