lastaflute / lasta-di

DI Container for LastaFlute, forked from Seasar as Java8
Apache License 2.0
9 stars 1 forks source link

Resolve variables in an array or collection from a container #12

Closed jfut closed 9 years ago

jfut commented 9 years ago

test.xml:

<component name="foo" class="org.example.Foo">
<component name="foo" class="org.example.Bar">

<component name="hoge1">[ foo, bar ]</component>
<component name="hoge2">{ foo, bar }</component>

I get the following error:

Caused by: java.lang.IllegalStateException: Look! Read the message below.
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Failed to evaluate the JavaScript expression.

[Di XML]
test.xml

[Expression]
[ foo, bar ]

[Context Map]
{}
* * * * * * * * * */
    at org.lastaflute.di.core.expression.engine.JavaScriptExpressionEngine.throwJavaScriptExpressionException(JavaScriptExpressionEngine.java:180)
    at org.lastaflute.di.core.expression.engine.JavaScriptExpressionEngine.actuallyEvaluate(JavaScriptExpressionEngine.java:160)
    at org.lastaflute.di.core.expression.engine.JavaScriptExpressionEngine.viaFirstNameResolvedEvaluate(JavaScriptExpressionEngine.java:144)
    at org.lastaflute.di.core.expression.engine.JavaScriptExpressionEngine.viaCastResolvedEvaluate(JavaScriptExpressionEngine.java:98)
    at org.lastaflute.di.core.expression.engine.JavaScriptExpressionEngine.viaVariableResolvedEvaluate(JavaScriptExpressionEngine.java:75)
    at org.lastaflute.di.core.expression.engine.JavaScriptExpressionEngine.evaluate(JavaScriptExpressionEngine.java:66)
    at org.lastaflute.di.core.expression.ScriptingExpression.evaluate(ScriptingExpression.java:85)
    at org.lastaflute.di.core.assembler.AbstractConstructorAssembler.assembleExpression(AbstractConstructorAssembler.java:56)
    at org.lastaflute.di.core.assembler.AbstractConstructorAssembler.assemble(AbstractConstructorAssembler.java:44)
    at org.lastaflute.di.core.deployer.SingletonComponentDeployer.assemble(SingletonComponentDeployer.java:52)
    at org.lastaflute.di.core.deployer.SingletonComponentDeployer.deploy(SingletonComponentDeployer.java:41)
    at org.lastaflute.di.core.deployer.SingletonComponentDeployer.init(SingletonComponentDeployer.java:35)
    at org.lastaflute.di.core.meta.impl.ComponentDefImpl.init(ComponentDefImpl.java:83)
    at org.lastaflute.di.core.meta.impl.LaContainerImpl.doInit(LaContainerImpl.java:435)
    at org.lastaflute.di.core.meta.impl.LaContainerImpl.init(LaContainerImpl.java:414)
    ... 21 more
Caused by: javax.script.ScriptException: ReferenceError: "foo" is not defined in <eval> at line number 1
    at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:451)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:403)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)
    at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at org.lastaflute.di.core.expression.engine.JavaScriptExpressionEngine.actuallyEvaluate(JavaScriptExpressionEngine.java:158)
    ... 34 more
Caused by: <eval>:1 ReferenceError: "multipartRequestParser" is not defined
    at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)
    at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319)
    at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291)
    at jdk.nashorn.internal.objects.Global.__noSuchProperty__(Global.java:1432)
    at jdk.nashorn.internal.scripts.Script$3$\^eval\_.:program(<eval>:1)
    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:640)
    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228)
    at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:446)
    ... 39 more

Is this expression mistaken?

jflute commented 9 years ago

Flexibility of Lasta Di's JavaScript expression is less than OGNL. so the pattern is unsupported for now.

While, Lasta Di suggests you keep Di xml to be simple as possible. (do not use complex expression)

But if you need the pattern, I will try to resolve it. Give me a time to think about implementation.

Or you can switch the engine to your original OGNL engine by 'dixml.script.expression.engine' in lasta_di.properties. (that implements ExpressionEngine interface)

thanks.

jflute commented 9 years ago

[share] target class is JavaScriptExpressionEngine in Lasta Di.

jflute commented 9 years ago

You can define it at the next version 0.6.4 (deployed 0.6.4-A-SNAPSHOT for now) The test case is following:

    <component name="sea" class="org.docksidestage.mylasta.trial.TrialDiSea"/>
    <component name="land" class="org.docksidestage.mylasta.trial.TrialDiLand"/>
    <component name="parks">[sea, land]</component>
    <component name="maihama" class="org.docksidestage.mylasta.trial.TrialDiMaihama">
        <property name="parkList">parks</property>
    </component>

However simple cases are only supported, sorry... e.g. o [sea, land] x [sea, land, [iks, bonvo], amba] // has nested list

We try to improve incrementally, so your feedback is very glad to us. Thank you.

Fixed class is: SimpleExpressionPlainHook

jfut commented 9 years ago

It sounds good! Thanks for improvement.:smile: