Tutorial 01 - Use the CodeGenerator to process a schema.

Top  Previous  Next

12/30/2016 - The current version of the software is 3.4.1

Please upgrade if you are not using the latest version of the software.

 

Last Updated: 12-06-2016

 

In this tutorial we will use the CodeGenerator to process a schema.

 

So imagine you have the following xml document with a list of books in it.

 

<Books>

    <Book>

        <ISBN10>1781390681</ISBN10>

        <ISBN13>978-1781390689</ISBN13>

        <Title>A Christmas Carol</Title>

        <Author>

            <FirstName>Charles</FirstName>

            <LastName>Dickens</LastName>

        </Author>

        <PublishYear>1843</PublishYear>

        <ImagePath>images/a-christmas-carol.png</ImagePath>

    </Book>

    <Book>

        <ISBN10>1477581855</ISBN10>

        <ISBN13>978-1477581858</ISBN13>

        <Title>Alice's Adventures In Wonderland</Title>

        <Author>

            <FirstName>Lewis</FirstName>

            <LastName>Carroll</LastName>

        </Author>

        <PublishYear>1865</PublishYear>

        <ImagePath>images/alices-adventures-in-wonderland.png</ImagePath>

    </Book>

    <Book>

        <ISBN10>0142418218</ISBN10>

        <ISBN13>978-0142418215</ISBN13>

        <Title>Charlie and the Chocolate Factory</Title>

        <Author>

            <FirstName>Roald</FirstName>

            <LastName>Dahl</LastName>

        </Author>

        <PublishYear>1964</PublishYear>

        <ImagePath>images/charlie-and-the-chocolate-factory.png</ImagePath>

    </Book>

 

...

 

How would you go about using the wickedfast solutions tools to access the data in it.

 

First, we need a schema describing the format of the xml document.

 

Second, we need to compile that schema into java code that can be used to access the data.

 

In this tutorial, we will provide you with a schema, in later tutorials we will show you how to create your own schemas.

 

Step 1

 

Save the file http://www.wickedfastsolutions.com/resources/books-instance.xml to your desktop.

 

Step 2

 

Save the file http://www.wickedfastsolutions.com/resources/books-schema.xml to your desktop.

 

Step 3

 

Create a new folder on your desktop and call it schemas. Put the books-schema.xml file into it.

 

Step 4

 

Type the following text into the console:

 

CodeGenerator -schemaFolder ../../../schemas -outputFolder ../../../output

 

Step 5

 

Make sure that the CodeGenerator has created the following directories and files.

 

1.output/build/dist/

2.output/buld/dist/classes.jar

3.output/build/dist/classes-nodep.jar

4.output/build/dist/dependencies.jar

5.output/build/doc/

6.output/build/doc/pages/

7.output/build/doc/books-schema.html

8.output/build/doc/books-schema.xsd

9.output/build/doc/javancss.txt

10. output/build/javadoc/

11. output/build/javadoc/index.html

12. output/build/src

 

#2 contains all the classes and dependencies required for the software to run

#3 contains just the compiled domain objects with no dependencies

#4 contains just the required dependencies

#7 contains the UIDS for mapping between domains

#8 contains a w3c version of the schema (in russian doll format)

#9 contains an overview of the number of lines of code generated

#11 contains the javadoc of the generated source code

#12 contains the generated source code

 

 

 

Step 6

 

Save the file http://www.wickedfastsolutions.com/resources/BooksApplication.java to your desktop.

 

Step 7

 

Move the classes.jar located in output/build/dist/classes.jar to the desktop.

 

Step 8

 

Compile the BooksApplication.java class with the following command.

 

(If you get warnings while compiling - try using the jdk that is distributed with the tools - wickedfastsolutions-3.3.6/bin/java/bin)

 

javac -cp classes.jar BooksApplication.java

 

Step 9

 

Run the application with the following command.

 

java -cp .;classes.jar BooksApplication

 

 

console

 

Step 10

 

Notice line 7 in the books-schema.xml

 

<ISBN10 length="10">0394800168</ISBN10>

 

The length attribute specifies that the data contained in the field must be of length 10.

 

What happens if you go into the books-instance.xml and add a character to one of these fields.

 

In books-instance.xml go to line 14 and change the ISBN10 field from 1477581855 to 14775818553

 

Run the application again.

 

You should see the following output.

 

error

 

Try changing other aspects of the data and schema. You can use the syntax reference portion of the website for a full listing of all the attributes available to you.

 

Congratulations, you have just finished Tutorial-01!