mondrian.xmla
Class XmlaUtil

java.lang.Object
  extended by mondrian.xmla.XmlaUtil
All Implemented Interfaces:
XmlaConstants

public class XmlaUtil
extends java.lang.Object
implements XmlaConstants

Utility methods for XML/A implementation.

Version:
$Id: //open/mondrian/src/main/mondrian/xmla/XmlaUtil.java#28 $
Author:
Gang Chen

Nested Class Summary
static class XmlaUtil.MetadataRowset
          Result of a metadata query.
static class XmlaUtil.Wildcard
          Wrapper which indicates that a restriction is to be treated as a SQL-style wildcard match.
 
Field Summary
 
Fields inherited from interface mondrian.xmla.XmlaConstants
CHH_AUTHORIZATION_CODE, CHH_AUTHORIZATION_FAULT_FS, CHH_CODE, CHH_FAULT_FS, CLIENT_FAULT_FC, CONTENT_DEFAULT, CONTEXT_ROLE, CONTEXT_ROLE_NAME, CONTEXT_XMLA_SESSION_ID, CONTEXT_XMLA_SESSION_STATE, CONTEXT_XMLA_SESSION_STATE_BEGIN, CONTEXT_XMLA_SESSION_STATE_END, CONTEXT_XMLA_SESSION_STATE_WITHIN, CPOSTA_CODE, CPOSTA_FAULT_FS, CPREA_CODE, CPREA_FAULT_FS, FAULT_ACTOR, FAULT_FC_PREFIX, FAULT_FS_PREFIX, FAULT_NS_PREFIX, HSB_ACCESS_DENIED_CODE, HSB_ACCESS_DENIED_FAULT_FS, HSB_BAD_COMMAND_CODE, HSB_BAD_COMMAND_FAULT_FS, HSB_BAD_METHOD_CODE, HSB_BAD_METHOD_FAULT_FS, HSB_BAD_METHOD_NS_CODE, HSB_BAD_METHOD_NS_FAULT_FS, HSB_BAD_NON_NULLABLE_COLUMN_CODE, HSB_BAD_NON_NULLABLE_COLUMN_FAULT_FS, HSB_BAD_PROPERTIES_CODE, HSB_BAD_PROPERTIES_FAULT_FS, HSB_BAD_PROPERTIES_LIST_CODE, HSB_BAD_PROPERTIES_LIST_FAULT_FS, HSB_BAD_REQUEST_TYPE_CODE, HSB_BAD_REQUEST_TYPE_FAULT_FS, HSB_BAD_RESTRICTION_LIST_CODE, HSB_BAD_RESTRICTION_LIST_FAULT_FS, HSB_BAD_RESTRICTION_TYPE_CODE, HSB_BAD_RESTRICTION_TYPE_FAULT_FS, HSB_BAD_RESTRICTION_VALUE_CODE, HSB_BAD_RESTRICTION_VALUE_FAULT_FS, HSB_BAD_RESTRICTIONS_CODE, HSB_BAD_RESTRICTIONS_FAULT_FS, HSB_BAD_SOAP_BODY_CODE, HSB_BAD_SOAP_BODY_FAULT_FS, HSB_BAD_STATEMENT_CODE, HSB_BAD_STATEMENT_FAULT_FS, HSB_CONNECTION_DATA_SOURCE_CODE, HSB_CONNECTION_DATA_SOURCE_FAULT_FS, HSB_DISCOVER_FORMAT_CODE, HSB_DISCOVER_FORMAT_FAULT_FS, HSB_DISCOVER_UNPARSE_CODE, HSB_DISCOVER_UNPARSE_FAULT_FS, HSB_DRILL_THROUGH_FORMAT_CODE, HSB_DRILL_THROUGH_FORMAT_FAULT_FS, HSB_DRILL_THROUGH_NOT_ALLOWED_CODE, HSB_DRILL_THROUGH_NOT_ALLOWED_FAULT_FS, HSB_DRILL_THROUGH_SQL_CODE, HSB_DRILL_THROUGH_SQL_FAULT_FS, HSB_DRILLDOWN_BAD_FIRST_ROWSET_CODE, HSB_DRILLDOWN_BAD_FIRST_ROWSET_FAULT_FS, HSB_DRILLDOWN_BAD_MAXROWS_CODE, HSB_DRILLDOWN_BAD_MAXROWS_FAULT_FS, HSB_DRILLDOWN_ERROR_CODE, HSB_DRILLDOWN_ERROR_FAULT_FS, HSB_EXECUTE_QUERY_CODE, HSB_EXECUTE_QUERY_FAULT_FS, HSB_EXECUTE_UNPARSE_CODE, HSB_EXECUTE_UNPARSE_FAULT_FS, HSB_PARSE_QUERY_CODE, HSB_PARSE_QUERY_FAULT_FS, HSB_PROCESS_CODE, HSB_PROCESS_FAULT_FS, HSB_UNKNOWN_CODE, HSB_UNKNOWN_FAULT_FS, HSB_UNSUPPORTED_OPERATION_CODE, HSB_UNSUPPORTED_OPERATION_FAULT_FS, HSH_BAD_SESSION_ID_CODE, HSH_BAD_SESSION_ID_FAULT_FS, HSH_MUST_UNDERSTAND_CODE, HSH_MUST_UNDERSTAND_FAULT_FS, HSH_UNKNOWN_CODE, HSH_UNKNOWN_FAULT_FS, METHOD_DISCOVER, METHOD_EXECUTE, MONDRIAN_NAMESPACE, MSM_UNKNOWN_CODE, MSM_UNKNOWN_FAULT_FS, MUST_UNDERSTAND_FAULT_FC, NS_SOAP_ENC_1_1, NS_SOAP_ENC_1_2, NS_SOAP_ENV_1_1, NS_SOAP_ENV_1_2, NS_SQL, NS_XMLA, NS_XMLA_EMPTY, NS_XMLA_EX, NS_XMLA_MDDATASET, NS_XMLA_ROWSET, NS_XSD, NS_XSI, SERVER_FAULT_FC, SOAP_MUST_UNDERSTAND_ATTR, SOAP_PREFIX, UNKNOWN_ERROR_CODE, UNKNOWN_ERROR_FAULT_FS, USM_DOM_FACTORY_CODE, USM_DOM_FACTORY_FAULT_FS, USM_DOM_PARSE_CODE, USM_DOM_PARSE_FAULT_FS, USM_DOM_PARSE_IO_CODE, USM_DOM_PARSE_IO_FAULT_FS, USM_REQUEST_INPUT_CODE, USM_REQUEST_INPUT_FAULT_FS, USM_REQUEST_STATE_CODE, USM_REQUEST_STATE_FAULT_FS, USM_UNKNOWN_CODE, USM_UNKNOWN_FAULT_FS, VERSION_MISSMATCH_FAULT_FC, XMLA_BEGIN_SESSION, XMLA_END_SESSION, XMLA_SESSION, XMLA_SESSION_ID
 
Constructor Summary
XmlaUtil()
           
 
Method Summary
static void element2Text(org.w3c.dom.Element elem, java.io.StringWriter writer)
           
static java.lang.String encodeElementName(java.lang.String name)
          Encodes an XML element name.
static org.w3c.dom.Element[] filterChildElements(org.w3c.dom.Element parent, java.lang.String ns, java.lang.String lname)
           
static org.w3c.dom.Element firstChildElement(org.w3c.dom.Element parent, java.lang.String ns, java.lang.String lname)
          Returns the first child element of an XML element, or null if there is no first child.
static void generateMetamodelJavadoc()
          Generates descriptions of the columns returned by each metadata query, in javadoc format, suitable for pasting into OlapDatabaseMetaData.
static XmlaUtil.MetadataRowset getMetadataRowset(Connection connection, java.lang.String catalogName, java.lang.String methodName, java.util.Map<java.lang.String,java.lang.Object> restrictionMap)
          Returns a set of column headings and rows for a given metadata request.
static java.lang.String normalizeNumericString(java.lang.String numericStr)
          Corrects for the differences between numeric strings arising because JDBC drivers use different representations for numbers (Double vs.
static java.lang.Throwable rootThrowable(java.lang.Throwable throwable)
          Finds root MondrianException in exception chain if exists, otherwise the input throwable.
static org.w3c.dom.Element stream2Element(java.io.InputStream stream)
           
static org.w3c.dom.Element text2Element(java.lang.String text)
           
static java.lang.String textInElement(org.w3c.dom.Element elem)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlaUtil

public XmlaUtil()
Method Detail

encodeElementName

public static java.lang.String encodeElementName(java.lang.String name)
Encodes an XML element name.

This function is mainly for encode element names in result of Drill Through execute, because its element names come from database, we cannot make sure they are valid XML contents.

Quoth the XML/A specification, version 1.1:

XML does not allow certain characters as element and attribute names. XML for Analysis supports encoding as defined by SQL Server 2000 to address this XML constraint. For column names that contain invalid XML name characters (according to the XML 1.0 specification), the nonvalid Unicode characters are encoded using the corresponding hexadecimal values. These are escaped as _xHHHH_ where HHHH stands for the four-digit hexadecimal UCS-2 code for the character in most-significant bit first order. For example, the name "Order Details" is encoded as Order_x0020_Details, where the space character is replaced by the corresponding hexadecimal code.

Parameters:
name - Name of XML element
Returns:
encoded name

element2Text

public static void element2Text(org.w3c.dom.Element elem,
                                java.io.StringWriter writer)
                         throws XmlaException
Throws:
XmlaException

text2Element

public static org.w3c.dom.Element text2Element(java.lang.String text)
                                        throws XmlaException
Throws:
XmlaException

stream2Element

public static org.w3c.dom.Element stream2Element(java.io.InputStream stream)
                                          throws XmlaException
Throws:
XmlaException

firstChildElement

public static org.w3c.dom.Element firstChildElement(org.w3c.dom.Element parent,
                                                    java.lang.String ns,
                                                    java.lang.String lname)
Returns the first child element of an XML element, or null if there is no first child.

Parameters:
parent - XML element
ns - Namespace
lname - Local name of child
Returns:
First child, or null if there is no child element

filterChildElements

public static org.w3c.dom.Element[] filterChildElements(org.w3c.dom.Element parent,
                                                        java.lang.String ns,
                                                        java.lang.String lname)

textInElement

public static java.lang.String textInElement(org.w3c.dom.Element elem)

rootThrowable

public static java.lang.Throwable rootThrowable(java.lang.Throwable throwable)
Finds root MondrianException in exception chain if exists, otherwise the input throwable.

Parameters:
throwable - Exception
Returns:
Root exception

normalizeNumericString

public static java.lang.String normalizeNumericString(java.lang.String numericStr)
Corrects for the differences between numeric strings arising because JDBC drivers use different representations for numbers (Double vs. BigDecimal) and these have different toString() behavior.

If it contains a decimal point, then strip off trailing '0's. After stripping off the '0's, if there is nothing right of the decimal point, then strip off decimal point.

Parameters:
numericStr - Numeric string
Returns:
Normalized string

getMetadataRowset

public static XmlaUtil.MetadataRowset getMetadataRowset(Connection connection,
                                                        java.lang.String catalogName,
                                                        java.lang.String methodName,
                                                        java.util.Map<java.lang.String,java.lang.Object> restrictionMap)
Returns a set of column headings and rows for a given metadata request.

Leverages mondrian's implementation of the XML/A specification, and is exposed here for use by mondrian's olap4j driver.

Parameters:
connection - Connection
catalogName - Catalog name
methodName - Metadata method name per XMLA (e.g. "MDSCHEMA_CUBES")
restrictionMap - Restrictions
Returns:
Set of rows and column headings

generateMetamodelJavadoc

public static void generateMetamodelJavadoc()
                                     throws java.io.IOException
Generates descriptions of the columns returned by each metadata query, in javadoc format, suitable for pasting into OlapDatabaseMetaData.

Throws:
java.io.IOException

Get Mondrian at SourceForge.net. Fast, secure and free Open Source software downloads