1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.impl; |
16 |
| |
17 |
| import java.util.List; |
18 |
| |
19 |
| import org.apache.hivemind.ApplicationRuntimeException; |
20 |
| import org.apache.hivemind.ErrorLog; |
21 |
| import org.apache.hivemind.Occurances; |
22 |
| import org.apache.hivemind.ServiceImplementationFactory; |
23 |
| import org.apache.hivemind.ServiceImplementationFactoryParameters; |
24 |
| import org.apache.hivemind.internal.Module; |
25 |
| import org.apache.hivemind.internal.ServiceImplementationConstructor; |
26 |
| import org.apache.hivemind.internal.ServicePoint; |
27 |
| import org.apache.hivemind.schema.Schema; |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| public final class InvokeFactoryServiceConstructor extends BaseLocatable implements |
36 |
| ServiceImplementationConstructor |
37 |
| { |
38 |
| private String _factoryServiceId; |
39 |
| |
40 |
| private ServicePoint _serviceExtensionPoint; |
41 |
| |
42 |
| private Module _contributingModule; |
43 |
| |
44 |
| |
45 |
| private List _parameters; |
46 |
| |
47 |
| |
48 |
| private ServiceImplementationFactory _factory; |
49 |
| |
50 |
| |
51 |
| private List _convertedParameters; |
52 |
| |
53 |
791
| public Object constructCoreServiceImplementation()
|
54 |
| { |
55 |
791
| setupFactoryAndParameters();
|
56 |
| |
57 |
791
| try
|
58 |
| { |
59 |
791
| ServiceImplementationFactoryParameters factoryParameters = new ServiceImplementationFactoryParametersImpl(
|
60 |
| _serviceExtensionPoint, _contributingModule, _convertedParameters); |
61 |
| |
62 |
791
| return _factory.createCoreServiceImplementation(factoryParameters);
|
63 |
| } |
64 |
| catch (Exception ex) |
65 |
| { |
66 |
0
| throw new ApplicationRuntimeException(ex.getMessage(), getLocation(), ex);
|
67 |
| } |
68 |
| } |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
791
| private synchronized void setupFactoryAndParameters()
|
75 |
| { |
76 |
791
| if (_factory == null)
|
77 |
| { |
78 |
489
| ServicePoint factoryPoint = _contributingModule.getServicePoint(_factoryServiceId);
|
79 |
| |
80 |
489
| Occurances expected = factoryPoint.getParametersCount();
|
81 |
| |
82 |
489
| _factory = (ServiceImplementationFactory) factoryPoint
|
83 |
| .getService(ServiceImplementationFactory.class); |
84 |
| |
85 |
489
| Schema schema = factoryPoint.getParametersSchema();
|
86 |
| |
87 |
489
| ErrorLog errorLog = _serviceExtensionPoint.getErrorLog();
|
88 |
| |
89 |
489
| SchemaProcessorImpl processor = new SchemaProcessorImpl(errorLog, schema);
|
90 |
| |
91 |
489
| processor.process(_parameters, _contributingModule);
|
92 |
| |
93 |
489
| _convertedParameters = processor.getElements();
|
94 |
| |
95 |
489
| checkParameterCounts(errorLog, expected);
|
96 |
| } |
97 |
| } |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
489
| private void checkParameterCounts(ErrorLog log, Occurances expected)
|
103 |
| { |
104 |
489
| int actual = _convertedParameters.size();
|
105 |
| |
106 |
489
| if (expected.inRange(actual))
|
107 |
488
| return;
|
108 |
| |
109 |
1
| String message = ImplMessages.wrongNumberOfParameters(_factoryServiceId, actual, expected);
|
110 |
| |
111 |
1
| log.error(message, getLocation(), null);
|
112 |
| } |
113 |
| |
114 |
1
| public Module getContributingModule()
|
115 |
| { |
116 |
1
| return _contributingModule;
|
117 |
| } |
118 |
| |
119 |
1283
| public void setContributingModule(Module module)
|
120 |
| { |
121 |
1283
| _contributingModule = module;
|
122 |
| } |
123 |
| |
124 |
1
| public List getParameters()
|
125 |
| { |
126 |
1
| return _parameters;
|
127 |
| } |
128 |
| |
129 |
1
| public ServicePoint getServiceExtensionPoint()
|
130 |
| { |
131 |
1
| return _serviceExtensionPoint;
|
132 |
| } |
133 |
| |
134 |
1283
| public void setParameters(List list)
|
135 |
| { |
136 |
1283
| _parameters = list;
|
137 |
| } |
138 |
| |
139 |
1282
| public void setFactoryServiceId(String string)
|
140 |
| { |
141 |
1282
| _factoryServiceId = string;
|
142 |
| } |
143 |
| |
144 |
1283
| public void setServiceExtensionPoint(ServicePoint point)
|
145 |
| { |
146 |
1283
| _serviceExtensionPoint = point;
|
147 |
| } |
148 |
| |
149 |
| } |