Repository: brooklyn-server
Updated Branches:
  refs/heads/master 4ed0e6e7b -> 88192c1f1


Adds deprecated decorate method to preserve backwards compatibility with 
BrooklynEntityDecorationResolver


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/7d50ae15
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/7d50ae15
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/7d50ae15

Branch: refs/heads/master
Commit: 7d50ae153886073e227b9a602cf90bf101df4bdb
Parents: 9679a38
Author: Andrew Donald Kennedy <andrew.kenn...@cloudsoftcorp.com>
Authored: Wed Aug 31 01:25:09 2016 +0100
Committer: Andrew Donald Kennedy <andrew.kenn...@cloudsoftcorp.com>
Committed: Wed Aug 31 01:33:17 2016 +0100

----------------------------------------------------------------------
 .../BrooklynEntityDecorationResolver.java       | 64 ++++++++++++--------
 1 file changed, 40 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7d50ae15/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynEntityDecorationResolver.java
----------------------------------------------------------------------
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 9e6ed8c..befe875 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.List;
 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 @@ import org.apache.brooklyn.util.guava.Maybe;
 
 /**
  * Pattern for resolving "decorations" on service specs / entity specs, such 
as policies, enrichers, etc.
+ *
  * @since 0.7.0
  */
-@Beta
 public abstract class BrooklynEntityDecorationResolver<DT> {
 
     public final BrooklynYamlTypeInstantiator.Factory instantiator;
-    
+
     protected 
BrooklynEntityDecorationResolver(BrooklynYamlTypeInstantiator.Factory 
instantiator) {
         this.instantiator = instantiator;
     }
-    
+
+    /** @deprected since 0.10.0 - use {@link #decorate(EntitySpec<?>, 
ConfigBag, Set<String>)} */
+    @Deprecated
+    public final void decorate(EntitySpec<?> entitySpec, ConfigBag attrs) {
+        decorate(entitySpec, attrs, ImmutableSet.<String>of());
+    }
+
     public abstract void decorate(EntitySpec<?> entitySpec, ConfigBag attrs, 
Set<String> encounteredRegisteredTypeIds);
 
     protected List<? extends DT> 
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 @@ public abstract class BrooklynEntityDecorationResolver<DT> {
     }
 
     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<DT> buildListOfTheseDecorationsFromIterable(Iterable<?> 
value) {
         List<DT> 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<DT> 
decorations) {
         addDecorationFromJsonMap(checkIsMap(decorationJson), decorations);
     }
+
     protected abstract void addDecorationFromJsonMap(Map<?,?> decorationJson, 
List<DT> decorations);
-    
 
     public static class PolicySpecResolver extends 
BrooklynEntityDecorationResolver<PolicySpec<?>> {
-        
+
         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<String> encounteredRegisteredTypeIds) {
             
entitySpec.policySpecs(buildListOfTheseDecorationsFromEntityAttributes(attrs));
         }
-        
+
         @Override
         protected Object getDecorationAttributeJsonValue(ConfigBag attrs) {
             return 
attrs.getStringKey(BrooklynCampReservedKeys.BROOKLYN_POLICIES);
@@ -117,7 +130,7 @@ public abstract class BrooklynEntityDecorationResolver<DT> {
 
             String policyType = decoLoader.getTypeName().get();
             ManagementContext mgmt = 
instantiator.loader.getManagementContext();
-            
+
             Maybe<RegisteredType> item = 
RegisteredTypes.tryValidate(mgmt.getTypeRegistry().get(policyType), 
RegisteredTypeLoadingContexts.spec(Policy.class));
             PolicySpec<?> spec;
             if (!item.isNull()) {
@@ -128,21 +141,23 @@ public abstract class 
BrooklynEntityDecorationResolver<DT> {
                 spec = PolicySpec.create(type)
                         .parameters(BasicSpecParameter.fromClass(mgmt, type));
             }
-            spec.configure( decoLoader.getConfigMap() );
+            spec.configure(decoLoader.getConfigMap());
             decorations.add(spec);
         }
     }
 
     public static class EnricherSpecResolver extends 
BrooklynEntityDecorationResolver<EnricherSpec<?>> {
-        
+
         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<String> encounteredRegisteredTypeIds) {
             
entitySpec.enricherSpecs(buildListOfTheseDecorationsFromEntityAttributes(attrs));
         }
-        
+
         @Override
         protected Object getDecorationAttributeJsonValue(ConfigBag attrs) {
             return 
attrs.getStringKey(BrooklynCampReservedKeys.BROOKLYN_ENRICHERS);
@@ -157,17 +172,19 @@ public abstract class 
BrooklynEntityDecorationResolver<DT> {
                 
.parameters(BasicSpecParameter.fromClass(instantiator.loader.getManagementContext(),
 type)));
         }
     }
-    
+
     public static class InitializerResolver extends 
BrooklynEntityDecorationResolver<EntityInitializer> {
-        
+
         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<String> encounteredRegisteredTypeIds) {
             
entitySpec.addInitializers(buildListOfTheseDecorationsFromEntityAttributes(attrs));
         }
-        
+
         @Override
         protected Object getDecorationAttributeJsonValue(ConfigBag attrs) {
             return 
attrs.getStringKey(BrooklynCampReservedKeys.BROOKLYN_INITIALIZERS);
@@ -211,5 +228,4 @@ public abstract class BrooklynEntityDecorationResolver<DT> {
             throw new IllegalStateException("Not called");
         }
     }
-
 }

Reply via email to