creatingForAnElement =
(component.getAnnotated().getStructureType() == Structure.ELEMENT);
ComplexType complexType = (ComplexType)type;
if (complexType.isTopLevel() && creatingForAnElement) {
//--move the view and keep the structure
Annotated saved = component.getAnnotated();
String previousPackage = component.getJavaPackage();
XMLBindingComponent baseComponent = new XMLBindingComponent(_config);
baseComponent.setBinding(component.getBinding());
baseComponent.setView(complexType);
String baseClassName = null;
String basePackage = baseComponent.getJavaPackage();
//--if the base class is not in the same package
//--of the current class then we have to qualify the base
//--class
if (basePackage != null && !basePackage.equals(previousPackage)) {
baseClassName = baseComponent.getQualifiedName();
if (baseClassName.indexOf('.') == -1) {
//--be sure it is a valid className
baseClassName = JavaNaming.toJavaClassName(baseClassName);
}
} else {
baseClassName = baseComponent.getJavaClassName();
}
jClass.setSuperClass(baseClassName);
basePackage = null;
baseClassName = null;
component.setView(saved);
saved = null;
}
//generate class if the complexType is anonymous and we create classes
//for an element OR if the complexType is top-level and we create
//classes for it.
else if (complexType.isTopLevel() || creatingForAnElement) {
//-- check Group type
if (complexType.getParticleCount() == 1) {
Particle particle = complexType.getParticle(0);
if (particle.getStructureType() == Structure.GROUP) {
Group group = (Group) particle;
if (group.getOrder() == Order.choice) {
classInfo.getGroupInfo().setAsChoice();
}
}
}
Annotated saved = component.getAnnotated();
processComplexType(complexType, state);
component.setView(saved);
saved = null;
}
}
//--5b the type is a simpleType
else if (type.isSimpleType()) {
SimpleType simpleType = (SimpleType)type;
//-- handle our special case for enumerated types
if (simpleType.hasFacet(Facet.ENUMERATION)) {
//-- Don't create source code for simple types that
//-- don't belong in the elements target namespace
String tns = simpleType.getSchema().getTargetNamespace();
boolean create = false;
if (tns == null)
create = (component.getTargetNamespace() == null);
else
create = tns.equals(component.getTargetNamespace());
if (create) {
ClassInfo tmpInfo = sgState.resolve(simpleType);
JClass tmpClass = null;
if (tmpInfo != null) {
tmpClass = tmpInfo.getJClass();
}
else {
tmpClass = createSourceCode(simpleType, sgState);
}
classInfo.setSchemaType(new XSClass(tmpClass));
}
} else {
//////////////////////////////////////////////////////////
//NOTE: generate sources if the flag for generating sources
//from imported schemas is on
//////////////////////////////////////////////////////////
return new JClass[0];
}
}
//--5c the type is an anyType
else if (type.isAnyType()) {
//-- Do not create classes for AnyType
classInfo.setSchemaType(new XSClass(SGTypes.Object));
return new JClass[0];
}
}
//--no type we must be facing an XML schema group
else {
//--MODEL GROUP OR GROUP
try{
Group group = (Group)component.getAnnotated();
createForSingleGroup = (group.getMaxOccurs() == 1);
processContentModel(group, state);
component.setView(group);
//-- Check Group Type
Order order = group.getOrder();
if (order == Order.choice)
classInfo.getGroupInfo().setAsChoice();
else if (order == Order.seq)
classInfo.getGroupInfo().setAsSequence();
else
classInfo.getGroupInfo().setAsAll();
} catch (ClassCastException ce) {
//--Should not happen
throw new IllegalArgumentException("Illegal binding component:"+ce.getMessage());
}
}
//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 = JavaNaming.toJavaMemberName(fname, false);
FieldInfo fInfo = null;
if (createForSingleGroup) {
//By default a nested group Item can occur only once
fInfo = infoFactory.createFieldInfo(new XSClass(jClass),
fname);
} else {
fInfo = infoFactory.createCollection(new XSClass(jClass),
"_items", fname);
}
fInfo.setContainer(true);
className = className.substring(0,className.length()-4);
state = new FactoryState(className, sgState, packageName);
classInfo = state.classInfo;
jClass = state.jClass;
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(complexType, state);
component.setView(saved);
if (complexType.getContentType() == ContentType.mixed) {
FieldInfo fieldInfo = memberFactory.createFieldInfoForContent(new XSString());
handleField(fieldInfo, state);