korat.gui.viz
Class ToXMLInstanceConverter

java.lang.Object
  extended by korat.gui.viz.ToXMLInstanceConverter

public class ToXMLInstanceConverter
extends Object

Converts arbitrary object into Alloy4Viz instance (.xml) file and theme (.thm) file. Those two files should be given to VizGUI instance in order to visualize its object structure.

Author:
Aleksandar Milicevic

Field Summary
private static String[] colors
           
static String DEFAULT_MODELS_HOME
           
static String DEFAULT_THEMES_HOME
           
private  String generatedModelFilename
           
private  String generatedThemeFilename
           
private static String[] shapes
           
private  boolean skipThemeGeneration
           
protected  Map<AlloyAtom,Object> visited
           
protected  Stack<AlloyAtom> workList
           
 
Constructor Summary
ToXMLInstanceConverter()
           
ToXMLInstanceConverter(boolean generateTheme)
           
 
Method Summary
private  void buildModel(Object obj)
           
 void convert(Object obj)
          Performs conversion of the given object.
 void convert(Object obj, int idx)
          Performs conversion of the given object.
 void convert(Object obj, PrintStream instanceXMLStream, PrintStream themeXMLStream)
          Performs conversion of the given object.
 void convert(Object obj, String suffix)
          Performs conversion of the given object.
 String getGeneratedModelFilename()
           
 String getGeneratedThemeFilename()
           
private  void handleArrayField(Object obj, Field f, AlloySig clzSig, AlloyAtom atom)
           
private  void handleClass(Class clz, AlloyAtom atom)
           
private  void handleCollectionField(Object obj, Field f, AlloySig clzSig, AlloyAtom atom)
           
private  void handleFields(Class clz, AlloyAtom atom)
           
private  void handlePrimitives(Object obj, Field f, AlloySig objSig, AlloyAtom objAtom)
           
private  void writeInstanceXML(PrintStream ps, String filename, String command)
           
private  void writeThemeXML(PrintStream ps)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

visited

protected Map<AlloyAtom,Object> visited

workList

protected Stack<AlloyAtom> workList

DEFAULT_MODELS_HOME

public static final String DEFAULT_MODELS_HOME
See Also:
Constant Field Values

DEFAULT_THEMES_HOME

public static final String DEFAULT_THEMES_HOME
See Also:
Constant Field Values

generatedThemeFilename

private String generatedThemeFilename

generatedModelFilename

private String generatedModelFilename

skipThemeGeneration

private boolean skipThemeGeneration

colors

private static final String[] colors

shapes

private static final String[] shapes
Constructor Detail

ToXMLInstanceConverter

public ToXMLInstanceConverter(boolean generateTheme)

ToXMLInstanceConverter

public ToXMLInstanceConverter()
Method Detail

getGeneratedModelFilename

public String getGeneratedModelFilename()

getGeneratedThemeFilename

public String getGeneratedThemeFilename()

convert

public void convert(Object obj)
             throws UnsupportedTypeException
Performs conversion of the given object. The resultant files will have default names and will be stored to default location. Relative file names of those files can be retrieved by calling getGeneratedModelFilename and getGeneratedThemeFilename methods.

Parameters:
obj - object to convert to alloy instance & theme file
Throws:
UnsupportedTypeException - currently, the only primitive type that is supported is int. If any other primitive type is found, the exception will be thrown.

convert

public void convert(Object obj,
                    int idx)
             throws UnsupportedTypeException
Performs conversion of the given object. The resultant files will have default names (with the given index at the end) and will be stored to default location. Relative file names of those files can be retrieved by calling getGeneratedModelFilename and getGeneratedThemeFilename methods.

Parameters:
obj - object to convert to alloy instance & theme file
idx - index to append at the end of the instance file name
Throws:
UnsupportedTypeException - currently, the only primitive type that is supported is int. If any other primitive type is found, the exception will be thrown.

convert

public void convert(Object obj,
                    String suffix)
             throws UnsupportedTypeException
Performs conversion of the given object. The resultant files will have default names (with the given suffix at the end) and will be stored to default location. Relative file names of those files can be retrieved by calling getGeneratedModelFilename and getGeneratedThemeFilename methods.

Parameters:
obj - object to convert to alloy instance & theme file
suffix - suffix to append at the end of the instance file name
Throws:
UnsupportedTypeException - currently, the only primitive type that is supported is int. If any other primitive type is found, the exception will be thrown.

convert

public void convert(Object obj,
                    PrintStream instanceXMLStream,
                    PrintStream themeXMLStream)
             throws UnsupportedTypeException
Performs conversion of the given object. The content of the generated instance and theme files will be sent to the given print streams (instanceXMLStream and themeXMLStream respectively).

Parameters:
obj - object to convert to alloy instance & theme
instanceXMLStream - stream to write the instance file to
themeXMLStream - stream to write the theme file to
Throws:
UnsupportedTypeException - currently, the only primitive type that is supported is int. If any other primitive type is found, the exception will be thrown.

writeThemeXML

private void writeThemeXML(PrintStream ps)

writeInstanceXML

private void writeInstanceXML(PrintStream ps,
                              String filename,
                              String command)

buildModel

private void buildModel(Object obj)
                 throws UnsupportedTypeException
Throws:
UnsupportedTypeException

handleClass

private void handleClass(Class clz,
                         AlloyAtom atom)
                  throws UnsupportedTypeException
Throws:
UnsupportedTypeException

handleFields

private void handleFields(Class clz,
                          AlloyAtom atom)
                   throws UnsupportedTypeException
Throws:
UnsupportedTypeException

handleArrayField

private void handleArrayField(Object obj,
                              Field f,
                              AlloySig clzSig,
                              AlloyAtom atom)
                       throws IllegalArgumentException,
                              IllegalAccessException
Throws:
IllegalArgumentException
IllegalAccessException

handleCollectionField

private void handleCollectionField(Object obj,
                                   Field f,
                                   AlloySig clzSig,
                                   AlloyAtom atom)
                            throws IllegalArgumentException,
                                   IllegalAccessException
Throws:
IllegalArgumentException
IllegalAccessException

handlePrimitives

private void handlePrimitives(Object obj,
                              Field f,
                              AlloySig objSig,
                              AlloyAtom objAtom)
                       throws UnsupportedTypeException,
                              IllegalAccessException
Throws:
UnsupportedTypeException
IllegalAccessException