Parameters extends ParameterComponent { public Object get(String key) { if (entry != null) { for (ParameterComponent paramComp : entry) { if (paramComp instanceof Parameter) { if (((Parameter) paramComp).getKey().equals(key)) { return ((Parameter) paramComp).getValue(); } else { } } else if (paramComp instanceof Parameters) { Object retour = ((Parameters) paramComp).get(key); if (retour != null) { return retour; } } } } return null; } Parameters(); void setDescription(String description); void add(ParameterComponent p); boolean set(String key, Object c); Object get(String key); Object get(String desc, String key); Parameters getParameters(String desc); String getString(String name); String getString(String desc, String name); boolean getBoolean(String name); boolean getBoolean(String desc, String name); double getDouble(String name); int getInteger(String name); float getFloat(String name); @XmlElementRef(name = "parameter")
	public List<ParameterComponent> entry; @XmlAttribute(name = "description")
	public String description; }
@Test public void testUnmarshallFileWithoutValidation() { try { Parameters p = Parameters.unmarshall(new File(ParametersTest.class.getClassLoader().getResource("simple.xml").getPath())); Assert.assertEquals(p.get("A").toString(), "B"); Assert.assertEquals(p.get("C").toString(), "D"); } catch(Exception e) { e.printStackTrace(); fail(); } }
@Test public void testUnmarshallFileWithValidation() { try { Parameters p = Parameters.unmarshall(new File(ParametersTest.class.getClassLoader().getResource("simple.xml").getPath()), PARAMETERS_SCHEMA); assertEquals(p.get("A").toString(), "B"); assertEquals(p.get("C").toString(), "D"); } catch(Exception e) { fail(); } }
@Test public void testUnmarshallString() { StringBuffer xmlResult = new StringBuffer(); xmlResult.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"); xmlResult.append("<parameters>"); xmlResult.append("<param key=\"A\" value=\"B\"/>"); xmlResult.append("<param key=\"C\" value=\"D\"/>"); xmlResult.append("</parameters>"); try { Parameters p = Parameters.unmarshall(xmlResult.toString(), PARAMETERS_SCHEMA); assertEquals("B", p.get("A").toString()); assertEquals("D", p.get("C").toString()); } catch(Exception e) { e.printStackTrace(); fail(); } xmlResult = new StringBuffer(); xmlResult.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"); xmlResult.append("<parameters>"); xmlResult.append("<param key=\"A\" value=\"D\"/>"); xmlResult.append("<param key=\"B\" value=\"E\"/>"); xmlResult.append("<param key=\"C\" value=\"D\"/>"); xmlResult.append("</parameters>"); try { Parameters p = Parameters.unmarshall(xmlResult.toString(), PARAMETERS_SCHEMA); assertEquals("D", p.get("A").toString()); assertEquals("E", p.get("B").toString()); assertEquals("D", p.get("C").toString()); } catch(Exception e) { fail(); } }