Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.xml/share/classes/jdk/xml/internal/JdkProperty.java
67862 views
1
/*
2
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
package jdk.xml.internal;
26
27
import static jdk.xml.internal.JdkConstants.FQ_IS_STANDALONE;
28
import static jdk.xml.internal.JdkConstants.JDK_DEBUG_LIMIT;
29
import static jdk.xml.internal.JdkConstants.JDK_ENTITY_COUNT_INFO;
30
import static jdk.xml.internal.JdkConstants.JDK_EXTENSION_CLASSLOADER;
31
import static jdk.xml.internal.JdkConstants.JDK_EXT_CLASSLOADER;
32
import static jdk.xml.internal.JdkConstants.JDK_IS_STANDALONE;
33
import static jdk.xml.internal.JdkConstants.ORACLE_IS_STANDALONE;
34
import static jdk.xml.internal.JdkConstants.SP_IS_STANDALONE;
35
import static jdk.xml.internal.JdkConstants.SP_XSLTC_IS_STANDALONE;
36
import static jdk.xml.internal.JdkConstants.ORACLE_ENABLE_EXTENSION_FUNCTION;
37
import static jdk.xml.internal.JdkConstants.ORACLE_FEATURE_SERVICE_MECHANISM;
38
import static jdk.xml.internal.JdkConstants.SP_ENABLE_EXTENSION_FUNCTION;
39
import static jdk.xml.internal.JdkConstants.SP_ENABLE_EXTENSION_FUNCTION_SPEC;
40
import static jdk.xml.internal.JdkConstants.CDATA_CHUNK_SIZE;
41
import static jdk.xml.internal.JdkConstants.OVERRIDE_PARSER;
42
import static jdk.xml.internal.JdkConstants.RESET_SYMBOL_TABLE;
43
44
/**
45
* Represents a JDK Implementation Specific Property. This class holds the name
46
* and value of a property along with a state indicating the means through which
47
* the property has been set. The value may change only if the setter has a state
48
* that represents an equal or higher overriding order.
49
*
50
* @param <T> the type of the property value.
51
*/
52
public final class JdkProperty<T> {
53
54
private final ImplPropMap pName;
55
private final Class<T> pType;
56
private T pValue;
57
private State pState = State.DEFAULT;
58
59
/**
60
* Constructs a JDkProperty.
61
* @param name the name of the property
62
* @param type the type of the value
63
* @param value the initial value
64
* @param state the state of the property
65
*/
66
public JdkProperty(ImplPropMap name, Class<T> type, T value, State state) {
67
this.pName = name;
68
this.pType = type;
69
this.pValue = value;
70
this.pState = state;
71
readSystemProperty();
72
}
73
74
/**
75
* Read from system properties, or those in jaxp.properties
76
*/
77
private void readSystemProperty() {
78
if (pState == State.DEFAULT) {
79
T value = null;
80
if (pName.systemProperty() != null) {
81
value = SecuritySupport.getJAXPSystemProperty(pType, pName.systemProperty(), null);
82
}
83
if (value == null && pName.systemPropertyOld() != null) {
84
value = SecuritySupport.getJAXPSystemProperty(pType, pName.systemPropertyOld(), null);
85
}
86
if (value != null) {
87
pValue = value;
88
pState = State.SYSTEMPROPERTY;
89
}
90
}
91
}
92
93
/**
94
* Returns the property value.
95
* @return the property value
96
*/
97
public T getValue() {
98
return pValue;
99
}
100
101
/**
102
* Sets the property value. The value is set only if the setter has a higher
103
* overriding order.
104
* @param name the property name
105
* @param value the value
106
* @param state the state of the specified property
107
* @return true if the value is set successfully (because the setter has a
108
* higher order); false otherwise.
109
*/
110
public boolean setValue(String name, T value, State state) {
111
State pState1;
112
if ((pState1 = pName.getState(name)) != null) {
113
if (pState1.compareTo(this.pState) >= 0) {
114
this.pState = pState1;
115
pValue = value;
116
return true;
117
}
118
}
119
return false;
120
}
121
122
/**
123
* Properties Name Map that includes Implementation-Specific Features and
124
* Properties except the limits that are defined in XMLSecurityManager.
125
* The purpose of the map is to provide a map between the new property names
126
* with a prefix "jdk.xml" as defined in the module summary and legacy names
127
* with URL style prefixes. The new names are the same as those of their
128
* System Properties.
129
*/
130
@SuppressWarnings("deprecation")
131
public static enum ImplPropMap {
132
133
ISSTANDALONE("isStandalone", FQ_IS_STANDALONE, SP_IS_STANDALONE, true, null, null),
134
XSLTCISSTANDALONE("xsltcIsStandalone", JDK_IS_STANDALONE, SP_XSLTC_IS_STANDALONE,
135
true, ORACLE_IS_STANDALONE, null),
136
CDATACHUNKSIZE("cdataChunkSize", CDATA_CHUNK_SIZE, CDATA_CHUNK_SIZE, false, null, null),
137
EXTCLSLOADER("extensionClassLoader", JDK_EXT_CLASSLOADER, null,
138
true, JDK_EXTENSION_CLASSLOADER, null),
139
ENABLEEXTFUNC("enableExtensionFunctions", ORACLE_ENABLE_EXTENSION_FUNCTION,
140
SP_ENABLE_EXTENSION_FUNCTION_SPEC, true, null, SP_ENABLE_EXTENSION_FUNCTION),
141
OVERRIDEPARSER("overrideDefaultParser", OVERRIDE_PARSER, OVERRIDE_PARSER,
142
false, ORACLE_FEATURE_SERVICE_MECHANISM, ORACLE_FEATURE_SERVICE_MECHANISM),
143
RESETSYMBOLTABLE("resetSymbolTable", RESET_SYMBOL_TABLE, RESET_SYMBOL_TABLE,
144
false, null, null),
145
ENTITYCOUNT("getEntityCountInfo", JDK_DEBUG_LIMIT, null, true, JDK_ENTITY_COUNT_INFO, null)
146
;
147
148
private final String name;
149
private final String qName;
150
private final String spName;
151
private final boolean differ;
152
private final String oldQName;
153
private final String oldSPName;
154
155
/**
156
* Constructs an instance.
157
* @param name the property name
158
* @param qName the qualified property name
159
* @param spName the corresponding System Property
160
* @param differ a flag indicating whether qName and spName are the same
161
* @param oldName the legacy property name, null if N/A
162
* @param oldSPName the legacy System Property name, null if N/A
163
*/
164
ImplPropMap(String name, String qName, String spName, boolean differ,
165
String oldQName, String oldSPName) {
166
this.name = name;
167
this.qName = qName;
168
this.spName = spName;
169
this.differ = differ;
170
this.oldQName = oldQName;
171
this.oldSPName = oldSPName;
172
}
173
174
/**
175
* Checks whether the specified name is the property. Checks both the
176
* property and System Property if they differ. Checks also the legacy
177
* name if applicable.
178
*
179
* @param name the specified name
180
* @return true if there is a match, false otherwise
181
*/
182
public boolean is(String name) {
183
// current spec calls for using a name same as spName
184
return (spName != null && spName.equals(name)) ||
185
// check qName only if it differs from spName
186
(differ && qName.equals(name)) ||
187
// check the legacy name if applicable
188
(oldQName != null && oldQName.equals(name));
189
}
190
191
/**
192
* Returns the value indicating whether the qName and spName are different.
193
* @return the value indicating whether the qName and spName are different
194
*/
195
public boolean isNameDiffer() {
196
return differ;
197
}
198
199
/**
200
* Returns the state of a property name. By the specification as of JDK 17,
201
* the "jdk.xml." prefixed System property name is also the current API
202
* name. Both the URI-based qName and old name if any are legacy.
203
*
204
* @param name the property name
205
* @return the state of the property name, null if no match
206
*/
207
public State getState(String name) {
208
if ((spName != null && spName.equals(name)) ||
209
(spName == null && qName.equals(name))) {
210
return State.APIPROPERTY;
211
} else if ((differ && qName.equals(name)) ||
212
(oldQName != null && oldQName.equals(name))) {
213
//both the URI-style qName and an old name if any are legacy
214
return State.LEGACY_APIPROPERTY;
215
}
216
return null;
217
}
218
219
/**
220
* Returns the qualified name of the property.
221
*
222
* @return the qualified name of the property
223
*/
224
public String qName() {
225
return qName;
226
}
227
228
/**
229
* Returns the legacy name of the property.
230
*
231
* @return the legacy name of the property
232
*/
233
public String qNameOld() {
234
return oldQName;
235
}
236
237
/**
238
* Returns the name of the corresponding System Property.
239
*
240
* @return the name of the System Property
241
*/
242
public String systemProperty() {
243
return spName;
244
}
245
246
/**
247
* Returns the name of the legacy System Property.
248
*
249
* @return the name of the legacy System Property
250
*/
251
public String systemPropertyOld() {
252
return oldSPName;
253
}
254
}
255
256
/**
257
* Represents the state of the settings of a property. The states are in
258
* descending order: the default value, value set by FEATURE_SECURE_PROCESSING (FSP),
259
* in jaxp.properties, by legacy or new system property, and on factories
260
* using legacy or new property names.
261
*/
262
public static enum State {
263
//this order reflects the overriding order
264
DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"), JAXPDOTPROPERTIES("jaxp.properties"),
265
LEGACY_SYSTEMPROPERTY("legacy system property"), SYSTEMPROPERTY("system property"),
266
LEGACY_APIPROPERTY("legacy property"), APIPROPERTY("property");
267
268
final String literal;
269
State(String literal) {
270
this.literal = literal;
271
}
272
273
public String literal() {
274
return literal;
275
}
276
}
277
}
278
279