Class C3P0XmlPropertiesConfigSource
- All Implemented Interfaces:
com.mchange.v2.cfg.PropertiesConfigSource,com.mchange.v2.cfg.VetoableConfig
Identifiers
c3p0-xml: followed by either:
- a classloader resource path beginning
/— every resource at that path is read and merged, earlier classpath entries winning, exactly asBasicPropertiesConfigSourcedoes for properties resources./alone is illegal, and so is a query string, which would otherwise be silently misread as part of the path. - a
file:URL — with the full treatment afile:identifier gets, including${system.property}references,?required=and?permissions=useronly. Those semantics are not reimplemented here; they come fromFileUrlPropertiesConfigSource.resolve(com.mchange.v2.cfg.VetoableConfig, java.lang.String, java.util.List<com.mchange.v2.cfg.DelayedLogItem>).
Because permissions=useronly can refuse, this source is a VetoableConfig,
which means — as for file: — that plain MConfig.AsProvided will not
read it. Use MConfig.AsProvidedVetoable or MConfig.AsProvidedIgnoreVetoed.
How names map
This class has no access to c3p0's list of configurable properties, so it cannot validate names. It applies a shape heuristic instead, and says so when it declines to guess:
<default-config>
maxPoolSize -> c3p0.maxPoolSize
c3p0.maxPoolSize -> c3p0.maxPoolSize (compound: kept as-is)
com.mchange.v2.log.freezeConfig -> com.mchange.v2.log.freezeConfig
<named-config name="X">
maxPoolSize -> c3p0.named-configs.X.maxPoolSize
c3p0.maxPoolSize -> c3p0.named-configs.X.maxPoolSize
com.mchange.v2.anything -> WARN and ignore
c3p0.a.b -> WARN and ignore
A <named-config> with no name is ignored with a warning, as is one whose
name contains a '.' — see below for why.
The asymmetry is deliberate. The default scope shares a namespace with properties-style
configuration, so a fully-qualified key written there means exactly itself. A named config is
a per-DataSource scope, and every reader of a com.mchange.* setting reads it
statically, with no DataSource in hand — so such a key inside a named config has no
coherent meaning, and silently promoting it to one would be worse than refusing it.
<user-overrides> names map the same way as a named config's, under
c3p0.user-overrides.<user>. or
c3p0.named-configs.<X>.user-overrides.<user>.. <extensions> names are
never processed: they are names a deployment invented for its own
getExtensions(..) lookup, so there is no vocabulary against which to correct them.
A declared named config leaves a mark, even when it is empty
<named-config name="X"/> with nothing in it is not the same as no
<named-config name="X"> at all, and c3p0 behaves differently in the two cases. But a
scope with no properties contributes no keys, so read naively the two would be
indistinguishable. This source therefore writes the bare scope key for every named config it
reads:
<named-config name="X"/> -> c3p0.named-configs.X=
<named-config name="X">maxPoolSize=30</named-config> -> c3p0.named-configs.X=
c3p0.named-configs.X.maxPoolSize=30
The bare scope key is the natural carrier: it is a prefix rather than a property, so it can
never collide with one, and no pseudo-property name has to be invented for the purpose. Its
value is the empty string, which is both what the declaration means and what an author would
write by hand in a properties file — so the convention is expressible in either format,
not only in XML. Since a key is a prefix of itself (see
MultiPropertiesConfig.getPropertiesByPrefix(java.lang.String)), the mark is visible as
getPropertiesByPrefix("c3p0.named-configs.X").containsKey("c3p0.named-configs.X").
Note what the mark does not mean. A scope declared only in properties-style configuration carries no mark, because nothing writes one there, yet it is plainly declared. So declared remains "the prefix has any keys at all", and the mark is what additionally makes declared but empty expressible:
declared -> getPropertiesByPrefix(pfx).size() > 0
declared, empty -> size() == 1 && containsKey(pfx)
This is also why a named config's name may not contain a '.', and such a scope is
refused with a warning. In the flat namespace these keys live in, scope a.b declared
empty and scope a carrying a pool property b both arrive as
c3p0.named-configs.a.b — and where that property's own value is empty, the two
are not merely ambiguous but identical. Refusing the name is cheaper than resolving the
collision, and a dotted scope name was never usable in the properties-style namespace
anyway.
<user-overrides> and <extensions> get no such mark, deliberately. Declared
and empty is behaviorally the same as undeclared for both — c3p0 needs only to see that
there are no overrides, or no extensions — and every mark is a key that every future
reader of the properties view would have to know to skip.
Parsing is hardened, and stays hardened
Doctypes, external entities, external DTDs and schemas, XInclude and entity expansion are
all disabled — see CVE-2018-20433. The single escape is the System property
com.mchange.v2.c3p0.cfg.xml.usePermissiveParser, and it is read only from the
sealed snapshot of System properties, never from configuration: a flag that relaxes XML
parsing must not be settable by the documents whose parsing it relaxes.
c3p0's deprecated com.mchange.v2.c3p0.cfg.xml.expandEntityReferences is not
honored here. If it is set, a warning points at usePermissiveParser instead, so that a
deployment migrating from c3p0's own config finder is told why its entity references stopped
resolving rather than left to discover it.
Note that PropertiesConfigSource implementations must not touch anything that directly logs,
as they are delegates of the com.mchange.v2.cfg library which must initialize
prior to to mlog library, as mlog itself is configured by that library.
C3P0ConfigUtilsNoLogging contains utilities that may need to be hit by c3p0 PropertiesConfigSource
implementations (like this class) and also used by other classes, with requiring or causing initialization of
the mlog logging library.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.mchange.v2.cfg.PropertiesConfigSource
com.mchange.v2.cfg.PropertiesConfigSource.Parse -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisC3P0XmlIdentifier(String identifier) com.mchange.v2.cfg.PropertiesConfigSource.ParsepropertiesFromSource(String identifier)
-
Constructor Details
-
C3P0XmlPropertiesConfigSource
public C3P0XmlPropertiesConfigSource()
-
-
Method Details
-
isC3P0XmlIdentifier
-
propertiesFromSource
public com.mchange.v2.cfg.PropertiesConfigSource.Parse propertiesFromSource(String identifier) throws FileNotFoundException, Exception - Specified by:
propertiesFromSourcein interfacecom.mchange.v2.cfg.PropertiesConfigSource- Throws:
FileNotFoundExceptionException
-