Objects within the HydraExpress Agent exchange information using attributes. Each request object, session object, and context object contains a collection of attributes. Servlets and filters use these attribute collections to transfer and store information between requests.
Each attribute is an instance of rwsf::Attribute. Class rwsf::Attribute is a container that holds a single object. The contained object must provide a copy constructor and assignment operator that do not change the semantics or validity of the original object. The contained object must also have a default constructor. To copy an object into an attribute, use operator<<(). Conversely, to copy an object out of an attribute, use operator>>().
The following code sample copies a string into a servlet attribute, then copies the string from the attribute to a different string:
std::string source("Servlets in C++"); rwsf::Attribute stringAttr; stringAttr << source; // 1 source = "HydraExpress"; // 2 std::string destination; stringAttr >> destination; // 3
|//1||Copies the string "Servlets in C++" from source to stringAttr.|
|//2||Changes source to contain the string "HydraExpress". Since stringAttr contains a copy of the original string, stringAttr still contains "Servlets in C++".|
|//3||Copies the string "Servlets in C++" from stringAttr to destination.|
At the end of the sample, destination and stringAttr each contain a separate copy of the string "Servlets in C++", while source contains the string "HydraExpress".
There are two important limitations to rwsf::Attribute. First, the compiler cannot always detect attempts to extract an attribute into an object of an incompatible type. In these cases, the extraction operator throws rwsf::Exception when the type of the destination does not match the type of the object stored in the attribute.
Second, an attribute can only store a single object. An attribute cannot store an array or a string literal. However, an attribute can store an object that encapsulates the same data. For example, the code below stores a string instead of a literal character string:
rwsf::Attribute stringAttr; stringAttr << std::string("Your string here.");
©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.