Creating JavaBeans With NetRexx

Cours creating JavaBeans With NetRexx, tutoriel & guide de travaux pratiques en pdf.

Starting with NetRexx

In this chapter we write a small NetRexx program and list the different file types that NetRexx uses.
Our First NetRexx Program
We are sorry, but we do not present the 4232th copy of a ªHello Worldº program in this book.
Our first NetRexx program is a mathematical program. It calculates the factorial of a given number. Of course this is not a big deal, but try it with languages other than Rexx, and you will see. Figure 5 shows the program, which consists of a few statements to print a prompt for a number, get your input, calculate the factorial, display the result, and do basic error handling.

File Types Used by NetRexx

The NetRexx compiler translates the NetRexx programs to Java and then compiles the generated Java programs. The NetRexx compiler uses or generates these file types:
*.nrx NetRexx program files
*.class Compiled NetRexx or Java program files
*.crossref Cross reference fileÐlists the variables, their types, and where they are
used
*.java.keep NetRexx program translated to Java (see option -keep in ªCompile
Optionsº on page 14)
*.java Temporary generated Java programÐrenamed to *.java.keep or erased
after compilation (see option -nocompile in ªCompile Optionsº on page 14)
The NetRexx Compiler
In Chapter 2, ªStarting with NetRexxº on page 7 we show how to compile and run a
NetRexx program with this simple syntax:
nrc Factor
java Factor
or, even simpler:
nrc -run Factor
In this chapter we explain in detail how the NetRexx compiler works.

Command Files

The NetRexx package provides some convenient command files to compile and run your NetRexx programs. These command files are available on only some platforms, so check the documentation of the package or the NetRexx Internet home page for the availability of versions of the command files for the platform you use.
NetRexxC.cmd OS/2 REXX script file that takes the file names and the options as
arguments. It also supports the -run option that runs the programs after they have been compiled.
nrc.cmd OS/2 REXX script file, abbreviation of NetRexxC.cmd
NetRexxC.bat DOS batch file for the Windows platforms, a (simple) clone of
NetRexxC.cmd. Be careful with the -run option; it has to be the first argument, and it is case sensitive.
For more detailed information, look at the content of the command files.
The command files are provided to make your life (and that of your keyboard) easier. The native method of compiling and running NetRexx programs looks like this:
java COM.ibm.netrexx.process.NetRexxC Factor.nrx
java Factor
which is the equivalent of:
nrc -run Factor

What happens here?

The NetRexx compiler (NetRexxC) translates NetRexx code into Java byte code.
 Copyright IBM Corp. 1997 11
NetRexxC itself is a Java class from the COM.ibm.netrexx.process package. Because it has a main method, the NetRexxC class is a real Java application (or Java program), and so it can be run with the Java interpreter:
java COM.ibm.netrexx.process.NetRexxC
The file to be compiled is supplied as an argument to this Java program, NetRexxC.
The generated Java byte code is stored in a file with the .class extension. In our case the compiler creates the file:
Factor.class
This generated file also represents a real Java application that can be executed by entering:
java Factor
The NetRexxC (or nrc) command file automatically executes java factor when the -run option is used. When you supply more than one file name, the sources are compiled first and then runÐin the same order.
Note, however, that the -run option is provided by the command files and not by the compiler.
Arguments and Return Codes
The compiler can take two kinds of arguments, file names and options. The file names represent NetRexx source files to be compiled together. For example:
java COM.ibm.netrexx.process.NetRexxC Pinger qtime
As you can see, there is no need to enter the file names with their default extension of .nrx.
You can also supply options as arguments. The options always begin with a hyphen (-), for

Example

This particular option tells the compiler to save the intermediate Java code that NetRexxC generates and passes to the Java compiler. The intermediate Java code is stored in a file with the extension of .java.keep. We discuss these options in more detail in ªCompile Optionsº on page 14.
The compiler always returns a return code, which can be 0, 1, or 2. A return code of 0 indicates that the compiler found no errors and no warnings. A return code of 1 indicates that there were warnings, and a return code of 2 indicates that the compile was not successful. In the latter case you will get some error messages, and the generated Java file (with extension .java) is kept instead of the anticipated Java class.
Creating Java Applications Using NetRexx

How Does the Compiler Work?
In this section we discuss the implementation of the NetRexxC class in more detail to explain what happens in case of an error.
The NetRexxC class runs in two phases:
Translate NetRexx code into Java source code
Let the Java compiler generate Java byte code from the Java source
The first phase transforms the NetRexx source into Java source. Errors encountered in this phase are reported with the NetRexx error codes. The explanation that comes with the error codes should help you on the way to correct the errors.
If a more detailed message is not available, as in this case:
NetRexx portable processor, version 1.00
Error: keyword.expected (sorry, full message unavailable)
the system gives the (cryptic) error and appends the message ªSorry, full message unavailable.º
Similar to the Java compiler, NetRexxC uses a .properties file to store its warning and error messages. Therefore, if you encounter a situation in which the compiler tells you:
ªSorry,…,º check that theNetRexxC.properties file is present in the LIB subdirectory of the NetRexx home directory.
The NetRexx home directory (netrexx.home) is usually the same as the Java home directory.
To change the home directory in the OS/2 environment, use the environment variable called
NETREXX_HOME, or use the -D option of the Java interpreter when invoking the compiler:
java -Dnetrexx.home=d:\NetRexx COM.ibm.netrexx.process.NetRexxC Factor
which sets the d:\NetRexx directory path as the NetRexx home directory. Under Windows 95 and Windows NT you must copy the NetRexxC.properties file to the LIB subdirectory of the Java home directory.
In the second phase of the execution, NetRexxC compiles Java code into byte code, using the default Java compiler, javac. Determining what went wrong when you get errors in this phase is not intuitive.
In the occasional case when javac fails to compile the Java source, there will be a file with the extension of .java (the input file for javac) in the current directory. The errors that the Java compiler reports are mostly due to incorrect conversions from NetRexx constructs to the corresponding Java constructs. NetRexx reports an error if the .java file already exists. Delete the file before you restart the NetRexx compiler, or use the REPLACE compiler option.

The NetRexx Compiler 13

Invoking the Compiler from NetRexx or Java
You can use NetRexxC as a normal Java class. For this purpose the compiler provides the main method. This is its signature (see ªSignature of Methodsº on page60):
method main(arg=Rexx) constant returns int
To use NetRexxC from within NetRexx (or from plain Java), call the main method with the file names and the options provided in a REXX string. Figure 6 shows an example of the use of the NetRexxC class from within a NetRexx program.

Preface
How This Document is Organized
The Team That Wrote This Redbook
Comments Welcome
Chapter 1. Introduction
What Is NetRexx?
Design Objectives
Why NetRexx?
Installation
Installation Verification
Software Prerequisites
Installing the Sample Programs
Installing the Packages of this Redbook
NetRexx Documentation
NetRexx Home Page on the Internet
Java Toolkit Documentation
Chapter 2. Starting with NetRexx
Our First NetRexx Program
File Types Used by NetRexx
Chapter 3. The NetRexx Compiler
Command Files
Arguments and Return Codes
How Does the Compiler Work?
Invoking the Compiler from NetRexx or Java
Compile Options
Compiler-Only Options
Options Keyword
More Details on Options
Chapter 4. The NetRexx Language
Case Sensitivity
Comments
Continuation Character
Input and Output
Data Types
Operators and Expressions
Class Definition
Class Instruction
Chapter 5. Using NetRexx As a Scripting Language
Why Scripts?
Straightforward Programs
Subroutines and Functions
External Methods
External Methods in a Package
Calling Non-Java Programs
Behind the Scenes
Handling Parameters in a NetRexx Script
Chapter 6. Creating and Using NetRexx Classes
Definition of Class
Why Use Classes?
Signature of Methods
Overloading Methods
Constructor Methods
Invoking Methods
Inheritance
Definition of Inheritance
Chapter 7. Creating Graphical User Interfaces
Applets and Applications
Applets
The Applet Tag
Structure of an Applet
Applications
Chapter 8. Threads
The Thread Class
Creating and Starting Threads
Controlling Threads
vi Creating Java Applications Using NetRexx
Lifetime of a Thread
Chapter 9. Handling Files
Streams
File Class
Line Mode I/O
Data-Oriented I/O
Chapter 10. Database Connectivity with JDBC
JDBC and ODBC
JDBC Concepts
Database URLs
Chapter 11. Network Programming
Socket Interface
Socket
Sending a Request to an HTTP Server
Testing the Simple HTTP Client
ServerSocket
Chapter 12. Using NetRexx for CGI Programs
CGI Concepts
Passing Parameters to a CGI Program
Get Method
Post Method
Chapter 13. Creating JavaBeans With NetRexx
JavaBeans Concepts
Writing a Bean in NetRexx
Bean Class
Chapter 14. Why NetRexx?
viii Creating Java Applications Using NetRexx
Appendix A. Redbook Package Reference
CloseWindow Class
EqualSizePanel Class

Cours gratuitTélécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *