Kinesis SoftwareKineticFusion

[Show Table of Contents]

5 Using The Server Component

[Hide Table of Contents]



5.1 Processing Documents Using the Server API

The Server Component provides API features for processing of both RVML and SWF documents and for analyzing external ActionScript classes.

To access the functionality of KineticFusion, it is necessary to obtain an instance of com.kinesis.server.KineticFusionServerType. This is an interface (all interfaces inside KineticFusion are normally called <Something>Type) and instances of the interface can be obtained from the class com.kinesis.server.KineticFusionServerFactory, using:

KineticFusionServerType myServer = KineticFusionServerFactory.getInstance().newServer();

Multiple servers can be instantiated and can execute at the same time - they will be automatically deleted when no longer referenced. The server is designed so that each server instance should execute in a separate thread - this enables each server to have an individual set of configuration options defined for it - however multiple instances can also be accessed serially in a single thread. However the server is designed so that multiple threads cannot simultaneously access the functionality of a single server instance.

The KineticFusionServerType interface provides the following methods:

    public ResultType processSingleRVMLMovie(RVMLInputType rvmlInput, SWFOutputType swfOutput)
														throws KineticFusionException;
	
    public boolean processSingleSWFMovie(SWFInputType swfInput, RVMLStreamOutputType rvmlOutput)
														throws KineticFusionException;
	
    public boolean processSingleSWFMovie(SWFInputType swfInput, RVMLSAXOutputType rvmlOutput)
														throws KineticFusionException;
	
    public ResultType analyzeClasses(String[] classPaths, String[] classes, int playerVersion)
														throws KineticFusionException;
											
    public String getVersion();

We will look at the first of these methods in more detail in the following sections.

5.1.1 Compiling an RVML Document

There are two mechanisms for translating RVML documents to SWF: the first mechanism is discussed in this section where the RVML is defined as an input text stream. Another mechanism exists for when the RVML already exists as an external Document Object Model. These can be processed without converting to text and is described in the Server SAX Component section.

The processSingleRVMLMovie() method is used to translate RVML text documents to SWF movies. The full signature is:

    /**
     * Process RVML input stream. An SWF movie is created and written to the
     * specified output stream.
     * 
     * @param rvmlInput
     *            Specification of the RVML input responsible for providing all
     *            required information relating to the input
     * @param swfOutput
     *            Specification of the SWF output responsible for providing all
     *            required information relating to the output
     * @return ResultType containing results of the processing operation
     * @throws KineticFusionException Wraps all embedded exceptions.
     */
    public ResultType processSingleRVMLMovie(RVMLInputType rvmlInput, 
                                             SWFOutputType swfOutput) 
                                                throws KineticFusionException;

The method takes two arguments, a specification of the input document, and a specification of the output document. The input specification is responsible for providing the input stream from which to read the RVML, the output SWF is written to a stream provided by the output specification, and the results of the operation, along with any ActionScript messages are returned to the user.

5.1.1.1 The RVML Input Document Specification

The RVML input document parameters are defined using the com.kinesis.RVMLInputType interface. This interface inherits from the descriptive com.kinesis.RVMLInputSpecificationType and provides the following methods:

public String getDocumentIdentifier()
Return a string used to identify the document in output log messages
public Map getGlobalData()
Defines a map of data that is added to the Global Data Source for the document
public File getDocumentRoot()
Defines the root location for the input document for resolving any document-relative locations
public Reader getRVMLReader()
Provides a Reader from which the RVML is read
public boolean closeReaderAfterUse()
Returns true if the reader is to be closed automatically by KineticFusion after use.
public UserResourceManagerType getResourceManager(String managerID)
Get a user-defined resource manager for resolving repository resource references

It is the responsibility of the user to provide an implementation of this interface based on the requirements of the application however we provide a demonstration class RVMLInput in the examples folder for reading from external files.

5.1.1.2 The SWF Output Document Specification

The SWF output document parameters are defined using the com.kinesis.SWFOutputType interface. This interface provides the following methods:

public String getDocumentIdentifier()
Return a string used to identify the document if output-specific errors occur
public OutputStream getOutputStream()
Get the output stream to write the generated SWF bytecode
public boolean closeStreamAfterUse()
Returns true if the output stream is to be closed by KineticFusion once the SWF is written

It is the responsibility of the user to provide an implementation of this interface based on the requirements of the application however we provide a demonstration class SWFOutput in the examples folder for writing to external files.

5.1.1.3 The Returned Results

The results from the operation are returned as an instance of the interface com.kinesis.server.ResultType. This interface defines the following methods:

public boolean isSuccess()
Returns true if the RVML was successfully compiled and written as SWF
public MessageEventType[] getProcessingMessages()
Returns an array of all the ActionScript compilation messages generated during compilation.

The quantity of messages will depend both on the configured warning levels of the messages, whether warning messages are enabled either for the document or for the server, and whether existing cached instances of classes were used. Each element of the array stores a single message and implements com.kinesis.log.MessageEventType with the following methods:

public MessagePriorityType getSeverity()
Get the severity of the message
public Integer getMessageID()
Get the message ID
public String getMessage()
Get the text of the message
public String getDocumentID()
Get the full name of the document containing the warning
public int getCol()
Get the source column number
public int getLine()
get the source line number
public String getSource()
Get the actual source line of ActionScript