}
protected AAssociateAC negotiate(Association as, AAssociateRQ rq)
throws IOException {
if ((rq.getProtocolVersion() & 1) == 0)
throw new AAssociateRJ(AAssociateRJ.RESULT_REJECTED_PERMANENT,
AAssociateRJ.SOURCE_SERVICE_PROVIDER_ACSE,
AAssociateRJ.REASON_PROTOCOL_VERSION_NOT_SUPPORTED);
if (!rq.getApplicationContext().equals(
UID.DICOMApplicationContextName))
throw new AAssociateRJ(AAssociateRJ.RESULT_REJECTED_PERMANENT,
AAssociateRJ.SOURCE_SERVICE_USER,
AAssociateRJ.REASON_APP_CTX_NAME_NOT_SUPPORTED);
ApplicationEntity ae = as.getApplicationEntity();
if (ae == null || !ae.getConnections().contains(as.getConnection())
|| !ae.isInstalled() || !ae.isAssociationAcceptor())
throw new AAssociateRJ(AAssociateRJ.RESULT_REJECTED_PERMANENT,
AAssociateRJ.SOURCE_SERVICE_USER,
AAssociateRJ.REASON_CALLED_AET_NOT_RECOGNIZED);
if (!ae.isAcceptedCallingAETitle(rq.getCallingAET()))
throw new AAssociateRJ(AAssociateRJ.RESULT_REJECTED_PERMANENT,
AAssociateRJ.SOURCE_SERVICE_USER,
AAssociateRJ.REASON_CALLING_AET_NOT_RECOGNIZED);
UserIdentityAC userIdentity = getUserIdNegotiator() != null
? getUserIdNegotiator().negotiate(as, rq.getUserIdentityRQ())
: null;
if (ae.getDevice().isLimitOfOpenAssociationsExceeded())
throw new AAssociateRJ(AAssociateRJ.RESULT_REJECTED_TRANSIENT,
AAssociateRJ.SOURCE_SERVICE_PROVIDER_ACSE,
AAssociateRJ.REASON_LOCAL_LIMIT_EXCEEDED);
return makeAAssociateAC(as, rq, userIdentity);
}