VisiBroker ORBがvaluetypeを受け取ると,まずデマーシャルする必要があります。それから,その型の適切なファクトリを,その型の新しいインスタンスを生成するために見つけなければなりません。インスタンスが生成されたら,値データはインスタンスにアンマーシャルされます。その型は呼び出しの時に渡されるRepositoryIDによって識別されます。型とファクトリ間のマッピングは,言語固有です。
コードサンプル25-5および25-6に,JDK1.2を使用したPoint valuetypeのファクトリのサンプルインプリメンテーションを示します。
class PointFactory: public CORBA::ValueFactoryBase
{
public:
PointFactory(){}
virtual ~PointFactory(){}
CORBA::ValueBase* create_for_unmarshal() {
return new PointImpl();
}
};
public class PointDefaultFactory implements
PointValueFactory {
public java.io.Serializable read_value(
org.omg.CORBA.portable.InputStream is) {
java.io.Serializable val = new PointImpl();
// create and initialize value
// It is very important that this call is made.
val = ((org.omg.CORBA_2_3.portable.InputStream)is).
read_value(val);
return val;
}
public Point create (int x, int y, java.lang.String z) {
// IMPLEMENT:
return NO_IMPLEMENT;
}
}
Borland Enterprise Server VisiBroker 4.5以降のバージョンは,JDK 1.2またはJDK 1.3のデフォルト値ファクトリメソッドの正しいシグニチャを生成します。既存(Borland Enterprise Server VisiBroker 4.0)の生成コードは,次のようにデフォルト値ファクトリメソッドシグニチャを修正しないかぎり,JDK 1.3で実行するように設計されていません。既存のコードをJDK 1.3で使用し,デフォルト値ファクトリを修正しないと,コードはコンパイルされません。またはNO_IMPLEMENT例外が発生します。したがって,正しいシグニチャを生成するにはコードを再生成することをお勧めします。
次のコードサンプルに,JDK 1.3でコンパイルできるようにデフォルト値ファクトリメソッドシグニチャを修正する方法を示します。
class PointFactory: public CORBA::ValueFactoryBase
{
public:
PointFactory(){}
virtual ~PointFactory(){}
CORBA::ValueBase* create_for_unmarshal() {
return new PointImpl();
}
};
public class PointDefaultFactory implements
PointValueFactory {
public java.io.Serializable read_value (
org.omg.CORBA_2_3.portable.InputStream is) {
java.io.Serializable val = new PointImpl();
// create and initialize value
// It is very important that this call is made.
val = ((org.omg.CORBA_2_3.portable.InputStream)is).
read_value(val);
return val;
}
public Point create (int x, int y, java.lang.String z) {
// IMPLEMENT:
return NO_IMPLEMENT;
}
}