レポートを生成するか、そうでない場合は生成時にイベントに応答するための Java™ コードを作成できるようになりました。
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);
2 番目のステートメントには、以下のような効果があります。
リスナーは、GenerationResultsServer オブジェクトの removeListener メソッドに渡すことで、登録解除できます。
ワークベンチと対話する場合、生成結果リスナーを登録するプラグインを作成する必要があります。 さらに、Eclipse ランタイム・コードのデフォルトの動作をオーバーライドする必要があります。このデフォルトの動作とは通常、プラグインを、以前にロードしたプラグインによって必要とされる場合にのみロードすることを指します。
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>
id 属性には、任意の値を割り当てられます。
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
ディレクトリーは共有ディレクトリーでないことに注意してください。
installationDir¥sdp70shared¥plugins
java org.eclipse.core.launcher.Main -application
test.genresults.listener.TestCMD argument_list
argument_list は、『EGLCMD』参照トピックで説明されている引数で置き換えます。
この例では、test.genresults.listener はプラグインの名前であり、TestCMD は、plugin.xml 内の <extension> エレメントの id 属性の値です。
eglbatchgen.jar ファイルのロケーションおよび他の前提条件については、『EGL ソフトウェア開発キット (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();
}