public void internalTrigger(final NodeInstance from, String type) {
if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException(
"An ActionNode only accepts default incoming connections!");
}
final Join join = getJoin();
switch ( join.getType() ) {
case Join.TYPE_XOR :
triggerCompleted();
break;
case Join.TYPE_AND :
Integer count = (Integer) this.triggers.get( from.getNodeId() );
if ( count == null ) {
this.triggers.put( from.getNodeId(),
1 );
} else {
this.triggers.put( from.getNodeId(),
count.intValue() + 1 );
}
if (checkAllActivated()) {
decreaseAllTriggers();
triggerCompleted();
}
break;
case Join.TYPE_DISCRIMINATOR :
boolean triggerCompleted = triggers.isEmpty();
triggers.put( from.getNodeId(), new Integer( 1 ) );
if (checkAllActivated()) {
resetAllTriggers();
}
if (triggerCompleted) {
triggerCompleted();
}
break;
case Join.TYPE_N_OF_M :
count = (Integer) this.triggers.get( from.getNodeId() );
if ( count == null ) {
this.triggers.put( from.getNodeId(),
1 );
} else {
this.triggers.put( from.getNodeId(),
count.intValue() + 1 );
}
int counter = 0;
for (final Connection connection: getJoin().getDefaultIncomingConnections()) {
if ( this.triggers.get( connection.getFrom().getId() ) != null ) {
counter++;
}
}
String n = join.getN();
Integer number = null;
if (n.startsWith("#{") && n.endsWith("}")) {
n = n.substring(2, n.length() - 1);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
resolveContextInstance(VariableScope.VARIABLE_SCOPE, n);
if (variableScopeInstance == null) {
throw new IllegalArgumentException(
"Could not find variable " + n + " when executing join.");
}
Object value = variableScopeInstance.getVariable(n);
if (value instanceof Number) {
number = ((Number) value).intValue();
} else {
throw new IllegalArgumentException(
"Variable " + n + " did not return a number when executing join: " + value);
}
} else {
number = new Integer(n);
}
if (counter >= number) {
resetAllTriggers();
triggerCompleted();
}
break;
default :
throw new IllegalArgumentException( "Illegal join type " + join.getType() );
}
}