Class MQConstants

java.lang.Object
com.ibm.mq.constants.MQConstants
All Implemented Interfaces:
CMQBC, CMQC, CMQCFC, CMQPSC, CMQXC, CMQZC, MQPropertyIdentifiers

public abstract class MQConstants extends Object implements CMQBC, CMQC, CMQCFC, CMQPSC, CMQXC, CMQZC, MQPropertyIdentifiers
Class allowing IBM MQ constants to be looked up by name or by value within an application. A typical use of this class is to obtain the named constant values for PCF parameters or exception reason codes from PCF responses. For example, if a response contains the integer value 2035 as the reason code, the lookupReasonCode method can be used to convert the value into the string MQRC_NOT_AUTHORIZED. Alternatively, this class can be used to look up constant values from names, for example when building PCF requests from user input.

The lookup method looks up constant names based upon a supplied value, using the set of constants defined in the CMQBC, CMQC, CMQCFC, CMQPSC, CMQXC and CMQZC interfaces. In general, there may be a number of constants that match a specific value. For example, there are two constants with the value 2035 (MQRC_NOT_AUTHORIZED and MQCA_REPOSITORY_NAME). To obtain a constant whose name follows a particular pattern, a regular expression can be specified that filters the set of matching constants to one whose name matches the expression.

When looking up a reason code, we are expecting a constant whose name begins MQRC_, which is expressed by a filter string MQRC_.*:

String reason = MQConstants.lookup(2035, "MQRC_.*");
The convenience methods lookupReasonCode is provided for the common case. For details of regular expression syntax, see the java.util.regex package documentation.

To return all constants that match a given value, pass null for the filter parameter.

Internally, this class uses Java reflection to look up constant names, and maintains a cache of previously accessed values. The reflected field information is loaded on demand and held by soft references in order that it is freed if necessary during garbage collection. Note that the interface TempConstants which this class implements is used in product development only and is an empty interface in released builds of the IBM MQ class files.

See Also:
  • Constructor Details

    • MQConstants

      public MQConstants()
  • Method Details

    • getValue

      public static Object getValue(String name)
      Returns the value of the named MQSeries constant. This will be an object of type Integer, String, byte[], or char[].
      Parameters:
      name - the constant name
      Returns:
      an object representing the constant value, or null if not found
    • getIntValue

      public static int getIntValue(String name) throws NoSuchElementException
      Returns the value of the named MQSeries constant as an int.
      Parameters:
      name - the constant name
      Returns:
      an integer representing the constant value.
      Throws:
      NoSuchElementException - if the named constant is not found or is not an integer field
      NoSuchElementException - if value is null or is not a number.
    • lookupCompCode

      public static String lookupCompCode(int reason)
      Convenience method for finding the constant name for a completion code. This is equivalent to
      
      lookup(compcode, "MQCC_.*")
      
      
      Parameters:
      reason - the reason code
      Returns:
      string representing the comp code
    • lookupReasonCode

      public static String lookupReasonCode(int reason)
      Convenience method for finding the constant name for a reason code. This is equivalent to
      
      lookup(reason, "MQRC_.*|MQRCCF_.*")
      
      
      Parameters:
      reason - the reason code
      Returns:
      string representing the reason code
    • lookup

      public static String lookup(Object value, String filter)
      Returns the MQSeries constant name or names for the supplied value of type Integer, String, byte[], or char[]. The filter argument is a regular expression to filter the set of constants returned. If the filter string is null, no filtering is performed and all matching constant names are returned in a whitespace-delimited string. If more than one constant name matches the supplied value and filter, the string returned is composed of the matching names separated by forward slashes.
      Parameters:
      value - an object which represents the value
      filter - a filter to apply to the name(s) to return
      Returns:
      string, or slash-delimited strings, representing the constant
    • lookup

      public static List<String> lookup(Object valueP, boolean parse)
      Parameters:
      valueP - Object referring to value whose name to be returned.
      parse - true if String values should be parsed as integers
      Returns:
      the IBM MQ constant name or names for the supplied value of type Integer, String, byte[], or char[].
    • lookup

      public static String lookup(int value, String filter)
      Returns the MQSeries constant name or names for the supplied int value. The filter argument is a regular expression to filter the set of constants returned. If the filter string is null, no filtering is performed and all matching constant names are returned in a whitespace-delimited string.
      Parameters:
      value - an object which represents the value
      filter - a filter to apply to the name(s) to return
      Returns:
      string, or white-space-delimited strings, representing the constant
    • filter

      public static final List<String> filter(List<String> constantNames, Pattern filterPattern)
      Applies a pattern to extract a matching individual constant name from a delimited string containing one or more constant names.
      Parameters:
      constantNames - List of names to be filtered
      filterPattern - pattern to filter with
      Returns:
      List of matching names
    • main

      public static void main(String[] args)
      Parameters:
      args - options values to decode
    • decodeOptions

      public static String decodeOptions(int options, String optionPattern)
      This helper method takes an integer representing a set of IBM MQ options for an MQI structure, and converts them into a string displaying the constants that the options represent.
      Parameters:
      options - - The options for a WMQ structure that need to be converted into a string
      optionPattern - - A regular expression representing an MQI structure, such as MQGMO_.*, that the options have been set on.
      Returns:
      A string containing the constant values that the options field represent.
    • decodeOptionsForTrace

      public static String decodeOptionsForTrace(int options, String optionPattern)
      This helper method takes an integer representing a set of IBM MQ options for an MQI structure, and converts them into a string displaying the constants that the options represent, in a form that service appreciate in trace...
      Parameters:
      options - - The options for a WMQ structure that need to be converted into a string
      optionPattern - - A regular expression representing an MQI structure, such as MQGMO_.*, that the options have been set on.
      Returns:
      A string containing the constant values that the options field represent.
    • decodeOptionsAsList

      public static List<List<String>> decodeOptionsAsList(int optionsP, String optionPattern)
      Parameters:
      optionsP - - The options for a WMQ structure that need to be converted into a string
      optionPattern - - A regular expression representing an MQI structure, such as MQGMO_.*,
      Returns:
      a list of lists - each embedded list is a list of potential names for one set bit in the options value
    • getHttpsCertValPolString

      public static String getHttpsCertValPolString(int httpsCertValPol)
      Converts integer representation of HTTPS certificate validation policy to string representation
      Parameters:
      httpsCertValPol - - integer value
      Returns:
      level of certificate validation