/**
* @param complexType the ComplexType to process
* @param state the FactoryState.
*/
private void processComplexType(final ComplexType complexType, final FactoryState state) {
XMLBindingComponent component = new XMLBindingComponent(getConfig(), getGroupNaming());
if (_binding != null) {
component.setBinding(_binding);
}
component.setView(complexType);
String typeName = component.getXMLName();
ClassInfo classInfo = state.getClassInfo();
XMLInfoNature xmlNature = new XMLInfoNature(classInfo);
xmlNature.setSchemaType(new XSClass(state.getJClass(), typeName));
/// I don't believe this should be here: kv 20030423
///classInfo.setNamespaceURI(component.getTargetNamespace());
//- Handle derived types
XMLType base = complexType.getBaseType();
//-- if the base is a complexType, we need to process it
if (base != null) {
if (base.isComplexType()) {
String baseClassName = null;
component.setView(base);
//-- Is this base type from the schema we are currently generating source for?
//////////////////////////////////////////////////////////
//NOTE: generate sources if the flag for generating sources
//from imported schemas in on
//////////////////////////////////////////////////////////
if (base.getSchema() == complexType.getSchema()) {
ClassInfo cInfo = state.resolve(base);
//--no classInfo yet so no source code available
//--for the base type: we need to generate it
if (cInfo == null) {
JClass[] classes = createSourceCode(component, state.getSGStateInfo());
cInfo = state.resolve(base);
baseClassName = classes[0].getName();
} else {
baseClassName = cInfo.getJClass().getName();
}
//set the base class
classInfo.setBaseClass(cInfo);
} else {
//-- Create qualified class name for a base type class
//-- from another package
baseClassName = component.getQualifiedName();
}
//-- Set super class
//-- and reset the view on the current ComplexType
component.setView(complexType);
// only set a super class name if the current complexType is not a
// restriction of a simpleContent (--> no object hierarchy, only content hierarchy)
/*
Note: There are times when a simpleContent restriction needs to
extend the hierarchy, such as a restriction of a restriction, so
I'm commenting out the following line for now. see bug 1875
for more details. If this causes any regressions we'll need to
find a more appropriate solution.
if (! ( complexType.isRestricted() && ((ComplexType)base).isSimpleContent() ) )
*/
state.getJClass().setSuperClass(baseClassName);
} //--complexType
//--if the content type is a simpleType create a field info for it.
if (complexType.getContentType().getType() == ContentType.SIMPLE) {
SimpleContent simpleContent = (SimpleContent) complexType.getContentType();
SimpleType temp = simpleContent.getSimpleType();
SimpleType baseType = (SimpleType) temp.getBaseType();
XSType xsType = _typeConversion.convertType(
temp, state.getPackageName(), getConfig().useJava50());
FieldInfo fieldInfo = null;
if ((baseType != null) && extendsSimpleType(state.getJClass(), baseType, state)) {
if (xsType.isEnumerated()) {
fieldInfo = _memberFactory.createFieldInfoForContent(
component, xsType, getConfig().useJava50());
fieldInfo.setBound(false);
handleField(fieldInfo, state, component);
//-- remove getter since we don't need to override the original getter
String mname = fieldInfo.getReadMethodName();
JClass jClass = state.getJClass();
JMethod method = jClass.getMethod(mname, 0);
jClass.removeMethod(method);
//-- update setter method
mname = fieldInfo.getWriteMethodName();
method = jClass.getMethod(mname, 0);
JSourceCode jsc = method.getSourceCode();
jsc.add("super.");
jsc.append(mname);
jsc.append("(this.");
jsc.append(fieldInfo.getName());
jsc.append(".toString());");
}
//-- else just use superclass setters/getters
//-- do nothing
} else {
//
while (temp.getBaseType() != null && !temp.isBuiltInType()) {
temp = (SimpleType) temp.getBaseType();
}
xsType = _typeConversion.convertType(
temp, state.getPackageName(), getConfig().useJava50());
fieldInfo = _memberFactory.createFieldInfoForContent(
component, xsType, getConfig().useJava50());
handleField(fieldInfo, state, component);
}
}
} //--base not null
//---------------------/
//- handle attributes -/
//- and mixed content -/
//---------------------/
if (!state.isCreateGroupItem()) {
processAttributes(component.getBinding(), complexType, state);
//--reset the view on the current ComplexType
component.setView(complexType);
if (complexType.getContentType() == ContentType.mixed) {
FieldInfo fieldInfo = _memberFactory.createFieldInfoForContent(
component, new XSString(), getConfig().useJava50());
handleField(fieldInfo, state, component);
}