Details
Description
Currently, it doesn't appear possible to access a ComponentAdapter from within the Groovy builder syntax. The following test case illustrates an 'ideal' for modifying the component adapter. Of course, I'd be happy to do it nearly any way using the builder syntax.
-Mike (R)
public void testBuildWithComponentAdapter() {
Reader script = new StringReader(""
+ "import java.text.SimpleDateFormat;\n"
+ "import com.genfw.core.container.BeanNanoDecorator;\n"
+ "import org.picocontainer.defaults.*\n"
+ "\n"
+ "builder = new org.nanocontainer.script.groovy.NanoContainerBuilder(new BeanNanoDecorator())\n"
+ "pico = builder.container() { \n"
+ " component([ class: SimpleDateFormat)
\n"
+ "}");
ObjectReference predefined = new SimpleReference();
predefined.set(new DefaultPicoContainer(new BeanPropertyComponentAdapterFactory(new DefaultComponentAdapterFactory())));
ScriptedContainerBuilder builder = new GroovyContainerBuilder(script, Thread.currentThread().getContextClassLoader());
builder.buildContainer(predefined,null,null, false);
PicoContainer rootContainer = (PicoContainer)predefined.get();
assertNotNull(rootContainer);
assertNotNull(rootContainer.getComponentAdapter(SimpleDateFormat.class));
assertEquals(BeanPropertyComponentAdapter.class, rootContainer.getComponentAdapter(SimpleDateFormat.class).getClass());
SimpleDateFormat dateFormat = (SimpleDateFormat)rootContainer.getComponentInstance(SimpleDateFormat.class);
assertNotNull(dateFormat);
//Currently fails
//assertEquals(false, dateFormat.isLenient());
//assertEquals(new Date(0), dateFormat.get2DigitYearStart());
}
Activity
Field | Original Value | New Value |
---|---|---|
Component/s | core [ 10193 ] | |
Component/s | groovy [ 11631 ] |
Assignee | Michael Rimov [ rimovm ] |
Fix Version/s | 1.0-RC2 [ 11851 ] | |
Resolution | Fixed [ 1 ] | |
Status | Open [ 1 ] | Closed [ 6 ] |
I've made the CA accessible.
I'm thinking what we need to add for you is
component(class:SimpleDateFormat)
{ obj = instance(); obj.setLenient(false) obj.set2DigitYearStart(new Date()) }and/or...
component(class:SimpleDateFormat) {
{ set(property:"lenient", value:false) set(property:"2DigitYearStart", value:new Date()) }instance
}
Thoughts?