From 7d50ae153886073e227b9a602cf90bf101df4bdb Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Wed, 31 Aug 2016 01:25:09 +0100 Subject: [PATCH] Adds deprecated decorate method to preserve backwards compatibility with BrooklynEntityDecorationResolver --- .../BrooklynEntityDecorationResolver.java | 64 ++++++++++++------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java index 9e6ed8cc2c..befe8756d8 100644 --- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java +++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java @@ -22,9 +22,9 @@ import java.util.Map; import java.util.Set; -import com.google.common.annotations.Beta; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import org.apache.brooklyn.api.entity.EntityInitializer; import org.apache.brooklyn.api.entity.EntitySpec; @@ -46,22 +46,28 @@ /** * Pattern for resolving "decorations" on service specs / entity specs, such as policies, enrichers, etc. + * * @since 0.7.0 */ -@Beta public abstract class BrooklynEntityDecorationResolver
{ public final BrooklynYamlTypeInstantiator.Factory instantiator; - + protected BrooklynEntityDecorationResolver(BrooklynYamlTypeInstantiator.Factory instantiator) { this.instantiator = instantiator; } - + + /** @deprected since 0.10.0 - use {@link #decorate(EntitySpec, ConfigBag, Set)} */ + @Deprecated + public final void decorate(EntitySpec entitySpec, ConfigBag attrs) { + decorate(entitySpec, attrs, ImmutableSet.of()); + } + public abstract void decorate(EntitySpec entitySpec, ConfigBag attrs, Set encounteredRegisteredTypeIds); protected List buildListOfTheseDecorationsFromEntityAttributes(ConfigBag attrs) { Object value = getDecorationAttributeJsonValue(attrs); - if (value==null) return MutableList.of(); + if (value==null) { return MutableList.of(); } if (value instanceof Iterable) { return buildListOfTheseDecorationsFromIterable((Iterable)value); } else { @@ -72,40 +78,47 @@ protected List buildListOfTheseDecorationsFromEntityAttributes(Con } protected Map checkIsMap(Object decorationJson) { - if (!(decorationJson instanceof Map)) + if (!(decorationJson instanceof Map)) { throw new IllegalArgumentException(getDecorationKind()+" value must be a Map, not " + (decorationJson==null ? null : decorationJson.getClass()) ); + } return (Map) decorationJson; } protected List
buildListOfTheseDecorationsFromIterable(Iterable value) { List
decorations = MutableList.of(); - for (Object decorationJson: value) + for (Object decorationJson : value) { addDecorationFromJsonMap(checkIsMap(decorationJson), decorations); + } return decorations; } protected abstract String getDecorationKind(); + protected abstract Object getDecorationAttributeJsonValue(ConfigBag attrs); - - /** creates and adds decorations from the given json to the given collection; - * default impl requires a map and calls {@link #addDecorationFromJsonMap(Map, List)} */ + + /** + * Creates and adds decorations from the given json to the given collection; + * default impl requires a map and calls {@link #addDecorationFromJsonMap(Map, List)} + */ protected void addDecorationFromJson(Object decorationJson, List
decorations) { addDecorationFromJsonMap(checkIsMap(decorationJson), decorations); } + protected abstract void addDecorationFromJsonMap(Map decorationJson, List
decorations); - public static class PolicySpecResolver extends BrooklynEntityDecorationResolver> { - + public PolicySpecResolver(BrooklynYamlTypeInstantiator.Factory loader) { super(loader); } - @Override protected String getDecorationKind() { return "Policy"; } + + @Override + protected String getDecorationKind() { return "Policy"; } @Override public void decorate(EntitySpec entitySpec, ConfigBag attrs, Set encounteredRegisteredTypeIds) { entitySpec.policySpecs(buildListOfTheseDecorationsFromEntityAttributes(attrs)); } - + @Override protected Object getDecorationAttributeJsonValue(ConfigBag attrs) { return attrs.getStringKey(BrooklynCampReservedKeys.BROOKLYN_POLICIES); @@ -117,7 +130,7 @@ protected void addDecorationFromJsonMap(Map decorationJson, List item = RegisteredTypes.tryValidate(mgmt.getTypeRegistry().get(policyType), RegisteredTypeLoadingContexts.spec(Policy.class)); PolicySpec spec; if (!item.isNull()) { @@ -128,21 +141,23 @@ protected void addDecorationFromJsonMap(Map decorationJson, List> { - + public EnricherSpecResolver(BrooklynYamlTypeInstantiator.Factory loader) { super(loader); } - @Override protected String getDecorationKind() { return "Enricher"; } + + @Override + protected String getDecorationKind() { return "Enricher"; } @Override public void decorate(EntitySpec entitySpec, ConfigBag attrs, Set encounteredRegisteredTypeIds) { entitySpec.enricherSpecs(buildListOfTheseDecorationsFromEntityAttributes(attrs)); } - + @Override protected Object getDecorationAttributeJsonValue(ConfigBag attrs) { return attrs.getStringKey(BrooklynCampReservedKeys.BROOKLYN_ENRICHERS); @@ -157,17 +172,19 @@ protected void addDecorationFromJsonMap(Map decorationJson, List { - + public InitializerResolver(BrooklynYamlTypeInstantiator.Factory loader) { super(loader); } - @Override protected String getDecorationKind() { return "Entity initializer"; } + + @Override + protected String getDecorationKind() { return "Entity initializer"; } @Override public void decorate(EntitySpec entitySpec, ConfigBag attrs, Set encounteredRegisteredTypeIds) { entitySpec.addInitializers(buildListOfTheseDecorationsFromEntityAttributes(attrs)); } - + @Override protected Object getDecorationAttributeJsonValue(ConfigBag attrs) { return attrs.getStringKey(BrooklynCampReservedKeys.BROOKLYN_INITIALIZERS); @@ -211,5 +228,4 @@ protected void addDecorationFromJsonMap(Map decorationJson, List