当前位置: 首页>>代码示例>>Java>>正文


Java WrapFactory类代码示例

本文整理汇总了Java中org.mozilla.javascript.WrapFactory的典型用法代码示例。如果您正苦于以下问题:Java WrapFactory类的具体用法?Java WrapFactory怎么用?Java WrapFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WrapFactory类属于org.mozilla.javascript包,在下文中一共展示了WrapFactory类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initWrapFactory

import org.mozilla.javascript.WrapFactory; //导入依赖的package包/类
private void initWrapFactory( )
{
	WrapFactory wrapFactory = new WrapFactory( ) {

		protected IJavascriptWrapper coreWrapper = new CoreJavaScriptWrapper( );

		/**
		 * wrapper an java object to javascript object.
		 */
		public Object wrap( Context cx, Scriptable scope, Object obj,
				Class staticType )
		{
			Object object = coreWrapper.wrap( cx, scope, obj, staticType );
			if ( object != obj )
			{
				return object;
			}
			return super.wrap( cx, scope, obj, staticType );
		}
	};
	context.setWrapFactory( wrapFactory );
	new CoreJavaScriptInitializer( ).initialize( context, global );
}
 
开发者ID:eclipse,项目名称:birt,代码行数:24,代码来源:JavascriptEngine.java

示例2: setParameter

import org.mozilla.javascript.WrapFactory; //导入依赖的package包/类
public void setParameter(String name, String value) {
    if ("wrapFactory".equals(name)) {
        if (StringUtil.isEmpty(value)) {
            throw new IllegalParameterValueException(getClass(), name);
        }
        Class clazz = ObjectUtil.loadClass(value, WrapFactory.class);
        setWrapFactory((WrapFactory) ObjectUtil.newInstance(clazz));
    } else if ("blockSign".equals(name)) {
        if (StringUtil.isEmpty(value)) {
            throw new IllegalParameterValueException(getClass(), name);
        }
        setBlockSign(value);
    } else if ("useGetterScriptEmulation".equals("name")) {
        if (StringUtil.isEmpty(value)) {
            throw new IllegalParameterValueException(getClass(), name);
        }
        _useGetterScriptEmulation = ObjectUtil.booleanValue(value, false);
    }
    super.setParameter(name, value);
}
 
开发者ID:seasarorg,项目名称:mayaa,代码行数:21,代码来源:ScriptEnvironmentImpl.java

示例3: convertValueForScript

import org.mozilla.javascript.WrapFactory; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Object convertValueForScript(final Object value, final ValueConverter globalDelegate, final Class<?> expectedClass)
{
    // no further distinction - always delegate
    final Context currentContext = Context.getCurrentContext();
    final WrapFactory factory = currentContext.getWrapFactory();

    final Object result;

    // mark for recursion prevention (DelegatingWrapFactory may otherwise indirectly delegate back)
    this.currentConversions.get().add(value);
    try
    {
        Class<?> staticType = value.getClass();
        if (WRAPPER_TO_PRIMITIVE.containsKey(staticType))
        {
            staticType = WRAPPER_TO_PRIMITIVE.get(staticType);
        }
        // if conversion call is made in a scope-ful context, the caller needs to take care of setting parentScope for Scriptable
        result = factory.wrap(currentContext, null, value, staticType);
    }
    finally
    {
        this.currentConversions.get().remove(value);
    }

    // we tried to check in advance as best as possible in #canConvertValueForScript
    return expectedClass.isInstance(result) ? result : null;
}
 
开发者ID:AFaust,项目名称:alfresco-enhanced-script-environment,代码行数:33,代码来源:WrapFactoryConverter.java

示例4: getInstance

import org.mozilla.javascript.WrapFactory; //导入依赖的package包/类
static synchronized WrapFactory getInstance() {
    if (theInstance == null) {
        theInstance = new RhinoWrapFactory();
    }
    return theInstance;
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:7,代码来源:RhinoWrapFactory.java

示例5: makeContext

import org.mozilla.javascript.WrapFactory; //导入依赖的package包/类
@Override
protected TimeLimitContext makeContext()
{
	TimeLimitContext context = new TimeLimitContext();
	context.setWrapFactory(new WrapFactory()
	{
		@Override
		public Scriptable wrapAsJavaObject(Context cx, Scriptable scope, Object javaObject, java.lang.Class<?> staticType)
		{
			return new NativeJavaObject(scope, javaObject, getClass())
			{
				private static final long serialVersionUID = 1L;

				@Override
				public Object get(String name, Scriptable start)
				{
					if (name.equals("getClass")) return NOT_FOUND;
					return super.get(name, start);
				}
			};
		}
	});
	context.setClassShutter(new ClassShutter()
	{
		@Override
		public boolean visibleToScripts(String fullClassName)
		{
			Class<?> clz;
			try
			{
				clz = Class.forName(fullClassName);
			}
			catch (ClassNotFoundException e)
			{
				e.printStackTrace();
				return false;
			}
			if(ScriptBinding.class.isAssignableFrom(clz)) return true;
			if(clz.equals(String.class)) return true;
			return false;
		}
	});
	return context;
}
 
开发者ID:GTAUN,项目名称:wl-race,代码行数:45,代码来源:ScriptExecutorFactory.java

示例6: invoke

import org.mozilla.javascript.WrapFactory; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable
{
    final Object[] arguments = invocation.getArguments();
    Scriptable scope = null;
    for (int idx = 0; idx < arguments.length && scope == null; idx++)
    {
        if (arguments[idx] instanceof Scriptable)
        {
            scope = (Scriptable) arguments[idx];
        }
    }

    final Context cx = Context.getCurrentContext();
    final WrapFactory wrapFactory = cx.getWrapFactory();

    // disabling before and enabling after invocation with manual wrapping "seems" pointless
    // this pattern is actually not meant for "this" invocation, but for any calls from Java code to any native script object to avoid
    // polluting Java scope with special AOP-enhanced script objects that Java code may not be able to handle
    if (wrapFactory instanceof DelegatingWrapFactory)
    {
        ((DelegatingWrapFactory) wrapFactory).disableWrap();
    }

    Object result;
    try
    {
        result = invocation.proceed();
    }
    finally
    {
        if (wrapFactory instanceof DelegatingWrapFactory)
        {
            ((DelegatingWrapFactory) wrapFactory).enableWrap();
        }
    }

    if (result != null && Undefined.instance != result && Scriptable.NOT_FOUND != result)
    {
        result = Context.jsToJava(result, Object.class);

        // even if signature may not use primitve, we prefer them (this also avoids wrapping them)
        Class<?> staticType = result.getClass();
        if (WRAPPER_TO_PRIMITIVE.containsKey(staticType))
        {
            staticType = WRAPPER_TO_PRIMITIVE.get(staticType);
        }

        result = wrapFactory.wrap(cx, scope != null ? scope : DUMMY_SCOPE, result, staticType);
    }
    return result;
}
 
开发者ID:AFaust,项目名称:alfresco-enhanced-script-environment,代码行数:56,代码来源:NativeJavaMethodWrapFactoryInterceptor.java

示例7: setWrapFactory

import org.mozilla.javascript.WrapFactory; //导入依赖的package包/类
static void setWrapFactory(WrapFactory wrap) {
    _wrap = wrap;
}
 
开发者ID:seasarorg,项目名称:mayaa,代码行数:4,代码来源:ScriptEnvironmentImpl.java

示例8: getWrapFactory

import org.mozilla.javascript.WrapFactory; //导入依赖的package包/类
static WrapFactory getWrapFactory() {
    return _wrap;
}
 
开发者ID:seasarorg,项目名称:mayaa,代码行数:4,代码来源:ScriptEnvironmentImpl.java

示例9: enter

import org.mozilla.javascript.WrapFactory; //导入依赖的package包/类
/**
 * カレントスレッドに関連付いたContextを取得します。
 * 同時にScriptEnvironmentからWrapFactoryを取得してContextにセットします。
 * Rhinoスクリプト実行前に、Context.enter()の代わりに利用します。
 * これを実行したあとは、try {} finally {} を使って Context.exit() を
 * 必ず実行する必要があります。
 *
 * @return カレントスレッドに関連付いたContext
 */
public static Context enter() {
    Context cx = Context.enter();
    WrapFactory factory = ScriptEnvironmentImpl.getWrapFactory();
    if (factory != null) {
        cx.setWrapFactory(factory);
    }
    return cx;
}
 
开发者ID:seasarorg,项目名称:mayaa,代码行数:18,代码来源:RhinoUtil.java


注:本文中的org.mozilla.javascript.WrapFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。