|
|||||||||||||||||||
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 | |||||||||||||||
InstanceTranslator.java | 100% | 100% | 100% | 100% |
|
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.schema.rules;
|
|
16 |
|
|
17 |
import org.apache.hivemind.ApplicationRuntimeException;
|
|
18 |
import org.apache.hivemind.HiveMind;
|
|
19 |
import org.apache.hivemind.Location;
|
|
20 |
import org.apache.hivemind.internal.Module;
|
|
21 |
|
|
22 |
/**
|
|
23 |
* Used to translate from a class name to an instance of the class.
|
|
24 |
*
|
|
25 |
* @author Howard Lewis Ship
|
|
26 |
*/
|
|
27 |
public class InstanceTranslator extends ClassTranslator |
|
28 |
{ |
|
29 | 391 |
public Object translate(
|
30 |
Module contributingModule, |
|
31 |
Class propertyType, |
|
32 |
String inputValue, |
|
33 |
Location location) |
|
34 |
{ |
|
35 | 391 |
Class objectClass = extractClass(contributingModule, inputValue); |
36 |
|
|
37 | 390 |
if (objectClass == null) |
38 | 1 |
return null; |
39 |
|
|
40 | 389 |
try
|
41 |
{ |
|
42 | 389 |
Object result = objectClass.newInstance(); |
43 |
|
|
44 | 388 |
HiveMind.setLocation(result, location); |
45 |
|
|
46 | 388 |
return result;
|
47 |
} |
|
48 |
catch (Exception ex)
|
|
49 |
{ |
|
50 |
// JDK 1.4 produces a good message here, but JDK 1.3 does not, so we
|
|
51 |
// create our own.
|
|
52 |
|
|
53 | 1 |
throw new ApplicationRuntimeException( |
54 |
RulesMessages.unableToInstantiateInstanceOfClass(objectClass, ex), |
|
55 |
location, |
|
56 |
ex); |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
} |
|
61 |
|
|