if (!shouldGenerate(metadata)) {
return null;
}
JavaField field;
JavaMethod method;
JavaClass retVal = createDynamicJavaClass(getDestinationClassname(metadata), getDestinationPackage(metadata), null, getMetadataProvider());
retVal.setModifiers(new String[] { "public" });
PkMetadata metaPk = getMetaPk(metadata);
String extendz = getExtends(metadata);
JavaClass parentBuilded[];
JavaClass parent = metadata.getSuperJavaClass();
while (parent != null) {
parentBuilded = buildFor(parent);
if ((parentBuilded != null) && (parentBuilded[0].getFullyQualifiedName().equals(extendz))) {
retVal.setSuperClass(parentBuilded[0].asType());
break;
}
parent = parent.getSuperJavaClass();
}
String[] implementz = getImplements(metadata);
Type[] implementzTypes = new Type[implementz.length];
for (int i = 0; i < implementz.length; i++) {
implementzTypes[i] = new Type(implementz[i]);
}
retVal.setImplementz(implementzTypes);
BeanProperty[] properties = metaPk.getProperties();
for (int i = 0; (properties != null) && (i < properties.length); i++) {
field = new JavaField(properties[i].getType(), properties[i].getName());
field.setModifiers(new String[] { "public" });
retVal.addField(field);
}
method = new JavaMethod(getDestinationClassname(metadata));
method.setConstructor(true);
method.setModifiers(new String[] { "public" });
retVal.addMethod(method);
BeanProperty[] parentProperties = metaPk.getParentProperties();
if ((properties != null && properties.length > 0)
|| (parentProperties != null && parentProperties.length > 0)) {
method = new JavaMethod(getDestinationClassname(metadata));
method.setConstructor(true);
method.setModifiers(new String[] { "public" });
JavaParameter[] params = new JavaParameter[((properties != null) ? properties.length : 0) + ((parentProperties != null) ? parentProperties.length : 0)];
int idx = 0;
for (int i = 0; (properties != null) && (i < properties.length); i++) {
params[idx++] = new JavaParameter(properties[i].getType(), properties[i].getName());
}
for (int i = 0; (parentProperties != null) && (i < parentProperties.length); i++) {
params[idx++] = new JavaParameter(parentProperties[i].getType(), parentProperties[i].getName());
}
method.setParameters(params);
retVal.addMethod(method);
}
for (int i = 0; (properties != null) && (i < properties.length); i++) {
method = new JavaMethod(getSetterName(properties[i]));
method.setModifiers(new String[] { "public" });
method.setParameters(new JavaParameter[]{new JavaParameter(properties[i].getType(), properties[i].getName())});
retVal.addMethod(method);
method = new JavaMethod(properties[i].getType(), getGetterName(properties[i]));
method.setModifiers(new String[] { "public" });
retVal.addMethod(method);
}
method = new JavaMethod(new Type("int"), "hashCode");
method.setModifiers(new String[] { "public" });
retVal.addMethod(method);
method = new JavaMethod(new Type("boolean"), "equals");
method.setModifiers(new String[] { "public" });
method.setParameters(new JavaParameter[]{new JavaParameter(new Type("java.lang.Object"), "other")});
retVal.addMethod(method);
method = new JavaMethod(new Type("java.lang.String"), "toString");
method.setModifiers(new String[] { "public" });
retVal.addMethod(method);
return new JavaClass[]{retVal};
}