[picocontainer-dev] JSON Pico container

Serban Iordache <[email protected]> Fri, 13 Dec 2013 20:00:38 +0100
Newsgroups gmane.comp.java.picocontainer.devel
Message-ID <[email protected]>
--_14f0718a-ab3b-4747-b954-2fcc314fcdeb_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all=2C
I would like to contribute a pico container that populates itself by means =
of a configuration file in JSON format.
For a usage example=2C let's consider the following code fragment:
  public class Banner extends JFrame {    public Banner(JTextComponent text=
Comp=2C String text=2C int size=2C boolean bold) {      textComp.setText(te=
xt)=3B      textComp.setFont(new Font("Arial"=2C (bold ? Font.BOLD : Font.P=
LAIN)=2C size))=3B      add(textComp)=3B      setDefaultCloseOperation(Wind=
owConstants.DISPOSE_ON_CLOSE)=3B      pack()=3B    }
    public static void main(String[] args) {      MutablePicoContainer pico=
 =3D new DefaultPicoContainer()=3B      pico.addComponent("textComp"=2C JTe=
xtArea.class=2C DefaultConstructorParameter.INSTANCE)=3B      pico.addCompo=
nent("banner"=2C Banner.class=2C           new ComponentParameter("textComp=
")=2C           new ConstantParameter("Hello=2C world!")=2C          new Co=
mponentParameter("size")=2C          new ComponentParameter("bold"))=3B    =
  pico.addConfig("size"=2C 36)=3B      pico.addConfig("bold"=2C true)=3B
      Banner banner =3D (Banner)pico.getComponent("banner")=3B      banner.=
setVisible(true)=3B    }  }
Using the JsonPicoContainer=2C the main method above can be rewritten as:
  public static void main(String[] args) {    MutablePicoContainer pico =3D=
 new JsonPicoContainer("banner.json")=3B
    Banner banner =3D (Banner)pico.getComponent("banner")=3B    banner.setV=
isible(true)=3B  }
And here is the content of the file banner.json:
[  {key: textComp=2C impl: javax.swing.JTextArea=2C parameters: [{}]}=2C  {=
key: banner=2C impl: com.picocontainer.gems.containers.Banner=2C parameters=
: [{key: textComp}=2C {value: "Hello=2C world"}=2C {key: size}=2C {key: bol=
d}]}=2C  {key: size=2C value: 36=2C type: int}=2C  {key: bold=2C value: tru=
e=2C type: boolean}]

The JSON container has a dependency on google-gson=2C therefore it would be=
long to the gems. I've tested the container using the code from the picocon=
tainer-git repository. (I assume that the development on Pico 2.x has been =
discontinued.)
Do you find such a JSON container useful? If yes=2C how can I contribute it=
?
Best regards=2CSerban
 		 	   		  =

--_14f0718a-ab3b-4747-b954-2fcc314fcdeb_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<style><!--
.hmmessage P
{
margin:0px=3B
padding:0px
}
body.hmmessage
{
font-size: 12pt=3B
font-family:Calibri
}
--></style></head>
<body class=3D'hmmessage'><div dir=3D'ltr'><div>Hi all=2C</div><div><br></d=
iv><div>I would like to contribute a pico container that populates itself b=
y means of a configuration file in JSON format.</div><div><br></div><div>Fo=
r a usage example=2C let's consider the following code fragment:</div><div>=
<br></div><div>&nbsp=3B public class Banner extends JFrame {</div><div>&nbs=
p=3B &nbsp=3B public Banner(JTextComponent textComp=2C String text=2C int s=
ize=2C boolean bold) {</div><div>&nbsp=3B &nbsp=3B &nbsp=3B textComp.setTex=
t(text)=3B</div><div>&nbsp=3B &nbsp=3B &nbsp=3B textComp.setFont(new Font("=
Arial"=2C (bold ? Font.BOLD : Font.PLAIN)=2C size))=3B</div><div>&nbsp=3B &=
nbsp=3B &nbsp=3B add(textComp)=3B</div><div>&nbsp=3B &nbsp=3B &nbsp=3B setD=
efaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)=3B</div><div>&nbsp=
=3B &nbsp=3B &nbsp=3B pack()=3B</div><div>&nbsp=3B &nbsp=3B }</div><div><br=
></div><div>&nbsp=3B &nbsp=3B public static void main(String[] args) {</div=
><div>&nbsp=3B &nbsp=3B &nbsp=3B MutablePicoContainer pico =3D new DefaultP=
icoContainer()=3B</div><div>&nbsp=3B &nbsp=3B &nbsp=3B pico.addComponent("t=
extComp"=2C JTextArea.class=2C DefaultConstructorParameter.INSTANCE)=3B</di=
v><div>&nbsp=3B &nbsp=3B &nbsp=3B pico.addComponent("banner"=2C Banner.clas=
s=2C&nbsp=3B</div><div>&nbsp=3B &nbsp=3B &nbsp=3B &nbsp=3B &nbsp=3B new Com=
ponentParameter("textComp")=2C&nbsp=3B</div><div>&nbsp=3B &nbsp=3B &nbsp=3B=
 &nbsp=3B &nbsp=3B new ConstantParameter("Hello=2C world!")=2C</div><div>&n=
bsp=3B &nbsp=3B &nbsp=3B &nbsp=3B &nbsp=3B new ComponentParameter("size")=
=2C</div><div>&nbsp=3B &nbsp=3B &nbsp=3B &nbsp=3B &nbsp=3B new ComponentPar=
ameter("bold"))=3B</div><div>&nbsp=3B &nbsp=3B &nbsp=3B pico.addConfig("siz=
e"=2C 36)=3B</div><div>&nbsp=3B &nbsp=3B &nbsp=3B pico.addConfig("bold"=2C =
true)=3B</div><div><br></div><div>&nbsp=3B &nbsp=3B &nbsp=3B Banner banner =
=3D (Banner)pico.getComponent("banner")=3B</div><div>&nbsp=3B &nbsp=3B &nbs=
p=3B banner.setVisible(true)=3B</div><div>&nbsp=3B &nbsp=3B }</div><div>&nb=
sp=3B }</div><div><br></div><div>Using the JsonPicoContainer=2C the main me=
thod above can be rewritten as:</div><div><br></div><div>&nbsp=3B public st=
atic void main(String[] args) {</div><div>&nbsp=3B &nbsp=3B MutablePicoCont=
ainer pico =3D new JsonPicoContainer("banner.json")=3B</div><div><br></div>=
<div>&nbsp=3B &nbsp=3B Banner banner =3D (Banner)pico.getComponent("banner"=
)=3B</div><div>&nbsp=3B &nbsp=3B banner.setVisible(true)=3B</div><div>&nbsp=
=3B }</div><div><br></div><div>And here is the content of the file banner.j=
son:</div><div><br></div><div>[</div><div>&nbsp=3B {key: textComp=2C impl: =
javax.swing.JTextArea=2C parameters: [{}]}=2C</div><div>&nbsp=3B {key: bann=
er=2C impl: com.picocontainer.gems.containers.Banner=2C parameters: [{key: =
textComp}=2C {value: "Hello=2C world"}=2C {key: size}=2C {key: bold}]}=2C</=
div><div>&nbsp=3B {key: size=2C value: 36=2C type: int}=2C</div><div>&nbsp=
=3B {key: bold=2C value: true=2C type: boolean}</div><div>]</div><div><br><=
/div><div><br></div><div>The JSON container has a dependency on google-gson=
=2C therefore it would belong to the gems. I've tested the container using =
the code from the picocontainer-git repository. (I assume that the developm=
ent on Pico 2.x has been discontinued.)</div><div><br></div><div>Do you fin=
d such a JSON container useful? If yes=2C how can I contribute it?</div><di=
v><br></div><div>Best regards=2C</div><div>Serban</div><div><br></div> 		 	=
   		  </div></body>
</html>=

--_14f0718a-ab3b-4747-b954-2fcc314fcdeb_--