use of org.eigenbase.xom.DOMWrapper in project pentaho-platform by pentaho.
the class MondrianCatalogHelper method makeSchema.
protected MondrianSchema makeSchema(final String catalogStr) {
if (MondrianCatalogHelper.logger.isDebugEnabled()) {
MondrianCatalogHelper.logger.debug("makeSchema (catalogStr=" + catalogStr.substring(0, Math.min(40, catalogStr.length())) + "...)");
}
MondrianSchema schema = null;
try {
final Parser xmlParser = XOMUtil.createDefaultParser();
final DOMWrapper def = xmlParser.parse(catalogStr);
MondrianDef.Schema schemaFromXml = new MondrianDef.Schema(def);
String schemaName = schemaFromXml.name;
List<MondrianCube> mondrianCubes = new ArrayList<MondrianCube>();
for (MondrianDef.Cube cube : schemaFromXml.cubes) {
if (cube.enabled == null || cube.enabled.booleanValue()) {
String name = cube.caption;
if (StringUtils.isBlank(name)) {
name = cube.name;
}
mondrianCubes.add(new MondrianCube(name, cube.name));
}
}
for (MondrianDef.VirtualCube cube : schemaFromXml.virtualCubes) {
String name = cube.caption;
if (StringUtils.isBlank(name)) {
name = cube.name;
}
if (cube.enabled == null || cube.enabled.booleanValue()) {
mondrianCubes.add(new MondrianCube(name, cube.name));
}
}
// Interpret the role names
MondrianDef.Role[] roles = schemaFromXml.roles;
String[] roleNames = null;
if ((roles != null) && (roles.length > 0)) {
roleNames = new String[roles.length];
for (int i = 0; i < roles.length; i++) {
// Note - getName() doesn't return the role name, it returns the word Role
roleNames[i] = roles[i].name;
}
}
schema = new MondrianSchema(schemaName, mondrianCubes, roleNames);
} catch (XOMException e) {
if (MondrianCatalogHelper.logger.isErrorEnabled()) {
MondrianCatalogHelper.logger.error(Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0008_ERROR_OCCURRED"), // $NON-NLS-1$
e);
}
throw Util.newError(e, Messages.getInstance().getErrorString("MondrianCatalogHelper.ERROR_0009_WHILE_PARSING_CATALOG", // $NON-NLS-1$
catalogStr));
}
return schema;
}
Aggregations