Provides_Type provides = ctx.getProvides();
Requires_Type requires = ctx.getRequires();
if (provides == null && requires == null) {
throw new ContextBrokerException("Both provides and " +
"requires are missing. Will not contextualize this. " +
"If there is nothing to do, do not include " +
"contextualization document.");
}
if (provides != null) {
IdentityProvides_Type[] givenIDs = provides.getIdentity();
if (givenIDs == null || givenIDs.length == 0) {
throw new ContextBrokerException("Provides section is " +
"present but has no identity elements. Will not " +
"contextualize.");
}
}
if (requires == null) {
return;
}
Requires_TypeIdentity[] givenID = requires.getIdentity();
if (givenID == null || givenID.length == 0) {
return;
}
// next two exceptions are for forwards compatibility where it
// may be possible to specify specific identities required
// (without going through role finding which will always place
// identities in the filled requires document for a role,
// regardless if all identities are required or not).
if (givenID.length > 1) {
throw new ContextBrokerException("Given requires " +
"section has multiple identity elements? Currently " +
"only supporting zero or one empty identity element " +
"in requires section (which signals all identities " +
"are desired). Will not contextualize.");
}
if (givenID[0].getHostname() != null ||
givenID[0].getIp() != null ||
givenID[0].getPubkey() != null) {
throw new ContextBrokerException("Given requires " +
"section has an identity element with information " +
"in it? Currently only supporting zero or one " +
"*empty* identity element in requires section " +
"(which signals all identities are desired). Will " +
"not contextualize.");