EJB3におけるremoteインタフェースの自動生成

あれからEJB 3.0 Early Draftを読み返したのですが、前日の日記で「インタフェースが真に一本化され...」と書いた部分が誤解を受けそうなので補足します。確かにインタフェースは一本化されたのですが、一本化されたのはEJB開発者側だけです。

EJB 3のbusiness interfaceでやろうとしているのは、EJB開発者がLocal/Remote別々のインタフェースを提供する必要がないということであって、クライアントから見て両者の区別がなくなるということではないのでしょう。おそらく、クライアント側では従来どおりLocal/Remoteに応じてキャストが必要でしょう。

EJB 3ではbean classから(XDocletのように)business interfaceを生成(generate)する機能があります。9.2 Annotations to Specify Local or Remote Accessibilityを読むと次のように書いてあります。これを読めばわかるように、生成されるのはremoteインタフェースです。

The Remote annotation can be applied to a business interface of a session bean or to a session bean class. When applied to a business interface, it denotes that the interface is implemented by the container as a java.rmi.Remote interface. When applied to the bean class, it denotes that the generated business interface of the bean class is a remote business interface.

Remoteアノテーションはsession beanのbusiness interfaceやbean classに適用できる。business interfaceに適用された場合は、ユーザが提供したbusiness interfaceからコンテナによってjava.rmi.Remoteのインタフェースが実装される。bean classに適用された場合は、remoteインタフェースが生成される。

インタフェースにも@Remoteがつけられるという点がXDocletとは違いますね。