|
|||||||||||||||||||
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 | |||||||||||||||
CtClassSource.java | - | 92.3% | 100% | 94.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.service.impl;
|
|
16 |
|
|
17 |
import javassist.CtClass;
|
|
18 |
import javassist.NotFoundException;
|
|
19 |
|
|
20 |
import org.apache.hivemind.ApplicationRuntimeException;
|
|
21 |
import org.apache.hivemind.service.ClassFabUtils;
|
|
22 |
|
|
23 |
/**
|
|
24 |
* Wrapper around Javassist's {@link javassist.ClassPool}and our own
|
|
25 |
* {@link org.apache.hivemind.service.impl.ClassFactoryClassLoader}that manages the creation of new
|
|
26 |
* instance of {@link javassist.CtClass}and converts finished CtClass's into instantiable Classes.
|
|
27 |
*
|
|
28 |
* @author Howard Lewis Ship
|
|
29 |
*/
|
|
30 |
public class CtClassSource |
|
31 |
{ |
|
32 |
private HiveMindClassPool _pool;
|
|
33 |
|
|
34 | 138 |
public CtClassSource(HiveMindClassPool pool)
|
35 |
{ |
|
36 | 138 |
_pool = pool; |
37 |
} |
|
38 |
|
|
39 | 21567 |
public CtClass getCtClass(Class searchClass)
|
40 |
{ |
|
41 | 21567 |
ClassLoader loader = searchClass.getClassLoader(); |
42 |
|
|
43 |
// Add the class loader for the searchClass to the class pool and
|
|
44 |
// delegating class loader if needed.
|
|
45 |
|
|
46 | 21567 |
_pool.appendClassLoader(loader); |
47 |
|
|
48 | 21567 |
String name = ClassFabUtils.getJavaClassName(searchClass); |
49 |
|
|
50 | 21567 |
try
|
51 |
{ |
|
52 | 21567 |
return _pool.get(name);
|
53 |
} |
|
54 |
catch (NotFoundException ex)
|
|
55 |
{ |
|
56 | 0 |
throw new ApplicationRuntimeException(ServiceMessages.unableToLookupClass(name, ex), ex); |
57 |
} |
|
58 |
} |
|
59 |
|
|
60 | 1958 |
public CtClass newClass(String name, Class superClass)
|
61 |
{ |
|
62 | 1958 |
CtClass ctSuperClass = getCtClass(superClass); |
63 |
|
|
64 | 1958 |
return _pool.makeClass(name, ctSuperClass);
|
65 |
} |
|
66 |
|
|
67 |
/**
|
|
68 |
* Creates a new, empty interace, with the given name.
|
|
69 |
*
|
|
70 |
* @since 1.1
|
|
71 |
*/
|
|
72 |
|
|
73 | 11 |
public CtClass newInterface(String name)
|
74 |
{ |
|
75 | 11 |
return _pool.makeInterface(name);
|
76 |
} |
|
77 |
|
|
78 | 1961 |
public Class createClass(CtClass ctClass)
|
79 |
{ |
|
80 |
// String className = ctClass.getName();
|
|
81 |
|
|
82 | 1961 |
try
|
83 |
{ |
|
84 | 1961 |
return _pool.toClass(ctClass);
|
85 |
} |
|
86 |
catch (Throwable ex)
|
|
87 |
{ |
|
88 | 3 |
throw new ApplicationRuntimeException(ServiceMessages.unableToWriteClass(ctClass, ex), |
89 |
ex); |
|
90 |
} |
|
91 |
} |
|
92 |
} |
|