JavaClass metadata = expandedClasses[i];
if (!shouldGenerate(metadata)) {
continue;
}
ValueObjectMetadata metaVo = getMetaVO(metadata);
BeanProperty pkProperty = metaVo.getPkProperty();
JavaField field;
JavaMethod method;
JavaClass retVal = createDynamicJavaClass(getDestinationClassname(metadata), getDestinationPackage(metadata), null, getMetadataProvider());
String[] modifiers = new String[isAbstract(metadata) ? 2 : 1];
modifiers[0] = "public";
if (isAbstract(metadata)) {
modifiers[1] = "abstract";
}
retVal.setModifiers(modifiers);
retVal.setSuperClass(new Type(getExtends(metadata)));
String[] implementz = getImplements(metadata);
Type[] implementzTypes = new Type[implementz.length];
for (int j = 0; j < implementz.length; j++) {
implementzTypes[j] = new Type(implementz[j]);
}
retVal.setImplementz(implementzTypes);
if (getEjbUtils().isUseSoftLocking(metadata)) {
field = new JavaField(new Type("int"), "_version");
field.setModifiers(new String[] { "private" });
retVal.addField(field);
}
ValueObjectFieldMetadata[] nonPkFields = metaVo.getNonPkFields();
for (int j = 0; j < nonPkFields.length; j++) {
ValueObjectFieldMetadata vField = nonPkFields[j];
field = new JavaField(vField.getProperty().getType(), vField.getProperty().getName());
field.setModifiers(new String[] { "private" });
retVal.addField(field);
field = new JavaField(new Type("boolean"), vField.getProperty().getName()+"HasBeenSet");
field.setModifiers(new String[] { "private" });
retVal.addField(field);
}
ValueObjectFieldMetadata[] pkFields = metaVo.getPkFields();
for (int j = 0; j < pkFields.length; j++) {
ValueObjectFieldMetadata vField = pkFields[j];
field = new JavaField(vField.getProperty().getType(), vField.getProperty().getName());
field.setModifiers(new String[] { "private" });
retVal.addField(field);
field = new JavaField(new Type("boolean"), vField.getProperty().getName()+"HasBeenSet");
field.setModifiers(new String[] { "private" });
retVal.addField(field);
}
ValueObjectRelationMetadata[] nonCollectionRel = metaVo.getNonCollectionRelations();
for (int j = 0; j < nonCollectionRel.length; j++) {
ValueObjectRelationMetadata vRelation = nonCollectionRel[j];
field = new JavaField(vRelation.getProperty().getType(), vRelation.getProperty().getName());
field.setModifiers(new String[] { "private" });
retVal.addField(field);
field = new JavaField(new Type("boolean"), vRelation.getProperty().getName()+"HasBeenSet");
field.setModifiers(new String[] { "private" });
retVal.addField(field);
}
ValueObjectRelationMetadata[] collectionRel = metaVo.getCollectionRelations();
for (int j = 0; j < collectionRel.length; j++) {
ValueObjectRelationMetadata vRelation = collectionRel[j];
field = new JavaField(vRelation.getProperty().getType(), vRelation.getProperty().getName());
field.setModifiers(new String[] { "private" });
retVal.addField(field);
}
method = new JavaMethod(getDestinationClassname(metadata));
method.setConstructor(true);
method.setModifiers(new String[] { "public" });
retVal.addMethod(method);
if (metaVo.isGeneratePKConstructor() && metaVo.hasPk()) {
if(!isEmpty(nonPkFields) || !metaVo.isSimplePkProperty()) {
method = new JavaMethod(getDestinationClassname(metadata));
method.setConstructor(true);
method.setModifiers(new String[] { "public" });
method.setParameters(new JavaParameter[]{new JavaParameter(pkProperty.getType(), pkProperty.getName())});
retVal.addMethod(method);
}
if(!isEmpty(nonPkFields) && !metaVo.isSimplePkProperty()) {
method = new JavaMethod(getDestinationClassname(metadata));
method.setConstructor(true);
method.setModifiers(new String[] { "public" });
JavaParameter[] params = new JavaParameter[nonPkFields.length + 1];
params[0] = new JavaParameter(pkProperty.getType(), pkProperty.getName());
for (int j = 0; j < nonPkFields.length; j++) {
ValueObjectFieldMetadata nonPkField = nonPkFields[j];
params[j+1] = new JavaParameter(nonPkField.getProperty().getType(), nonPkField.getProperty().getName());
}
method.setParameters(params);
retVal.addMethod(method);
}
}
ValueObjectFieldMetadata[] fields = metaVo.getFields();
if (!isEmpty(fields)) {
method = new JavaMethod(getDestinationClassname(metadata));
method.setConstructor(true);
method.setModifiers(new String[] { "public" });
JavaParameter[] params = new JavaParameter[fields.length];
for (int j = 0; j < fields.length; j++) {
ValueObjectFieldMetadata vField = fields[j];
params[j] = new JavaParameter(vField.getProperty().getType(), vField.getProperty().getName());
}
method.setParameters(params);
retVal.addMethod(method);
}
if (metaVo.hasPk() && !metaVo.isSimplePkProperty()) {
method = new JavaMethod(pkProperty.getType(), pkProperty.getAccessor().getName());
modifiers = new String[metaVo.isFullSynchronization() ? 2 : 1];
modifiers[0] = "public";
if (metaVo.isFullSynchronization()) {
modifiers[1] = "synchronized";
}
method.setModifiers(modifiers);
retVal.addMethod(method);
method = new JavaMethod(pkProperty.getMutator().getName());
modifiers = new String[metaVo.isFullSynchronization() ? 2 : 1];
modifiers[0] = "public";
if (metaVo.isFullSynchronization()) {
modifiers[1] = "synchronized";
}
method.setModifiers(modifiers);
method.setParameters(new JavaParameter[]{new JavaParameter(pkProperty.getType(), pkProperty.getName())});
retVal.addMethod(method);
}
if (getEjbUtils().isUseSoftLocking(metadata)) {
method = new JavaMethod(new Type("int"), "getVersion");