String descriptorClassName = getQualifiedDescriptorClassName(jClass.getName());
DescriptorJClass classDesc = new DescriptorJClass(_config, descriptorClassName, jClass);
//-- get handle to default constuctor
JConstructor cons = classDesc.getConstructor(0);
JSourceCode jsc = cons.getSourceCode();
XMLInfoNature xmlNature = new XMLInfoNature(classInfo);
//-- Set namespace prefix
String nsPrefix = xmlNature.getNamespacePrefix();
if ((nsPrefix != null) && (nsPrefix.length() > 0)) {
jsc.add("_nsPrefix = \"");
jsc.append(nsPrefix);
jsc.append("\";");
}
//-- Set namespace URI
String nsURI = xmlNature.getNamespaceURI();
if ((nsURI != null) && (nsURI.length() > 0)) {
jsc.add("_nsURI = \"");
jsc.append(nsURI);
jsc.append("\";");
}
//-- set XML Name
String xmlName = xmlNature.getNodeName();
if (xmlName != null) {
jsc.add("_xmlName = \"");
jsc.append(xmlName);
jsc.append("\";");
}
//-- set Element Definition flag
boolean elementDefinition = xmlNature.isElementDefinition();
jsc.add("_elementDefinition = ");
jsc.append(new Boolean(elementDefinition).toString());
jsc.append(";");
//-- set grouping compositor
if (xmlNature.isChoice()) {
jsc.add("");
jsc.add("//-- set grouping compositor");
jsc.add("setCompositorAsChoice();");
} else if (xmlNature.isSequence()) {
jsc.add("");
jsc.add("//-- set grouping compositor");
jsc.add("setCompositorAsSequence();");
}
// handle substitution groups
List<String> substitutionGroups = xmlNature.getSubstitutionGroups();
if (!substitutionGroups.isEmpty()) {
jsc.add("java.util.List substitutionGroups = new java.util.ArrayList();");
Iterator<String> substitutionGroupIter = substitutionGroups.iterator();
while (substitutionGroupIter.hasNext()) {
String substitutionGroup = substitutionGroupIter.next();
jsc.add("substitutionGroups.add(\"");
jsc.append(substitutionGroup);
jsc.append("\");");
}
jsc.add("setSubstitutes(substitutionGroups);");
}
//-- To prevent compiler warnings...make sure
//-- we don't declare temp variables if field count is 0;
if (classInfo.getFieldCount() == 0) {
return classDesc;
}
//-- declare temp variables
jsc.add("org.exolab.castor.xml.util.XMLFieldDescriptorImpl desc = null;");
jsc.add("org.exolab.castor.mapping.FieldHandler handler = null;");
jsc.add("org.exolab.castor.xml.FieldValidator fieldValidator = null;");
//-- handle content
if (classInfo.allowContent()) {
createDescriptor(classDesc, classInfo.getTextField(), localClassName, null, jsc);
}
ClassInfo base = classInfo.getBaseClass();
FieldInfo[] atts = classInfo.getAttributeFields();
//--------------------------------/
//- Create attribute descriptors -/
//--------------------------------/
jsc.add("//-- initialize attribute descriptors");
jsc.add("");
for (int i = 0; i < atts.length; i++) {
FieldInfo member = atts[i];
//-- skip transient members
if (member.isTransient()) {
continue;
}
if (base != null) {
String baseNodeName = new XMLInfoNature(member).getNodeName();
if (baseNodeName.equals(XMLInfo.CHOICE_NODE_NAME_ERROR_INDICATION)) {
createDescriptor(classDesc, member, localClassName, nsURI, jsc);
} else {
if (base.getAttributeField(baseNodeName) != null) {
createRestrictedDescriptor(member, jsc);
} else {
createDescriptor(classDesc, member, localClassName,
nsURI, jsc);
}
}
} else {
createDescriptor(classDesc, member, localClassName, nsURI, jsc);
}
}
//------------------------------/
//- Create element descriptors -/
//------------------------------/
FieldInfo[] elements = classInfo.getElementFields();
jsc.add("//-- initialize element descriptors");
jsc.add("");
for (int i = 0; i < elements.length; i++) {
FieldInfo member = elements[i];
//-- skip transient members
if (member.isTransient()) {