String subjectURN = Val.chkStr(context.getRequestOptions().getSubject());
String predicateURN = Val.chkStr(context.getRequestOptions().getPredicate());
boolean wasSubjectRecognized = false;
boolean wasPredicateRecognized = false;
if (subjectURN.length() == 0) {
throw new AsnInvalidOperationException("The subject URN was empty.");
} else if (predicateURN.length() == 0) {
throw new AsnInvalidOperationException("The predicate URN was empty.");
} else {
for (AsnOperation configuredOp: this.operations) {
AsnSubject subject = configuredOp.getSubject();
AsnPredicate predicate = configuredOp.getPredicate();
if ((subject != null) && (predicate != null)) {
boolean subjectFound = false;
String stPfx = Val.chkStr(subject.getURNPrefix());
if (subject.getRequiresValuePart()) {
if (!stPfx.endsWith(":")) stPfx += ":";
subjectFound = subjectURN.startsWith(stPfx);
} else {
subjectFound = subjectURN.equals(stPfx);
}
if (subjectFound) {
wasSubjectRecognized = true;
String ptUrn = Val.chkStr(predicate.getURN());
if (predicateURN.equals(ptUrn)) {
wasPredicateRecognized = true;
if (subject.getRequiresValuePart()) {
String subjValuePart = subjectURN.substring(stPfx.length());
if (subjValuePart.length() == 0) {
String msg = "The value part of the subject URN was empty "+subjectURN;
throw new AsnInvalidOperationException(msg);
} else {
operation = configuredOp.duplicate();
operation.getSubject().setURN(subjectURN);
operation.getSubject().setValuePart(subjValuePart);
}
} else {
operation = configuredOp.duplicate();
operation.getSubject().setURN(subjectURN);
}
}
} else if (!wasPredicateRecognized) {
String ptUrn = Val.chkStr(predicate.getURN());
if (predicateURN.equals(ptUrn)) {
wasPredicateRecognized = true;
}
}
}
}
}
if (operation == null) {
if (!wasSubjectRecognized) {
String msg = "The subject URN was not recognized "+subjectURN;
throw new AsnInvalidOperationException(msg);
} else if (!wasPredicateRecognized) {
String msg = "The predicate URN was not recognized "+predicateURN;
throw new AsnInvalidOperationException(msg);
} else {
throw new AsnInvalidOperationException();
}
} else {
return operation;
}
}