cancel
Showing results for 
Search instead for 
Did you mean: 

Context at runtime

Former Member
0 Kudos

Hi all,

Can anybody help on

1.What is Type Context API ?

2.What is Generic Context API ?

and what is the purpose.

With Regards

Vijay

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member182372
Active Contributor
0 Kudos

Hi vijay,

AS far as I remember - from Chris Whealy`s book:

Type context API:

is an independent value node


// Get a reference to node {cn}
I{cn}Node node{cn} = wdContext.node{cn}();
// Get the element at the lead selection {cn}
I{cn}Element this{cn}El = node{cn}.current{cn}Element();
// Get the value of {ca} using its accessor

// Get the size of the node element collection int size{cn} = node{cn}.size();
// Loop over all the elements in {cn}’s collection
for (int i=0; i<size{cn}; i++) {
I{cn}Element this{cn}El = (I{cn}Element) node{cn}
.getElementAt(i);
// Get the value of {ca} using its accessor method {dtca} this{ca} = this{cn}El.get{ca}();
// Do something useful with attribute values
}

for example


// Get a reference to the SalesOrders node
ISalesOrdersNode soNode = wdContext.nodeSalesOrders();
// Create a new element for node SalesOrders
ISalesOrdersElement newSoEl = soNode.createSalesOrdersElement();
// Use the attribute mutator methods to set the values
newSoEl.setLongText("Printer supplies");
newSoEl.setOrderNo(1000);
newSoEl.setSalesDate(new Date(System.currentTimeMillis());
newSoEl.setSalesRep("Harry Hawk");
// Append the new element to the node’s collection
soNode.addElement(newSoEl);

Generic Context API:


// Get a generic reference to node {cn}
IWDNode node{cn} = wdContext.getChildNode("{cn}",0); int leadSel = node{cn}.getLeadSelection();
// Select element 0 if no element is currently selected if (leadSel == -1) ++leadSel;
// Get the element at the lead selection
IWDNodeElement this{cn}El = node{cn}.getElementAt(leadSel);
// Get the attribute values using the generic accessor methods
String this{ca1} = this{cn}El.getAttributeAsText("{ca1}"); {dtca2} this{ca2} = ({dtca2})this{cn}El.getAttributeValue("{ca2}");

for example:


// Get a generic reference to the SalesOrders node
IWDNode soNode = wdContext.getChildNode("SalesOrders",0);
// Create a new element for node SalesOrders
IWDNodeElement newSoEl = soNode.createElement();
// Use the generic attribute mutator methods to set the values
newSoEl.setAttributeValue("LongText","Printer supplies");
newSoEl.setAttributeValue("OrderNo",new Integer(1000));
newSoEl.setAttributeValue("SalesDate",new Date(System.currentTimeMillis()));
newSoEl.setAttributeValue("SalesRep","Harry Hawk");

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

vijay,

You may work with context node/elements/attributes either in generic way like:


IWDNode node = <...>
IWDNodeElement el = node.createElement();
node.addElement(el);
el.setAttributeValue("MyStr",  "StringValue");
el.setAttributeValue("MyInt",  new Integer(10));
el.setAttributeValue("MyDate", new java.sql.Date());

or (typically) you may create node in NW context designer and WD build plugins will generate type for every node/element, so you may access them like:


IPrivate<ControllerName>.I<NodeName>Node node = <...>
IPrivate<ControllerName>.I<NodeName>Element el 
  = node.create<NodeName>Element();
el.setMyStr("StringValue");
el.setMyInt(10));
el.setMyDate(new java.sql.Date());

Under the hood generated typed classes delegates calls to generic interface.

Use generic approach only if you need to create some reusable functionality (utility class, library, component) that should work for all nodes or large subset of nodes.

Use typed approach for anything else when exact structure is known (AFAIK, majority of cases).

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com