Using com.bowstreet.builders.webapp.api.Method

I've been writing some more custom builders recently and had a hard time figuring out how to generate a method with arguments.

Below is an example:

        Method method = new Method(builderCall, genContext);
method.setName("myMethod");
IXml args = null;

try {
args = XmlUtil.parseXml("<top><Argument><Name>msgValue</Name><Type>String</Type></Argument></top>");
} catch (IOException e) {
e.printStackTrace();
}

method.setArguments(args);
StringBuffer sb = new StringBuffer("{ \n");
sb.append(" webAppAccess.getVariables().getVariable(\"myVar\").setValue(msgValue); \n");
sb.append("}");
method.setBody(sb.toString());
method.invokeBuilder();

and here's the code added to the model on regen:

/**
* Generated Method [myMethod]
*/
public void myMethod(WebAppAccess webAppAccess, String msgValue)
{
webAppAccess.getVariables().getVariable("myVar").setValue(msgValue);
}
I figured out the magic XML for method.setArguments() by looking at the model XML for a standard method builder.

Comments

Popular posts from this blog

How to Open QR Codes

Jim Henson predicted the end of the world

Mega Giveaway! (Today only!!!)