Path: blob/master/src/java.xml/share/classes/jdk/xml/internal/JdkProperty.java
67862 views
/*1* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package jdk.xml.internal;2526import static jdk.xml.internal.JdkConstants.FQ_IS_STANDALONE;27import static jdk.xml.internal.JdkConstants.JDK_DEBUG_LIMIT;28import static jdk.xml.internal.JdkConstants.JDK_ENTITY_COUNT_INFO;29import static jdk.xml.internal.JdkConstants.JDK_EXTENSION_CLASSLOADER;30import static jdk.xml.internal.JdkConstants.JDK_EXT_CLASSLOADER;31import static jdk.xml.internal.JdkConstants.JDK_IS_STANDALONE;32import static jdk.xml.internal.JdkConstants.ORACLE_IS_STANDALONE;33import static jdk.xml.internal.JdkConstants.SP_IS_STANDALONE;34import static jdk.xml.internal.JdkConstants.SP_XSLTC_IS_STANDALONE;35import static jdk.xml.internal.JdkConstants.ORACLE_ENABLE_EXTENSION_FUNCTION;36import static jdk.xml.internal.JdkConstants.ORACLE_FEATURE_SERVICE_MECHANISM;37import static jdk.xml.internal.JdkConstants.SP_ENABLE_EXTENSION_FUNCTION;38import static jdk.xml.internal.JdkConstants.SP_ENABLE_EXTENSION_FUNCTION_SPEC;39import static jdk.xml.internal.JdkConstants.CDATA_CHUNK_SIZE;40import static jdk.xml.internal.JdkConstants.OVERRIDE_PARSER;41import static jdk.xml.internal.JdkConstants.RESET_SYMBOL_TABLE;4243/**44* Represents a JDK Implementation Specific Property. This class holds the name45* and value of a property along with a state indicating the means through which46* the property has been set. The value may change only if the setter has a state47* that represents an equal or higher overriding order.48*49* @param <T> the type of the property value.50*/51public final class JdkProperty<T> {5253private final ImplPropMap pName;54private final Class<T> pType;55private T pValue;56private State pState = State.DEFAULT;5758/**59* Constructs a JDkProperty.60* @param name the name of the property61* @param type the type of the value62* @param value the initial value63* @param state the state of the property64*/65public JdkProperty(ImplPropMap name, Class<T> type, T value, State state) {66this.pName = name;67this.pType = type;68this.pValue = value;69this.pState = state;70readSystemProperty();71}7273/**74* Read from system properties, or those in jaxp.properties75*/76private void readSystemProperty() {77if (pState == State.DEFAULT) {78T value = null;79if (pName.systemProperty() != null) {80value = SecuritySupport.getJAXPSystemProperty(pType, pName.systemProperty(), null);81}82if (value == null && pName.systemPropertyOld() != null) {83value = SecuritySupport.getJAXPSystemProperty(pType, pName.systemPropertyOld(), null);84}85if (value != null) {86pValue = value;87pState = State.SYSTEMPROPERTY;88}89}90}9192/**93* Returns the property value.94* @return the property value95*/96public T getValue() {97return pValue;98}99100/**101* Sets the property value. The value is set only if the setter has a higher102* overriding order.103* @param name the property name104* @param value the value105* @param state the state of the specified property106* @return true if the value is set successfully (because the setter has a107* higher order); false otherwise.108*/109public boolean setValue(String name, T value, State state) {110State pState1;111if ((pState1 = pName.getState(name)) != null) {112if (pState1.compareTo(this.pState) >= 0) {113this.pState = pState1;114pValue = value;115return true;116}117}118return false;119}120121/**122* Properties Name Map that includes Implementation-Specific Features and123* Properties except the limits that are defined in XMLSecurityManager.124* The purpose of the map is to provide a map between the new property names125* with a prefix "jdk.xml" as defined in the module summary and legacy names126* with URL style prefixes. The new names are the same as those of their127* System Properties.128*/129@SuppressWarnings("deprecation")130public static enum ImplPropMap {131132ISSTANDALONE("isStandalone", FQ_IS_STANDALONE, SP_IS_STANDALONE, true, null, null),133XSLTCISSTANDALONE("xsltcIsStandalone", JDK_IS_STANDALONE, SP_XSLTC_IS_STANDALONE,134true, ORACLE_IS_STANDALONE, null),135CDATACHUNKSIZE("cdataChunkSize", CDATA_CHUNK_SIZE, CDATA_CHUNK_SIZE, false, null, null),136EXTCLSLOADER("extensionClassLoader", JDK_EXT_CLASSLOADER, null,137true, JDK_EXTENSION_CLASSLOADER, null),138ENABLEEXTFUNC("enableExtensionFunctions", ORACLE_ENABLE_EXTENSION_FUNCTION,139SP_ENABLE_EXTENSION_FUNCTION_SPEC, true, null, SP_ENABLE_EXTENSION_FUNCTION),140OVERRIDEPARSER("overrideDefaultParser", OVERRIDE_PARSER, OVERRIDE_PARSER,141false, ORACLE_FEATURE_SERVICE_MECHANISM, ORACLE_FEATURE_SERVICE_MECHANISM),142RESETSYMBOLTABLE("resetSymbolTable", RESET_SYMBOL_TABLE, RESET_SYMBOL_TABLE,143false, null, null),144ENTITYCOUNT("getEntityCountInfo", JDK_DEBUG_LIMIT, null, true, JDK_ENTITY_COUNT_INFO, null)145;146147private final String name;148private final String qName;149private final String spName;150private final boolean differ;151private final String oldQName;152private final String oldSPName;153154/**155* Constructs an instance.156* @param name the property name157* @param qName the qualified property name158* @param spName the corresponding System Property159* @param differ a flag indicating whether qName and spName are the same160* @param oldName the legacy property name, null if N/A161* @param oldSPName the legacy System Property name, null if N/A162*/163ImplPropMap(String name, String qName, String spName, boolean differ,164String oldQName, String oldSPName) {165this.name = name;166this.qName = qName;167this.spName = spName;168this.differ = differ;169this.oldQName = oldQName;170this.oldSPName = oldSPName;171}172173/**174* Checks whether the specified name is the property. Checks both the175* property and System Property if they differ. Checks also the legacy176* name if applicable.177*178* @param name the specified name179* @return true if there is a match, false otherwise180*/181public boolean is(String name) {182// current spec calls for using a name same as spName183return (spName != null && spName.equals(name)) ||184// check qName only if it differs from spName185(differ && qName.equals(name)) ||186// check the legacy name if applicable187(oldQName != null && oldQName.equals(name));188}189190/**191* Returns the value indicating whether the qName and spName are different.192* @return the value indicating whether the qName and spName are different193*/194public boolean isNameDiffer() {195return differ;196}197198/**199* Returns the state of a property name. By the specification as of JDK 17,200* the "jdk.xml." prefixed System property name is also the current API201* name. Both the URI-based qName and old name if any are legacy.202*203* @param name the property name204* @return the state of the property name, null if no match205*/206public State getState(String name) {207if ((spName != null && spName.equals(name)) ||208(spName == null && qName.equals(name))) {209return State.APIPROPERTY;210} else if ((differ && qName.equals(name)) ||211(oldQName != null && oldQName.equals(name))) {212//both the URI-style qName and an old name if any are legacy213return State.LEGACY_APIPROPERTY;214}215return null;216}217218/**219* Returns the qualified name of the property.220*221* @return the qualified name of the property222*/223public String qName() {224return qName;225}226227/**228* Returns the legacy name of the property.229*230* @return the legacy name of the property231*/232public String qNameOld() {233return oldQName;234}235236/**237* Returns the name of the corresponding System Property.238*239* @return the name of the System Property240*/241public String systemProperty() {242return spName;243}244245/**246* Returns the name of the legacy System Property.247*248* @return the name of the legacy System Property249*/250public String systemPropertyOld() {251return oldSPName;252}253}254255/**256* Represents the state of the settings of a property. The states are in257* descending order: the default value, value set by FEATURE_SECURE_PROCESSING (FSP),258* in jaxp.properties, by legacy or new system property, and on factories259* using legacy or new property names.260*/261public static enum State {262//this order reflects the overriding order263DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"), JAXPDOTPROPERTIES("jaxp.properties"),264LEGACY_SYSTEMPROPERTY("legacy system property"), SYSTEMPROPERTY("system property"),265LEGACY_APIPROPERTY("legacy property"), APIPROPERTY("property");266267final String literal;268State(String literal) {269this.literal = literal;270}271272public String literal() {273return literal;274}275}276}277278279