Class BrokerFormat

java.lang.Object
COM.activesw.api.client.BrokerFormat

public class BrokerFormat extends Object
String formatting functions. The string can reference values from an Object (currently only supports BrokerEvent). See also BrokerEvent.toFormattedString(...). Event fields can be referenced in the format string by a $ character followed by the fully qualified event field name. The name is terminated by the first space character following the $ character, or it can be enclosed in curly braces: $foo ${foo} $struct.sequence[3].field a${foo}b Optionally, a format specifier can be appended to each field name with a ':': $foo:x ${foo:x} The following formatting options are supported:
   :s - sinqle quoting. Enclose the value in <'>, and escape
        single quotes in the value with a <\>
   :d - double quotes. Enclose the value in <">, and escape double quotes
        in the value with <\>
   :q - SQL quoting. Like :s, but escape with <'>
   :v - Bind variable mode. Primarly intended for use with databases,
        Replace the reference with a proper bind variable placeholder.
        Default is Oracle style, as in :v0, :v1, :v2. Can be changed to
        use <?> with the setFormatMode() call.
   :c - numeric. Use value as numeric value. If value is non-numeric, any
        non-numeric portions will be discarded. I.e. if the value is
        "123X", only "123" will be used in the result.
   :###x - Specify a minimum field length together with one of the options
        above, i.e. <:5d> will print a value of  as <'AB   '>.
 
'\' can be used to escape the following character outside of variable names. To get a '$' character into the result, escape it with a '\', i.e. \\\a\$foo will be returned as \a$foo
  • Field Details

    • modeV

      protected static char modeV
  • Constructor Details

    • BrokerFormat

      public BrokerFormat(String format_string)
      Constructor. Parse the format string into a series of tokens
      Parameters:
      format_string -
  • Method Details

    • getTokenCount

      public int getTokenCount()
      Returns the number of tokens.
      Returns:
      number of tokens
    • isReferenceToken

      public boolean isReferenceToken(int t)
      Checks if a token is a reference to an event field.
      Parameters:
      t - token number
      Returns:
      true if token references an event field, or false if it is a fixed string
    • getTokenValue

      public String getTokenValue(int t)
      Return the value of a token. The value is either a fixed string, or the name of an event field (see isReferenceToken()).
      Parameters:
      t - token number
      Returns:
      value of the token
    • format

      public String format()
      Return formatted string, without event data. Event field values will be formatted for the US English locale.
      Returns:
      formatted string
    • format

      public String format(BrokerEvent event) throws BrokerException
      Return formatted string, using for resolving all event field references. Event field values will be formatted for the US English locale.
      Parameters:
      event - the event for the data
      Returns:
      the formatted string
      Throws:
      BrokerException
    • format

      public String format(BrokerEvent event, Locale locale) throws BrokerException
      Return formatted string, using for resolving all event field references. Event field values will be formatted for the specified locale.
      Parameters:
      event - the event for the data
      locale - determines format of field value output
      Returns:
      the formatted string
      Throws:
      BrokerException
    • setFormatMode

      public static boolean setFormatMode(String format_option, String mode)
      set the mode for a format option (see above). These options can currently be configured: v - ':' (as in :v0, :v1) or '?' Date formatting can be affected by setting the mode to one of these: - BrokerDate -> use BrokerDate.toString() - DateFormat -> Use java.text.DateFormat to format dates Returns true if a valid mode was set. Returns false if format_option or mode are not valid values.
    • format

      public static String format(BrokerEvent event, String format_string) throws BrokerException
      Format an event using a format string. Equivalent to format(event, format_string, java.util.Locale.US)
      Parameters:
      event - the event for the data
      format_string - the format string
      Returns:
      the formatted string
      Throws:
      BrokerException
    • format

      public static String format(BrokerEvent event, String format_string, Locale locale) throws BrokerException
      Format an event using a format string. Event field values will be formatted for the specified locale.
      Parameters:
      event - the event for the data
      format_string - the format string
      locale - determines formatting of field values
      Returns:
      the formatted string
      Throws:
      BrokerException
    • preparse

      public static Vector<COM.activesw.api.client.BrokerFormatToken> preparse(String format_string)
      Take a string, and break it up into a list of tokens. Deprecated - consider using new BrokerFormat(format_string) instead. Returns null if format_string is null.
    • assemble

      public static String assemble(BrokerEvent event, Vector tokens) throws BrokerException
      Assemble a string from the tokens, replacing references with values from the event. Field values will be formatted for the US English locale. Equivalent to assemble(event,tokens,java.util.Locale.US) Deprecated - consider using format() method instead
      Throws:
      BrokerFieldNotFoundException - If a field is referenced in the format string that is not in the event.
      BrokerInvalidTypeException - If a field is not of a type supported by the string formatter.
      BrokerException
    • assemble

      public static String assemble(BrokerEvent event, Vector tokens, Locale locale) throws BrokerException
      Assemble a string from the tokens, replacing references with values from the event. Field values will be formatted for the specified locale. Deprecated - consider using format() method instead
      Throws:
      BrokerFieldNotFoundException - If a field is referenced in the format string that is not in the event.
      BrokerInvalidTypeException - If a field is not of a type supported by the string formatter.
      BrokerException
    • assemble

      public static String assemble(Vector tokens)
      Assemble a string from the tokens, without an event reference. Event field values will be formatted for the US English locale. Deprecated - consider using format() method instead
    • formatBindVariable

      public String formatBindVariable(int index, StringBuffer place_holder_name)
      Returns the name of the bind variable at token in . Returns null if there is no bind variable at that position, or if the index is not valid. If place_holder_name is not null, it will be set to a string that represents the place holder in the statement (i.e. ":v0" or "?").