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.types;
25
26 import java.util.List;
27 import java.util.Map;
28
29 import org.objectweb.fractal.adl.ADLException;
30 import org.objectweb.fractal.adl.ComponentVisitor;
31 import org.objectweb.fractal.adl.Definition;
32 import org.objectweb.fractal.adl.Node;
33 import org.objectweb.fractal.adl.components.ComponentContainer;
34 import org.objectweb.fractal.api.Component;
35 import org.objectweb.fractal.cecilia.adl.TypeNameProvider;
36 import org.objectweb.fractal.task.core.AbstractTaskFactoryUser;
37 import org.objectweb.fractal.task.core.TaskException;
38 import org.objectweb.fractal.task.core.primitive.annotations.ServerInterface;
39 import org.objectweb.fractal.task.core.primitive.annotations.ServerInterfaces;
40 import org.objectweb.fractal.task.core.primitive.annotations.TaskParameters;
41
42
43
44
45 public class TypeVisitor extends AbstractTaskFactoryUser
46 implements
47 ComponentVisitor {
48
49 public Component visit(final List<Node> path, final ComponentContainer node,
50 final Map<Object, Object> context) throws ADLException, TaskException {
51 return taskFactoryItf.newPrimitiveTask(new TypeNameProviderImpl(
52 getAbsoluteName(path, node)), node);
53 }
54
55
56
57
58
59 protected String getAbsoluteName(final List<Node> path,
60 final ComponentContainer container) {
61 String realname = getComponentName(container);
62 for (int i = path.size() - 1; i >= 0; i--)
63 realname = getComponentName(path.get(i)) + "/" + realname;
64 return realname;
65 }
66
67 protected String getComponentName(final Node container) {
68 if (container instanceof Definition)
69 return ((Definition) container).getName();
70 else if (container instanceof org.objectweb.fractal.adl.components.Component)
71 return ((org.objectweb.fractal.adl.components.Component) container)
72 .getName();
73 else
74 throw new IllegalArgumentException(
75 "The given node is neither a Definition nor a Component");
76 }
77
78
79
80
81
82
83
84
85 @TaskParameters("componentNode")
86 @ServerInterfaces(@ServerInterface(name = "type-name-provider", signature = TypeNameProvider.class, record = "role:typeNameProvider, id:%", parameters = "componentNode"))
87 public static class TypeNameProviderImpl implements TypeNameProvider {
88
89 protected final String typeName;
90 protected final String cTypeName;
91
92
93
94
95
96
97
98
99 public TypeNameProviderImpl(final String typeName) {
100 this.typeName = typeName;
101 cTypeName = typeName.replace('.', '_').replace('-', '_')
102 .replace('/', '_');
103 }
104
105
106
107
108
109 public String getTypeName() {
110 return typeName;
111 }
112
113 public String getCTypeName() {
114 return cTypeName;
115 }
116 }
117 }