Skip Headers

Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Implementing the Component Interfaces

The component interfaces define the business methods of the bean that a client can invoke.

## Implementing the Remote Component Interface

The remote interface defines the business methods that a remote client can invoke. The requirements for developing the remote component interface include:

- The remote component interface of the bean must extend the `javax.ejb.EJBObject` interface, and its methods must throw the `java.rmi.RemoteException` exception.

- You must declare the remote interface and its methods as `public` for remote clients.

- The remote component interface, all its method parameters, and return types must be serializable. In general, any object that is passed between the client and the EJB must be serializable, because RMI marshals and unmarshalls the object on both ends.

- Any exception can be thrown to the client, as long as it is serializable. Runtime exceptions, including `EJBException` and `RemoteException`, are transferred back to the client as remote runtime exceptions.

Example 11-9 shows a remote component interface called `Hello` with its defined methods, each of which will be implemented in the corresponding session bean.

Example 11-9 Remote Component Interface for EJB 2.1 Session Bean

    package hello;

    import javax.ejb.*;
    import java.rmi.*;

    public interface Hello extends EJBObject
    {
        public String sayHello(String myName) throws RemoteException;
        public String sayHello() throws RemoteException;
    }

## Implementing the Local Component Interface

The local component interface defines the business methods of the bean that a local (collocated) client can invoke. The requirements for developing the local component interface include:

- The local component interface of the bean must extend the `javax.ejb.EJBLocalObject` interface.

- You declare the local component interface and its methods as `public`.

Example 11-10 shows a local component interface called `HelloLocal` with its defined methods, each of which will be implemented in the corresponding session bean.

Example 11-10 Local Component Interface for EJB 2.1 Session Bean

    package hello;

    import javax.ejb.*;

    public interface HelloLocal extends EJBLocalObject
    {
        public String sayHello(String myName);
        public String sayHello();
    }