![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Note: | The File control is available in BEA Workshop for WebLogic Platform only if you are licensed to use WebLogic Integration. |
A File control makes it easy to read, write, or append to a file in a file system. The topics in this section describe how to work with the File control. For information on how to add control instances to business processes, see Using Controls in Business Processes.
A File control makes it easy to read, write, or append to a file in a file system. The files can be one of the following types: XmlObject, RawData (binary), or String. When creating a File control, select the file type that matches the files present in the specified directory.
In addition, the File control supports file manipulation operations such as copy, rename, and delete. You can also retrieve a list of the files stored in the specified directory.
A File control performs an operation on a file. Each File control is customized to perform certain operations.
This topic describes how to create a new File control and provides an example of the File control's declaration in the java file.
For information on how to add control instances to business processes, see Using Controls in Business Processes.
You can create a new File control and add it to your business process. To define a new File control:
Note: | If the Data Palette view is not visible in BEA Workshop for WebLogic Platform, click Window![]() ![]() ![]() |
The Insert control: File dialog box appears.
A directory name is the absolute path name for the directory; it includes the drive specification as well as the path specification. For example, the following are valid directory names:
C:\directory (Windows)
/directory (Unix)
\\servername\sharename\directory (Win32 UNC)
You can also enter a period (.
), which specifies the current working directory. When you enter a forward slash (/
) in the Directory Name field, it is interpreted as follows:
C:
if the user directory is C:\bea
).The Directory Name field is required. Leaving the Directory Name field empty results in an error.
Note: | When writing files locally, if the specified directory does not already exist, it is created and the file is written into the new directory. |
*
), it is treated as a file mask. A wild-card character is specified to get the list of files in a directory. Wild-card characters are not valid for any other operation.The File name filter field is optional when inserting a control, but this property must then be set dynamically before performing a file operation.
write(String
data
)
or write(XmlObject
data
)
or write(RawData
data
)
) are generated for the File control. For example, if the directory contains XML documents, the type should be set to XmlObject so that read/write methods generated for the control will accept XmlObject variables. The same is true for RawData and String types.readLine()
method is created with support for large files.You can define a line by specifying either its record size or a delimiter string:
WARNING: | If the specified delimiter string does not exist in a file being processed, application behavior is unpredictable. |
If no record size or string delimiter is specified, the file is processed one line at a time. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. This style of file processing can be used with any size file.
Note: | You cannot define a line by specifying both a record size and a string delimiter. |
To learn about the methods available on the File control, see the Interface FileControl.
When you create a new File control, its declaration appears in the java file. The following code snippet is an example of what the declaration looks like when you choose the The directory contains large files to be processed option:
package requestquote;
import com.bea.control.FileControl;
import org.apache.beehive.controls.api.bean.ControlExtension;
import com.bea.wli.control.dynamicProperties.FileControlPropertiesDocument;
/*
* A custom File control.
*/
@ControlExtension
@FileControl.FileInfo(directoryName = "C:/bea/")
public interface FileCntrl extends com.bea.control.FileControl {
@FileControl.IOOperation(ioType = FileIOType.READLINE, delimiterString = "")
String readline();
static final long serialVersionUID = 1L;
public FileCntrl create();
}
The actual attributes that are present on the @jc:file
and @jc:file-operation
annotations depend on the values you entered in the Insert Control dialog.
The @FileControl
annotation controls the behavior of the File control. All of the attributes of the @FileControl
annotation are optional and have default values.
To learn more, see FileControl Annotation.
The File control, named TaxControlFile
in the example above, is declared as an extension of FileControl
. The @FileControl.Operation
annotations indicate that the file operation is readline (read tax_file.txt
record by record) and specifies the record size.
A File control performs operations on a file such as reading a file, writing a file, and appending data to a file. You can also use the File control to copy, rename, and delete files.
You usually configure a separate File control for each file you want to manipulate. You can specify settings for a File control in several different ways. One way is to set the File control's properties in Design view. Another way is to call the setProperties method of the FileControl
interface. You can change File control configuration properties dynamically. To get the current property settings, use the getProperties()
method.
You can also use the Interface ControlContext for access to a control's properties at run time and for handling control events. Property values set by a developer who is using the control are stored as annotations on the control's declaration in a JWS, JSP, or Process.java file, or as annotations on its interface, callback, or method declarations in a control file.
The following sections describe how to configure the File control.
You can specify the behavior of a File control in Design View by setting the control's properties in the Properties pane. These properties correspond to attributes of the @FileControl
and @FileControl.Operation
annotations, which identify the File control in your code. The following attributes specify class- and method-level configuration attributes for the File control.
To learn more about specifying default File control behavior with attributes of the @FileControl
annotation, see
FileControl Annotation.
Once you have declared and configured a File control, you can invoke its methods from within your application to perform file operations and to change its configuration. For complete information on each method, see the Interface FileControl.
Use the following methods of the FileControl interface to perform file operations and reconfigure the File control.
The File control does not provide callbacks to wait for a file to appear. If the business process needs to wait for a file to appear, use the File Event Generator functionality. The business process can use the Message Broker Subscribe control to subscribe to a channel if it is interested in processing the files in a given directory. A File Event Generator is then configured so that when a file appears in that directory, it publishes a message to the associated channel containing the contents of the file.
The File control invokes an error handler when exceptions are encountered in read()
methods. (Exceptions can occur when the contents of the file are invalid.) The error handler moves the file to an error directory. However, if the error directory is not configured, the error handler throws the following exception: File or Directory does not exist. To ensure that useful information about the exception is available, the exception thrown by the error handler is logged and appears on the WebLogic Server Console and the original exception is rethrown.
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:
In this scenario, you add one instance of the File control to your business process.
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.
An instance of a File control, named myFile, is created in your project and displayed in the Controls tab.
FileControlPropertiesDocument write(com.bea.xml.XmlObject someData)
FileControlPropertiesDocument write(com.bea.xml.XmlObject someData)
write
() method: XmlObject someData
.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).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.
![]() ![]() ![]() |