com.ibm.mq.constants

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 java.lang.Object
    implements CMQBC, CMQC, CMQCFC, CMQPSC, CMQXC, CMQZC, MQPropertyIdentifiers
    Class allowing MQSeries 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.

    See Also:
    CMQBC, CMQC, CMQCFC, CMQPSC, CMQXC, CMQZC
    • Constructor Detail

      • MQConstants

        public MQConstants()
    • Method Detail

      • getValue

        public static java.lang.Object getValue(java.lang.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(java.lang.String name)
                               throws java.util.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:
        java.util.NoSuchElementException - if the named constant is not found or is not an integer field
        java.util.NoSuchElementException
      • lookupCompCode

        public static java.lang.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 java.lang.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 java.lang.String lookup(java.lang.Object value,
                                              java.lang.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 java.lang.String lookup(int value,
                                              java.lang.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
      • main

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

        public static java.lang.String decodeOptions(int optionsP,
                                                     java.lang.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:
        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_.*, that the options have been set on.
        Returns:
        A string containing the constant values that the options field represent.
(c) Copyright IBM Corp. 2008, 2016. All Rights Reserved.