IBM FileNet P8, バージョン 5.2.1            

CodeModule オブジェクトの作成

提供されている Java™ および C# の例では、複数のアクション・ハンドラーを格納する JAR ファイルが、オブジェクト・ストアの CodeModules フォルダーにチェックインされます。

CodeModule オブジェクトのコンテンツがクラス・ファイルまたは JAR ファイルで構成される可能性があるため、このコードは ContentTransfer オブジェクトの ContentType プロパティーを設定するために、Java モジュールの種類を調べます。このとき CodeModule オブジェクトにチェックインする必要があります。チェックインしないと、このコードは CodeModule オブジェクトの予約 (進行中) バージョンとして保管されるため、Action サブオブジェクトを作成しようとすると例外が発生します。

この例には、CodeModule オブジェクトを作成するのと同じ手順で Action サブオブジェクトを作成する方法を示すオプション・コードも含まれています。このような手順は、コード・モジュール作成のための選択肢をユーザーに提供するイベント・アクションの作成ウィザードで役立ちます。これらのオブジェクトを両方とも作成する手順をコード化する場合は、必ず Action サブオブジェクトの作成時の潜在的な例外をトラップして、前に作成された CodeModule オブジェクトを catch ブロックで削除してください。この処理を行わない場合、例外が発生すると、コードを再実行したときに、最初の CodeModule オブジェクトのコピーが作成されます。作成例外をスローするエラーとして、CodeModule オブジェクトのチェックインが失敗すること、または Action サブオブジェクトの ProgId プロパティーが誤った値に設定されることが考えられます。

Java の例

...
// Create a File object for the JAR containing the event handlers.
File handlerJar = new File("C:¥¥EclipseWorkspace¥¥EventHandlers¥¥EventHandlers.jar");
// non-Windows: File handlerJar = new File("/EclipseWorkspace/EventHandlers/EventHandlers.jar");

// オブジェクト・ストアに JAR を保管する既存フォルダーのオブジェクトを取得する
Folder folder=Factory.Folder.fetchInstance(os, "/CodeModules", null);

// JAR コンテンツから ContentTransfer オブジェクトを作成する
ContentElementList contentList = Factory.ContentTransfer.createList();
ContentTransfer ctNew;
FileInputStream fileIS;
ctNew = Factory.ContentTransfer.createInstance();
fileIS = new FileInputStream(handlerJar.getAbsolutePath());
ctNew.setCaptureSource(fileIS);

// Java モジュールがクラスであるか JAR であるかによって MIME タイプを設定する
String fileName = handlerJar.getName();
if (fileName.endsWith(".class"))
{
   ctNew.set_ContentType("application/java-byte-code");
}
else if (fileName.endsWith(".jar"))
{
   ctNew.set_ContentType("application/java-archive");
}

// コンテンツ・エレメントをリストに追加する (リストは CodeModule オブジェクトに追加される)
contentList.add(ctNew);

// CodeModule オブジェクトを作成する
CodeModule newCM = Factory.CodeModule.createInstance(os, "CodeModule"); 
// DocumentTitle プロパティーを設定する
String propertyName = "DocumentTitle";
newCM.getProperties().putValue(propertyName, "Java Event Handlers");
// コンテンツ・エレメントを CodeModule オブジェクトに追加する
newCM.set_ContentElements(contentList);

// CodeModule オブジェクトをチェックインする
newCM.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
newCM.save(RefreshMode.REFRESH);

// CodeModule オブジェクトをファイリングして、保存する
DynamicReferentialContainmentRelationship drcr 
   = (DynamicReferentialContainmentRelationship)folder.file((IndependentlyPersistableObject)newCM,
      AutoUniqueName.AUTO_UNIQUE,
      "Java Event Handlers",
      DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
drcr.save(RefreshMode.NO_REFRESH);
//////////////////////////////////////////////
// 以下のコードはオプションです。Action サブオブジェクトの作成方法を記述したものです。
// このコードの場合、EventAction を使用して例外処理コードを記述しています。
try
{
   EventAction eventAction = Factory.EventAction.createInstance(os, null);
   eventAction.set_ProgId("RenameActionHandler");
   eventAction.set_CodeModule(newCM);
   eventAction.set_DisplayName("EventActionWithCodeModule");
   eventAction.save(RefreshMode.REFRESH);
}
catch (Exception e)
{
   System.out.println("EventAction creation failed: " + e.getMessage());
   newCM.delete();
   newCM.save(RefreshMode.REFRESH);
}

C# の例

...
// Create a FileInfo object for the JAR containing the event handlers.
FileInfo handlerJar = new FileInfo (@"C:¥¥EclipseWorkspace¥¥EventHandlers¥¥EventHandlers.jar");

// オブジェクト・ストアに JAR を保管する既存フォルダーのオブジェクトを取得する
IFolder folder = Factory.Folder.FetchInstance(os, "/CodeModules", null);

// JAR コンテンツから ContentTransfer オブジェクトを作成する
IContentElementList contentList = Factory.ContentTransfer.CreateList();
IContentTransfer ctNew;
FileStream fileS = handlerJar.OpenRead();
ctNew = Factory.ContentTransfer.CreateInstance();
ctNew.SetCaptureSource(fileS);

// Java モジュールがクラスであるか JAR であるかによって MIME タイプを設定する
string filename = handlerJar.Name;
if (filename.EndsWith(".class"))
{
   ctNew.ContentType = "application/java-byte-code";
}
else if (filename.EndsWith(".jar"))
{
   ctNew.ContentType = "application/java-archive";
}

// コンテンツ・エレメントをリストに追加する (リストは CodeModule オブジェクトに追加される)
contentList.Add(ctNew);

// CodeModule オブジェクトを作成する
ICodeModule newCM = Factory.CodeModule.CreateInstance(os, "CodeModule");

// DocumentTitle プロパティーを設定する
newCM.Properties["DocumentTitle"] = "Java Event Handlers");

// コンテンツ・エレメントを CodeModule オブジェクトに追加する
newCM.ContentElements = contentList;

// CodeModule オブジェクトをチェックインする
newCM.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
newCM.Save(RefreshMode.REFRESH);

// CodeModule オブジェクトをファイリングして、保存する
IDynamicReferentialContainmentRelationship drcr
   = (IDynamicReferentialContainmentRelationship) folder.File((IIndependentlyPersistableObject)newCM,
      AutoUniqueName.AUTO_UNIQUE,
      "Java Event Handlers",
      DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
drcr.Save(RefreshMode.NO_REFRESH);
//////////////////////////////////////////////
// 以下のコードはオプションです。IAction サブオブジェクトの作成方法を記述したものです。
// このコードの場合、IEventAction を使用して例外処理コードを記述しています。
try
{
   IEventAction eventAction = Factory.EventAction.CreateInstance(os, null);
   eventAction.ProgId = "RenameActionHandler";
   eventAction.CodeModule = newCM;
   eventAction.DisplayName = "EventActionWithCodeModule";
   eventAction.Save(RefreshMode.REFRESH);
}
catch (Exception e)
{
   System.Console.WriteLine("EventAction creation failed: " + e.Message );
   newCM.Delete();
   newCM.Save(RefreshMode.REFRESH);
}


最終更新日: 2015 年 10 月
server_procedures_codemodule_creating.htm

© Copyright IBM Corp. 2015.