Tutorial: Building Your First Business Process

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

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:

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 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 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 ControlsArrow symbolFile. The Insert Control dialog box is displayed.
  3. In the Insert Control dialog box:
    1. Enter myFileQuote as the variable name for this control, and click Next.
    2. In the Create Control dialog box, select Create a new File control to use, then enter MyFileQuote in the Name field and click Next.
    3. In the Insert Control - File dialog box, enter values in the following fields:
    4. 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 name filter—Enter a name for the file. For example, enter quote.xml.

      Type of data—Select XmlObject from the drop-down list.

    5. Click Finish to close the Insert Control dialog box.
    6. An instance of a File control, named myFileQuote, is created in your project and displayed under the Controls folder.

  4. From the Workshop menu, select FileArrow symbolSave.
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:
  2. FileControlPropertiesDocument write(XmlObject someData)
  3. 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.
  4. Rename the node from write to Write Quote to File.
  5. Double-click the Write Quote to File node. Its node builder opens on the General Settings tab.
  6. Confirm that myFileQuote is displayed in the Control field and that the following method is selected in the Method field:
  7. FileControlPropertiesDocument write(XmlObject someData)
  8. 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.
  9. 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.)
  10. 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.
  11. To continue with the tutorial without specifying a variable on the Receive Data tab, click Close to close the node builder.
  12. From the Workshop menu, select FileArrow symbolSave.
  13. 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.

  14. 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 project in your tutorial application. (See the project in the Package Explorer 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. The Variable type field populated with com.bea.wli.control.dynamicProperties.FileControlPropertiesDocument. In the Select Variable Typed pane, expand system/DynamicProperties.xsd, then select FileControlProperties.
  6. Note: By default the com.bea.wli.control.dynamicProperties.FileControlPropertiesDocument is selected in the Variable type field.
  7. Click OK. The new variable is displayed in the node builder.


  8. To close the node builder, click Close.
  9. From the Workshop menu, select FileArrow symbolSave.
  10. 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 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 BEA Products applications in BEA Workshop.
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.java file in Source view. By completing the steps described in the preceding section, the following code is written in your JAVA 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


  Back to Top       Previous  Next