JavaMethod getInstanceByName = pSource.newJavaMethod("getInstanceByName",
pSource.getQName(),
JavaSource.PUBLIC);
getInstanceByName.setStatic(true);
getInstanceByName.addParam(String.class, "pName");
JavaComment jc = getInstanceByName.newComment();
jc.addLine("Returns the item with the given name.</p>");
jc.addThrows(IllegalArgumentException.class.getName() +
" The name <code>pName</code> is invalid and no such item exists.");
getInstanceByName.addLine(String.class, " s = pName.intern();");
boolean first = true;
for (int i = 0; i < pItems.length; i++) {
Item item = pItems[i];
Object[] args = new Object[]{JavaSource.getQuoted(item.getName()), " == s"};
getInstanceByName.addIf(first, args);
getInstanceByName.addLine("return ", item.getName(), ";");
first = false;
}
getInstanceByName.addElse();
getInstanceByName.addLine("throw new ", IllegalArgumentException.class, "(",
JavaSource.getQuoted("Invalid name: "),
" + pName);");
getInstanceByName.addEndIf();
JavaMethod getInstanceByValue = pSource.newJavaMethod("getInstanceByValue",
pSource.getQName(),
JavaSource.PUBLIC);
getInstanceByValue.setStatic(true);
getInstanceByValue.addParam(String.class, "pValue");
jc = getInstanceByValue.newComment();
jc.addLine("Returns the item with the given value.</p>");
jc.addThrows(IllegalArgumentException.class.getName() +
" The name <code>pValue</code> is invalid and no such item exists.");
getInstanceByValue.addLine(String.class, " s = pValue.intern();");
first = true;
for (int i = 0; i < pItems.length; i++) {
Item item = pItems[i];