ptolemy.copernicus.applet
Class AppletWriter

java.lang.Object
  extended by soot.Transformer
      extended by soot.SceneTransformer
          extended by ptolemy.copernicus.applet.AppletWriter
All Implemented Interfaces:
soot.HasPhaseOptions

public class AppletWriter
extends soot.SceneTransformer
implements soot.HasPhaseOptions

A transformer that writes an applet version of a model. For a model called Foo, we generate Foo/makefile, Foo/Foo.xml, Foo/Foo.htm Foo/FooVergil.htm in the directory named by the outputDirectory parameter.

The model is traversed and jar files are found for each class. If a model uses other code by reference at runtime, then if the model includes a parameter named "_jnlpClassesToJars", then that parameter is expected to be an array of two element arrays, where the first element is dot separated class name, and the second element is the slash separated path to the jar file. For example, {{"ptolemy.domains.sdf.kernel.SDFDirectory", "ptolemy/domains/sdf/sdf.jar"}} means that sdf.jar should be included in the jar files.

Potential future enhancements

  • Pull out the top level annotation and add the text to the web page.
  • Since:
    Ptolemy II 2.0
    Version:
    $Id: AppletWriter.java 59167 2010-09-21 17:08:02Z cxh $
    Author:
    Christopher Hylands
    Accepted Rating:
    Red (cxh)
    Proposed Rating:
    Red (cxh)

    Field Summary
    private  java.lang.String _codeBase
               
    private  java.lang.String _configurationName
               
    private  boolean _debug
               
    private  java.lang.String _domainJar
               
    private  java.lang.String _jnlpJars
               
    private  CompositeActor _model
               
    private  java.lang.String _modelJarFiles
               
    private  java.lang.String _modelPath
               
    private  java.lang.String _outputDirectory
               
    private  java.lang.String _ptIIJarsPath
               
    private  java.lang.String _ptIILocalURL
               
    private  java.lang.String _ptIIUserDirectory
               
    private  java.lang.String _sanitizedModelName
               
    private  java.util.Map _substituteMap
               
    private  java.lang.String _targetPackage
               
    private  java.lang.String _targetPath
               
    private  java.lang.String _templateDirectory
               
    private  java.lang.String _vergilJarFiles
               
    private static java.lang.String TEMPLATE_DIRECTORY_DEFAULT
               
     
    Constructor Summary
    private AppletWriter(CompositeActor model)
              Construct a new transformer
     
    Method Summary
    private  java.util.Map _allAtomicEntityJars()
               
    private  java.util.Map _allAttributeJars(CompositeEntity compositeEntity)
               
    private static java.lang.String _checkForJNLPExtensions(java.lang.String jarFileName)
               
    private  void _copyFile(java.lang.String sourceFileName, java.lang.String destinationDirectory, java.lang.String destinationFileName)
               
    private  boolean _copyJarFiles(java.util.Map classMap, java.util.HashSet jarFilesThatHaveBeenRequired)
              Copy the jar files listed in the map.
    private static void _copyModelRemoveGeneratorTableau(java.net.URL modelPathURL, java.io.File newModelFile)
               
    private  boolean _copyPotentialJarFile(java.lang.String jarFile, java.lang.String className, java.util.HashSet jarFilesThatHaveBeenRequired)
               
    private  void _createJarFile(java.io.File jarFile, java.io.File optionalJarFile, java.lang.String[] jarFileNames, java.io.File[] filesToBeJared)
              Create a jar file.
    private  java.util.Map _deepOpaqueEntityJars()
               
    private  java.util.Set _findModelJarFiles(Director director)
               
    private  java.util.Set _findVergilJarFiles(Director director, java.util.Set modelJarFiles)
               
    private static java.lang.String _getDomainJar(java.lang.String domainPackage)
               
    private static java.lang.String _getToplevelDocumentation(java.net.URL modelPathURL)
              Get the top level documentation.
    private  java.lang.String _jarFileLengthAttribute(java.lang.String fileName)
              Return the file size as a JNLP file attribute
    private static void _signJarFile(java.lang.String jarFileName, java.lang.String signedJarFileName)
              Sign a jar file.
    private  java.lang.String[] _updateJar(java.util.jar.JarOutputStream jarOutputStream, java.util.jar.JarInputStream jarInputStream, java.lang.String[] jarFileNames)
              Update a jar file and ignore filenames that are in jarFileNames.
    private  java.util.Map _userSpecifiedJars()
               
     java.lang.String getDeclaredOptions()
              Return the declared options.
     java.lang.String getDefaultOptions()
              Return the default options.
     java.lang.String getPhaseName()
              Return the phase name.
    protected  void internalTransform(java.lang.String phaseName, java.util.Map options)
              Save the model as an applet.
    static AppletWriter v(CompositeActor model)
              Return an instance of this transformer that will operate on the given model.
     
    Methods inherited from class soot.SceneTransformer
    transform, transform, transform
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    _codeBase

    private java.lang.String _codeBase

    _configurationName

    private java.lang.String _configurationName

    _debug

    private boolean _debug

    _domainJar

    private java.lang.String _domainJar

    _model

    private CompositeActor _model

    _modelJarFiles

    private java.lang.String _modelJarFiles

    _modelPath

    private java.lang.String _modelPath

    _outputDirectory

    private java.lang.String _outputDirectory

    _sanitizedModelName

    private java.lang.String _sanitizedModelName

    _ptIIJarsPath

    private java.lang.String _ptIIJarsPath

    _ptIILocalURL

    private java.lang.String _ptIILocalURL

    _ptIIUserDirectory

    private java.lang.String _ptIIUserDirectory

    _substituteMap

    private java.util.Map _substituteMap

    _targetPackage

    private java.lang.String _targetPackage

    _targetPath

    private java.lang.String _targetPath

    _templateDirectory

    private java.lang.String _templateDirectory

    TEMPLATE_DIRECTORY_DEFAULT

    private static final java.lang.String TEMPLATE_DIRECTORY_DEFAULT
    See Also:
    Constant Field Values

    _vergilJarFiles

    private java.lang.String _vergilJarFiles

    _jnlpJars

    private java.lang.String _jnlpJars
    Constructor Detail

    AppletWriter

    private AppletWriter(CompositeActor model)
    Construct a new transformer

    Method Detail

    v

    public static AppletWriter v(CompositeActor model)
    Return an instance of this transformer that will operate on the given model. The model is assumed to already have been properly initialized so that resolved types and other static properties of the model can be inspected.

    Parameters:
    model - The model that this class will operate on.
    Returns:
    An instance of the AppletWriter transformer.

    getDefaultOptions

    public java.lang.String getDefaultOptions()
    Return the default options. The default options for this transformer is the string:
      templateDirectory: ptolemy/copernicus/applet/
      

    Specified by:
    getDefaultOptions in interface soot.HasPhaseOptions
    Returns:
    the default options.

    getDeclaredOptions

    public java.lang.String getDeclaredOptions()
    Return the declared options. The declared options for this transformer is the string
      modelPath outputDirectory ptIIJarsPath ptIILocalURL ptIIUserDirectory targetPackage targetPath templateDirectory
      

    Specified by:
    getDeclaredOptions in interface soot.HasPhaseOptions
    Returns:
    the declared options.

    getPhaseName

    public java.lang.String getPhaseName()
    Return the phase name. The phase name of this transformer is the empty string.

    Specified by:
    getPhaseName in interface soot.HasPhaseOptions
    Returns:
    the phase name.

    internalTransform

    protected void internalTransform(java.lang.String phaseName,
                                     java.util.Map options)
    Save the model as an applet.

    For example, if the model is called MyModel, and this phase is called with:

            -p wjtp.appletWriter targetPackage:foo.bar
      
    Then we will create the directory $PTII/foo/bar/MyModel and place MyModel.xml, MyModel.htm, MyModelVergil.htm in that directory.

    Specified by:
    internalTransform in class soot.SceneTransformer
    Parameters:
    phaseName - The name of the phase, for example wjtp.appletWriter.
    options - The options Map. This method uses the targetPackage option to specify package to generate code in.

    _allAttributeJars

    private java.util.Map _allAttributeJars(CompositeEntity compositeEntity)

    _allAtomicEntityJars

    private java.util.Map _allAtomicEntityJars()

    _deepOpaqueEntityJars

    private java.util.Map _deepOpaqueEntityJars()

    _checkForJNLPExtensions

    private static java.lang.String _checkForJNLPExtensions(java.lang.String jarFileName)

    _copyModelRemoveGeneratorTableau

    private static void _copyModelRemoveGeneratorTableau(java.net.URL modelPathURL,
                                                         java.io.File newModelFile)
                                                  throws java.lang.Exception
    Throws:
    java.lang.Exception

    _copyPotentialJarFile

    private boolean _copyPotentialJarFile(java.lang.String jarFile,
                                          java.lang.String className,
                                          java.util.HashSet jarFilesThatHaveBeenRequired)
                                   throws java.io.IOException
    Throws:
    java.io.IOException

    _copyJarFiles

    private boolean _copyJarFiles(java.util.Map classMap,
                                  java.util.HashSet jarFilesThatHaveBeenRequired)
                           throws java.io.IOException
    Copy the jar files listed in the map.

    Parameters:
    classMap - A map consisting of String keys that are dot separated class name and a value that is a String naming a jar file.
    jarFilesThatHaveBeenRequired - A set of strings that is set to the names of the jar files that have been found.
    Returns:
    true if there was a problem and the jar files need to be fixed because "make install" was not run.
    Throws:
    java.io.IOException

    _copyFile

    private void _copyFile(java.lang.String sourceFileName,
                           java.lang.String destinationDirectory,
                           java.lang.String destinationFileName)
                    throws java.io.IOException
    Throws:
    java.io.IOException

    _getToplevelDocumentation

    private static java.lang.String _getToplevelDocumentation(java.net.URL modelPathURL)
                                                       throws java.lang.Exception
    Get the top level documentation. We reparse the model because the filters will have removed the DocAttribute and the Annotations

    Returns:
    the value DocAttribute.description or the longest Annotation.text if there is no DocAttribute
    Throws:
    java.lang.Exception

    _jarFileLengthAttribute

    private java.lang.String _jarFileLengthAttribute(java.lang.String fileName)
                                              throws java.io.IOException
    Return the file size as a JNLP file attribute

    Throws:
    java.io.IOException

    _findModelJarFiles

    private java.util.Set _findModelJarFiles(Director director)
                                      throws java.io.IOException
    Throws:
    java.io.IOException

    _findVergilJarFiles

    private java.util.Set _findVergilJarFiles(Director director,
                                              java.util.Set modelJarFiles)
                                       throws java.io.IOException
    Throws:
    java.io.IOException

    _getDomainJar

    private static java.lang.String _getDomainJar(java.lang.String domainPackage)

    _signJarFile

    private static void _signJarFile(java.lang.String jarFileName,
                                     java.lang.String signedJarFileName)
                              throws java.lang.Exception
    Sign a jar file.

    Throws:
    java.lang.Exception

    _createJarFile

    private void _createJarFile(java.io.File jarFile,
                                java.io.File optionalJarFile,
                                java.lang.String[] jarFileNames,
                                java.io.File[] filesToBeJared)
                         throws java.lang.Exception
    Create a jar file. Based on http://www.java2s.com/Code/Java/File-Input-Output/CreateJarfile.htm

    Throws:
    java.lang.Exception

    _updateJar

    private java.lang.String[] _updateJar(java.util.jar.JarOutputStream jarOutputStream,
                                          java.util.jar.JarInputStream jarInputStream,
                                          java.lang.String[] jarFileNames)
                                   throws java.io.IOException
    Update a jar file and ignore filenames that are in jarFileNames.

    Parameters:
    jarOutputStream - The Jar output stream to be written.
    jarInputStream - The Jar output stream to be read.
    jarFileNames - An array of file names that have been already added to the jar file.
    Returns:
    An array of jar file names that have already been added to the jar file _and_ that were added by this method.
    Throws:
    java.io.IOException

    _userSpecifiedJars

    private java.util.Map _userSpecifiedJars()