Example 1 | Using is to set a simple property. |
Example 2 | Using is to set an indexed property. |
Example 3 | Using is to set a mapped property. |
Using is
to set a simple property.
<snack> <fruit> <is type="apple" colour="red"/> </fruit> </snack>Where the
snack
bean is:
public static class SnackBean { FruitBean fruit; public void setFruit(FruitBean bean) { this.fruit = bean; } }and the
fruit
bean is:
public static class FruitBean { private String type; private String colour; public void setType(String type) { this.type = type; } public void setColour(String colour) { this.colour = colour; } }
Using is
to set an indexed property.
<snack> <fruit> <is type="apple" colour="red"/> <is type="pear" colour="green"/> </fruit> </snack>Where the
snack
bean is:
public static class IndexedSnack { private List<FruitBean> fruit = new ArrayList<FruitBean>(); public void setFruit(int index, FruitBean bean) { if (bean == null) { fruit.remove(index); } else { fruit.add(index, bean); } } }and the
fruit
bean is as above.
Using is
to set a mapped property.
<snack> <fruit> <is key="morning" type="apple" colour="red"/> <is key="afternoon" type="grapes" colour="white"/> </fruit> </snack>Where the
snack
bean is:
public static class MappedSnack { private Map<String, FruitBean> fruit = new HashMap<String, FruitBean>(); public void setFruit(String key, FruitBean bean) { if (fruit == null) { fruit.remove(key); } else { this.fruit.put(key, bean); } } }and the
fruit
bean is as above.