brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [7/9] incubator-brooklyn git commit: more converting CatalogItem access to RegisteredType
Date Mon, 02 Nov 2015 16:43:04 GMT
more converting CatalogItem access to RegisteredType

use JavaCatalogToSpecTransformer to transform java types,
introduce RegisteredTypeConstraints,
start to clean up / migrate createSpec calls,
deprecated syntax updated


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

Branch: refs/heads/master
Commit: 50ebfafbc0e186c3ad65593504b7566014f240a3
Parents: dc968f9
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri Oct 30 13:38:33 2015 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Mon Nov 2 08:01:12 2015 +0000

----------------------------------------------------------------------
 .../brooklyn/api/catalog/BrooklynCatalog.java   |   4 -
 .../org/apache/brooklyn/api/entity/Entity.java  |   6 +
 .../internal/AbstractBrooklynObjectSpec.java    |  14 +-
 .../brooklyn/api/objs/BrooklynObjectType.java   |  30 +++-
 .../apache/brooklyn/api/objs/BrooklynType.java  |   3 +
 .../api/typereg/BrooklynTypeRegistry.java       |  23 ++-
 .../brooklyn/api/typereg/RegisteredType.java    |  10 ++
 .../api/typereg/RegisteredTypeConstraint.java   |  45 +++++
 .../catalog/internal/BasicBrooklynCatalog.java  |  80 ++++-----
 .../core/catalog/internal/CatalogUtils.java     |  47 ++++-
 .../internal/JavaCatalogToSpecTransformer.java  |  22 ++-
 .../brooklyn/core/entity/AbstractEntity.java    |  26 +++
 .../apache/brooklyn/core/entity/Entities.java   |  27 ++-
 .../core/entity/factory/ApplicationBuilder.java |   3 +-
 .../core/location/BasicLocationRegistry.java    |  37 ++--
 .../core/location/CatalogLocationResolver.java  |   6 +-
 .../core/mgmt/EntityManagementUtils.java        |  25 ++-
 .../OsgiBrooklynClassLoadingContext.java        |   9 +-
 .../internal/AbstractManagementContext.java     |   5 +-
 .../BrooklynMementoPersisterToObjectStore.java  |  10 +-
 .../core/mgmt/persist/XmlMementoSerializer.java |   3 +-
 .../mgmt/rebind/RebindContextLookupContext.java |   9 +-
 .../core/mgmt/rebind/RebindIteration.java       |  28 +--
 .../brooklyn/core/resolve/ResolveUtils.java     |  21 +--
 .../entity/CatalogEntitySpecResolver.java       |  60 +++----
 .../resolve/entity/JavaEntitySpecResolver.java  |   8 +
 .../core/typereg/BasicBrooklynTypeRegistry.java |  98 ++++++-----
 .../core/typereg/RegisteredTypeConstraints.java | 152 ++++++++++++++++
 .../core/typereg/RegisteredTypePredicates.java  | 105 ++++++-----
 .../brooklyn/core/typereg/RegisteredTypes.java  |  77 ++++++++-
 .../core/catalog/internal/CatalogTestUtils.java |  47 -----
 .../mgmt/osgi/OsgiVersionMoreEntityTest.java    |  89 +++++-----
 .../mgmt/persist/XmlMementoSerializerTest.java  |   6 +-
 .../rebind/ActivePartialRebindVersionTest.java  |  22 ++-
 .../core/mgmt/rebind/RebindCatalogItemTest.java |   6 +-
 .../core/mgmt/rebind/RebindTestFixture.java     |  20 +--
 .../typereg/RegisteredTypePredicatesTest.java   | 172 +++++++++++++++++++
 .../BrooklynComponentTemplateResolver.java      |  12 +-
 .../BrooklynEntityDecorationResolver.java       |   5 +-
 .../spi/creation/CampToSpecTransformer.java     |  13 +-
 .../camp/brooklyn/spi/creation/CampUtils.java   |   4 +-
 .../lookup/AbstractTemplateBrooklynLookup.java  |  14 +-
 .../lookup/AssemblyTemplateBrooklynLookup.java  |   3 +-
 ...PlatformComponentTemplateBrooklynLookup.java |   3 +-
 .../brooklyn/JavaWebAppsIntegrationTest.java    |   2 +-
 .../camp/brooklyn/PoliciesYamlTest.java         |  14 +-
 .../camp/brooklyn/TestEntityWithInitConfig.java |   3 +-
 .../TestSensorAndEffectorInitializer.java       |   1 -
 .../camp/brooklyn/WindowsYamlLiveTest.java      |   4 +-
 .../CatalogOsgiVersionMoreEntityTest.java       |  72 ++++----
 .../brooklyn/catalog/CatalogXmlOsgiTest.java    |  20 +--
 .../brooklyn/catalog/CatalogYamlCombiTest.java  |   6 +-
 .../brooklyn/catalog/CatalogYamlEntityTest.java |   6 +-
 .../catalog/CatalogYamlLocationTest.java        |   2 +-
 .../brooklyn/catalog/CatalogYamlPolicyTest.java |   8 +-
 .../brooklyn/catalog/CatalogYamlRebindTest.java |  33 ++--
 .../catalog/CatalogYamlTemplateTest.java        |  44 ++---
 .../catalog/CatalogYamlVersioningTest.java      |  58 ++++---
 .../brooklyn/test/lite/CampYamlLiteTest.java    |   4 +-
 .../apache/brooklyn/rest/BrooklynWebConfig.java |   2 +-
 .../resources/AbstractBrooklynRestResource.java |   1 -
 .../rest/resources/ApplicationResource.java     |  21 ++-
 .../rest/resources/CatalogResource.java         |  42 ++---
 .../rest/resources/EffectorResource.java        |  19 +-
 .../rest/resources/EntityConfigResource.java    |  17 +-
 .../brooklyn/rest/resources/EntityResource.java |  17 +-
 .../rest/resources/LocationResource.java        |   4 +-
 .../rest/resources/PolicyConfigResource.java    |   3 +-
 .../brooklyn/rest/resources/SensorResource.java |  22 +--
 .../brooklyn/rest/resources/ServerResource.java |  14 +-
 .../rest/transform/CatalogTransformer.java      |   1 +
 .../rest/transform/EffectorTransformer.java     |   3 +-
 .../rest/transform/EntityTransformer.java       |   3 +-
 .../rest/transform/PolicyTransformer.java       |   5 +-
 .../rest/util/BrooklynRestResourceUtils.java    |  94 +++++++---
 .../brooklyn/rest/domain/ApplicationTest.java   |   3 +-
 .../rest/resources/CatalogResetTest.java        |   7 +-
 .../rest/resources/CatalogResourceTest.java     |   8 +-
 .../brooklynnode/DeployBlueprintTest.java       |   3 +-
 .../rest/testing/mocks/CapitalizePolicy.java    |   1 +
 .../util/BrooklynRestResourceUtilsTest.java     |   4 -
 .../guava/IllegalStateExceptionSupplier.java    |  24 ++-
 82 files changed, 1257 insertions(+), 747 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java b/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
index da850d7..b47d4b1 100644
--- a/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
+++ b/api/src/main/java/org/apache/brooklyn/api/catalog/BrooklynCatalog.java
@@ -68,10 +68,6 @@ public interface BrooklynCatalog {
     /** creates a spec for the given catalog item, throwing exceptions if any problems */
     // TODO this should be cached on the item and renamed getSpec(...), else we re-create it too often (every time catalog is listed)
     <T, SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT createSpec(CatalogItem<T, SpecT> item);
-    
-    /** @deprecated since 0.7.0 use {@link #createSpec(CatalogItem)} */
-    // used in one place in BRRU with warnings added in 0.9.0. remove after 0.9. 
-    CatalogItem<?,?> getCatalogItemForType(String typeName);
 
     /**
      * Adds an item (represented in yaml) to the catalog.

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java b/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java
index 3bca701..14d3c23 100644
--- a/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java
+++ b/api/src/main/java/org/apache/brooklyn/api/entity/Entity.java
@@ -363,6 +363,9 @@ public interface Entity extends BrooklynObject {
          */
         Iterator<T> iterator();
         
+        int size();
+        boolean isEmpty();
+        
         /**
          * Adds an instance.
          */
@@ -432,5 +435,8 @@ public interface Entity extends BrooklynObject {
          */
         @Override
         Iterator<Group> iterator();
+        
+        int size();
+        boolean isEmpty();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java b/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
index 91aa869..7e8a022 100644
--- a/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
+++ b/api/src/main/java/org/apache/brooklyn/api/internal/AbstractBrooklynObjectSpec.java
@@ -29,7 +29,7 @@ import com.google.common.base.Objects;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 
-public abstract class AbstractBrooklynObjectSpec<T,K extends AbstractBrooklynObjectSpec<T,K>> implements Serializable {
+public abstract class AbstractBrooklynObjectSpec<T,SpecT extends AbstractBrooklynObjectSpec<T,SpecT>> implements Serializable {
 
     private static final long serialVersionUID = 3010955277740333030L;
     
@@ -45,8 +45,8 @@ public abstract class AbstractBrooklynObjectSpec<T,K extends AbstractBrooklynObj
     }
     
     @SuppressWarnings("unchecked")
-    protected K self() {
-        return (K) this;
+    protected SpecT self() {
+        return (SpecT) this;
     }
 
     @Override
@@ -56,23 +56,23 @@ public abstract class AbstractBrooklynObjectSpec<T,K extends AbstractBrooklynObj
 
     protected abstract void checkValidType(Class<? extends T> type);
     
-    public K displayName(String val) {
+    public SpecT displayName(String val) {
         displayName = val;
         return self();
     }
     
-    public K catalogItemId(String val) {
+    public SpecT catalogItemId(String val) {
         catalogItemId = val;
         return self();
     }
     
-    public K tag(Object tag) {
+    public SpecT tag(Object tag) {
         tags.add(tag);
         return self();
     }
 
     /** adds the given tags */
-    public K tags(Iterable<Object> tagsToAdd) {
+    public SpecT tags(Iterable<Object> tagsToAdd) {
         Iterables.addAll(this.tags, tagsToAdd);
         return self();
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynObjectType.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynObjectType.java b/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynObjectType.java
index f6cd057..e0ef84c 100644
--- a/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynObjectType.java
+++ b/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynObjectType.java
@@ -20,9 +20,14 @@ package org.apache.brooklyn.api.objs;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
 import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.policy.Policy;
+import org.apache.brooklyn.api.policy.PolicySpec;
 import org.apache.brooklyn.api.sensor.Enricher;
+import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.sensor.Feed;
 
 import com.google.common.annotations.Beta;
@@ -30,19 +35,22 @@ import com.google.common.base.CaseFormat;
 
 @Beta
 public enum BrooklynObjectType {
-    ENTITY(Entity.class, "entities"),
-    LOCATION(Location.class, "locations"),
-    POLICY(Policy.class, "policies"),
-    ENRICHER(Enricher.class, "enrichers"),
-    FEED(Feed.class, "feeds"),
-    CATALOG_ITEM(CatalogItem.class, "catalog"),
-    UNKNOWN(null, "unknown");
+    // these are correctly type-checked by i can't tell how to get java not to warn!
+    @SuppressWarnings("unchecked") ENTITY(Entity.class, EntitySpec.class, "entities"),
+    @SuppressWarnings("unchecked") LOCATION(Location.class, LocationSpec.class, "locations"),
+    @SuppressWarnings("unchecked") POLICY(Policy.class, PolicySpec.class, "policies"),
+    @SuppressWarnings("unchecked") ENRICHER(Enricher.class, EnricherSpec.class, "enrichers"),
+    FEED(Feed.class, null, "feeds"),
+    CATALOG_ITEM(CatalogItem.class, null, "catalog"),
+    UNKNOWN(null, null, "unknown");
     
-    private Class<? extends BrooklynObject> interfaceType;
+    private final Class<? extends BrooklynObject> interfaceType;
+    private final Class<? extends AbstractBrooklynObjectSpec<?,?>> specType;
     private final String subPathName;
     
-    BrooklynObjectType(Class<? extends BrooklynObject> interfaceType, String subPathName) {
+    <T extends BrooklynObject,K extends AbstractBrooklynObjectSpec<T,K>> BrooklynObjectType(Class<T> interfaceType, Class<K> specType, String subPathName) {
         this.interfaceType = interfaceType;
+        this.specType = specType;
         this.subPathName = subPathName;
     }
     public String toCamelCase() {
@@ -57,6 +65,10 @@ public enum BrooklynObjectType {
         return interfaceType;
     }
     
+    public Class<? extends AbstractBrooklynObjectSpec<?, ?>> getSpecType() {
+        return specType;
+    }
+    
     public static BrooklynObjectType of(BrooklynObject instance) {
         for (BrooklynObjectType t: values()) {
             if (t.getInterfaceType()!=null && t.getInterfaceType().isInstance(instance))

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynType.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynType.java b/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynType.java
index f16b1d9..72d0be9 100644
--- a/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynType.java
+++ b/api/src/main/java/org/apache/brooklyn/api/objs/BrooklynType.java
@@ -30,6 +30,9 @@ import org.apache.brooklyn.config.ConfigKey;
  * were added or removed on-the-fly then those changes will be included in subsequent
  * snapshots. Therefore instances of a given class could have different {@link BrooklynType}s.
  */
+// TODO rename as BrooklynObjectSignature or BrooklynObjectMetadata;
+// or (perhaps better and easier to retire deprecated usage, if that is required?)
+// introduce new mechanism for storing accessing this information
 public interface BrooklynType extends Serializable {
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java b/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
index 25f07ab..e13f2e6 100644
--- a/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
+++ b/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
@@ -42,14 +42,27 @@ public interface BrooklynTypeRegistry {
     Iterable<RegisteredType> getAll();
     Iterable<RegisteredType> getAll(Predicate<? super RegisteredType> alwaysTrue);
     
-    RegisteredType get(String symbolicNameWithOptionalVersion, @Nullable RegisteredTypeKind kind, @Nullable Class<?> requiredSupertype);
-    RegisteredType get(String symbolicName, String version, @Nullable RegisteredTypeKind kind, @Nullable Class<?> requiredSupertype);
+    /** @return The item matching the given given 
+     * {@link RegisteredType#getSymbolicName() symbolicName} 
+     * and optionally {@link RegisteredType#getVersion()},
+     * filtered for the optionally supplied {@link RegisteredTypeConstraint}, 
+     * taking the best version if the version is null or a default marker,
+     * returning null if no matches are found. */
+    RegisteredType get(String symbolicName, String version, @Nullable RegisteredTypeConstraint constraint);
+    /** as {@link #get(String, String, RegisteredTypeConstraint)} with no constraints */
     RegisteredType get(String symbolicName, String version);
+    /** as {@link #get(String, String, RegisteredTypeConstraint)} but allows <code>"name:version"</code> 
+     * (the {@link RegisteredType#getId()}) in addition to the unversioned name,
+     * using a default marker if no version can be inferred */
+    RegisteredType get(String symbolicNameWithOptionalVersion, @Nullable RegisteredTypeConstraint constraint);
+    /** as {@link #get(String, RegisteredTypeConstraint)} but with no constraints */
+    RegisteredType get(String symbolicNameWithOptionalVersion);
 
-    @SuppressWarnings("rawtypes")
-    <T extends AbstractBrooklynObjectSpec> T createSpec(RegisteredType type, @Nullable Class<T> specKind);
+    // NB the seemingly more correct generics <T,SpecT extends AbstractBrooklynObjectSpec<T,SpecT>> 
+    // cause compile errors, not in Eclipse, but in maven (?) 
+    <SpecT extends AbstractBrooklynObjectSpec<?,?>> SpecT createSpec(RegisteredType type, @Nullable RegisteredTypeConstraint optionalConstraint, Class<SpecT> optionalSpecSuperType);
     
     // TODO when we support beans
-//    <T> T createBean(RegisteredType type, Class<T> superType);
+//    <T> T createBean(RegisteredType type, @Nullable RegisteredTypeConstraint optionalConstraint, Class<T> optionalResultSuperType);
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java b/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
index 5158c34..6ffa09c 100644
--- a/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
+++ b/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
@@ -51,5 +51,15 @@ public interface RegisteredType extends Identifiable {
      * for instance because the YAML has not yet been parsed or OSGi bundles downloaded). 
      */
     Class<?> getJavaType();
+
+    /**
+     * @return True if the item has been deprecated (i.e. its use is discouraged)
+     */
+    boolean isDeprecated();
+    
+    /**
+     * @return True if the item has been disabled (i.e. its use is forbidden, except for pre-existing apps)
+     */
+    boolean isDisabled();
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredTypeConstraint.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredTypeConstraint.java b/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredTypeConstraint.java
new file mode 100644
index 0000000..b55d546
--- /dev/null
+++ b/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredTypeConstraint.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.api.typereg;
+
+import java.util.Set;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind;
+
+public interface RegisteredTypeConstraint {
+    
+    /** The kind required, if specified. */
+    @Nullable public RegisteredTypeKind getKind();
+    
+    /** A java super-type or interface that should be filtered for; 
+     * for specs, this refers to the target type, not the spec 
+     * (eg {@link Entity} not {@link EntitySpec}). 
+     * If nothing is specified, this returns {@link Object}'s class. */
+    @Nonnull public Class<?> getJavaSuperType();
+    
+    /** encountered types, so that during resolution, 
+     * if we have already attempted to resolve a given type,
+     * the instantiator can avoid recursive cycles */
+    public Set<String> getEncounteredTypes();
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index ce168b6..c176a42 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -25,6 +25,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
+import java.util.Set;
 
 import javax.annotation.Nullable;
 
@@ -39,11 +40,13 @@ import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.core.catalog.CatalogPredicates;
 import org.apache.brooklyn.core.catalog.internal.CatalogClasspathDo.CatalogScanningModes;
 import org.apache.brooklyn.core.location.BasicLocationRegistry;
-import org.apache.brooklyn.core.mgmt.EntityManagementUtils;
 import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContext;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
+import org.apache.brooklyn.core.plan.PlanToSpecFactory;
+import org.apache.brooklyn.core.plan.PlanToSpecTransformer;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.core.flags.TypeCoercions;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.guava.Maybe;
@@ -298,13 +301,37 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         if (loadedItem == null) throw new RuntimeException(item+" not in catalog; cannot create spec");
         if (loadedItem.getSpecType()==null) return null;
 
-        SpecT spec = EntityManagementUtils.createCatalogSpec(mgmt, loadedItem);
+        SpecT spec = internalCreateSpecWithTransformers(mgmt, loadedItem, MutableSet.<String>of());
         if (spec != null) {
             return spec;
         }
 
         throw new IllegalStateException("No known mechanism to create instance of "+item);
     }
+    
+    /** @deprecated since introduction in 0.9.0, only used for backwards compatibility, can be removed any time;
+     * uses the type-creation info on the item */
+    @Deprecated 
+    public static <T,SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT internalCreateSpecWithTransformers(ManagementContext mgmt, final CatalogItem<T, SpecT> item, final Set<String> encounteredTypes) {
+        // deprecated lookup
+        if (encounteredTypes.contains(item.getSymbolicName())) {
+            throw new IllegalStateException("Type being resolved '"+item.getSymbolicName()+"' has already been encountered in " + encounteredTypes + "; recursive cycle detected");
+        }
+        return PlanToSpecFactory.attemptWithLoaders(mgmt, new Function<PlanToSpecTransformer, SpecT>() {
+            @Override
+            public SpecT apply(PlanToSpecTransformer input) {
+                return input.createCatalogSpec(item, encounteredTypes);
+            }
+        }).get();
+    }
+
+    /**
+     * as internalCreateSpecFromItemWithTransformers, but marking contexts where the creation is being attempted
+     * @deprecated since introduction in 0.9.0, only used for backwards compatibility, can be removed any time */
+    @Deprecated
+    public static <T,SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT internalCreateSpecAttempting(ManagementContext mgmt, final CatalogItem<T, SpecT> item, final Set<String> encounteredTypes) {
+        return internalCreateSpecWithTransformers(mgmt, item, encounteredTypes);
+    }
 
     @Deprecated /** @deprecated since 0.7.0 only used by other deprecated items */ 
     private <T,SpecT> CatalogItemDtoAbstract<T,SpecT> getAbstractCatalogItem(CatalogItem<T,SpecT> item) {
@@ -620,7 +647,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         
         public PlanInterpreterGuessingType(@Nullable String id, Object item, String itemYaml, @Nullable CatalogItemType optionalCiType, 
                 Collection<CatalogBundle> libraryBundles, List<CatalogItemDtoAbstract<?,?>> itemsDefinedSoFar) {
-            // ID is useful to prevent recursive references (currently for entities only)
+            // ID is useful to prevent recursive references (possibly only supported for entities?)
             this.id = id;
             
             if (item instanceof String) {
@@ -717,7 +744,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
                     .libraries(libraryBundles)
                     .build();
                 @SuppressWarnings("unchecked")
-                Object spec = EntityManagementUtils.createCatalogSpec(mgmt, itemToAttempt);
+                Object spec = internalCreateSpecAttempting(mgmt, itemToAttempt, MutableSet.<String>of());
                 if (spec!=null) {
                     catalogItemType = candidateCiType;
                     planYaml = candidateYaml;
@@ -755,7 +782,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
                             .libraries(libraryBundles)
                             .build();
                     @SuppressWarnings("unchecked")
-                    Object cutdownSpec = EntityManagementUtils.createCatalogSpec(mgmt, itemToAttempt);
+                    Object cutdownSpec = internalCreateSpecAttempting(mgmt, itemToAttempt, MutableSet.<String>of());
                     if (cutdownSpec!=null) {
                         catalogItemType = candidateCiType;
                         planYaml = candidateYaml;
@@ -1027,47 +1054,4 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
             serializer = new CatalogXmlSerializer();
     }
 
-    @Override
-    @Deprecated
-    public CatalogItem<?,?> getCatalogItemForType(String typeName) {
-        final CatalogItem<?,?> resultI;
-        final BrooklynCatalog catalog = mgmt.getCatalog();
-        if (CatalogUtils.looksLikeVersionedId(typeName)) {
-            //All catalog identifiers of the form xxxx:yyyy are composed of symbolicName+version.
-            //No javaType is allowed as part of the identifier.
-            resultI = CatalogUtils.getCatalogItemOptionalVersion(mgmt, typeName);
-        } else {
-            //Usually for catalog items with javaType (that is items from catalog.xml)
-            //the symbolicName and javaType match because symbolicName (was ID)
-            //is not specified explicitly. But could be the case that there is an item
-            //whose symbolicName is explicitly set to be different from the javaType.
-            //Note that in the XML the attribute is called registeredTypeName.
-            Iterable<CatalogItem<Object,Object>> resultL = catalog.getCatalogItems(CatalogPredicates.javaType(Predicates.equalTo(typeName)));
-            if (!Iterables.isEmpty(resultL)) {
-                //Push newer versions in front of the list (not that there should
-                //be more than one considering the items are coming from catalog.xml).
-                resultI = sortVersionsDesc(resultL).iterator().next();
-                if (log.isDebugEnabled() && Iterables.size(resultL)>1) {
-                    log.debug("Found "+Iterables.size(resultL)+" matches in catalog for type "+typeName+"; returning the result with preferred version, "+resultI);
-                }
-            } else {
-                //As a last resort try searching for items with the same symbolicName supposedly
-                //different from the javaType.
-                resultI = catalog.getCatalogItem(typeName, BrooklynCatalog.DEFAULT_VERSION);
-                if (resultI != null) {
-                    if (resultI.getJavaType() == null) {
-                        //Catalog items scanned from the classpath (using reflection and annotations) now
-                        //get yaml spec rather than a java type. Can't use those when creating apps from
-                        //the legacy app spec format.
-                        log.warn("Unable to find catalog item for type "+typeName +
-                                ". There is an existing catalog item with ID " + resultI.getId() +
-                                " but it doesn't define a class type.");
-                        return null;
-                    }
-                }
-            }
-        }
-        return resultI;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
index 4561046..db4b72a 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
@@ -28,6 +28,7 @@ import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.objs.BrooklynObject;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
 import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
 import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.BrooklynLogging;
@@ -41,12 +42,14 @@ import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl.RebindTracker;
 import org.apache.brooklyn.core.objs.BrooklynObjectInternal;
+import org.apache.brooklyn.core.typereg.RegisteredTypeConstraints;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.time.Time;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.api.client.util.Preconditions;
 import com.google.common.annotations.Beta;
 import com.google.common.base.Joiner;
 import com.google.common.base.Stopwatch;
@@ -73,7 +76,7 @@ public class CatalogUtils {
         ManagementContext mgmt = ((EntityInternal)entity).getManagementContext();
         String catId = entity.getCatalogItemId();
         if (Strings.isBlank(catId)) return JavaBrooklynClassLoadingContext.create(mgmt);
-        CatalogItem<?, ?> cat = getCatalogItemOptionalVersion(mgmt, catId);
+        RegisteredType cat = mgmt.getTypeRegistry().get(catId, RegisteredTypeConstraints.spec(Entity.class));
         if (cat==null) {
             log.warn("Cannot load "+catId+" to get classloader for "+entity+"; will try with standard loader, but might fail subsequently");
             return JavaBrooklynClassLoadingContext.create(mgmt);
@@ -200,6 +203,7 @@ public class CatalogUtils {
     }
 
     /** @deprecated since 0.9.0 use {@link #getSymbolicNameFromVersionedId(String)} */
+    // all uses removed
     @Deprecated
     public static String getIdFromVersionedId(String versionedId) {
         return getSymbolicNameFromVersionedId(versionedId);
@@ -230,9 +234,8 @@ public class CatalogUtils {
         return id + VERSION_DELIMITER + version;
     }
 
-    //TODO Don't really like this, but it's better to have it here than on the interface to keep the API's 
-    //surface minimal. Could instead have the interface methods accept VerionedId object and have the helpers
-    //construct it as needed.
+    /** @deprecated since 0.9.0 use {@link BrooklynTypeRegistry#get(String, org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind, Class)} */
+    // only a handful of items remaining, and those require a CatalogItem
     public static CatalogItem<?, ?> getCatalogItemOptionalVersion(ManagementContext mgmt, String versionedId) {
         if (versionedId == null) return null;
         if (looksLikeVersionedId(versionedId)) {
@@ -245,11 +248,13 @@ public class CatalogUtils {
     }
 
     public static boolean isBestVersion(ManagementContext mgmt, CatalogItem<?,?> item) {
-        CatalogItem<?, ?> bestVersion = getCatalogItemOptionalVersion(mgmt, item.getSymbolicName());
+        RegisteredType bestVersion = mgmt.getTypeRegistry().get(item.getSymbolicName(), BrooklynCatalog.DEFAULT_VERSION, null);
         if (bestVersion==null) return false;
         return (bestVersion.getVersion().equals(item.getVersion()));
     }
 
+    /** @deprecated since 0.9.0 use {@link BrooklynTypeRegistry#get(String, org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind, Class)} */
+    // only a handful of items remaining, and those require a CatalogItem
     public static <T,SpecT> CatalogItem<T, SpecT> getCatalogItemOptionalVersion(ManagementContext mgmt, Class<T> type, String versionedId) {
         if (looksLikeVersionedId(versionedId)) {
             String id = getSymbolicNameFromVersionedId(versionedId);
@@ -260,4 +265,36 @@ public class CatalogUtils {
         }
     }
 
+    /** @deprecated since it was introduced in 0.9.0; TBD where this should live */
+    public static void setDeprecated(ManagementContext mgmt, String symbolicNameAndOptionalVersion, boolean newValue) {
+        RegisteredType item = mgmt.getTypeRegistry().get(symbolicNameAndOptionalVersion);
+        Preconditions.checkNotNull(item, "No such item: "+symbolicNameAndOptionalVersion);
+        setDeprecated(mgmt, item.getSymbolicName(), item.getVersion(), newValue);
+    }
+    
+    /** @deprecated since it was introduced in 0.9.0; TBD where this should live */
+    public static void setDisabled(ManagementContext mgmt, String symbolicNameAndOptionalVersion, boolean newValue) {
+        RegisteredType item = mgmt.getTypeRegistry().get(symbolicNameAndOptionalVersion);
+        Preconditions.checkNotNull(item, "No such item: "+symbolicNameAndOptionalVersion);
+        setDisabled(mgmt, item.getSymbolicName(), item.getVersion(), newValue);
+    }
+    
+    /** @deprecated since it was introduced in 0.9.0; TBD where this should live */
+    @Deprecated
+    public static void setDeprecated(ManagementContext mgmt, String symbolicName, String version, boolean newValue) {
+        CatalogItem<?, ?> item = mgmt.getCatalog().getCatalogItem(symbolicName, version);
+        Preconditions.checkNotNull(item, "No such item: "+symbolicName+" v "+version);
+        item.setDeprecated(newValue);
+        mgmt.getCatalog().persist(item);
+    }
+
+    /** @deprecated since it was introduced in 0.9.0; TBD where this should live */
+    @Deprecated
+    public static void setDisabled(ManagementContext mgmt, String symbolicName, String version, boolean newValue) {
+        CatalogItem<?, ?> item = mgmt.getCatalog().getCatalogItem(symbolicName, version);
+        Preconditions.checkNotNull(item, "No such item: "+symbolicName+" v "+version);
+        item.setDisabled(newValue);
+        mgmt.getCatalog().persist(item);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
index a6a8e3a..742625a 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
@@ -28,18 +28,23 @@ import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.api.policy.PolicySpec;
-import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContext;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.plan.PlanNotRecognizedException;
 import org.apache.brooklyn.core.plan.PlanToSpecTransformer;
+import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Old-style catalog items (can be defined in catalog.xml only) don't have structure, only a single type, so
- * they are loaded as a simple java type, only taking the class name from the catalog item instead of the
- * type value in the YAML. Classpath entries in the item are also used (through the catalog root classloader).
+ * Instantiates classes from a registered type which simply
+ * defines the java class name and OSGi bundles to use.
+ * <p>
+ * This is used where a {@link RegisteredType} is defined simply with the name of a java class
+ * (no YAML etc); and for legacy old-style (c0.7.0) catalog items (defined in catalog.xml only)
+ * with structure, only a single type.
  */
 public class JavaCatalogToSpecTransformer implements PlanToSpecTransformer {
+    @SuppressWarnings("unused")
     private static final Logger log = LoggerFactory.getLogger(JavaCatalogToSpecTransformer.class);
 
     private ManagementContext mgmt;
@@ -51,7 +56,7 @@ public class JavaCatalogToSpecTransformer implements PlanToSpecTransformer {
 
     @Override
     public String getShortDescription() {
-        return "Deprecated java-type catalog items transformer";
+        return "Java type instantiator";
     }
 
     @Override
@@ -68,11 +73,11 @@ public class JavaCatalogToSpecTransformer implements PlanToSpecTransformer {
     public <T, SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT createCatalogSpec(
             CatalogItem<T, SpecT> item, Set<String> encounteredTypes) throws PlanNotRecognizedException {
         if (item.getJavaType() != null) {
-            log.warn("Deprecated functionality (since 0.9.0). Using old-style xml catalog items with java type attribute for " + item);
             Class<?> type;
             try {
-                type = mgmt.getCatalogClassLoader().loadClass(item.getJavaType());
-            } catch (ClassNotFoundException e) {
+                type = CatalogUtils.newClassLoadingContext(mgmt, item).loadClass(item.getJavaType());
+            } catch (Exception e) {
+                Exceptions.propagateIfFatal(e);
                 throw new IllegalStateException("Unable to load old-style java catalog item type " + item.getJavaType() + " for item " + item, e);
             }
             AbstractBrooklynObjectSpec<?,?> spec;
@@ -87,6 +92,7 @@ public class JavaCatalogToSpecTransformer implements PlanToSpecTransformer {
             } else {
                 throw new IllegalStateException("Catalog item " + item + " java type " + item.getJavaType() + " is not a Brooklyn supported object.");
             }
+            spec.catalogItemId(item.getCatalogItemId());
             @SuppressWarnings("unchecked")
             SpecT untypedSpc = (SpecT) spec;
             return untypedSpc;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
index c75c908..09b362d 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
@@ -715,6 +715,14 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
         public Iterator<Group> iterator() { 
             return asList().iterator();
         }
+        @Override
+        public int size() {
+            return asList().size();
+        }
+        @Override
+        public boolean isEmpty() {
+            return asList().isEmpty();
+        }
         
         protected List<Group> asList() { 
             return ImmutableList.copyOf(groupsInternal);
@@ -1598,6 +1606,15 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
             return asList().iterator();
         }
 
+        @Override
+        public int size() {
+            return policiesInternal.size();
+        }
+        @Override
+        public boolean isEmpty() {
+            return policiesInternal.isEmpty();
+        }
+        
         protected List<Policy> asList() {
             return ImmutableList.<Policy>copyOf(policiesInternal);
         }
@@ -1661,6 +1678,15 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
             return asList().iterator();
         }
 
+        @Override
+        public int size() {
+            return enrichersInternal.size();
+        }
+        @Override
+        public boolean isEmpty() {
+            return enrichersInternal.isEmpty();
+        }
+        
         protected List<Enricher> asList() {
             return ImmutableList.<Enricher>copyOf(enrichersInternal);
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
index 0120fd7..8b10676 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java
@@ -42,7 +42,6 @@ import java.util.concurrent.atomic.AtomicReference;
 import org.apache.brooklyn.api.effector.Effector;
 import org.apache.brooklyn.api.entity.Application;
 import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntityLocal;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.entity.Group;
 import org.apache.brooklyn.api.entity.drivers.EntityDriver;
@@ -170,7 +169,7 @@ public class Entities {
      *
      * @return {@link ParallelTask} containing results from each invocation
      */
-    public static <T> Task<List<T>> invokeEffectorList(EntityLocal callingEntity, Iterable<? extends Entity> entitiesToCall,
+    public static <T> Task<List<T>> invokeEffectorList(Entity callingEntity, Iterable<? extends Entity> entitiesToCall,
             final Effector<T> effector, final Map<String,?> parameters) {
         // formulation is complicated, but it is building up a list of tasks, without blocking on them initially,
         // but ensuring that when the parallel task is gotten it does block on all of them
@@ -194,25 +193,25 @@ public class Entities {
         return DynamicTasks.queueIfPossible(invoke).orSubmitAsync(callingEntity).asTask();
     }
 
-    public static <T> Task<List<T>> invokeEffectorListWithMap(EntityLocal callingEntity, Iterable<? extends Entity> entitiesToCall,
+    public static <T> Task<List<T>> invokeEffectorListWithMap(Entity callingEntity, Iterable<? extends Entity> entitiesToCall,
             final Effector<T> effector, final Map<String,?> parameters) {
         return invokeEffectorList(callingEntity, entitiesToCall, effector, parameters);
     }
 
     @SuppressWarnings("unchecked")
-    public static <T> Task<List<T>> invokeEffectorListWithArgs(EntityLocal callingEntity, Iterable<? extends Entity> entitiesToCall,
+    public static <T> Task<List<T>> invokeEffectorListWithArgs(Entity callingEntity, Iterable<? extends Entity> entitiesToCall,
             final Effector<T> effector, Object ...args) {
         return invokeEffectorListWithMap(callingEntity, entitiesToCall, effector,
                 // putting into a map, unnecessarily, as it ends up being the array again...
                 EffectorUtils.prepareArgsForEffectorAsMapFromArray(effector, args));
     }
 
-    public static <T> Task<List<T>> invokeEffectorList(EntityLocal callingEntity, Iterable<? extends Entity> entitiesToCall,
+    public static <T> Task<List<T>> invokeEffectorList(Entity callingEntity, Iterable<? extends Entity> entitiesToCall,
             final Effector<T> effector) {
         return invokeEffectorList(callingEntity, entitiesToCall, effector, Collections.<String,Object>emptyMap());
     }
 
-    public static <T> Task<T> invokeEffector(EntityLocal callingEntity, Entity entityToCall,
+    public static <T> Task<T> invokeEffector(Entity callingEntity, Entity entityToCall,
             final Effector<T> effector, final Map<String,?> parameters) {
         Task<T> t = Effectors.invocation(entityToCall, effector, parameters).asTask();
         TaskTags.markInessential(t);
@@ -231,19 +230,19 @@ public class Entities {
     }
 
     @SuppressWarnings("unchecked")
-    public static <T> Task<T> invokeEffectorWithArgs(EntityLocal callingEntity, Entity entityToCall,
+    public static <T> Task<T> invokeEffectorWithArgs(Entity callingEntity, Entity entityToCall,
             final Effector<T> effector, Object ...args) {
         return invokeEffector(callingEntity, entityToCall, effector,
                 EffectorUtils.prepareArgsForEffectorAsMapFromArray(effector, args));
     }
 
-    public static <T> Task<T> invokeEffector(EntityLocal callingEntity, Entity entityToCall,
+    public static <T> Task<T> invokeEffector(Entity callingEntity, Entity entityToCall,
             final Effector<T> effector) {
         return invokeEffector(callingEntity, entityToCall, effector, Collections.<String,Object>emptyMap());
     }
 
     /** Invokes in parallel if multiple, but otherwise invokes the item directly. */
-    public static Task<?> invokeEffector(EntityLocal callingEntity, Iterable<? extends Entity> entitiesToCall,
+    public static Task<?> invokeEffector(Entity callingEntity, Iterable<? extends Entity> entitiesToCall,
             final Effector<?> effector, final Map<String,?> parameters) {
         if (Iterables.size(entitiesToCall)==1)
             return invokeEffector(callingEntity, entitiesToCall.iterator().next(), effector, parameters);
@@ -252,7 +251,7 @@ public class Entities {
     }
 
     /** Invokes in parallel if multiple, but otherwise invokes the item directly. */
-    public static Task<?> invokeEffector(EntityLocal callingEntity, Iterable<? extends Entity> entitiesToCall,
+    public static Task<?> invokeEffector(Entity callingEntity, Iterable<? extends Entity> entitiesToCall,
             final Effector<?> effector) {
         return invokeEffector(callingEntity, entitiesToCall, effector, Collections.<String,Object>emptyMap());
     }
@@ -376,14 +375,14 @@ public class Entities {
             out.append(currentIndentation+tab+tab+"Members: "+members.toString()+"\n");
         }
 
-        if (!e.getPolicies().isEmpty()) {
+        if (!e.policies().isEmpty()) {
             out.append(currentIndentation+tab+tab+"Policies:\n");
             for (Policy policy : e.policies()) {
                 dumpInfo(policy, out, currentIndentation+tab+tab+tab, tab);
             }
         }
 
-        if (!e.getEnrichers().isEmpty()) {
+        if (!e.enrichers().isEmpty()) {
             out.append(currentIndentation+tab+tab+"Enrichers:\n");
             for (Enricher enricher : e.enrichers()) {
                 dumpInfo(enricher, out, currentIndentation+tab+tab+tab, tab);
@@ -699,7 +698,7 @@ public class Entities {
             log.warn("Using deprecated discouraged mechanism to start management -- Entities.start(Application, Locations) -- caller should create and use the preferred management context");
             startManagement(e);
         }
-        if (e instanceof Startable) Entities.invokeEffector((EntityLocal)e, e, Startable.START,
+        if (e instanceof Startable) Entities.invokeEffector(e, e, Startable.START,
                 MutableMap.of("locations", locations)).getUnchecked();
     }
 
@@ -714,7 +713,7 @@ public class Entities {
                 unmanage(e);
                 log.debug("destroyed and unmanaged read-only copy of "+e);
             } else {
-                if (e instanceof Startable) Entities.invokeEffector((EntityLocal)e, e, Startable.STOP).getUnchecked();
+                if (e instanceof Startable) Entities.invokeEffector(e, e, Startable.STOP).getUnchecked();
                 
                 // if destroying gracefully we might also want to do this (currently gets done by GC after unmanage,
                 // which is good enough for leaks, but not sure if that's ideal for subscriptions etc)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/entity/factory/ApplicationBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/factory/ApplicationBuilder.java b/core/src/main/java/org/apache/brooklyn/core/entity/factory/ApplicationBuilder.java
index f8167a0..66f4795 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/factory/ApplicationBuilder.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/factory/ApplicationBuilder.java
@@ -217,7 +217,8 @@ public abstract class ApplicationBuilder {
             this.managementContext = managementContext;
             this.app = managementContext.getEntityManager().createEntity(appSpec);
             doBuild();
-            Entities.startManagement(app, managementContext);
+            // not needed with 0.9.0 (TODO - remove when confirmed)
+//            Entities.startManagement(app, managementContext);
             managed = true;
             return app;
         } finally {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java b/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
index 573da76..202ecf4 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
@@ -38,12 +38,14 @@ import org.apache.brooklyn.api.location.LocationRegistry;
 import org.apache.brooklyn.api.location.LocationResolver;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.config.ConfigMap;
-import org.apache.brooklyn.core.catalog.CatalogPredicates;
 import org.apache.brooklyn.core.config.ConfigPredicates;
 import org.apache.brooklyn.core.config.ConfigUtils;
 import org.apache.brooklyn.core.location.internal.LocationInternal;
 import org.apache.brooklyn.core.mgmt.internal.LocalLocationManager;
+import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.config.ConfigBag;
@@ -72,8 +74,8 @@ import com.google.common.collect.Sets;
  * <p>
  * Any location item added to the catalog must therefore be registered here.
  * Whenever an item is added to the catalog, it will automatically call 
- * {@link #updateDefinedLocation(CatalogItem)}. Similarly, when a location
- * is deleted from the catalog it will call {@link #removeDefinedLocation(CatalogItem)}.
+ * {@link #updateDefinedLocation(RegisteredType)}. Similarly, when a location
+ * is deleted from the catalog it will call {@link #removeDefinedLocation(RegisteredType)}.
  * <p>
  * However, the location item in the catalog has an unparsed blob of YAML, which contains
  * important things like the type and the config of the location. This is only parsed when 
@@ -86,8 +88,8 @@ import com.google.common.collect.Sets;
  * <ol>
  *   <li>Call {@link BrooklynCatalog#addItems(String)}
  *     <ol>
- *       <li>This automatically calls {@link #updateDefinedLocation(CatalogItem)}
- *       <li>A LocationDefinition is creating, using as its id the {@link CatalogItem#getSymbolicName()}.
+ *       <li>This automatically calls {@link #updateDefinedLocation(RegisteredType)}
+ *       <li>A LocationDefinition is creating, using as its id the {@link RegisteredType#getSymbolicName()}.
  *           The definition's spec is {@code brooklyn.catalog:<symbolicName>:<version>},
  *     </ol>
  *   <li>A blueprint can reference the catalog item using its symbolic name, 
@@ -100,8 +102,8 @@ import com.google.common.collect.Sets;
  *           found for it.
  *       <li>This uses the {@link CatalogLocationResolver}, because the spec starts with {@code brooklyn.catalog:}.
  *       <li>This resolver extracts from the spec the <symobolicName>:<version>, and looks up the 
- *           catalog item using {@link BrooklynCatalog#getCatalogItem(String, String)}.
- *       <li>It then creates a {@link LocationSpec} by calling {@link BrooklynCatalog#createSpec(CatalogItem)}.
+ *           location item using the {@link BrooklynTypeRegistry}.
+ *       <li>It then creates a {@link LocationSpec} by calling {@link BrooklynTypeRegistry#createSpec(RegisteredType)}.
  *         <ol>
  *           <li>This first tries to use the type (that is in the YAML) as a simple Java class.
  *           <li>If that fails, it will resolve the type using {@link #resolve(String, Boolean, Map)}, which
@@ -113,7 +115,7 @@ import com.google.common.collect.Sets;
  *     </ol>
  * </ol>
  * 
- * There is no concept of a location version in this registry. The version
+ * TODO There is no concept of a location version in this registry. The version
  * in the catalog is generally ignored.
  */
 @SuppressWarnings({"rawtypes","unchecked"})
@@ -222,6 +224,21 @@ public class BasicLocationRegistry implements LocationRegistry {
         updateDefinedLocation(locDefinition);
     }
 
+    /**
+     * Converts the given item from the catalog into a LocationDefinition, and adds it
+     * to the registry (overwriting anything already registered with the id
+     * {@link RegisteredType#getId()}.
+     */
+    public void updateDefinedLocation(RegisteredType item) {
+        String id = item.getId();
+        String symbolicName = item.getSymbolicName();
+        String spec = CatalogLocationResolver.NAME + ":" + id;
+        Map<String, Object> config = ImmutableMap.<String, Object>of();
+        BasicLocationDefinition locDefinition = new BasicLocationDefinition(symbolicName, symbolicName, spec, config);
+        
+        updateDefinedLocation(locDefinition);
+    }
+
     public void removeDefinedLocation(CatalogItem<Location, LocationSpec<?>> item) {
         removeDefinedLocation(item.getSymbolicName());
     }
@@ -244,7 +261,7 @@ public class BasicLocationRegistry implements LocationRegistry {
             // we need ability/format for persisting named locations, and better support for adding+saving via REST/GUI)
             int count = 0; 
             String NAMED_LOCATION_PREFIX = "brooklyn.location.named.";
-            ConfigMap namedLocationProps = mgmt.getConfig().submap(ConfigPredicates.startingWith(NAMED_LOCATION_PREFIX));
+            ConfigMap namedLocationProps = mgmt.getConfig().submap(ConfigPredicates.nameStartsWith(NAMED_LOCATION_PREFIX));
             for (String k: namedLocationProps.asMapWithStringKeys().keySet()) {
                 String name = k.substring(NAMED_LOCATION_PREFIX.length());
                 // If has a dot, then is a sub-property of a named location (e.g. brooklyn.location.named.prod1.user=bob)
@@ -271,7 +288,7 @@ public class BasicLocationRegistry implements LocationRegistry {
                 definedLocations.putAll(oldDefined);
             }
             
-            for (CatalogItem<Location, LocationSpec<?>> item : mgmt.getCatalog().getCatalogItems(CatalogPredicates.IS_LOCATION)) {
+            for (RegisteredType item: mgmt.getTypeRegistry().getAll(RegisteredTypePredicates.IS_LOCATION)) {
                 updateDefinedLocation(item);
                 count++;
             }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/location/CatalogLocationResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/CatalogLocationResolver.java b/core/src/main/java/org/apache/brooklyn/core/location/CatalogLocationResolver.java
index db4c0d5..5db14b7 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/CatalogLocationResolver.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/CatalogLocationResolver.java
@@ -28,7 +28,7 @@ import org.apache.brooklyn.api.location.LocationRegistry;
 import org.apache.brooklyn.api.location.LocationResolver;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -53,14 +53,14 @@ public class CatalogLocationResolver implements LocationResolver {
     @SuppressWarnings({ "rawtypes", "unchecked" })
     public Location newLocationFromString(Map locationFlags, String spec, LocationRegistry registry) {
         String id = spec.substring(NAME.length()+1);
-        CatalogItem<?, ?> item = CatalogUtils.getCatalogItemOptionalVersion(managementContext, id);
+        RegisteredType item = managementContext.getTypeRegistry().get(id);
         if (item.isDisabled()) {
             throw new IllegalStateException("Illegal use of disabled catalog item "+item.getSymbolicName()+":"+item.getVersion());
         } else if (item.isDeprecated()) {
             log.warn("Use of deprecated catalog item "+item.getSymbolicName()+":"+item.getVersion());
         }
         
-        LocationSpec origLocSpec = (LocationSpec) managementContext.getCatalog().createSpec((CatalogItem)item);
+        LocationSpec origLocSpec = (LocationSpec) managementContext.getTypeRegistry().createSpec(item, null, LocationSpec.class);
         LocationSpec locSpec = LocationSpec.create(origLocSpec)
                 .configure(locationFlags);
         return managementContext.getLocationManager().createLocation(locSpec);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java
index 889f74f..9c4ebc1 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java
@@ -28,12 +28,12 @@ import javax.annotation.Nullable;
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Application;
 import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntityLocal;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
 import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.effector.Effectors;
 import org.apache.brooklyn.core.entity.Entities;
@@ -89,6 +89,7 @@ public class EntityManagementUtils {
     }
     
     public static EntitySpec<? extends Application> createEntitySpecForApplication(ManagementContext mgmt, final String plan) {
+        // TODO-type-registry
         return PlanToSpecFactory.attemptWithLoaders(mgmt, new Function<PlanToSpecTransformer, EntitySpec<? extends Application>>() {
             @Override
             public EntitySpec<? extends Application> apply(PlanToSpecTransformer input) {
@@ -97,20 +98,16 @@ public class EntityManagementUtils {
         }).get();
     }
 
+    @Deprecated /** @deprecated since 0.9.0; use {@link BrooklynTypeRegistry#createSpec(RegisteredType, org.apache.brooklyn.api.typereg.RegisteredTypeConstraint, Class)} */
+    // not used in Brooklyn
     public static <T,SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT createCatalogSpec(ManagementContext mgmt, CatalogItem<T, SpecT> item) {
         return createCatalogSpec(mgmt, item, ImmutableSet.<String>of());
     }
 
+    @Deprecated /** @deprecated since 0.9.0; use {@link BrooklynTypeRegistry#createSpec(RegisteredType, org.apache.brooklyn.api.typereg.RegisteredTypeConstraint, Class)} */
+    // not used in Brooklyn
     public static <T,SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT createCatalogSpec(ManagementContext mgmt, final CatalogItem<T, SpecT> item, final Set<String> encounteredTypes) {
-        if (encounteredTypes.contains(item.getSymbolicName())) {
-            throw new IllegalStateException("Already encountered types " + encounteredTypes + " must not contain catalog item being resolver " + item.getSymbolicName());
-        }
-        return PlanToSpecFactory.attemptWithLoaders(mgmt, new Function<PlanToSpecTransformer, SpecT>() {
-            @Override
-            public SpecT apply(PlanToSpecTransformer input) {
-                return input.createCatalogSpec(item, encounteredTypes);
-            }
-        }).get();
+        return BasicBrooklynCatalog.internalCreateSpecWithTransformers(mgmt, item, encounteredTypes);
     }
 
     /** container for operation which creates something and which wants to return both
@@ -145,21 +142,21 @@ public class EntityManagementUtils {
     }
 
     public static <T extends Application> CreationResult<T,Void> start(T app) {
-        Task<Void> task = Entities.invokeEffector((EntityLocal)app, app, Startable.START,
+        Task<Void> task = Entities.invokeEffector(app, app, Startable.START,
             // locations already set in the entities themselves;
             // TODO make it so that this arg does not have to be supplied to START !
             MutableMap.of("locations", MutableList.of()));
         return CreationResult.of(app, task);
     }
     
-    public static CreationResult<List<Entity>, List<String>> addChildren(final EntityLocal parent, String yaml, Boolean start) {
+    public static CreationResult<List<Entity>, List<String>> addChildren(final Entity parent, String yaml, Boolean start) {
         if (Boolean.FALSE.equals(start))
             return CreationResult.of(addChildrenUnstarted(parent, yaml), null);
         return addChildrenStarting(parent, yaml);
     }
     
     /** adds entities from the given yaml, under the given parent; but does not start them */
-    public static List<Entity> addChildrenUnstarted(final EntityLocal parent, String yaml) {
+    public static List<Entity> addChildrenUnstarted(final Entity parent, String yaml) {
         log.debug("Creating child of "+parent+" from yaml:\n{}", yaml);
 
         ManagementContext mgmt = parent.getApplication().getManagementContext();
@@ -193,7 +190,7 @@ public class EntityManagementUtils {
         return children;
     }
 
-    public static CreationResult<List<Entity>,List<String>> addChildrenStarting(final EntityLocal parent, String yaml) {
+    public static CreationResult<List<Entity>,List<String>> addChildrenStarting(final Entity parent, String yaml) {
         final List<Entity> children = addChildrenUnstarted(parent, yaml);
         String childrenCountString;
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/mgmt/classloading/OsgiBrooklynClassLoadingContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/classloading/OsgiBrooklynClassLoadingContext.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/classloading/OsgiBrooklynClassLoadingContext.java
index 74f3de1..524f7b5 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/classloading/OsgiBrooklynClassLoadingContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/classloading/OsgiBrooklynClassLoadingContext.java
@@ -22,10 +22,9 @@ import java.net.URL;
 import java.util.Collection;
 import java.util.Collections;
 
-import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
-import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
 import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
@@ -48,11 +47,11 @@ public class OsgiBrooklynClassLoadingContext extends AbstractBrooklynClassLoadin
 
     public Collection<? extends OsgiBundleWithUrl> getBundles() {
         if (_bundles!=null || !hasBundles) return _bundles;
-        CatalogItem<?, ?> cat = CatalogUtils.getCatalogItemOptionalVersion(mgmt, catalogItemId);
-        if (cat==null) {
+        RegisteredType item = mgmt.getTypeRegistry().get(catalogItemId);
+        if (item==null) {
             throw new IllegalStateException("Catalog item not found for "+catalogItemId+"; cannot create loading context");
         }
-        _bundles = cat.getLibraries();
+        _bundles = item.getLibraries();
         return _bundles;
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
index 284b357..cba394c 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/AbstractManagementContext.java
@@ -33,7 +33,6 @@ import java.util.concurrent.atomic.AtomicLong;
 import javax.annotation.Nullable;
 
 import org.apache.brooklyn.api.catalog.BrooklynCatalog;
-import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.effector.Effector;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.drivers.EntityDriverManager;
@@ -49,6 +48,7 @@ import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityManager;
 import org.apache.brooklyn.api.mgmt.rebind.RebindManager;
 import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.config.StringConfigMap;
 import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
 import org.apache.brooklyn.core.catalog.internal.CatalogInitialization;
@@ -127,7 +127,8 @@ public abstract class AbstractManagementContext implements ManagementContextInte
                 if (input instanceof EntityInternal) {
                     EntityInternal internal = (EntityInternal)input;
                     if (internal.getCatalogItemId() != null) {
-                        CatalogItem<?, ?> item = CatalogUtils.getCatalogItemOptionalVersion(internal.getManagementContext(), internal.getCatalogItemId());
+                        RegisteredType item = internal.getManagementContext().getTypeRegistry().get(internal.getCatalogItemId());
+
                         if (item != null) {
                             return CatalogUtils.newClassLoadingContext(internal.getManagementContext(), item);
                         } else {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynMementoPersisterToObjectStore.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynMementoPersisterToObjectStore.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynMementoPersisterToObjectStore.java
index 10f349a..adbb01f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynMementoPersisterToObjectStore.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/BrooklynMementoPersisterToObjectStore.java
@@ -35,9 +35,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import javax.annotation.Nullable;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.mgmt.rebind.PersistenceExceptionHandler;
 import org.apache.brooklyn.api.mgmt.rebind.RebindExceptionHandler;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMemento;
@@ -48,6 +45,7 @@ import org.apache.brooklyn.api.mgmt.rebind.mementos.CatalogItemMemento;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.Memento;
 import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.api.objs.BrooklynObjectType;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.config.StringConfigMap;
 import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
@@ -56,7 +54,6 @@ import org.apache.brooklyn.core.mgmt.classloading.ClassLoaderFromBrooklynClassLo
 import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore.StoreObjectAccessor;
 import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore.StoreObjectAccessorWithLock;
 import org.apache.brooklyn.core.mgmt.rebind.PeriodicDeltaChangeListener;
-import org.apache.brooklyn.core.mgmt.rebind.PersisterDeltaImpl;
 import org.apache.brooklyn.core.mgmt.rebind.dto.BrooklynMementoImpl;
 import org.apache.brooklyn.core.mgmt.rebind.dto.BrooklynMementoManifestImpl;
 import org.apache.brooklyn.util.collections.MutableMap;
@@ -66,9 +63,10 @@ import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.time.Duration;
 import org.apache.brooklyn.util.time.Time;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.Beta;
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Objects;
 import com.google.common.base.Stopwatch;
 import com.google.common.collect.ImmutableSet;
@@ -176,7 +174,7 @@ public class BrooklynMementoPersisterToObjectStore implements BrooklynMementoPer
         }
         // See RebindIteration.BrooklynObjectInstantiator.load(), for handling where catalog item is missing;
         // similar logic here.
-        CatalogItem<?, ?> catalogItem = CatalogUtils.getCatalogItemOptionalVersion(lookupContext.lookupManagementContext(), catalogItemId);
+        RegisteredType catalogItem = lookupContext.lookupManagementContext().getTypeRegistry().get(catalogItemId);
         if (catalogItem == null) {
             // TODO do we need to only log once, rather than risk log.warn too often? I think this only happens on rebind, so ok.
             LOG.warn("Unable to load catalog item "+catalogItemId+" for custom class loader of "+type+" "+objectId+"; will use default class loader");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java
index 3d2ecef..98b5aa2 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/XmlMementoSerializer.java
@@ -40,6 +40,7 @@ import org.apache.brooklyn.api.objs.Identifiable;
 import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.api.sensor.Enricher;
 import org.apache.brooklyn.api.sensor.Feed;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.catalog.internal.CatalogBundleDto;
 import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.config.BasicConfigKey;
@@ -439,7 +440,7 @@ public class XmlMementoSerializer<T> extends XmlSerializer<T> implements Memento
             try {
                 if (Strings.isNonBlank(catalogItemId)) {
                     if (lookupContext==null) throw new NullPointerException("lookupContext required to load catalog item "+catalogItemId);
-                    CatalogItem<?, ?> cat = CatalogUtils.getCatalogItemOptionalVersion(lookupContext.lookupManagementContext(), catalogItemId);
+                    RegisteredType cat = lookupContext.lookupManagementContext().getTypeRegistry().get(catalogItemId);
                     if (cat==null) throw new NoSuchElementException("catalog item: "+catalogItemId);
                     BrooklynClassLoadingContext clcNew = CatalogUtils.newClassLoadingContext(lookupContext.lookupManagementContext(), cat);
                     pushXstreamCustomClassLoader(clcNew);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindContextLookupContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindContextLookupContext.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindContextLookupContext.java
index 1faaa1c..eb55784 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindContextLookupContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindContextLookupContext.java
@@ -18,12 +18,8 @@
  */
 package org.apache.brooklyn.core.mgmt.rebind;
 
-import java.util.NoSuchElementException;
-
 import javax.annotation.Nullable;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.location.Location;
@@ -37,6 +33,8 @@ import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.api.sensor.Enricher;
 import org.apache.brooklyn.api.sensor.Feed;
 import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /** Looks in {@link RebindContext} <i>and</i> {@link ManagementContext} to find entities, locations, etc. */
 public class RebindContextLookupContext implements LookupContext {
@@ -115,10 +113,13 @@ public class RebindContextLookupContext implements LookupContext {
         return result;
     }
 
+    @SuppressWarnings("deprecation")
     @Override
     public CatalogItem<?, ?> lookupCatalogItem(String id) {
         CatalogItem<?, ?> result = rebindContext.getCatalogItem(id);
         if (result == null) {
+            // TODO-type-registry
+//          result = managementContext.getTypeRegistry().get(id, null, null);
             result = CatalogUtils.getCatalogItemOptionalVersion(managementContext, id);
         }
         if (result == null) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
index 2279e8c..3655886 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
@@ -30,8 +30,6 @@ import java.util.concurrent.Semaphore;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.brooklyn.api.catalog.BrooklynCatalog;
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.Application;
@@ -43,6 +41,7 @@ import org.apache.brooklyn.api.mgmt.rebind.RebindExceptionHandler;
 import org.apache.brooklyn.api.mgmt.rebind.RebindSupport;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMemento;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoManifest;
+import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoManifest.EntityMementoManifest;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoPersister;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoRawData;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.CatalogItemMemento;
@@ -53,12 +52,13 @@ import org.apache.brooklyn.api.mgmt.rebind.mementos.LocationMemento;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.Memento;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.PolicyMemento;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.TreeNode;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoManifest.EntityMementoManifest;
 import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.api.objs.BrooklynObjectType;
 import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.api.sensor.Enricher;
 import org.apache.brooklyn.api.sensor.Feed;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.BrooklynFeatureEnablement;
 import org.apache.brooklyn.core.BrooklynLogging;
 import org.apache.brooklyn.core.BrooklynLogging.LoggingLevel;
@@ -98,6 +98,8 @@ import org.apache.brooklyn.util.javalang.Reflections;
 import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.time.Duration;
 import org.apache.brooklyn.util.time.Time;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
@@ -787,12 +789,13 @@ public abstract class RebindIteration {
             EntityMementoManifest ptr = entityManifest;
             while (ptr != null) {
                 if (ptr.getCatalogItemId() != null) {
-                    CatalogItem<?, ?> catalogItem = CatalogUtils.getCatalogItemOptionalVersion(managementContext, ptr.getCatalogItemId());
-                    if (catalogItem != null) {
-                        return catalogItem.getId();
+                    RegisteredType type = managementContext.getTypeRegistry().get(ptr.getCatalogItemId());
+                    if (type != null) {
+                        return type.getId();
                     } else {
                         //Couldn't find a catalog item with this id, but return it anyway and
                         //let the caller deal with the error.
+                        //TODO under what circumstances is this permitted?
                         return ptr.getCatalogItemId();
                     }
                 }
@@ -807,13 +810,13 @@ public abstract class RebindIteration {
             //The current convention is to set catalog item IDs to the java type (for both plain java or CAMP plan) they represent.
             //This will be applicable only the first time the store is rebinded, while the catalog items don't have the default
             //version appended to their IDs, but then we will have catalogItemId set on entities so not neede further anyways.
-            BrooklynCatalog catalog = managementContext.getCatalog();
+            BrooklynTypeRegistry types = managementContext.getTypeRegistry();
             ptr = entityManifest;
             while (ptr != null) {
-                CatalogItem<?, ?> catalogItem = catalog.getCatalogItem(ptr.getType(), BrooklynCatalog.DEFAULT_VERSION);
-                if (catalogItem != null) {
-                    LOG.debug("Inferred catalog item ID "+catalogItem.getId()+" for "+entityManifest+" from ancestor "+ptr);
-                    return catalogItem.getId();
+                RegisteredType t = types.get(ptr.getType(), BrooklynCatalog.DEFAULT_VERSION);
+                if (t != null) {
+                    LOG.debug("Inferred catalog item ID "+t.getId()+" for "+entityManifest+" from ancestor "+ptr);
+                    return t.getId();
                 }
                 if (ptr.getParent() != null) {
                     ptr = entityIdToManifest.get(ptr.getParent());
@@ -827,7 +830,8 @@ public abstract class RebindIteration {
             if (JavaBrooklynClassLoadingContext.create(managementContext).tryLoadClass(entityManifest.getType()).isPresent())
                 return null;
 
-            for (CatalogItem<?, ?> item : catalog.getCatalogItems()) {
+            // TODO get to the point when we can deprecate this behaviour!:
+            for (RegisteredType item : types.getAll()) {
                 BrooklynClassLoadingContext loader = CatalogUtils.newClassLoadingContext(managementContext, item);
                 boolean canLoadClass = loader.tryLoadClass(entityManifest.getType()).isPresent();
                 if (canLoadClass) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50ebfafb/core/src/main/java/org/apache/brooklyn/core/resolve/ResolveUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/resolve/ResolveUtils.java b/core/src/main/java/org/apache/brooklyn/core/resolve/ResolveUtils.java
index c3fc85f..6ecbe96 100644
--- a/core/src/main/java/org/apache/brooklyn/core/resolve/ResolveUtils.java
+++ b/core/src/main/java/org/apache/brooklyn/core/resolve/ResolveUtils.java
@@ -21,18 +21,18 @@ package org.apache.brooklyn.core.resolve;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.catalog.CatalogItem.CatalogItemType;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.api.policy.PolicySpec;
-import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
-import org.apache.brooklyn.core.mgmt.EntityManagementUtils;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContext;
 import org.apache.brooklyn.core.objs.BrooklynObjectInternal.ConfigurationSupportInternal;
 import org.apache.brooklyn.util.guava.Maybe;
 
+@Deprecated /** @deprecated since 0.9.0 never belonged here, and not used much; new principled TypeRegistry simplifies things */
+// only used for camp
+// TODO-type-registry
 public class ResolveUtils {
 
     @SuppressWarnings("unchecked")
@@ -40,16 +40,13 @@ public class ResolveUtils {
             String versionedId,
             BrooklynClassLoadingContext loader,
             Set<String> encounteredCatalogTypes) {
+        
         PolicySpec<? extends Policy> spec;
-        CatalogItem<?, ?> policyItem = CatalogUtils.getCatalogItemOptionalVersion(loader.getManagementContext(), versionedId);
-        if (policyItem != null && !encounteredCatalogTypes.contains(policyItem.getSymbolicName())) {
-            if (policyItem.getCatalogItemType() != CatalogItemType.POLICY) {
-                throw new IllegalStateException("Non-policy catalog item in policy context: " + policyItem);
-            }
-            @SuppressWarnings("rawtypes")
-            CatalogItem rawItem = policyItem;
-            spec = (PolicySpec<? extends Policy>) EntityManagementUtils.createCatalogSpec(loader.getManagementContext(), rawItem, encounteredCatalogTypes);
+        RegisteredType item = loader.getManagementContext().getTypeRegistry().get(versionedId);
+        if (item != null && !encounteredCatalogTypes.contains(item.getSymbolicName())) {
+            return loader.getManagementContext().getTypeRegistry().createSpec(item, null, PolicySpec.class);
         } else {
+            // TODO-type-registry pass the loader in to the above, and allow it to load with the loader
             spec = PolicySpec.create(loader.loadClass(versionedId, Policy.class));
         }
         return spec;


Mime
View raw message