} else {
classes = new JClass[1];
}
//3-- Create factoryState and chain it to sgState to prevent endless loop
FactoryState state =
new FactoryState(className, sgState, packageName, component);
state.setCreateGroupItem(createGroupItem);
if (sgState.getCurrentFactoryState() != null) {
state.setParent(sgState.getCurrentFactoryState());
}
sgState.setCurrentFactoryState(state);
//--Prevent endless loop
if (state.processed(component.getAnnotated())) {
return new JClass[0];
}
//-- Mark the enclosed annotated structure as processed in the
//-- current FactoryState for preventing endless loop.
state.markAsProcessed(component.getAnnotated());
//////////////////////////////////////////////////////
//NOTE: check that the component is not referring to
//an imported schema to prevent class creation
//////////////////////////////////////////////////////
//4-- intialization of the JClass
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