inf.compilers
Class SyntaxAdaptorRegistry

java.lang.Object
  extended by inf.compilers.SyntaxAdaptorRegistry

public class SyntaxAdaptorRegistry
extends java.lang.Object

This class can be used to specify the SyntaxAdaptors that are to be used for a given combination of an internal representation class and an external syntactical language. It is used, for example, by an XmlAdaptor to determine which SyntaxAdaptor to use for an inner expression in a layered language.

Author:
Gerhard Wickler

Field Summary
protected  java.util.Map<java.lang.String,java.util.Map<java.lang.Class<? extends SyntaxAdaptable>,SyntaxAdaptor<? extends SyntaxAdaptable>>> byExtern
          the Map to SyntaxAdaptors using the external language as the primary key
protected  java.util.Map<java.lang.Class<? extends SyntaxAdaptable>,java.util.Map<java.lang.String,SyntaxAdaptor<? extends SyntaxAdaptable>>> byIntern
          the Map to SyntaxAdaptors using the internal class as the primary key
 
Constructor Summary
SyntaxAdaptorRegistry()
           
 
Method Summary
protected  java.lang.Object clone()
          This class does not support cloning and an exception will be thrown if this method is called.
 java.util.Map<java.lang.String,SyntaxAdaptor<? extends SyntaxAdaptable>> forClass(java.lang.Class<? extends SyntaxAdaptable> intern)
           This function retrieves a Map from languages used as external representations to SyntaxAdaptors for the given internal language.
 java.util.Map<java.lang.Class<? extends SyntaxAdaptable>,SyntaxAdaptor<? extends SyntaxAdaptable>> forSyntax(java.lang.String extern)
           This function retrieves a Map from classes used as internal representations to SyntaxAdaptors for the given external language.
 SyntaxAdaptor<? extends SyntaxAdaptable> getSyntaxAdaptor(java.lang.Class<? extends SyntaxAdaptable> intern, java.lang.String extern)
           This function retrieves the previously registered SyntaxAdaptor for the given internal and external representation.
 int hashCode()
          This class does not support hashing and an exception will be thrown if this method is called.
 void register(SyntaxAdaptor<? extends SyntaxAdaptable> adaptor)
           This function registers the given SyntaxAdaptor with this SyntaxAdaptorRegistry.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

byIntern

protected java.util.Map<java.lang.Class<? extends SyntaxAdaptable>,java.util.Map<java.lang.String,SyntaxAdaptor<? extends SyntaxAdaptable>>> byIntern
the Map to SyntaxAdaptors using the internal class as the primary key


byExtern

protected java.util.Map<java.lang.String,java.util.Map<java.lang.Class<? extends SyntaxAdaptable>,SyntaxAdaptor<? extends SyntaxAdaptable>>> byExtern
the Map to SyntaxAdaptors using the external language as the primary key

Constructor Detail

SyntaxAdaptorRegistry

public SyntaxAdaptorRegistry()
Method Detail

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException

This class does not support cloning and an exception will be thrown if this method is called.

Overrides:
clone in class java.lang.Object
Returns:
nothing
Throws:
java.lang.CloneNotSupportedException - will be thrown

register

public void register(SyntaxAdaptor<? extends SyntaxAdaptable> adaptor)

This function registers the given SyntaxAdaptor with this SyntaxAdaptorRegistry. The given SyntaxAdaptor must not be null. The internal class and the name of the external language are extracted from the SyntaxAdaptor. If there was a SyntaxAdaptor that was previously registered for the same combination of internal and external representation, this will be replaced.

Parameters:
adaptor - the new SyntaxAdaptor to be added

getSyntaxAdaptor

public SyntaxAdaptor<? extends SyntaxAdaptable> getSyntaxAdaptor(java.lang.Class<? extends SyntaxAdaptable> intern,
                                                                 java.lang.String extern)

This function retrieves the previously registered SyntaxAdaptor for the given internal and external representation. If there is no SyntaxAdaptor for the given internal representation class, this function will try to find a SyntaxAdaptor for the nearest super-class or interface.

Parameters:
intern - the Class used as the internal representation
extern - the name of the external language
Returns:
a SyntaxAdaptor that adapts between the given representations, or null if none has been registered

forSyntax

public java.util.Map<java.lang.Class<? extends SyntaxAdaptable>,SyntaxAdaptor<? extends SyntaxAdaptable>> forSyntax(java.lang.String extern)

This function retrieves a Map from classes used as internal representations to SyntaxAdaptors for the given external language. This Map should not be modified!

Parameters:
extern - the name of the external language
Returns:
a Map with values being all the registered SyntaxAdaptors for the given language

forClass

public java.util.Map<java.lang.String,SyntaxAdaptor<? extends SyntaxAdaptable>> forClass(java.lang.Class<? extends SyntaxAdaptable> intern)

This function retrieves a Map from languages used as external representations to SyntaxAdaptors for the given internal language. This Map should not be modified!

Parameters:
intern - the Class used as the internal representation
Returns:
a Map with values being all the registered SyntaxAdaptors for the given internal representation class

hashCode

public int hashCode()
             throws java.lang.UnsupportedOperationException

This class does not support hashing and an exception will be thrown if this method is called.

Overrides:
hashCode in class java.lang.Object
Returns:
nothing
Throws:
java.lang.UnsupportedOperationException - will be thrown