jclass.addInterface("org.exolab.castor.tests.framework.CastorTestable");
jclass.addImport("org.exolab.castor.tests.framework.CastorTestable");
jclass.addImport("org.exolab.castor.tests.framework.RandomHelper");
//implementation of randomizeFields
JMethod jMethod = new JMethod(null, "randomizeFields");
jMethod.addException(new JClass("InstantiationException"));
jMethod.addException(new JClass("IllegalAccessException"));
jMethod.setComment("implementation of org.exolab.castor.tests.framework.CastorTestable");
jclass.addMethod(jMethod);
JSourceCode jsc = jMethod.getSourceCode();
JField[] fields = jclass.getFields();
for (int i = 0; i <fields.length; i++) {
JField temp = fields[i];
JType type = temp.getType();
String name = temp.getName();
if (name.startsWith("_"))
name = JavaNaming.toJavaClassName(name.substring(1));
else
name = JavaNaming.toJavaClassName(name);
String setName = "set" + name;
String componentName = null;
if (name.indexOf("Has") == -1) {
//Collection needs a specific handling
if ( (type.getName().equals("java.util.Vector")) ||
(type.getName().equals("java.util.ArrayList")) ) {
//if we are dealing with a Vector or an ArrayList
//we retrieve the type included in this Collection
int listLocat = name.lastIndexOf("List");
String tempName = name;
if (listLocat != -1)
tempName = tempName.substring(0,listLocat);
String methodName = JavaNaming.toJavaClassName(tempName);
methodName = "get"+methodName;
JMethod method = jclass.getMethod(methodName,0);
//@todo handle the Item introduced in with the group handling
if (method == null)
continue;
componentName = method.getReturnType().getName();
method = null;
methodName = null;
tempName = null;
jsc.add(temp.getName());
jsc.append(" = RandomHelper.getRandom(");
jsc.append(temp.getName());
jsc.append(", ");
jsc.append(componentName);
jsc.append(".class);");
}//Vector or ArrayList
else if (type.isPrimitive()) {
jsc.add(setName);
jsc.append("(RandomHelper.getRandom(");
jsc.append(temp.getName());
jsc.append("));");
}
else {
jsc.add(setName);
jsc.append("((");
jsc.append(type.getName());
jsc.append(")RandomHelper.getRandom(");
jsc.append(temp.getName());
jsc.append(", ");
jsc.append(type.getName());
jsc.append(".class));");
}
jsc.add("");
}
}
//implementation of dumpFields
jMethod = new JMethod(SGTypes.String, "dumpFields");
jMethod.setComment("implementation of org.exolab.castor.tests.framework.CastorTestable");
jclass.addMethod(jMethod);
jsc = jMethod.getSourceCode();
jsc.add("String result = \"DumpFields() for element: ");
jsc.append(jclass.getName());