brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreatu...@apache.org
Subject [08/17] incubator-brooklyn git commit: changes to the camp builder to support pure-javac 1.7 compilation
Date Tue, 03 Feb 2015 11:41:39 GMT
changes to the camp builder to support pure-javac 1.7 compilation

the root cause was (from http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html):

> Non-static nested classes (inner classes) have access to other members of the enclosing
class, even if they are declared private. Static nested classes do not have access to other
members of the enclosing class.


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/8f55a6e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/8f55a6e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/8f55a6e3

Branch: refs/heads/master
Commit: 8f55a6e3fcbf9395efefb935dae4a6ccedf6c6fb
Parents: efdb672
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Thu Jan 29 13:16:46 2015 +0000
Committer: Andrea Turli <andrea.turli@gmail.com>
Committed: Tue Feb 3 11:25:07 2015 +0100

----------------------------------------------------------------------
 .../io/brooklyn/camp/spi/AbstractResource.java  | 47 +++++++++-----------
 .../brooklyn/camp/spi/ApplicationComponent.java | 31 ++++++-------
 .../camp/spi/ApplicationComponentTemplate.java  |  7 +--
 .../java/io/brooklyn/camp/spi/Assembly.java     | 33 +++++++-------
 .../io/brooklyn/camp/spi/AssemblyTemplate.java  | 38 ++++++++--------
 .../io/brooklyn/camp/spi/PlatformComponent.java | 33 +++++++-------
 .../camp/spi/PlatformComponentTemplate.java     |  7 +--
 .../brooklyn/camp/spi/PlatformRootSummary.java  |  7 +--
 8 files changed, 89 insertions(+), 114 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8f55a6e3/camp/camp-base/src/main/java/io/brooklyn/camp/spi/AbstractResource.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/AbstractResource.java b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/AbstractResource.java
index 036a8d6..5f04e20 100644
--- a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/AbstractResource.java
+++ b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/AbstractResource.java
@@ -129,7 +129,7 @@ public class AbstractResource {
     // builder
     @SuppressWarnings("rawtypes")
     public static Builder<? extends AbstractResource,? extends Builder> builder() {
-        return new AbstractResourceBuilder(CAMP_TYPE);
+        return new AbstractResource().new AbstractResourceBuilder(CAMP_TYPE);
     }
     
     /** Builder creates the instance up front to avoid repetition of fields in the builder;
@@ -137,59 +137,54 @@ public class AbstractResource {
      * so effectively immutable.
      * <p>
      * Similarly setters in the class are private so those objects are also typically effectively
immutable. */
-    public abstract static class Builder<T extends AbstractResource,U extends Builder<T,U>>
{
+    public abstract class Builder<T extends AbstractResource,U extends Builder<T,U>>
{
         
         private boolean built = false;
         private String type = null;
-        private T instance = null;
+        private boolean initialized = false;
         
         protected Builder(String type) {
             this.type = type;
         }
         
-        @SuppressWarnings("unchecked")
-        protected T createResource() {
-            return (T) new AbstractResource();
-        }
-        
-        protected synchronized T instance() {
+        protected final synchronized void check() {
             if (built) 
                 throw new IllegalStateException("Builder instance from "+this+" cannot be
access after build");
-            if (instance==null) {
-                instance = createResource();
+            if (!initialized) {
+                initialized = true;
                 initialize();
             }
-            return instance;
         }
 
         protected void initialize() {
             if (type!=null) type(type);
         }
-        
+
+        @SuppressWarnings("unchecked")
         public synchronized T build() {
-            T result = instance();
+            check();
             built = true;
-            return result;
+            return (T) AbstractResource.this;
         }
         
         @SuppressWarnings("unchecked")
         protected U thisBuilder() { return (U)this; }
         
-        public U type(String x) { instance().setType(x); return thisBuilder(); }
-        public U id(String x) { instance().setId(x); return thisBuilder(); }
-        public U name(String x) { instance().setName(x); return thisBuilder(); }
-        public U description(String x) { instance().setDescription(x); return thisBuilder();
}
-        public U created(Date x) { instance().setCreated(x); return thisBuilder(); }
-        public U tags(List<String> x) { instance().setTags(x); return thisBuilder();
}
-        public U representationSkew(RepresentationSkew x) { instance().setRepresentationSkew(x);
return thisBuilder(); }
-        public U customAttribute(String key, Object value) { instance().setCustomAttribute(key,
value); return thisBuilder(); }
-        public U sourceCode(String x) { instance().setSourceCode(x); return thisBuilder();
}
+        public U type(String x) { check(); AbstractResource.this.setType(x); return thisBuilder();
}
+        public U id(String x) { check(); AbstractResource.this.setId(x); return thisBuilder();
}
+        public U name(String x) { check(); AbstractResource.this.setName(x); return thisBuilder();
}
+        public U description(String x) { check(); AbstractResource.this.setDescription(x);
return thisBuilder(); }
+        public U created(Date x) { check(); AbstractResource.this.setCreated(x); return thisBuilder();
}
+        public U tags(List<String> x) { check(); AbstractResource.this.setTags(x);
return thisBuilder(); }
+        public U representationSkew(RepresentationSkew x) { check(); AbstractResource.this.setRepresentationSkew(x);
return thisBuilder(); }
+        public U customAttribute(String key, Object value) { check(); AbstractResource.this.setCustomAttribute(key,
value); return thisBuilder(); }
+        public U sourceCode(String x) { check(); AbstractResource.this.setSourceCode(x);
return thisBuilder(); }
 
 //        public String type() { return instance().type; }
     }
-
+    
     @VisibleForTesting
-    protected static class AbstractResourceBuilder extends Builder<AbstractResource,AbstractResourceBuilder>
{
+    protected class AbstractResourceBuilder extends Builder<AbstractResource,AbstractResourceBuilder>
{
         protected AbstractResourceBuilder(String type) {
             super(type);
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8f55a6e3/camp/camp-base/src/main/java/io/brooklyn/camp/spi/ApplicationComponent.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/ApplicationComponent.java b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/ApplicationComponent.java
index 2d70f9c..3e956a4 100644
--- a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/ApplicationComponent.java
+++ b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/ApplicationComponent.java
@@ -57,40 +57,37 @@ public class ApplicationComponent extends AbstractResource {
     // builder
     
     public static Builder<? extends ApplicationComponent> builder() {
-        return new Builder<ApplicationComponent>(CAMP_TYPE);
+        return new ApplicationComponent().new Builder<ApplicationComponent>(CAMP_TYPE);
     }
     
-    public static class Builder<T extends ApplicationComponent> extends AbstractResource.Builder<T,Builder<T>>
{
+    public class Builder<T extends ApplicationComponent> extends AbstractResource.Builder<T,Builder<T>>
{
         
         protected Builder(String type) { super(type); }
 
-        public Builder<T> applicationComponentTemplates(ResourceLookup<ApplicationComponent>
x) { instance().setApplicationComponents(x); return thisBuilder(); }
-        public Builder<T> platformComponentTemplates(ResourceLookup<PlatformComponent>
x) { instance().setPlatformComponents(x); return thisBuilder(); }
+        public Builder<T> applicationComponentTemplates(ResourceLookup<ApplicationComponent>
x) { ApplicationComponent.this.setApplicationComponents(x); return thisBuilder(); }
+        public Builder<T> platformComponentTemplates(ResourceLookup<PlatformComponent>
x) { ApplicationComponent.this.setPlatformComponents(x); return thisBuilder(); }
         
         public synchronized Builder<T> add(ApplicationComponent x) {
-            if (instance().applicationComponents==null) {
-                instance().applicationComponents = new BasicResourceLookup<ApplicationComponent>();
+            if (ApplicationComponent.this.applicationComponents==null) {
+                ApplicationComponent.this.applicationComponents = new BasicResourceLookup<ApplicationComponent>();
             }
-            if (!(instance().applicationComponents instanceof BasicResourceLookup)) {
-                throw new IllegalStateException("Cannot add to resource lookup "+instance().applicationComponents);
+            if (!(ApplicationComponent.this.applicationComponents instanceof BasicResourceLookup))
{
+                throw new IllegalStateException("Cannot add to resource lookup "+ApplicationComponent.this.applicationComponents);
             }
-            ((BasicResourceLookup<ApplicationComponent>)instance().applicationComponents).add(x);
+            ((BasicResourceLookup<ApplicationComponent>)ApplicationComponent.this.applicationComponents).add(x);
             return thisBuilder();
         }
         
         public synchronized Builder<T> add(PlatformComponent x) {
-            if (instance().platformComponents==null) {
-                instance().platformComponents = new BasicResourceLookup<PlatformComponent>();
+            if (ApplicationComponent.this.platformComponents==null) {
+                ApplicationComponent.this.platformComponents = new BasicResourceLookup<PlatformComponent>();
             }
-            if (!(instance().platformComponents instanceof BasicResourceLookup)) {
-                throw new IllegalStateException("Cannot add to resource lookup "+instance().platformComponents);
+            if (!(ApplicationComponent.this.platformComponents instanceof BasicResourceLookup))
{
+                throw new IllegalStateException("Cannot add to resource lookup "+ApplicationComponent.this.platformComponents);
             }
-            ((BasicResourceLookup<PlatformComponent>)instance().platformComponents).add(x);
+            ((BasicResourceLookup<PlatformComponent>)ApplicationComponent.this.platformComponents).add(x);
             return thisBuilder();
         }
-
-        @SuppressWarnings("unchecked")
-        protected T createResource() { return (T) new ApplicationComponent(); }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8f55a6e3/camp/camp-base/src/main/java/io/brooklyn/camp/spi/ApplicationComponentTemplate.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/ApplicationComponentTemplate.java
b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/ApplicationComponentTemplate.java
index 34d03f4..f3212c7 100644
--- a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/ApplicationComponentTemplate.java
+++ b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/ApplicationComponentTemplate.java
@@ -41,16 +41,13 @@ public class ApplicationComponentTemplate extends AbstractResource {
     // builder
     
     public static Builder<? extends ApplicationComponentTemplate> builder() {
-        return new Builder<ApplicationComponentTemplate>(CAMP_TYPE);
+        return new ApplicationComponentTemplate().new Builder<ApplicationComponentTemplate>(CAMP_TYPE);
     }
     
-    public static class Builder<T extends ApplicationComponentTemplate> extends AbstractResource.Builder<T,Builder<T>>
{
+    public class Builder<T extends ApplicationComponentTemplate> extends AbstractResource.Builder<T,Builder<T>>
{
         
         protected Builder(String type) { super(type); }
         
-        @SuppressWarnings("unchecked")
-        protected T createResource() { return (T) new ApplicationComponentTemplate(); }
-        
 //        public Builder<T> foo(String x) { instance().setFoo(x); return thisBuilder();
}
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8f55a6e3/camp/camp-base/src/main/java/io/brooklyn/camp/spi/Assembly.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/Assembly.java b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/Assembly.java
index 991f704..15cfd51 100644
--- a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/Assembly.java
+++ b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/Assembly.java
@@ -67,39 +67,36 @@ public class Assembly extends AbstractResource {
     // builder
     
     public static Builder<? extends Assembly> builder() {
-        return new Builder<Assembly>(CAMP_TYPE);
+        return new Assembly().new Builder<Assembly>(CAMP_TYPE);
     }
     
-    public static class Builder<T extends Assembly> extends AbstractResource.Builder<T,Builder<T>>
{
+    public class Builder<T extends Assembly> extends AbstractResource.Builder<T,Builder<T>>
{
         
         protected Builder(String type) { super(type); }
         
-        @SuppressWarnings("unchecked")
-        protected T createResource() { return (T) new Assembly(); }
-        
-        public Builder<T> assemblyTemplate(AssemblyTemplate x) { instance().setAssemblyTemplate(x);
return thisBuilder(); }
-        public Builder<T> applicationComponentTemplates(ResourceLookup<ApplicationComponent>
x) { instance().setApplicationComponents(x); return thisBuilder(); }
-        public Builder<T> platformComponentTemplates(ResourceLookup<PlatformComponent>
x) { instance().setPlatformComponents(x); return thisBuilder(); }
+        public Builder<T> assemblyTemplate(AssemblyTemplate x) { Assembly.this.setAssemblyTemplate(x);
return thisBuilder(); }
+        public Builder<T> applicationComponentTemplates(ResourceLookup<ApplicationComponent>
x) { Assembly.this.setApplicationComponents(x); return thisBuilder(); }
+        public Builder<T> platformComponentTemplates(ResourceLookup<PlatformComponent>
x) { Assembly.this.setPlatformComponents(x); return thisBuilder(); }
         
         public synchronized Builder<T> add(ApplicationComponent x) {
-            if (instance().applicationComponents==null) {
-                instance().applicationComponents = new BasicResourceLookup<ApplicationComponent>();
+            if (Assembly.this.applicationComponents==null) {
+                Assembly.this.applicationComponents = new BasicResourceLookup<ApplicationComponent>();
             }
-            if (!(instance().applicationComponents instanceof BasicResourceLookup)) {
-                throw new IllegalStateException("Cannot add to resource lookup "+instance().applicationComponents);
+            if (!(Assembly.this.applicationComponents instanceof BasicResourceLookup)) {
+                throw new IllegalStateException("Cannot add to resource lookup "+Assembly.this.applicationComponents);
             }
-            ((BasicResourceLookup<ApplicationComponent>)instance().applicationComponents).add(x);
+            ((BasicResourceLookup<ApplicationComponent>)Assembly.this.applicationComponents).add(x);
             return thisBuilder();
         }
         
         public synchronized Builder<T> add(PlatformComponent x) {
-            if (instance().platformComponents==null) {
-                instance().platformComponents = new BasicResourceLookup<PlatformComponent>();
+            if (Assembly.this.platformComponents==null) {
+                Assembly.this.platformComponents = new BasicResourceLookup<PlatformComponent>();
             }
-            if (!(instance().platformComponents instanceof BasicResourceLookup)) {
-                throw new IllegalStateException("Cannot add to resource lookup "+instance().platformComponents);
+            if (!(Assembly.this.platformComponents instanceof BasicResourceLookup)) {
+                throw new IllegalStateException("Cannot add to resource lookup "+Assembly.this.platformComponents);
             }
-            ((BasicResourceLookup<PlatformComponent>)instance().platformComponents).add(x);
+            ((BasicResourceLookup<PlatformComponent>)Assembly.this.platformComponents).add(x);
             return thisBuilder();
         }
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8f55a6e3/camp/camp-base/src/main/java/io/brooklyn/camp/spi/AssemblyTemplate.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/AssemblyTemplate.java b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/AssemblyTemplate.java
index c308b87..4779a1c 100644
--- a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/AssemblyTemplate.java
+++ b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/AssemblyTemplate.java
@@ -70,49 +70,47 @@ public class AssemblyTemplate extends AbstractResource {
     // builder
     
     public static Builder<? extends AssemblyTemplate> builder() {
-        return new Builder<AssemblyTemplate>(CAMP_TYPE);
+        return new AssemblyTemplate().new Builder<AssemblyTemplate>(CAMP_TYPE);
     }
     
-    public static class Builder<T extends AssemblyTemplate> extends AbstractResource.Builder<T,Builder<T>>
{
+    public class Builder<T extends AssemblyTemplate> extends AbstractResource.Builder<T,Builder<T>>
{
         
         protected Builder(String type) { super(type); }
         
-        @SuppressWarnings("unchecked")
-        protected T createResource() { return (T) new AssemblyTemplate(); }
-        
-        public Builder<T> instantiator(Class<? extends AssemblyTemplateInstantiator>
x) { instance().setInstantiator(x); return thisBuilder(); }
-        public Builder<T> applicationComponentTemplates(ResourceLookup<ApplicationComponentTemplate>
x) { instance().setApplicationComponentTemplates(x); return thisBuilder(); }
-        public Builder<T> platformComponentTemplates(ResourceLookup<PlatformComponentTemplate>
x) { instance().setPlatformComponentTemplates(x); return thisBuilder(); }
+        public Builder<T> instantiator(Class<? extends AssemblyTemplateInstantiator>
x) { AssemblyTemplate.this.setInstantiator(x); return thisBuilder(); }
+        public Builder<T> applicationComponentTemplates(ResourceLookup<ApplicationComponentTemplate>
x) { AssemblyTemplate.this.setApplicationComponentTemplates(x); return thisBuilder(); }
+        public Builder<T> platformComponentTemplates(ResourceLookup<PlatformComponentTemplate>
x) { AssemblyTemplate.this.setPlatformComponentTemplates(x); return thisBuilder(); }
 
         /** allows callers to see the partially formed instance when needed, for example
to query instantiators;
          *  could be replaced by specific methods as and when that is preferred */
-        public T peek() { return instance(); }
+        @SuppressWarnings("unchecked")
+        public T peek() { return (T) AssemblyTemplate.this; }
         
         public synchronized Builder<T> add(ApplicationComponentTemplate x) {
-            if (instance().applicationComponentTemplates==null) {
-                instance().applicationComponentTemplates = new BasicResourceLookup<ApplicationComponentTemplate>();
+            if (AssemblyTemplate.this.applicationComponentTemplates==null) {
+                AssemblyTemplate.this.applicationComponentTemplates = new BasicResourceLookup<ApplicationComponentTemplate>();
             }
-            if (!(instance().applicationComponentTemplates instanceof BasicResourceLookup))
{
-                throw new IllegalStateException("Cannot add to resource lookup "+instance().applicationComponentTemplates);
+            if (!(AssemblyTemplate.this.applicationComponentTemplates instanceof BasicResourceLookup))
{
+                throw new IllegalStateException("Cannot add to resource lookup "+AssemblyTemplate.this.applicationComponentTemplates);
             }
-            ((BasicResourceLookup<ApplicationComponentTemplate>)instance().applicationComponentTemplates).add(x);
+            ((BasicResourceLookup<ApplicationComponentTemplate>)AssemblyTemplate.this.applicationComponentTemplates).add(x);
             return thisBuilder();
         }
         
         public synchronized Builder<T> add(PlatformComponentTemplate x) {
-            if (instance().platformComponentTemplates==null) {
-                instance().platformComponentTemplates = new BasicResourceLookup<PlatformComponentTemplate>();
+            if (AssemblyTemplate.this.platformComponentTemplates==null) {
+                AssemblyTemplate.this.platformComponentTemplates = new BasicResourceLookup<PlatformComponentTemplate>();
             }
-            if (!(instance().platformComponentTemplates instanceof BasicResourceLookup))
{
-                throw new IllegalStateException("Cannot add to resource lookup "+instance().platformComponentTemplates);
+            if (!(AssemblyTemplate.this.platformComponentTemplates instanceof BasicResourceLookup))
{
+                throw new IllegalStateException("Cannot add to resource lookup "+AssemblyTemplate.this.platformComponentTemplates);
             }
-            ((BasicResourceLookup<PlatformComponentTemplate>)instance().platformComponentTemplates).add(x);
+            ((BasicResourceLookup<PlatformComponentTemplate>)AssemblyTemplate.this.platformComponentTemplates).add(x);
             return thisBuilder();
         }
         
         @Override
         public synchronized T build() {
-            Preconditions.checkNotNull(instance().instantiator);
+            Preconditions.checkNotNull(AssemblyTemplate.this.instantiator);
             return super.build();
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8f55a6e3/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformComponent.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformComponent.java b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformComponent.java
index 3e3363b..d531174 100644
--- a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformComponent.java
+++ b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformComponent.java
@@ -64,41 +64,38 @@ public class PlatformComponent extends AbstractResource {
     // builder
     
     public static Builder<? extends PlatformComponent> builder() {
-        return new Builder<PlatformComponent>(CAMP_TYPE);
+        return new PlatformComponent().new Builder<PlatformComponent>(CAMP_TYPE);
     }
     
-    public static class Builder<T extends PlatformComponent> extends AbstractResource.Builder<T,Builder<T>>
{
+    public class Builder<T extends PlatformComponent> extends AbstractResource.Builder<T,Builder<T>>
{
         
         protected Builder(String type) { super(type); }
         
-        public Builder<T> externalManagementUri(String x) { instance().setExternalManagementUri(x);
return thisBuilder(); }
-        public Builder<T> applicationComponentTemplates(ResourceLookup<ApplicationComponent>
x) { instance().setApplicationComponents(x); return thisBuilder(); }
-        public Builder<T> platformComponentTemplates(ResourceLookup<PlatformComponent>
x) { instance().setPlatformComponents(x); return thisBuilder(); }
+        public Builder<T> externalManagementUri(String x) { PlatformComponent.this.setExternalManagementUri(x);
return thisBuilder(); }
+        public Builder<T> applicationComponentTemplates(ResourceLookup<ApplicationComponent>
x) { PlatformComponent.this.setApplicationComponents(x); return thisBuilder(); }
+        public Builder<T> platformComponentTemplates(ResourceLookup<PlatformComponent>
x) { PlatformComponent.this.setPlatformComponents(x); return thisBuilder(); }
         
         public synchronized Builder<T> add(ApplicationComponent x) {
-            if (instance().applicationComponents==null) {
-                instance().applicationComponents = new BasicResourceLookup<ApplicationComponent>();
+            if (PlatformComponent.this.applicationComponents==null) {
+                PlatformComponent.this.applicationComponents = new BasicResourceLookup<ApplicationComponent>();
             }
-            if (!(instance().applicationComponents instanceof BasicResourceLookup)) {
-                throw new IllegalStateException("Cannot add to resource lookup "+instance().applicationComponents);
+            if (!(PlatformComponent.this.applicationComponents instanceof BasicResourceLookup))
{
+                throw new IllegalStateException("Cannot add to resource lookup "+PlatformComponent.this.applicationComponents);
             }
-            ((BasicResourceLookup<ApplicationComponent>)instance().applicationComponents).add(x);
+            ((BasicResourceLookup<ApplicationComponent>)PlatformComponent.this.applicationComponents).add(x);
             return thisBuilder();
         }
         
         public synchronized Builder<T> add(PlatformComponent x) {
-            if (instance().platformComponents==null) {
-                instance().platformComponents = new BasicResourceLookup<PlatformComponent>();
+            if (PlatformComponent.this.platformComponents==null) {
+                PlatformComponent.this.platformComponents = new BasicResourceLookup<PlatformComponent>();
             }
-            if (!(instance().platformComponents instanceof BasicResourceLookup)) {
-                throw new IllegalStateException("Cannot add to resource lookup "+instance().platformComponents);
+            if (!(PlatformComponent.this.platformComponents instanceof BasicResourceLookup))
{
+                throw new IllegalStateException("Cannot add to resource lookup "+PlatformComponent.this.platformComponents);
             }
-            ((BasicResourceLookup<PlatformComponent>)instance().platformComponents).add(x);
+            ((BasicResourceLookup<PlatformComponent>)PlatformComponent.this.platformComponents).add(x);
             return thisBuilder();
         }
-
-        @SuppressWarnings("unchecked")
-        protected T createResource() { return (T) new PlatformComponent(); }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8f55a6e3/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformComponentTemplate.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformComponentTemplate.java
b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformComponentTemplate.java
index 8cedcb4..7f93f34 100644
--- a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformComponentTemplate.java
+++ b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformComponentTemplate.java
@@ -39,16 +39,13 @@ public class PlatformComponentTemplate extends AbstractResource {
     // builder
     
     public static Builder<? extends PlatformComponentTemplate> builder() {
-        return new Builder<PlatformComponentTemplate>(CAMP_TYPE);
+        return new PlatformComponentTemplate().new Builder<PlatformComponentTemplate>(CAMP_TYPE);
     }
     
-    public static class Builder<T extends PlatformComponentTemplate> extends AbstractResource.Builder<T,Builder<T>>
{
+    public class Builder<T extends PlatformComponentTemplate> extends AbstractResource.Builder<T,Builder<T>>
{
         
         protected Builder(String type) { super(type); }
         
-        @SuppressWarnings("unchecked")
-        protected T createResource() { return (T) new PlatformComponentTemplate(); }
-        
 //        public Builder<T> foo(String x) { instance().setFoo(x); return thisBuilder();
}
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8f55a6e3/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformRootSummary.java
----------------------------------------------------------------------
diff --git a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformRootSummary.java b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformRootSummary.java
index ca6b433..eb34ff9 100644
--- a/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformRootSummary.java
+++ b/camp/camp-base/src/main/java/io/brooklyn/camp/spi/PlatformRootSummary.java
@@ -53,16 +53,13 @@ public class PlatformRootSummary extends AbstractResource {
     // builder
     
     public static Builder<? extends PlatformRootSummary> builder() {
-        return new Builder<PlatformRootSummary>(CAMP_TYPE);
+        return new PlatformRootSummary().new Builder<PlatformRootSummary>(CAMP_TYPE);
     }
     
-    public static class Builder<T extends PlatformRootSummary> extends AbstractResource.Builder<T,Builder<T>>
{
+    public class Builder<T extends PlatformRootSummary> extends AbstractResource.Builder<T,Builder<T>>
{
         
         protected Builder(String type) { super(type); }
         
-        @SuppressWarnings("unchecked")
-        protected T createResource() { return (T) new PlatformRootSummary(); }
-        
         protected void initialize() {
             super.initialize();
             // TODO a better way not to have an ID here (new subclass BasicIdentifiableResource
for other BasicResource instances)


Mime
View raw message