mirror of https://github.com/apache/openjpa.git
OPENJPA-2065: allow interface as result class
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1190723 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3494fab794
commit
8d21608618
|
@ -117,10 +117,9 @@ public class ResultPacker {
|
||||||
/**
|
/**
|
||||||
* Internal constructor.
|
* Internal constructor.
|
||||||
*/
|
*/
|
||||||
private ResultPacker(Class candidate, Class[] types, String[] aliases,
|
private ResultPacker(Class<?> candidate, Class<?>[] types, String[] aliases, Class<?> resultClass) {
|
||||||
Class resultClass) {
|
|
||||||
_aliases = aliases;
|
_aliases = aliases;
|
||||||
if (candidate == resultClass
|
if (candidate == resultClass || isInterface(resultClass, candidate)
|
||||||
||(types != null && types.length == 1 && types[0] == resultClass)
|
||(types != null && types.length == 1 && types[0] == resultClass)
|
||||||
|| resultClass.isArray()) {
|
|| resultClass.isArray()) {
|
||||||
_resultClass = resultClass;
|
_resultClass = resultClass;
|
||||||
|
@ -135,7 +134,7 @@ public class ResultPacker {
|
||||||
_constructor = null;
|
_constructor = null;
|
||||||
} else if (!_stdTypes.contains(_resultClass = resultClass)) {
|
} else if (!_stdTypes.contains(_resultClass = resultClass)) {
|
||||||
// check for a constructor that matches the projection types
|
// check for a constructor that matches the projection types
|
||||||
Constructor cons = null;
|
Constructor<?> cons = null;
|
||||||
if (types != null && types.length > 0) {
|
if (types != null && types.length > 0) {
|
||||||
try {
|
try {
|
||||||
cons = _resultClass.getConstructor(types);
|
cons = _resultClass.getConstructor(types);
|
||||||
|
@ -150,7 +149,7 @@ public class ResultPacker {
|
||||||
_put = findPut(methods);
|
_put = findPut(methods);
|
||||||
_sets = new Member[aliases.length];
|
_sets = new Member[aliases.length];
|
||||||
|
|
||||||
Class type;
|
Class<?> type;
|
||||||
for (int i = 0; i < _sets.length; i++) {
|
for (int i = 0; i < _sets.length; i++) {
|
||||||
type = (types == null) ? candidate : types[i];
|
type = (types == null) ? candidate : types[i];
|
||||||
_sets[i] = findSet(aliases[i], type, fields, methods);
|
_sets[i] = findSet(aliases[i], type, fields, methods);
|
||||||
|
@ -172,6 +171,15 @@ public class ResultPacker {
|
||||||
_constructor = null;
|
_constructor = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isInterface(Class<?> intf, Class<?> actual) {
|
||||||
|
Class<?>[] intfs = actual.getInterfaces();
|
||||||
|
for (Class<?> c : intfs) {
|
||||||
|
if (c == intf)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure that conversion is possible.
|
* Ensure that conversion is possible.
|
||||||
|
|
Loading…
Reference in New Issue