skip to main content
Gantt > Programmer's documentation > Developing with the JViews Gantt SDK > Connecting to data > Connecting to XML data
 
Connecting to XML data
Describes SDXL and how to use this language to serialize schedule data.
*The SDXL format
*Explains where to find more information about the SDXL format.
*The schedule data exchange language
*Explains the SDXL language, presents the design criteria of the language as well as some scenarios of how it can be used.
*How to write an IlvGanttModel to an SDXL file using serialization
*Describes how to write IlvGanttModel objects using the ilog.views.gantt.xml package.
*How to read an IlvGanttModel from an SDXL file using serialization
*Describes how to read IlvGanttModel objects by using the ilog.views.gantt.xml package.
*Handling exceptions while reading SDXL files
*Describes how to handle exceptions during serialization.
The SDXL format
JViews Gantt allows you to serialize schedule data to Schedule Data Exchange Language (SDXL) files. Use the classes in ilog.views.gantt.xml. You can find a description of the SDXL format in Content and structure of an XML data file in Using the Designer. You can also find the DTD specification of the SDXL format in Document type definition for SDXL.
You can find the DTD file in:
<installdir>/jviews-gantt/data/sdxl.dtd
The schedule data exchange language
The Gantt chart ( IlvGanttChart) and the Schedule chart ( IlvScheduleChart) are designed to visualize and to edit schedule data in a JViews Gantt model ( IlvGanttModel). Users of the Gantt chart and the Schedule chart need first to save their schedule data and then to exchange the schedule data with other users.
SDXL is an application of W3C XML. It is designed to meet the following needs:
*Serialize the schedule data (IlvGanttModel) represented by an IlvGanttChart or an IlvScheduleChart. This allows users to save their schedule data to SDXL files and to load the saved schedule data from SDXL files.
*Exchange the schedule data with other programs developed with or without JViews Gantt. Since SDXL is an application of W3C XML, it can be easily read by other programs that are capable of reading XML files. It can also be translated to other formats by using technologies such as XSL.
Scenarios of how SDXL can be used
Since SDXL is a flexible XML application, its usage is not limited in scope.
However, to give a general idea, imagine the following scenarios:
*You use a JViews Gantt program to manage your projects. The program is heavy because it is connected to a database and uses the database to store the schedule data. SDXL can help distribute this schedule data. You can save your schedules to SDXL files and distribute them by means of a lightweight JViews Gantt program that does not need database connections.
*You use a JViews Gantt program to manage your schedules. You can save your schedules to SDXL files. An optimization program loads the SDXL files and runs optimization algorithms to make your schedules more efficient. Then, you reload the optimized schedules by using your JViews Gantt program to visualize them.
API for reading and writing SDXL
The following figure shows that the ilog.views.gantt.xml contains all the classes that make it possible to serialize schedule data to SDXL files:
The previous figure shows how the ilog.views.gantt.xml package can serialize schedule data contained in an IlvGanttModel to SDXL files. The ilog.views.gantt.xml package is based on java.io and JAXP (Java™ API for XML Processing) since it has to use java.io APIs and JAXP to read and write SDXL files.
To be able to use the ilog.views.gantt.xml package, you need both:
*The JViews Gantt JAR files.
*Some JAR files of the Rogue Wave® JViews Framework library, provided in
<installdir>/jviews-framework/lib/external
To use these libraries, you need a thin and lightweight API that provides a standard way to seamlessly integrate any XML-compliant parser with a Java application. JViews Gantt comes with the Apache™ Xerces parser implementation.
The ilog.views.gantt.xml package is designed to serialize schedule data defined by the following classes:
*IlvSimpleActivity and IlvGeneralActivity
*IlvSimpleResource and IlvGeneralResource
*IlvSimpleReservation and IlvGeneralReservation
*IlvSimpleConstraint and IlvGeneralConstraint
*IlvDefaultGanttModel
If your Gantt data model is exclusively defined by these classes, the ilog.views.gantt.xml package contains all the classes you need to serialize your schedule data. The following table lists by level the readers and writers available in the package. An interface is given for each reader or writer. This interface defines the functionality the reader or the writer must implement. One of the benefits of using interfaces is that you can interchange readers or writers that implement the same interface. This makes the package flexible and customizable.
For each reader and writer, the package provides two default implementations. The “simple” implementations read and write the default data model classes, while the “general” implementations read and write the data model classes that support user-defined properties.
These can be used as-is.
Level
Functions
Interfaces
Default implementations in the ilog.views.gantt.xml package
Level 1: Element readers and writers
Read/write an activity, a resource, a reservation, or a constraint from/to an element
IlvActivityReader
IlvActivityWriter
IlvResourceReader
IlvResourceWriter
IlvReservationReader
IlvReservationWriter
IlvConstraintReader
IlvConstraintWriter
IlvSimpleActivityReader
IlvSimpleActivityWriter
IlvSimpleResourceReader
IlvSimpleResourceWriter
IlvSimpleReservationReader
IlvSimpleReservationWriter
IlvSimpleConstraintReader
IlvSimpleConstraintWriter
IlvGeneralActivityReader
IlvGeneralActivityWriter
IlvGeneralResourceReader
IlvGeneralResourceWriter
IlvGeneralReservationReader
IlvGeneralReservationWriter
IlvGeneralConstraintReader
IlvGeneralConstraintWriter
Level 2: Document reader and writer
Read/write a Gantt data model from/to a document
 
IlvGanttDocumentReader
IlvGanttDocumentWriter
Level 3: Stream writer
Write a document to an OutputStream
 
IlvGanttStreamWriter
The readers and writers are arranged by levels. Level 1 is the lowest level and level 3 is the highest. In most cases, the readers and writers of level N are based on the readers and writers of level N-1. For example, to read a Gantt data model from a document, the IlvGanttDocumentReader (level 2) uses element readers (level 1), that is, IlvSimpleActivityReader, IlvSimpleResourceReader, IlvSimpleReservationReader, and IlvSimpleConstraintReader.
*IlvGanttDocumentReader is at the highest level (level 2) among the readers. This reader can read an IlvGanttModel instance from a document. The document is the only input of the package. To read a Gantt data model, the user must provide a document object. See How to read an IlvGanttModel from an SDXL file using serialization for information on how to create a document from an SDXL file by using JAXP.
*IlvGanttStreamWriter is at the highest level (level 3) among the writers. It is capable of writing an IlvGanttModel instance to an OutputStream object. The OutputStream is the only output point of the package. Users who want to write an SDXL file should provide an OutputStream. See How to write an IlvGanttModel to an SDXL file using serialization for information on how to create an OutputStream object for an SDXL file by using the java.io package.
Customizing readers and writers
The default readers and writers provided by JViews Gantt are sufficient to serialize default Gantt data models. If you created a customized Gantt data model, you need to customize the default readers and writers in order to serialize the customized schedule data. All level readers and writers are customizable. You can customize them either by creating subclasses of the default readers and writers implemented, or by writing you own readers or writers that implement the reader or writer interfaces.
How to write an IlvGanttModel to an SDXL file using serialization
This section shows how to use the main classes of the ilog.views.gantt.xml package. You will learn how to write an IlvGanttModel to an SDXL file and then how to read back an IlvGanttModel from an SDXL file.
Two examples show how to serialize schedule data:
*<installdir>/jviews-gantt/samples/xmlGantt/src/xml/XMLGanttExample.java presented in:
<installdir>/jviews-gantt/samples/xmlGantt.
*<installdir>/jviews-gantt/samples/xmlSchedule/src/xml/XMLScheduleExample.java presented in:
<installdir>/jviews-gantt/samples/xmlSchedule.
To write the contents of an IlvGanttModel to an SDXL file, follow these recommended stages:
1. Creating an org.w3c.dom.Document: Use your XML Java™ API to create an instance of org.w3c.dom.Document.
2. Creating an IlvGanttDocumentWriter: Use the ilog.views.gantt.xml package to create an instance of IlvGanttDocumentWriter.
3. Writing a Gantt data model to a document: Use the IlvGanttDocumentWriter to write your IlvGanttModel to the document you created in Step 1.
4. Creating an output stream: Use the java.io package to create a java.io.OutputStream object for the SDXL file you want to write to.
5. Creating a stream writer: Use the ilog.views.gantt.xml package to create an instance of IlvGanttStreamWriter.
6. Writing a document to an output stream: Use the stream writer to write the document to the output stream you created in Step 4.
Creating an org.w3c.dom.Document
This section shows you how to use the javax.xml.parsers package to create an org.w3c.dom.Document instance. This is one of many ways of creating document objects. You can, of course, use other ways.
To create a new org.w3c.dom.Document instance:
1. Import the packages:
import javax.xml.parsers.*;
import org.w3c.dom.*;
2. Get an instance of the DocumentBuilderFactory:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
3. Get an instance of DocumentBuilder from the DocumentBuilderFactory:
DocumentBuilder builder = factory.newDocumentBuilder();
4. Use the DocumentBuilder to create the document object:
Document document = builder.newDocument();
See
<installdir>/jviews-gantt/samples/xmlGantt/src/xml/XMLGanttActions.java
for a concrete implementation.
Creating an IlvGanttDocumentWriter
Use the ilog.views.gantt.xml package to create an instance of IlvGanttDocumentWriter. Then the document writer is ready to write an IlvGanttModel to a document.
The IlvGanttDocumentWriter constructor takes a locale as argument that affects how dates are serialized. In the example the document writer is configured to use the current locale.
To create a new IlvGanttDocumentWriter instance:
1. Import the package:
import ilog.views.gantt.xml.*;
2. Create the IlvGanttDocumentWriter:
IlvGanttDocumentWriter documentWriter =
    new IlvGanttDocumentWriter(Locale.getDefault());
Writing a Gantt data model to a document
The IlvGanttDocumentWriter has a method called writeGanttModel.
To write your Gantt data model:
*Call writeGanttModel
documentWriter.writeGanttModel(document, yourGanttModel);
The document argument is the document object you created in Creating an org.w3c.dom.Document. The argument yourGanttModel is the IlvGanttModel you want to write to the document.
Creating an output stream
You can use the java.io package to create an OutputStream. This is one of many ways of creating output streams. You can, of course, use other ways.
To create an OutputStream instance:
1. Import the java.io package:
import java.io
2. Create an OutputStream for the file you want to write to:
String filename = "c:\mysdxl.xml";
FileOutputStream outstream = new FileOutputStream(filename);
The argument filename is the name of the SDXL file you want to write to.
Creating a stream writer
After creating the OutputStream, you need a utility class that helps you write the document to the stream. The ilog.views.gantt.xml package provides a stream writer named IlvGanttStreamWriter. You can directly create an instance of this class and use it to write your document. The stream writer is ready to write a document object to an OutputStream.
To create an OutputStream instance:
1. Import the ilog.views.gantt.xml package:
import ilog.views.gantt.xml
2. Create the stream writer:
IlvGanttStreamWriter streamWriter = new IlvGanttStreamWriter();
Writing a document to an output stream
Now that you have the OutputStream instance and the document, you can write your document to the OutputStream object.
To do this:
1. Call the writeDocument method of the stream writer created in the previous step to write the document to the OutputStream.
streamWriter.writeDocument(outstream, document);
2. Close the output stream:
outstrem.close();
Your IlvGanttModel is written to an SDXL file.
How to read an IlvGanttModel from an SDXL file using serialization
Change the itemized list back to a numbered list in XML.
To read the contents of an SDXL file to an IlvGanttModel, follow these recommended stages:
*Creating an input source: Use your XML Java™ API to create an InputSource for the file you want to read.
*Parsing an input source: Use Java XML parser to parse the InputSource in order to get an org.w3c.dom.Document.
*Creating an IlvGanttDocumentReader: Use the ilog.views.gantt.xml package to create an instance of IlvGanttDocumentReader.
*Reading a Gantt data model from a document: Create a target IlvGanttModel to receive the schedule data and use the IlvGanttDocumentReader to read the document created in Step 2 to the IlvGanttModel created in Step 4.
*Handling exceptions while reading SDXL files
These stages are seen in more detail in the subsequent sections.
Creating an input source
You can use your XML Java API to create an InputSource instance for the SDXL file you want to read. This section presents one of many ways of creating input sources. You can, of course, use other ways.
To create an InputSource instance for the SDXL file you want to read:
1. Import the package:
import org.xml.sax.*;
Suppose you want to read an SDXL file named /nfs/works/myschedule.xml:
String url = "file:///nfs/works/myschedule.xml";
2. You can create directly an InputSource for the file to read:
InputSource source = new InputSource(url);
The input source is ready to be parsed by your XML parser.
Parsing an input source
The DocumentBuilder provided by your XML Java API can parse an input source. You can create an instance of the builder and use it to parse the input source.
To parse an input source:
1. Import the packages:
import javax.xml.parsers.*;
import org.w3c.dom.*;
2. Get an instance of the DocumentBuilderFactory:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
3. Get an instance of DocumentBuilder from the DocumentBuilderFactory:
DocumentBuilder builder = factory.newDocumentBuilder();
4. Use the DocumentBuilder to parse the input source:
Document document = builder.parse(source);
Now you need an IlvGanttDocumentReader instance to read the document.
Creating an IlvGanttDocumentReader
The ilog.views.gantt.xml package provides the IlvGanttDocumentReader class.
To create an instance of this class:
1. Import the package:
import ilog.views.gantt.xml.*;
2. Create the IlvGanttDocumentReader:
IlvGanttDocumentReader documentReader = new IlvGanttDocumentReader();
The document reader is ready to read a document.
Reading a Gantt data model from a document
The IlvGanttDocumentReader class has a method called readGanttModel. You can call this method to read a JViews Gantt model from a document. Before reading the document you must create a target IlvGanttModel to receive the schedule data.
To read a Gantt data model from a document:
1. Import the ilog.views.gantt and ilog.views.gantt.model packages:
import ilog.views.gantt.*;
import ilog.views.gantt.model.*;
2. Create a default Gantt data model:
IlvGanttModel model = new IlvDefaultGanttModel();
3. Read the Gantt data model from the document:
documentReader.readGanttModel(document, model);
The document argument is the document object you created in the previous step.
Your IlvGanttModel has now been read from an SDXL file.
Handling exceptions while reading SDXL files
Exceptions might be encountered during the reading of the document. The exceptions are reported by IlvGanttReaderException objects. The following example shows how to handle such exceptions.
try {
  docReader.readGanttModel(document, model);
} catch(IlvGanttReaderException e) {
  //...

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.