blob: 41df6858efd08cda28038acfe9f87867d455730f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*
* <copyright>
*
* Copyright (c) 2005-2006 Markus Voelter and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Voelter - Initial API and implementation
*
* </copyright>
*/
package org.eclipse.m2t.common.recipe.eval;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.m2t.common.recipe.core.Check;
import org.eclipse.m2t.common.recipe.core.CheckSet;
import org.eclipse.m2t.common.recipe.core.EvalStatus;
import org.eclipse.m2t.common.recipe.core.EvalTrigger;
import org.eclipse.m2t.common.recipe.core.EvaluationStop;
public class CheckEvaluator {
private List<CheckEvaluationListener> listeners;
private EvaluationContext context;
public CheckEvaluator( EvaluationContext c ) {
this.context = c;
}
public void addListener( CheckEvaluationListener l ) {
if ( listeners == null ) listeners = new ArrayList<CheckEvaluationListener>();
listeners.add( l );
}
protected void notify( Check c, boolean checked ) {
if ( listeners == null ) return;
for (Iterator<CheckEvaluationListener> iter = listeners.iterator(); iter.hasNext();) {
CheckEvaluationListener l = iter.next();
l.evaluated(c, checked);
}
}
public void evaluate( CheckSet checks ) {
context.setCheckEvaluator(this);
if ( checks != null ) {
for (Iterator<Check> iter = checks.getChecks().iterator(); iter.hasNext();) {
Check c = iter.next();
evaluate( c );
}
}
}
public void evaluate( Check c ) {
context.setCheckEvaluator(this);
if ( ( c.getTrigger() == EvalTrigger.ON_CHANGE && context.evaluateOnChangeTriggeredCheck() ) ||
( c.getTrigger() == EvalTrigger.ON_REQUEST && context.evaluateOnRequestTriggeredCheck() ) ) {
if ( context.reevaluateAlreadyEvaluated() ) {
try {
c.evaluate( context );
} catch ( EvaluationStop ignore ) {}
notify(c, true);
} else {
if ( c.getStatus() != EvalStatus.OK ) {
try {
c.evaluate( context );
} catch ( EvaluationStop ignore ) {}
notify(c, true);
} else {
notify(c,false);
}
}
}
}
}
|