Information Technology Reference
In-Depth Information
Agent agentAsAgent = (Agent) agentAsDO;
agentAsAgent.setId("123"); // static API
agentAsDO.setString("name", "Tom"); // dynamic API
System.out.println("agent = " + agentAsDO);
S AMPLE 3. Updating Agent properties.
agent = com.ibm.watson.oats.orderentry.impl.AgentImpl@5a50a67a (id:
123, name: Tom, password: null)
S AMPLE 4. Output from print Agent.
DataObject agentDOViaXPath =
orderEntryDO.getDataObject("/agents.0");
DataObject agentDOViaXPath2 = (DataObject) orderEntryDO
.get("agents[name='Tom']");
S AMPLE 5. Retrieving an Agent.
OrderEntry; we must therefore cast OrderEntry to DataObject to access the DataOb-
ject methods.
DataObject properties may be updated using static, Agent-specific, methods such
as setId , but this requires the application to first cast the DO to an Agent . Alter-
natively, the application can use the dynamic (generic) DataObject methods such as
setString() (see Sample 3 ). The output from printing the Agent DataObject is
shown in Sample 4 .
Sample 5 shows the usage of XPath queries to retrieve Agents. If the Agent is
known to be the first one contained within OrderEntry, the query “/agents.0” will
retrieve it. If the value of one of the Agent properties is known (e.g., “name”), the
property can be specified in the XPath query, as in the second example.
XPath queries may also be used to navigate within DataObjects, or from one
DataObject to another. Sample 6 shows an XPath query which navigates from the
Agent to its “name” property.
Search WWH ::




Custom Search