Skip to contentMethod: getInstance()
1: /*
2: * Copyright (c) 2023 Contributors to the Eclipse Foundation
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16: package jakarta.el;
17:
18: import jakarta.el.BeanELResolver.BeanProperties;
19:
20: /*
21: * Provides an abstraction so the BeanELResolver can obtain JavaBeans specification support via different
22: * implementations.
23: */
24: abstract class BeanSupport {
25:
26: private static final BeanSupport beanSupport;
27:
28: static {
29: // Only intended for unit tests. Not intended to be part of public API.
30: boolean doNotCacheInstance = Boolean.getBoolean("jakarta.el.BeanSupport.doNotCacheInstance");
31: if (doNotCacheInstance) {
32: beanSupport = null;
33: } else {
34: beanSupport = createInstance();
35: }
36: }
37:
38: private static BeanSupport createInstance() {
39: // Only intended for unit tests. Not intended to be part of public API.
40: boolean useFull = !Boolean.getBoolean("jakarta.el.BeanSupport.useStandalone");
41:
42: if (useFull) {
43: // If not explicitly configured to use standalone, use the full implementation unless it is not available.
44: try {
45: Class.forName("java.beans.BeanInfo");
46: } catch (Exception e) {
47: // Ignore: Expected if using modules and java.desktop module is not present
48: useFull = false;
49: }
50: }
51: if (useFull) {
52: // The full implementation provided by the java.beans package
53: return new BeanSupportFull();
54: } else {
55: // The cut-down local implementation that does not depend on the java.beans package
56: return new BeanSupportStandalone();
57: }
58: }
59:
60: static BeanSupport getInstance() {
61:• if (beanSupport == null) {
62: return createInstance();
63: }
64: return beanSupport;
65: }
66:
67: abstract BeanProperties getBeanProperties(Class<?> type);
68: }