org.eigenbase.util14
Class ConnectStringParser

java.lang.Object
  extended by org.eigenbase.util14.ConnectStringParser

public class ConnectStringParser
extends Object

ConnectStringParser is a utility class that parses or creates a JDBC connect string according to the OLE DB connect string syntax described at OLE DB Connection String Syntax.

This code adapted from Mondrian code at Util.java.

The primary differences between this and its Mondrian progenitor are:

ConnectStringParser has a private constructor. Callers use the static members:

parse(String)
Parses the connect string into a new Properties object.
parse(String, Properties)
Parses the connect string into an existing Properties object.
getParamString(Properties)
Returns a param string, quoted and escaped as needed, to represent the supplied name-value pairs.

Since:
Apr 03, 2006
Version:
$Id: //open/dev/farrago/src/org/eigenbase/util14/ConnectStringParser.java#6 $
Author:
adapted by Steve Herskovitz from Mondrian

Field Summary
private  int i
           
private  int n
           
private  StringBuffer nameBuf
           
private  String s
           
private  StringBuffer valueBuf
           
 
Constructor Summary
private ConnectStringParser(String s)
          Creates a new connect string parser.
 
Method Summary
static String getParamString(Properties props)
          Returns a param string, quoted and escaped as needed, to represent the supplied name-value pairs.
(package private)  Properties parse(Properties props)
          Parses the connect string into a Properties object.
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)  String parseName()
          Reads "name=".
(package private)  void parsePair(Properties props)
          Reads "name=value;" or "name=value".
(package private)  String parseQuoted(char q)
          Reads a string quoted by a given character.
(package private)  String parseValue()
          Reads "value;" or "value"
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s

private final String s

n

private final int n

i

private int i

nameBuf

private final StringBuffer nameBuf

valueBuf

private final StringBuffer valueBuf
Constructor Detail

ConnectStringParser

private ConnectStringParser(String s)
Creates a new connect string parser.

Parameters:
s - connect string to parse
See Also:
parse(String), parse(String, Properties)
Method Detail

parse

public static Properties parse(String s)
                        throws SQLException
Parses the connect string into a new Properties object.

Parameters:
s - connect string to parse
Returns:
properties object with parsed params
Throws:
SQLException - error parsing name-value pairs

parse

public static Properties parse(String s,
                               Properties props)
                        throws SQLException
Parses the connect string into an existing Properties object.

Parameters:
s - connect string to parse
props - optional properties object, may be null
Returns:
properties object with parsed params; if an input props was supplied, any duplicate properties will have been replaced by those from the connect string.
Throws:
SQLException - error parsing name-value pairs

parse

Properties parse(Properties props)
           throws SQLException
Parses the connect string into a Properties object. Note that the string can only be parsed once. Subsequent calls return empty/unchanged Properties.

Parameters:
props - optional properties object, may be null
Returns:
properties object with parsed params; if an input props was supplied, any duplicate properties will have been replaced by those from the connect string.
Throws:
SQLException - error parsing name-value pairs

parsePair

void parsePair(Properties props)
         throws SQLException
Reads "name=value;" or "name=value".

Throws:
SQLException - error parsing value

parseName

String parseName()
Reads "name=". Name can contain equals sign if equals sign is doubled.


parseValue

String parseValue()
            throws SQLException
Reads "value;" or "value"

Throws:
SQLException - if find an unterminated quoted value

parseQuoted

String parseQuoted(char q)
             throws SQLException
Reads a string quoted by a given character. Occurrences of the quoting character must be doubled. For example, parseQuoted('"') reads "a ""new"" string" and returns a "new" string.

Throws:
SQLException - if find an unterminated quoted value

getParamString

public static String getParamString(Properties props)
Returns a param string, quoted and escaped as needed, to represent the supplied name-value pairs.

Parameters:
props - name-value pairs
Returns:
param string, never null