Package org.springframework.scripting

Examples of org.springframework.scripting.ScriptSource


     * @return the corresponding ScriptSource instance
     * @see #convertToScriptSource
     */
    protected ScriptSource getScriptSource(String beanName, String scriptSourceLocator) {
        synchronized (this.scriptSourceCache) {
            ScriptSource scriptSource = this.scriptSourceCache.get(beanName);
            if (scriptSource == null) {
                scriptSource = convertToScriptSource(beanName, scriptSourceLocator, this.resourceLoader);
                this.scriptSourceCache.put(beanName, scriptSource);
            }
            return scriptSource;
View Full Code Here


    @Test
    public void test() throws ExecutionException, InterruptedException {
        ScriptEvaluator scriptEvaluator = new GroovyScriptEvaluator();

        //ResourceScriptSource 外部的
        ScriptSource source = new StaticScriptSource("i+j");
        Map<String, Object> args = new HashMap<>();
        args.put("i", 1);
        args.put("j", 2);
        System.out.println(scriptEvaluator.evaluate(source, args));
    }
View Full Code Here

   * @return the corresponding ScriptSource instance
   * @see #convertToScriptSource
   */
  protected ScriptSource getScriptSource(String beanName, String scriptSourceLocator) {
    synchronized (this.scriptSourceCache) {
      ScriptSource scriptSource = this.scriptSourceCache.get(beanName);
      if (scriptSource == null) {
        scriptSource = convertToScriptSource(beanName, scriptSourceLocator, this.resourceLoader);
        this.scriptSourceCache.put(beanName, scriptSource);
      }
      return scriptSource;
View Full Code Here

      String scriptFactoryBeanName = SCRIPT_FACTORY_NAME_PREFIX + beanName;
      String scriptedObjectBeanName = SCRIPTED_OBJECT_NAME_PREFIX + beanName;
      prepareScriptBeans(bd, scriptFactoryBeanName, scriptedObjectBeanName);

      ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
      ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
      Class<?>[] interfaces = scriptFactory.getScriptInterfaces();

      Class<?> scriptedType = scriptFactory.getScriptedObjectType(scriptSource);
      if (scriptedType != null) {
        return scriptedType;
View Full Code Here

    String scriptFactoryBeanName = SCRIPT_FACTORY_NAME_PREFIX + beanName;
    String scriptedObjectBeanName = SCRIPTED_OBJECT_NAME_PREFIX + beanName;
    prepareScriptBeans(bd, scriptFactoryBeanName, scriptedObjectBeanName);

    ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName, ScriptFactory.class);
    ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName, scriptFactory.getScriptSourceLocator());
    boolean isFactoryBean = false;
    try {
      Class<?> scriptedObjectType = scriptFactory.getScriptedObjectType(scriptSource);
      // Returned type may be null if the factory is unable to determine the type.
      if (scriptedObjectType != null) {
View Full Code Here

        this.scriptBeanFactory.registerBeanDefinition(scriptFactoryBeanName,
            createScriptFactoryBeanDefinition(bd));
        ScriptFactory scriptFactory = this.scriptBeanFactory
            .getBean(scriptFactoryBeanName, ScriptFactory.class);
        ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName,
            scriptFactory.getScriptSourceLocator());
        Class<?>[] interfaces = scriptFactory.getScriptInterfaces();

        Class<?>[] scriptedInterfaces = interfaces;
        if (scriptFactory.requiresConfigInterface() && !bd.getPropertyValues().isEmpty()) {
View Full Code Here

      assertTrue(ex.contains(ScriptCompilationException.class));
    }
  }

  public void testScriptThatCompilesButIsJustPlainBad() throws Exception {
    ScriptSource script = mock(ScriptSource.class);
    final String badScript = "String getMessage() { throw new IllegalArgumentException(); }";
    given(script.getScriptAsString()).willReturn(badScript);
    given(script.isModified()).willReturn(true);
    BshScriptFactory factory = new BshScriptFactory(
        ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript, Messenger.class);
    try {
      Messenger messenger = (Messenger) factory.getScriptedObject(script, Messenger.class);
      messenger.getMessage();
View Full Code Here

    }
  }

  @Test
  public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception {
    ScriptSource script = mock(ScriptSource.class);
    final String badScript = "class Foo { public Foo(String foo) {}}";
    given(script.getScriptAsString()).willReturn(badScript);
    given(script.suggestedClassName()).willReturn("someName");
    GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX
        + badScript);
    try {
      factory.getScriptedObject(script);
      fail("Must have thrown a ScriptCompilationException (no public no-arg ctor in scripted class).");
View Full Code Here

    }
  }

  @Test
  public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception {
    ScriptSource script = mock(ScriptSource.class);
    final String badScript = "class Foo { protected Foo() {}}";
    given(script.getScriptAsString()).willReturn(badScript);
    given(script.suggestedClassName()).willReturn("someName");
    GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX
        + badScript);
    try {
      factory.getScriptedObject(script);
      fail("Must have thrown a ScriptCompilationException (no oublic no-arg ctor in scripted class).");
View Full Code Here

    }
  }

  @Test
  public void testGetScriptedObjectDoesNotChokeOnNullInterfacesBeingPassedIn() throws Exception {
    ScriptSource script = mock(ScriptSource.class);
    given(script.getScriptAsString()).willReturn("class Bar {}");
    given(script.suggestedClassName()).willReturn("someName");

    GroovyScriptFactory factory = new GroovyScriptFactory("a script source locator (doesn't matter here)");
    Object scriptedObject = factory.getScriptedObject(script);
    assertNotNull(scriptedObject);
  }
View Full Code Here

TOP

Related Classes of org.springframework.scripting.ScriptSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.