# Example: File Control

This section provides an example of a File control used in the context of a business process. In this case, the File control instance writes a file to a specified location, triggered by a user request. This example assumes that you have created a new business process containing a client request node.

The business process is shown in the following figure:

The business process starts with a client request node, File Request, representing a point in the process at which a client sends a request to a process. In this case, the client invokes the fileRequest() method on the process to write a file with information on a new customer to the file system.

Complete the following tasks to design your business process to write the requested file 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

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. Click Integration Controls, then choose File. The Insert Control dialog box is displayed.
3. In the Insert File Control dialog box:

1. In Step 1, enter myFile as the variable name for this control.
2. In Step 2, ensure that the following option is selected: Create a new File control to use. Then, enter myFile 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. In this case, the directory name is C:/temp/customers.

file-mask—Enter a name for the file. For example, enter CustFile.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 myFile, is created in your project and displayed in the Controls tab.

4. Select File —> Save to save your work.

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

1. Expand the myFile control instance in the Data Palette. Then click the following method:

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

2. Drag the method from the Data Palette and drop it on your FileWrite business process in the Design View, placing it immediately after the File Request node. The node is named write by default.
3. Rename the node, replacing write with Write CustFile.
4. Double-click the Write CustFile node. Its node builder opens on the General Settings tab.
5. Confirm that myFile is displayed in the Control field and that the following method is selected in the Method field:

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

6. Click Send Data to open the second tab in the node builder. The Method Expects field is populated with the data type expected by the write() method: XmlObject someData.
7. In the Select variables to assign field, click the arrow to display the list of variables in your project. Then choose requestCustFile(InputDocument). If the variable does not already exist, you can choose Create new variable... to create it now.
8. Click Apply and Close.
9. Double click on the client request node (File Request) to open the node builder.
10. Click Receive Data to open the second tab on the node builder. The Method Expects field is populated with the data type expected, in this case InputDocument CustFile. In the Select variables to assign field, click the arrow to display the list of variables in your project. Then choose requestCustFile(InputDocument).
11. Click Apply and Close.

This step completes the design of your File control node.

At run time, pass a variable of type XmlObject to the Client Request method. The customer document is written to your file system in the location specified.