Quick start
SiDO @ SF
Downloads
Javadoc
Issue tracking
Wiki

Create a SiDOL schema

Create a SiDOL schema in a file myschema.sidol. For example, schema MySchema.

a Person type
has
 a firstName,
 a lastName,
 a nullable integer as age,
 an array of string as emails
 .
						

Loads the factory and the schema

Creates a factory and loads the previously created schema:

...
DataFactory factory = DataFactories.typedFactory();
new SiDOLDataFactoryLoader().load(getClass().getResourceAsInputStream("/path/to/myschema.sidol", factory);
...
						

Creates an instance and plays with it

...
DataType type = factory.getType("MySchema::Person");
DataObject person = type.newInstance();
person.setString("firstName", "Damien");
person.setString("lastName", "Coraboeuf");
person.setInteger("age", 38);
person.setArray("emails", new Array("myemail@gmail.com", "myotheremail@yahoo.fr"));
...
						

You can also chain the calls:

...
DataType type = ;
DataObject person = factory.getType("MySchema::Person")
   .newInstance()
   .setString("firstName", "Damien")
   .setString("lastName", "Coraboeuf")
   .setInteger("age", 38)
   .setArray("emails", new Array("myemail@gmail.com", "myotheremail@yahoo.fr"));
...
						

To read the values:

...
String value = person.getString("lastName");
int age = person.getInteger("age");
Array emails = person.getArray("emails");
...
						

Reading or setting non existing properties will raise an exception:

...
person.setDecimal("wages", BigDecimal.ZERO); // This raises a DOUndefinedPropertyException
...
						

Writing/reading SiDO objects

You can write a DataObject to XML:

...
String xml = DataObjectIO.writeString(new XMLDataObjectWriter(), person);
...
						

or to JSON:

...
String json = DataObjectIO.writeString(new JSONDataObjectWriter(), person);
...
						

You can read those items back from XML:

...
DataObject o = DataObjectIO.readString(new XMLDataObjectReader(), xml);
...
						

or from JSON:

...
DataObject o = DataObjectIO.readString(new JSONDataObjectReader(), json);
...
						

XML/JSONDataObjectReader/Writer classes have also methods that allow to write/read at a lower level (to/from streams, to/from JSON/XML trees).

Copies

Any DataObject can be copied (deep copy):

DataObject copy = person.copy();
						

or made immutable:

DataObject copy = person.immutable();
copy.setString("firstName", "Albert"); // Will raise a DOImmutableException