this.bindAction = bindAction;
}
public boolean onCreate(ModelRuleDescriptor creatorDescriptor, ModelPath path, ModelPromise promise) {
if (boundTo != null && isTypeCompatible(promise)) {
throw new InvalidModelRuleException(descriptor, new ModelRuleBindingException(
new AmbiguousBindingReporter(reference, boundTo, boundToCreator, path, creatorDescriptor).asString()
));
} else if (reference.getPath() == null) {
boolean typeCompatible = isTypeCompatible(promise);
if (typeCompatible) {
bindAction.execute(path);
boundTo = path;
boundToCreator = creatorDescriptor;
return false; // don't unregister listener, need to keep listening for other potential bindings
}
} else if (path.equals(reference.getPath())) {
boolean typeCompatible = isTypeCompatible(promise);
if (typeCompatible) {
bindAction.execute(path);
return true; // bound by type and path, stop listening
} else {
throw new InvalidModelRuleException(descriptor, new ModelRuleBindingException(
IncompatibleTypeReferenceReporter.of(creatorDescriptor, promise, reference, writable).asString()
));
}
}