The JavaTM Web Services Tutorial
Home
TOC
PREV TOP NEXT

Types Supported By JAX-RPC

Behind the scenes, the JAX-RPC reference implementation maps types of the Java programming language ("Java types") to XML/WSDL definitions. For example, the reference implementation maps the java.lang.String class to the xsd:string XML data type. Application developers don't need to know the details of these mappings, but they should be aware that not every class in the Java 2 Standard Edition (J2SE) can be used as a method parameter or return type in JAX-RPC.

J2SE SDK Classes

JAX-RPC supports the following J2SE SDK classes:

java.lang.String	
java.lang.Boolean	
java.lang.Byte	
java.lang.Double	
java.lang.Float	
java.lang.Integer	
java.lang.Long	
java.lang.Short	
java.lang.String	
	
java.math.BigDecimal	
java.math.BigInteger	
	
java.util.Calendar	
java.util.Date
 

Note that classes in the Java Collections Framework, such as java.util.ArrayList, are not supported by JAX-RPC. Unsupported classes can be mapped to XML/WSDL definitions with pluggable serializers and deserializers. However, this mapping technique is for advanced developers and is not covered in this tutorial. For more information on pluggable serializers and deserializers, see the Extensible Type Mapping chapter of the JAX-RPC Specification.

Primitives

JAX-RPC supports the following primitive types of the Java programming language:

boolean	
byte	
double	
float	
int	
long	
short
 

Arrays

JAX-RPC also supports arrays with members of supported JAX-RPC types. Examples of supported arrays are int[] and String[]. Multidimensional arrays, such as BigDecimal[][], are also supported.

For an example of a remote procedure with a String[] parameter, take a look at the code sample in the tutorial/examples/jaxrpc/simplebean directory. In the implementation class named HelloImpl, the reverse method accepts as input a String[] parameter named words and returns copy of the array in reverse order. The code for the reverse method follows:

public String[] reverse(String[] words) {	
	
    String[] result = new String[words.length];	
    int r = 0;	
    for (int w = words.length - 1; w >= 0; w--) {	
        result[r] = words[w];	
        r++;	
    }	
    return result;	
}
 

In the following code snippet, the HelloClient program invokes the reverse method and displays the results:

private static void demoArray(HelloIF_Stub stub) {	
	
    try {	
        String[] words = {"it", "was", "a", "dark", "and",	
                          "stormy", "night"};	
        System.out.println("demoArray method:");	
        for (int j = 0; j < words.length; j++) {	
            System.out.print(words[j] + " ");	
        }	
        System.out.println();	
        String[] backwards = stub.reverse(words);	
        for (int j = 0; j < backwards.length; j++) {	
            System.out.print(backwards[j] + " ");	
        }	
        System.out.println();	
    } catch (Exception ex) {	
        ex.printStackTrace();	
    }	
}
 

To build, install, and run the example, follow these steps:

  1. If you haven't already done so, follow the instructions in Setting Up.
  2. In a terminal window, go to the docs/tutorial/examples/jaxrpc/simplebean directory.
  3. Type the following commands:
    ant build	
    ant install	
    ant run
     
    

The lines displayed by the client should include the following:

demoArray method:	
it was a dark and stormy night 	
night stormy and dark a was it 	
...
 

(The other lines displayed are for the JavaBeans component example, which is discussed in a later section.)

Application Classes

JAX-RPC also supports classes that you've written for your applications. In an order processing application, for example, you might provide classes named Order, LineItem, and Product. The JAX-RPC Specification refers to such classes as value types, because their values (or states) may be passed between clients and remote services as method parameters or return values.

To be supported by JAX-RPC, an application class must conform to the following rules:

The class may contain public, private, or protected fields. For its value to be passed (or returned) during a remote call, a field must meet these requirements:

JavaBeans Components

JAX-RPC also supports JavaBeans components, which must conform to the same set of rules as application classes. In addition, a JavaBeans component must have a getter and setter method for each bean property. The type of the bean property must be a supported JAX-RPC type.

The code sample in the tutorial/examples/jaxrpc/simplebean directory shows how to use a JavaBeans component in a remote call. In this example, the JavaBeans component is called SimpleAccountBean:

package simplebean;	
	
import java.io.Serializable;	
import java.math.BigDecimal;	
	
public class SimpleAccountBean implements Serializable {	
	
    private BigDecimal balance;	
    private String customerName;	
	
    public SimpleAccountBean() {	
        BigDecimal balance = new BigDecimal("0.00");	
        String customerName = null;	
    }	
	
	
    public BigDecimal getBalance() {	
        return balance;	
    }	
	
    public String getCustomerName() {	
        return customerName;	
    }	
	
    public void setBalance(BigDecimal balance) {	
        System.out.println	
            ("SimpleAccountBean: setting balance to " 	
            + balance);	
        this.balance = balance;	
    }	
	
    public void setCustomerName(String customerName) {	
        System.out.println	
            ("SimpleAccountBean: setting customerName to " 	
            + customerName);	
        this.customerName = customerName;	
    }	
}
 

In the HelloImpl class, the calculateInterest method has a SimpleAccountBean parameter:

public BigDecimal calculateInterest	
    (SimpleAccountBean simpleAccount) {	
	
    BigDecimal rate = new BigDecimal("0.05");	
    BigDecimal factor = rate.add(new BigDecimal("1.00"));	
    BigDecimal newBalance = 	
        simpleAccount.getBalance().multiply(factor);	
    return newBalance;	
}
 

The HelloClient program invokes the calculateInterest method as follows:

private static void demoBean(HelloIF_Stub stub) {	
	
    try {	
        System.out.println();	
        System.out.println("demoBean method:");	
        SimpleAccountBean dukesAccount =	
            new SimpleAccountBean();	
        dukesAccount.setBalance(new BigDecimal("1200.00"));	
        dukesAccount.setCustomerName("Duke");	
        BigDecimal newBalance =	
            stub.calculateInterest(dukesAccount);	
        System.out.println("newBalance: " + newBalance);	
        dukesAccount.setBalance(newBalance);	
    } catch (Exception ex) {	
        ex.printStackTrace();	
    }	
}
 

To build, install, and run the example, follow these steps:

  1. If you haven't already done so, follow the instructions in Setting Up.
  2. In a terminal window, go to the docs/tutorial/examples/jaxrpc/simplebean directory.
  3. The code example in the simplebean subdirectory demonstrates not only JavaBeans components, but also arrays. If you have already performed the steps in the section Arrays, then you may skip this step. Otherwise, type the following commands:
       ant build	
       ant install
     
    
  4. To run the client, type the following:
       ant run
     
    

The lines displayed by the client should include the following:

demoBean method:	
SimpleAccountBean: setting balance to 1200.00	
SimpleAccountBean: setting customerName to Duke	
newBalance: 1260.0000	
SimpleAccountBean: setting balance to 1260.0000
 

(The other lines displayed are for the example discussed in the section Arrays.)

Home
TOC
PREV TOP NEXT