// it's not a URL, so we can't handle this reference
return new PolicyFinderResult();
}
// try resolving the URL
AbstractPolicy policy = null;
try {
policy = reader.readPolicy(url);
} catch (ParsingException pe) {
// An error loading the policy could be many things (the URL
// doesn't actually resolve a policy, the server is down, the
// policy is invalid, etc.). This could be interpreted as an
// error case, or simply as a case where no applicable policy
// is available (as is done when we pre-load policies). This
// module chooses the latter interpretation.
return new PolicyFinderResult();
}
// check that we got the right kind of policy...if we didn't, then
// we can't handle the reference
if (type == PolicyReference.POLICY_REFERENCE) {
if (!(policy instanceof Policy))
return new PolicyFinderResult();
} else {
if (!(policy instanceof PolicySet))
return new PolicyFinderResult();
}
// finally, check that the constraints match ... note that in a more
// powerful module, you could actually have used the constraints to
// construct a more specific URL, passed the constraints to the
// server, etc., but this example module is staying simple
if (!constraints.meetsConstraint(policy.getVersion()))
return new PolicyFinderResult();
// if we got here, then we successfully resolved a policy that is
// the correct type, so return it
return new PolicyFinderResult(policy);