Re: [picocontainer-dev] JSON Pico container

Paul Hammant <[email protected]> Fri, 13 Dec 2013 14:10:01 -0500
Newsgroups gmane.comp.java.picocontainer.devel
Message-ID <CA+298Uhe6o3yrAMKeOKLQxJ+ujMs6_ODeNmiQRf1-FpW9a+E3Q@mail.gmail.com>
--047d7b6da6e47e2a9404ed6f35c3
Content-Type: text/plain; charset=ISO-8859-1

If you've got JUnit tests that shows it in use, feel free to donate it -
we're more than happy to facilitate other people's use-cases.

As it happens we're on the cusp of releasing PicoContainer 3, but you may
have a strong preference for doing this for PicoContainer 2.0, and we're
happy with cooperating with that agenda too.  Patch-files for Pico2
(imperfect Subversion world).  A Github fork (and pull request) for
PicoContainer 3, if your happy with an implicit delay on release.

- Paul


On Fri, Dec 13, 2013 at 2:00 PM, Serban Iordache <[email protected]>wrote:

> Hi all,
>
> I would like to contribute a pico container that populates itself by means
> of a configuration file in JSON format.
>
> For a usage example, let's consider the following code fragment:
>
>   public class Banner extends JFrame {
>     public Banner(JTextComponent textComp, String text, int size, boolean
> bold) {
>       textComp.setText(text);
>       textComp.setFont(new Font("Arial", (bold ? Font.BOLD : Font.PLAIN),
> size));
>       add(textComp);
>       setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
>       pack();
>     }
>
>     public static void main(String[] args) {
>       MutablePicoContainer pico = new DefaultPicoContainer();
>       pico.addComponent("textComp", JTextArea.class,
> DefaultConstructorParameter.INSTANCE);
>       pico.addComponent("banner", Banner.class,
>           new ComponentParameter("textComp"),
>           new ConstantParameter("Hello, world!"),
>           new ComponentParameter("size"),
>           new ComponentParameter("bold"));
>       pico.addConfig("size", 36);
>       pico.addConfig("bold", true);
>
>       Banner banner = (Banner)pico.getComponent("banner");
>       banner.setVisible(true);
>     }
>   }
>
> Using the JsonPicoContainer, the main method above can be rewritten as:
>
>   public static void main(String[] args) {
>     MutablePicoContainer pico = new JsonPicoContainer("banner.json");
>
>     Banner banner = (Banner)pico.getComponent("banner");
>     banner.setVisible(true);
>   }
>
> And here is the content of the file banner.json:
>
> [
>   {key: textComp, impl: javax.swing.JTextArea, parameters: [{}]},
>   {key: banner, impl: com.picocontainer.gems.containers.Banner,
> parameters: [{key: textComp}, {value: "Hello, world"}, {key: size}, {key:
> bold}]},
>   {key: size, value: 36, type: int},
>   {key: bold, value: true, type: boolean}
> ]
>
>
> The JSON container has a dependency on google-gson, therefore it would
> belong to the gems. I've tested the container using the code from the
> picocontainer-git repository. (I assume that the development on Pico 2.x
> has been discontinued.)
>
> Do you find such a JSON container useful? If yes, how can I contribute it?
>
> Best regards,
> Serban
>
>

--047d7b6da6e47e2a9404ed6f35c3
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">If you&#39;ve got JUnit tests that shows it in use, feel f=
ree to donate it - we&#39;re more than happy to facilitate other people&#39=
;s use-cases.<div><br></div><div>As it happens we&#39;re on the cusp of rel=
easing PicoContainer 3, but you may have a strong preference for doing this=
 for PicoContainer 2.0, and we&#39;re happy with cooperating with that agen=
da too. =A0Patch-files for Pico2 (imperfect Subversion world). =A0A Github =
fork (and pull request) for PicoContainer 3, if your happy with an implicit=
 delay on release.</div>
<div><br></div><div>- Paul</div></div><div class=3D"gmail_extra"><br><br><d=
iv class=3D"gmail_quote">On Fri, Dec 13, 2013 at 2:00 PM, Serban Iordache <=
span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_bla=
nk">[email protected]</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">


<div><div dir=3D"ltr"><div>Hi all,</div><div><br></div><div>I would like to=
 contribute a pico container that populates itself by means of a configurat=
ion file in JSON format.</div><div><br></div><div>For a usage example, let&=
#39;s consider the following code fragment:</div>
<div><br></div><div>=A0 public class Banner extends JFrame {</div><div>=A0 =
=A0 public Banner(JTextComponent textComp, String text, int size, boolean b=
old) {</div><div>=A0 =A0 =A0 textComp.setText(text);</div><div>=A0 =A0 =A0 =
textComp.setFont(new Font(&quot;Arial&quot;, (bold ? Font.BOLD : Font.PLAIN=
), size));</div>
<div>=A0 =A0 =A0 add(textComp);</div><div>=A0 =A0 =A0 setDefaultCloseOperat=
ion(WindowConstants.DISPOSE_ON_CLOSE);</div><div>=A0 =A0 =A0 pack();</div><=
div>=A0 =A0 }</div><div><br></div><div>=A0 =A0 public static void main(Stri=
ng[] args) {</div><div>
=A0 =A0 =A0 MutablePicoContainer pico =3D new DefaultPicoContainer();</div>=
<div>=A0 =A0 =A0 pico.addComponent(&quot;textComp&quot;, JTextArea.class, D=
efaultConstructorParameter.INSTANCE);</div><div>=A0 =A0 =A0 pico.addCompone=
nt(&quot;banner&quot;, Banner.class,=A0</div>
<div>=A0 =A0 =A0 =A0 =A0 new ComponentParameter(&quot;textComp&quot;),=A0</=
div><div>=A0 =A0 =A0 =A0 =A0 new ConstantParameter(&quot;Hello, world!&quot=
;),</div><div>=A0 =A0 =A0 =A0 =A0 new ComponentParameter(&quot;size&quot;),=
</div><div>=A0 =A0 =A0 =A0 =A0 new ComponentParameter(&quot;bold&quot;));</=
div>
<div>=A0 =A0 =A0 pico.addConfig(&quot;size&quot;, 36);</div><div>=A0 =A0 =
=A0 pico.addConfig(&quot;bold&quot;, true);</div><div><br></div><div>=A0 =
=A0 =A0 Banner banner =3D (Banner)pico.getComponent(&quot;banner&quot;);</d=
iv><div>=A0 =A0 =A0 banner.setVisible(true);</div>
<div>=A0 =A0 }</div><div>=A0 }</div><div><br></div><div>Using the JsonPicoC=
ontainer, the main method above can be rewritten as:</div><div><br></div><d=
iv>=A0 public static void main(String[] args) {</div><div>=A0 =A0 MutablePi=
coContainer pico =3D new JsonPicoContainer(&quot;banner.json&quot;);</div>
<div><br></div><div>=A0 =A0 Banner banner =3D (Banner)pico.getComponent(&qu=
ot;banner&quot;);</div><div>=A0 =A0 banner.setVisible(true);</div><div>=A0 =
}</div><div><br></div><div>And here is the content of the file banner.json:=
</div><div>
<br></div><div>[</div><div>=A0 {key: textComp, impl: javax.swing.JTextArea,=
 parameters: [{}]},</div><div>=A0 {key: banner, impl: com.picocontainer.gem=
s.containers.Banner, parameters: [{key: textComp}, {value: &quot;Hello, wor=
ld&quot;}, {key: size}, {key: bold}]},</div>
<div>=A0 {key: size, value: 36, type: int},</div><div>=A0 {key: bold, value=
: true, type: boolean}</div><div>]</div><div><br></div><div><br></div><div>=
The JSON container has a dependency on google-gson, therefore it would belo=
ng to the gems. I&#39;ve tested the container using the code from the picoc=
ontainer-git repository. (I assume that the development on Pico 2.x has bee=
n discontinued.)</div>
<div><br></div><div>Do you find such a JSON container useful? If yes, how c=
an I contribute it?</div><div><br></div><div>Best regards,</div><div>Serban=
</div><div><br></div> 		 	   		  </div></div>
</blockquote></div><br></div>

--047d7b6da6e47e2a9404ed6f35c3--