Path: blob/master/src/java.xml/share/classes/jdk/xml/internal/JdkProperty.java
40948 views
/*1* Copyright (c) 2021, 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 ImplPropMap pName;54private T pValue;55private State pState = State.DEFAULT;5657/**58* Constructs a JDkProperty.59* @param name the name of the property60* @param value the initial value61* @param state the state of the property62*/63public JdkProperty(ImplPropMap name, T value, State state) {64this.pName = name;65this.pValue = value;66this.pState = state;67}6869/**70* Returns the property value.71* @return the property value72*/73public T getValue() {74return pValue;75}7677/**78* Sets the property value. The value is set only if the setter has a higher79* overriding order.80* @param name the property name81* @param value the value82* @param state the state of the specified property83* @return true if the value is set successfully (because the setter has a84* higher order); false otherwise.85*/86public boolean setValue(String name, T value, State state) {87State pState1;88if ((pState1 = pName.getState(name)) != null) {89if (pState1.compareTo(this.pState) >= 0) {90this.pState = pState1;91pValue = value;92return true;93}94}95return false;96}9798/**99* Properties Name Map that includes Implementation-Specific Features and100* Properties except the limits that are defined in XMLSecurityManager.101* The purpose of the map is to provide a map between the new property names102* with a prefix "jdk.xml" as defined in the module summary and legacy names103* with URL style prefixes. The new names are the same as those of their104* System Properties.105*/106@SuppressWarnings("deprecation")107public static enum ImplPropMap {108109ISSTANDALONE("isStandalone", FQ_IS_STANDALONE, SP_IS_STANDALONE, true, null, null),110XSLTCISSTANDALONE("xsltcIsStandalone", JDK_IS_STANDALONE, SP_XSLTC_IS_STANDALONE,111true, ORACLE_IS_STANDALONE, null),112CDATACHUNKSIZE("cdataChunkSize", CDATA_CHUNK_SIZE, CDATA_CHUNK_SIZE, false, null, null),113EXTCLSLOADER("extensionClassLoader", JDK_EXT_CLASSLOADER, null,114true, JDK_EXTENSION_CLASSLOADER, null),115ENABLEEXTFUNC("enableExtensionFunctions", ORACLE_ENABLE_EXTENSION_FUNCTION,116SP_ENABLE_EXTENSION_FUNCTION_SPEC, true, null, SP_ENABLE_EXTENSION_FUNCTION),117OVERRIDEPARSER("overrideDefaultParser", OVERRIDE_PARSER, OVERRIDE_PARSER,118false, ORACLE_FEATURE_SERVICE_MECHANISM, ORACLE_FEATURE_SERVICE_MECHANISM),119RESETSYMBOLTABLE("resetSymbolTable", RESET_SYMBOL_TABLE, RESET_SYMBOL_TABLE,120false, null, null),121ENTITYCOUNT("getEntityCountInfo", JDK_DEBUG_LIMIT, null, true, JDK_ENTITY_COUNT_INFO, null)122;123124private final String name;125private final String qName;126private final String spName;127private final boolean differ;128private final String oldQName;129private final String oldSPName;130131/**132* Constructs an instance.133* @param name the property name134* @param qName the qualified property name135* @param spName the corresponding System Property136* @param differ a flag indicating whether qName and spName are the same137* @param oldName the legacy property name, null if N/A138* @param oldSPName the legacy System Property name, null if N/A139*/140ImplPropMap(String name, String qName, String spName, boolean differ,141String oldQName, String oldSPName) {142this.name = name;143this.qName = qName;144this.spName = spName;145this.differ = differ;146this.oldQName = oldQName;147this.oldSPName = oldSPName;148}149150/**151* Checks whether the specified name is the property. Checks both the152* property and System Property if they differ. Checks also the legacy153* name if applicable.154*155* @param name the specified name156* @return true if there is a match, false otherwise157*/158public boolean is(String name) {159// current spec calls for using a name same as spName160return (spName != null && spName.equals(name)) ||161// check qName only if it differs from spName162(differ && qName.equals(name)) ||163// check the legacy name if applicable164(oldQName != null && oldQName.equals(name));165}166167/**168* Returns the value indicating whether the qName and spName are different.169* @return the value indicating whether the qName and spName are different170*/171public boolean isNameDiffer() {172return differ;173}174175/**176* Returns the state of a property name. By the specification as of JDK 17,177* the "jdk.xml." prefixed System property name is also the current API178* name. Both the URI-based qName and old name if any are legacy.179*180* @param name the property name181* @return the state of the property name, null if no match182*/183public State getState(String name) {184if ((spName != null && spName.equals(name)) ||185(spName == null && qName.equals(name))) {186return State.APIPROPERTY;187} else if ((differ && qName.equals(name)) ||188(oldQName != null && oldQName.equals(name))) {189//both the URI-style qName and an old name if any are legacy190return State.LEGACY_APIPROPERTY;191}192return null;193}194195/**196* Returns the qualified name of the property.197*198* @return the qualified name of the property199*/200public String qName() {201return qName;202}203204/**205* Returns the legacy name of the property.206*207* @return the legacy name of the property208*/209public String qNameOld() {210return oldQName;211}212213/**214* Returns the name of the corresponding System Property.215*216* @return the name of the System Property217*/218public String systemProperty() {219return spName;220}221222/**223* Returns the name of the legacy System Property.224*225* @return the name of the legacy System Property226*/227public String systemPropertyOld() {228return oldSPName;229}230}231232/**233* Represents the state of the settings of a property. The states are in234* descending order: the default value, value set by FEATURE_SECURE_PROCESSING (FSP),235* in jaxp.properties, by legacy or new system property, and on factories236* using legacy or new property names.237*/238public static enum State {239//this order reflects the overriding order240DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"), JAXPDOTPROPERTIES("jaxp.properties"),241LEGACY_SYSTEMPROPERTY("legacy system property"), SYSTEMPROPERTY("system property"),242LEGACY_APIPROPERTY("legacy property"), APIPROPERTY("property");243244final String literal;245State(String literal) {246this.literal = literal;247}248249public String literal() {250return literal;251}252}253}254255256