]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Change in ExecutionParameterPostProcessor to avoid instantiation problem with osgi
authorOlivier Capillon <olivier.capillon@gmail.com>
Fri, 20 Mar 2009 18:30:27 +0000 (18:30 +0000)
committerOlivier Capillon <olivier.capillon@gmail.com>
Fri, 20 Mar 2009 18:30:27 +0000 (18:30 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2293 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

demo/site/org.argeo.slc.demo.basic/conf/basic.xml
demo/site/org.argeo.slc.demo.basic/conf/canonic.xml
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionParameterPostProcessor.java
runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/applicationContext.xml
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/createRef.xml [deleted file]
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/test.xml

index 25ff40583e5a7b911a109a0f7b7b44520d1f0466..6cb92172c1c752f5cd008c0bd4a7700dfe60ee2f 100644 (file)
@@ -26,8 +26,8 @@
                </property>\r
        </bean>\r
 \r
-       <bean id="basic.ref" factory-bean="basic.spec" factory-method="createRef"\r
-               abstract="true" />\r
+<!--   <bean id="basic.ref" factory-bean="basic.spec" factory-method="createRef"\r
+               abstract="true" />-->\r
 \r
        <bean id="basic.flowTemplate" parent="slcTemplate.simpleFlow"\r
                abstract="true">\r
@@ -42,7 +42,7 @@
                                <bean parent="testRun">\r
                                        <property name="testDefinition" ref="testDef" />\r
                                        <property name="testData">\r
-                                               <bean parent="basic.ref">\r
+                                               <bean parent="parameterRef">\r
                                                        <constructor-arg value="testData1" />\r
                                                </bean>\r
                                        </property>\r
@@ -55,7 +55,7 @@
                </property>\r
        </bean>\r
 \r
-       <bean id="ref1" parent="basic.ref" scope="prototype">\r
+       <bean id="ref1" parent="parameterRef" scope="prototype">\r
                <constructor-arg value="testData2" />\r
        </bean>\r
 \r
index 7754734d28ea410779a8a41914dc5d59637541b4..07e73e4751d3f53230d6962d0ea748868a7dc246 100644 (file)
@@ -31,7 +31,7 @@
 \r
        <bean id="canonic.flowTemplate" parent="slcTemplate.simpleFlow"\r
                abstract="true">\r
-               <constructor-arg ref="basic.spec" />\r
+               <constructor-arg ref="canonic.spec" />\r
                <property name="executables">\r
                        <list>\r
                                <bean parent="task.echo"\r
index e39e9fab78aec4798477daf7e707400111f6dc74..e85962dc5ac1f71d077c0eb00aac25d942e0906d 100644 (file)
@@ -58,15 +58,15 @@ public class ExecutionParameterPostProcessor extends
                        throws BeansException {
                
                
-//             boolean inFlowInitialization = DefaultExecutionSpec.isInFlowInitialization();
+               boolean inFlowInitialization = instantiationManager.isInFlowInitialization();
                                
-//             if (((executionScope == null) || (!executionScope.hasExecutionContext()))
-//                             && !inFlowInitialization) {
-//                     //log.info("Skip parameter conversion for bean " + beanName);
-//                     return pvs;
-//             } else {
-//                     //log.info("Execute parameter conversion for bean " + beanName);
-//             }
+               if (((executionScope == null) || (!executionScope.hasExecutionContext()))
+                               && !inFlowInitialization) {
+                       //log.info("Skip parameter conversion for bean " + beanName);                   
+                       return pvs;
+               } else {
+                       //log.info("Execute parameter conversion for bean " + beanName);
+               }
 
                Properties props = new Properties();
                CustomPpc ppc = new CustomPpc(props);
@@ -120,6 +120,7 @@ public class ExecutionParameterPostProcessor extends
                        setSystemPropertiesMode(SYSTEM_PROPERTIES_MODE_NEVER);
                }
 
+               //TODO: could be removed as well as props
                public String process(String strVal) {
                        String value = parseStringValue(strVal, this.props,
                                        new HashSet<String>());
@@ -128,27 +129,14 @@ public class ExecutionParameterPostProcessor extends
 
                @Override
                protected String resolvePlaceholder(String placeholder, Properties props) {
-                       if ((executionScope != null) && (executionScope.hasExecutionContext())) {
-                               // if we have an execution context, look there for the placeholder
+                       //log.info("Try convert placeholder " + placeholder);
+                       if ((executionScope != null) && (executionScope.hasExecutionContext()))
                                return executionContext.getVariable(placeholder).toString();
-                       }
-                       else {
-                               // TODO: check scope of the bean
-                               // throw exception if trying to resolve placeholder on bean of scope singleton 
-                               
-                               if (instantiationManager.isInFlowInitialization()) {
-                                       String resolved = instantiationManager.getInitializingFlowParameter(
-                                                       placeholder).toString();
-//                                     log.info("Initialization placeholder resolution " + placeholder 
-//                                                     + ">>" + resolved);
-                                       return resolved;
-                               }
-                               else {
-       //                              return super.resolvePlaceholder(placeholder, props);
-                                       throw new SlcException("Placeholder '" + placeholder 
-                                                       + "' can not be resolved outside of Flow Initialization or Flow Execution.");
-                               }
-                       }
+                       else if (instantiationManager.isInFlowInitialization())
+                               return instantiationManager.getInitializingFlowParameter(
+                                               placeholder).toString();
+                       else
+                               return super.resolvePlaceholder(placeholder, props);
                }
        }
 }
index edafb44909e9133a6b3df3c1f594f67a62711546..280a242d7a966b744c41936b29ab1982a5fecf8a 100644 (file)
@@ -5,45 +5,27 @@ import org.argeo.slc.execution.ExecutionFlow;
 import org.argeo.slc.test.TestStatus;\r
 import org.argeo.slc.unit.AbstractSpringTestCase;\r
 import org.springframework.beans.factory.BeanCreationException;\r
-import org.springframework.beans.factory.config.BeanDefinition;\r
 import org.springframework.context.ConfigurableApplicationContext;\r
 import org.springframework.context.support.ClassPathXmlApplicationContext;\r
 \r
 public class ExecutionFlowTest extends AbstractSpringTestCase {\r
        \r
        public void testSimpleExecution() throws Exception {\r
-//             prepareExecution("applicationContext.xml");\r
-               configureAndExecuteSlcFlow("applicationContext.xml", "main_2");\r
-               \r
-//             ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(inPackage("applicationContext.xml"));\r
-//             String[] beanNames = applicationContext.getBeanDefinitionNames();\r
-//             for(String beanName : beanNames) {\r
-//                     log.info("beanName='" + beanName + "'");\r
-////                   if(beanName.equals("main_temp")) {\r
-//                             BeanDefinition beanDef = applicationContext.getBeanFactory().getBeanDefinition(beanName);\r
-//                             String scope = beanDef.getScope();\r
-//                             String[] attrs = beanDef.();\r
-//                             log.info("scope=" + scope + ", nbAttr=" + attrs.length);\r
-//                             for(String attr : attrs) {\r
-//                                     log.info(attr + "=" + beanDef.getAttribute(attr));\r
-//                             }\r
-////                   }\r
-//             }\r
-               \r
+               configureAndExecuteSlcFlow("applicationContext.xml", "main");\r
        }\r
        \r
        public void testCanonic() throws Exception {\r
                // Parameter without default value in specification\r
-//             configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");\r
-//             configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");\r
-//\r
-//             try {\r
-//                     prepareExecution("canonic-003.error.xml");\r
-//                     fail("Parameter not set - should be rejected.");\r
-//             } catch (BeanCreationException e) {\r
-//                     // exception expected\r
-//                     logException(e);\r
-//             }\r
+/*             configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");\r
+               configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");\r
+\r
+               try {\r
+                       configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");\r
+                       fail("Parameter not set - should be rejected.");\r
+               } catch (BeanCreationException e) {\r
+                       // exception expected\r
+                       logException(e);\r
+               }*/\r
                \r
 /*             try {\r
                        configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");\r
@@ -54,20 +36,16 @@ public class ExecutionFlowTest extends AbstractSpringTestCase {
                }       */\r
        }       \r
        \r
-       public void testRecursive() throws Exception {\r
-//             ConfigurableApplicationContext applicationContext = prepareExecution("test.xml");\r
-//             ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean("first");\r
-//             executionFlow.execute();                \r
-//             SimpleTestResult res = (SimpleTestResult) applicationContext.getBean("basicTestResult");\r
-//             if(res.getParts().get(0).getStatus() != TestStatus.PASSED) {\r
-//                     fail("Unexpected string returned");\r
-//             }\r
-//             applicationContext.close();             \r
-       }\r
-       \r
-       public void testCreateRef() throws Exception {\r
-//             configureAndExecuteSlcFlow("createRef.xml", "basic.001");\r
-       }\r
+/*     public void testRecursive() throws Exception {\r
+               ConfigurableApplicationContext applicationContext = prepareExecution("test.xml");\r
+               ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean("first");\r
+               executionFlow.execute();                \r
+               SimpleTestResult res = (SimpleTestResult) applicationContext.getBean("basicTestResult");\r
+               if(res.getParts().get(0).getStatus() != TestStatus.PASSED) {\r
+                       fail("Unexpected string returned");\r
+               }\r
+               applicationContext.close();             \r
+       }*/\r
        \r
        protected void logException(Throwable ex) {\r
                log.info("Got Exception of class " + ex.getClass().toString()\r
index abd8facef7a1eb1c75f17ca204bfdde0d96606c7..50aff9f1e02ba091c70c1e0a14d92bab261f8204 100644 (file)
                <property name="version" value="dummyversion" />\r
        </bean>\r
  \r
-       <bean id="echoNonExecution" parent="task.echo" scope="prototype">\r
-               <property name="message"\r
-                       value="echoNonExecution @{testKey}" />\r
-       </bean>\r
\r
-       <bean id="main_temp" parent="slcTemplate.simpleFlow" abstract="true">\r
-               <constructor-arg >\r
+       <bean id="main" parent="slcTemplate.simpleFlow">\r
+               <constructor-arg>\r
                        <bean parent="slcTemplate.simpleSpec">\r
                                <property name="attributes">\r
                                        <map>\r
                                                </entry>\r
                                        </map>\r
                                </property>\r
-                       </bean> \r
+                       </bean>\r
                </constructor-arg>\r
-\r
                <property name="executables">\r
                        <list>\r
-                               <ref local="echoExecution" />\r
-                               <ref local="echoNonExecution" />\r
-                               <bean parent="task.echo">\r
-                                       <property name="message"\r
-                                               value="echoNonExecutionEmbedded @{testKey}" />\r
-                               </bean>                         \r
+                               <ref local="echo1" />\r
                        </list>\r
                </property>\r
        </bean>\r
 \r
-       <bean id="main" parent="main_temp">\r
-               <constructor-arg >\r
-                       <map>\r
-                               <entry key="testKey" value="666" />\r
-                       </map>          \r
-               </constructor-arg>   \r
-       </bean>\r
-\r
-       <bean id="main_2" parent="main_temp">\r
-               <constructor-arg >\r
-                       <map>\r
-                               <entry key="testKey" value="main_2" />\r
-                       </map>          \r
-               </constructor-arg>   \r
-       </bean>\r
-\r
-       <bean id="echoExecution" parent="task.echo" scope="execution">\r
+       <bean id="echo1" parent="task.echo" scope="execution">\r
                <property name="message"\r
-                       value="echoExecution @{testKey}" />\r
+                       value="From main! @{testKey}" />\r
                <aop:scoped-proxy />\r
        </bean>\r
 \r
diff --git a/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/createRef.xml b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/createRef.xml
deleted file mode 100644 (file)
index 0424ca7..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>\r
-<beans xmlns="http://www.springframework.org/schema/beans"\r
-       xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
-       xmlns:aop="http://www.springframework.org/schema/aop"\r
-       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
-       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">\r
-\r
-       <import resource="imports.xml" /> \r
-\r
-       <bean id="testDef" class="org.argeo.slc.core.test.BasicTestDefinition"\r
-               scope="prototype" />\r
-\r
-       <bean id="testResult" parent="slcDefault.test.basicTreeTestResult" />\r
-\r
-       <bean id="testRun" class="org.argeo.slc.core.test.SimpleTestRun"\r
-               abstract="true">\r
-               <property name="testResult" ref="testResult" />\r
-       </bean>\r
-\r
-       <bean id="basic.spec" parent="slcTemplate.simpleSpec">\r
-               <property name="attributes">\r
-                       <map>\r
-                               <entry key="testedComponentId">\r
-                                       <bean parent="specAttr.primitive">\r
-                                               <property name="value" value="100" />\r
-                                               <property name="isParameter" value="true" />\r
-                                               <property name="type" value="integer" />\r
-                                       </bean>\r
-                               </entry>\r
-                               <entry key="testData1">\r
-                                       <bean parent="specAttr.ref">\r
-                                               <property name="isParameter" value="true" />\r
-                                               <property name="targetClass" value="org.argeo.slc.core.test.BasicTestData" />\r
-                                               <property name="isFrozen" value="true" />                                               \r
-                                       </bean>\r
-                               </entry>\r
-                               <entry key="testData2">\r
-                                       <bean parent="specAttr.ref">\r
-                                               <property name="isParameter" value="true" />\r
-                                               <property name="targetClass" value="org.argeo.slc.core.test.BasicTestData" />\r
-                                               <property name="isFrozen" value="true" />                                               \r
-                                       </bean>\r
-                               </entry>\r
-                       </map>\r
-               </property>\r
-       </bean>\r
-\r
-       <bean id="basic.flowTemplate" parent="slcTemplate.simpleFlow"\r
-               abstract="true">\r
-               <constructor-arg >\r
-                       <ref bean="basic.spec" />\r
-               </constructor-arg>\r
-               <property name="executables">\r
-                       <list>\r
-                               <bean parent="task.echo">\r
-                                       <property name="message" value="From basic @{testedComponentId}" />\r
-                               <!--    <aop:scoped-proxy /> -->\r
-                               </bean>\r
-                               <bean parent="testRun">\r
-                                       <property name="path" value="/test/basic" />\r
-                                       <property name="testDefinition" ref="testDef" />\r
-                                       <property name="testData">\r
-                                               <bean parent="parameterRef">\r
-                                                       <constructor-arg value="testData1" />\r
-                                               </bean>\r
-                                       </property>\r
-                               </bean>\r
-                               <bean parent="testRun">\r
-                                       <property name="testDefinition" ref="testDef" />\r
-                                       <property name="testData" ref="ref1" />\r
-                               </bean>\r
-                       </list>\r
-               </property>\r
-       </bean>\r
-\r
-       <bean id="ref1" parent="parameterRef" scope="prototype">\r
-               <constructor-arg value="testData2" />\r
-       </bean>\r
-\r
-\r
-       <bean id="basic.testData" class="org.argeo.slc.core.test.BasicTestData">\r
-<!--           <aop:scoped-proxy /> -->\r
-               <property name="expected" value="tata" />\r
-               <property name="reached" value="tata" />\r
-       </bean>\r
-\r
-       <bean id="basic.001" parent="basic.flowTemplate">\r
-               <constructor-arg>\r
-                       <map>\r
-                               <entry key="testData1" value-ref="basic.001.testData" />\r
-                               <entry key="testData2">\r
-                                       <bean class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
-                                               <aop:scoped-proxy /> \r
-                                               <property name="expected" value="tata101" />\r
-                                               <property name="reached" value="tata@{testedComponentId}" />\r
-                                       </bean>\r
-                               </entry>\r
-                       </map>\r
-               </constructor-arg>\r
-       </bean>\r
-\r
-       <bean id="basic.001.testData" class="org.argeo.slc.core.test.BasicTestData"\r
-               scope="prototype">\r
-               <aop:scoped-proxy />\r
-               <property name="expected" value="tata100" />\r
-               <property name="reached" value="tata@{testedComponentId}" />\r
-       </bean>\r
-\r
-</beans>
\ No newline at end of file
index 20a497b8ea457a6369635938606f29eca9ba7e3d..8d08ca10563b10c0005b440858753fc61741a57c 100644 (file)
@@ -7,8 +7,8 @@
 \r
        <import resource="imports.xml" /> \r
 \r
-       <bean id="second" parent="slcTemplate.simpleFlow" scope="prototype">\r
-               <constructor-arg>\r
+       <bean id="second" parent="slcTemplate.simpleFlow">\r
+               <property name="executionSpec">\r
                        <bean parent="slcTemplate.simpleSpec">\r
                                <property name="attributes">\r
                                        <map>\r
@@ -18,7 +18,7 @@
                                        </map>\r
                                </property>\r
                        </bean>\r
-               </constructor-arg>              \r
+               </property>\r
                <property name="executables">\r
                        <list>\r
                                <ref local="echo1" />\r
@@ -31,8 +31,9 @@
                </property>\r
        </bean>\r
 \r
+\r
        <bean id="first" parent="slcTemplate.simpleFlow">\r
-               <constructor-arg>\r
+               <property name="executionSpec">\r
                        <bean parent="slcTemplate.simpleSpec">\r
                                <property name="attributes">\r
                                        <map>\r
                                        </map>\r
                                </property>\r
                        </bean>\r
-               </constructor-arg>              \r
+               </property>\r
                <property name="executables">\r
                        <list>\r
                                <ref local="second" />\r
-                               <ref local="echo1" />\r
-                               <bean parent="task.echo" scope="prototype">\r
-                                       <property name="message"\r
-                                               value="In flow first, emebedded - testKey=@{testKey}" />\r
-                               </bean>\r
                        </list>\r
                </property>\r
        </bean>\r
 \r
-       <bean id="echo1" parent="task.echo" scope="prototype">\r
-               <property name="message"\r
-                       value="testKey=@{testKey}" />\r
-       </bean>\r
-\r
-       <bean id="basic.testData" class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
+       <bean id="basic.testData" class="org.argeo.slc.core.test.BasicTestData" scope="execution">\r
+               <aop:scoped-proxy />\r
                <property name="expected" value="first" />\r
                <property name="reached" value="@{testKey}" />\r
        </bean>\r
        \r
        <bean id="basic.testDef" class="org.argeo.slc.core.test.BasicTestDefinition">\r
+               <aop:scoped-proxy />\r
        </bean> \r
 \r
+\r
+       <bean id="echo1" parent="task.echo" scope="execution">\r
+               <property name="message"\r
+                       value="testKey=@{testKey}" />\r
+               <aop:scoped-proxy />\r
+       </bean>\r
+       \r
        <bean id="basicTestResult" class="org.argeo.slc.core.test.SimpleTestResult" />\r
 \r
 </beans>
\ No newline at end of file