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 package org.objectweb.fractal.cecilia.composite.c.controllers;
26
27 import static org.objectweb.fractal.cecilia.adl.controllers.ControllerInterface.BC;
28 import static org.objectweb.fractal.cecilia.adl.controllers.ControllerInterface.BINDING_CONTROLLER_SIGNATURE;
29 import static org.objectweb.fractal.cecilia.adl.controllers.ControllerInterface.CC;
30 import static org.objectweb.fractal.cecilia.adl.controllers.ControllerInterface.CI;
31 import static org.objectweb.fractal.cecilia.adl.controllers.ControllerInterface.COMPONENT_IDENTITY_SIGNATURE;
32 import static org.objectweb.fractal.cecilia.adl.controllers.ControllerInterface.CONTENT_CONTROLLER_SIGNATURE;
33 import static org.objectweb.fractal.cecilia.adl.controllers.ControllerInterface.LCC;
34 import static org.objectweb.fractal.cecilia.adl.controllers.ControllerInterface.LIFECYCLE_CONTROLLER_SIGNATURE;
35
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.Map;
39
40 import org.objectweb.fractal.adl.ADLException;
41 import org.objectweb.fractal.adl.attributes.AttributesContainer;
42 import org.objectweb.fractal.adl.components.ComponentContainer;
43 import org.objectweb.fractal.adl.error.GenericErrors;
44 import org.objectweb.fractal.adl.implementations.ImplementationContainer;
45 import org.objectweb.fractal.adl.interfaces.Interface;
46 import org.objectweb.fractal.adl.interfaces.InterfaceContainer;
47 import org.objectweb.fractal.adl.types.TypeInterface;
48 import org.objectweb.fractal.cecilia.adl.controllers.AbstractControllerChecker;
49
50
51
52
53 public class CompositeControllerLoader extends AbstractControllerChecker {
54
55 protected static final String DEFAULT_COMPOSITE = "fractal.lib.defaultComposite";
56
57
58
59
60
61 @Override
62 protected void checkComponent(final ComponentContainer container)
63 throws ADLException {
64 if (container instanceof ImplementationContainer
65 && (((ImplementationContainer) container).getImplementation() != null))
66 throw new ADLException(
67 GenericErrors.GENERIC_ERROR,
68 "This controller description can only be used for composite components",
69 container);
70
71 if (container instanceof AttributesContainer
72 && ((AttributesContainer) container).getAttributes() != null) {
73 throw new ADLException(GenericErrors.GENERIC_ERROR,
74 "This controller description does not allows "
75 + "attributes on composite component", container);
76 }
77 }
78
79 @Override
80 protected List<Interface> getControllerInterfaces(
81 final ComponentContainer container, final Map<Object, Object> context)
82 throws ADLException {
83 final List<Interface> controllerItfs = new ArrayList<Interface>();
84 final Interface ciItf = getComponentIdentityInterface(container, context);
85 if (ciItf != null) controllerItfs.add(ciItf);
86
87 final Interface bcItf = getBindingControllerInterface(container, context);
88 if (bcItf != null) controllerItfs.add(bcItf);
89
90 final Interface lccItf = getLifeCycleControllerInterface(container, context);
91 if (lccItf != null) controllerItfs.add(lccItf);
92
93 final Interface ccItf = getContentControllerInterface(container, context);
94 if (ccItf != null) controllerItfs.add(ccItf);
95
96 return controllerItfs;
97 }
98
99
100
101
102
103 protected Interface getComponentIdentityInterface(
104 final ComponentContainer container, final Map<Object, Object> context)
105 throws ADLException {
106 final TypeInterface ciItf = newServerInterfaceNode(CI,
107 COMPONENT_IDENTITY_SIGNATURE);
108 setItfCode(ciItf, context, DEFAULT_COMPOSITE);
109 return ciItf;
110 }
111
112 protected Interface getBindingControllerInterface(
113 final ComponentContainer container, final Map<Object, Object> context)
114 throws ADLException {
115 final TypeInterface bcItf = newServerInterfaceNode(BC,
116 BINDING_CONTROLLER_SIGNATURE);
117 setItfCode(bcItf, context, DEFAULT_COMPOSITE);
118 return bcItf;
119 }
120
121 protected Interface getLifeCycleControllerInterface(
122 final ComponentContainer container, final Map<Object, Object> context)
123 throws ADLException {
124 final InterfaceContainer itfContainer = (InterfaceContainer) container;
125 TypeInterface lccItf = getInterface(LCC, itfContainer);
126 if (lccItf == null) {
127 lccItf = newServerInterfaceNode(LCC, LIFECYCLE_CONTROLLER_SIGNATURE);
128 } else {
129 checkServerInterface(lccItf);
130
131 itfContainer.removeInterface(lccItf);
132 }
133 setItfCode(lccItf, context, DEFAULT_COMPOSITE);
134 return lccItf;
135 }
136
137 protected Interface getContentControllerInterface(
138 final ComponentContainer container, final Map<Object, Object> context)
139 throws ADLException {
140 final TypeInterface ccItf = newServerInterfaceNode(CC,
141 CONTENT_CONTROLLER_SIGNATURE);
142 setItfCode(ccItf, context, DEFAULT_COMPOSITE);
143 return ccItf;
144 }
145 }