public PolicyResult resolveCallbackPolicies(LogicalBinding<?> binding) throws PolicyResolutionException { LogicalBinding<RemoteBindingDefinition> remoteBinding = new LogicalBinding<>(RemoteBindingDefinition.INSTANCE, binding.getParent()); Bindable bindable = binding.getParent(); if (bindable instanceof LogicalReference) { return resolvePolicies(bindable.getCallbackOperations(), remoteBinding, binding, bindable.getParent(), null); } else if (bindable instanceof LogicalService) { return resolvePolicies(bindable.getCallbackOperations(), remoteBinding, binding, bindable.getParent(), null); } else { throw new IllegalArgumentException("Only services and references can have callback operations"); } }
/** * Matches operation definitions on the source and target sides of a wire so that policy sets and intents can be determined. Note that if the source * operation belongs to a service, the wire is a callback wire. * * @param operation the source operation to match against. * @param bindable the target bindable. * @return the matching operation * @throws PolicyResolutionException if there is a matching error */ private LogicalOperation matchOperation(LogicalOperation operation, Bindable bindable) throws PolicyResolutionException { String name = operation.getDefinition().getName(); List<LogicalOperation> operations; if (bindable instanceof LogicalReference) { // target is a reference so this is a callback operations = bindable.getCallbackOperations(); } else { operations = bindable.getOperations(); } try { LogicalOperation matched = operationResolver.resolve(operation, operations); if (matched == null) { throw new AssertionError("No matching operation for " + name); } return matched; } catch (OperationNotFoundException e) { throw new PolicyResolutionException(e); } }