brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Flesh out type creation using the...
Date Thu, 12 Nov 2015 09:00:36 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1017#discussion_r44633926
  
    --- 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 --
    
    No point in adding code to support tests, better adapt the tests?
    Also don't get the recursive transformers comment, can you give an example.


---
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