|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
InvokeFactoryServiceConstructor.java | 100% | 96.2% | 100% | 97.4% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
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 |
* Constructs a new service by invoking methods on another service (which implements the
|
|
31 |
* {@link org.apache.hivemind.ServiceImplementationFactory}interface.
|
|
32 |
*
|
|
33 |
* @author Howard Lewis Ship
|
|
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 |
/** List of {@link org.apache.hivemind.Element}, the raw XML parameters. */
|
|
45 |
private List _parameters;
|
|
46 |
|
|
47 |
/** The factory service to be invoked. */
|
|
48 |
private ServiceImplementationFactory _factory;
|
|
49 |
|
|
50 |
/** The parameters converted to objects as per the factory's parameter schema. */
|
|
51 |
private List _convertedParameters;
|
|
52 |
|
|
53 |
// TODO: Should this method be synchronized?
|
|
54 |
|
|
55 | 430 |
public Object constructCoreServiceImplementation()
|
56 |
{ |
|
57 | 430 |
if (_factory == null) |
58 |
{ |
|
59 | 390 |
ServicePoint factoryPoint = _contributingModule.getServicePoint(_factoryServiceId); |
60 |
|
|
61 | 390 |
Occurances expected = factoryPoint.getParametersCount(); |
62 |
|
|
63 | 390 |
_factory = (ServiceImplementationFactory) factoryPoint |
64 |
.getService(ServiceImplementationFactory.class);
|
|
65 |
|
|
66 | 390 |
Schema schema = factoryPoint.getParametersSchema(); |
67 |
|
|
68 | 390 |
ErrorLog errorLog = _serviceExtensionPoint.getErrorLog(); |
69 |
|
|
70 | 390 |
SchemaProcessorImpl processor = new SchemaProcessorImpl(errorLog, schema);
|
71 |
|
|
72 | 390 |
processor.process(_parameters, _contributingModule); |
73 |
|
|
74 | 390 |
_convertedParameters = processor.getElements(); |
75 |
|
|
76 | 390 |
checkParameterCounts(errorLog, expected); |
77 |
} |
|
78 |
|
|
79 | 430 |
try
|
80 |
{ |
|
81 | 430 |
ServiceImplementationFactoryParameters factoryParameters = new ServiceImplementationFactoryParametersImpl(
|
82 |
_serviceExtensionPoint, _contributingModule, _convertedParameters); |
|
83 |
|
|
84 | 430 |
return _factory.createCoreServiceImplementation(factoryParameters);
|
85 |
} |
|
86 |
catch (Exception ex)
|
|
87 |
{ |
|
88 | 0 |
throw new ApplicationRuntimeException(ex.getMessage(), getLocation(), ex); |
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
/**
|
|
93 |
* Checks that the number of parameter elements matches the expected count.
|
|
94 |
*/
|
|
95 | 390 |
private void checkParameterCounts(ErrorLog log, Occurances expected) |
96 |
{ |
|
97 | 390 |
int actual = _convertedParameters.size();
|
98 |
|
|
99 | 390 |
if (expected.inRange(actual))
|
100 | 389 |
return;
|
101 |
|
|
102 | 1 |
String message = ImplMessages.wrongNumberOfParameters(_factoryServiceId, actual, expected); |
103 |
|
|
104 | 1 |
log.error(message, getLocation(), null);
|
105 |
} |
|
106 |
|
|
107 | 1 |
public Module getContributingModule()
|
108 |
{ |
|
109 | 1 |
return _contributingModule;
|
110 |
} |
|
111 |
|
|
112 | 885 |
public void setContributingModule(Module module) |
113 |
{ |
|
114 | 885 |
_contributingModule = module; |
115 |
} |
|
116 |
|
|
117 | 1 |
public List getParameters()
|
118 |
{ |
|
119 | 1 |
return _parameters;
|
120 |
} |
|
121 |
|
|
122 | 1 |
public ServicePoint getServiceExtensionPoint()
|
123 |
{ |
|
124 | 1 |
return _serviceExtensionPoint;
|
125 |
} |
|
126 |
|
|
127 | 885 |
public void setParameters(List list) |
128 |
{ |
|
129 | 885 |
_parameters = list; |
130 |
} |
|
131 |
|
|
132 | 884 |
public void setFactoryServiceId(String string) |
133 |
{ |
|
134 | 884 |
_factoryServiceId = string; |
135 |
} |
|
136 |
|
|
137 | 885 |
public void setServiceExtensionPoint(ServicePoint point) |
138 |
{ |
|
139 | 885 |
_serviceExtensionPoint = point; |
140 |
} |
|
141 |
|
|
142 |
} |
|