Hello!
Snua is a tiny little library that I
MP'ed yesterday night and finished today. It's very young, and incomplete. Anyway, it uses DOM to parse XML and returns Java objects from that XML. Everything is built around using a generic Decoder interface (with inbuilt implementations of boolean, byte, char, double, float, int, long, short and String decoders). It takes an org.w3c.dom.Node argument and produces a generic object from it. Here is a tiny bit of code for showing off.
SnuaTest.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| import java.io.FileInputStream; import java.io.FileNotFoundException;
import se.sickan.snua.Resource; import se.sickan.snua.ResourceException; import se.sickan.snua.Resources;
public class SnuaTest implements Resource { public boolean booleanTest; public byte byteTest; public char charTest; public double doubleTest; public float floatTest; public int intTest; public long longTest; public short shortTest; public String stringTest; public static void main(String[] args) throws ResourceException, FileNotFoundException { Resources resources = new Resources(new FileInputStream("test.xml")); resources.loadResources(); SnuaTest snuaTest = resources.getResource("test"); System.out.println(snuaTest.booleanTest); System.out.println(snuaTest.byteTest); System.out.println(snuaTest.charTest); System.out.println(snuaTest.doubleTest); System.out.println(snuaTest.floatTest); System.out.println(snuaTest.intTest); System.out.println(snuaTest.longTest); System.out.println(snuaTest.shortTest); System.out.println(snuaTest.stringTest); } } |
And the complementary test.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <resources> <define name="SnuaTest" class="SnuaTest"/> <SnuaTest name="test"> <booleanTest>false</booleanTest> <byteTest>0</byteTest> <charTest>p</charTest> <doubleTest>1d</doubleTest> <floatTest>2f</floatTest> <intTest>3</intTest> <longTest>4</longTest> <shortTest>5</shortTest> <stringTest>6</stringTest> </SnuaTest> </resources> |
And lastly, the glorious output:
1 2 3 4 5 6 7 8 9
| false 0 p 1.0 2.0 3 4 5 6 |
To download a baby, goto
https://dl.dropbox.com/u/42258713/snua.zip!