JSR-223 based StandardScriptFactory (including <lang:std> support)
This commit also completes 4.2 schema variants in spring-context. Issue: SPR-5215
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -90,6 +90,35 @@ public class GroovyScriptFactoryTests {
|
||||
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticScriptUsingJsr223() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContextWithJsr223.xml", getClass());
|
||||
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Calculator.class)).contains("calculator"));
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messenger"));
|
||||
|
||||
Calculator calc = (Calculator) ctx.getBean("calculator");
|
||||
Messenger messenger = (Messenger) ctx.getBean("messenger");
|
||||
|
||||
assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(calc));
|
||||
assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger));
|
||||
|
||||
assertFalse("Scripted object should not be instance of Refreshable", calc instanceof Refreshable);
|
||||
assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);
|
||||
|
||||
assertEquals(calc, calc);
|
||||
assertEquals(messenger, messenger);
|
||||
assertTrue(!messenger.equals(calc));
|
||||
assertTrue(messenger.hashCode() != calc.hashCode());
|
||||
assertTrue(!messenger.toString().equals(calc.toString()));
|
||||
|
||||
String desiredMessage = "Hello World!";
|
||||
assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
|
||||
|
||||
assertTrue(ctx.getBeansOfType(Calculator.class).values().contains(calc));
|
||||
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticPrototypeScript() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
|
||||
@@ -109,6 +138,25 @@ public class GroovyScriptFactoryTests {
|
||||
assertEquals("Byebye World!", messenger2.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticPrototypeScriptUsingJsr223() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContextWithJsr223.xml", getClass());
|
||||
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
||||
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
|
||||
|
||||
assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger));
|
||||
assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);
|
||||
|
||||
assertNotSame(messenger, messenger2);
|
||||
assertSame(messenger.getClass(), messenger2.getClass());
|
||||
assertEquals("Hello World!", messenger.getMessage());
|
||||
assertEquals("Hello World!", messenger2.getMessage());
|
||||
messenger.setMessage("Bye World!");
|
||||
messenger2.setMessage("Byebye World!");
|
||||
assertEquals("Bye World!", messenger.getMessage());
|
||||
assertEquals("Byebye World!", messenger2.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticScriptWithInstance() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
|
||||
@@ -123,6 +171,20 @@ public class GroovyScriptFactoryTests {
|
||||
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticScriptWithInstanceUsingJsr223() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContextWithJsr223.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstance"));
|
||||
Messenger messenger = (Messenger) ctx.getBean("messengerInstance");
|
||||
|
||||
assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger));
|
||||
assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);
|
||||
|
||||
String desiredMessage = "Hello World!";
|
||||
assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
|
||||
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticScriptWithInlineDefinedInstance() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContext.xml", getClass());
|
||||
@@ -137,6 +199,20 @@ public class GroovyScriptFactoryTests {
|
||||
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticScriptWithInlineDefinedInstanceUsingJsr223() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContextWithJsr223.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstanceInline"));
|
||||
Messenger messenger = (Messenger) ctx.getBean("messengerInstanceInline");
|
||||
|
||||
assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger));
|
||||
assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);
|
||||
|
||||
String desiredMessage = "Hello World!";
|
||||
assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
|
||||
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonStaticScript() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyRefreshableContext.xml", getClass());
|
||||
@@ -311,8 +387,6 @@ public class GroovyScriptFactoryTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
// see http://build.springframework.org/browse/SPR-TRUNKQUICK-908
|
||||
@Test
|
||||
public void testResourceScriptFromTag() throws Exception {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd.xml", getClass());
|
||||
@@ -409,6 +483,49 @@ public class GroovyScriptFactoryTests {
|
||||
assertEquals(4, beans.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsr223FromTag() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-jsr223.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messenger"));
|
||||
Messenger messenger = (Messenger) ctx.getBean("messenger");
|
||||
assertFalse(AopUtils.isAopProxy(messenger));
|
||||
assertEquals("Hello World!", messenger.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsr223FromTagWithInterface() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-jsr223.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithInterface"));
|
||||
Messenger messenger = (Messenger) ctx.getBean("messengerWithInterface");
|
||||
assertFalse(AopUtils.isAopProxy(messenger));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshableJsr223FromTag() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-jsr223.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));
|
||||
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
|
||||
assertTrue(AopUtils.isAopProxy(messenger));
|
||||
assertTrue(messenger instanceof Refreshable);
|
||||
assertEquals("Hello World!", messenger.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineJsr223FromTag() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-jsr223.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("inlineMessenger"));
|
||||
Messenger messenger = (Messenger) ctx.getBean("inlineMessenger");
|
||||
assertFalse(AopUtils.isAopProxy(messenger));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineJsr223FromTagWithInterface() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-jsr223.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("inlineMessengerWithInterface"));
|
||||
Messenger messenger = (Messenger) ctx.getBean("inlineMessengerWithInterface");
|
||||
assertFalse(AopUtils.isAopProxy(messenger));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the SPR-2098 bug whereby no more than 1 property element could be
|
||||
* passed to a scripted bean :(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -64,6 +64,27 @@ public class JRubyScriptFactoryTests {
|
||||
assertNotSame(messenger.hashCode(), calc.hashCode());
|
||||
assertTrue(!messenger.toString().equals(calc.toString()));
|
||||
|
||||
assertEquals(3, calc.add(1, 2));
|
||||
String desiredMessage = "Hello World!";
|
||||
assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticScriptUsingJsr223() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("jrubyContextWithJsr223.xml", getClass());
|
||||
Calculator calc = (Calculator) ctx.getBean("calculator");
|
||||
Messenger messenger = (Messenger) ctx.getBean("messenger");
|
||||
|
||||
assertFalse("Scripted object should not be instance of Refreshable", calc instanceof Refreshable);
|
||||
assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);
|
||||
|
||||
assertEquals(calc, calc);
|
||||
assertEquals(messenger, messenger);
|
||||
assertTrue(!messenger.equals(calc));
|
||||
assertNotSame(messenger.hashCode(), calc.hashCode());
|
||||
assertTrue(!messenger.toString().equals(calc.toString()));
|
||||
|
||||
assertEquals(3, calc.add(1, 2));
|
||||
String desiredMessage = "Hello World!";
|
||||
assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
|
||||
}
|
||||
@@ -163,6 +184,15 @@ public class JRubyScriptFactoryTests {
|
||||
assertEquals(testBean, messengerByName.getTestBean());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResourceScriptFromTagUsingJsr223() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd-jsr223.xml", getClass());
|
||||
|
||||
Messenger messenger = (Messenger) ctx.getBean("messenger");
|
||||
assertEquals("Hello World!", messenger.getMessage());
|
||||
assertFalse(messenger instanceof Refreshable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrototypeScriptFromTag() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd.xml", getClass());
|
||||
@@ -185,6 +215,16 @@ public class JRubyScriptFactoryTests {
|
||||
Calculator calculator = (Calculator) ctx.getBean("calculator");
|
||||
assertNotNull(calculator);
|
||||
assertFalse(calculator instanceof Refreshable);
|
||||
assertEquals(3, calculator.add(1, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineScriptFromTagUsingJsr223() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd-jsr223.xml", getClass());
|
||||
Calculator calculator = (Calculator) ctx.getBean("calculator");
|
||||
assertNotNull(calculator);
|
||||
assertFalse(calculator instanceof Refreshable);
|
||||
assertEquals(3, calculator.add(1, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -195,6 +235,15 @@ public class JRubyScriptFactoryTests {
|
||||
assertTrue("Messenger should be Refreshable", messenger instanceof Refreshable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshableFromTagUsingJsr223() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd-jsr223.xml", getClass());
|
||||
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
|
||||
assertEquals("Hello World!", messenger.getMessage());
|
||||
assertTrue("Messenger should be Refreshable", messenger instanceof Refreshable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatMultipleScriptInterfacesAreSupported() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd.xml", getClass());
|
||||
Messenger messenger = (Messenger) ctx.getBean("calculatingMessenger");
|
||||
@@ -214,6 +263,15 @@ public class JRubyScriptFactoryTests {
|
||||
assertEquals(1, printable.count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithComplexArgUsingJsr223() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("jrubyContextWithJsr223.xml", getClass());
|
||||
Printer printer = (Printer) ctx.getBean("printer");
|
||||
CountingPrintable printable = new CountingPrintable();
|
||||
printer.print(printable);
|
||||
assertEquals(1, printable.count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithPrimitiveArgsInReturnTypeAndParameters() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("jrubyContextForPrimitives.xml", getClass());
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.scripting.support;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.target.dynamic.Refreshable;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.scripting.Messenger;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* {@link StandardScriptFactory} (lang:std) tests for JavaScript.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 4.2
|
||||
*/
|
||||
public class StandardScriptFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testJsr223FromTagWithInterface() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("jsr223-with-xsd.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithInterface"));
|
||||
Messenger messenger = (Messenger) ctx.getBean("messengerWithInterface");
|
||||
assertFalse(AopUtils.isAopProxy(messenger));
|
||||
assertEquals("Hello World!", messenger.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshableJsr223FromTagWithInterface() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("jsr223-with-xsd.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessengerWithInterface"));
|
||||
Messenger messenger = (Messenger) ctx.getBean("refreshableMessengerWithInterface");
|
||||
assertTrue(AopUtils.isAopProxy(messenger));
|
||||
assertTrue(messenger instanceof Refreshable);
|
||||
assertEquals("Hello World!", messenger.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineJsr223FromTagWithInterface() throws Exception {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("jsr223-with-xsd.xml", getClass());
|
||||
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("inlineMessengerWithInterface"));
|
||||
Messenger messenger = (Messenger) ctx.getBean("inlineMessengerWithInterface");
|
||||
assertFalse(AopUtils.isAopProxy(messenger));
|
||||
assertEquals("Hello World!", messenger.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:lang="http://www.springframework.org/schema/lang"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.2.xsd">
|
||||
|
||||
<lang:std id="messenger" script-source="classpath:org/springframework/scripting/groovy/Messenger.groovy">
|
||||
<lang:property name="message" value="Hello World!"/>
|
||||
</lang:std>
|
||||
|
||||
<lang:std id="messengerWithInterface" script-source="classpath:org/springframework/scripting/groovy/Messenger.groovy"
|
||||
script-interfaces="org.springframework.scripting.Messenger"/>
|
||||
|
||||
<lang:std id="refreshableMessenger" refresh-check-delay="5000"
|
||||
script-source="classpath:org/springframework/scripting/groovy/Messenger.groovy">
|
||||
<lang:property name="message" value="Hello World!"/>
|
||||
</lang:std>
|
||||
|
||||
<lang:std id="inlineMessenger" engine="Groovy">
|
||||
<lang:inline-script>
|
||||
package org.springframework.scripting.groovy;
|
||||
import org.springframework.scripting.Messenger
|
||||
class GroovyMessenger implements Messenger {
|
||||
def String message;
|
||||
}
|
||||
return new GroovyMessenger();
|
||||
</lang:inline-script>
|
||||
</lang:std>
|
||||
|
||||
<lang:std id="inlineMessengerWithInterface" engine="Groovy" script-interfaces="org.springframework.scripting.Messenger">
|
||||
<lang:inline-script>
|
||||
package org.springframework.scripting.groovy;
|
||||
import org.springframework.scripting.Messenger
|
||||
class GroovyMessenger implements Messenger {
|
||||
def String message;
|
||||
}
|
||||
return new GroovyMessenger();
|
||||
</lang:inline-script>
|
||||
</lang:std>
|
||||
|
||||
</beans>
|
||||
@@ -3,12 +3,11 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:lang="http://www.springframework.org/schema/lang"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
|
||||
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd">
|
||||
|
||||
<lang:groovy id="refreshableMessenger" refresh-check-delay="5000" proxy-target-class="true"
|
||||
script-source="classpath:org/springframework/scripting/groovy/Messenger.groovy">
|
||||
<lang:property name="message" value="Hello World!" />
|
||||
script-source="classpath:org/springframework/scripting/groovy/Messenger.groovy">
|
||||
<lang:property name="message" value="Hello World!"/>
|
||||
</lang:groovy>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -33,7 +33,7 @@ class GroovyCalculator implements Calculator {
|
||||
return x + y;
|
||||
}
|
||||
}
|
||||
</lang:inline-script>
|
||||
</lang:inline-script>
|
||||
</lang:groovy>
|
||||
|
||||
<lang:groovy id="customizer">
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
|
||||
<bean class="org.springframework.scripting.support.ScriptFactoryPostProcessor"/>
|
||||
|
||||
<bean id="calculator"
|
||||
class="org.springframework.scripting.groovy.GroovyScriptFactory">
|
||||
<bean id="calculator" class="org.springframework.scripting.groovy.GroovyScriptFactory">
|
||||
<constructor-arg>
|
||||
<value>inline:
|
||||
package org.springframework.scripting.groovy;
|
||||
@@ -25,28 +24,24 @@ class GroovyCalculator implements Calculator {
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="messenger"
|
||||
class="org.springframework.scripting.groovy.GroovyScriptFactory">
|
||||
<bean id="messenger" class="org.springframework.scripting.groovy.GroovyScriptFactory">
|
||||
<constructor-arg value="classpath:org/springframework/scripting/groovy/Messenger.groovy"/>
|
||||
<property name="message" value="Hello World!"/>
|
||||
</bean>
|
||||
|
||||
<bean id="messengerPrototype"
|
||||
class="org.springframework.scripting.groovy.GroovyScriptFactory"
|
||||
<bean id="messengerPrototype" class="org.springframework.scripting.groovy.GroovyScriptFactory"
|
||||
scope="prototype">
|
||||
<constructor-arg value="classpath:org/springframework/scripting/groovy/Messenger.groovy"/>
|
||||
<property name="message" value="Hello World!"/>
|
||||
</bean>
|
||||
|
||||
<bean id="messengerInstance"
|
||||
class="org.springframework.scripting.groovy.GroovyScriptFactory">
|
||||
<bean id="messengerInstance" class="org.springframework.scripting.groovy.GroovyScriptFactory">
|
||||
<constructor-arg value="classpath:org/springframework/scripting/groovy/MessengerInstance.groovy"/>
|
||||
<property name="message" ref="myMessage"/>
|
||||
</bean>
|
||||
|
||||
<bean id="messengerInstanceInline"
|
||||
class="org.springframework.scripting.groovy.GroovyScriptFactory">
|
||||
<constructor-arg>
|
||||
<bean id="messengerInstanceInline" class="org.springframework.scripting.groovy.GroovyScriptFactory">
|
||||
<constructor-arg>
|
||||
<value>inline:
|
||||
package org.springframework.scripting.groovy;
|
||||
import org.springframework.scripting.Messenger
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:lang="http://www.springframework.org/schema/lang"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<bean class="org.springframework.scripting.support.ScriptFactoryPostProcessor"/>
|
||||
|
||||
<bean id="calculator" class="org.springframework.scripting.support.StandardScriptFactory">
|
||||
<constructor-arg value="Groovy"/>
|
||||
<constructor-arg>
|
||||
<value>inline:
|
||||
package org.springframework.scripting.groovy;
|
||||
import org.springframework.scripting.Calculator
|
||||
class GroovyCalculator implements Calculator {
|
||||
int add(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
}
|
||||
</value>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="messenger" class="org.springframework.scripting.support.StandardScriptFactory">
|
||||
<constructor-arg value="classpath:org/springframework/scripting/groovy/Messenger.groovy"/>
|
||||
<property name="message" value="Hello World!"/>
|
||||
</bean>
|
||||
|
||||
<bean id="messengerPrototype" class="org.springframework.scripting.support.StandardScriptFactory"
|
||||
scope="prototype">
|
||||
<constructor-arg value="classpath:org/springframework/scripting/groovy/Messenger.groovy"/>
|
||||
<property name="message" value="Hello World!"/>
|
||||
</bean>
|
||||
|
||||
<bean id="messengerInstance" class="org.springframework.scripting.support.StandardScriptFactory">
|
||||
<constructor-arg value="classpath:org/springframework/scripting/groovy/MessengerInstance.groovy"/>
|
||||
<property name="message" ref="myMessage"/>
|
||||
</bean>
|
||||
|
||||
<bean id="messengerInstanceInline" class="org.springframework.scripting.support.StandardScriptFactory">
|
||||
<constructor-arg value="Groovy"/>
|
||||
<constructor-arg>
|
||||
<value>inline:
|
||||
package org.springframework.scripting.groovy;
|
||||
import org.springframework.scripting.Messenger
|
||||
class GroovyMessenger implements Messenger {
|
||||
def String message;
|
||||
}
|
||||
return new GroovyMessenger();
|
||||
</value>
|
||||
</constructor-arg>
|
||||
<property name="message" ref="myMessage"/>
|
||||
</bean>
|
||||
|
||||
<bean id="myMessage" class="java.lang.String">
|
||||
<constructor-arg value="Hello World!"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,25 @@
|
||||
require 'java'
|
||||
|
||||
class RubyMessenger
|
||||
include org.springframework.scripting.ConfigurableMessenger
|
||||
|
||||
@@message = "Hello World!"
|
||||
|
||||
def setMessage(message)
|
||||
@@message = message
|
||||
end
|
||||
|
||||
def getMessage
|
||||
@@message
|
||||
end
|
||||
|
||||
def setTestBean(testBean)
|
||||
@@testBean = testBean
|
||||
end
|
||||
|
||||
def getTestBean
|
||||
@@testBean
|
||||
end
|
||||
end
|
||||
|
||||
RubyMessenger.new
|
||||
@@ -0,0 +1,11 @@
|
||||
require 'java'
|
||||
|
||||
class RubyPrinter
|
||||
include org.springframework.scripting.jruby.Printer
|
||||
|
||||
def print(obj)
|
||||
puts obj.getContent
|
||||
end
|
||||
end
|
||||
|
||||
RubyPrinter.new
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:lang="http://www.springframework.org/schema/lang"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.2.xsd">
|
||||
|
||||
<lang:std id="messenger"
|
||||
script-source="classpath:org/springframework/scripting/jruby/MessengerWithInstance.rb">
|
||||
</lang:std>
|
||||
|
||||
<lang:std id="calculator" engine="jruby">
|
||||
<lang:inline-script>
|
||||
require 'java'
|
||||
|
||||
class RubyCalculator
|
||||
include org.springframework.scripting.Calculator
|
||||
|
||||
def add(x, y)
|
||||
x + y
|
||||
end
|
||||
end
|
||||
|
||||
RubyCalculator.new
|
||||
</lang:inline-script>
|
||||
</lang:std>
|
||||
|
||||
<lang:std id="refreshableMessenger"
|
||||
script-source="classpath:org/springframework/scripting/jruby/MessengerWithInstance.rb"
|
||||
refresh-check-delay="5000">
|
||||
</lang:std>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean class="org.springframework.scripting.support.ScriptFactoryPostProcessor"/>
|
||||
|
||||
<bean id="calculator" class="org.springframework.scripting.support.StandardScriptFactory">
|
||||
<constructor-arg value="jruby"/>
|
||||
<constructor-arg>
|
||||
<value>inline:
|
||||
require 'java'
|
||||
|
||||
class RubyCalculator
|
||||
include org.springframework.scripting.Calculator
|
||||
|
||||
def add(x, y)
|
||||
x + y
|
||||
end
|
||||
end
|
||||
|
||||
RubyCalculator.new
|
||||
</value>
|
||||
</constructor-arg>
|
||||
<constructor-arg value="org.springframework.scripting.Calculator"/>
|
||||
</bean>
|
||||
|
||||
<bean id="messenger" class="org.springframework.scripting.support.StandardScriptFactory">
|
||||
<constructor-arg value="jruby"/>
|
||||
<constructor-arg value="classpath:org/springframework/scripting/jruby/MessengerWithInstance.rb"/>
|
||||
<constructor-arg value="org.springframework.scripting.Messenger"/>
|
||||
</bean>
|
||||
|
||||
<bean id="printer" class="org.springframework.scripting.support.StandardScriptFactory">
|
||||
<constructor-arg value="jruby"/>
|
||||
<constructor-arg value="classpath:org/springframework/scripting/jruby/PrinterWithInstance.rb"/>
|
||||
<constructor-arg value="org.springframework.scripting.jruby.Printer"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1 @@
|
||||
function getMessage() { return "Hello World!" }
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:lang="http://www.springframework.org/schema/lang"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.2.xsd">
|
||||
|
||||
<lang:std id="messengerWithInterface" script-source="classpath:org/springframework/scripting/support/Messenger.js"
|
||||
script-interfaces="org.springframework.scripting.Messenger"/>
|
||||
|
||||
<lang:std id="refreshableMessengerWithInterface" refresh-check-delay="5000"
|
||||
script-source="classpath:org/springframework/scripting/support/Messenger.js"
|
||||
script-interfaces="org.springframework.scripting.Messenger">
|
||||
</lang:std>
|
||||
|
||||
<lang:std id="inlineMessengerWithInterface" engine="JavaScript"
|
||||
script-interfaces="org.springframework.scripting.Messenger">
|
||||
<lang:inline-script>
|
||||
function getMessage() { return "Hello World!" }
|
||||
</lang:inline-script>
|
||||
</lang:std>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user