JeSDOb - JENS SIMPLE DYNAMIC OBJECTS

Download

Binaries can be downloaded here.

Source can be downloaded here.

License

JesDob is released under the Apache License, Version 2.0. In short, this gives you the right do almost anything with the code or/and binaries, as long as you include the license info with your code/binaries. You can use the code in our own open/closed/commercial project in almost any way you want.

Dobs

[Scroll back up]

A Dob is a dynamic object, containing data. It is possible add attributes to a dob, and to assign values to these attributes.

				IDob dob = new Dob();
				dob.attr("name", "Jens");
				dob.attr("occupation", "Programmer");
				dob.attr("age", 30);
				dob.attr("invisible", false);
			

Is is possible to read back the values for a specific attribute.

				String name = dob.attr("name");
				boolean invisible = dob.is("invisible");
			

Dobs can be exported to text as json-format, xml-format or dob-format.

				String dobData = dob.toDob();
				String xmlData = dob.toXml();
				String jsonData = dob.toJson();
			

Dob datastrings are easy to read. They looks like this:

				[name='Jens' occupation='Programmer' age='30' invisible='false']
			

They can be saved to files, and read back as dynamic objects when they are needed.

IDob newDob = Dob.create(dobData);

Dobs can also be created directly from Dob datastrings:

				IDob anotherDob = Dob.create("[type_of_animal='cat' number_of_legs='4' has_a_tail='true']");
			

DobCollections

[Scroll back up]

A DobCollection is a collection containing one or more IDobs (dynamic objects). It is possible to add objects to a collection, and to remove objects from a collection.

				IDobCollection enemies = new DobCollection();
				enemies.add(Dob.create("[enemy='goblin' weapon='sword' strength='3' speed='8' health='10']"));
				enemies.add(Dob.create("[enemy='troll' weapon='club' strength='8' speed='1' health='70']"));
				enemies.add(Dob.create("[enemy='knight' weapon='sword' strength='7' speed='5' health='30']"));
				enemies.add(Dob.create("[enemy='dragon' weapon='breath' strength='10' speed='6' health='100']"));
			

It is possible to get IDobs from the collection, by index, or by searching a specific attribute and value.

				// Gets enemies by index.
				IDob goblin = enemies.get(0);
				IDob knight = enemies.get(2);
				
				// Gets enemies by attributes.
				IDob dragon = enemies.get("enemy", "dragon");
				IDob troll = enemies.get("weapon", "club");
				
				// Gets all enemies with swords - both the goblin and the knight.
				IDobCollection enemiesWithSwords = enemies.getAll("weapon", "sword");
			

You can also filter the DobCollection by using a IDobQuery-object. This will make the IDob-object act a bit like a database.

				/**
				 * Gets all non human enemies - the goblin, the knight and the dragon.
				 */
				IDobCollection nonHumans = enemies.filter(new DobQuery().isNot("human"));
				
				/** Gets all enemies who are not human, and where strength is bigger or equal to 5.
				 * The returned collection will contain the troll and the dragon.
				 */
				IDobCollection powerfullNonHumans = enemies.filter(new DobQuery()
						.isNot("human")
						.biggerOrEqual("strength", 5));
				
				/** 
				 * Gets all enemies who are not dragons, but where speed is bigger than 1,
				 * and where strength is bigger than five. The returned collection will
				 * contain the knight.
				 */
				IDobCollection dangerousEnemies = enemies.filter(new DobQuery()
						.notEquals("enemy", "dragon")
						.bigger("speed", 1)
						.bigger("strength", 5));
			

There are lots of options for DobQueries. Look at the JavaDocs for further info.

DobCollections can be exported to text as json-format, xml-format or dob-format. They can then be saved to files and read as dynamic objects when they are needed.

				String dobData = enemies.toDob();
				String xmlData = enemies.toXml();
				String jsonData = enemies.toJson();
			

DobFactory

[Scroll back up]

A DobFactory can be used to create Dobs from Dob datastrings, xml-data or json-data.

				IDob dobSword = DobFactory.getDob(DataFormat.DOB, "[weapon='sword' condition='mint']");
				IDob xmlSword = DobFactory.getDob(DataFormat.XML, "<weapon=\"sword\" condition=\"mint\" />");
				IDob jsonSword = DobFactory.getDob(DataFormat.JSON, "{\"weapon\": \"sword\", \"condition\": \"mint\"}");
			

Or to create DobCollections:

				IDobCollection myDobWeapons = DobFactory.getDobs(DataFormat.DOB,
						"[weapon='sword' condition='mint']"
						+ "[weapon='dagger' condition='broken']"
						+ "[weapon='spoon' condition='shiny']");

				IDobCollection myXmlWeapons = DobFactory.getDobs(DataFormat.XML,
						"<dobcollection>"
						+ "<dob weapon=\"sword\" condition=\"mint\" />"
						+ "<dob weapon=\"dagger\" condition=\"broken\" />"
						+ "<dob weapon=\"spoon\" condition=\"shiny\" />"
						+ "</dobcollection>");

				IDobCollection myJSonWeapons = DobFactory.getDobs(DataFormat.JSON,
						"{weapon=\"sword\" condition=\"mint\"}"
						+ "{weapon=\"dagger\" condition=\"broken\"}"
						+ "{weapon=\"spoon\" condition=\"shiny\"}");
			

A DobFactory can also be used to load Dobs from files a resource in your jar-file:

				try {
				  IDobCollection myDobs = DobFactory.getDobsFromResource("/resources/dobs/specialDobs.dob");
				} catch (UnsupportedFormatException ex) {
				  // Exception thrown when a specific format is not supported by the Dob-engine.
				  System.out.println(ex.getMessage());
				} catch (CouldNotLoadResourceException ex) {
				  // This is an exception thrown when a specific file could not be loaded.
				  System.out.println(ex.getMessage());
				}
			

Or from a specific file on disc:

				  IDobCollection myDobs = DobFactory.getDobsFromFile("/my_dobs/dobs.dob");
			

This makes it possible to store your Dobs separated from your source code, which makes it possible to use use Dobs for domain specific languages or scripting.

FAQ

[Scroll back up]

Q:What can Dobs be used for?
A:Almost everything: configuration files, small domain specific languages, containers for results from database queries, level-data for games. Since dobs can be exported to json, they are also very AJAX-friendly and easy to send over the web.
Q:Is jesDob used in "real" applications?
A:Yes! I've been using Dobs in everything from games to enterprise applications.
Q:How optimized is jesDob?
A:Flexibility is more prioritized than performance. You have to test if jesDob is fast enough for your needs.
Q:How can I load Dobs from resource in my libgdx-based project?
A:You can use the DobGDXFactory.java.
Q:Is it possible to use a '-char in a value in a Dob datastring?
A:Yes, you can escape the ' as \'. Example: [text='I\'m here' ], and in Java: String a = "[text='I\\'m here' ]";
Q:Is jesDob thread safe?
A:No, not really... You have to handle thread-safety on your own. However, Dobs and DobCollections are more or less immutable so thread safety doesn't need to be a big issue.
Q:Can I use jesDob in commercial applications?
A:Of course. See the license info for more details.
Q:Is there any relation between "your" Dobs and the magazine Dr. Dobbs?
A:Um... No.