XSComplexTypeDefinition complexTypeDefi = Util.getComplexType(element.getTypeDefinition());
if (complexTypeDefi != null) {
List<XSAttributeUse> attributeUses = Util.objectListToList(complexTypeDefi.getAttributeUses());
for (XSAttributeUse attrUse : attributeUses) {
if (Util.isAttributeInitializationRequired(attrUse, dataProvider.getConfig())) {
XSSimpleTypeDefinition attrType = Util.getType(attrUse);
String codeTmpl = dataProvider.getConfig().getTemplateAttributeInitObject();
if (codeTmpl.contains(Constants.TMPL_ATTR_INIT_OBJECT)) {
boolean hasDefaultVal = Util.hasDefaultValue(attrUse);
String constraintValue = attrUse.getConstraintValue();
String attrValue = null;
if (codeTmpl.contains(Constants.TMPL_ATTR_INIT_OBJECT_SET_PRESENT)) {
String setPresent = null;
if (hasDefaultVal) {
setPresent = Constants.TMPL_INDENT + Constants.TMPL_ATTR_PRESENT_SET;
} else {
setPresent = "";
}
codeTmpl = codeTmpl.replace(Constants.TMPL_ATTR_INIT_OBJECT_SET_PRESENT, setPresent);
}
switch (Util.findVariety(attrType)) {
case UNION:
if (hasDefaultVal) {
String unionDefault = config.getTemplateAttributeInitObjectUnionDefault();
if (unionDefault.contains(Constants.TMPL_ATTR_INIT_OBJECT_DEFAULT_VAL)) {
unionDefault = unionDefault.replace(Constants.TMPL_ATTR_INIT_OBJECT_DEFAULT_VAL,
"\"" + constraintValue + "\"");
}
if (unionDefault.contains(Constants.TMPL_ATTR_INIT_OBJECT_DEFAULT_VAL_LENGTH)) {
unionDefault = unionDefault.replace(
Constants.TMPL_ATTR_INIT_OBJECT_DEFAULT_VAL_LENGTH, String
.valueOf(constraintValue.length()));
}
unionDefault = fillInUnionTemplate(unionDefault, attrType, dataProvider);
attrValue = config.getTemplateAttributeInitObjectUnionPreDefault();
attrValue += config.getTemplateAttributeInitObjectNoDefaultLHS() + unionDefault;
} else {
CppEnumNameCreator cppEnumOrUnionNameCreator = dataProvider.getEnumOrUnionNameCreator();
String unionType = cppEnumOrUnionNameCreator.createUnionTypeName(attrType, dataProvider
.getElementStack());
attrValue = config.getTemplateAttributeInitObjectNoDefaultLHS() + unionType + "();";
}
break;
case LIST:
if (hasDefaultVal) {
XSSimpleTypeDefinition itemType = attrType.getItemType();
String xsdType = Util.findXSDSimpleTypeString(itemType, config);
String listType;
if (Util.findVariety(itemType) == Variety.UNION) {
listType = dataProvider.getConfig()
.getTemplateUnionAttributeListTypeConversionNoItemValidation();