JClass jClass = state.getJClass();
String className = jClass.getLocalName();
JField fValues = null;
JDocComment jdc = null;
JSourceCode jsc = null;
//-- modify constructor
JConstructor constructor = jClass.getConstructor(0);
constructor.getModifiers().makePrivate();
fValues = new JField(new JArrayType(
baseType.getJType(), getConfig().useJava50()), "values");
//-- Loop through "enumeration" facets
//-- and create the default values for the type.
int count = 0;
StringBuilder values = new StringBuilder("{\n");
while (enumeration.hasMoreElements()) {
Facet facet = (Facet) enumeration.nextElement();
String value = facet.getValue();
//-- Should we make sure the value is valid before proceeding??
//-- we need to move this code to XSType so that we don't have to do
//-- special code here for each type
if (count > 0) {
values.append(",\n");
}
//-- indent for fun
values.append(" ");
if (baseType.getType() == XSType.STRING_TYPE) {
values.append('\"');
//-- escape value
values.append(escapeValue(value));
values.append('\"');
} else {
values.append(value);
}
++count;
}
values.append("\n}");
fValues.setInitString(values.toString());
jClass.addField(fValues);
//-- #valueOf method
JMethod method = new JMethod("valueOf", jClass,
"the String value of the provided " + baseType.getJType());
method.addParameter(new JParameter(SGTypes.STRING, "string"));
method.getModifiers().setStatic(true);
jClass.addMethod(method);
jdc = method.getJDocComment();
jdc.appendComment("Returns the " + baseType.getJType());
jdc.appendComment(" based on the given String value.");
jsc = method.getSourceCode();
jsc.add("for (int i = 0; i < values.length; i++) {");
jsc.add("}");
jsc.add("throw new IllegalArgumentException(\"");