1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.service.impl; |
16 |
| |
17 |
| import java.util.HashMap; |
18 |
| import java.util.Map; |
19 |
| |
20 |
| import org.apache.hivemind.Location; |
21 |
| import org.apache.hivemind.ServiceImplementationFactoryParameters; |
22 |
| import org.apache.hivemind.internal.Module; |
23 |
| import org.apache.hivemind.schema.Translator; |
24 |
| import org.apache.hivemind.util.ConstructorUtils; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public class BuilderPropertyFacet extends BuilderFacet |
34 |
| { |
35 |
| private String _translatorName; |
36 |
| |
37 |
| private String _literalValue; |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| private Map _valuesCache = new HashMap(); |
44 |
| |
45 |
446
| public Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters,
|
46 |
| Class targetType) |
47 |
| { |
48 |
446
| Object result = _valuesCache.get(targetType);
|
49 |
| |
50 |
446
| if (result == null)
|
51 |
| { |
52 |
437
| Translator translator = factoryParameters.getInvokingModule().getTranslator(
|
53 |
| _translatorName); |
54 |
| |
55 |
437
| result = translator.translate(
|
56 |
| factoryParameters.getInvokingModule(), |
57 |
| targetType, |
58 |
| _literalValue, |
59 |
| getLocation()); |
60 |
| |
61 |
435
| _valuesCache.put(targetType, result);
|
62 |
| } |
63 |
| |
64 |
444
| return result;
|
65 |
| } |
66 |
| |
67 |
21
| public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters,
|
68 |
| Class targetType) |
69 |
| { |
70 |
| |
71 |
21
| Object facetValue = getFacetValue(factoryParameters, targetType);
|
72 |
| |
73 |
20
| if (facetValue == null)
|
74 |
1
| return !targetType.isPrimitive();
|
75 |
| |
76 |
19
| return ConstructorUtils.isCompatible(targetType, facetValue.getClass());
|
77 |
| } |
78 |
| |
79 |
| |
80 |
426
| public void setTranslator(String translatorName)
|
81 |
| { |
82 |
426
| _translatorName = translatorName;
|
83 |
| } |
84 |
| |
85 |
425
| public void setValue(String value)
|
86 |
| { |
87 |
425
| _literalValue = value;
|
88 |
| } |
89 |
| |
90 |
| } |