|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
@@ -85,25 +85,38 @@ public static enum XPathResultType {
|
85 | 85 | /**
|
86 | 86 | * Compares this type to the specified class type.
|
87 | 87 | * @param clsType class type
|
88 |
| - * @return true if the argument is not null and is a class type that |
| 88 | + * @return true if the argument is not null and is a class type or accepted subtype that |
89 | 89 | * matches that this type represents, false otherwise.
|
90 | 90 | */
|
91 | 91 | private boolean equalsClassType(Class<?> clsType) {
|
92 |
| - Objects.nonNull(clsType); |
93 |
| - if (clsType.isAssignableFrom(this.clsType)) { |
| 92 | + if (Objects.nonNull(clsType) && this.clsType.isAssignableFrom(clsType)) { |
| 93 | + if (this.clsType == Number.class) { |
| 94 | + return isAcceptedNumberSubType(clsType); |
| 95 | + } |
94 | 96 | return true;
|
95 | 97 | }
|
96 | 98 | return false;
|
97 | 99 | }
|
98 | 100 |
|
| 101 | + /** |
| 102 | + * Compares the specified class type to accepted subtypes of number. |
| 103 | + * @param clsType class type |
| 104 | + * @return true if class type is an accepted subtype of Number, false otherwise |
| 105 | + */ |
| 106 | + private boolean isAcceptedNumberSubType(Class<?> clsType) { |
| 107 | + return clsType.isAssignableFrom(Double.class) || |
| 108 | + clsType.isAssignableFrom(Integer.class) || |
| 109 | + clsType.isAssignableFrom(Long.class); |
| 110 | + } |
| 111 | + |
99 | 112 | /**
|
100 | 113 | * Returns the QName type as specified in {@link XPathConstants} that
|
101 | 114 | * corresponds to the specified class type.
|
102 | 115 | * @param clsType a class type that the enum type supports
|
103 | 116 | * @return the QName type that matches with the specified class type,
|
104 | 117 | * null if there is no match
|
105 | 118 | */
|
106 |
| - static public QName getQNameType(Class<?> clsType) { |
| 119 | + static public QName getQNameType(Class<?> clsType) { |
107 | 120 | for (XPathResultType type : XPathResultType.values()) {
|
108 | 121 | if (type.equalsClassType(clsType)) {
|
109 | 122 | return type.qnameType;
|
|
0 commit comments