Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.xml/share/classes/jdk/xml/internal/JdkProperty.java
40948 views
1
/*
2
* Copyright (c) 2021, 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 ImplPropMap pName;
55
private T pValue;
56
private State pState = State.DEFAULT;
57
58
/**
59
* Constructs a JDkProperty.
60
* @param name the name of the property
61
* @param value the initial value
62
* @param state the state of the property
63
*/
64
public JdkProperty(ImplPropMap name, T value, State state) {
65
this.pName = name;
66
this.pValue = value;
67
this.pState = state;
68
}
69
70
/**
71
* Returns the property value.
72
* @return the property value
73
*/
74
public T getValue() {
75
return pValue;
76
}
77
78
/**
79
* Sets the property value. The value is set only if the setter has a higher
80
* overriding order.
81
* @param name the property name
82
* @param value the value
83
* @param state the state of the specified property
84
* @return true if the value is set successfully (because the setter has a
85
* higher order); false otherwise.
86
*/
87
public boolean setValue(String name, T value, State state) {
88
State pState1;
89
if ((pState1 = pName.getState(name)) != null) {
90
if (pState1.compareTo(this.pState) >= 0) {
91
this.pState = pState1;
92
pValue = value;
93
return true;
94
}
95
}
96
return false;
97
}
98
99
/**
100
* Properties Name Map that includes Implementation-Specific Features and
101
* Properties except the limits that are defined in XMLSecurityManager.
102
* The purpose of the map is to provide a map between the new property names
103
* with a prefix "jdk.xml" as defined in the module summary and legacy names
104
* with URL style prefixes. The new names are the same as those of their
105
* System Properties.
106
*/
107
@SuppressWarnings("deprecation")
108
public static enum ImplPropMap {
109
110
ISSTANDALONE("isStandalone", FQ_IS_STANDALONE, SP_IS_STANDALONE, true, null, null),
111
XSLTCISSTANDALONE("xsltcIsStandalone", JDK_IS_STANDALONE, SP_XSLTC_IS_STANDALONE,
112
true, ORACLE_IS_STANDALONE, null),
113
CDATACHUNKSIZE("cdataChunkSize", CDATA_CHUNK_SIZE, CDATA_CHUNK_SIZE, false, null, null),
114
EXTCLSLOADER("extensionClassLoader", JDK_EXT_CLASSLOADER, null,
115
true, JDK_EXTENSION_CLASSLOADER, null),
116
ENABLEEXTFUNC("enableExtensionFunctions", ORACLE_ENABLE_EXTENSION_FUNCTION,
117
SP_ENABLE_EXTENSION_FUNCTION_SPEC, true, null, SP_ENABLE_EXTENSION_FUNCTION),
118
OVERRIDEPARSER("overrideDefaultParser", OVERRIDE_PARSER, OVERRIDE_PARSER,
119
false, ORACLE_FEATURE_SERVICE_MECHANISM, ORACLE_FEATURE_SERVICE_MECHANISM),
120
RESETSYMBOLTABLE("resetSymbolTable", RESET_SYMBOL_TABLE, RESET_SYMBOL_TABLE,
121
false, null, null),
122
ENTITYCOUNT("getEntityCountInfo", JDK_DEBUG_LIMIT, null, true, JDK_ENTITY_COUNT_INFO, null)
123
;
124
125
private final String name;
126
private final String qName;
127
private final String spName;
128
private final boolean differ;
129
private final String oldQName;
130
private final String oldSPName;
131
132
/**
133
* Constructs an instance.
134
* @param name the property name
135
* @param qName the qualified property name
136
* @param spName the corresponding System Property
137
* @param differ a flag indicating whether qName and spName are the same
138
* @param oldName the legacy property name, null if N/A
139
* @param oldSPName the legacy System Property name, null if N/A
140
*/
141
ImplPropMap(String name, String qName, String spName, boolean differ,
142
String oldQName, String oldSPName) {
143
this.name = name;
144
this.qName = qName;
145
this.spName = spName;
146
this.differ = differ;
147
this.oldQName = oldQName;
148
this.oldSPName = oldSPName;
149
}
150
151
/**
152
* Checks whether the specified name is the property. Checks both the
153
* property and System Property if they differ. Checks also the legacy
154
* name if applicable.
155
*
156
* @param name the specified name
157
* @return true if there is a match, false otherwise
158
*/
159
public boolean is(String name) {
160
// current spec calls for using a name same as spName
161
return (spName != null && spName.equals(name)) ||
162
// check qName only if it differs from spName
163
(differ && qName.equals(name)) ||
164
// check the legacy name if applicable
165
(oldQName != null && oldQName.equals(name));
166
}
167
168
/**
169
* Returns the value indicating whether the qName and spName are different.
170
* @return the value indicating whether the qName and spName are different
171
*/
172
public boolean isNameDiffer() {
173
return differ;
174
}
175
176
/**
177
* Returns the state of a property name. By the specification as of JDK 17,
178
* the "jdk.xml." prefixed System property name is also the current API
179
* name. Both the URI-based qName and old name if any are legacy.
180
*
181
* @param name the property name
182
* @return the state of the property name, null if no match
183
*/
184
public State getState(String name) {
185
if ((spName != null && spName.equals(name)) ||
186
(spName == null && qName.equals(name))) {
187
return State.APIPROPERTY;
188
} else if ((differ && qName.equals(name)) ||
189
(oldQName != null && oldQName.equals(name))) {
190
//both the URI-style qName and an old name if any are legacy
191
return State.LEGACY_APIPROPERTY;
192
}
193
return null;
194
}
195
196
/**
197
* Returns the qualified name of the property.
198
*
199
* @return the qualified name of the property
200
*/
201
public String qName() {
202
return qName;
203
}
204
205
/**
206
* Returns the legacy name of the property.
207
*
208
* @return the legacy name of the property
209
*/
210
public String qNameOld() {
211
return oldQName;
212
}
213
214
/**
215
* Returns the name of the corresponding System Property.
216
*
217
* @return the name of the System Property
218
*/
219
public String systemProperty() {
220
return spName;
221
}
222
223
/**
224
* Returns the name of the legacy System Property.
225
*
226
* @return the name of the legacy System Property
227
*/
228
public String systemPropertyOld() {
229
return oldSPName;
230
}
231
}
232
233
/**
234
* Represents the state of the settings of a property. The states are in
235
* descending order: the default value, value set by FEATURE_SECURE_PROCESSING (FSP),
236
* in jaxp.properties, by legacy or new system property, and on factories
237
* using legacy or new property names.
238
*/
239
public static enum State {
240
//this order reflects the overriding order
241
DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"), JAXPDOTPROPERTIES("jaxp.properties"),
242
LEGACY_SYSTEMPROPERTY("legacy system property"), SYSTEMPROPERTY("system property"),
243
LEGACY_APIPROPERTY("legacy property"), APIPROPERTY("property");
244
245
final String literal;
246
State(String literal) {
247
this.literal = literal;
248
}
249
250
public String literal() {
251
return literal;
252
}
253
}
254
}
255
256