String projectName,
String mapperName,
JormMIMappingBuilder mb,
Collection createdMOs)
throws SpeedoException, PException {
Class clazz = manager.getClass(sc.getFQName());
logger.log(BasicLevel.DEBUG, "Generate the Jorm MI for the references of class "
+ clazz.getFQName());
Mapping mapping = null;
ClassMapping cm = null;
if (projectName != null && mapperName != null) {
mapping = clazz.getClassProject(projectName)
.getMapping(mapperName);
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 '"