Search in sources :

Example 6 with Parser

use of org.eigenbase.xom.Parser in project mondrian by pentaho.

the class RolapCube method createCalculatedMember.

public Member createCalculatedMember(String xml) {
    MondrianDef.CalculatedMember xmlCalcMember;
    try {
        final Parser xmlParser = XOMUtil.createDefaultParser();
        final DOMWrapper def = xmlParser.parse(xml);
        final String tagName = def.getTagName();
        if (tagName.equals("CalculatedMember")) {
            xmlCalcMember = new MondrianDef.CalculatedMember(def);
        } else {
            throw new XOMException("Got <" + tagName + "> when expecting <CalculatedMember>");
        }
    } catch (XOMException e) {
        throw Util.newError(e, "Error while creating calculated member from XML [" + xml + "]");
    }
    try {
        loadInProgress = true;
        final List<RolapMember> memberList = new ArrayList<RolapMember>();
        createCalcMembersAndNamedSets(Collections.singletonList(xmlCalcMember), Collections.<MondrianDef.NamedSet>emptyList(), memberList, new ArrayList<Formula>(), this, true);
        assert memberList.size() == 1;
        return memberList.get(0);
    } finally {
        loadInProgress = false;
    }
}
Also used : Parser(org.eigenbase.xom.Parser)

Example 7 with Parser

use of org.eigenbase.xom.Parser in project mondrian by pentaho.

the class RolapSchema method createDimension.

public Dimension createDimension(Cube cube, String xml) {
    MondrianDef.CubeDimension xmlDimension;
    try {
        final Parser xmlParser = XOMUtil.createDefaultParser();
        final DOMWrapper def = xmlParser.parse(xml);
        final String tagName = def.getTagName();
        if (tagName.equals("Dimension")) {
            xmlDimension = new MondrianDef.Dimension(def);
        } else if (tagName.equals("DimensionUsage")) {
            xmlDimension = new MondrianDef.DimensionUsage(def);
        } else {
            throw new XOMException("Got <" + tagName + "> when expecting <Dimension> or <DimensionUsage>");
        }
    } catch (XOMException e) {
        throw Util.newError(e, "Error while adding dimension to cube '" + cube + "' from XML [" + xml + "]");
    }
    return ((RolapCube) cube).createDimension(xmlDimension, xmlSchema);
}
Also used : ByteString(mondrian.util.ByteString) Parser(org.eigenbase.xom.Parser)

Example 8 with Parser

use of org.eigenbase.xom.Parser in project mondrian by pentaho.

the class RolapSchema method load.

/**
 * Method called by all constructors to load the catalog into DOM and build
 * application mdx and sql objects.
 *
 * @param catalogUrl URL of catalog
 * @param catalogStr Text of catalog, or null
 */
protected void load(String catalogUrl, String catalogStr) {
    try {
        final Parser xmlParser = XOMUtil.createDefaultParser();
        final DOMWrapper def;
        if (catalogStr == null) {
            InputStream in = null;
            try {
                in = Util.readVirtualFile(catalogUrl);
                def = xmlParser.parse(in);
            } finally {
                if (in != null) {
                    in.close();
                }
            }
            // Md5 hash.
            if (getLogger().isDebugEnabled() || md5Bytes == null) {
                try {
                    catalogStr = Util.readVirtualFileAsString(catalogUrl);
                } catch (java.io.IOException ex) {
                    getLogger().debug("RolapSchema.load: ex=" + ex);
                    catalogStr = "?";
                }
            }
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("RolapSchema.load: content: \n" + catalogStr);
            }
        } else {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("RolapSchema.load: catalogStr: \n" + catalogStr);
            }
            def = xmlParser.parse(catalogStr);
        }
        if (md5Bytes == null) {
            // computed it above by re-reading the catalog URL.
            assert catalogStr != null;
            md5Bytes = new ByteString(Util.digestMd5(catalogStr));
        }
        // throw error if we have an incompatible schema
        checkSchemaVersion(def);
        xmlSchema = new MondrianDef.Schema(def);
        if (getLogger().isDebugEnabled()) {
            StringWriter sw = new StringWriter(4096);
            PrintWriter pw = new PrintWriter(sw);
            pw.println("RolapSchema.load: dump xmlschema");
            xmlSchema.display(pw, 2);
            pw.flush();
            getLogger().debug(sw.toString());
        }
        load(xmlSchema);
    } catch (XOMException e) {
        throw Util.newError(e, "while parsing catalog " + catalogUrl);
    } catch (FileSystemException e) {
        throw Util.newError(e, "while parsing catalog " + catalogUrl);
    } catch (IOException e) {
        throw Util.newError(e, "while parsing catalog " + catalogUrl);
    }
    aggTableManager.initialize();
    setSchemaLoadDate();
}
Also used : java.io(java.io) ByteString(mondrian.util.ByteString) Parser(org.eigenbase.xom.Parser) FileSystemException(org.apache.commons.vfs2.FileSystemException)

Example 9 with Parser

use of org.eigenbase.xom.Parser in project mondrian by pentaho.

the class DynamicDatasourceXmlaServletTest method getDataSources.

private static DataSourcesConfig.DataSources getDataSources(Map<String, String[]> dsCatalog) throws XOMException {
    final String str = getDataSourceString(dsCatalog);
    final Parser xmlParser = XOMUtil.createDefaultParser();
    final DOMWrapper def = xmlParser.parse(str);
    return new DataSourcesConfig.DataSources(def);
}
Also used : Parser(org.eigenbase.xom.Parser)

Example 10 with Parser

use of org.eigenbase.xom.Parser in project mondrian by pentaho.

the class XmlaSupport method parseDataSources.

public static DataSourcesConfig.DataSources parseDataSources(String dataSourcesConfigString, Logger logger) {
    try {
        if (dataSourcesConfigString == null) {
            logger.warn("XmlaSupport.parseDataSources: null input");
            return null;
        }
        dataSourcesConfigString = Util.replaceProperties(dataSourcesConfigString, Util.toMap(System.getProperties()));
        if (logger.isDebugEnabled()) {
            logger.debug("XmlaSupport.parseDataSources: dataSources=" + dataSourcesConfigString);
        }
        final Parser parser = XOMUtil.createDefaultParser();
        final DOMWrapper doc = parser.parse(dataSourcesConfigString);
        return new DataSourcesConfig.DataSources(doc);
    } catch (XOMException e) {
        throw Util.newError(e, "Failed to parse data sources config: " + dataSourcesConfigString);
    }
}
Also used : Parser(org.eigenbase.xom.Parser)

Aggregations

Parser (org.eigenbase.xom.Parser)12 DOMWrapper (org.eigenbase.xom.DOMWrapper)5 ByteString (mondrian.util.ByteString)3 XOMException (org.eigenbase.xom.XOMException)2 java.io (java.io)1 ArrayList (java.util.ArrayList)1 MondrianDef (mondrian.olap.MondrianDef)1 DataSources (mondrian.xmla.DataSourcesConfig.DataSources)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1