Package net.aifusion.metamodel
Class ModelUtilities
java.lang.Object
net.aifusion.metamodel.ModelUtilities
This class contains a number of static methods used in the metamodel package
- Author:
- Sharad Singhal
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
Decode a base64 encoded string to a byte arraystatic String
base64Encode
(byte[] bytes) Encode a byte array to a base64 encoded stringstatic String
base64Encode
(byte[] bytes, int offset, int length) Encode a byte array to a base64 encoded stringstatic String
Escapes special characters in a string for MOF stringsGet a hashmap containing {name, value} pairs passed as an argument list.getPathElements
(String localPath) Get path elements from a local path definition.getProperties
(CimStructure template, Map<String, String> recordProperties) Convert a set of {propertyName, propertyValue} pairs to DataValuesstatic String
getRandomString
(int len) Get a random string of ascii charactersstatic String
normalizePath
(String localPath) Normalize a local path to remove .static String
Escapes special characters in a string to generate a MOF formatted stringstatic String
toMOFString
(DataType type, Object value) Return the string representation of a dataValue singletonstatic String
unescapeString
(String inp) Removes the first level of escapes from a MOF stringstatic String
Removes the first level of quotes and escapes from a string
-
Method Details
-
quote
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
Removes the first level of quotes and escapes from a string- Parameters:
value
- - the string to unquote- Returns:
- the unquoted string
- See Also:
-
escape
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
Removes the first level of escapes from a MOF string- Parameters:
inp
- the string to unescape- Returns:
- the unescaped string
- See Also:
-
toMOFString
Return the string representation of a dataValue singleton- Parameters:
type
- - data type of dataValuevalue
- - underlying java object containing dataValue- Returns:
- - string representation
-
base64Encode
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
Encode a byte array to a base64 encoded string- Parameters:
bytes
- - array containing bytes to be encodedoffset
- - offset within array where transformation startslength
- - 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
Decode a base64 encoded string to a byte array- Parameters:
s
- - string to be decoded- Returns:
- - decoded byte array
- See Also:
-
normalizePath
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
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
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 valuesrecordProperties
- - record properties provided. Array properties should be given as "," separated string values- Returns:
- map containing invalid input: '<'propertyName, DataValue>
-
getRandomString
Get a random string of ascii characters- Parameters:
len
- - length of string- Returns:
- random string
-