@@ -275,8 +275,8 @@ void printStaticTypeDeclaration(SchemaType sType, SchemaTypeSystem system) throw
275
275
276
276
277
277
emit (factoryName + "<" + fullName + "> Factory = new " + factoryName +
278
- "<>(" + sysName + ".TypeSystemHolder.typeSystem, \" " + ((SchemaTypeSystemImpl ) system ).handleForType (sType ) + "\" );"
279
- );
278
+ "<>(" + sysName + ".TypeSystemHolder.typeSystem, \" " + ((SchemaTypeSystemImpl ) system ).handleForType (sType ) + "\" );"
279
+ );
280
280
emit ("org.apache.xmlbeans.SchemaType type = Factory.getType();" );
281
281
emit ("" );
282
282
}
@@ -318,7 +318,7 @@ void printInnerType(SchemaType sType, SchemaTypeSystem system) throws IOExceptio
318
318
319
319
void printNestedInnerTypes (SchemaType sType , SchemaTypeSystem system ) throws IOException {
320
320
boolean redefinition = sType .getName () != null &&
321
- sType .getName ().equals (sType .getBaseType ().getName ());
321
+ sType .getName ().equals (sType .getBaseType ().getName ());
322
322
while (sType != null ) {
323
323
SchemaType [] anonTypes = sType .getAnonymousTypes ();
324
324
for (SchemaType anonType : anonTypes ) {
@@ -331,7 +331,7 @@ void printNestedInnerTypes(SchemaType sType, SchemaTypeSystem system) throws IOE
331
331
// For redefinition other than by extension for complex types, go ahead and print
332
332
// the anonymous types in the base
333
333
if (!redefinition ||
334
- (sType .getDerivationType () != SchemaType .DT_EXTENSION && !sType .isSimpleType ())) {
334
+ (sType .getDerivationType () != SchemaType .DT_EXTENSION && !sType .isSimpleType ())) {
335
335
break ;
336
336
}
337
337
sType = sType .getBaseType ();
@@ -424,7 +424,7 @@ private static SchemaTypeImpl getImpl(SchemaType sType) {
424
424
425
425
private void emitSpecializedAccessors (SchemaType sType ) throws IOException {
426
426
if (sType .getSimpleVariety () == SchemaType .ATOMIC &&
427
- sType .getPrimitiveType ().getBuiltinTypeCode () == SchemaType .BTC_DECIMAL ) {
427
+ sType .getPrimitiveType ().getBuiltinTypeCode () == SchemaType .BTC_DECIMAL ) {
428
428
int bits = sType .getDecimalSize ();
429
429
int parentBits = sType .getBaseType ().getDecimalSize ();
430
430
if (bits != parentBits || sType .getBaseType ().getFullJavaName () == null ) {
@@ -505,8 +505,8 @@ void printJavaDocBody(String doc) throws IOException{
505
505
// add some poor mans code injection protection
506
506
// this is not protecting against annotation based RCEs like CVE-2018-16621
507
507
String docClean = doc .trim ()
508
- .replace ("\t " , "" )
509
- .replace ("*/" , "* /" );
508
+ .replace ("\t " , "" )
509
+ .replace ("*/" , "* /" );
510
510
511
511
for (String s : docClean .split ("[\\ n\\ r]+" )) {
512
512
emit (" * " + s );
@@ -1077,9 +1077,9 @@ void printConstructor(SchemaType sType, String shortName) throws IOException {
1077
1077
emit ("public " + shortName + "(org.apache.xmlbeans.SchemaType sType) {" );
1078
1078
startBlock ();
1079
1079
emit ("super(sType" + (sType .getSimpleVariety () == SchemaType .NOT_SIMPLE ?
1080
- "" :
1081
- ", " + !sType .isSimpleType ()) +
1082
- ");" );
1080
+ "" :
1081
+ ", " + !sType .isSimpleType ()) +
1082
+ ");" );
1083
1083
endBlock ();
1084
1084
1085
1085
if (sType .getSimpleVariety () != SchemaType .NOT_SIMPLE ) {
@@ -1105,7 +1105,7 @@ void startClass(SchemaType sType, boolean isInner) throws IOException {
1105
1105
}
1106
1106
1107
1107
emit ("public " + (isInner ? "static " : "" ) + "class " + shortName +
1108
- " extends " + baseClass + " implements " + interfaces + " {" );
1108
+ " extends " + baseClass + " implements " + interfaces + " {" );
1109
1109
1110
1110
startBlock ();
1111
1111
@@ -1415,16 +1415,7 @@ void printJSetValue(int javaType, String safeVarName, SchemaTypeImpl stype) thro
1415
1415
emit (em .replace ("#VARNAME#" , safeVarName ) + ";" );
1416
1416
}
1417
1417
1418
- String getIdentifier (Map <QName , Integer > qnameMap , QName qName ) {
1419
- return "PROPERTY_QNAME[" + qnameMap .get (qName ) + "]" ;
1420
- }
1421
-
1422
- String getSetIdentifier (Map <QName , Integer > qnameMap , QName qName , Map <QName , Integer > qsetMap ) {
1423
- Integer ord = qsetMap .get (qName );
1424
- return ord == null ? getIdentifier (qnameMap , qName ) : "PROPERTY_QSET[" + ord + "]" ;
1425
- }
1426
-
1427
- void printStaticFields (SchemaProperty [] properties , Map <QName , Integer > qnameMap , Map <QName , Integer > qsetMap ) throws IOException {
1418
+ void printStaticFields (SchemaProperty [] properties , Map <SchemaProperty , Identifier > propMap ) throws IOException {
1428
1419
if (properties .length == 0 ) {
1429
1420
return ;
1430
1421
}
@@ -1435,7 +1426,7 @@ void printStaticFields(SchemaProperty[] properties, Map<QName, Integer> qnameMap
1435
1426
indent ();
1436
1427
for (SchemaProperty prop : properties ) {
1437
1428
final QName name = prop .getName ();
1438
- qnameMap .put (name , qnameMap .size ());
1429
+ propMap .put (prop , new Identifier ( propMap .size () ));
1439
1430
emit ("new QName(\" " + name .getNamespaceURI () + "\" , \" " + name .getLocalPart () + "\" )," );
1440
1431
countQSet = Math .max (countQSet , (prop .acceptedNames () == null ? 0 : prop .acceptedNames ().length ));
1441
1432
}
@@ -1446,10 +1437,10 @@ void printStaticFields(SchemaProperty[] properties, Map<QName, Integer> qnameMap
1446
1437
if (countQSet > 1 ) {
1447
1438
emit ("private static final QNameSet[] PROPERTY_QSET = {" );
1448
1439
for (SchemaProperty prop : properties ) {
1449
- final QName name = prop .getName ();
1450
1440
final QName [] qnames = prop .acceptedNames ();
1441
+ int index = 0 ;
1451
1442
if (qnames != null && qnames .length > 1 ) {
1452
- qsetMap . put ( name , qsetMap . size () );
1443
+ propMap . get ( prop ). setSetIndex ( index ++ );
1453
1444
emit ("QNameSet.forArray( new QName[] { " );
1454
1445
indent ();
1455
1446
for (QName qname : qnames ) {
@@ -1475,7 +1466,7 @@ void emitImplementationPostamble() throws IOException {
1475
1466
}
1476
1467
1477
1468
void emitAddTarget (String identifier , boolean isAttr , String xtype )
1478
- throws IOException {
1469
+ throws IOException {
1479
1470
if (isAttr ) {
1480
1471
emit ("target = (" + xtype + ")get_store().add_attribute_user(" + identifier + ");" );
1481
1472
} else {
@@ -1550,7 +1541,7 @@ void emitGetTarget(String setIdentifier,
1550
1541
String index ,
1551
1542
int nullBehaviour ,
1552
1543
String xtype )
1553
- throws IOException {
1544
+ throws IOException {
1554
1545
assert setIdentifier != null && identifier != null ;
1555
1546
1556
1547
emit (xtype + " target = null;" );
@@ -1587,7 +1578,7 @@ void emitGetTarget(String setIdentifier,
1587
1578
}
1588
1579
1589
1580
void printListGetterImpl (String propdesc , String propertyName , String wrappedType , boolean xmltype , boolean xget )
1590
- throws IOException {
1581
+ throws IOException {
1591
1582
Set <BeanMethod > bmList = (opt == null ) ? null : opt .getCompilePartialMethod ();
1592
1583
if (bmList != null && !bmList .contains (xget ? BeanMethod .XGET_LIST : BeanMethod .GET_LIST )) {
1593
1584
return ;
@@ -1638,11 +1629,11 @@ void printListGetterImpl(String propdesc, String propertyName, String wrappedTyp
1638
1629
endBlock ();
1639
1630
}
1640
1631
1641
- void printGetterImpls (SchemaProperty prop , Map <QName , Integer > qnameMap , Map < QName , Integer > qsetMap )
1642
- throws IOException {
1632
+ void printGetterImpls (SchemaProperty prop , Map <SchemaProperty , Identifier > propMap )
1633
+ throws IOException {
1643
1634
final QName qName = prop .getName ();
1644
- final String identifier = getIdentifier (qnameMap , qName );
1645
- final String setIdentifier = getSetIdentifier (qnameMap , qName , qsetMap );
1635
+ final String identifier = propMap . get ( prop ). getIdentifier ();
1636
+ final String setIdentifier = propMap . get ( prop ). getSetIdentifier ();
1646
1637
final boolean several = prop .extendsJavaArray ();
1647
1638
final boolean nillable = prop .hasNillable () != SchemaProperty .NEVER ;
1648
1639
final String type = javaTypeForProperty (prop );
@@ -1677,15 +1668,15 @@ void printGetterImpls(SchemaProperty prop, Map<QName, Integer> qnameMap, Map<QNa
1677
1668
emitGetTarget (setIdentifier , identifier , isAttr , "0" , NOTHING , jtargetType );
1678
1669
1679
1670
if (isAttr && (prop .hasDefault () == SchemaProperty .CONSISTENTLY ||
1680
- prop .hasFixed () == SchemaProperty .CONSISTENTLY )) {
1671
+ prop .hasFixed () == SchemaProperty .CONSISTENTLY )) {
1681
1672
emit ("if (target == null) {" );
1682
1673
startBlock ();
1683
1674
makeAttributeDefaultValue (jtargetType , prop , identifier );
1684
1675
endBlock ();
1685
1676
}
1686
1677
1687
1678
emit ("return (target == null) ? " + makeMissingValue (javaType ) +
1688
- " : " + printJGetValue (javaType , type , (SchemaTypeImpl ) prop .getType ()) + ";" );
1679
+ " : " + printJGetValue (javaType , type , (SchemaTypeImpl ) prop .getType ()) + ";" );
1689
1680
1690
1681
emitImplementationPostamble ();
1691
1682
@@ -1704,7 +1695,7 @@ void printGetterImpls(SchemaProperty prop, Map<QName, Integer> qnameMap, Map<QNa
1704
1695
emitGetTarget (setIdentifier , identifier , isAttr , "0" , NOTHING , xtype );
1705
1696
1706
1697
if (isAttr && (prop .hasDefault () == SchemaProperty .CONSISTENTLY ||
1707
- prop .hasFixed () == SchemaProperty .CONSISTENTLY )) {
1698
+ prop .hasFixed () == SchemaProperty .CONSISTENTLY )) {
1708
1699
emit ("if (target == null) {" );
1709
1700
startBlock ();
1710
1701
makeAttributeDefaultValue (xtype , prop , identifier );
@@ -1859,11 +1850,11 @@ void printGetterImpls(SchemaProperty prop, Map<QName, Integer> qnameMap, Map<QNa
1859
1850
}
1860
1851
}
1861
1852
1862
- void printSetterImpls (SchemaProperty prop , Map <QName , Integer > qnameMap , Map < QName , Integer > qsetMap , SchemaType sType )
1863
- throws IOException {
1853
+ void printSetterImpls (SchemaProperty prop , Map <SchemaProperty , Identifier > propMap , SchemaType sType )
1854
+ throws IOException {
1864
1855
final QName qName = prop .getName ();
1865
- final String identifier = getIdentifier (qnameMap , qName );
1866
- final String setIdentifier = getSetIdentifier (qnameMap , qName , qsetMap );
1856
+ final String identifier = propMap . get ( prop ). getIdentifier ();
1857
+ final String setIdentifier = propMap . get ( prop ). getSetIdentifier ();
1867
1858
final boolean several = prop .extendsJavaArray ();
1868
1859
final boolean nillable = prop .hasNillable () != SchemaProperty .NEVER ;
1869
1860
final String type = javaTypeForProperty (prop );
@@ -1895,7 +1886,7 @@ void printSetterImpls(SchemaProperty prop, Map<QName, Integer> qnameMap, Map<QNa
1895
1886
if (xmltype && !isSubstGroup && !isAttr ) {
1896
1887
emitPre (sType , PrePostExtension .OPERATION_SET , identifier , false , several ? "0" : "-1" );
1897
1888
emit ("generatedSetterHelperImpl(" + safeVarName + ", " + setIdentifier + ", 0, " +
1898
- "org.apache.xmlbeans.impl.values.XmlObjectBase.KIND_SETTERHELPER_SINGLETON);" );
1889
+ "org.apache.xmlbeans.impl.values.XmlObjectBase.KIND_SETTERHELPER_SINGLETON);" );
1899
1890
emitPost (sType , PrePostExtension .OPERATION_SET , identifier , false , several ? "0" : "-1" );
1900
1891
} else {
1901
1892
emitImplementationPreamble ();
@@ -2034,13 +2025,13 @@ void printSetterImpls(SchemaProperty prop, Map<QName, Integer> qnameMap, Map<QNa
2034
2025
emit ("org.apache.xmlbeans.SimpleValue[] dests = arraySetterHelper(" + safeVarName + "Array.length" + ", " + identifier + ");" );
2035
2026
emit ("for ( int i = 0 ; i < dests.length ; i++ ) {" );
2036
2027
emit (" " + getUserTypeStaticHandlerMethod (true , (SchemaTypeImpl ) prop .getType ())
2037
- + "(" + safeVarName + "Array[i], dests[i]);" );
2028
+ + "(" + safeVarName + "Array[i], dests[i]);" );
2038
2029
emit ("}" );
2039
2030
} else {
2040
2031
emit ("org.apache.xmlbeans.SimpleValue[] dests = arraySetterHelper(" + safeVarName + "Array.length" + ", " + identifier + ", " + setIdentifier + ");" );
2041
2032
emit ("for ( int i = 0 ; i < dests.length ; i++ ) {" );
2042
2033
emit (" " + getUserTypeStaticHandlerMethod (true , (SchemaTypeImpl ) prop .getType ())
2043
- + "(" + safeVarName + "Array[i], dests[i]);" );
2034
+ + "(" + safeVarName + "Array[i], dests[i]);" );
2044
2035
emit ("}" );
2045
2036
}
2046
2037
} else {
@@ -2067,7 +2058,7 @@ void printSetterImpls(SchemaProperty prop, Map<QName, Integer> qnameMap, Map<QNa
2067
2058
if (xmltype && !isSubstGroup ) {
2068
2059
emitPre (sType , PrePostExtension .OPERATION_SET , identifier , isAttr , "i" );
2069
2060
emit ("generatedSetterHelperImpl(" + safeVarName + ", " + setIdentifier + ", i, " +
2070
- "org.apache.xmlbeans.impl.values.XmlObjectBase.KIND_SETTERHELPER_ARRAYITEM);" );
2061
+ "org.apache.xmlbeans.impl.values.XmlObjectBase.KIND_SETTERHELPER_ARRAYITEM);" );
2071
2062
emitPost (sType , PrePostExtension .OPERATION_SET , identifier , isAttr , "i" );
2072
2063
} else {
2073
2064
emitImplementationPreamble ();
@@ -2143,7 +2134,7 @@ void printSetterImpls(SchemaProperty prop, Map<QName, Integer> qnameMap, Map<QNa
2143
2134
} else // This is a subst group case
2144
2135
{
2145
2136
emit ("(" + jtargetType + ")get_store().insert_element_user(" + setIdentifier + ", " +
2146
- identifier + ", i);" );
2137
+ identifier + ", i);" );
2147
2138
}
2148
2139
outdent ();
2149
2140
printJSetValue (javaType , safeVarName , (SchemaTypeImpl ) prop .getType ());
@@ -2184,7 +2175,7 @@ void printSetterImpls(SchemaProperty prop, Map<QName, Integer> qnameMap, Map<QNa
2184
2175
} else // This is a subst group case
2185
2176
{
2186
2177
emit ("target = (" + xtype + ")get_store().insert_element_user(" +
2187
- setIdentifier + ", " + identifier + ", i);" );
2178
+ setIdentifier + ", " + identifier + ", i);" );
2188
2179
}
2189
2180
emitPost (sType , PrePostExtension .OPERATION_INSERT , identifier , isAttr , "i" );
2190
2181
emit ("return target;" );
@@ -2264,7 +2255,7 @@ SchemaProperty[] getSchemaProperties(SchemaType sType) {
2264
2255
}
2265
2256
2266
2257
void printInnerTypeImpl (
2267
- SchemaType sType , SchemaTypeSystem system , boolean isInner ) throws IOException {
2258
+ SchemaType sType , SchemaTypeSystem system , boolean isInner ) throws IOException {
2268
2259
String shortName = sType .getShortJavaImplName ();
2269
2260
2270
2261
printInnerTypeJavaDoc (sType );
@@ -2277,15 +2268,14 @@ void printInnerTypeImpl(
2277
2268
2278
2269
if (!sType .isSimpleType ()) {
2279
2270
SchemaProperty [] properties = getSchemaProperties (sType );
2280
- Map <QName , Integer > qnameMap = new HashMap <>();
2281
- Map <QName , Integer > qsetMap = new HashMap <>();
2282
- printStaticFields (properties , qnameMap , qsetMap );
2271
+ Map <SchemaProperty , Identifier > propMap = new HashMap <>();
2272
+ printStaticFields (properties , propMap );
2283
2273
2284
2274
for (SchemaProperty prop : properties ) {
2285
- printGetterImpls (prop , qnameMap , qsetMap );
2275
+ printGetterImpls (prop , propMap );
2286
2276
2287
2277
if (!prop .isReadOnly ()) {
2288
- printSetterImpls (prop , qnameMap , qsetMap , sType );
2278
+ printSetterImpls (prop , propMap , sType );
2289
2279
}
2290
2280
}
2291
2281
}
@@ -2398,7 +2388,7 @@ void printInterfaceMethodImpl(String handler, InterfaceExtension.MethodSignature
2398
2388
2399
2389
void printNestedTypeImpls (SchemaType sType , SchemaTypeSystem system ) throws IOException {
2400
2390
boolean redefinition = sType .getName () != null &&
2401
- sType .getName ().equals (sType .getBaseType ().getName ());
2391
+ sType .getName ().equals (sType .getBaseType ().getName ());
2402
2392
while (sType != null ) {
2403
2393
SchemaType [] anonTypes = sType .getAnonymousTypes ();
2404
2394
for (SchemaType anonType : anonTypes ) {
@@ -2411,7 +2401,7 @@ void printNestedTypeImpls(SchemaType sType, SchemaTypeSystem system) throws IOEx
2411
2401
// For redefinition by extension, go ahead and print the anonymous
2412
2402
// types in the base
2413
2403
if (!redefinition ||
2414
- (sType .getDerivationType () != SchemaType .DT_EXTENSION && !sType .isSimpleType ())) {
2404
+ (sType .getDerivationType () != SchemaType .DT_EXTENSION && !sType .isSimpleType ())) {
2415
2405
break ;
2416
2406
}
2417
2407
sType = sType .getBaseType ();
@@ -2441,4 +2431,25 @@ public void printHolder(Writer writer, SchemaTypeSystem system, XmlOptions opt,
2441
2431
outdent ();
2442
2432
emit ("}" );
2443
2433
}
2434
+
2435
+ private static class Identifier {
2436
+ private final int getindex ;
2437
+ private Integer setindex = null ;
2438
+
2439
+ private Identifier (int index ) {
2440
+ this .getindex = index ;
2441
+ }
2442
+
2443
+ public String getIdentifier () {
2444
+ return "PROPERTY_QNAME[" + getindex + "]" ;
2445
+ }
2446
+
2447
+ public String getSetIdentifier () {
2448
+ return setindex == null ? getIdentifier () : "PROPERTY_QSET[" + setindex + "]" ;
2449
+ }
2450
+
2451
+ public void setSetIndex (int setindex ) {
2452
+ this .setindex = setindex ;
2453
+ }
2454
+ }
2444
2455
}
0 commit comments