private static void generateParseOnXmlAttributes ( BindTypeContext context , MethodSpec . Builder methodBuilder , BindEntity entity ) { BindTransform bindTransform ; int count = 0 ; // count property to manage { // for each elements for ( BindProperty property : entity . getCollection ( ) ) { if ( property . xmlInfo . xmlType != XmlType . ATTRIBUTE ) continue ; count ++ ; } } if ( count > 0 ) { // @formatter:off methodBuilder . addCode ( "\n// attributes \n" ) ; methodBuilder . addStatement ( "String attributeName = null" ) ; // methodBuilder.addStatement("String attributeValue = null"); methodBuilder . addStatement ( "int attributesCount = xmlParser.getAttributeCount();" ) ; methodBuilder . beginControlFlow ( "for (int attributeIndex = 0; attributeIndex < attributesCount; attributeIndex++)" ) ; methodBuilder . addStatement ( "attributeName = xmlParser.getAttributeName(attributeIndex)" ) ; // methodBuilder.addStatement("attributeValue = // $T.unescapeXml(xmlParser.getAttributeValue(attributeIndex))", // StringEscapeUtils.class); methodBuilder . beginControlFlow ( "switch(attributeName)$>" ) ; for ( BindProperty property : entity . getCollection ( ) ) { if ( property . xmlInfo . xmlType != XmlType . ATTRIBUTE ) continue ; methodBuilder . addCode ( "case $S:\n$>" , BindProperty . xmlName ( property ) ) ; bindTransform = BindTransformer . lookup ( property ) ; methodBuilder . addCode ( "// field $L (mapped by $S)\n" , property . getName ( ) , BindProperty . xmlName ( property ) ) ; bindTransform . generateParseOnXml ( context , methodBuilder , "xmlParser" , property . getPropertyType ( ) . getTypeName ( ) , "instance" , property ) ; methodBuilder . addStatement ( "$<break" ) ; } methodBuilder . addCode ( "default:\n$>" ) ; methodBuilder . addStatement ( "$<break$<" ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . endControlFlow ( ) ; // @formatter:on } else { methodBuilder . addCode ( "// No attributes found\n" ) ; } }
Generate parse on xml attributes .