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");
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("setVersion");
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(new Type("int"), "version")});
retVal.addMethod(method);
}
for (int j = 0; (fields != null) && (j < fields.length); j++) {
ValueObjectFieldMetadata vField = fields[j];
method = new JavaMethod(vField.getProperty().getType(), vField.getProperty().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(vField.getProperty().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(vField.getProperty().getType(), vField.getProperty().getName())});
retVal.addMethod(method);
method = new JavaMethod(new Type("boolean"), vField.getProperty().getName()+"HasBeenSet");
modifiers = new String[metaVo.isFullSynchronization() ? 2 : 1];
modifiers[0] = "public";
if (metaVo.isFullSynchronization()) {
modifiers[1] = "synchronized";
}
method.setModifiers(modifiers);
retVal.addMethod(method);
}
for (int k = 0; k < nonCollectionRel.length; k++) {
ValueObjectRelationMetadata nonColRel = nonCollectionRel[k];
method = new JavaMethod(nonColRel.getProperty().getType(), nonColRel.getProperty().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(nonColRel.getProperty().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(nonColRel.getProperty().getType(), nonColRel.getProperty().getName())});
retVal.addMethod(method);
method = new JavaMethod(new Type("boolean"), nonColRel.getProperty().getName()+"HasBeenSet");
modifiers = new String[metaVo.isFullSynchronization() ? 2 : 1];
modifiers[0] = "public";
if (metaVo.isFullSynchronization()) {
modifiers[1] = "synchronized";
}
method.setModifiers(modifiers);
retVal.addMethod(method);
}
for (int k = 0; k < collectionRel.length; k++) {
ValueObjectRelationMetadata colRel = collectionRel[k];
field = new JavaField(colRel.getProperty().getType(), "added" + colRel.getProperty().getName());
field.setModifiers(new String[]{"protected"});
retVal.addField(field);
field = new JavaField(colRel.getProperty().getType(), "onceAdded" + colRel.getProperty().getName());
field.setModifiers(new String[]{"protected"});
retVal.addField(field);
field = new JavaField(colRel.getProperty().getType(), "removed" + colRel.getProperty().getName());
field.setModifiers(new String[]{"protected"});
retVal.addField(field);
field = new JavaField(colRel.getProperty().getType(), "updated" + colRel.getProperty().getName());
field.setModifiers(new String[]{"protected"});
retVal.addField(field);
method = new JavaMethod(colRel.getProperty().getType(), "getAdded" + colRel.getProperty().getName());
method.setModifiers(new String[]{"public"});
retVal.addMethod(method);
method = new JavaMethod(colRel.getProperty().getType(), "getOnceAdded" + colRel.getProperty().getName());
method.setModifiers(new String[]{"public"});
retVal.addMethod(method);
method = new JavaMethod(colRel.getProperty().getType(), "getRemoved" + colRel.getProperty().getName());
method.setModifiers(new String[]{"public"});
retVal.addMethod(method);
method = new JavaMethod(colRel.getProperty().getType(), "getUpdated" + colRel.getProperty().getName());
method.setModifiers(new String[]{"public"});
retVal.addMethod(method);
method = new JavaMethod(colRel.getProperty().getType(), colRel.getProperty().getAccessor().getName()+"Collection");
method.setModifiers(new String[]{"public"});
retVal.addMethod(method);
method = new JavaMethod(new Type(colRel.getAggregate(),1), colRel.getProperty().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(colRel.getProperty().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(new Type(colRel.getAggregate(),1), colRel.getProperty().getName())});
retVal.addMethod(method);
method = new JavaMethod("clear"+colRel.getProperty().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("add"+colRel.getAggregateName());
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(new Type(colRel.getAggregate()), "other")});
retVal.addMethod(method);
method = new JavaMethod("remove"+colRel.getAggregateName());
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(new Type(colRel.getAggregate()), "other")});
retVal.addMethod(method);
method = new JavaMethod("update"+colRel.getAggregateName());
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(new Type(colRel.getAggregate()), "other")});
retVal.addMethod(method);
method = new JavaMethod("clean"+colRel.getAggregateName());
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("copy"+colRel.getProperty().getName()+"From");
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(new Type(getDestinationFullyQualifiedClassName(metadata)), "other")});
retVal.addMethod(method);
}
method = new JavaMethod(new Type("java.lang.String"), "toString");
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(new Type("boolean"), "hasIdentity");
modifiers = new String[metaVo.isFullSynchronization() ? 2 : 1];
modifiers[0] = "protected";
if (metaVo.isFullSynchronization()) {
modifiers[1] = "synchronized";
}
method.setModifiers(modifiers);
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);
if (metaVo.isStrictOrdering()) {
method = new JavaMethod(new Type("int"), "compareTo");
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.Object"), "clone");
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(new Type("int"), "hashCode");
modifiers = new String[metaVo.isFullSynchronization() ? 2 : 1];
modifiers[0] = "public";
if (metaVo.isFullSynchronization()) {
modifiers[1] = "synchronized";
}
method.setModifiers(modifiers);
retVal.addMethod(method);
JavaClass innerClass = createDynamicJavaClass("ReadOnly" + getDestinationClassname(metadata), getDestinationPackage(metadata), null, getMetadataProvider());
innerClass.setModifiers(new String[]{"final","private"});
retVal.addClass(innerClass);
method = new JavaMethod(innerClass.asType(), "getReadOnly"+getDestinationClassname(metadata));
method.setModifiers(new String[]{"public"});
retVal.addMethod(method);
method = new JavaMethod(new Type("java.util.Collection"), "wrapCollection");
method.setModifiers(new String[]{"private", "static"});
method.setParameters(new JavaParameter[]{new JavaParameter(new Type("java.util.Collection"), "input")});
retVal.addMethod(method);
method = new JavaMethod(new Type("java.util.Set"), "wrapCollection");
method.setModifiers(new String[]{"private", "static"});
method.setParameters(new JavaParameter[]{new JavaParameter(new Type("java.util.Set"), "input")});
retVal.addMethod(method);
method = new JavaMethod(new Type("java.util.Collection"), "wrapReadOnly");
method.setModifiers(new String[]{"private", "static"});
method.setParameters(new JavaParameter[]{new JavaParameter(new Type("java.util.Collection"), "input")});
retVal.addMethod(method);
method = new JavaMethod(new Type("java.util.Set"), "wrapReadOnly");
method.setModifiers(new String[]{"private", "static"});
method.setParameters(new JavaParameter[]{new JavaParameter(new Type("java.util.Set"), "input")});
retVal.addMethod(method);
// handle inner class
implementz = getImplements(metadata);
implementzTypes = new Type[implementz.length];
for (int j = 0; j < implementz.length; j++) {
implementzTypes[j] = new Type(implementz[j]);
}
innerClass.setImplementz(implementzTypes);
method = new JavaMethod(retVal.asType(), "underlying");
method.setModifiers(new String[]{"private"});
innerClass.addMethod(method);
for (int j = 0; (fields != null) && (j < fields.length); j++) {
ValueObjectFieldMetadata vField = fields[j];
method = new JavaMethod(vField.getProperty().getType(), vField.getProperty().getAccessor().getName());
method.setModifiers(new String[]{"public"});
innerClass.addMethod(method);
method = new JavaMethod(new Type("boolean"), vField.getProperty().getName()+"HasBeenSet");
method.setModifiers(new String[]{"public"});
innerClass.addMethod(method);
}
for (int k = 0; k < nonCollectionRel.length; k++) {
ValueObjectRelationMetadata nonColRel = nonCollectionRel[k];
method = new JavaMethod(nonColRel.getProperty().getType(), nonColRel.getProperty().getAccessor().getName());
method.setModifiers(new String[]{"public"});
innerClass.addMethod(method);
method = new JavaMethod(new Type("boolean"), nonColRel.getProperty().getName()+"HasBeenSet");
method.setModifiers(new String[]{"public"});
innerClass.addMethod(method);
}
for (int k = 0; k < collectionRel.length; k++) {
ValueObjectRelationMetadata colRel = collectionRel[k];
method = new JavaMethod(colRel.getProperty().getType(), "getAdded" + colRel.getProperty().getName());
method.setModifiers(new String[]{"public"});
innerClass.addMethod(method);
method = new JavaMethod(colRel.getProperty().getType(), "getOnceAdded" + colRel.getProperty().getName());
method.setModifiers(new String[]{"public"});
innerClass.addMethod(method);
method = new JavaMethod(colRel.getProperty().getType(), "getRemoved" + colRel.getProperty().getName());
method.setModifiers(new String[]{"public"});
innerClass.addMethod(method);
method = new JavaMethod(colRel.getProperty().getType(), "getUpdated" + colRel.getProperty().getName());
method.setModifiers(new String[]{"public"});
innerClass.addMethod(method);
method = new JavaMethod(colRel.getProperty().getType(), colRel.getProperty().getAccessor().getName()+"Collection");
method.setModifiers(new String[]{"public"});
innerClass.addMethod(method);
method = new JavaMethod(new Type(colRel.getAggregate(),1), colRel.getProperty().getAccessor().getName());
method.setModifiers(new String[]{"public"});
innerClass.addMethod(method);
}
method = new JavaMethod(new Type("int"), "hashCode");
method.setModifiers(new String[]{"public"});
innerClass.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")});
innerClass.addMethod(method);
if (metaVo.isStrictOrdering()) {
method = new JavaMethod(new Type("int"), "compareTo");
method.setModifiers(new String[]{"public"});
method.setParameters(new JavaParameter[]{new JavaParameter(new Type("java.lang.Object"), "other")});
innerClass.addMethod(method);
}
// add to list
retLst.add(retVal);