logger.log(BasicLevel.DEBUG, "GenClass reference field: "
+ sp.name + " / javatype: " + javatype
+ " / innerType: " + innerType
+ " / ptype=" + (type == null ? null : type.getJavaName()));
}
GenClassRef gcr = clazz.createGenClassRef(sp.name, javatype);
GenClassMapping gcm = null;
ClassRef cr = null;
SpeedoClass tsc = null;
//element of the gen class
if (type != null) {
// gen class of primitive type
gcr.createPrimitiveElement(type, PType.NOSIZE, PType.NOSIZE);
} else if (!isGenClassRef(innerType)) {
// gen class of classref
tsc = sc.moPackage.xmlDescriptor.smi
.getSpeedoClass(innerType, sc.moPackage);
if (tsc == null) {
throw new SpeedoException("The persistent class '"
+ sc.getFQName()
+ "' tries to reference (througth the field '"
+ sp.name
+ "') the class '" + innerType
+ "' not defined in the .jdo file '"
+ sc.moPackage.xmlDescriptor.xmlFile + "'");
}
Class tclass = manager.getClass(tsc.getFQName());
if (tclass == null) {
throw new SpeedoException("The inner element class '"
+ tsc.getFQName() + "' of the multivalued field '"
+ sp.name + "' of the class '" + sc.getFQName()
+ "' in the .jdo file '"
+ sc.moPackage.xmlDescriptor.xmlFile
+ "' has not been found among the persitent classes : "
+ manager.getClasses());
}
cr = gcr.createClassRef(tclass);
} else {
throw new SpeedoException(
"unmanaged the inner-element of the field '"
+ sp.name + "' of the class '" + sc.getFQName()
+ "' : " + innerType);
}
//Map the element of the generic class
if (mapping != null) {
gcm = mb.createGenClassMapping(gcr, sp, mapping);
if (gcr.isPrimitive()) {
mb.createGenClassElementMapping(gcr.getPrimitiveElement(), sp, gcm);
} else {
NameDef elemNd = cr.createRefNameDef();
nmf.getNamingManager(tsc).defineClassReferenceNameDef(elemNd, cr, sp, sc, gcm, this, mb);
//fillNameDef(elemNd, tsc, sc, gcr, gcr, gcm, mb, false, true, true, createdMOs);
gcm.createReferenceMapping(sp.name, elemNd);
cm.addDependency(tsc.getFQName());
}
}
// reference to a generic class from the class
NameDef refNd = gcr.createRefNameDef();
nmf.getNamingManager(sc).defineGenClassReferenceNameDef(refNd, gcr, sp, sc, cm, this, mb);
//fillNameDef(refNd, sc, sc, clazz, gcr, cm, mb, false, false, false, createdMOs);
if (cm != null) {
cm.createReferenceMapping(sp.name, refNd);
}
//identifier of the gen class
NameDef gcidNd = gcr.createIdNameDef();
nmf.getNamingManager(sc).defineGenClassIdentifierNameDef(
gcidNd, gcr, sp, sc, gcm, this, mb);
//fillNameDef(gcidNd, sc, sc, gcr, gcr, gcm, mb, true, true, true, createdMOs);
if (gcm != null) {
gcm.createIdentifierMapping(gcidNd);
}
//index of the gen class
java.lang.Class gcClass;
try {
gcClass = java.lang.Class.forName(javatype);
} catch (ClassNotFoundException e) {
throw new SpeedoException(
"The multivalued field '" + sp.name
+ "' of the class '" + sc.getFQName()
+ "' is not a well known class " + javatype, e);
}
if (isSubType(gcClass, java.util.List.class)) {
PrimitiveElement pe = gcr.createHiddenField(
LIST_INDEX, PTypeSpace.INT, PType.NOSIZE, PType.NOSIZE);
if (gcm != null) {
mb.createGenClassIndexMapping(pe, sp, gcm);
}
gcr.addIndexField(LIST_INDEX);
} else if (isSubType(gcClass, java.util.Map.class)) {
String keyfield = sp.getExtensionValueByKey(SpeedoProperties.KEY_FIELD);
if (keyfield == null) {
keyfield = MAP_INDEX;
}
PrimitiveElement pe = gcr.createHiddenField(
keyfield, getMapKeyPType(sp), PType.NOSIZE, PType.NOSIZE);
if (gcm != null) {
mb.createGenClassIndexMapping(pe, sp, gcm);
}
gcr.addIndexField(pe.getName());
}
}
}
}