com.bbn.swede.tools.codegenerator
Class AbstractCodeGenerator

java.lang.Object
  extended bycom.bbn.swede.tools.codegenerator.AbstractCodeGenerator
Direct Known Subclasses:
InterfaceGenerator, VocabularyGenerator

public abstract class AbstractCodeGenerator
extends Object

An abstract base class that provides the essential functionality for code generators. It provides persistence of generated code locations through project metadata, overwrite warnings, and a progress monitor for the generation process. Subclasses need only implement #configureProject(IProject) and #performGeneration(IOWLDocument) to handle project setup and do the actual code generation.

Extenders of the com.bbn.swede.tools.codeGenerator extension point must extend this class.

Author:
jlerner, tself

Field Summary
protected  String _sDisplayName
          The name to display in the user interface.
protected  String _sID
          The unique identifier of the generator.
 
Constructor Summary
AbstractCodeGenerator()
           
 
Method Summary
 boolean checkExisting(IOWLDocument document)
          Checks if a document has already had the generator run against it.
protected abstract  void configureProject(IProject project)
          Implement configureProject to perform any setup operations that must be completed before generated code will be usable (i.e.
 void generate(IOWLDocument document)
          This method is not intended to be overriden in subclasses.
 String getDisplayName()
          Retrieves the display name for the code generator.
 String getID()
          Retrieves the unique ID of the code generator.
protected abstract  IPath performGeneration(IOWLDocument document, IProject project, IProgressMonitor monitor)
          Runs the code generator for the given OWL document and project.
 void runGeneration(IOWLDocument document, IProgressMonitor monitor)
          Runs the heavy lifting of generating the interfaces.
 void setDisplayName(String sDisplayName)
          Sets the display name for the code generator.
 void setID(String sID)
          Sets the ID of the code generator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_sDisplayName

protected String _sDisplayName
The name to display in the user interface.


_sID

protected String _sID
The unique identifier of the generator.

Constructor Detail

AbstractCodeGenerator

public AbstractCodeGenerator()
Method Detail

configureProject

protected abstract void configureProject(IProject project)
Implement configureProject to perform any setup operations that must be completed before generated code will be usable (i.e. adding natures, classpath setup, etc.)

Parameters:
project - The project that will contain the generated code

generate

public void generate(IOWLDocument document)
This method is not intended to be overriden in subclasses. Generate code for a given OWL document in a given project. This method takes care of the entire code generation process, including automatically checking for existing generated code, configuring the project, doing the actual generation, and setting the document's metadata to reflect the location of the generated file(s).

Parameters:
document - The OWL document for which to generate code

checkExisting

public boolean checkExisting(IOWLDocument document)
Checks if a document has already had the generator run against it. If it has, the user is prompted to authorize the overwrite.

Parameters:
document - The document to check for already-generated code
Returns:
true if it's OK to proceed with the code generation, false if it should be cancelled.

runGeneration

public void runGeneration(IOWLDocument document,
                          IProgressMonitor monitor)
                   throws CoreException,
                          InterruptedException
Runs the heavy lifting of generating the interfaces. This method is called by generate inside a WorkspaceModifyOperation

Parameters:
document - The OWL document for which to generate code
monitor - A progress monitor to update as work is performed, or null to generate without a progress bar
Throws:
CoreException - if generation fails
InterruptedException - if the user cancels the operation

performGeneration

protected abstract IPath performGeneration(IOWLDocument document,
                                           IProject project,
                                           IProgressMonitor monitor)
                                    throws CoreException,
                                           InterruptedException
Runs the code generator for the given OWL document and project.

Parameters:
document - The OWL document for which to generate code
project - The project that generated files should be added to
monitor - A progress monitor to update as work is done, or null.
Returns:
a project-relative path for the generated file. If multiple files are generated, the path may refer to a directory which contains the generated files.
Throws:
CoreException - if generation fails
InterruptedException - if generation is cancelled by the user

getDisplayName

public String getDisplayName()
Retrieves the display name for the code generator. Display names are short strings suitable for use in GUIs.

Returns:
The code generator's display name

setDisplayName

public void setDisplayName(String sDisplayName)
Sets the display name for the code generator. Display names should be relatively short, as they are intended for use in GUIs.

Parameters:
sDisplayName - The new display name for the code generator

getID

public String getID()
Retrieves the unique ID of the code generator. Typically, this will be the ID of the com.bbn.swede.ui.codeGenerator extension.

Returns:
The code generator ID

setID

public void setID(String sID)
Sets the ID of the code generator. IDs must be unique.

Parameters:
sID - The new ID for the code generator.


Copyright © 2004-2005 BBN Technologies. All Rights Reserved.