This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
The following commit(s) were added to refs/heads/master by this push:
new 351e1d0639 remove unnecessary template model wrapping
351e1d0639 is described below
commit 351e1d06390cb5c7ac211ed55a6740f5ea180587
Author: Alex Heneveld <[email protected]>
AuthorDate: Thu Apr 11 10:52:19 2024 +0100
remove unnecessary template model wrapping
as it confuses some unwrapping, causing surprising lookups and errors
---
.../brooklyn/util/core/text/TemplateProcessor.java | 22 ++++------------------
1 file changed, 4 insertions(+), 18 deletions(-)
diff --git
a/core/src/main/java/org/apache/brooklyn/util/core/text/TemplateProcessor.java
b/core/src/main/java/org/apache/brooklyn/util/core/text/TemplateProcessor.java
index 3777c322f4..b620ca11ef 100644
---
a/core/src/main/java/org/apache/brooklyn/util/core/text/TemplateProcessor.java
+++
b/core/src/main/java/org/apache/brooklyn/util/core/text/TemplateProcessor.java
@@ -99,6 +99,7 @@ public class TemplateProcessor {
static CrossTaskThreadLocalStack<Boolean> IS_FOR_WORKFLOW = new
CrossTaskThreadLocalStack<>();
public interface UnwrappableTemplateModel {
+ // could make sense to distinguish 'unwrappable as result' from
'unwrappable for alternative lookup'
Maybe<Object> unwrap();
}
@@ -441,7 +442,7 @@ public class TemplateProcessor {
* Freemarker will only do this when in inside bracket notation in an
outer map, as in <code>${outer['a.b.']}</code>;
* as a result this is intended only for use by {@link
EntityAndMapTemplateModel} where
* a caller has used bracked notation, as in
<code>${mgmt['key.subkey']}</code>. */
- protected static final class EntityConfigTemplateModel implements
TemplateHashModel, UnwrappableTemplateModel {
+ protected static final class EntityConfigTemplateModel implements
TemplateHashModel {
protected final EntityInternal entity;
protected final ManagementContext mgmt;
@@ -450,11 +451,6 @@ public class TemplateProcessor {
this.mgmt = entity.getManagementContext();
}
- @Override
- public Maybe<Object> unwrap() {
- return Maybe.of(entity);
- }
-
@Override
public boolean isEmpty() { return false; }
@@ -524,7 +520,7 @@ public class TemplateProcessor {
* Freemarker will only do this when in inside bracket notation in an
outer map, as in <code>${outer['a.b.']}</code>;
* as a result this is intended only for use by {@link
LocationAndMapTemplateModel} where
* a caller has used bracked notation, as in
<code>${mgmt['key.subkey']}</code>. */
- protected static final class LocationConfigTemplateModel implements
TemplateHashModel, UnwrappableTemplateModel {
+ protected static final class LocationConfigTemplateModel implements
TemplateHashModel {
protected final LocationInternal location;
protected final ManagementContext mgmt;
@@ -533,11 +529,6 @@ public class TemplateProcessor {
this.mgmt = location.getManagementContext();
}
- @Override
- public Maybe<Object> unwrap() {
- return Maybe.of(location);
- }
-
@Override
public boolean isEmpty() { return false; }
@@ -597,15 +588,10 @@ public class TemplateProcessor {
throw new TemplateModelException(msg+":
"+Exceptions.collapseText(cause), cause);
}
- protected final static class EntityAttributeTemplateModel implements
TemplateHashModel, UnwrappableTemplateModel {
+ protected final static class EntityAttributeTemplateModel implements
TemplateHashModel {
protected final EntityInternal entity;
private final SensorResolutionMode mode;
- @Override
- public Maybe<Object> unwrap() {
- return Maybe.of(entity);
- }
-
enum SensorResolutionMode { SENSOR_DEFINITION,
ATTRIBUTE_VALUE,
ATTRIBUTE_WHEN_READY_FOR_TEMPLATES,