Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/291#discussion_r74491248
--- Diff:
camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/methods/BrooklynDslCommon.java
---
@@ -384,24 +445,48 @@ public Object apply(List<Object> input) {
config.put(name,
((DeferredSupplier<?>) value).get());
}
}
- return create(type, fields, config);
+ if (factoryMethodName == null) {
+ return create(clazz, constructorArgs,
fields, config);
+ } else {
+ return create(clazz, factoryMethodName,
factoryMethodArgs, fields, config);
+ }
}
}, tasks);
}
- public static <T> T create(Class<T> type, Map<String,?> fields,
Map<String,?> config) {
+ public static <T> T create(Class<T> type, List<?> constructorArgs,
Map<String,?> fields, Map<String,?> config) {
try {
T bean;
try {
bean = (T) TypeCoercions.coerce(fields, type);
} catch (ClassCoercionException ex) {
- bean =
Reflections.invokeConstructorFromArgs(type).get();
+ bean = Reflections.invokeConstructorFromArgs(type,
constructorArgs.toArray()).get();
+ BeanUtils.populate(bean, fields);
+ }
+ if (bean instanceof Configurable && config.size() > 0) {
+ ConfigBag configBag = ConfigBag.newInstance(config);
+ FlagUtils.setFieldsFromFlags(bean, configBag);
+ FlagUtils.setAllConfigKeys((Configurable) bean,
configBag, true);
+ }
+ return bean;
+ } catch (Exception e) {
+ throw Exceptions.propagate(e);
+ }
+ }
+
+ public static Object create(Class<?> type, String
factoryMethodName, List<Object> factoryMethodArgs, Map<String,?> fields,
Map<String,?> config) {
+ try {
+ Object bean;
+ try {
+ bean = TypeCoercions.coerce(fields, type);
--- End diff --
I don't follow this line. Why are we trying to coerce the fields (which is
a map) to the expected object type?
Do we expect to support someone using `$brooklyn:object: { type: Map,
object.fields: { a: b } }` to instantiate a map with contents `{a: b}`?!
---
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.
---