Write XTM with tmapi-utils

This example extends the filesystem to topic map example from the last section. Now we want to serialize the filesystem topic map to an XTM file. Therefore the tmapi-utils package is used.

The topic map is written to the file specified with the second parameter to the program. This example can be found in the file examples/example3.java

Example 3. Writing XTM With tmapi-utils

	  [0] import org.tmapiutils.impexp.xtm.XTMSerializer;
	  ...
	  [1] public void printXTM(FileOutputStream os){
	  [2]	try{
	  [3]	    XTMSerializer xtmS = new XTMSerializer();
	  [4]	    xtmS.serialize(os, tm);
	  [5]	}catch(TMAPIException e){
	  [6]	    e.printStackTrace();
	  [7]	}
	  [8] }	  
	  

On line 0 the org.tmapiutils.impexp.xtm.XTMSerializer is imported. Line 3 instanciates the XTMSerializer. In line 4 the method XTMSerializer.serialize(OutputStream os, TopicMap tm) is used to serialize the given TopicMap to the given OutputStream.

Now a TMAPI implementation has to be choosen, to run this example. Cause of the Lookup Procedure for TopicMapSystemFactory Implementations, you just have to add the Jar of the TMAPI implementation to the Classpath.

Procedure 3. Compile and execute the example

  1. Compiling

    Go to the examples directory and enter the following command

    javac example3.java -classpath ".;..\tmapi-1_0.jar;{tmapi-utils-dir}\tmapi-utils-xx.jar"

  2. Execution with tinyTIM

    java -classpath ".;..\tmapi-1_0.jar;{tmapi-utils-dir}\tmapi-utils-xx.jar;{tinyTIM_Directory}\tinyTIM-1_0.jar" example3 .. ..\dir.xtm

    The Classpath contains the actual directory "." where the example1.class is located. It also contains the "tmapi-1_0.jar" from the parent directory. For writing XTM the "tmapi-utils-xx.jar" is needed. The last jar in the Classpath is the jar of the TMAPI implementation, in this case it is the "tinyTIM-1_0.jar" from the {tinyTIM_Directory}.

    The parameter after example3 ".." defines the directory to be parsed and converted to a topic map. In this case it is the parent directory. The last parameter defines the filename, where to write the serialized topic map.

  3. Execution with TM4J

    java -classpath ".;..\tmapi-1_0.jar;{tmapi-utils-dir}\tmapi-utils-xx.jar;{TM4J}\tm4j-tmapi-x.x.x.jar;{TM4J}\tm4j-x.x.x.jar;{TM4J}\resolver.jar;{TM4J}\commons-logging.jar;{TM4J}\mango.jar" example3 .. ../dir.xtm

    The Classpath contains the actual directory "." where the example3.class is located. It also contains the "tmapi-1_0.jar" from the parent directory. For writing XTM the "tmapi-utils-xx.jar" is needed. The remaining jars in the classpath are required for the TM4J implementation of TMAPI.

    The parameter after example3 ".." defines the directory to be parsed and converted to a topic map. In this case it is the parent directory. The last parameter defines the filename, where to write the serialized topic map.