verinec.adaptation.repository
Class XSLFileRepository

java.lang.Object
  extended by verinec.adaptation.repository.XSLFileRepository
All Implemented Interfaces:
ITranslationRepository

public class XSLFileRepository
extends Object
implements ITranslationRepository

Implementation of the interface for managing the XSL translation stylesheets.

The translators and restrictors are stored in a directory named after the service they translate, the filename is the name of the implementation with the extension .xsl.
The top directory is defined by the system property verinec.adaptation.repository.xslfile_basedir which should denote either an absolute path or one relative to the current working directory. If the property is not defined, ./translation is used.

The directory structure is created as
{basedir}/{service-name}/translators/{name}.xsl
{basedir}/{service-name}/restrictors/{name}.xsl

A service-name could be 'packet-filters' or 'ethernet' (if hardware has children ethernet|wlan|serial, they are treated as service). A name could be 'iptables' or 'linux-redhat'.

If a restrictor is not present, the file {basedir}/unrestricted.xsl is used instead.

All translators and restrictors get cached. The cache never gets emptied, because we assume there is only a limited diversity of translators that gets ever used.
Translators are never re-read from file after they have been used for the first time! (Unless you restart the application, that is)

If a translator is not found in the directory, the repository tries to load it as a resource from location /res/translation/{service-name}/translators/{name}.xsl. To provide such a resource, place the file under that location into one of the jars in the classpath.

Version:
$Revision:367 $
Author:
david.buchmann at unifr.ch

Field Summary
private static File fileRoot
          The directory under which repository looks for xsl files.
private  Logger log
           
private static String RESTRICT_DIR
          Directory name inside fileRoot for restrictors
private  Hashtable restrictors
          Cache for the restrictors
private static String TRANSLATE_DIR
          Directory name inside fileRoot for translators
private  Hashtable translators
          Cache for the translators
 
Constructor Summary
XSLFileRepository()
          Instantiate the repository, creating the necessary files.
 
Method Summary
 XSLTransformer getRestrictor(String service, String name)
          Get a restriction analyzer.
 String[] getServiceNames()
          Get the names of all existing services.
 XSLTransformer getTranslator(String service, String name)
          Get a translator.
 String[] getTranslatorNames(String service)
          Get all available translators for this service
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileRoot

private static final File fileRoot
The directory under which repository looks for xsl files.

This is set by the system property verinec.adaptation.repository.xslfile_basedir and defaults to ./translation if not set.

If the files are not there, looks also in the classpath to load it as a resource from /res/translation


TRANSLATE_DIR

private static final String TRANSLATE_DIR
Directory name inside fileRoot for translators

See Also:
Constant Field Values

RESTRICT_DIR

private static final String RESTRICT_DIR
Directory name inside fileRoot for restrictors

See Also:
Constant Field Values

translators

private Hashtable translators
Cache for the translators


restrictors

private Hashtable restrictors
Cache for the restrictors


log

private Logger log
Constructor Detail

XSLFileRepository

public XSLFileRepository()
Instantiate the repository, creating the necessary files.

Method Detail

getServiceNames

public String[] getServiceNames()
Get the names of all existing services.

Specified by:
getServiceNames in interface ITranslationRepository
Returns:
The names of defined services.

getTranslatorNames

public String[] getTranslatorNames(String service)
                            throws VerinecException
Get all available translators for this service

Specified by:
getTranslatorNames in interface ITranslationRepository
Parameters:
service - Name of the service to retreive translators for
Returns:
Enumeration of String with names of all nodes that can be retreived using getNode()
Throws:
VerinecException - if there is no such service

getTranslator

public XSLTransformer getTranslator(String service,
                                    String name)
                             throws VerinecException
Get a translator.

The translator transforms a abstract xml configuration into concrete configuration for a target system.

Specified by:
getTranslator in interface ITranslationRepository
Parameters:
service - Name of the service the desired translator should be for
name - Type of target system for the translation
Returns:
The Jdom XSLTransformer for the requested service.
Throws:
VerinecException - If there is no translator

getRestrictor

public XSLTransformer getRestrictor(String service,
                                    String name)
                             throws VerinecException
Get a restriction analyzer. Restriction analyzers are normal XSLT documents. They produce warnings about what would get lost if a configuration is translated using their corresponding translator.

Specified by:
getRestrictor in interface ITranslationRepository
Parameters:
service - Name of the service this translator is for
name - Name of translation to retreive
Returns:
The Jdom XSL transformer to create restriction warnings
Throws:
VerinecException - If there is no translator

Copyright © 2005 Verinec, DIUF