// First check that the requested type of managed object
// corresponds to the path.
AbstractManagedObjectDefinition<?, ?> supr = target
.getManagedObjectDefinition();
if (!supr.isParentOf(d)) {
throw new DefaultBehaviorException(
nextProperty, new DefinitionDecodingException(supr,
Reason.WRONG_TYPE_INFORMATION));
}
// Save the current property in case of recursion.
PropertyDefinition<T> pd1 = nextProperty;
try {
// Determine the requested property definition.
PropertyDefinition<T> pd2;
try {
// FIXME: we use the definition taken from the default
// behavior here when we should really use the exact
// definition of the component being created.
PropertyDefinition<?> pdTmp = d.getPropertyDefinition(propertyName);
pd2 = pd1.getClass().cast(pdTmp);
} catch (IllegalArgumentException e) {
throw new PropertyNotFoundException(propertyName);
} catch (ClassCastException e) {
// FIXME: would be nice to throw a better exception here.
throw new PropertyNotFoundException(propertyName);
}
// If the path relates to the current managed object and the
// managed object is in the process of being created it won't
// exist, so we should just use the default values of the
// referenced property.
if (isCreate && firstPath.equals(target)) {
// Recursively retrieve this property's default values.
Collection<T> tmp = find(target, pd2);
Collection<T> values = new ArrayList<T>(tmp.size());
for (T value : tmp) {
pd1.validateValue(value);
values.add(value);
}
return values;
} else {
// FIXME: issue 2481 - this is broken if the referenced property
// inherits its defaults from the newly created managed object.
return getPropertyValues(target, pd2);
}
} catch (DefaultBehaviorException e) {
// Wrap any errors due to recursion.
throw new DefaultBehaviorException(pd1, e);
} catch (DefinitionDecodingException e) {
throw new DefaultBehaviorException(pd1, e);
} catch (PropertyNotFoundException e) {
throw new DefaultBehaviorException(pd1, e);
} catch (AuthorizationException e) {
throw new DefaultBehaviorException(pd1, e);
} catch (ManagedObjectNotFoundException e) {
throw new DefaultBehaviorException(pd1, e);
} catch (CommunicationException e) {
throw new DefaultBehaviorException(pd1, e);
} catch (PropertyException e) {
throw new DefaultBehaviorException(pd1, e);
}
}