package brooklyn.entity.proxying;

import java.util.Collections;
import java.util.Map;

import brooklyn.config.ConfigKey;
import brooklyn.entity.Entity;
import brooklyn.util.MutableMap;

public class WrappingEntitySpec<T extends Entity> extends BasicEntitySpec<T, WrappingEntitySpec<T>> {

    private final EntitySpec<T> delegate;

    public static <T extends Entity> WrappingEntitySpec<T> newInstance(EntitySpec<T> delegate) {
        return new WrappingEntitySpec<T>(delegate);
    }

    public WrappingEntitySpec(EntitySpec<T> delegate) {
        super(delegate.getType());
        this.delegate = delegate;
    }
    
    @Override
    public Class<? extends T> getImplementation() {
        return (super.getImplementation() == null) ? delegate.getImplementation() : super.getImplementation();
    }
    
    @Override
    public Entity getParent() {
        return (super.getParent() == null) ? delegate.getParent() : super.getParent();
    }
    
    @Override
    public Map<String, ?> getFlags() {
        return Collections.unmodifiableMap(MutableMap.<String,Object>builder()
                .putAll(delegate.getFlags())
                .putAll(super.getFlags())
                .build());
    }
    
    public Map<ConfigKey<?>, Object> getConfig() {
        return Collections.unmodifiableMap(MutableMap.<ConfigKey<?>,Object>builder()
                .putAll(delegate.getConfig())
                .putAll(super.getConfig())
                .build());
    }
    
}

@@ -58,16 +58,39 @@
 ctions;%0A
+import java.util.List;%0A
 import j
@@ -103,16 +103,16 @@
 il.Map;%0A
-
 %0Aimport 
@@ -189,23 +189,103 @@
 lyn.
-util.MutableMap
+policy.Policy;%0Aimport brooklyn.util.MutableMap;%0A%0Aimport com.google.common.collect.ImmutableList
 ;%0A%0Ap
@@ -1059,32 +1059,423 @@
  %0A    @Override%0A
+    public String getDisplayName() %7B%0A        return (super.getDisplayName() == null) ? delegate.getDisplayName() : super.getDisplayName();%0A    %7D%0A%0A    @Override%0A    public List%3CPolicy%3E getPolicies() %7B%0A        return ImmutableList.%3CPolicy%3Ebuilder()%0A                .addAll(delegate.getPolicies())%0A                .addAll(super.getPolicies())%0A                .build();%0A    %7D%0A    %0A    @Override%0A
     public Map%3CS

Fix WrappingEntitySpec