www.altova.com
Previous  Top  Next

Java Interface


The AltovaXML Java interface (AltovaXML.jar) connects to the AltovaXML COM interface using native functions in the AltovaXMLLib.dll. This DLL will have been installed in the WINDIR\system32\ directory when you install AltovaXML using the AltovaXML installer. AltovaXML.jar contains the package com.altova.engines, which is the package containing the Altova engines.

 

 

Setup

In order to use the Java interface, add the AltovaXML.jar file to the CLASSPATH. COM registration is done automatically by the AltovaXML Installer. If you change the location of the file AltovaXML_COM.exe after installation, you should register AltovaXML as a COM server object by running the command AltovaXML_COM.exe /regserver. See Registering AltovaXML as a COM Server Object for more details.

 

 

Documentation

This section contains a detailed description of the AltovaXML Java interface. This documentation is also available in HTML format in the ZIP archive, AltovaXMLJavaDocs.zip, which is located in the AltovaXML2008 application folder.

 

 

Examples

For detailed examples, see the example files in the Examples folder in the application folder.

 

 

The com.altova.engines package

To use the Java interface, your starting point is the package com.altova.engines. This is the Java interface for the AltovaXML COM server object; it provides access to XMLValidator and to the XSLT 1.0, XSLT 2.0 and XQuery 1.0 engines.

 

The com.altova.engines package provides connection to the AltovaXML COM interface using the native functions in AltovaXMLLib.dll, which is installed in the WINDIR\system32\ directory.

 

To connect to a new instance of AltovaXML COM server object, use the static method getInstance() of the AltovaXMLFactory class. From the returned interface you can choose the required engine using the getENGINENAMEInstance() function.

 

Given below is a sample of code that uses the Java interface:

 

import com.altova.engines.*;

 

/**

* Test application for AltovaXML COM components java interface

*/

public class AltovaXMLTest {

   /**

    * public constructor for AltovaXMLTest

    */

   public AltovaXMLTest(){

   }

 

   /**

    * application main

    */

   public static void main(String[] args) {

       System.out.println("AltovaXML Java Interface Test Application");

 

       //request a COM server object - fails if AltovaXML is not registered

       IAltovaXMLFactory objXmlApp = AltovaXMLFactory.getInstance();

 

       if ( objXmlApp != null ) {

           //get interface for the XQuery engine

           IXQuery xquery = objXmlApp.getXQueryInstance();

           //set XQuery statement

           xquery.setXQueryStatement("<doc><a>{1 to 3}</a>This data is well-formed.</doc>");

           //execute the statement previously set.

           //There was no input XML specified so the initial context is empty.

           String sres = xquery.executeAndGetResultAsString();

           //release XQuery engine's connection to the COM server object

           xquery.releaseInstance();

           System.out.println(sres);

 

 

           IXMLValidator validator = objXmlApp.getXMLValidatorInstance();

           validator.setInputXMLFromText(sres);

           boolean b = validator.isWellFormed();

           if ( b )

               System.out.println("XML data is well-formed.");

           else

               System.out.println("Data is not well-formed.");

           validator.releaseInstance();

 

           //release Application object connection to the COM server object.

           //After this the COM server object will shut down automatically.

           objXmlApp.releaseInstance();

       } else{

           System.out.println("Creating instance of IAltovaXMLFactory failed.");

           System.out.println("Please make sure AltovaXML.exe is correctly registered!");

       }

   }

}

 


Previous  Top  Next

© 2008 Altova