cm = mapping.getClassMapping();
}
Iterator fieldsIt = sc.fields.values().iterator();
//System.out.println("Manage reference of the class " + sc.getFQName());
while (fieldsIt.hasNext()) {
SpeedoField sp = (SpeedoField) fieldsIt.next();
if (clazz.getTypedElement(sp.name) != null) {
//the primitive element is already managed before(createJormClass)
continue;
}
Type t = Type.getType(sp.type);
String javatype = t.getClassName();
if (!isGenClassRef(javatype)) {
// reference to a class //
//============================================================//
if (debug) {
logger.log(BasicLevel.DEBUG, "Class reference field: "
+ sp.name + " / javatype: " + javatype);
}
// reference to a class
SpeedoClass tsc = sc.moPackage.xmlDescriptor
.getSpeedoClass(javatype, true);
if (tsc == null) {
throw new SpeedoException("No persistent class '"
+ javatype + "' found in the file: "
+ sc.moPackage.xmlDescriptor.xmlFile);
}
Class tclass = manager.getClass(tsc.getFQName());
if (tclass == null) {
manager.createClass(tsc.getFQName());
}
ClassRef cr = clazz.createClassRef(sp.name, tclass);
NameDef refNd = cr.createRefNameDef();
nmf.getNamingManager(tsc)
.defineClassReferenceNameDef(refNd, cr, sp, sc, cm, this, mb);
if ( cm != null) {
cm.createReferenceMapping(sp.name, refNd);
cm.addDependency(tsc.getFQName());
}
} else {
// reference to a generic class //
//============================================================//
String innerType = getInnerType(sp);
if (innerType == null) {
throw new SpeedoException("The inner element type is " +
"required for the multivalued field '" + sp.name
+ "' of the class '" + sc.getFQName()
+ "' in the .jdo file '"
+ sc.moPackage.xmlDescriptor.xmlFile + "'");
}
PType type = getPrimitivePType(innerType);
if (type == null && !isPersistentClass(innerType, sc.moPackage.name, manager)) {
logger.log(BasicLevel.INFO, "The field '" + sc.getFQName()
+ "." + sp.name + " is managed as a Serialized field.");
type = PTypeSpace.SERIALIZED;
}
if (debug) {
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);