|
|
Writing the code to launch a Ketuk applicationThe class XBMapper is used to maintain links between a XML source document and generated components. An instance of this class must be created, using the source XML document and the XSLT transformations to apply as parameters. org.w3c.Document sourceDoc = ...; // the XML source document org.w3c.Document xslDoc = ...; // the XSLT document XBMapper mapper = new XBMapper(sourceDoc, xslDoc); The generated component is represented by the return value of the method processBM. If the bean is a window component, it can directly be displayed on the screen. Otherwise, it should be included in a Frame. The following code illustrates the different possibilities:
Object resultObj = mapper.processBM();
if (resultObj == null) {
System.err.println("no bean is created");
System.exit(1);
}
else if (Window.class.isAssignableFrom(resultObj.getClass())) {
// if the result object is a Window, there's only to set is
// as visible
((Window)resultObj).setVisible(true);
}
else if (Component.class.isInstance(resultObj)) {
// if the result object is another kink of component
// it should be included in a JFrame
JFrame f = new JFrame();
f.getContentPane().add((Component)resultObj);
f.pack();
f.setVisible(true);
}
To be able to receive and process XEditEvents, a listener for these events must be placed on a class implementing XEditListener. The xEditPerformed method is called each time a modification is performed on the source XML document. After the code reating and initializing the XBMapper, the line below has to be added: mapper.addXEditListener(theXEditListener); theXEditListener being an instance of the following class:
public class XListen implements XEditListener {
public void xEditPerformed(XEditEvent xe) {
... specific code handling XEdit events
}
}
Most application will only need to handle END events to output the content of the modified source document ; by calling a specific serialize method for example:
public void xEditPerformed(XEditEvent xe) {
if (xe.getEventType() == XEditEvent.END) {
serialize(mapper.getXmlDocument());
}
}
|
|
|
|
|
Created by Claude Pasquier |
|