brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahgittin <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Flesh out type creation using the...
Date Tue, 17 Nov 2015 10:28:44 GMT
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1017#discussion_r45043213
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
---
    @@ -90,31 +96,95 @@ public RegisteredType get(String symbolicNameWithOptionalVersion,
RegisteredType
     
         @Override
         public RegisteredType get(String symbolicNameWithOptionalVersion) {
    -        return get(symbolicNameWithOptionalVersion, (RegisteredTypeConstraint)null);
    +        return get(symbolicNameWithOptionalVersion, (RegisteredTypeLoadingContext)null);
         }
     
         @SuppressWarnings({ "deprecation", "unchecked", "rawtypes" })
         @Override
    -    public <SpecT extends AbstractBrooklynObjectSpec<?,?>> SpecT createSpec(RegisteredType
type, @Nullable RegisteredTypeConstraint constraint, Class<SpecT> specSuperType) {
    -        if (!(type instanceof RegisteredSpecType)) { 
    -            throw new IllegalStateException("Cannot create spec from type "+type);
    +    public <SpecT extends AbstractBrooklynObjectSpec<?,?>> SpecT createSpec(RegisteredType
type, @Nullable RegisteredTypeLoadingContext constraint, Class<SpecT> specSuperType)
{
    +        Preconditions.checkNotNull(type, "type");
    +        if (type.getKind()!=RegisteredTypeKind.SPEC) { 
    +            throw new IllegalStateException("Cannot create spec from type "+type+" (kind
"+type.getKind()+")");
             }
             if (constraint!=null) {
    -            if (constraint.getKind()!=null && constraint.getKind()!=RegisteredTypeKind.SPEC)
{
    +            if (constraint.getExpectedKind()!=null && constraint.getExpectedKind()!=RegisteredTypeKind.SPEC)
{
                     throw new IllegalStateException("Cannot create spec with constraint "+constraint);
                 }
    -            if (constraint.getEncounteredTypes().contains(type.getSymbolicName())) {
    +            if (constraint.getAlreadyEncounteredTypes().contains(type.getSymbolicName()))
{
                     // avoid recursive cycle
                     // TODO implement using java if permitted
                 }
             }
    -        constraint = RegisteredTypeConstraints.extendedWithSpecSuperType(constraint,
specSuperType);
    +        constraint = RegisteredTypeLoadingContexts.withSpecSuperType(constraint, specSuperType);
     
    -        // TODO look up in the actual registry
    +        Maybe<Object> result = TypePlanTransformers.transform(mgmt, type, constraint);
    +        if (result.isPresent()) return (SpecT) result.get();
             
             // fallback: look up in (legacy) catalog
    +        // TODO remove once all transformers are available in the new style
             CatalogItem item = (CatalogItem) mgmt.getCatalog().getCatalogItem(type.getSymbolicName(),
type.getVersion());
    -        return (SpecT) BasicBrooklynCatalog.internalCreateSpecWithTransformers(mgmt,
item, constraint.getEncounteredTypes());
    +        if (item==null) {
    +            // if not in catalog (because loading a new item?) then look up item based
on type
    +            // (only really used in tests; possibly also for any recursive legacy transformers
we might have to create a CI; cross that bridge when we come to it)
    +            CatalogItemType ciType = CatalogItemType.ofTargetClass( (Class)constraint.getExpectedJavaSuperType()
);
    --- End diff --
    
    this is a port of old logic; the TODO above notes we want to remove the block


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message