01: package org.osbl;
02:
03: import org.apache.commons.logging.LogFactory;
04:
05: import java.util.*;
06:
07: public class ReferenceCheckers {
08: private static org.apache.commons.logging.Log LOG = LogFactory
09: .getLog(ReferenceCheckers.class);
10:
11: private final Map<Class, Set<ReferenceChecker>> checkers = new HashMap<Class, Set<ReferenceChecker>>();
12:
13: public void registerReferenceChecker(Class type,
14: ReferenceChecker referenceChecker) {
15: LOG.info("Register ReferenceChecker: "
16: + referenceChecker.getClass().getSimpleName() + " for "
17: + type.getSimpleName());
18: Set<ReferenceChecker> set = checkers.get(type);
19: if (set == null) {
20: set = new HashSet<ReferenceChecker>();
21: checkers.put(type, set);
22: }
23: set.add(referenceChecker);
24: }
25:
26: public Set<ReferenceChecker> get(Class type) {
27: return checkers.get(type);
28: }
29:
30: public List<Object> referenceChecks(Class type,
31: Collection<Object> objects) {
32: Set<ReferenceChecker> set = get(type);
33: if (set == null)
34: return null;
35:
36: List<Object> references = new LinkedList<Object>();
37: for (ReferenceChecker referenceChecker : set)
38: references.addAll(referenceChecker.check(objects));
39:
40: return references;
41: }
42: }
|