/*-------------------------------------------------------------------------
jConX java Configuration for Xml library
$Date: 2002/10/19 $

@author: Filippo Diotalevi <filipd@libero.it>

http://jconx.sourceforge.net/

Please report bugs to filipd@libero.it. Thank you.

Copyright (c) 2002 Filippo Diotalevi <filipd@libero.it>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------*/

*******************************************

"jConX: A 5-minutes tutorial"
Firt jConX tutorial

By Filippo Diotalevi <filipd@libero.it>
version 0.1
23th October 2002

*******************************************



Please read "jConX: installing tutorial" first.


jConX has been developed thinking primarily to be easy to use.

In this tutorial you'll learn how to use jConX to bind data contained in
a really simple xml configuration file with data contained in some fields
of a java bean.

Consider this simple xml file (simple.xml):

---
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <first>this is my first try</first>
    <second type="integer">12345</second>
    <another>another tag</another>
    <another id="2">hello world!</another>
    </root>
---


OK.
Now let's write the bean that will contain data stored in xml file.


---

import it.fdiotalevi.jconx.BaseConfiguration;
import it.fdiotalevi.jconx.BaseInternalNode;

public class Simple extends BaseConfiguration //The main class must extend BaseConfiguration
{
    public BaseInternalNode first = new BaseInternalNode(); //A simple node (with no child, only text
    public BaseInternalNode second = new BaseInternalNode(); //or attributes) must be of BaseInternalNode
    public BaseInternalNode another = new BaseInternalNode(); //type


    public BaseInternalNode getFirst() {
       return first;
    }
    public void setFirst(BaseInternalNode first) {
       this.first = first;
    }

    public BaseInternalNode getSecond() {
       return second;
    }
    public void setSecond(BaseInternalNode second) {
       this.second = second;
    }


    public BaseInternalNode getAnother() {
       return another;
    }
    public void setAnother(BaseInternalNode another) {
       this.another = another;
    }

}

---

It may seem quite a long class for such a simple xml file! but with a modern
java IDE it will take you no more than 90 seconds.... (i tried!)


OK guys... that's all...
Let's see jConX at work now

---
import it.fdiotalevi.jconx.ConfigurationReader;
import it.fdiotalevi.jconx.ConfigurationReaderFactory;

public class TrySimple {

public static void main(String[] args)
{
try
{
       ConfigurationReader cr = new ConfigurationReaderFactory(Simple.class).create(); //create a ConfigurationReader
       Simple obj = (Simple) cr.parse("simple.xml"); //parse xml configuration file

       //Print value of 'first' tag
       System.out.println("FIRST = "+obj.first.value);

       //Print value of 'second' tag
       System.out.println("SECOND = "+obj.second.value);
       //Print value of attribute 'type'
       System.out.println("SECOND attribute 'type' = "+obj.second.attribute("type"));

       //Print value of first 'another' tag
       System.out.println("ANOTHER = "+obj.another.value);
       //Print value of attribute 'id' //IT DOES NOT EXISTS!!!!!!!!!!
       System.out.println("ANOTHER attribute 'id' = "+obj.another.attribute("id"));

       //Condider the next 'another' tag
       obj.another.next();
       //Print value of second 'another' tag
       System.out.println("ANOTHER = "+obj.another.value);
       //Print value of attribute 'id'
       System.out.println("ANOTHER attribute 'id' = "+obj.another.attribute("id"));


    }
    catch (Exception e)
    {
       System.out.println(e.getMessage());
    }
}
}
---

Isn't it lovely?

Run it, and look at the console:

FIRST = this is my first try
SECOND = 12345
SECOND attribute 'type' = integer
ANOTHER = another tag
ANOTHER attribute 'id' = null
ANOTHER = hello world!
ANOTHER attribute 'id' = 2


really simple, isn't it?
jConX has much more interesting features! But there's not enough time for them, in a 5-minutes tutorial!

Enjoy jConX! Regards,
Filippo Diotalevi <filipd@libero.it>