A summary of how schemas are mapped to classes follows:
For each element in the schema there is a corresponding Java class.
If the element has data, setData() and getData() methods are provided to access and manipulate the element data.
An element containing attributes is mapped to a Java class containing an instance variable for the entire set of attributes.
Elements having attributes contain the methods setAttribute<attribute name>() and getAttribute<attribute name>() in their class for accessing and manipulating the attributes.
For elements with children, get() and set() methods are provided to access and modify child elements.
The get<element name>() methods are used to access child element class instances. They return opaque java.lang.Object. The get() methods always return a valid class instance, and through the hasValidElement() method, you can find out if the class instance holds a valid element.
The set<element name>() methods are available to access the existing child element class instances or create new child element class instances.
The root element class has more methods than member element classes because validation, serialization, deserialization and other methods are provided in the root class only.
The following table shows some highlights of the DataBeans generated for the Recipe DTD:
DTD element |
Generated Java class |
---|---|
An element containing only text. <!ELEMENT Name (#PCDATA)> |
A single Java class representing the element, with public accessor and mutator methods for the text.
public String getData() public void setData( String data ) |
An element containing child elements. <!ELEMENT Ingredient (Food, Quantity) |
A Java class representing the parent element, with public accessor and mutator methods for the child element.
public Food getFood() public Food setFood() public Quantity getQuantity() public Quantity setQuantity() |
An element containing a repeating child and attributes. <!ELEMENT IngredientList (Ingredient+)> <!ATTLIST IngredientList serves CDATA #REQUIRED> |
A Java class representing the parent element, with public methods for accessing and modifying the list of children.
public Ingredient setIngredient( int index ) public Ingredient getIngredient( int index ) java.lang.Object (getint index) java.util.List get Ingredient() void set Ingredient (Ingredient instance, int index) java.lang.String getAttributeServes(java.lang.String attrValue) |
An element containing child elements and text. Recipe is the root. <!ELEMENT Recipe (#PCDATA | IndexCard | IngredientList | StepList )*> |
A Java class representing the parent with accessor and mutator methods for each child, for the text data, and for the object. The get object method is for any element that has more than one child and enables you to retrieve the children in the order they were originally specified.
public java.util.List getIndexCard() public IndexCard getIndexCard(int index) public void setIndexCard(IndexCard instance, int index) public IndexCard setIndexCard(int index) public java.util.List getIngredientList() public IngredientList getIngredientList(int index) public void setIngredientList(IngredientList instance, int index) public IngredientList setIngredientList(int index) public java.util.List getStepList() public StepList getStepList(int index) public void setStepList(StepList instance, int index) public StepList setStepList(int index) public Data getData( int index ) public Data setData( String data, int index ) public Object get( int index ) public void setMainDocument ( com.sybase.DataBean.serializable. DataBeanSerializable mainDocument ) public void validate() public void serializeXML ( java.io.OutputStream ostrm ) public void deserializeXML ( java.io.InputStream istrm, boolean validate ) |
Copyright © 2005. Sybase Inc. All rights reserved. |
![]() |