코드 생성의 세부사항을 캡처하기 위한 Java 코드 작성
보고서를 생성하거나 아니면 생성 시 이벤트에 대해 응답하기 위한 Java™ 코드를 작성할 수 있습니다.
제품은 com.ibm.etools.egl.genresults라는 패키지의 com.ibm.etools.egl라는
플러그인에 다음의 코드를 제공합니다.
- 리스너를 작성하기 위해 구현하는 Java 인터페이스. 이 인터페이스의 이름은 GenerationResultsListener입니다.
- 두 번째 Java 인터페이스 세트와 이를 구현하는 제품 클래스.
제품 클래스는 리스너에서 다음 메소드를 호출합니다.
- 생성의 시작 시 generationStarted.
- 생성 단계의 시작 시 phaseStarted 및
이 단계의 종료 시 phaseFinished. 생성
단계는 출력 파일 세트가 작성되는 기간입니다.
- 이전 생성 모드가 적용되는 경우 파일이 기본 파트 및 연관에 해당하거나
- "파트에 의한 생성" 모드가 적용되는 경우 파일이 단일 파트에 해당합니다.
제품 클래스는 각 단계 중 다음의 메소드를 호출할 수 있습니다.- 파트에 대한 모든 출력의 생성이 시작될 때 generatingPart.
- 출력 파일이 생성되었을 때 createdArtifact. 제품은 출력 파일의 위치에 대한 세부사항을 제공합니다.
- 제품이 특정 종류의 메시지를 발행할 때 error, warning 및 information.
- 생성이 종료될 때 generationFinished.
다음은 생성 중 발생할 수 있는 호출의 순서입니다.
generationStarted
phaseStarted
warning
generatingPart
createdArtifact
warning
createdArtifact
createdArtifact
generatingPart
warning
generatingPart
createdArtifact
information
phaseFinished
phaseStarted
generatingPart
createdArtifact
generatingPart
generatingPart
createdArtifact
phaseFinished
generationFinished
일반적으로 다음과 같이 수행하십시오.
- 인터페이스 세부사항 절에 설명된 바와 같이 GenerationResultsListener 인터페이스를 구현하기 위한 클래스를 작성하십시오.
- 리스너를 작성하기 위한 클래스를 인스턴스화한 후 EGL 생성기에
리스너를 등록하십시오. 예는 다음과 같습니다.
MyListenerClass myListenerObject = new MyListenerClass(); com.ibm.etools.egl.genresults.GenerationResultsServer. getInstance().addListener(myListenerObject);두 번째 명령문은 다음과 같은 영향을 줍니다.
- 해당 클래스의 정적 getInstance 메소드를 호출하여 GenerationResultsServer 오브젝트를 확보합니다.
- GenerationResultsServer 오브젝트의 addListener 메소드로 myListenerObject라는 리스너를 전달합니다.
GenerationResultsServer 오브젝트의 removeListener 메소드에 전달하여 리스너의 등록을 취소할 수 있습니다.
이 태스크에 대한 자세한 정보는 사용자의 필요에 맞는 절을 참조하십시오.
워크벤치와 상호작용
워크벤치와 상호작용하는 경우 생성 결과 리스너를 등록하는 플러그인을 작성해야 합니다. 또한 일반적으로 이전에 로드된 플러그인에 필요할 때에만 플러그인을 로드하는 Eclipse 런타임 코드의 기본 동작을 대체해야 합니다.
다음과 같이 수행하십시오.
- 사용자의 코드를 플러그인에 입력하고 사용자의 플러그인이 다음 플러그인에
종속되도록 MANIFEST.MF 파일을 업데이트하십시오.
- 제품 설치 디렉토리에 있는 com.ibm.etools.egl.
- org.eclipse.ui.
- 하나의 메소드 earlyStartup만 있는
Java 인터페이스인 org.eclipse.ui.IStartup을
구현하는 클래스를 작성하십시오. earlyStartup을 구현하면
다음 예와 같이 리스너 오브젝트가 등록됩니다.
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)); } } - plugin.xml 파일에 다음 항목을 포함하십시오.
<extension point="org.eclipse.ui.startup"> <startup class="com.ibm.test.egl.genresults.listener.StartupClass"/> </extension> - 다음과 같이 jar 파일에 플러그인을 내보내십시오.
- 를 클릭하십시오. 내보내기 페이지가 열립니다.
- 플러그인 개발을 펼치고 배치 가능한 플러그인 및 단편을 클릭하십시오. 배치 가능한 플러그인 및 단편 페이지가 열립니다.
- 페이지의 중간에 있는 대상 탭에 Eclipse dropins 폴더(예: C:\Program Files\IBM\SDP80\dropins)를 지정하십시오.
- 옵션 탭을 클릭하고 개별 JAR 아카이브로 플러그인 패키징이 선택되어 있는지 확인하십시오.
- 완료를 클릭하십시오. jar 파일은 dropins 폴더의 plugins 폴더에 있습니다.
- Windows 탐색기를 열고 plugins 폴더로 이동하십시오.
- dropins 폴더에 바로 배치되도록 새 jar 파일을 이동하십시오.
- 비어 있는 plugins 폴더를 삭제하십시오.
워크벤치 일괄처리 인터페이스(EGLCMD) 사용
워크벤치 일괄처리 인터페이스(EGLCMD)를 사용하는 경우 다음과 같이
수행하십시오.
- 플러그인을 작성하십시오.
- 플러그인이 제품 설치 디렉토리에 있는 com.ibm.etools.egl 플러그인에 종속되도록 MANIFEST.MF 파일을 업데이트하십시오.
- plugin.xml 파일에 있는 다음의 코드 예와 같이 플러그인이 org.eclipse.core.runtime.applications라는
확장점을 참조하는지 확인하십시오.
<extension id="TestCMD" point="org.eclipse.core.runtime.applications"> <application> <run class="com.ibm.test.egl.genresults.listener.TestCMD"></run> </application> </extension>id 속성의 값은 사용자가 지정하는 값입니다.
class 속성의 값은 Eclipse IApplication 인터페이스를 구현하고 GenerationResultsListener 오브젝트를 등록하고 com.ibm.etools.edt.core.ide.batch.EGLCMD.process 메소드에 명령행 인수를 전달하는 클래스를 식별합니다. 다음은 이러한 클래스의 예입니다.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() {} } - 다음과 같이 jar 파일에 플러그인을 내보내십시오.
- 를 클릭하십시오. 내보내기 페이지가 열립니다.
- 플러그인 개발을 펼치고 배치 가능한 플러그인 및 단편을 클릭하십시오. 배치 가능한 플러그인 및 단편 페이지가 열립니다.
- 페이지의 중간에 있는 대상 탭에 Eclipse dropins 폴더(예: C:\Program Files\IBM\SDP80\dropins)를 지정하십시오.
- 옵션 탭을 클릭하고 개별 JAR 아카이브로 플러그인 패키징이 선택되어 있는지 확인하십시오.
- 완료를 클릭하십시오. jar 파일은 dropins 폴더의 plugins 폴더에 있습니다.
- Windows 탐색기를 열고 plugins 폴더로 이동하십시오.
- dropins 폴더에 바로 배치되도록 새 jar 파일을 이동하십시오.
- 비어 있는 plugins 폴더를 삭제하십시오.
- Java 클래스 경로가 다음 JAR 파일에
대한 액세스를 제공하는지 확인하십시오.
- 다음 디렉토리에 있는
org.eclipse.equinox.launcher_version.jar.
installationDir\sdp70\plugins- installationDir
- 제품 설치 디렉토리(예: C:\Program Files\IBM).
디렉토리가 공유 디렉토리가 아님을 참고하십시오.
- 다음 디렉토리에 있는
com.ibm.etools.edt.core.ide.version.
installationDir\sdp70shared\plugins- installationDir
- 제품 설치 디렉토리(예: C:\Program Files\IBM).
- 다음 디렉토리에 있는
org.eclipse.equinox.launcher_version.jar.
- 다음과 같이 애플리케이션을 호출하십시오.
java org.eclipse.core.launcher.Main -application test.genresults.listener.TestCMD argument_listargument_list 대신 "EGLCMD" 참조 주제에 설명된 인수를 대체하십시오.
이 예에서 test.genresults.listener는 플러그인의 이름이고 TestCMD는 plugin.xml에 있는 <extension> 요소의 id 속성에 대한 값입니다.
EGL Software Development Kit(EGLSDK) 사용
EGL Software Development Kit(EGLSDK)을 사용하는 경우
사용자의 Java 클래스를 작성하고
EGLSDK 명령 대신 이를 실행해야 합니다.
- eglbatchgen.jar 파일을 사용할 수 있도록 클래스 경로를 설정하십시오.
- 사용자의 코드를 개발할 때 eglbatchgen.jar 파일이 Java 컴파일러의 클래스 경로에 있어야 합니다.
- 코드를 실행하는 경우 eglbatchgen.jar 파일이 CLASSPATH 시스템 변수에 있어야 합니다.
eglbatchgen.jar 파일의 위치 및 기타 전제조건에 대한 자세한 정보는 "EGL SDK(Software Development Kit)를 사용한 생성"을 참조하십시오.
- 다음의 예와 같이 유형이 GenerationResultsListener인 오브젝트를
등록하고 EGLSDK 오브젝트를 작성하십시오.
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 ); } } - EGLSDK 명령을 호출하는 경우와 동일한 인수를 사용하여
EGLSDK 명령 대신 클래스를 실행하십시오. 다음은 인스턴스화하는 EGLSDK 클래스에 대한 자세한 정보입니다.
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(); }다음은 EGLSDK 클래스에 참조되는 메시지 클래스입니다.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(); }
EGL Ant 스크립트 사용
EGL Ant 스크립트를 사용하는 경우 다음과 같이 수행하십시오.
- 단편 프로젝트를 작성하십시오. 호스트 플러그인을 com.ibm.etools.edt.ant로 설정해야 합니다.
- GenerationResultsListener를 구현하는 생성 리스너 클래스를 정의하십시오.
- 다음과 같이 jar 파일에 플러그인을 내보내십시오.
- 를 클릭하십시오. 내보내기 페이지가 열립니다.
- 플러그인 개발을 펼치고 배치 가능한 플러그인 및 단편을 클릭하십시오. 배치 가능한 플러그인 및 단편 페이지가 열립니다.
- 페이지의 중간에 있는 대상 탭에 Eclipse dropins 폴더(예: C:\Program Files\IBM\SDP80\dropins)를 지정하십시오.
- 옵션 탭을 클릭하고 개별 JAR 아카이브로 플러그인 패키징이 선택되어 있는지 확인하십시오.
- 완료를 클릭하십시오. jar 파일은 dropins 폴더의 plugins 폴더에 있습니다.
- Windows 탐색기를 열고 plugins 폴더로 이동하십시오.
- dropins 폴더에 바로 배치되도록 새 jar 파일을 이동하십시오.
- 비어 있는 plugins 폴더를 삭제하십시오.
- -clean을 사용하여 RBD를 다시 시작하고 단편 jar이 선택되었는지 확인하십시오.
- 새 스크립트를 작성하거나 기존 Ant 스크립트를 여십시오.
- "generationListenerClass"를 egl.generate 또는 egl.cmd에 추가하십시오. 샘플
스크립트는 다음과 같습니다.
<egl.generate part="pkg1.*" project="testJava" buildDescriptorFile="testJava/EGLSource/testJava.eglbld" buildDescriptorName="testJavaJavaBuildOptions" generationListenerClass="com.hjiyong.TestListener" verbose="yes" /> - Ant 스크립트를 실행하십시오.
인터페이스 세부사항
다음은 GenerationResultsListener 인터페이스입니다.
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 );
}
다음은 추가 Java 인터페이스입니다.
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();
}