Re: [Simple-support] Bug when read XML with ArrayList and HashMap created by simple
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2011-06-09 11:35:48
|
Hi,
Can you write this as a unit test?
Thanks,
Niall
--- On Tue, 7/6/11, user <xx...@ra...> wrote:
> From: user <xx...@ra...>
> Subject: [Simple-support] Bug when read XML with ArrayList and HashMap created by simple
> To: sim...@li...
> Received: Tuesday, 7 June, 2011, 5:38 AM
> There is a small class which creates
> default configuration and saves it
> into file:
>
> package videocontroldesk.params;
>
> import java.io.File;
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.List;
> import java.util.Map;
> import java.util.logging.Level;
> import java.util.logging.Logger;
> import org.simpleframework.xml.Element;
> import org.simpleframework.xml.ElementList;
> import org.simpleframework.xml.ElementMap;
> import org.simpleframework.xml.Root;
> import org.simpleframework.xml.Serializer;
> import org.simpleframework.xml.core.Persister;
>
> @Root
> public class VCDParams {
>
> private static VCDParams instance;
> private static final String filename =
> "VCDParams.xml";
> private static final Logger logger =
> Logger.getLogger(VCDParams.class.getName());
>
> @Element
> private int selectedLayoutIdx;
>
> @ElementList
> private List<LayoutParams> layouts;
>
> @ElementMap
> private Map<String, String>
> ipForCamera;
>
> private VCDParams() {
> selectedLayoutIdx = 0;
> layouts = new
> ArrayList<LayoutParams>();
> for (int i = 0; i < 4; ++i)
> {
> layouts.add(new
> LayoutParams());
> }
> ipForCamera = new
> HashMap<String, String>();
> ipForCamera.put("БК1",
> "192.168.0.101");
> }
>
> public int getLayoutsCount() {
> return layouts.size();
> }
>
> public LayoutParams getLayout(int layoutIdx)
> {
> return layouts.get(layoutIdx);
> }
>
> public static VCDParams getInstance() {
> if (instance == null) {
> try {
>
> instance = read();
> }
> catch (Exception
> ex) {
>
> instance = new VCDParams();
> }
> }
> return instance;
> }
>
> private static VCDParams read() throws
> Exception {
> Serializer reader = new
> Persister();
> File f = new File(filename);
> return
> reader.read(VCDParams.class, f);
> }
>
> public void save() {
> Serializer saver = new
> Persister();
> File f = new File(filename);
> try {
> saver.write(this,
> f);
> } catch (Exception ex) {
>
> logger.log(Level.WARNING, "Не могу сохранить
> файл {0}",
> filename);
> }
> }
>
> public static void main(String[] args) {
>
> //VCDParams.getInstance().save();
> VCDParams params =
> VCDParams.getInstance();
> //String[] cams =
> VCDParams.getInstance().getLayout(0).getAllCamIds();
> }
>
> }
>
>
> If I uncomment "save()" method call I get the following
> XML:
>
> <VCDParams>
> <selectedLayoutIdx>0</selectedLayoutIdx>
> <layouts
> class="java.util.ArrayList">
> <layoutParams columnsCount="2"
> rowsCount="1">
> <cell
> cellId="0">БК1</cell>
> </layoutParams>
> <layoutParams columnsCount="2"
> rowsCount="1">
> <cell
> cellId="0">БК1</cell>
> </layoutParams>
> <layoutParams columnsCount="2"
> rowsCount="1">
> <cell
> cellId="0">БК1</cell>
> </layoutParams>
> <layoutParams columnsCount="2"
> rowsCount="1">
> <cell
> cellId="0">БК1</cell>
> </layoutParams>
> </layouts>
> <ipForCamera
> class="java.util.HashMap">
> <entry>
>
> <string>БК1</string>
>
> <string>192.168.0.101</string>
> </entry>
> </ipForCamera>
> </VCDParams>
>
>
> It looks OK. Then I comment "save()" and uncomment "
> VCDParams.getInstance()" call.
> When I set breakpoint right after this call I check the
> value of
> layouts.size(). It return 8 instead of 4.
> Please fix it.
> Tested on 2.5.3 and 2.4.1.
>
> ------------------------------------------------------------------------------
> EditLive Enterprise is the world's most technically
> advanced content
> authoring tool. Experience the power of Track Changes,
> Inline Image
> Editing and ensure content is compliant with Accessibility
> Checking.
> http://p.sf.net/sfu/ephox-dev2dev
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
>
|