Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/1017#discussion_r45052574
--- 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) {
--- End diff --
Yes, this is what I'm trying to clear up in the next PR. Your reference is
helpful!
---
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.
---