ClassInfo classInfo = state.getClassInfo();
JClass jClass = state.getJClass();
initialize(jClass);
if (classInfo.hasNature(XMLInfoNature.class.getName())) {
final XMLInfoNature xmlNature = new XMLInfoNature(classInfo);
//-- name information
xmlNature.setNodeName(component.getXMLName());
//-- namespace information
xmlNature.setNamespaceURI(component.getTargetNamespace());
//5--processing the type
XMLType type = component.getXMLType();
boolean createForSingleGroup = false;
boolean creatingForAnElement =
(component.getAnnotated().getStructureType() == Structure.ELEMENT);
//-- created from element definition information
xmlNature.setElementDefinition(creatingForAnElement);
// deal with substitution groups
if (creatingForAnElement) {
ElementDecl elementDeclaration = (ElementDecl) component.getAnnotated();
Enumeration<ElementDecl> possibleSubstitutes = elementDeclaration.getSubstitutionGroupMembers();
if (possibleSubstitutes.hasMoreElements()) {
List<String> substitutionGroupMembers = new ArrayList<String>();
while (possibleSubstitutes.hasMoreElements()) {
ElementDecl substitute = possibleSubstitutes.nextElement();
substitutionGroupMembers.add(substitute.getName());
}
xmlNature.setSubstitutionGroups(substitutionGroupMembers);
}
}
if (type != null) {
if (type.isComplexType()) {
processComplexType(component, sgState, state);
} else if (type.isSimpleType()) {
SimpleType simpleType = (SimpleType) type;
//-- handle our special case for enumerated types
if (simpleType.hasFacet(Facet.ENUMERATION)) {
processSimpleTypeEnumeration(component, sgState, classInfo, simpleType);
} else {
//////////////////////////////////////////////////////////
//NOTE: generate sources if the flag for generating sources
//from imported schemas is on
//////////////////////////////////////////////////////////
return new JClass[0];
}
} else if (type.isAnyType()) {
//-- Do not create classes for AnyType
xmlNature.setSchemaType(new XSClass(SGTypes.OBJECT));
return new JClass[0];
}
} else {
//--no type we must be facing an XML schema group
//--MODEL GROUP OR GROUP
createForSingleGroup = processSchemaGroup(component, state, classInfo);
}
//6--createGroupItem
if (createGroupItem) {
//-- create Bound Properties code
if (component.hasBoundProperties()) {
createPropertyChangeMethods(jClass);
}
sgState.bindReference(jClass, classInfo);
classes[1] = jClass;
//-- create main group class
String fname = component.getJavaClassName() + ITEM_NAME;
fname = getJavaNaming().toJavaMemberName(fname, false);
FieldInfo fInfo = null;
if (createForSingleGroup) {
//By default a nested group Item can occur only once
fInfo = getInfoFactory().createFieldInfo(new XSClass(jClass), fname);
} else {
fInfo = getInfoFactory().createCollection(
new XSClass(jClass), "_items", fname, getJavaNaming(), getConfig().useJava50());
}
fInfo.setContainer(true);
String newClassName = className.substring(0, className.length() - 4);
state = new FactoryState(newClassName, sgState, packageName, component);
classInfo = state.getClassInfo();
jClass = state.getJClass();
initialize(jClass);
if (type != null && type.isComplexType()) {
ComplexType complexType = (ComplexType) type;
if (complexType.isTopLevel() ^ creatingForAnElement) {
//process attributes and content type since it has not be performed before
Annotated saved = component.getAnnotated();
processAttributes(component.getBinding(), complexType, state);
component.setView(saved);
if (complexType.getContentType() == ContentType.mixed) {
FieldInfo fieldInfo = _memberFactory.createFieldInfoForContent(
component, new XSString(), getConfig().useJava50());
handleField(fieldInfo, state, component);
} else if (complexType.getContentType().getType() == ContentType.SIMPLE) {
SimpleContent simpleContent = (SimpleContent) complexType.getContentType();
SimpleType temp = simpleContent.getSimpleType();
XSType xsType = _typeConversion.convertType(
temp, packageName, getConfig().useJava50());
FieldInfo fieldInfo = _memberFactory.createFieldInfoForContent(
component, xsType, getConfig().useJava50());
handleField(fieldInfo, state, component);
temp = null;
} else {
// handle multi-valued choice group
xmlNature.setSchemaType(new XSClass(jClass));
}
}
}
classInfo.addFieldInfo(fInfo);
fInfo.getMemberAndAccessorFactory().createJavaField(fInfo, jClass);
fInfo.getMemberAndAccessorFactory().createAccessMethods(
fInfo, jClass, getConfig().useJava50(), getConfig().getAnnotationBuilders());
fInfo.getMemberAndAccessorFactory().generateInitializerCode(
fInfo, jClass.getConstructor(0).getSourceCode());
//-- name information
XMLInfoNature xmlInfoNature = new XMLInfoNature(classInfo);
xmlInfoNature.setNodeName(component.getXMLName());
//-- mark as a container
xmlInfoNature.setContainer(true);
// -- if we have a superclass, make sure that the actual type extends it, not the
// xxxItem holder class.
String actSuperClass = classes[1].getSuperClassQualifiedName();
jClass.setSuperClass(actSuperClass);