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

WFCORE-6779 Replace PersistentResourceXMLDescription with more robust API #6261

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/dep-diff-pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 11
java-version: 17

# Run the caching against the base version only
- name: Cache local Maven repository
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Building

Prerequisites:

* JDK 11 or newer - check `java -version`
* JDK 17 or newer - check `java -version`
* Maven 3.6.0 or newer - check `mvn -v`

To build with your own Maven installation:
Expand Down Expand Up @@ -63,7 +63,7 @@ Contributing
Using Eclipse
-------------
1. Install the latest version of Eclipse.
2. Make sure Xmx in Eclipse.ini is at least 1280M, and it's using java 11
2. Make sure Xmx in Eclipse.ini is at least 1280M, and it's using java 17
3. Launch Eclipse and install the m2e plugin, make sure it uses your repo configs
(get it from: https://www.eclipse.org/m2e/
or install "Maven Integration for Eclipse" from the Eclipse Marketplace).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@


import java.util.Collections;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.jboss.as.controller.operations.validation.ParameterValidator;
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.as.controller.xml.XMLCardinality;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLExtendedStreamReader;

Expand Down Expand Up @@ -96,6 +98,15 @@ public String getXmlName(final AttributeDefinition attribute){
return attribute.getXmlName();
}

/**
* Returns the cardinality of the XML particle for the specified attribute.
* @param attribute an attribute definition
* @return the cardinality of the XML particle for the specified attribute.
*/
public XMLCardinality getCardinality(AttributeDefinition attribute) {
return this.isParseAsElement() ? (attribute.isNillable() ? XMLCardinality.Single.OPTIONAL : XMLCardinality.Single.REQUIRED) : XMLCardinality.NONE;
}

public static final AttributeParser SIMPLE = new AttributeParser() {
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.xml.stream.XMLStreamException;

import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.as.controller.xml.XMLCardinality;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLExtendedStreamReader;

Expand Down Expand Up @@ -95,39 +96,35 @@ public void parseElement(AttributeDefinition attribute, XMLExtendedStreamReader
assert attribute instanceof MapAttributeDefinition;
MapAttributeDefinition mapAttribute = (MapAttributeDefinition) attribute;

operation.get(attribute.getName()).setEmptyObject();//create empty attribute to address WFCORE-1448
if (!operation.hasDefined(attribute.getName())) {
// Create empty attribute to address WFCORE-1448
operation.get(attribute.getName()).setEmptyObject();
}
if (wrapElement) {
if (!reader.getLocalName().equals(wrapper)) {
throw ParseUtils.unexpectedElement(reader, Collections.singleton(wrapper));
} else {
// allow empty properties list
if (reader.nextTag() == END_ELEMENT) {
return;
}
}
}

do {
if (elementName.equals(reader.getLocalName())) {
//real parsing happens
parseSingleElement(mapAttribute, reader, operation);
} else {
throw ParseUtils.unexpectedElement(reader, Collections.singleton(elementName));
while (reader.hasNext() && (reader.nextTag() != END_ELEMENT)) {
this.readElement(mapAttribute, reader, operation);
}
} else {
this.readElement(mapAttribute, reader, operation);
}
}

} while (reader.hasNext() && reader.nextTag() != END_ELEMENT && reader.getLocalName().equals(elementName));

if (wrapElement) {
// To exit the do loop either we hit an END_ELEMENT or a START_ELEMENT not for 'elementName'
// The latter means a bad document
if (reader.getEventType() != END_ELEMENT) {
throw ParseUtils.unexpectedElement(reader, Collections.singleton(elementName));
}
private void readElement(MapAttributeDefinition attribute, XMLExtendedStreamReader reader, ModelNode operation) throws XMLStreamException {
if (!reader.getLocalName().equals(this.elementName)) {
throw ParseUtils.unexpectedElement(reader, Collections.singleton(this.elementName));
}
this.parseSingleElement(attribute, reader, operation);
}

public abstract void parseSingleElement(MapAttributeDefinition attribute, XMLExtendedStreamReader reader, ModelNode operation) throws XMLStreamException;

@Override
public XMLCardinality getCardinality(AttributeDefinition attribute) {
return (this.wrapperElement != null) ? (attribute.isNillable() ? XMLCardinality.Single.OPTIONAL : XMLCardinality.Single.REQUIRED) : (attribute.isNillable() ? XMLCardinality.Unbounded.OPTIONAL : XMLCardinality.Unbounded.REQUIRED);
}
}


Expand Down Expand Up @@ -192,7 +189,6 @@ public void parseSingleElement(MapAttributeDefinition attribute, XMLExtendedStre
String key = reader.getAttributeValue(null, keyAttributeName);
ModelNode op = operation.get(attribute.getName(), key);
parseEmbeddedElement(objectType, reader, op, keyAttributeName);
ParseUtils.requireNoContent(reader);
}
}

Expand All @@ -218,9 +214,6 @@ public void parseElement(AttributeDefinition attribute, XMLExtendedStreamReader
} else {
throw ParseUtils.unexpectedElement(reader, Collections.singleton(attribute.getXmlName()));
}
if (!reader.isEndElement()) {
ParseUtils.requireNoContent(reader);
}
}

static void parseEmbeddedElement(ObjectTypeAttributeDefinition attribute, XMLExtendedStreamReader reader, ModelNode op, String... additionalExpectedAttributes) throws XMLStreamException {
Expand Down Expand Up @@ -261,8 +254,9 @@ static void parseEmbeddedElement(ObjectTypeAttributeDefinition attribute, XMLExt
throw ParseUtils.unexpectedElement(reader, attributeElements.keySet());
}
}
} else {
ParseUtils.requireNoContent(reader);
}

}

}
Expand Down Expand Up @@ -297,9 +291,6 @@ public void parseElement(AttributeDefinition attribute, XMLExtendedStreamReader
} else {
throw ParseUtils.unexpectedElement(reader, Collections.singleton(objectType.getXmlName()));
}
if (!reader.isEndElement()) {
ParseUtils.requireNoContent(reader);
}
}
operation.get(attribute.getName()).set(listValue);
}
Expand Down Expand Up @@ -327,9 +318,11 @@ public void parseElement(AttributeDefinition attribute, XMLExtendedStreamReader
} else {
throw ParseUtils.unexpectedElement(reader, Collections.singleton(xmlName));
}
if (!reader.isEndElement()) {
ParseUtils.requireNoContent(reader);
}
}

@Override
public XMLCardinality getCardinality(AttributeDefinition attribute) {
return attribute.isNillable() ? XMLCardinality.Unbounded.OPTIONAL : XMLCardinality.Unbounded.REQUIRED;
}
}

Expand All @@ -348,6 +341,11 @@ public void parseElement(AttributeDefinition ad, XMLExtendedStreamReader reader,
addPermissionMapper.get(ad.getName()).add(name);
ParseUtils.requireNoContent(reader);
}

@Override
public XMLCardinality getCardinality(AttributeDefinition attribute) {
return attribute.isNillable() ? XMLCardinality.Unbounded.OPTIONAL : XMLCardinality.Unbounded.REQUIRED;
}
}

static AttributeParser getObjectMapAttributeParser(String keyElementName) {
Expand Down
Loading
Loading