|
|
|
Copyright © 2003-2010 ZeroC, Inc. |
33.5 Facet Selection
Given that we have decided to extend an application with facets, we have to deal with the question of how clients select the correct facet. The answer typically involves an explicit selection of a facet sometime during client start‑up. For example, in our file system application, clients always begin their interactions with the file system by creating a proxy to the root directory. Let us assume that our versioning requirements have led to version 1 and version 2 definitions of directories as follows:module Filesystem { // Original version
// ...
interface Directory extends Node {
idempotent NodeSeq list();
// ...
};
};
module FilesystemV2 {
// ...
enum NodeType { Directory, File };
class NodeDetails {
NodeType type;
string name;
DateTime createdTime;
DateTime accessedTime;
DateTime modifiedTime;
// ...
};
interface Directory extends Filesystem::Node {
idempotent NodeDetailsSeq list();
// ...
};
};In this case, the semantics of the list operation have changed in version 2. A version 1 client uses the following code to obtain a proxy to the root directory:// Create a proxy for the root directory
//
Ice::ObjectPrx base
= communicator()‑>stringToProxy("RootDir:default ‑p 10000");
if (!base)
throw "Could not create proxy";
// Down‑cast the proxy to a Directory proxy
//
Filesystem::DirectoryPrx rootDir
= Filesystem::DirectoryPrx::checkedCast(base);
if (!rootDir)
throw "Invalid proxy";For a version 2 client, the bootstrap code is almost identical—instead of down-casting to Filesystem::Directory, the client selects the “V2” facet during the down-cast to the type FileSystemV2::Directory:// Create a proxy for the root directory
//
Ice::ObjectPrx base
= communicator()‑>stringToProxy("RootDir:default ‑p 10000");
if (!base)
throw "Could not create proxy";
// Down‑cast the proxy to a V2 Directory proxy
//
FilesystemV2::DirectoryPrx rootDir
= FilesystemV2::DirectoryPrx::checkedCast(base, "V2");
if (!rootDir)
throw "Invalid proxy";Of course, we can also create a client that can deal with both version 1 and version 2 directories: if the down-cast to version 2 fails, the client is dealing with a version 1 server and can adjust its behavior accordingly.
|
|