IBM FileNet P8, バージョン 5.2.1            

ライフサイクル関連オブジェクトの操作

ライフサイクル・ポリシーを使用して Document オブジェクトを制御するには、DocumentLifecyclePolicy オブジェクトが必要です。このオブジェクトは、ドキュメントが遷移する状態と、状態遷移に対応して実行されるアクションを指定します。「ライフサイクル・アクション」で説明したように、アクションをライフサイクル・アクション・ハンドラーにコーディングし、DocumentLifecycleAction オブジェクトにより参照することができます。次に DocumentLifecyclePolicy オブジェクトで DocumentLifecycleAction が設定されます。

DocumentLifecycleAction オブジェクトとライフ・サイクル・アクション・ハンドラーが存在しない場合は、最初にオブジェクトとハンドラーを作成してから、DocumentLifecyclePolicy オブジェクトを関連付ける必要があります。以降のトピックではこの手順を説明します。

作成した DocumentLifecyclePolicy オブジェクトを、Document オブジェクトまたは Document クラスあるいはサブクラスに割り当てることができます。 「DocumentLifecyclePolicy オブジェクトの割り当て」を参照してください。

DocumentLifecyclePolicy オブジェクトの効果を得るには、DocumentLifecyclePolicy オブジェクトが割り当てられているドキュメントの状態を変更する必要があります。「ドキュメントの状態の変更」を参照してください。

DocumentLifecyclePolicy オブジェクトを取得して、このオブジェクトのプロパティーとアクセス権限を設定および取得することができます。「DocumentLifecyclePolicy オブジェクトの取得」を参照してください。

ライフサイクル・ポリシーの概要については、『ライフサイクル・ポリシー』を参照してください。

ライフサイクル・アクション・ハンドラーの作成

ドキュメント・ライフサイクル・アクション・ハンドラーを作成するには、Java™ DocumentLifecycleActionHandler インターフェースのすべてのメソッドを実装する必要があります。Java による実装と JavaScript による実装の例を以下に示します。各メソッドのパラメーターは同じです。状態が変化する Document オブジェクトと、Document オブジェクトに付加された DocumentLifecyclePolicy オブジェクトです。基本的に、各メソッドではドキュメントの現行の状態を判別し、その状態に基づいて何らかの操作を実行します。ドキュメントの状態は、ポリシーの DocumentState オブジェクトのリストで定義されています。ドキュメントが昇格または降格すると状態が順序に従って遷移し、リセットするとドキュメントは最初の状態に設定されます。例外発生時にはドキュメントが現行状態でフリーズされ、例外が取り除かれるとドキュメントの状態が遷移可能になります。

このハンドラー例では、ポリシーが付加されたドキュメントの名前に状態の変更が反映されます。ドキュメントの状態が変更されると、ポリシーによりドキュメントの現行状態がドキュメント名に付加されます。例えば、自動車ローン・ドキュメントが申請 (application) 状態から承認 (approval) 状態に遷移し、さらに融資 (funding) 状態に遷移すると、このドキュメントの名前は、「CarLoan_Application」から「CarLoan_Approval」、さらに「CarLoan_Funding」に変更されます。このシナリオに適用できるドキュメント・ライフサイクル・ポリシーのサンプル・コードについては、「DocumentLifecyclePolicy オブジェクトの作成」を参照してください。

実装の詳細については、アクション・ハンドラーを参照してください。 Content Engine のパッケージに含まれる DocumentLifecycleActionHandler 実装のサンプル・ソース・コードを表示するには、以下の Content Engine ディレクトリーに移動してください。
  • Windows: C:¥Program Files¥Filenet¥Content Engine¥samples
  • Windows 以外: /opt/IBM/FileNet/ContentEngine/samples

Java の例

package sample.actionhandler;
import com.filenet.api.engine.DocumentLifecycleActionHandler;
import com.filenet.api.events.DocumentLifecyclePolicy;
import com.filenet.api.exception.EngineRuntimeException;
import com.filenet.api.core.Document;

public class LifecycleActionHandler implements DocumentLifecycleActionHandler
{
    public void onDocumentPromote( Document doc, DocumentLifecyclePolicy policy )
    {
        int index = doc.get_Name().indexOf("_");
        String docName = index != -1 ? doc.get_Name().substring(0, index) : doc.get_Name();
        doc.getProperties().putValue( "DocumentTitle", docName + "_" + doc.get_CurrentState() );
    }

    public void onDocumentDemote( Document doc, DocumentLifecyclePolicy policy ) throws EngineRuntimeException
    {
        int index = doc.get_Name().indexOf("_");
        String docName = index != -1 ? doc.get_Name().substring(0, index) : doc.get_Name();
        doc.getProperties().putValue( "DocumentTitle", docName + "_" + doc.get_CurrentState() );
    }
        
    public void onDocumentSetException( Document doc, DocumentLifecyclePolicy policy ) throws EngineRuntimeException
    {
        int index = doc.get_Name().indexOf("_");
        String docName = index != -1 ? doc.get_Name().substring(0, index) : doc.get_Name();
        doc.getProperties().putValue( "DocumentTitle", docName + "_" + doc.get_CurrentState() +"_InException" );
    }
        
    public void onDocumentClearException( Document doc, DocumentLifecyclePolicy policy ) throws EngineRuntimeException
    {
        int index = doc.get_Name().indexOf("_");
        String docName = index != -1 ? doc.get_Name().substring(0, index) : doc.get_Name();
        doc.getProperties().putValue( "DocumentTitle", docName + "_" + doc.get_CurrentState() );
    }

    public void onDocumentResetLifecycle( Document doc, DocumentLifecyclePolicy policy ) throws EngineRuntimeException
    {
        int index = doc.get_Name().indexOf("_");
        String docName = index != -1 ? doc.get_Name().substring(0, index) : doc.get_Name();
        doc.getProperties().putValue( "DocumentTitle", docName + "_" + doc.get_CurrentState() );
    }
}

JavaScript の例

importClass(Packages.com.filenet.api.engine.DocumentLifecycleActionHandler);
importClass(Packages.com.filenet.api.events.DocumentLifecyclePolicy);
importClass(Packages.com.filenet.api.exception.EngineRuntimeException);
importClass(Packages.com.filenet.api.core.Document);

function OnDocument_Promote(doc, policy )
{
   var index = doc.get_Name().indexOf("_");
   var docName = index != -1 ? doc.get_Name().substring(0, index) : doc.get_Name();
   doc.getProperties().putValue( "DocumentTitle", docName + "_" + doc.get_CurrentState() );
}

function OnDocument_Demote(doc, policy )
{
   var index = doc.get_Name().indexOf("_");
   var docName = index != -1 ? doc.get_Name().substring(0, index) : doc.get_Name();
   doc.getProperties().putValue( "DocumentTitle", docName + "_" + doc.get_CurrentState() );
}

function OnDocument_SetException(doc, policy ) 
{
   var index = doc.get_Name().indexOf("_");
   var docName = index != -1 ? doc.get_Name().substring(0, index) : doc.get_Name();
   doc.getProperties().putValue( "DocumentTitle", docName + "_" + doc.get_CurrentState() +"_InException" );
}

function OnDocument_ClearException(doc, policy )
{
   var index = doc.get_Name().indexOf("_");
   var docName = index != -1 ? doc.get_Name().substring(0, index) : doc.get_Name();
   doc.getProperties().putValue( "DocumentTitle", docName + "_" + doc.get_CurrentState() );
}

function OnDocument_ResetLifecycle(doc, policy )
{
   var index = doc.get_Name().indexOf("_");
   var docName = index != -1 ? doc.get_Name().substring(0, index) : doc.get_Name();
   doc.getProperties().putValue( "DocumentTitle", docName + "_" + doc.get_CurrentState() );
}

DocumentLifecycleAction オブジェクトの作成

DocumentLifecycleAction オブジェクトは、ドキュメントの状態が変化したときに開始するドキュメント・ライフ・サイクル・アクション・ハンドラーを示します。以下の Java および C# のコード例では、DocumentLifecycleAction オブジェクトを作成し、このオブジェクトをドキュメント・ライフ・サイクル・アクション・ハンドラーに関連付けるプロパティー (ProgId、および条件によっては CodeModule) を設定する方法を示します。Java で実装されたハンドラーの場合、ProgId プロパティーに、ハンドラー・クラスの完全修飾名を設定する必要があります。 例に示すように、イベント・アクション・ハンドラーがオブジェクト・ストアに格納された CodeModule に含まれている場合は、CodeModule オブジェクトも取得し、このオブジェクトを DocumentLifecycleAction オブジェクトの CodeModule プロパティーに割り当てる必要があります。CodeModule プロパティーを CodeModule の予約 (実行中) バージョンに設定することはできません。詳細については、「CodeModule オブジェクトの作成」を参照してください。

注: アプリケーション・サーバーのクラスパスをドキュメント・ライフ・サイクル・アクション・ハンドラーのロケーションに設定する場合は CodeModule プロパティーを設定しないでください。

保存された DocumentLifecycleAction オブジェクトは、Content Engine オブジェクト・ストアの Document Lifecycles/Document Lifecycle Actions フォルダーに格納されます。

Java の例

   ...
   // Create lifecycle action.
   DocumentLifecycleAction lifecycleAction = Factory.DocumentLifecycleAction.createInstance(os, 
              ClassNames.DOCUMENT_LIFECYCLE_ACTION);
   // ハンドラー・クラスの完全修飾名を指定して ProgId プロパティーを設定する
   lifecycleAction.set_ProgId("sample.actionhandler.LifecycleActionHandler");
   // CodeModule オブジェクトの取得
   CodeModule cm = Factory.CodeModule.getInstance( os, 
              ClassNames.CODE_MODULE, new Id("{5653773F-D5F2-4292-8684-55E60A654F6B}") ); 
   // CodeModule プロパティーの設定
   lifecycleAction.set_CodeModule(cm);
   lifecycleAction.set_DisplayName("LoanLifecycleAction");
   lifecycleAction.save(RefreshMode.REFRESH);
}

C# の例

   ...
   // Create event action.
   IDocumentLifecycleAction lifecycleAction = Factory.DocumentLifecycleAction.CreateInstance(os, 
              ClassNames.DOCUMENT_LIFECYCLE_ACTION);
   // ハンドラー・クラスの完全修飾名を指定して ProgId プロパティーを設定する
   lifecycleAction.ProgId = "sample.actionhandler.LifecycleActionHandler";
   // CodeModule オブジェクトの取得
   ICodeModule cm = Factory.CodeModule.GetInstance(os, 
              ClassNames.CODE_MODULE, new Id("{5653773F-D5F2-4292-8684-55E60A654F6B}") );
   // CodeModule プロパティーの設定
   lifecycleAction.CodeModule = cm;
   lifecycleAction.DisplayName = "LoanLifecycleAction";
   lifecycleAction.Save(RefreshMode.REFRESH);
}

DocumentLifecyclePolicy オブジェクトの作成

ドキュメント・ライフ・サイクル・アクション・ハンドラーと DocumentLifecycleAction オブジェクトを作成したら、次に DocumentLifecyclePolicy オブジェクトを作成し、オブジェクト・ストアに永続化できます。

単純なローン申請クライアント・プログラムで使用する DocumentLifecyclePolicy オブジェクトの作成方法を示す Java と C# の例を次に示します。基本的には、DocumentLifecyclePolicy オブジェクトを作成し、その主要プロパティー (DocumentLifecycleAction と DocumentStates) を設定します。DocumentLifecycleAction プロパティーには既存のオブジェクトを設定し、DocumentStates プロパティーには新規に作成された DocumentState オブジェクトを設定します。このオブジェクトは、ローン申請プロセスの 1 つの状態を表します。クライアント・プログラムでユーザーがローン申請ドキュメントの状態を変更できます。状態は「申請」状態から始まり、「完了」状態で終わります。

「完了」状態を表す最終 DocumentState オブジェクトに設定されたプロパティーに注意してください。CanBeDemoted プロパティーが FALSE に設定されたため、ユーザーが完了したローン申請を直前の「返済中」状態に戻す操作が防止されます。また TemplatePermissions プロパティーへの設定は、状態に基づいてドキュメントのセキュリティーを変更できます。このプロパティーには、次のコード例に示す setStatePermissions メソッドから返される AccessPermissionList オブジェクトが設定されます。この「setStatePermissions」メソッドは、ローン・マネージャーに対しローン申請の完全な管理権限を付与しますが、ローン処理グループへは書き込みアクセス権限を付与しません。したがって、ローン申請が完了した時点で、ローン申請に新しいアクセス権限が適用されます。これにより、ローン処理グループのすべてのユーザーはライフ・サイクルをリセットできません。グループのマネージャーのみが、ライフ・サイクルを初期状態の「申請」にリセットできる権限を持っています。

保存された DocumentLifecyclePolicy オブジェクトは、Content Engine オブジェクト・ストアの Document Lifecycles/Document Lifecycle Policies フォルダーに格納されます。

Java の例

   ...
   // Create DocumentLifecyclePolicy object and name the policy.
   DocumentLifecyclePolicy lifecyclePolicy = Factory.DocumentLifecyclePolicy.createInstance(os,
                  ClassNames.DOCUMENT_LIFECYCLE_POLICY);
   lifecyclePolicy.set_DisplayName("LoanLifecyclePolicy");

   // 前の例で作成された DocumentLifeCycleAction を取得し、
   // and set policy's DocumentLifecycleAction property.
   DocumentLifecycleAction lifecycleAction = Factory.DocumentLifecycleAction.fetchInstance(os, 
                  new Id("{4250EEB5-A11F-4BA0-A542-2AEB246204C3}"), null);
   lifecyclePolicy.set_DocumentLifecycleAction(lifecycleAction);

   // ローン・アプリケーションに対して DocumentState オブジェクトを作成する
   DocumentState ds1 = Factory.DocumentState.createInstance();
   ds1.set_StateName("Application");
   DocumentState ds2 = Factory.DocumentState.createInstance();
   ds2.set_StateName("Approval");
   DocumentState ds3 = Factory.DocumentState.createInstance();
   ds3.set_StateName("Funding");
   DocumentState ds4 = Factory.DocumentState.createInstance();
   ds4.set_StateName("Servicing");
   DocumentState ds5 = Factory.DocumentState.createInstance();
   ds5.set_StateName("Closed");
   ds5.set_CanBeDemoted(Boolean.FALSE);
   ds5.set_TemplatePermissions(setStatePermissions());
   ds5.set_ApplyTemplatePermissions(Boolean.TRUE);

   // DocumentStateList を作成し、ポリシーの DocumentStates プロパティーを設定する
   DocumentStateList dsl = Factory.DocumentState.createList();
   dsl.add(ds1);
   dsl.add(ds2);
   dsl.add(ds3);
   dsl.add(ds4);
   dsl.add(ds5);
   lifecyclePolicy.set_DocumentStates(dsl);

   // ライフ・サイクル・ポリシーで定義された権限を与え、ドキュメントの権限を上書きする
   lifecyclePolicy.set_PreserveDirectPermissions(Boolean.FALSE);
   
   // ライフ・サイクル・ポリシー・オブジェクトへの変更をコミット
   lifecyclePolicy.save(RefreshMode.REFRESH);
}

public AccessPermissionList setStatePermissions()
{
   final int ACCESS_MANAGER = AccessRight.WRITE_OWNER.getValue() |
   AccessRight.WRITE_ACL.getValue() |  AccessRight.READ_ACL.getValue() |
   AccessRight.DELETE.getValue() | AccessRight.PUBLISH.getValue() |
   AccessRight.CHANGE_STATE.getValue() | AccessRight.CREATE_INSTANCE.getValue() |
   AccessRight.VIEW_CONTENT.getValue() | AccessRight.MINOR_VERSION.getValue() |
   AccessRight.UNLINK.getValue() | AccessRight.LINK.getValue() |
   AccessRight.MAJOR_VERSION.getValue() |AccessRight.WRITE.getValue() |
   AccessRight.READ.getValue();

   final int ACCESS_GROUP = AccessRight.READ_ACL.getValue() |
   AccessRight.CHANGE_STATE.getValue() |  AccessRight.CREATE_INSTANCE.getValue() |
   AccessRight.UNLINK.getValue() | AccessRight.LINK.getValue() |
   AccessRight.WRITE.getValue();

   AccessPermissionList apl = Factory.AccessPermission.createList();
   
   AccessPermission permManager = Factory.AccessPermission.createInstance();
   permManager.set_AccessMask(new Integer(ACCESS_MANAGER));
   permManager.set_GranteeName("loan manager");
   AccessType at = AccessType.ALLOW;
   permManager.set_AccessType(at);
   apl.add(permManager);
   
   AccessPermission permGroup = Factory.AccessPermission.createInstance();
   permGroup.set_AccessMask(new Integer(ACCESS_GROUP));
   permGroup.set_GranteeName("loan processing group");
   at = AccessType.DENY;
   permGroup.set_AccessType(at);
   apl.add(permGroup);
   
   return apl;
}

C# の例

   ...
   // Create DocumentLifecyclePolicy object and name the policy.
   IDocumentLifecyclePolicy lifecyclePolicy = Factory.DocumentLifecyclePolicy.CreateInstance(os,
                  ClassNames.DOCUMENT_LIFECYCLE_POLICY);
   lifecyclePolicy.DisplayName = "LoanLifecyclePolicyC#";

   // 前の例で作成された DocumentLifeCycleAction を取得し、
   // and set policy's DocumentLifecycleAction property.
            IDocumentLifecycleAction lifecycleAction = Factory.DocumentLifecycleAction.FetchInstance(os,
   new Id("{4250EEB5-A11F-4BA0-A542-2AEB246204C3}"), null);
   lifecyclePolicy.DocumentLifecycleAction = lifecycleAction;

   // ローン・アプリケーションに対して DocumentState オブジェクトを作成する
   IDocumentState ds1 = Factory.DocumentState.CreateInstance();
   ds1.StateName = "Application";
   IDocumentState ds2 = Factory.DocumentState.CreateInstance();
   ds2.StateName = "Approval";
   IDocumentState ds3 = Factory.DocumentState.CreateInstance();
   ds3.StateName = "Funding";
   IDocumentState ds4 = Factory.DocumentState.CreateInstance();
   ds4.StateName = "Servicing";
   IDocumentState ds5 = Factory.DocumentState.CreateInstance();
   ds5.StateName = "Closed";
   ds5.CanBeDemoted = false;
   ds5.TemplatePermissions = setStatePermissions();
   ds5.ApplyTemplatePermissions = true;

   // DocumentStateList を作成し、ポリシーの DocumentStates プロパティーを設定する
   IDocumentStateList dsl = Factory.DocumentState.CreateList();
   dsl.Add(ds1);
   dsl.Add(ds2);
   dsl.Add(ds3);
   dsl.Add(ds4);
   dsl.Add(ds5);
   lifecyclePolicy.DocumentStates = dsl;

   // ライフ・サイクル・ポリシーで定義された権限を与え、ドキュメントの権限を上書きする
   lifecyclePolicy.PreserveDirectPermissions = false;

   // ライフ・サイクル・ポリシー・オブジェクトへの変更をコミット
   lifecyclePolicy.Save(RefreshMode.REFRESH);
}

public IAccessPermissionList setStatePermissions()
{
   const int ACCESS_MANAGER = (int)AccessRight.WRITE_OWNER |
   (int)AccessRight.WRITE_ACL |  (int)AccessRight.READ_ACL |
   (int)AccessRight.DELETE | (int)AccessRight.PUBLISH |
   (int)AccessRight.CHANGE_STATE | (int)AccessRight.CREATE_INSTANCE |
   (int)AccessRight.VIEW_CONTENT | (int)AccessRight.MINOR_VERSION |
   (int)AccessRight.UNLINK | (int)AccessRight.LINK |
   (int)AccessRight.MAJOR_VERSION | (int)AccessRight.WRITE |
   (int)AccessRight.READ;

   const int ACCESS_GROUP = (int)AccessRight.READ_ACL |
   (int)AccessRight.CHANGE_STATE |  (int)AccessRight.CREATE_INSTANCE |
   (int)AccessRight.UNLINK | (int)AccessRight.LINK |
   (int)AccessRight.WRITE;
   
   IAccessPermissionList apl = Factory.AccessPermission.CreateList();

   IAccessPermission permManager = Factory.AccessPermission.CreateInstance();
   permManager.AccessMask = (int)ACCESS_MANAGER;
   permManager.GranteeName = "loan manager";
   permManager.AccessType = AccessType.ALLOW;
   apl.Add(permManager);

   IAccessPermission permGroup = Factory.AccessPermission.CreateInstance();
   permGroup.AccessMask = (int)ACCESS_GROUP;
   permGroup.GranteeName = "loan processing group";
   permGroup.AccessType = AccessType.DENY;
   apl.Add(permGroup);

   return apl;
}

DocumentLifecyclePolicy オブジェクトの割り当て

以降のサブセクションに示すように、ドキュメント・ライフ・サイクル・ポリシーを個々の Document オブジェクトに割り当てるか、または Document クラスあるいはそのサブクラスに割り当てることができます。Document オブジェクトにドキュメント・ライフ・サイクル・ポリシーを割り当てることができるのは、Document オブジェクトの作成時のみでであることに注意してください。ドキュメント・ライフ・サイクル・ポリシーを使用して既存の Document オブジェクトを更新することはできません。

クラスに付加されたドキュメント・ライフ・サイクル・ポリシーは、そのクラス・タイプのすべての新規 Document オブジェクトに自動的に適用されます。ただし、そのクラス・タイプのドキュメントの作成時に別のドキュメント・ライフ・サイクル・ポリシーを明示的に設定する場合を除きます。

Document オブジェクトへの割り当て

新規に作成されたドキュメントに既存の DocumentLifecyclePolicy オブジェクトを割り当てる方法を次の Java と C# のサンプル・コードに示します。

Java の例

   ...
   Document doc=Factory.Document.createInstance(os, null);
   doc.getProperties().putValue("DocumentTitle", "CarLoanApplication");
   DocumentLifecyclePolicy dlcp = Factory.DocumentLifecyclePolicy.getInstance(os, ClassNames.DOCUMENT_LIFECYCLE_POLICY,
            new Id("{47A1D313-ADC8-4A53-90CC-66B83ABAF229}") );
   doc.set_DocumentLifecyclePolicy(dlcp);
   doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
   doc.save(RefreshMode.REFRESH);
}

C# の例

   ...
IDocument doc=Factory.Document.CreateInstance(os, null);
   doc.Properties["DocumentTitle"] = "CarLoanApplication";
   IDocumentLifecyclePolicy dlcp = Factory.DocumentLifecyclePolicy.GetInstance(os, ClassNames.DOCUMENT_LIFECYCLE_POLICY,
            new Id("{47A1D313-ADC8-4A53-90CC-66B83ABAF229}"));
   doc.DocumentLifecyclePolicy = dlcp;
   doc.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
   doc.Save(RefreshMode.REFRESH);
}

Document クラスへの割り当て

既存の DocumentLifecyclePolicy オブジェクトを Document クラスに割り当てる方法を、次の Java と C# の例に示します。この例では実質的に DocumentClassDefinition オブジェクト (Document クラスのクラス定義を表すオブジェクト) と PropertyDefinition オブジェクト (Document クラスのライフ・サイクル・ポリシー・システム・プロパティーを表すオブジェクト) を操作します。Document クラスの PropertyDefinition オブジェクトのリストを取得し、ドキュメント・ライフ・サイクル・ポリシー・プロパティーの PropertyDefinition オブジェクトが検出されるまでリストを反復処理します。デフォルトでは、このプロパティーには値は設定されていません。与えられた DocumentLifecyclePolicy オブジェクト値に対し、PropertyDefinition オブジェクトを PropertyDefinitionObject オブジェクトにキャストした上で、DocumentLifecyclePolicy オブジェクトを割り当てます。

Java の例

   ...
   // GUIDは "Document Class" ClassDefinition オブジェクトのもの
   DocumentClassDefinition classDef = Factory.DocumentClassDefinition.fetchInstance(os, 
          new Id("{01A3A8C2-7AEC-11D1-A31B-0020AF9FBB1C}"), null);
   PropertyDefinitionList propDefList = classDef.get_PropertyDefinitions();
   PropertyDefinition propertyDef = null;
   Iterator iter = propDefList.iterator();
   while (iter.hasNext()) 
   {
      propertyDef = (PropertyDefinition)iter.next();
      if ( propertyDef.get_SymbolicName().equals("DocumentLifecyclePolicy") ) 
         break;
   }
   DocumentLifecyclePolicy dlp = Factory.DocumentLifecyclePolicy.getInstance(os, 
          ClassNames.DOCUMENT_LIFECYCLE_POLICY, new Id("{A94B2678-D9C6-4DA2-9D1A-D12482B8A125}") );
   PropertyDefinitionObject propertyDefObject = (PropertyDefinitionObject)propertyDef;
   propertyDefObject.set_PropertyDefaultObject(dlp);
   classDef.save(RefreshMode.REFRESH);
}

C# の例

   ...
   // GUIDは "Document Class" ClassDefinition オブジェクトのもの
   IDocumentClassDefinition classDef = Factory.DocumentClassDefinition.FetchInstance(os, 
          new Id("{01A3A8C2-7AEC-11D1-A31B-0020AF9FBB1C}"), null);
   IPropertyDefinitionList propDefList = classDef.PropertyDefinitions;
   IPropertyDefinition propertyDef = null;
   System.Collections.IEnumerator propDefListIter = propDefList.GetEnumerator();
   while (propDefListIter.MoveNext())
   {
      propertyDef = (IPropertyDefinition)propDefListIter.Current;
      if ( propertyDef.SymbolicName.Equals("DocumentLifecyclePolicy") ) 
         break;
   }
   IDocumentLifecyclePolicy dlp = Factory.DocumentLifecyclePolicy.GetInstance(os,
          ClassNames.DOCUMENT_LIFECYCLE_POLICY, new Id("{A94B2678-D9C6-4DA2-9D1A-D12482B8A125}"));
   IPropertyDefinitionObject propertyDefObject = (IPropertyDefinitionObject)propertyDef;
   propertyDefObject.PropertyDefaultObject = dlp;
   classDef.Save(RefreshMode.REFRESH);
}

ドキュメントの状態の変更

次の Java と C# の例に示すように、DocumentLifecyclePolicy オブジェクトが付加された Document オブジェクトの現行状態を取得し、Document オブジェクトの状態を変更できます。

現行状態を取得すると、DocumentState オブジェクトによって表されるユーザー定義の状態の 1 つを示す文字列が返されます。

changeState メソッドは LifecycleChangeFlags 定数をとります。変更をコミットするには、Document オブジェクトを保存する必要がある点に注意してください (例には示されていません)。

Java の例

// 現行状態の取得
String state = document.get_CurrentState();

// 現行状態の変更
document.changeState(LifecycleChangeFlags.PROMOTE);

C# の例

// 現行状態の取得
String state = document.CurrentState;

// 現行状態の変更
document.ChangeState(LifecycleChangeFlags.PROMOTE);

DocumentLifecyclePolicy オブジェクトの取得

1 つの DocumentLifecyclePolicy オブジェクトを取得するには、Factory.DocumentLifecylePolicy メソッドを使用するか、または Document オブジェクトの DocumentLifecyclePolicy プロパティーを取得します。DocumentLifecyclePolicy オブジェクトのコレクション (DocumentLifecyclePolicySet) を取得するには、DocumentLifecycleAction オブジェクトまたは ObjectStore オブジェクトの DocumentLifecyclePolicies プロパティーを取得します。

DocumentLifecycleAction オブジェクトにはドキュメント・ライフ・サイクル・アクション・ハンドラーが関連付けられています。1 つのハンドラーで複数のドキュメント・ライフ・サイクル・ポリシーを処理するようコーディングする場合、このオブジェクトは複数の DocumentLifecyclePolicy オブジェクトに含まれています。「ライフ・サイクル・アクション・ハンドラーの作成」に示したように、DocumentLifecycleActionHandler インターフェースの各メソッドには DocumentLifecyclePolicy オブジェクトが渡されます。したがって、ハンドラーに渡される DocumentLifecyclePolicy オブジェクトに基づいて、ハンドラーの条件付きアクションをコーディングできます。

以下の Java および C# の例では、DocumentLifecycleAction オブジェクトから、DocumentLifecyclePolicySet コレクションを取得する方法を示します。コレクションの各 DocumentLifecyclePolicy オブジェクトの DocumentStates プロパティーが取得されます。このプロパティーには DocumentStateList 値が設定されています。この例では、リストを反復処理し、DocumentState オブジェクトの名前を出力します。

Java の例

   ...
   DocumentLifecycleAction lifecycleAction = Factory.DocumentLifecycleAction.fetchInstance(os, 
                new Id("{4250EEB5-A11F-4BA0-A542-2AEB246204C3}"), null);
   DocumentLifecyclePolicySet dlpSet = lifecycleAction.get_DocumentLifecyclePolicies();
   DocumentLifecyclePolicy dlpObject;
   DocumentState ds;
   Iterator iterOuter = dlpSet.iterator();
   while (iterOuter.hasNext()) 
   {
      dlpObject = (DocumentLifecyclePolicy)iterOuter.next();
      System.out.println("DocumentLifecyclePolicy: " + dlpObject.get_DisplayName() );
      DocumentStateList dsList = dlpObject.get_DocumentStates();
      Iterator iterInner = dsList.iterator();
      while (iterInner.hasNext())
      {
         ds = (DocumentState)iterInner.next(); 
         System.out.println("   DocumentState: " + ds.get_StateName() );
      }
   }
}

C# の例

   ...
   IDocumentLifecycleAction lifecycleAction = Factory.DocumentLifecycleAction.FetchInstance(os,
                new Id("{4250EEB5-A11F-4BA0-A542-2AEB246204C3}"), null);
   IDocumentLifecyclePolicySet dlpSet = lifecycleAction.DocumentLifecyclePolicies;
   IDocumentLifecyclePolicy dlpObject;
   IDocumentState ds;
   System.Collections.IEnumerator iterOuter = dlpSet.GetEnumerator();
   while (iterOuter.MoveNext())
   {
      dlpObject = (IDocumentLifecyclePolicy)iterOuter.Current;
      System.Console.WriteLine("DocumentLifecyclePolicy: " + dlpObject.DisplayName);
      IDocumentStateList dsList = dlpObject.DocumentStates;
      System.Collections.IEnumerator iterInner = dsList.GetEnumerator();
      while (iterInner.MoveNext())
      {
         ds = (IDocumentState)iterInner.Current;
         System.Console.WriteLine("   DocumentState: " + ds.StateName);
      }
   }
}
      


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

© Copyright IBM Corp. 2015.