1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.objectweb.fractal.cecilia.adl.components;
25
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.Map;
29
30 import org.objectweb.fractal.adl.ADLException;
31 import org.objectweb.fractal.adl.Definition;
32 import org.objectweb.fractal.adl.components.Component;
33 import org.objectweb.fractal.adl.components.ComponentContainer;
34 import org.objectweb.fractal.api.NoSuchInterfaceException;
35 import org.objectweb.fractal.api.control.BindingController;
36 import org.objectweb.fractal.api.control.IllegalBindingException;
37 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
38 import org.objectweb.fractal.cecilia.adl.Checker;
39
40
41
42
43
44
45 public class ComponentChecker implements Checker, BindingController {
46
47
48
49
50
51
52
53
54
55 public static final String PRIMITIVE_CHECKER_ITF = "primitive-checker";
56
57
58 protected PrimitiveChecker primitiveCheckerItf;
59
60
61
62
63
64 public void check(final Definition definition,
65 final Map<Object, Object> context) throws ADLException {
66 if (definition instanceof ComponentContainer) {
67 check(new ArrayList<ComponentContainer>(),
68 (ComponentContainer) definition, context);
69 }
70 }
71
72
73
74
75
76 void check(final List<ComponentContainer> path,
77 final ComponentContainer container, final Map<Object, Object> context)
78 throws ADLException {
79 primitiveCheckerItf.beforeSubComponentCheck(path, container, context);
80 path.add(container);
81 final Component[] comps = container.getComponents();
82 for (final Component element : comps) {
83 check(path, element, context);
84 }
85 path.remove(path.size() - 1);
86
87 primitiveCheckerItf.afterSubComponentCheck(path, container, context);
88 }
89
90 public void bindFc(final String itfName, final Object value)
91 throws NoSuchInterfaceException, IllegalBindingException,
92 IllegalLifeCycleException {
93
94 if (itfName == null) {
95 throw new IllegalArgumentException("Interface name can't be null");
96 }
97
98 if (itfName.equals(PRIMITIVE_CHECKER_ITF)) {
99 try {
100 this.primitiveCheckerItf = (PrimitiveChecker) value;
101 } catch (final RuntimeException e) {
102 e.printStackTrace();
103 throw new IllegalBindingException("Unmatching types for interface '"
104 + itfName + "'");
105 }
106 } else {
107 throw new NoSuchInterfaceException("There is no interface named '"
108 + itfName + "'");
109 }
110
111 }
112
113 public String[] listFc() {
114 return new String[]{PRIMITIVE_CHECKER_ITF};
115 }
116
117 public Object lookupFc(final String itfName) throws NoSuchInterfaceException {
118
119 if (itfName == null) {
120 throw new IllegalArgumentException("Interface name can't be null");
121 }
122
123 if (itfName.equals(PRIMITIVE_CHECKER_ITF)) {
124
125 return this.primitiveCheckerItf;
126 } else {
127 throw new NoSuchInterfaceException("There is no interface named '"
128 + itfName + "'");
129 }
130 }
131
132 public void unbindFc(final String itfName) throws NoSuchInterfaceException,
133 IllegalBindingException, IllegalLifeCycleException {
134
135 if (itfName == null) {
136 throw new IllegalArgumentException("Interface name can't be null");
137 }
138
139 if (itfName.equals(PRIMITIVE_CHECKER_ITF)) {
140
141 this.primitiveCheckerItf = null;
142 } else {
143 throw new NoSuchInterfaceException("There is no interface named '"
144 + itfName + "'");
145 }
146 }
147 }