Java 类org.mozilla.javascript.NativeJavaMethod 实例源码

项目:alfresco-enhanced-script-environment    文件:NativeJavaMethodWrappingInterceptor.java   
/**
 * {@inheritDoc}
 */
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable
{
    Object result = invocation.proceed();

    if (result instanceof NativeJavaMethod)
    {
        final ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.addAdvice(AdapterObjectInterceptor.getInstance());
        proxyFactory.addAdvice(NativeJavaMethodArgumentCorrectingInterceptor.getDefaultInstance());
        proxyFactory.addAdvice(NativeJavaMethodWrapFactoryInterceptor.getInstance());
        proxyFactory.setInterfaces(ClassUtils.collectInterfaces(NativeJavaMethod.class,
                Arrays.<Class<?>> asList(AdapterObject.class)));
        proxyFactory.setTarget(result);
        result = proxyFactory.getProxy();
    }

    return result;
}
项目:birt    文件:JsValue.java   
static boolean isValidJsValue( Object val )
{
    return ( val != Scriptable.NOT_FOUND
            && !( val instanceof Undefined )
            && !( val instanceof NativeJavaMethod )
            && !( val instanceof NativeJavaConstructor ) && !( val instanceof NativeJavaPackage ) );

}
项目:alfresco-enhanced-script-environment    文件:NativeStringMethodSwitchInterceptor.java   
/**
 * {@inheritDoc}
 */
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable
{
    Object result;

    final Object _this = invocation.getThis();
    if (_this instanceof NativeJavaMethod)
    {
        final Object[] arguments = invocation.getArguments();

        final Method method = invocation.getMethod();
        final String metaMethodName = method.getName();
        final String calledFnName = ((NativeJavaMethod) _this).getFunctionName();
        if ("call".equals(metaMethodName))
        {
            // signature is call(Context cs, Scriptable scope, Scriptable thisObj, Object[] args)
            final Scriptable scope = (Scriptable) arguments[1];
            final Object _stringThis = arguments[2];
            final Object[] fnArgs = (Object[]) arguments[3];

            String backingString = null;
            if (_stringThis instanceof NativeJavaObject)
            {
                final Object unwrapped = ((NativeJavaObject) _stringThis).unwrap();
                if (unwrapped instanceof String)
                {
                    backingString = (String) unwrapped;
                }
            }

            if (backingString != null)
            {
                if (REGEX_FN_NAMES.contains(calledFnName) && fnArgs[0] instanceof NativeRegExp)
                {
                    final Scriptable nativeString = ScriptRuntime.toObject(Context.getCurrentContext(), scope, backingString);
                    result = ScriptableObject.callMethod(nativeString, calledFnName, fnArgs);
                }
                // TODO Need to handle other fn/method constellations
                else
                {
                    result = invocation.proceed();
                }
            }
            else
            {
                result = invocation.proceed();
            }
        }
        else
        {
            result = invocation.proceed();
        }
    }
    else
    {
        result = invocation.proceed();
    }

    return result;
}