|
|||||||||||||||||||
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 | |||||||||||||||
CreateClassServiceConstructor.java | 100% | 91.7% | 100% | 95% |
|
1 |
// Copyright 2004 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 org.apache.hivemind.ApplicationRuntimeException;
|
|
18 |
import org.apache.hivemind.ClassResolver;
|
|
19 |
import org.apache.hivemind.internal.Module;
|
|
20 |
import org.apache.hivemind.internal.ServiceImplementationConstructor;
|
|
21 |
import org.apache.hivemind.util.ConstructorUtils;
|
|
22 |
|
|
23 |
/**
|
|
24 |
* Constructs a service by instantiating a class.
|
|
25 |
*
|
|
26 |
* @author Howard Lewis Ship
|
|
27 |
*/
|
|
28 |
public final class CreateClassServiceConstructor |
|
29 |
extends BaseLocatable
|
|
30 |
implements ServiceImplementationConstructor
|
|
31 |
{ |
|
32 |
private Module _contributingModule;
|
|
33 |
private String _instanceClassName;
|
|
34 |
private Class _instanceClass;
|
|
35 |
|
|
36 | 195 |
public Object constructCoreServiceImplementation()
|
37 |
{ |
|
38 | 195 |
Class instanceClass = getInstanceClass(); |
39 |
|
|
40 | 195 |
return ConstructorUtils.invokeConstructor(instanceClass, null); |
41 |
} |
|
42 |
|
|
43 | 195 |
private synchronized Class getInstanceClass() |
44 |
{ |
|
45 | 195 |
if (_instanceClass == null) |
46 |
{ |
|
47 | 194 |
try
|
48 |
{ |
|
49 | 194 |
ClassResolver resolver = _contributingModule.getClassResolver(); |
50 |
|
|
51 | 194 |
_instanceClass = resolver.findClass(_instanceClassName); |
52 |
} |
|
53 |
catch (Exception ex)
|
|
54 |
{ |
|
55 | 0 |
throw new ApplicationRuntimeException(ex.getMessage(), getLocation(), ex); |
56 |
} |
|
57 |
} |
|
58 |
|
|
59 | 195 |
return _instanceClass;
|
60 |
} |
|
61 |
|
|
62 | 1 |
public Module getContributingModule()
|
63 |
{ |
|
64 | 1 |
return _contributingModule;
|
65 |
} |
|
66 |
|
|
67 | 1 |
public String getInstanceClassName()
|
68 |
{ |
|
69 | 1 |
return _instanceClassName;
|
70 |
} |
|
71 |
|
|
72 | 611 |
public void setContributingModule(Module module) |
73 |
{ |
|
74 | 611 |
_contributingModule = module; |
75 |
} |
|
76 |
|
|
77 | 611 |
public void setInstanceClassName(String string) |
78 |
{ |
|
79 | 611 |
_instanceClassName = string; |
80 |
} |
|
81 |
|
|
82 |
} |
|
83 |
|
|