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:
and here's the code added to the model on regen:
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:
/**I figured out the magic XML for method.setArguments() by looking at the model XML for a standard method builder.
* Generated Method [myMethod]
*/
public void myMethod(WebAppAccess webAppAccess, String msgValue)
{
webAppAccess.getVariables().getVariable("myVar").setValue(msgValue);
}
Comments
Post a Comment