Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes a serious problem in xmlbeans #10

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1415,16 +1415,7 @@ void printJSetValue(int javaType, String safeVarName, SchemaTypeImpl stype) thro
emit(em.replace("#VARNAME#", safeVarName) + ";");
}

String getIdentifier(Map<QName, Integer> qnameMap, QName qName) {
return "PROPERTY_QNAME[" + qnameMap.get(qName) + "]";
}

String getSetIdentifier(Map<QName, Integer> qnameMap, QName qName, Map<QName, Integer> qsetMap) {
Integer ord = qsetMap.get(qName);
return ord == null ? getIdentifier(qnameMap, qName) : "PROPERTY_QSET["+ ord + "]";
}

void printStaticFields(SchemaProperty[] properties, Map<QName, Integer> qnameMap, Map<QName, Integer> qsetMap) throws IOException {
void printStaticFields(SchemaProperty[] properties, Map<SchemaProperty, Identifier> propMap) throws IOException {
if (properties.length == 0) {
return;
}
Expand All @@ -1435,7 +1426,7 @@ void printStaticFields(SchemaProperty[] properties, Map<QName, Integer> qnameMap
indent();
for (SchemaProperty prop : properties) {
final QName name = prop.getName();
qnameMap.put(name, qnameMap.size());
propMap.put(prop, new Identifier(propMap.size()));
emit("new QName(\"" + name.getNamespaceURI() + "\", \"" + name.getLocalPart() + "\"),");
countQSet = Math.max(countQSet, (prop.acceptedNames() == null ? 0 : prop.acceptedNames().length));
}
Expand All @@ -1446,10 +1437,10 @@ void printStaticFields(SchemaProperty[] properties, Map<QName, Integer> qnameMap
if (countQSet > 1) {
emit("private static final QNameSet[] PROPERTY_QSET = {");
for (SchemaProperty prop : properties) {
final QName name = prop.getName();
final QName[] qnames = prop.acceptedNames();
int index = 0;
if (qnames != null && qnames.length > 1) {
qsetMap.put(name, qsetMap.size());
propMap.get(prop).setSetIndex(index++);
emit("QNameSet.forArray( new QName[] { ");
indent();
for (QName qname : qnames) {
Expand Down Expand Up @@ -1638,11 +1629,11 @@ void printListGetterImpl(String propdesc, String propertyName, String wrappedTyp
endBlock();
}

void printGetterImpls(SchemaProperty prop, Map<QName, Integer> qnameMap, Map<QName, Integer> qsetMap)
void printGetterImpls(SchemaProperty prop, Map<SchemaProperty, Identifier> propMap)
throws IOException {
final QName qName = prop.getName();
final String identifier = getIdentifier(qnameMap, qName);
final String setIdentifier = getSetIdentifier(qnameMap, qName, qsetMap);
final String identifier = propMap.get(prop).getIdentifier();
final String setIdentifier = propMap.get(prop).getSetIdentifier();
final boolean several = prop.extendsJavaArray();
final boolean nillable = prop.hasNillable() != SchemaProperty.NEVER;
final String type = javaTypeForProperty(prop);
Expand Down Expand Up @@ -1859,11 +1850,11 @@ void printGetterImpls(SchemaProperty prop, Map<QName, Integer> qnameMap, Map<QNa
}
}

void printSetterImpls(SchemaProperty prop, Map<QName, Integer> qnameMap, Map<QName, Integer> qsetMap, SchemaType sType)
void printSetterImpls(SchemaProperty prop, Map<SchemaProperty, Identifier> propMap, SchemaType sType)
throws IOException {
final QName qName = prop.getName();
final String identifier = getIdentifier(qnameMap, qName);
final String setIdentifier = getSetIdentifier(qnameMap, qName, qsetMap);
final String identifier = propMap.get(prop).getIdentifier();
final String setIdentifier = propMap.get(prop).getSetIdentifier();
final boolean several = prop.extendsJavaArray();
final boolean nillable = prop.hasNillable() != SchemaProperty.NEVER;
final String type = javaTypeForProperty(prop);
Expand Down Expand Up @@ -2277,15 +2268,14 @@ void printInnerTypeImpl(

if (!sType.isSimpleType()) {
SchemaProperty[] properties = getSchemaProperties(sType);
Map<QName, Integer> qnameMap = new HashMap<>();
Map<QName, Integer> qsetMap = new HashMap<>();
printStaticFields(properties, qnameMap, qsetMap);
Map<SchemaProperty, Identifier> propMap = new HashMap<>();
printStaticFields(properties, propMap);

for (SchemaProperty prop : properties) {
printGetterImpls(prop, qnameMap, qsetMap);
printGetterImpls(prop, propMap);

if (!prop.isReadOnly()) {
printSetterImpls(prop, qnameMap, qsetMap, sType);
printSetterImpls(prop, propMap, sType);
}
}
}
Expand Down Expand Up @@ -2441,4 +2431,25 @@ public void printHolder(Writer writer, SchemaTypeSystem system, XmlOptions opt,
outdent();
emit("}");
}

private static class Identifier {
private final int getindex;
private Integer setindex = null;

private Identifier(int index) {
this.getindex = index;
}

public String getIdentifier() {
return "PROPERTY_QNAME[" + getindex + "]";
}

public String getSetIdentifier() {
return setindex == null ? getIdentifier() : "PROPERTY_QSET["+ setindex + "]";
}

public void setSetIndex(int setindex) {
this.setindex = setindex;
}
}
}