Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1017#discussion_r44642260
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java ---
    @@ -66,180 +94,131 @@ public static RegisteredType of(CatalogItem<?, ?> 
item) {
             type.deprecated = item.isDeprecated();
     
             // TODO
    -        // javaType, specType, registeredTypeName ...
    -        // tags ?
    +        // probably not: javaType, specType, registeredTypeName ...
    +        // maybe: tags ?
             return type;
         }
     
    -    /** Visitor adapter which can be used to ensure all kinds are 
supported */
    -    public static abstract class RegisteredTypeKindVisitor<T> {
    -        public T visit(RegisteredType type) {
    -            if (type==null) throw new NullPointerException("Registered 
type must not be null");
    -            if (type instanceof RegisteredSpecType) {
    -                return visitSpec((RegisteredSpecType)type);
    -            }
    -            // others go here
    -            throw new IllegalStateException("Unexpected registered type: 
"+type.getClass());
    -        }
    -
    -        protected abstract T visitSpec(RegisteredSpecType type);
    -        
    -        // TODO beans, others
    +    /** Preferred mechanism for defining a bean {@link RegisteredType} */
    +    public static RegisteredType bean(String symbolicName, String version, 
TypeImplementationPlan plan, @Nullable Class<?> superType) {
    +        return addSuperType(new 
BasicRegisteredType(RegisteredTypeKind.BEAN, symbolicName, version, plan), 
superType);
         }
         
    -    public static RegisteredTypeKind getKindOf(RegisteredType type) {
    -        return new RegisteredTypeKindVisitor<RegisteredTypeKind>() {
    -            @Override protected RegisteredTypeKind 
visitSpec(RegisteredSpecType type) { return RegisteredTypeKind.SPEC; }
    -        }.visit(type);
    +    public static RegisteredType spec(String symbolicName, String version, 
TypeImplementationPlan plan, @Nullable Class<?> superType) {
    +        return addSuperType(new 
BasicRegisteredType(RegisteredTypeKind.SPEC, symbolicName, version, plan), 
superType);
         }
    -    
    -    public abstract static class AbstractRegisteredType implements 
RegisteredType {
     
    -        final String symbolicName;
    -        final String version;
    +    /** returns the {@link Class} object corresponding to the given java 
type name,
    +     * using the cache on the type and the loader defined on the type
    +     * @param mgmt */
    +    @Beta
    +    // TODO should this be on the AbstractTypePlanTransformer ?
    +    public static Class<?> loadActualJavaType(String javaTypeName, 
ManagementContext mgmt, RegisteredType type, RegisteredTypeLoadingContext 
context) throws Exception {
    +        Class<?> result = 
((BasicRegisteredType)type).getCache().get(ACTUAL_JAVA_TYPE);
    +        if (result!=null) return result;
             
    -        List<OsgiBundleWithUrl> bundles;
    -        String displayName;
    -        String description;
    -        String iconUrl;
    -        boolean deprecated;
    -        boolean disabled;
    -
    -        // TODO ensure this is re-populated on rebind
    -        transient Class<?> javaType;
    +        result = CatalogUtils.newClassLoadingContext(mgmt, type, 
context==null ? null : context.getLoader()).loadClass( javaTypeName );
    +        Preconditions.checkNotNull(result, "Could not load class 
"+javaTypeName+"; returned null (should have thrown a different exception!)");
             
    -        public AbstractRegisteredType(String symbolicName, String version, 
Class<?> javaType) {
    -            this.symbolicName = symbolicName;
    -            this.version = version;
    -            this.javaType = javaType;
    -        }
    -
    -        @Override
    -        public String getId() {
    -            return symbolicName + (version!=null ? ":"+version : "");
    -        }
    +        ((BasicRegisteredType)type).getCache().put(ACTUAL_JAVA_TYPE, 
result);
    +        return result;
    +    }
     
    -        @Override
    -        public String getSymbolicName() {
    -            return symbolicName;
    +    @Beta
    +    public static RegisteredType addSuperType(RegisteredType type, 
@Nullable Class<?> superType) {
    +        if (superType!=null) {
    +            ((BasicRegisteredType)type).superTypes.add(superType);
             }
    +        return type;
    +    }
     
    -        @Override
    -        public String getVersion() {
    -            return version;
    -        }
    -        
    -        @Override
    -        public Collection<OsgiBundleWithUrl> getLibraries() {
    -            return bundles;
    +    @Beta
    +    public static RegisteredType addSuperType(RegisteredType type, 
@Nullable RegisteredType superType) {
    +        if (superType!=null) {
    +            if (isSubTypeOf(superType, type)) {
    +                throw new IllegalStateException(superType+" declares 
"+type+" as a supertype; cannot set "+superType+" as a supertype of "+type);
    +            }
    +            ((BasicRegisteredType)type).superTypes.add(superType);
             }
    +        return type;
    +    }
     
    -        @Override
    -        public String getDisplayName() {
    -            return displayName;
    -        }
    +    /** returns the implementation data for a spec if it is a string (e.g. 
plan yaml or java class name); else false */
    --- End diff --
    
    ; else null


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to