public ContextInstance getContextInstance(final Context context) {
ContextInstanceFactoryRegistry contextRegistry =
((InternalRuleBase) ((ProcessInstance) getProcessInstance())
.getWorkingMemory().getRuleBase())
.getConfiguration().getProcessContextInstanceFactoryRegistry();
ContextInstanceFactory conf = contextRegistry.getContextInstanceFactory(context);
if (conf == null) {
throw new IllegalArgumentException("Illegal context type (registry not found): " + context.getClass());
}
ContextInstance contextInstance = (ContextInstance) conf.getContextInstance(context, this, (ProcessInstance) getProcessInstance());
if (contextInstance == null) {
throw new IllegalArgumentException("Illegal context type (instance not found): " + context.getClass());
}
return contextInstance;
}