Skip to content

Commit

Permalink
Fix custom named action property parsing (#1425)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 authored Nov 6, 2024
1 parent c38f894 commit 9cabbe2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions core/src/main/java/tc/oc/pgm/action/ActionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,27 @@ public ActionParser(MapFactory factory) {
this.methodParsers = MethodParsers.getMethodParsersForClass(getClass());
}

@SuppressWarnings("unchecked")
public <B extends Filterable<?>> Action<? super B> parseProperty(
Element el, @Nullable Class<B> bound) throws InvalidXMLException {
return parse(el, bound, true);
}

public <B extends Filterable<?>> Action<? super B> parse(Element el, @Nullable Class<B> bound)
throws InvalidXMLException {
return parse(el, bound, false);
}

@SuppressWarnings("unchecked")
private <B extends Filterable<?>> Action<? super B> parse(
Element el, @Nullable Class<B> bound, boolean property) throws InvalidXMLException {
String id = FeatureDefinitionContext.parseId(el);

Node node = new Node(el);
if (id != null && maybeReference(el)) {
if (id != null && maybeReference(el, property)) {
return parseReference(node, id, bound);
}

Action<? super B> result = parseDynamic(el, bound);
Action<? super B> result = property ? parseAction(el, bound) : parseDynamic(el, bound);
if (bound != null) validate(result, ActionScopeValidation.of(bound), node);
if (result instanceof ActionDefinition) {
if (XMLUtils.parseBoolean(Node.fromAttr(el, "expose"), false)) {
Expand All @@ -112,8 +122,8 @@ public Set<String> actionTypes() {
return methodParsers.keySet();
}

private boolean maybeReference(Element el) {
return "action".equals(el.getName()) && el.getChildren().isEmpty();
private boolean maybeReference(Element el, boolean property) {
return (property || "action".equals(el.getName())) && el.getChildren().isEmpty();
}

public <B> Action<? super B> parseReference(Node node, Class<B> bound)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/util/xml/XMLFluentParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public <T extends Filterable<?>> Builder.Generic<Action<? super T>> action(
protected Action<? super T> parse(Node node) throws InvalidXMLException {
return node.isAttribute()
? actions.parseReference(node, clazz)
: actions.parse(node.getElement(), clazz);
: actions.parseProperty(node.getElement(), clazz);
}
};
}
Expand Down

0 comments on commit 9cabbe2

Please sign in to comment.