Class PropertyUtil

java.lang.Object
org.apache.qpid.jms.util.PropertyUtil

public class PropertyUtil extends Object
Utilities for properties
  • Constructor Details

    • PropertyUtil

      public PropertyUtil()
  • Method Details

    • replaceQuery

      public static URI replaceQuery(URI originalURI, Map<String,String> properties) throws URISyntaxException
      Creates a URI from the original URI and the given parameters. The string values in the Map will be URL Encoded by this method which means that if an already encoded value is passed it will be double encoded resulting in corrupt values in the newly created URI.
      Parameters:
      originalURI - The URI whose current parameters are removed and replaced with the given remainder value.
      properties - The URI properties that should be used to replace the current ones in the target.
      Returns:
      a new URI that matches the original one but has its query options replaced with the given ones.
      Throws:
      URISyntaxException - if the given URI is invalid.
    • replaceQuery

      public static URI replaceQuery(URI uri, String query) throws URISyntaxException
      Creates a URI with the given query, removing an previous query value from the given URI.
      Parameters:
      uri - The source URI whose existing query is replaced with the newly supplied one.
      query - The new URI query string that should be appended to the given URI.
      Returns:
      a new URI that is a combination of the original URI and the given query string.
      Throws:
      URISyntaxException - if the given URI is invalid.
    • eraseQuery

      public static URI eraseQuery(URI uri) throws URISyntaxException
      Creates a URI with the given query, removing an previous query value from the given URI.
      Parameters:
      uri - The source URI whose existing query is replaced with the newly supplied one.
      Returns:
      a new URI that is a combination of the original URI and the given query string.
      Throws:
      URISyntaxException - if the given URI is invalid.
    • createQueryString

      public static String createQueryString(Map<String,? extends Object> options) throws URISyntaxException
      Given a key / value mapping, create and return a URI formatted query string that is valid and can be appended to a URI string. The values in the given Map are URL Encoded during construction of the query string, if the original values were previously encoded this can result in double encoding.
      Parameters:
      options - The Mapping that will create the new Query string.
      Returns:
      a URI formatted query string.
      Throws:
      URISyntaxException - if the given URI is invalid.
    • parseQuery

      public static Map<String,String> parseQuery(URI uri) throws Exception
      Get properties from the Query portion of the given URI.
      Parameters:
      uri - the URI whose Query string should be parsed.
      Returns:
      Map of properties from the parsed string.
      Throws:
      Exception - if an error occurs while parsing the query options.
    • parseQuery

      public static Map<String,String> parseQuery(String queryString) throws Exception
      Get properties from a URI Query String obtained by calling the getRawQuery method on a given URI or from some other source.
      Parameters:
      queryString - the query string obtained from called getRawQuery on a given URI.
      Returns:
      Map of properties from the parsed string.
      Throws:
      Exception - if an error occurs while parsing the query options.
    • filterProperties

      public static Map<String,String> filterProperties(Map<String,String> properties, String optionPrefix)
      Given a map of properties, filter out only those prefixed with the given value, the values filtered are returned in a new Map instance.
      Parameters:
      properties - The map of properties to filter.
      optionPrefix - The prefix value to use when filtering.
      Returns:
      a filter map with only values that match the given prefix.
    • setProperties

      public static Map<String,String> setProperties(Object target, Map<String,String> properties)
      Set properties on an object using the provided map. The return value indicates if all properties from the given map were set on the target object.
      Parameters:
      target - the object whose properties are to be set from the map options.
      properties - the properties that should be applied to the given object.
      Returns:
      true if all values in the properties map were applied to the target object.
    • setProperties

      public static Map<String,Object> setProperties(Object target, Properties properties)
      Set properties on an object using the provided Properties object. The return value indicates if all properties from the given map were set on the target object.
      Parameters:
      target - the object whose properties are to be set from the map options.
      properties - the properties that should be applied to the given object.
      Returns:
      an unmodifiable map with any values that could not be applied to the target.
    • getProperties

      public static Map<String,String> getProperties(Object object) throws Exception
      Get properties from an object using reflection. If the passed object is null an empty Map is returned.
      Parameters:
      object - the Object whose properties are to be extracted.
      Returns:
      Map of properties extracted from the given object.
      Throws:
      Exception - if an error occurs while examining the object's properties.
    • getProperty

      public static Object getProperty(Object object, String name) throws Exception
      Find a specific property getter in a given object based on a property name.
      Parameters:
      object - the object to search.
      name - the property name to search for.
      Returns:
      the result of invoking the specific property get method.
      Throws:
      Exception - if an error occurs while searching the object's bean info.
    • setProperty

      public static boolean setProperty(Object target, String name, Object value)
      Set a property named property on a given Object.

      The object is searched for an set method that would match the given named property and if one is found. If necessary an attempt will be made to convert the new value to an acceptable type.

      Parameters:
      target - The object whose property is to be set.
      name - The name of the property to set.
      value - The new value to set for the named property.
      Returns:
      true if the property was able to be set on the target object.
    • stripPrefix

      public static String stripPrefix(String value, String prefix)
      Return a String minus the given prefix. If the string does not start with the given prefix the original string value is returned.
      Parameters:
      value - The String whose prefix is to be removed.
      prefix - The prefix string to remove from the target string.
      Returns:
      stripped version of the original input string.
    • stripUpto

      public static String stripUpto(String value, char c)
      Return a portion of a String value by looking beyond the given character.
      Parameters:
      value - The string value to split
      c - The character that marks the split point.
      Returns:
      the sub-string value starting beyond the given character.
    • stripBefore

      public static String stripBefore(String value, char c)
      Return a String up to and including character
      Parameters:
      value - The string value to split
      c - The character that marks the start of split point.
      Returns:
      the sub-string value starting from the given character.