Class ModelUtilities

java.lang.Object
net.aifusion.metamodel.ModelUtilities

public class ModelUtilities extends Object
This class contains a number of static methods used in the metamodel package
Author:
Sharad Singhal
  • Method Details

    • quote

      public static String quote(String inp)
      Escapes special characters in a string to generate a MOF formatted string
      Parameters:
      inp - the string to process
      Returns:
      The string with all of the special characters escaped.
      See Also:
    • unquote

      public static String unquote(String value)
      Removes the first level of quotes and escapes from a string
      Parameters:
      value - - the string to unquote
      Returns:
      the unquoted string
      See Also:
    • escape

      public static String escape(String str)
      Escapes special characters in a string for MOF strings
      Parameters:
      str - the string to process
      Returns:
      The string with all of the special characters escaped
      See Also:
    • unescapeString

      public static String unescapeString(String inp)
      Removes the first level of escapes from a MOF string
      Parameters:
      inp - the string to unescape
      Returns:
      the unescaped string
      See Also:
    • toMOFString

      public static String toMOFString(DataType type, Object value)
      Return the string representation of a dataValue singleton
      Parameters:
      type - - data type of dataValue
      value - - underlying java object containing dataValue
      Returns:
      - string representation
    • base64Encode

      public static String base64Encode(byte[] bytes)
      Encode a byte array to a base64 encoded string
      Parameters:
      bytes - - array of bytes to be encoded
      Returns:
      - string representation of bytes
      See Also:
    • base64Encode

      public static String base64Encode(byte[] bytes, int offset, int length)
      Encode a byte array to a base64 encoded string
      Parameters:
      bytes - - array containing bytes to be encoded
      offset - - offset within array where transformation starts
      length - - number of bytes to be encoded
      Returns:
      - string containing base64 representation of the array
      Throws:
      ModelException - if the operation goes past either end of the array
    • base64Decode

      public static byte[] base64Decode(String s)
      Decode a base64 encoded string to a byte array
      Parameters:
      s - - string to be decoded
      Returns:
      - decoded byte array
      See Also:
    • normalizePath

      public static String normalizePath(String localPath)
      Normalize a local path to remove . and .. segments.
      Parameters:
      localPath - - local path to be checked
      Returns:
      - local path with all "." and ".." segments removed. An empty local path will return "/"
    • getPathElements

      public static Vector<String> getPathElements(String localPath)
      Get path elements from a local path definition. The path is split using "/" or "\" characters. All '.' and empty segments are ignored, and all ".." segments move up the hierarchy without going past the initial level. All path elements are converted to lower case
      Parameters:
      localPath - - local path to be broken
      Returns:
      - vector containing path elements
    • getArgs

      public static HashMap<String,String> getArgs(String[] argv)
      Get a hashmap containing {name, value} pairs passed as an argument list. Each {name, value} pair is represented as [-name value] ... in the argument list. In case the value contains spaces, it can either be quoted, or be enclosed in braces. The returned Hashmap is keyed by name (sans the '-') and contains the corresponding value. Note that names are converted to lowercase, so are case insensitive
      Parameters:
      argv - - string array to be parsed
      Returns:
      - argument map
    • getProperties

      public static HashMap<String,DataValue> getProperties(CimStructure template, Map<String,String> recordProperties)
      Convert a set of {propertyName, propertyValue} pairs to DataValues
      Parameters:
      template - - CimStructure template to scan for constructing values
      recordProperties - - record properties provided. Array properties should be given as "," separated string values
      Returns:
      map containing invalid input: '<'propertyName, DataValue>
    • getRandomString

      public static String getRandomString(int len)
      Get a random string of ascii characters
      Parameters:
      len - - length of string
      Returns:
      random string