Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Introduction to the XCO

DZone's Guide to

Introduction to the XCO

Don't just sit there — read David Gao's short intro to the XCO, code blocks included!

· Web Dev Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

1. Introduction to the XCO

XCO (XSON common object) is a common data object, the underlying use of a Map-like data structure for data storage access, to facilitate the way of XML data object serialization and deserialization, suitable for isomorphism, Data transfer, and exchange between heterogeneous systems.

2. Supported Data Types

  • A. 8 basic types (byte, boolean, short, int, long, float, double, char)
  • B. 8 basic types of arrays
  • E. String, String array, String collection
  • C. Date, sql.Date, sql.Time
  • D. BigInteger, BigDecimal
  • E. XCO, XCO array, XCO set

3. XML Format

<?xml version="1.0" encoding="UTF-8"?>
<X>
    <B K="byteVal" V="3"/>
    <O K="booleanVal" V="true"/>
    <H K="shortVal" V="5"/>
    <I K="intVal" V="2"/>
    <L K="longVal" V="2"/>
    <F K="floatVal" V="2.0"/>
    <D K="doubleVal" V="-0.3"/>
    <C K="charVal" V="x"/>
    <S K="stringVal" V="hello world"/>
    <A K="dateTimeVal" V="2016-09-02 16:58:25"/>
    <E K="dateVal" V="2016-09-02"/>
    <G K="TimeVal" V="16:58:25"/>
    <K K="bigIntegerVal" V="1380000"/>
    <M K="bigDecimal" V="1380000.9999"/>
    <X K="xcoVal"/>
    <IA K="intArray" V="1,3,5,8"/>
    <SA K="stringArray">
        <S V="aa"/>
        <S V="bb"/>
        <S V="cc"/>
    </SA>
    <SL K="stringList"/>
    <SS K="stringSet"/>
</X>


Description

a. Take this as an example:<H K="shortVal" V="5"/>
    H: data type identification, the current marked short type
    K: key
    V: specific values
b. Description of the data type identification
    B: byte
    H: short
    I: int
    L: Long
    F: float
    D: double
    C: char
    O: boolean
    S: String
    X: xco
    A: date
    E: sql.date
    G: sql.time
    J: sql.timestamp
    K: bigInteger
    M: bigDecimal
    ...
    See org.xson.common.object.DataType for more details

4. Common Methods


a. Assignment

    // Set a value of type int, field to key
    public final void setIntegerValue(String field, int var)

    // Set a value of type String, field for the key
    public final void setStringValue(String field, String var)

    //setXxx


b. Taking Value

    // Gets a value of type int, field is key
    public final int getIntegerValue(String field)

    // Gets a value of type String, field is key
    public final String getStringValue(String field)

    //getXxx


c. Serialization

    // The XCO object to XML way serialization
    public String toXMLString() 

    // Deserializes an XML string from an XML string into an XCO object
    public static XCO fromXML(String xml)

    // The XCO object to JSON way serialization
    public String toJSON()

5. Examples of Use

    XCO xco = new XCO();

    // Set the base type
    xco.setByteValue("byteVal", (byte) 3);
    xco.setBooleanValue("booleanVal", true);
    xco.setShortValue("shortVal", (short) 5);
    xco.setIntegerValue("intVal", 2);
    xco.setLongValue("longVal", 2L);
    xco.setFloatValue("floatVal", 2.0F);
    xco.setDoubleValue("doubleVal", -0.3D);
    xco.setCharValue("charVal", 'x');

    // Set the object type
    xco.setStringValue("stringVal", "hello world");
    xco.setDateTimeValue("dateTimeVal", new java.util.Date());
    xco.setDateValue("dateVal", new java.sql.Date(System.currentTimeMillis()));
    xco.setTimeValue("TimeVal", new java.sql.Time(System.currentTimeMillis()));
    xco.setBigIntegerValue("bigIntegerVal", new BigInteger("1380000"));
    xco.setBigDecimalValue("bigDecimal", new BigDecimal("1380000.9999"));
    xco.setXCOValue("xcoVal", new XCO());

    // Set the array
    xco.setIntegerArrayValue("intArray", new int[] { 1, 3, 5, 8 });
    xco.setStringArrayValue("stringArray", new String[] { "aa", "bb", "cc" });

    // Set the collection
    List<String> list = new ArrayList<String>();
    xco.setStringListValue("stringList", list);
    Set<String> set = new TreeSet<String>();
    xco.setStringSetValue("stringSet", set);

    // XML serialization
    String xml = xco.toXMLString();
    // deserialize
    XCO newXco = XCO.fromXML(xml);

    // taking value
    byte byteVal = xco.getByteValue("byteVal");
    boolean booleanVal = xco.getBooleanValue("booleanVal");
    short shortVal = xco.getShortValue("shortVal");
    int intVal = xco.getIntegerValue("intVal");
    long longVal = xco.getLongValue("longVal");
    float floatVal = xco.getFloatValue("floatVal");
    double doubleVal = xco.getDoubleValue("doubleVal");
    String stringVal = xco.getStringValue("stringVal");
    XCO xcoVal = xco.getXCOValue("xcoVal"); 

6. Design Drawings

Design drawings

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:
xml ,common data object ,xco ,web dev

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}