Basic operation of the model

1. Get the model

    A model can be obtained by path to the model. The path rules of the model are basically the same as the rules of Java class names, except that the path of the model can also include the path of the child nodes. Such as test.HelloWorldModel is the path of the descriptor model.

import org.xmeta.Thing;
import org.xmeta.World;

// get the descriptor model
Thing thing = World.getInstance().getThing("test.HelloWorldModel");

2. Attributes and child nodes of the model

    The model (Thing) itself is a Map<String, Object>, and the child node of the model is a List<Thing>.

// get the value of the property
Object value = thing.get("name");

// set the value of the property
thing.set("name", "Hello World");

//Get the value of the attribute and convert it to the corresponding type, supporting the conversion of common types
//Generally the getX(Stirng name) method, where X is the corresponding type
int age = thing.getInt("age");
//Note: Attributes do not necessarily need to be defined in the model (XML), but undefined attributes will not be saved to XML when serialized and stored

//Get the child nodes of the model
List<Thing> childs = thing.getChilds();

3. Use code to create and save models

import org.xmeta.Thing;

//Create a model using the descriptor's path
Thing thing = new Thing("Person");

//Specify to save, _local is the name of the model manager, test.Zhangsan is the path of the model
thing.saveAs("_local", "test.Zhangsan");

//Save, if the model has been set with a model manager and path, it can be serialized and stored directly;

4. Model and XML generation

// Parse the model from XML
thing.parseXML(String xml);

// Convert the model to XML
String xml = thing.toXML();


Copyright ©  2007-2019  版权所有  沪ICP备08000575号