[Simple-support] Using constructors with arguments
Brought to you by:
niallg
|
From: Kevin D. <ke...@tr...> - 2009-01-21 00:28:16
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<STYLE type=text/css> P, UL, OL, DL, DIR, MENU, PRE { margin: 0 auto;}</STYLE>
<META content="MSHTML 6.00.6000.16788" name=GENERATOR></HEAD>
<BODY leftMargin=1 topMargin=1 rightMargin=1><FONT face=Arial size=2>
<DIV>For starters, I really like what I see in this project (just started reviewing it this afternoon). I'm hoping that I can get some pointers on a specific use-case.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>I would like to use Simple in conjunction with a dependency injection system (probably Guice) and List implementations from the GlazedLists project.</DIV>
<DIV> </DIV>
<DIV>We have to use a constructor on our list implementations that contains arguments (some of the arguments provided by Guice, some from element or attribute data in the XML).</DIV>
<DIV> </DIV>
<DIV>What is the best way to approach this with Simple?</DIV>
<DIV> </DIV>
<DIV></DIV>
<DIV>It seems that some sort of Strategy mixed with a custom Type is in order, but I'm not entirely clear on the best approach. The architecture of the framework looks powerful enough to do what we need, but I can't see where to get started just yet.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>To give a pseudo-code example of what we are trying to do (in real life, we'll be injecting SomeInjectedObject using Guice or a factory/service provider call):</DIV>
<DIV> </DIV>
<DIV>class SpecialList<E>{</DIV>
<DIV> public SpecialList(SomeInjectedObject injected, String valueFromAttribute, SomeObject valueFromElement){</DIV>
<DIV> ...</DIV>
<DIV> }</DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>class MyObject{</DIV>
<DIV><FONT color=#646464 size=2><FONT color=#646464 size=2>
<P> @ElementList</P></FONT></FONT></DIV>
<DIV> SpecialList<ElementObject> list = new SpecialList<ElementObject>(SomeInjectedObject.defaultInstance, "test", new SomeObject());</DIV>
<DIV> </DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>When we serialize this with Simple, we'd like to see something approximately like the following:</DIV>
<DIV> </DIV>
<DIV><myObject valueFromAttribute="test"></DIV>
<DIV>
<DIV> <someObject> ... </someObject></DIV> <list></DIV>
<DIV> <elementObject> ... whatever goes into this ... </elementObject></DIV>
<DIV>
<DIV> <elementObject> ... whatever goes into this ... </elementObject></DIV>
<DIV> ...</DIV> </list></DIV>
<DIV></myObject></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Note that:</DIV>
<DIV> </DIV>
<DIV>1. The <list> element doesn't have a class attribute</DIV>
<DIV>2. When we construct the list during deserialization, we need to be able to pull the 'valueFromAttribute' and 'someObject' values to use during construction of the SpecialList object</DIV>
<DIV>3. The SpecialList object needs to have the 3 argument constructor called (not a zero-arg constructor). And it is not possible to call a zero arg constructor, then modify the object afterwards to get the same result.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Any pointers? I may be pushing the framework too hard (some of the above requirements can be relaxed - if it isn't possible to obtain valueFromAttribute or someObject at construction time, we can find workarounds - but we have to be able to create the SpecialList instance using values from a factory/Guice/etc...). For what it's worth, we have this type of behavior working in Betwixt using custom BeanCreator implementations.</DIV>
<DIV> </DIV>
<DIV>Thanks much,</DIV>
<DIV> </DIV>
<DIV>- Kevin</DIV></FONT></BODY></HTML>
|