names.add(itemName);
names.add(itemValue);
}
pSource.addImplements(Serializable.class);
JavaField name = pSource.newJavaField("name", String.class, JavaSource.PRIVATE);
name.setFinal(true);
JavaField value = pSource.newJavaField("value", String.class, JavaSource.PRIVATE);
name.setFinal(true);
JavaConstructor jcon = pSource.newJavaConstructor(JavaSource.PRIVATE);
jcon.addParam(String.class, "pName");
jcon.addParam(String.class, "pValue");
jcon.addLine("name = pName;");
jcon.addLine("value = pValue;");
List instanceList = new ArrayList();
for (int i = 0; i < pItems.length; i++) {
Item item = pItems[i];
String itemName = item.getName();
String itemValue = item.getValue();
JavaField instance = pSource.newJavaField(itemName, pSource.getQName(),
JavaSource.PUBLIC);
instance.newComment().addLine("The enumeration item with name " + itemName +
" and value " + itemValue + ".");
instance.setStatic(true);
instance.setFinal(true);
instance.addLine("new ", pSource.getQName(), "(", JavaSource.getQuoted(itemName),
", ", JavaSource.getQuoted(itemValue), ")");
if (i > 0) instanceList.add(", ");
instanceList.add(instance);
}
JavaQName arrayType = JavaQNameImpl.getArray(pSource.getQName());
JavaField allInstances = pSource.newJavaField("allInstances", arrayType,
JavaSource.PRIVATE);
allInstances.setStatic(true);
allInstances.setFinal(true);
allInstances.addLine("new ", arrayType, "{", instanceList, "}");
JavaMethod getName = pSource.newJavaMethod("getName", String.class,
JavaSource.PUBLIC);
getName.newComment().addLine("The enumeration items name.");
getName.addLine("return ", name, ";");