# Step 10: Write Quote to File System

Complete this step to create a node, at which your business process writes the quote created in the preceding step to your file system. A File control makes it easy to read, write, or append to a file in a file system.

Complete the following tasks to design your business process to write the combined price and availability quote to your file system:

- To Create an Instance of a File Control in Your Project
- To Design a Control Send Node in Your Business Process to Interact With Your File Control

The following tasks are optional. They are provided to deepen your understanding of File controls but are not required for the completion of the tutorial.

- To Assign File Control Properties to a Variable in Your Business Process
- To Use the File Control Properties in Your Business Process

To Create an Instance of a File Control in Your Project

In this scenario, you add one instance of the File control to your business process.

1. Click Add on the Data Palette Controls tab to display a list of controls that represent the resources with which your business process can interact.
2. Select Integration Controls —> File. The Insert Control dialog box is displayed.
3. In the Insert Control dialog box:

1. In Step 1, enter myFileQuote as the variable name for this control.
2. In Step 2, select Create a new File control to use, then enter MyFileQuote in the New JCX name field.
3. In Step 3, enter values in the following fields:

directory-name—Enter the location in which you want the File control to write the file. You can use any location on your file system.

file-mask—Enter a name for the file. For example, enter quote.xml.

file-type—Select XmlObject from the drop-down list.

4. Click Create to close the Insert Control dialog box.

An instance of a File control, named myFileQuote, is created in your project and displayed in the Controls tab.

4. From the Workshop menu, select File —> Save.

Note: In the simple case, each instance of the File control allows you to manipulate a separate file. To learn about how your File control can operate on multiple files, see File Control.

To Design a Control Send Node in Your Business Process to Interact With Your File Control

1. Expand the myFileQuote control instance in the Data Palette, then click the following method:

    FileControlPropertiesDocument write(com.bea.xml.XmlObject someData)

2. From the Data Palette, drag the method and drop it on your RequestQuote business process, placing it immediately after the Combine Price and Avail Quotes node (and immediately before the Finish node). The node is named write by default.
3. Rename the node from write to Write Quote to File.
4. Double-click the Write Quote to File node. Its node builder opens on the General Settings tab.
5. Confirm that myFileQuote is displayed in the Control field and that the following method is selected in the Method field:

    FileControlPropertiesDocument write(XmlObject someData)

6. Click Send Data to open the second tab in the node builder. The Control Expects field is populated with XmlObject someData, which is the data type expected by the write() method.
7. In the Select variables to assign field, click the arrow to display the list of variables in your project, then choose Quote (quote). (Recall that you created the Quote variable to hold the quote in Step 9: Create Quote Document.)

Note: The node builder for this node contains a Receive Data tab. You can use this tab to specify a variable to which the data returned by the File control is assigned. For the purposes of this tutorial scenario, it is not required that you specify this variable; you can ignore the Receive Data tab. However, to learn how to specify a variable on the Receive Data tab, and a scenario in which you might subsequently use the variable, proceed to Note About File Control Properties.

8. To continue with the tutorial without specifying a variable on the Receive Data tab, close the node builder by clicking the X in the top right-hand corner.
9. From the Workshop menu, select File —> Save.

This step completes the design of your File control node. At run time, the quote document you created in Step 9: Create Quote Document is written to your file system in the location specified by you.

10. Proceed to Step 10: Write Quote to File System.

Note About File Control Properties

This optional section provides additional steps you can use to further define the Write Quote to File node you created in the preceding section. You are not required to complete the steps in this section to complete the tutorial. The steps are provided to help you understand and use the File Control Properties returned to your business process by the File control's FileControlPropertiesDocument write(XmlObject someData) method.

When you use a File control to write a file to the file system as you do in this step, the control returns information about the file you wrote. The information is returned in a document of type XML: FileControlPropertiesDocument. The FileControlPropertiesDocument is valid against an XML Schema: DynamicProperties.xsd. The Schema is provided for you in the Schemas project in your tutorial application. (See the Schemas project in the Application tab.)

To Assign File Control Properties to a Variable in Your Business Process

The following steps describe how to design the Write Quote to File node in your business process to include assigning a variable to which the File Control Properties are assigned:

Note: Before starting this section, you should have completed steps 1 through 7 as described in To Design a Control Send Node in Your Business Process to Interact With Your File Control.

1. If the Write Quote to File node builder is not open, double-click the node.
2. Click Receive Data to open the third tab in the node builder. The Control Returns field is populated with FileControlPropertiesDocument, which is the data type returned by the write() method.
3. In the Select variables to assign field, click the arrow to display the list of variables in your project, then choose create new variable.... The Create Variable dialog box is displayed.

4. In the Variable Name field, enter fileProperties.
5. In the Select Variable Type pane, expand system/DynamicProperties.xsd, then select FileControlProperties. The Variable type field populated with com.bea.wli.control.dynamicProperties.FileControlPropertiesDocument.
6. Click OK. The new variable is displayed in the node builder.

7. To close the node builder, click the X in the top right-hand corner.
8. From the Workshop menu, select File —> Save.

This step completes the design of your File control node. At run time, the quote document you create in Step 9: Create Quote Document is written to your file system in the location specified by you. Information about the file you wrote is returned to the RequestQuote business process, and assigned to the fileProperties variable you created.

Note: The Dynamic Properties.xsd XML Schema must be available in a Schemas project in your application before you can create a variable to hold the file control properties that are returned to your business process from the File control. Dynamic Properties.xsd is one of the system schemas available to you when you create WebLogic Integration applications in WebLogic Workshop. To create a project that contains system schemas in your application, choose File —> New —> Project from the WebLogic Workshop menu to open the New Project dialog box. Select Schema in the left pane, then WLI System Schemas in the right pane. Enter a name for your project in the Project name field and click Create.

To Use the File Control Properties in Your Business Process

In the preceding steps, you assigned the data returned from the File control to a variable named fileProperties. You can derive information about the file you wrote from fileProperties.

Click the Source View tab to view your RequestQuote.jpd file in Source View. By completing the steps described in the preceding section, the following code is written in your JPD file in keeping with the work you did in the Design View.

The fileProperties variable declaration is shown in the following listing:

    public com.bea.wli.control.dynamicProperties.FileControlPropertiesDocument fileProperties;

The write() method on the myFileQuote control is shown in the following listing:

    public void myFileQuoteWrite() throws Exception
        {
            //#START: CODE GENERATED - PROTECTED SECTION - you can safely add code
    above this comment in this method. #//

            // input transform
            // return method call
            this.fileProperties = myFileQuote.write(this.Quote);
            // output transform
            // output assignments
           //#END: CODE GENERATED - PROTECTED SECTION - you can safely add code below
    this comment in this method. #//
        }

You can edit this method (outside the PROTECTED SECTION of code) to write code that derives information from the fileProperties variable. For example, the following line of code returns the FileMask:

    this.fileProperties.getFileControlProperties().getFileMask()

To illustrate this example further, edit the public void fileQuoteWrite() method in Source View to include the line of code shown in bold in the following listing:

    //#END: CODE GENERATED - PROTECTED SECTION - you can safely add code below this comment in this method. #//

    System.out.println ("The RequestQuote Process logged the quote in the following file  "
     + this.fileProperties.getFileControlProperties().getFileMask());

    }

Note that you must add the code after the PROTECTED SECTION comment. Code completion in the Source View helps you write the code. When you switch back to the Design View, note that the Write Quote to File node changes to include the following icon: . This is a visual reminder that you edited the code associated with this node in the Source View.

When you run the business process, the name you gave the file (the FileMask) is printed to the console.

Related Topics

File Control

Using Integration Controls

How Do I: Create a Schemas Project Folder?

How Do I: Import Files into a Schemas Project Folder?