IBM FileNet P8, バージョン 5.2.1            

複合ドキュメントの操作

複合ドキュメントの統合

複合ドキュメントを単純なテキストとして出力するために統合します。これらのルーチンは、ほかの複合ドキュメントの例でも使用されています。より複雑な複合ドキュメントの場合、下記例よりさらに拡張された統合ロジックが必要になります。一般に、ドキュメントの統合は、子コンポーネント・ドキュメントを取得する処理と、それを適切な順序でマージする処理から成ります。子コンポーネント自体が複合ドキュメントである場合もあるため、統合は次のような再帰的な処理になります。親と見なされる子ごとに、子コンポーネント・ドキュメントを取得し、適切な順序でマージします。

Java™ の例

// 複合ドキュメントのコンポーネントを再帰的に出力
private void outputCompoundDocument(
    Document docParent,
    FileOutputStream outStream) throws Exception
{
    // Output text for parent document.
    outputContent(docParent, outStream);
            
    // Iterate through child components.
    DocumentSet components = docParent.get_ChildDocuments();
    Iterator iterChild = components.iterator();            
    while (iterChild.hasNext() == true)
    {
        // Output text for child document (recursive call).
        Document docChild = (Document) iterChild.next();
        outputCompoundDocument(docChild, outStream);
    }            
}
        
// ドキュメントのコンテンツ・エレメントを出力
private void outputContent(
    Document doc,
    FileOutputStream outStream) throws Exception
{
    // Get content elements for document.
    ContentElementList cel = doc.get_ContentElements();
    
    // Iterate through content elements.
    Iterator iterElement = cel.iterator();
    while (iterElement.hasNext() == true)
    {
        ContentElement ce = (ContentElement) iterElement.next();
                
        if (ce instanceof ContentTransfer)
        {
            // Get input stream to content.
            ContentTransfer ct = (ContentTransfer) ce;
            InputStream inStream = ct.accessContentStream();
                     
            // Output content to book.
            byte[] outputBytes = new byte[100];
            int byteCount = 0;
            while ((byteCount = inStream.read(outputBytes)) != -1)
            {
                outStream.write(outputBytes, 0, byteCount);                            
            }
        }        
    }        
}

C# の例

// 複合ドキュメントのコンポーネントを再帰的に出力
private void outputCompoundDocument(
    IDocument docParent,
    FileStream outStream)
{
    // Output text for parent document.
    outputContent(docParent, outStream);
            
    // Iterate through child components.
    IDocumentSet components = docParent.ChildDocuments;
    foreach (IDocument docChild in components)
    {
        // Output text for child document (recursive call).
        outputCompoundDocument(docChild, outStream);
    }        
}

// ドキュメントのコンテンツ・エレメントを出力
private void outputContent(
    IDocument doc,
    FileStream outStream)
{
    // Get content elements for document.
    IContentElementList cel = doc.ContentElements;
    
    // Iterate through content elements.
    foreach (IContentElement ce in cel)
    {
        if (ce is IContentTransfer)
        {
            // Get input stream to content.
            IContentTransfer ct = (IContentTransfer) ce;
            Stream inStream = ct.AccessContentStream();
                     
            // Output content to book.
            const Int32 BYTE_MAX = 100;
            byte[] outputBytes = new byte[BYTE_MAX];
            int byteCount = 0;
            while ((byteCount = inStream.Read(outputBytes, 0, BYTE_MAX)) != 0)
            {
                outStream.Write(outputBytes, 0, byteCount);            
            }
        }        
    }        

}

        

静的なコンポーネント関係の作成

このコード例は、静的なコンポーネント関係 (ComponentRelationshipType = STATIC_CR) を使用して複合ドキュメントを作成します。この関係では、ParentComponent プロパティーで示されるドキュメントは、ChildComponent プロパティーで明示的に設定されたドキュメントのバージョンにバインドされます。

Java の例

private void ExampleCreatingStaticCR(ObjectStore os) throws Exception
{
    /////////////////////////////////////////////////////////////////
    // Construct compound document.

    Document docBook = constructStaticBook(os);

    /////////////////////////////////////////////////////////
    // Assemble compound document.

    // 書籍用の出力ストリームを開始
    String bookFile = "C:¥¥CDExample¥¥Output¥¥BookStaticCR.txt"; 
    // non-Windows: String bookFile = "/tmp/CDExample/Output/BookStaticCR.txt"; 
    FileOutputStream outStream = new FileOutputStream(bookFile);            

    // 出力を実行
    outputCompoundDocument(docBook, outStream);            
    outStream.close();
            
}

private Document constructStaticBook(ObjectStore os) throws Exception
{
    // 書籍全体を表す親ドキュメントを作成
    Document docBook = Factory.Document.createInstance(os, null); 
    docBook.set_CompoundDocumentState(
        CompoundDocumentState.COMPOUND_DOCUMENT);
    docBook.checkin(null, CheckinType.MAJOR_VERSION);
    docBook.save(RefreshMode.REFRESH);            
            
    // 章コンポーネントを作成
    for (int chapterNumber = 1; chapterNumber < 4; chapterNumber++)
    {
        // Get chapter text.
        String chapterFile 
            = "C:¥¥CDExample¥¥BookText¥¥Chapter" + chapterNumber + ".txt";
        // non-Windows: String chapterFile = "/tmp/CDExample/BookText/Chapter" + chapterNumber + ".txt";
        FileInputStream stream = new FileInputStream(chapterFile);
        ContentTransfer ct 
            = Factory.ContentTransfer.createInstance();
        ct.setCaptureSource(stream);
                
        // コンテンツ・リストを作成
        ContentElementList list 
            = Factory.ContentElement.createList();
        list.add(ct);
                
        // Create child document representing a chapter.
        Document docChapter 
            = Factory.Document.createInstance(os, null); 
        docChapter.set_ContentElements(list);
        docChapter.checkin(null, CheckinType.MAJOR_VERSION);
        docChapter.save(RefreshMode.REFRESH);            

        // この章のコンポーネント関係を作成
        ComponentRelationship cr 
            = Factory.ComponentRelationship.createInstance(os, null);
        cr.set_ParentComponent(docBook);
        cr.set_ChildComponent(docChapter);
        cr.set_ComponentSortOrder(new Integer(chapterNumber));
        cr.set_ComponentRelationshipType(
            ComponentRelationshipType.STATIC_CR);            
        cr.save(RefreshMode.REFRESH);
    }
    return docBook;

}

C# の例

private void ExampleCreatingStaticCR(IObjectStore os)
{
    /////////////////////////////////////////////////////////////////
    // Construct compound document.

    IDocument docBook = constructStaticBook(os);

    /////////////////////////////////////////////////////////
    // Assemble compound document.

    // 書籍用の出力ストリームを開始
    String bookFile = "C:¥¥CDExample¥¥Output¥¥BookStaticCR.txt"; 
    FileStream outStream = new FileStream(bookFile, FileMode.Create);

    // 出力を実行
    outputCompoundDocument(docBook, outStream);
    outStream.Close();
            
}

private IDocument constructStaticBook(IObjectStore os)
{
    // 書籍全体を表す親ドキュメントを作成
    IDocument docBook = Factory.Document.CreateInstance(os, null); 
    docBook.CompoundDocumentState = CompoundDocumentState.COMPOUND_DOCUMENT;
    docBook.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
    docBook.Save(RefreshMode.REFRESH);

    // 各章となるコンポーネントを作成
    for (int chapterNumber = 1; chapterNumber < 4; chapterNumber++)
    {
        // Get chapter text.
        String chapterFile 
            = "C:¥¥CDExample¥¥BookText¥¥Chapter" + chapterNumber + ".txt"
        FileStream stream = new FileStream(chapterFile, FileMode.Open);
        IContentTransfer ct = Factory.ContentTransfer.CreateInstance();
        ct.SetCaptureSource(stream);
                
        // コンテンツ・リストを作成
        IContentElementList list = Factory.ContentElement.CreateList();
        list.Add(ct);
                
        // Create child document representing a chapter.
        IDocument docChapter = Factory.Document.CreateInstance(os, null);
        docChapter.ContentElements = list;
        docChapter.Checkin(
            AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
        docChapter.Save(RefreshMode.REFRESH);

        // この章のコンポーネント関係を作成
        IComponentRelationship cr 
            = Factory.ComponentRelationship.CreateInstance(os, null);
        cr.ParentComponent = docBook;
        cr.ChildComponent = docChapter;
        cr.ComponentSortOrder = chapterNumber;
        cr.ComponentRelationshipType = ComponentRelationshipType.STATIC_CR;
        cr.Save(RefreshMode.REFRESH);
    }   
    return docBook;

}

動的なコンポーネント関係の生成

このコード例は、動的なコンポーネント関係 (ComponentRelationshipType = DYNAMIC_CR) を使用して複合ドキュメントを作成します。この関係では、ParentComponent プロパティーで示されるドキュメントは、ChildComponent プロパティーで設定されたドキュメントのいずれかのバージョンにバインドされます。バインド先のバージョンは、VersionBindType プロパティーの設定値によって決まります。最新バージョンか、または最新メジャー・バージョンのいずれかにバインドされます。

Java の例

private void ExampleCreatingDynamicCR(ObjectStore os) throws Exception
{
    /////////////////////////////////////////////
    // Construct compound document.
    
    // 書籍全体を表す親ドキュメントを作成
    Document docBook = Factory.Document.createInstance(os, null); 
    docBook.set_CompoundDocumentState(
        CompoundDocumentState.COMPOUND_DOCUMENT);
    docBook.checkin(null, CheckinType.MAJOR_VERSION);
    docBook.save(RefreshMode.REFRESH);            
            
    // 章コンポーネントを作成
    for (int chapterNumber = 1; chapterNumber < 4; chapterNumber++)
    {
        // Get chapter text for minor version.
        String chapterFile 
            = "C:¥¥CDExample¥¥BookText¥¥Chapter" + chapterNumber + ".txt";
        // non-Windows: String chapterFile = "/tmp/CDExample/BookText/Chapter" + chapterNumber + ".txt";
        FileInputStream stream = new FileInputStream(chapterFile);
        ContentTransfer ct = Factory.ContentTransfer.createInstance();
        ct.setCaptureSource(stream);
                
        // コンテンツ・リストを作成
        ContentElementList list 
            = Factory.ContentElement.createList();
        list.add(ct);
                
        // Create child document representing a chapter.
        // マイナー・バージョンとしてチェックイン
        Document docChapter 
            = Factory.Document.createInstance(os, null); 
        docChapter.set_ContentElements(list);
        docChapter.checkin(null, CheckinType.MINOR_VERSION);
        docChapter.save(RefreshMode.REFRESH);            

        // メジャー・バージョン用の章のテキストを取得
        String majorChapterFile 
            = "C:¥¥CDExample¥¥BookText¥¥MajorChapter" + chapterNumber + ".txt";
        // non-Windows: String majorChapterFile = "/tmp/CDExample/BookText/MajorChapter" + chapterNumber + ".txt";                      
        FileInputStream majorStream 
            = new FileInputStream(majorChapterFile);
        ContentTransfer majorCt 
            = Factory.ContentTransfer.createInstance();
        majorCt.setCaptureSource(majorStream);
                
        // コンテンツ・リストを作成
        ContentElementList majorList 
            = Factory.ContentElement.createList();
        majorList.add(majorCt);

        // メジャー・バージョンとしてチェックイン
        docChapter.checkout(null, null, null, null);
        docChapter.save(RefreshMode.REFRESH);
        Document docMajorChapter 
            = (Document) docChapter.get_Reservation();
        docMajorChapter.set_ContentElements(majorList);
        docMajorChapter.checkin(null, CheckinType.MAJOR_VERSION);
        docMajorChapter.save(RefreshMode.REFRESH);            
                                
        // この章のコンポーネント関係を作成
        ComponentRelationship cr 
            = Factory.ComponentRelationship.createInstance(os, null);
        cr.set_ParentComponent(docBook);
        cr.set_ChildComponent(docChapter);
        cr.set_ComponentSortOrder(new Integer(chapterNumber));
        cr.set_ComponentRelationshipType(
            ComponentRelationshipType.DYNAMIC_CR);            
        cr.set_VersionBindType(
            VersionBindType.LATEST_MAJOR_VERSION);
        cr.save(RefreshMode.REFRESH);
    }

    /////////////////////////////////////////////
    // Assemble compound document.

    // 書籍用の出力ストリームを開始
    String bookFile = "C:¥¥CDExample¥¥Output¥¥BookDynamicCR.txt";
    // non-Windows: String bookFile = "/tmp/CDExample/Output/BookDynamicCR.txt"; 
    FileOutputStream outStream = new FileOutputStream(bookFile);            

    // 複合ドキュメントを出力
    outputCompoundDocument(docBook, outStream);            
    outStream.close();
            
}

C# の例

private void ExampleCreatingDynamicCR(IObjectStore os)
{
    /////////////////////////////////////////////
    // Construct compound document.
    
    // 書籍全体を表す親ドキュメントを作成
    IDocument docBook = Factory.Document.CreateInstance(os, null); 
    docBook.CompoundDocumentState = CompoundDocumentState.COMPOUND_DOCUMENT;
    docBook.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
    docBook.Save(RefreshMode.REFRESH);            
            
    // 章コンポーネントを作成
    for (int chapterNumber = 1; chapterNumber < 4; chapterNumber++)
    {
        // Get chapter text for minor version.
        String chapterFile 
            = "C:¥¥CDExample¥¥BookText¥¥Chapter" + chapterNumber + ".txt";
        FileStream stream = new FileStream(chapterFile, FileMode.Open);
        IContentTransfer ct = Factory.ContentTransfer.CreateInstance();
        ct.SetCaptureSource(stream);
                
        // コンテンツ・リストを作成
        IContentElementList list = Factory.ContentElement.CreateList();
        list.Add(ct);
                
        // Create child document representing a chapter.
        // マイナー・バージョンとしてチェックイン
        IDocument docChapter = Factory.Document.CreateInstance(os, null); 
        docChapter.ContentElements = list;
        docChapter.Checkin(
            AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MINOR_VERSION);
        docChapter.Save(RefreshMode.REFRESH);            

        // メジャー・バージョン用の章のテキストを取得
        String majorChapterFile 
            = "C:¥¥CDExample¥¥BookText¥¥MajorChapter" + chapterNumber + ".txt";
        FileStream majorStream = new FileStream(majorChapterFile, FileMode.Open);
        IContentTransfer majorCt = Factory.ContentTransfer.CreateInstance();
        majorCt.SetCaptureSource(majorStream);
                
        // コンテンツ・リストを作成
        IContentElementList majorList = Factory.ContentElement.CreateList();
        majorList.Add(majorCt);

        // メジャー・バージョンとしてチェックイン
        docChapter.Checkout(ReservationType.OBJECT_STORE_DEFAULT, null, null, null);
        docChapter.Save(RefreshMode.REFRESH);
        IDocument docMajorChapter = (IDocument) docChapter.Reservation;
        docMajorChapter.ContentElements = majorList;
        docMajorChapter.Checkin(
            AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
        docMajorChapter.Save(RefreshMode.REFRESH);            
                                
        // この章のコンポーネント関係を作成
        IComponentRelationship cr 
            = Factory.ComponentRelationship.CreateInstance(os, null);
        cr.ParentComponent = docBook;
        cr.ChildComponent = docChapter;
        cr.ComponentSortOrder = chapterNumber;
        cr.ComponentRelationshipType = ComponentRelationshipType.DYNAMIC_CR;            
        cr.VersionBindType = VersionBindType.LATEST_MAJOR_VERSION;
        cr.Save(RefreshMode.REFRESH);
    }

    /////////////////////////////////////////////
    // Assemble compound document.

    // 書籍用の出力ストリームを開始
    String bookFile = "C:¥¥CDExample¥¥Output¥¥BookDynamicCR.txt";
    FileStream outStream = new FileStream(bookFile, FileMode.Create);

    // 複合ドキュメントを出力
    outputCompoundDocument(docBook, outStream);            
    outStream.Close();
           
}

動的なラベル・コンポーネント関係の作成

このコード例は、動的なラベル・コンポーネント関係 (ComponentRelationshipType = DYNAMIC_LABEL_CR) を使用して複合ドキュメントを作成します。この関係では、ParentComponent プロパティーで示されるドキュメントは、ChildComponent プロパティーで設定されたドキュメントのいずれかのバージョンにバインドされます。バインド先のバージョンは、VersionBindType プロパティーの設定値と LabelBindValue プロパティー値によって決まります。VersionBindType により、ドキュメントのバインド可能なバージョンが決まります。全バージョン、または全メジャー・バージョンのいずれかがバインドの候補になります。一致するラベルがある最新の使用可能なバージョンが、バインドされます。Document オブジェクトの ComponentBindingLabel プロパティーは、ラベルを指定します。このラベルと LabelBindValue の値が一致するか、このラベルに非 NULL 値が設定され、かつ LabelBindValue に NULL 値が設定されている場合に、一致したと見なされます。

Java の例

private void ExampleCreatingDynamicLabelCR(ObjectStore os) throws Exception
{
    /////////////////////////////////////////////
    // Construct compound document.
            
    // 保険証書全体を表す親ドキュメントを作成
    Document docPolicy = Factory.Document.createInstance(os, null); 
               
    docPolicy.set_CompoundDocumentState(
        CompoundDocumentState.COMPOUND_DOCUMENT);
    docPolicy.checkin(null, CheckinType.MAJOR_VERSION);
    docPolicy.save(RefreshMode.REFRESH);             

    // 各項となるコンポーネントを作成
    Document docParagraph2 = null;
    for (int paraNumber = 1; paraNumber < 4; paraNumber++)
    {
        // Get chapter text.
        String paraFile 
            = "C:¥¥CDExample¥¥InsurancePolicy¥¥Paragraph" + paraNumber + ".txt";
        // non-Windows: String paraFile = "/tmp/CDExample/InsurancePolicy/Paragraph" + paraNumber + ".txt";
        FileInputStream stream = new FileInputStream(paraFile);
        ContentTransfer ct = Factory.ContentTransfer.createInstance();
        ct.setCaptureSource(stream);
                
        // コンテンツ・リストを作成
        ContentElementList list = Factory.ContentElement.createList();
        list.add(ct);
                
        // Create child document representing a paragraph.
        Document docParagraph 
            = Factory.Document.createInstance(os, null); 
        docParagraph.set_ContentElements(list);
        docParagraph.checkin(null, CheckinType.MAJOR_VERSION);
        docParagraph.save(RefreshMode.REFRESH);            

        // Save reference to paragraph 2.
        if (paraNumber == 2)
        {
            docParagraph2 = docParagraph;
        }
                
        // Create component relationship for this paragraph.
        ComponentRelationship cr 
            = Factory.ComponentRelationship.createInstance(os, null);
        cr.set_ParentComponent(docPolicy);
        cr.set_ChildComponent(docParagraph);
        cr.set_ComponentSortOrder(new Integer(paraNumber));
        cr.set_ComponentRelationshipType(
            ComponentRelationshipType.STATIC_CR);            
        cr.save(RefreshMode.REFRESH);
    }

    // 各州の略語をロード
    String states[] =
        { "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", 
          "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA",
          "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", 
          "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", 
          "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", 
          "VA", "WA", "WV", "WI", "WY"
        };            

    final String COMPONENT_BINDING_LABEL = "ComponentBindingLabel";

    // Set paragraph 2 as compound document.                    
    docParagraph2.set_CompoundDocumentState(
        CompoundDocumentState.COMPOUND_DOCUMENT);
    docParagraph2.save(RefreshMode.REFRESH);                 
            
    // Create state subcomponents for paragraph 2.
    for (int index = 0; index < states.length; index++)
    {
        // Get chapter text.
        String stateFile 
            = "C:¥¥CDExample¥¥InsurancePolicy¥¥" + states[index] + ".txt";
        // non-Windows: String stateFile = "/tmp/CDExample/InsurancePolicy/" + states[index] + ".txt";
        FileInputStream stream = new FileInputStream(stateFile);
        ContentTransfer ct = Factory.ContentTransfer.createInstance();
        ct.setCaptureSource(stream);
                
        // コンテンツ・リストを作成
        ContentElementList list = Factory.ContentElement.createList();
        list.add(ct);
                
        // Create state document.
        Document docState = Factory.Document.createInstance(os, null); 
        docState.set_ContentElements(list);
        docState
            .getProperties()
            .putValue(COMPONENT_BINDING_LABEL, states[index]);                
        docState.checkin(null, CheckinType.MAJOR_VERSION);
        docState.save(RefreshMode.REFRESH);            

        // この州のコンポーネント関係を作成
        ComponentRelationship cr 
            = Factory.ComponentRelationship.createInstance(os, null);
        cr.set_ParentComponent(docParagraph2);
        cr.set_ChildComponent(docState);
        cr.set_ComponentRelationshipType(
            ComponentRelationshipType.DYNAMIC_LABEL_CR);            
        cr.set_VersionBindType(
            VersionBindType.LATEST_MAJOR_VERSION);
        cr.set_LabelBindValue(states[index]);
        cr.save(RefreshMode.REFRESH);
    }
            
    /////////////////////////////////////////////
    // Assemble compound document.

    // 書籍用の出力ストリームを開始
    String bookFile 
        = "C:¥¥CDExample¥¥Output¥¥PolicyDynamicLabelCR.txt"; 
    // non-Windows: String bookFile = "/tmp/CDExample/Output/PolicyDynamicLabelCR.txt"; 
    FileOutputStream outStream = new FileOutputStream(bookFile);            
            
    // 特定の州の証書を作成
    // Iterate through child relationships for paragraph 2. 
    String policyState = "AK";
    ComponentRelationshipSet crSet 
        = docParagraph2.get_ChildRelationships();
    Iterator iterCR = crSet.iterator();
    while (iterCR.hasNext() == true)
    {
        ComponentRelationship cr 
            = (ComponentRelationship) iterCR.next();
        cr.set_LabelBindValue(policyState);
        cr.save(RefreshMode.NO_REFRESH);
    }
            
    // Refresh paragraph 2. 
    // Causes ChildDocuments property to reflect correct policy state.
    docParagraph2.refresh();
            
    // Output document.
    outputCompoundDocument(docPolicy, outStream);
            
}

C# の例

private void ExampleCreatingDynamicLabelCR(IObjectStore os)
{
    /////////////////////////////////////////////
    // Construct compound document.
            
    // 保険証書全体を表す親ドキュメントを作成
    IDocument docPolicy = Factory.Document.CreateInstance(os, null); 
               
    docPolicy.CompoundDocumentState = CompoundDocumentState.COMPOUND_DOCUMENT;
    docPolicy.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
    docPolicy.Save(RefreshMode.REFRESH);             

    // 各項となるコンポーネントを作成
    IDocument docParagraph2 = null;
    for (int paraNumber = 1; paraNumber < 4; paraNumber++)
    {
        // Get chapter text.
        String paraFile 
            = "C:¥¥CDExample¥¥InsurancePolicy¥¥Paragraph" + paraNumber + ".txt";
        FileStream stream = new FileStream(paraFile, FileMode.Open);
        IContentTransfer ct = Factory.ContentTransfer.CreateInstance();
        ct.SetCaptureSource(stream);
                
        // コンテンツ・リストを作成
        IContentElementList list = Factory.ContentElement.CreateList();
        list.Add(ct);
                
        // Create child document representing a paragraph.
        IDocument docParagraph = Factory.Document.CreateInstance(os, null); 
        docParagraph.ContentElements = list;
        docParagraph.Checkin(
            AutoClassify.DO_NOT_AUTO_CLASSIFY,
            CheckinType.MAJOR_VERSION);
        docParagraph.Save(RefreshMode.REFRESH);            

        // Save reference to paragraph 2.
        if (paraNumber == 2)
        {
            docParagraph2 = docParagraph;
        }
                
        // Create component relationship for this paragraph.
        IComponentRelationship cr 
            = Factory.ComponentRelationship.CreateInstance(os, null);
        cr.ParentComponent = docPolicy;
        cr.ChildComponent = docParagraph;
        cr.ComponentSortOrder = paraNumber;
        cr.ComponentRelationshipType = ComponentRelationshipType.STATIC_CR;    
        cr.Save(RefreshMode.REFRESH);
    }

    // 各州の略語をロード
    String[] states =
        { "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", 
          "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA",
          "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", 
          "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", 
          "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", 
          "VA", "WA", "WV", "WI", "WY"
        };            

    const String COMPONENT_BINDING_LABEL = "ComponentBindingLabel";

    // Set paragraph 2 as compound document.
    docParagraph2.CompoundDocumentState = CompoundDocumentState.COMPOUND_DOCUMENT;
    docParagraph2.Save(RefreshMode.REFRESH);                 
            
    // Create state subcomponents for paragraph 2.
    for (int index = 0; index < states.Length; index++)
    {
        // Get chapter text.
        String stateFile 
            = "C:¥¥CDExample¥¥InsurancePolicy¥¥" + states[index] + ".txt";
        FileStream stream = new FileStream(stateFile, FileMode.Open);
        IContentTransfer ct = Factory.ContentTransfer.CreateInstance();
        ct.SetCaptureSource(stream);
                
        // コンテンツ・リストを作成
        IContentElementList list = Factory.ContentElement.CreateList();
        list.Add(ct);
                
        // Create state document.
        IDocument docState = Factory.Document.CreateInstance(os, null); 
        docState.ContentElements = list;
        docState.Checkin(
            AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
        docState.Save(RefreshMode.REFRESH);            
                
        docState
            .Properties
            .GetProperty(COMPONENT_BINDING_LABEL)
            .SetObjectValue(states[index]);
        docState.Save(RefreshMode.REFRESH);            

        // この州のコンポーネント関係を作成
        IComponentRelationship cr 
            = Factory.ComponentRelationship.CreateInstance(os, null);
        cr.ParentComponent = docParagraph2;
        cr.ChildComponent = docState;
        cr.ComponentRelationshipType = ComponentRelationshipType.DYNAMIC_LABEL_CR;
        cr.VersionBindType = VersionBindType.LATEST_MAJOR_VERSION;
        cr.LabelBindValue = states[index];
        cr.Save(RefreshMode.REFRESH);
    }
            
    /////////////////////////////////////////////
    // Assemble compound document.

    // 書籍用の出力ストリームを開始
    String bookFile = "C:¥¥CDExample¥¥Output¥¥PolicyDynamicLabelCR.txt"; 
    FileStream outStream = new FileStream(bookFile, FileMode.Create);            
            
    // 特定の州の証書を作成
    // Iterate through child relationships for paragraph 2. 
    String policyState = "AK";
    IComponentRelationshipSet crSet = docParagraph2.ChildRelationships;

    foreach (IComponentRelationship cr in crSet)
    {
        cr.LabelBindValue = policyState;
        cr.Save(RefreshMode.NO_REFRESH);
    }
            
    // Refresh paragraph 2. 
    // Causes ChildDocuments property to reflect correct policy state.
    docParagraph2.Refresh();
            
    // Output document.
    outputCompoundDocument(docPolicy, outStream);
            
}

コンポーネントの削除

この例では、ComponentCascadeDelete プロパティーを使用して、親コンポーネントを削除したときに、自動的に子コンポーネントを削除します。ComponentPreventDelete プロパティーを使用すると、親コンポーネントまたは子コンポーネントの削除を防止することにより、複合ドキュメントの整合性を保つことができます。

Java の例

private void ExampleDeletingComponents(ObjectStore os) throws Exception
{
    // Create book compound document.
    Document docBook = constructStaticBook(os);
                
    // コンポーネント関係内で反復
    // 段階的削除を設定
    Document docChapter = null;
    Iterator crIter = docBook.get_ChildRelationships().iterator();
    while (crIter.hasNext() == true)
    {
        // Update component relationship.
        ComponentRelationship cr = (ComponentRelationship) crIter.next();
        cr.set_ComponentCascadeDelete(
            ComponentCascadeDeleteAction.CASCADE_DELETE);
        cr.save(RefreshMode.REFRESH);                

        // 最終章を保持
        docChapter = cr.get_ChildComponent();
    }
            
    // Delete book.
    // すべての章が段階的に削除される
    docBook.delete();
    docBook.save(RefreshMode.REFRESH);
            
    // Attempt to refresh chapter (now deleted).
    try
    {
        docChapter.refresh();
    }
    catch (Exception exc)
    {
        System.out.println("Chapters cascade-deleted (as expected): "
                        + exc.getMessage());
    }
}

C# の例

private void ExampleDeletingComponents(IObjectStore os)
{
    // Create book compound document.
    IDocument docBook = constructStaticBook(os);
                
    // コンポーネント関係内で反復
    // 段階的削除を設定
    IDocument docChapter = null;
    foreach (IComponentRelationship cr in docBook.ChildRelationships)
    {
        // Update component relationship.
        cr.ComponentCascadeDelete = ComponentCascadeDeleteAction.CASCADE_DELETE;
        cr.Save(RefreshMode.REFRESH);                

        // 最終章を保持
        docChapter = cr.ChildComponent;
    }
            
    // Delete book.
    // すべての章が段階的に削除される
    docBook.Delete();
    docBook.Save(RefreshMode.REFRESH);
            
    // Attempt to refresh chapter (now deleted).
    try
    {
        docChapter.Refresh();
    }
    catch (System.Exception exc)
    {
        Console.WriteLine("Chapters cascade-deleted (as expected): "
                                        + exc.Message);
    }
        
}

親のバージョン管理

この例では、CopyToReservation プロパティーを使用して、自動的にドキュメントの次のバージョンの子コンポーネントにする既存の子コンポーネントを制御します。デフォルトでは、親ドキュメントの次のバージョン (ドキュメントのチェックアウトおよびチェックインにより作成される) には、前のバージョンと同じすべての子コンポーネントについて、同じ関係があります。この関係を変更して、次のバージョンには前のバージョンと同じ子コンポーネントの一部のみがあるように、またはどの子コンポーネントもないようにできます。

Java の例

private void ExampleVersioningParents(ObjectStore os) throws Exception
{
    // Create book compound document.
    Document docBook1 = constructStaticBook(os);
            
    // コンポーネント関係内で反復
    // copy-to-reservation プロパティーを設定
    int b1ChapterCount = 0;
    Iterator crIter1 = docBook1.get_ChildRelationships().iterator();
    while (crIter1.hasNext() == true)
    {
        // Increment count.
        b1ChapterCount++;
                
        // Update component relationship.
        ComponentRelationship cr 
            = (ComponentRelationship) crIter1.next();
        cr.set_CopyToReservation(Boolean.TRUE);
        cr.save(RefreshMode.REFRESH);                
    }

    // 書籍の新しいバージョンを作成
    docBook1.checkout(null, null, null, null);
    docBook1.save(RefreshMode.REFRESH);
    Document docBook2 = (Document) docBook1.get_Reservation();
    docBook2.checkin(null, CheckinType.MAJOR_VERSION);
    docBook2.save(RefreshMode.REFRESH);                 
            
    // New version should point to same chapters as previous version.
    int b2ChapterCount = 0;
    Iterator crIter2 = docBook2.get_ChildRelationships().iterator();
    while (crIter2.hasNext() == true)
    {
        // Increment count.
        crIter2.next();
        b2ChapterCount++;
    }
            
    System.out.println("Book 1 chapter count: " + b1ChapterCount);
    System.out.println("Book 2 chapter count: " + b2ChapterCount);
}

C# の例

private void ExampleVersioningParents(IObjectStore os)
{
    // Create book compound document.
    IDocument docBook1 = constructStaticBook(os);
            
    // コンポーネント関係内で反復
    // copy-to-reservation プロパティーを設定
    int b1ChapterCount = 0;
    foreach (IComponentRelationship cr in docBook1.ChildRelationships)
    {
        // Increment count.
        b1ChapterCount++;
                
        // Update component relationship.
        cr.CopyToReservation = true;
        cr.Save(RefreshMode.REFRESH);                
    }

    // 書籍の新しいバージョンを作成
    docBook1.Checkout(ReservationType.OBJECT_STORE_DEFAULT, null, null, null);
    docBook1.Save(RefreshMode.REFRESH);
    IDocument docBook2 = (IDocument) docBook1.Reservation;
    docBook2.Checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
    docBook2.Save(RefreshMode.REFRESH);                 
            
    // New version should point to same chapters as previous version.
    int b2ChapterCount = 0;
    foreach (IComponentRelationship cr in docBook2.ChildRelationships)
    {
        // Increment count.
        b2ChapterCount++;
    }
            
    Console.WriteLine("Book 1 chapter count: " + b1ChapterCount);
    Console.WriteLine("Book 2 chapter count: " + b2ChapterCount);

}


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

© Copyright IBM Corp. 2015.