Sie können jetzt Java™-Code schreiben, um einen Bericht oder eine andere Antwort auf Ereignisse zur Generierungszeit zu erzeugen.
generationStarted
phaseStarted
warning
generatingPart
createdArtifact
warning
createdArtifact
createdArtifact
generatingPart
warning
generatingPart
createdArtifact
information
phaseFinished
phaseStarted
generatingPart
createdArtifact
generatingPart
generatingPart
createdArtifact
phaseFinished
generationFinished
MyListenerClass myListenerObject = new MyListenerClass();
com.ibm.etools.egl.genresults.GenerationResultsServer.
getInstance().addListener(myListenerObject);
Die zweite Anweisung hat die folgenden Auswirkungen:
Sie können die Registrierung des Listeners zurücknehmen, indem Sie ihn an die Methode 'removeListener' des Objekts 'GenerationResultsServer' übergeben.
Wenn Sie mit der Workbench interagieren, müssen Sie ein Plug-in erstellen, das einen Listener für die Generierungsergebnisse registriert. Zusätzlich müssen Sie ein Standardverhalten des Eclipse-Laufzeitcodes überschreiben, das in der Regel ein Plug-in nur dann lädt, wenn das Plug-in von einem zuvor geladenen Plug-in benötigt wird.
package com.ibm.test.egl.genresults.listener;
import org.eclipse.ui.IStartup;
import com.ibm.etools.egl.genresults.GenerationResultsServer;
public class StartupClass implements IStartup
{
public void earlyStartup()
{
GenerationResultsServer.getInstance().addListener(new TestListener(true));
}
}
<extension point="org.eclipse.ui.startup">
<startup class="com.ibm.test.egl.genresults.listener.StartupClass"/>
</extension>
<extension id="TestCMD" point="org.eclipse.core.runtime.applications">
<application>
<run class="com.ibm.test.egl.genresults.listener.TestCMD"></run>
</application>
</extension>
Der Wert des Attributs id kann ein beliebiger Wert sein, den Sie zuordnen.
package com.ibm.test.egl.genresults.listener;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import com.ibm.etools.edt.core.ide.batch.EGLCMD;
import com.ibm.etools.egl.genresults.GenerationResultsServer;
public class TestCMD implements IApplication
{
@Override
public Object start( IApplicationContext appContext ) throws Exception
{
// Register a GenerationResultsListener.
GenerationResultsServer.getInstance().addListener(new TestListener(true));
// Get the command-line arguments.
String[] args = (String[])appContext.getArguments().
get( IApplicationContext.APPLICATION_ARGS );
// Pass the command-line arguments to EGLCMD.
EGLCMD.process( args );
return null;
}
@Override
public void stop()
{}
}
installationDir\sdp70\plugins
Bitte beachten Sie, dass dieses Verzeichnis ein gemeinsam genutztes Verzeichnis ist.
installationDir\sdp70shared\plugins
java org.eclipse.core.launcher.Main -application
test.genresults.listener.TestCMD argument_list
Anstelle von argument_list geben Sie die Argumente an, die im Referenzabschnitt "EGLCMD" dokumentiert sind.
In diesem Beispiel ist test.genresults.listener der Name des Plug-ins und TestCMD ist der Wert der id-Attribute im Element <extension> in 'plugin.xml'.
Einzelheiten zur Position der Datei 'eglbatchgen.jar' und anderer Voraussetzungen finden Sie unter "Generierung mit dem EGL-Software-Development-Kit (SDK)".
package example;
import com.ibm.etools.egl.genresults.GenerationResultsServer;
import com.ibm.etools.egl.util.EGLSDK;
public class EGLSDKWithListener
{
public static void main( String[] args )
{
MyListenerClass myListenerObject = new MyListenerClass();
GenerationResultsServer.getInstance().addListener(myListenerObject);
EGLSDK sdk = new EGLSDK();
sdk.process( args );
}
}
public class EGLSDK
{
/* Creates an EGLSDK object that does not print messages to System.out. */
public EGLSDK();
/* Creates an EGLSDK object that might print messages to System.out.
*
* @param printMessages true if messages should be printed to System.out.
*/
public EGLSDK(boolean printMessages);
/*
* Generates EGL.
*
* @param args are the EGLSDK command-line arguments.
*/
public void process(String[] args);
/*
* Returns the messages from the most recent call of process(String[]).
*
* @return the messages. The array may be empty but will not be null.
*/
public Message[] getMessages();
/*
* Indicates if there were any errors during generation.
*
* @return true if any errors occurred
* in the most recent call of process(String[]).
*/
public boolean generationFailed();
}
package com.ibm.etools.egl.util;
public class Message
{
public static final int ERROR_MESSAGE = 1;
public static final int WARNING_MESSAGE = 2;
public static final int INFORMATIONAL_MESSAGE = 3;
public String getText();
public int getSeverity();
public boolean isError();
}
public interface GenerationResultsListener
{
// Called when generation starts
void generationStarted( GenerationStartedEvent gse );
// Called when generation ends
void generationFinished();
// Called when a generation phase starts
void phaseStarted( GenerationPhase gp );
// Called when a generation phase ends
void phaseFinished();
// Called when generation of a part begins
void generatingPart( PartGenerationEvent event );
// Called after one generated output is created for the part
// during the most recent event of type PartGenerationEvent
void createdArtifact( ArtifactCreatedEvent event );
// Called when an error message is issued
void error( MessageEvent event );
// Called when a warning message is issued.
void warning( MessageEvent event );
// Called when an informational message is issued.
void information( MessageEvent event );
}
public interface GenerationStartedEvent
{
/**
* Returns true if generation is running in the workbench or EGLCMD,
* false if generation is running in EGLSDK.
*/
boolean generatingInEclipse();
/**
* Returns the path to the Eclipse workspace if generation is running
* in the workbench or EGLCMD. Returns the eglpath value if generation
* is running in EGLSDK.
*/
String getWorkPath();
}
public interface GenerationPhase
{
/**
* Returns a Part object (explained later)
* that gives details on the build descriptor.
*/
Part getPart();
}
public interface PartGenerationEvent
{
/**
* Returns a Part object that gives details on the part being generated.
*/
Part getPart();
}
public interface ArtifactCreatedEvent
{
/**
* Returns the path to a file generated from the part.
* The path is relative to the Eclipse workspace if generation
* is running in the workbench or EGLCMD and if the artifact was generated
* into a project named by the genProject option in the build descriptor.
*
* In other cases, the path is an absolute path in the file system.
*/
String getFileName();
/**
* Returns the absolute path to a file generated from the part.
* (The method returns the same value as getFileName if generation
* is running in EGLSDK or if the artifact was not generated into a project.)
*/
String getAbsolutePath();
}
public interface Part
{
static final int BUILD_DESCRIPTOR = 1;
static final int DEPLOYMENT_DESCRIPTOR = 2;
static final int PROGRAM = 3;
static final int LIBRARY = 4;
static final int HANDLER = 5;
static final int RECORD = 6;
static final int DATA_TABLE = 7;
static final int FORM_GROUP = 8;
static final int SERVICE = 9;
static final int DELEGATE = 10;
/**
*
* Returns the constant identifying the kind of part
* that has been generated.
*/
int getKind();
/**
* Returns the name of the part.
*/
String getName();
/**
* Returns the package name of the part.
* If the part is in the default package, an empty string is returned.
* If the part represents a build descriptor or deployment descriptor,
* the method returns null.
*/
String getPackageName();
/**
* Returns the path to the EGL file for the part. The path is relative to the
* Eclipse workspace if generation is running in the workbench or EGLCMD. The path
* is an absolute path in the file system if generation is running in EGLSDK.
*/
String getFileName();
/**
* Returns the absolute path to the EGL file for the part.
* (This method returns the same value as getFileName
* if generation is running in EGLSDK.)
*/
String getAbsolutePath();
}
public interface MessageEvent
{
static final int ERROR = 1;
static final int WARNING = 2;
static final int INFORMATION = 3;
/**
* Returns INFORMATION, WARNING, or ERROR.
*/
int getKind();
/**
* Returns the text of the message.
*/
String getText();
/**
* Returns the ID of the message.
*/
String getID();
}