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


Java Bindings类代码示例

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


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

示例1: readVariableValues

import javax.script.Bindings; //导入依赖的package包/类
/**
 * Reads the variables from JShell into bindings.
 */
private void readVariableValues(Bindings globalBindings, Bindings engineBindings) {
	jshell.variables().forEach(varSnippet -> {
		try {
			String name = varSnippet.name();
			Object value = executionControl.getActualVarValue(varSnippet);
			if(globalBindings != null && !engineBindings.containsKey(name) && globalBindings.containsKey(name)) {
				globalBindings.put(name, value);
			} else {
				engineBindings.put(name, value);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	});
}
 
开发者ID:dmac100,项目名称:JShellScriptEngine,代码行数:19,代码来源:JShellScriptEngine.java

示例2: getAttributesFromInlineGroovyScript

import javax.script.Bindings; //导入依赖的package包/类
private static Map<String, Object> getAttributesFromInlineGroovyScript(final Map<String, Object> attributes,
                                                                       final Matcher matcherInline) throws ScriptException {
    final String script = matcherInline.group(1).trim();
    final ScriptEngine engine = new ScriptEngineManager().getEngineByName("groovy");
    if (engine == null) {
        LOGGER.warn("Script engine is not available for Groovy");
        return new HashMap<>();
    }
    final Object[] args = {attributes, LOGGER};
    LOGGER.debug("Executing script, with parameters [{}]", args);

    final Bindings binding = new SimpleBindings();
    binding.put("attributes", attributes);
    binding.put("logger", LOGGER);
    return (Map<String, Object>) engine.eval(script, binding);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:ScriptedRegisteredServiceAttributeReleasePolicy.java

示例3: appendTo

import javax.script.Bindings; //导入依赖的package包/类
public static void appendTo(Bindings bindings) {
    // standard java collections
    bindings.put("newArrayList", ARRAY_LIST);
    bindings.put("newLinkedList", LINKED_LIST);
    bindings.put("newHashSet", HASH_SET);
    bindings.put("newHashMap", HASH_MAP);
    bindings.put("newCopyOnWriteArrayList", COPY_ON_WRITE_ARRAY_LIST);
    bindings.put("newConcurrentHashSet", CONCURRENT_HASH_SET);
    bindings.put("newConcurrentHashMap", CONCURRENT_HASH_MAP);

    bindings.put("listOf", LIST_OF);
    bindings.put("setOf", SET_OF);

    // guava immutables
    bindings.put("immutableListOf", IMMUTABLE_LIST_OF);
    bindings.put("immutableSetOf", IMMUTABLE_SET_OF);

    // misc
    bindings.put("parseUuid", PARSE_UUID);
}
 
开发者ID:lucko,项目名称:helper,代码行数:21,代码来源:GeneralScriptBindings.java

示例4: appendTo

import javax.script.Bindings; //导入依赖的package包/类
@Override
public void appendTo(@Nonnull Bindings bindings) {

    // provide exports to access the exports registry & core server classes
    bindings.put("exports", exports);
    bindings.put("server", Bukkit.getServer());
    bindings.put("plugin", plugin);
    bindings.put("services", Bukkit.getServicesManager());

    // some util functions
    bindings.put("colorize", (Function<Object, String>) HelperScriptBindings::colorize);
    bindings.put("newMetadataKey", (Function<Object, MetadataKey>) HelperScriptBindings::newMetadataKey);
    bindings.put("newEmptyScheme", (Supplier<MenuScheme>) HelperScriptBindings::newScheme);
    bindings.put("newScheme", (Function<SchemeMapping, MenuScheme>) HelperScriptBindings::newScheme);

    // some general functions for working with java collections in js
    GeneralScriptBindings.appendTo(bindings);

    // provide hook into the resolvePackageWildcard method below, used by the importWildcardPackage function
    bindings.put("resolvePackageWildcard", (Function<String, List<String>>) HelperScriptBindings::resolvePackageWildcard);
}
 
开发者ID:lucko,项目名称:helper,代码行数:22,代码来源:HelperScriptBindings.java

示例5: transformCombination

import javax.script.Bindings; //导入依赖的package包/类
private IJsonType transformCombination( JsonSchemaType parent, URL enclosing, String name, Bindings jsonObj )
{
  IJsonType type = transformAllOf( parent, enclosing, name, jsonObj );
  if( type != null )
  {
    return type;
  }

  type = transformAnyOf( parent, enclosing, name, jsonObj );
  if( type != null )
  {
    return type;
  }

  return transformOneOf( parent, enclosing, name, jsonObj );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:17,代码来源:JsonSchemaTransformer.java

示例6: findReferenceTypeOrCombinationType

import javax.script.Bindings; //导入依赖的package包/类
private IJsonType findReferenceTypeOrCombinationType( JsonSchemaType parent, URL enclosing, String name, Bindings jsonObj )
{
  IJsonType result;
  result = findReference( parent, enclosing, jsonObj );
  if( result == null )
  {
    result = transformCombination( parent, enclosing, name, jsonObj );
    if( result == null )
    {
      result = deriveTypeFromEnum( jsonObj );
      if( result == null )
      {
        // No type or other means of deriving a type could be found.
        // Default type is Dynamic (in Java this is Object)
        result = DynamicType.instance();
      }
    }
  }
  return result;
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:21,代码来源:JsonSchemaTransformer.java

示例7: makeValue

import javax.script.Bindings; //导入依赖的package包/类
/**
 * Convert the Object to a String value suitable for a Json Url argument.
 * @param value A Json value.  On of: Bindings, List, or simple value.
 * @return Json formatted value String.
 */
@Extension
public static String makeValue( Object value )
{
  if( value instanceof Bindings )
  {
    value = JsonUtil.toJson( (Bindings)value );
  }
  else if( value instanceof List )
  {
    value = JsonUtil.listToJson( (List)value );
  }

  try
  {
    return URLEncoder.encode( value.toString(), "UTF-8" );
  }
  catch( UnsupportedEncodingException e )
  {
    throw new RuntimeException( e );
  }
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:27,代码来源:ManBindingsExt.java

示例8: transferIssuesFromErrantType

import javax.script.Bindings; //导入依赖的package包/类
private void transferIssuesFromErrantType( JsonSchemaType parent, IJsonType result, Bindings jsonObj )
{
  if( result instanceof ErrantType )
  {
    Object value = jsonObj.get( JSCH_REF );
    Token token = null;
    if( value instanceof Pair )
    {
      token = ((Token[])((Pair)value).getFirst())[1];
    }

    for( JsonIssue issue: ((ErrantType)result).getIssues() )
    {
      parent.addIssue( new JsonIssue( issue.getKind(), token, issue.getMessage() ) );
    }
  }
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:18,代码来源:JsonSchemaTransformer.java

示例9: parseJson

import javax.script.Bindings; //导入依赖的package包/类
@Override
public Bindings parseJson( String jsonText, boolean withBigNumbers, boolean withTokens ) throws ScriptException
{
  SimpleParserImpl parser = new SimpleParserImpl( new Tokenizer( new StringReader( jsonText ) ), withBigNumbers );
  Object result = parser.parse( withTokens );
  List<String> errors = parser.getErrors();
  if( errors.size() != 0 )
  {
    StringBuilder sb = new StringBuilder( "Found errors:\n" );
    for( String err : errors )
    {
      sb.append( err ).append( "\n" );
    }
    throw new ScriptException( sb.toString() );
  }
  if( result instanceof Pair )
  {
    result = ((Pair)result).getSecond();
  }
  if( result instanceof Bindings )
  {
    return (Bindings)result;
  }
  return NashornJsonParser.wrapValueInBindings( result );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:26,代码来源:DefaultParser.java

示例10: getGuardedInvocation

import javax.script.Bindings; //导入依赖的package包/类
@Override
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception {
    final Object self = request.getReceiver();
    final CallSiteDescriptor desc = request.getCallSiteDescriptor();
    if (self == null || !canLinkTypeStatic(self.getClass())) {
        return null;
    }

    GuardedInvocation inv;
    if (self instanceof JSObject) {
        inv = lookup(desc, request, linkerServices);
        inv = inv.replaceMethods(linkerServices.filterInternalObjects(inv.getInvocation()), inv.getGuard());
    } else if (self instanceof Map || self instanceof Bindings) {
        // guard to make sure the Map or Bindings does not turn into JSObject later!
        final GuardedInvocation beanInv = nashornBeansLinker.getGuardedInvocation(request, linkerServices);
        inv = new GuardedInvocation(beanInv.getInvocation(),
            NashornGuards.combineGuards(beanInv.getGuard(), NashornGuards.getNotJSObjectGuard()));
    } else {
        throw new AssertionError("got instanceof: " + self.getClass()); // Should never reach here.
    }

    return Bootstrap.asTypeSafeReturn(inv, linkerServices, desc);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:JSObjectLinker.java

示例11: createBindingsTest

import javax.script.Bindings; //导入依赖的package包/类
@Test
public void createBindingsTest() {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    final Bindings b = e.createBindings();
    b.put("foo", 42.0);
    Object res = null;
    try {
        res = e.eval("foo == 42.0", b);
    } catch (final ScriptException | NullPointerException se) {
        se.printStackTrace();
        fail(se.getMessage());
    }

    assertEquals(res, Boolean.TRUE);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ScopeTest.java

示例12: userEngineScopeBindingsRetentionTest

import javax.script.Bindings; //导入依赖的package包/类
@Test
public void userEngineScopeBindingsRetentionTest() throws ScriptException {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    final ScriptContext newContext = new SimpleScriptContext();
    newContext.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);
    e.eval("function foo() {}", newContext);

    // definition retained with user's ENGINE_SCOPE Binding
    assertTrue(e.eval("typeof foo", newContext).equals("function"));

    final Bindings oldBindings = newContext.getBindings(ScriptContext.ENGINE_SCOPE);
    // but not in another ENGINE_SCOPE binding
    newContext.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);
    assertTrue(e.eval("typeof foo", newContext).equals("undefined"));

    // restore ENGINE_SCOPE and check again
    newContext.setBindings(oldBindings, ScriptContext.ENGINE_SCOPE);
    assertTrue(e.eval("typeof foo", newContext).equals("function"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ScopeTest.java

示例13: multiThreadedPrimitiveTest

import javax.script.Bindings; //导入依赖的package包/类
/**
 * Test multi-threaded access to primitive prototype properties for shared script classes with multiple globals.
 */
@Test
public static void multiThreadedPrimitiveTest() throws ScriptException, InterruptedException {
    final ScriptEngineManager m = new ScriptEngineManager();
    final ScriptEngine e = m.getEngineByName("nashorn");
    final Bindings b = e.createBindings();
    final ScriptContext origContext = e.getContext();
    final ScriptContext newCtxt = new SimpleScriptContext();
    newCtxt.setBindings(b, ScriptContext.ENGINE_SCOPE);

    final Object obj1 = e.eval("String.prototype.foo = 'original context';", origContext);
    final Object obj2 = e.eval("String.prototype.foo = 'new context';", newCtxt);
    assertEquals(obj1, "original context");
    assertEquals(obj2, "new context");
    final String sharedScript = "''.foo";

    final Thread t1 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000));
    final Thread t2 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "new context", 1000));
    t1.start();
    t2.start();
    t1.join();
    t2.join();

    final Object obj3 = e.eval("delete String.prototype.foo; Object.prototype.foo = 'newer context';", newCtxt);
    assertEquals(obj3, "newer context");
    final Thread t3 = new Thread(new ScriptRunner(e, origContext, sharedScript, "original context", 1000));
    final Thread t4 = new Thread(new ScriptRunner(e, newCtxt, sharedScript, "newer context", 1000));

    t3.start();
    t4.start();
    t3.join();
    t4.join();

    Assert.assertEquals(e.eval(sharedScript), "original context");
    Assert.assertEquals(e.eval(sharedScript, newCtxt), "newer context");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:ScopeTest.java

示例14: getBindings

import javax.script.Bindings; //导入依赖的package包/类
@SuppressWarnings("unused")
protected Bindings getBindings( Object value )
{
  if( value instanceof Pair )
  {
    return getBindings( ((Pair)value).getSecond() );
  }
  if( value instanceof Bindings )
  {
    return (Bindings)value;
  }
  if( value instanceof JsonImplBase )
  {
    return ((JsonImplBase)value)._bindings;
  }
  throw new IllegalStateException( "Unhandled type: " + value.getClass() );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:18,代码来源:JsonImplBase.java

示例15: postForTextContent

import javax.script.Bindings; //导入依赖的package包/类
/**
 * Use http POST to pass JSON bindings to this URL and get back the full content as a String.
 * <p>
 * If an argument is a javax.script.Bindings or a List, it is transformed to JSON.  Otherwise,
 * the argument is coerced to a String.  All arguments are URL encoded.
 *
 * @return The full content of this URL coerced to a String.
 *
 * @see #postForJsonContent(URL, Bindings)
 */
public static String postForTextContent( @This URL url, Bindings bindings )
{
  try
  {
    byte[] bytes = bindings.makeArguments().getBytes( "UTF-8" );
    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    conn.setRequestMethod( "POST" );
    conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" );
    conn.setRequestProperty( "Content-Length", String.valueOf( bytes.length ) );
    conn.setDoOutput( true );
    try( OutputStream out = conn.getOutputStream() )
    {
      out.write( bytes );
    }
    try( Reader in = StreamUtil.getInputStreamReader( conn.getInputStream() ) )
    {
      return StreamUtil.getContent( in );
    }
  }
  catch( Exception e )
  {
    throw new RuntimeException( e );
  }
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:35,代码来源:ManUrlExt.java


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