public class ConnectStringParser extends Object
This code was adapted from Mondrian's mondrian.olap.Util class. The primary differences between this and its Mondrian progenitor are:
Properties for compatibility with the JDBC API
(replaces Mondrian's use of its own order-preserving and case-insensitive
PropertyList, found in Util.java at link above)parse(java.lang.String) a pre-existing Properties object into
which properties are to be parsed, possibly overriding prior valuesSQLExceptions rather than unchecked
RuntimeExceptionsConnectStringParser has a private constructor. Callers use the static members:
parse(String)
parse(String, Properties)
getParamString(Properties)
| Modifier and Type | Field and Description |
|---|---|
private int |
i |
private int |
n |
private StringBuilder |
nameBuf |
private String |
s |
private StringBuilder |
valueBuf |
| Modifier | Constructor and Description |
|---|---|
private |
ConnectStringParser(String s)
Creates a new connect string parser.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
getParamString(Properties props)
Returns a param string, quoted and escaped as needed, to represent the
supplied name-value pairs.
|
static Properties |
parse(String s)
Parses the connect string into a new Properties object.
|
static Properties |
parse(String s,
Properties props)
Parses the connect string into an existing Properties object.
|
(package private) Properties |
parseInternal(Properties props)
Parses the connect string into a Properties object.
|
(package private) String |
parseName()
Reads "name=".
|
(package private) void |
parsePair(Properties props)
Reads "name=value;" or "name=value<EOF>".
|
(package private) String |
parseQuoted(char q)
Reads a string quoted by a given character.
|
(package private) String |
parseValue()
Reads "value;" or "value<EOF>"
|
static Map<String,String> |
toMap(Properties properties)
Converts a
Properties object to a . |
private final String s
private final int n
private int i
private final StringBuilder nameBuf
private final StringBuilder valueBuf
private ConnectStringParser(String s)
s - connect string to parseparse(String),
parse(String, Properties)public static Properties parse(String s) throws SQLException
s - connect string to parseSQLException - error parsing name-value pairspublic static Properties parse(String s, Properties props) throws SQLException
s - connect string to parseprops - optional properties object, may be null
props was supplied, any duplicate properties will have been
replaced by those from the connect string.SQLException - error parsing name-value pairsProperties parseInternal(Properties props) throws SQLException
props - optional properties object, may be null
props was supplied, any duplicate properties will have been
replaced by those from the connect string.SQLException - error parsing name-value pairsvoid parsePair(Properties props) throws SQLException
SQLException - error parsing valueString parseName()
String parseValue() throws SQLException
SQLException - if find an unterminated quoted valueString parseQuoted(char q) throws SQLException
parseQuoted('"')
reads "a ""new"" string" and returns a "new"
string.SQLException - if find an unterminated quoted valuepublic static String getParamString(Properties props)
props - name-value pairsnullpublic static Map<String,String> toMap(Properties properties)
Properties object to a Map<String,
String>.
This is necessary because Properties is a dinosaur class. It
ought to extend Map<String,String>, but instead
extends .
Hashtable<Object,Object>
Typical usage, to iterate over a Properties:
Properties properties;
for (Map.Entry<String, String> entry =
Util.toMap(properties).entrySet()) {
println("key=" + entry.getKey() + ", value=" + entry.getValue());
}
Copyright © 2012–2016 The Apache Software Foundation. All rights reserved.