

import oracle.AWXML.*;
import oracle.AWAction.*;
import java.util.*;
import java.sql.*;
import oracle.jdbc.*;


public class xml_build_xademo_aw 
{
  public static AWConnection m_connection;
  private Interaction curInteraction;
  
  public xml_build_xademo_aw(String user, String pwd, String connection)
  {
    m_connection = new AWConnection(user, pwd, connection);
    curInteraction = new Interaction();
    curInteraction.setConnection(m_connection);
    BuildDatabase myBuild = (BuildDatabase)curInteraction.createAction("BUILDDATABASE");
    myBuild.setAWName("XADEMO");
    myBuild.setRunSolve(false);
    myBuild.Execute();
    System.out.println("Done!");
  }


  public static void main(String args[])
  {
    try
    {
      xml_build_xademo_aw newBuild = 
        new xml_build_xademo_aw("xademo", "xademo", "twister12:1865:main1");

      System.out.println("successful");
    }
    catch(Exception e)
    {
      System.out.println("failed to Build with " + e.toString());
    }
    try
    {
      DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
      OracleConnection connection = 
      (OracleConnection)DriverManager.getConnection("jdbc:oracle:thin:@" + "twister12:1865:main1",
        "xademo", "xademo");
      
      String result=null;
      String sqlText = "select distinct xml_loadid " +
                       "from olapsys.xml_load_log " +
                       "order by xml_loadid desc";
      Statement sqlStmt = connection.createStatement();
      ResultSet rs = sqlStmt.executeQuery(sqlText);
      if(rs.next())
      {
        //get the first value
        int loadid = rs.getInt(1);
        rs.close();

        //now get the rest of the log
        sqlText = "select xml_message " +
                  "from olapsys.xml_load_log " +
                  "where xml_loadid = " + loadid + " " +
                  "order by xml_loadid, xml_recordid";
        rs = sqlStmt.executeQuery(sqlText);
        String tempResult;
        while(rs.next())
        {
          tempResult = rs.getString(1);
          if(result == null)
            result = tempResult.trim();
          else
            result = result + "\n" + tempResult.trim();
        }
      }
      System.out.println(result);
    }
    catch(Exception e)
    {
      System.out.println("verifier failure with " + e.toString());
    }
    m_connection.close();
  }
}




import oracle.AWXML.*;
import java.util.*;

public class xml_create_xademo_aw 
{
  Vector _keys = new Vector(0);
  Vector _cols = new Vector(0);  
  Vector _levels = new Vector(0);
  Vector _levColumns = new Vector(0);
  Vector _dimList = new Vector(0);
  Vector _measures = new Vector(0);
  Vector _measCols = new Vector(0);
    
  public xml_create_xademo_aw()
  {
    AW xademo = new AW();
    xademo.setName("XADEMO");
    xademo.setShortName("XADEMO");
    xademo.setPluralName("XADEMO");
    
  //////////////////////////////////////////////////////
  // Create the CHANNEL Dimensions
  /////////////////////////////////////////////////////
    Dimension _channel = xademo.createDimension();
    _channel.setName("CHANNEL_AW");
    _channel.setPluralName("Channels");
    _channel.setShortName("Channel");

    this.createChannelDim(_channel);
    Vector _channel_levels = _channel.getLevels();
    Level _chan_lev_standard_1 = (Level)_channel_levels.elementAt(1);
    
    // Create the channel dimension that will eventually be 
    // solved value based via OLAPI Enablement
     Dimension _channel_value = xademo.createDimension();
    _channel_value.setName("CHANNEL_VALUE_AW");
    _channel_value.setPluralName("Channels");
    _channel_value.setShortName("Channel");

    this.createChannelDim(_channel_value);

    Vector _channel_value_levels = _channel_value.getLevels();
    Level _chan_value_lev_standard_1 = (Level)_channel_value_levels.elementAt(1);

//////////////////////////////////////////////////////////////
// Create the CITY Dimension
/////////////////////////////////////////////////////////////   
    Dimension _city = xademo.createDimension();
    _city.setName("CITY_AW");
    _city.setPluralName("Cities");
    _city.setShortName("City");

  // Create the CITY Attributes
    Attribute _city_AC = _city.createAttribute();
    _city_AC.setName("AREA_CITY");
    Attribute _city_LD = createLongDescAttr(_city);
    Attribute _city_SPC = _city.createAttribute();
    _city_SPC.setName("SALESPERSON_CITY");
    Attribute _city_SD = createShortDescAttr(_city);

  // Create the CITY Level for CITY
    Level _cityLev = _city.createLevel();
    _cityLev.setName("CITY");

  // Create the Attribute Projections for the CITY Level
    this.setupAttributeProjection(_cityLev, "AREA_CITY", _city_AC);
    this.setupAttributeProjection(_cityLev, "SALESPERSON_CITY", _city_SPC);
    this.setupAttributeProjection(_cityLev, "Long Description", _city_LD);
    this.setupAttributeProjection(_cityLev, "Short Description", _city_SD);

     this.clearLevelMapVectors();  
    _keys.add("XADEMO.XADEMO_CITY.CITY");
    _cols.add("XADEMO.XADEMO_CITY.CITY_AREA");
    _cols.add("XADEMO.XADEMO_CITY.CITY_SALESPERSON");
    _cols.add("XADEMO.XADEMO_CITY.CITY_LLABEL");
    _cols.add("XADEMO.XADEMO_CITY.CITY_SLABEL");
    this.createLevelMap(_cityLev, _keys, _cols);

/////////////////////////////////////////////////////////////////////////////
// Create the DAY Dimension
/////////////////////////////////////////////////////////////////////////////  
    Dimension _day = xademo.createDimension();
    _day.setName("DAY_AW");
    _day.setPluralName("Days");
    _day.setShortName("Day");

    Level _dayLev = this.setupSimpleDim(_day);
    
    this.clearLevelMapVectors();  
    _keys.add("XADEMO.XADEMO_DAY.DAY");
    _cols.add("XADEMO.XADEMO_DAY.DAY_LLABEL");
    _cols.add("XADEMO.XADEMO_DAY.DAY_SLABEL");
    this.createLevelMap(_dayLev, _keys, _cols);

/////////////////////////////////////////////////////////////////////////////
// Create the DIVISION Dimension
/////////////////////////////////////////////////////////////////////////////
    Dimension _division = xademo.createDimension();
    _division.setName("DIVISION_AW");
    _division.setPluralName("Divisions");
    _division.setShortName("Division");

    Level _divisionLev = this.setupSimpleDim(_division);

    this.clearLevelMapVectors();  
    _keys.add("XADEMO.XADEMO_DIVISION.DIVISION");
    _cols.add("XADEMO.XADEMO_DIVISION.DIVISION_LLABEL");
    _cols.add("XADEMO.XADEMO_DIVISION.DIVISION_SLABEL");
    this.createLevelMap(_divisionLev, _keys, _cols);

/////////////////////////////////////////////////////////////////////////////
// Create the LINE Dimension
/////////////////////////////////////////////////////////////////////////////
    Dimension _line = xademo.createDimension();
    _line.setName("LINE_AW");
    _line.setPluralName("Lines");
    _line.setShortName("Line");

    Level _lineLev = this.setupSimpleDim(_line);

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_LINE.LINE");
    _cols.add("XADEMO.XADEMO_LINE.LINE_LLABEL");
    _cols.add("XADEMO.XADEMO_LINE.LINE_SLABEL");
    this.createLevelMap(_lineLev, _keys, _cols);

/////////////////////////////////////////////////////////////////////////////
// Create the STKMEAS Dimension
/////////////////////////////////////////////////////////////////////////////
    Dimension _stkmeas = xademo.createDimension();
    _stkmeas.setName("STKMEAS_AW");
    _stkmeas.setPluralName("Stock Measures");
    _stkmeas.setShortName("stkmeas");

    Level _stkmeasLev = this.setupSimpleDim(_stkmeas);

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_STKMEAS.STKMEAS");
    _cols.add("XADEMO.XADEMO_STKMEAS.STKMEAS_LLABEL");
    _cols.add("XADEMO.XADEMO_STKMEAS.STKMEAS_SLABEL");
    this.createLevelMap(_stkmeasLev, _keys, _cols);

/////////////////////////////////////////////////////////////////////////////
// Create the STOCK Dimension
/////////////////////////////////////////////////////////////////////////////
    Dimension _stock = xademo.createDimension();
    _stock.setName("STOCK_AW");
    _stock.setPluralName("Stocks");
    _stock.setShortName("Stock");

    Level _stockLev = this.setupSimpleDim(_stock);

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_STOCK.STOCK");
    _cols.add("XADEMO.XADEMO_STOCK.STOCK_LLABEL");
    _cols.add("XADEMO.XADEMO_STOCK.STOCK_SLABEL");
    this.createLevelMap(_stockLev, _keys,_cols);
    
/////////////////////////////////////////////////////////////////////////////
// Create the TIME Dimensions
/////////////////////////////////////////////////////////////////////////////
     Dimension _time = xademo.createDimension();
    _time.setName("TIME_AW");
    _time.setPluralName("Times");
    _time.setShortName("Time");
    _time.setIsTime(true);

    this.createTimeDim(_time);
    Vector _time_levels = _time.getLevels();
    Level _time_l3 = (Level)_time_levels.elementAt(2);
    
    // Create the time dimension that will eventually be 
    // solved value based via OLAPI Enablement
     Dimension _time_value = xademo.createDimension();
    _time_value.setName("TIME_VALUE_AW");
    _time_value.setPluralName("Times");
    _time_value.setShortName("Time");
    _time_value.setIsTime(true);
    
    this.createTimeDim(_time_value);
    Vector _time_value_levels = _time_value.getLevels();
    Level _time_value_l3 = (Level)_time_value_levels.elementAt(2);
    
/////////////////////////////////////////////////////////////////////
// Create the GEOGRAPHY Dimension
/////////////////////////////////////////////////////////////////////
     Dimension _geography = xademo.createDimension();
    _geography.setName("GEOGRAPHY_AW");
    _geography.setPluralName("Geographys");
    _geography.setShortName("Geography");

    this.createGeographyDim(_geography);
    Vector _geography_levels = _geography.getLevels();
    Level _geography_l4 = (Level)_geography_levels.elementAt(3);
    
    // Create the geography dimension that will eventually be 
    // solved value based via OLAPI Enablement
     Dimension _geography_value = xademo.createDimension();
    _geography_value.setName("GEOGRAPHY_VALUE_AW");
    _geography_value.setPluralName("Geographys");
    _geography_value.setShortName("Geography");

    this.createGeographyDim(_geography_value);

    Vector _geography_value_levels = _geography_value.getLevels();
    Level _geography_value_l4 = (Level)_geography_value_levels.elementAt(3);

///////////////////////////////////////////////////////////////////////////
// Create the PRODUCT Dimensions
///////////////////////////////////////////////////////////////////////////    
    Dimension _product = xademo.createDimension();
    _product.setName("PRODUCT_AW");
    _product.setPluralName("Products");
    _product.setShortName("Product");

    this.createProductDim(_product);
    Vector _product_levels = _product.getLevels();
    Level _product_l4 = (Level)_product_levels.elementAt(3);
    
    // Create the product dimension that will eventually be 
    // solved value based via OLAPI Enablement
     Dimension _product_value = xademo.createDimension();
    _product_value.setName("PRODUCT_VALUE_AW");
    _product_value.setPluralName("Products");
    _product_value.setShortName("Product");

    this.createProductDim(_product_value);

    Vector _product_value_levels = _product_value.getLevels();
    Level _product_value_l4 = (Level)_product_value_levels.elementAt(3);
    
////////////////////////////////////////////////////////////////////////////////
// Create the GEOGMULTI Dimension
////////////////////////////////////////////////////////////////////////////////
     Dimension _geogmulti = xademo.createDimension();
    _geogmulti.setName("GEOGMULTI_AW");
    _geogmulti.setPluralName("Geographies");
    _geogmulti.setShortName("Geogmulti");

  // Create the Long and Short Description Attributes for GEOGMULTI
    Attribute _geogmulti_LD = createLongDescAttr(_geogmulti);
    Attribute _geogmulti_SD = createShortDescAttr(_geogmulti);

  // Create the L1 Level for GEOGMULTI
    Level _geomulti_l1 = _geogmulti.createLevel();
    _geomulti_l1.setName("L1");

  // Create the Long and Short  Description Attribute Projection for GEOMULTI's L1 Level
    this.setupAttributeProjection(_geomulti_l1, "Long Description", _geogmulti_LD);
    this.setupAttributeProjection(_geomulti_l1, "Short Description", _geogmulti_SD);

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_TOP");
    _cols.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_TOP_LLABEL");
    _cols.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_TOP_SLABEL");
    this.createLevelMap(_geomulti_l1, _keys,_cols);

  // Create the L2 Level for GEOGMULTI
    Level _geomulti_l2 = _geogmulti.createLevel();
    _geomulti_l2.setName("L2");

  // Create the Long and Short  Description Attribute Projection for GEOMULTI's L1 Level
    this.setupAttributeProjection(_geomulti_l2, "Long Description", _geogmulti_LD);
    this.setupAttributeProjection(_geomulti_l2, "Short Description", _geogmulti_SD);

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_CONTINENT");
    _cols.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_CONTINENT_LLABEL");
    _cols.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_CONTINENT_SLABEL");
    this.createLevelMap(_geomulti_l2, _keys,_cols);

  // Create the L3 Level for GEOGMULTI
    Level _geomulti_l3 = _geogmulti.createLevel();
    _geomulti_l3.setName("L3");

  // Create the Long and Short Description Attribute Projection for GEOMULTI's L1 Level
    this.setupAttributeProjection(_geomulti_l3, "Long Description", _geogmulti_LD);
    this.setupAttributeProjection(_geomulti_l3, "Short Description", _geogmulti_SD);

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_CONTINENT");
    _keys.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_AREA");
    _cols.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_AREA_LLABEL");
    _cols.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_AREA_SLABEL");
    this.createLevelMap(_geomulti_l3, _keys, _cols);

  // Create the L4 Level for GEOGMULTI
    Level _geomulti_l4 = _geogmulti.createLevel();
    _geomulti_l4.setName("L4");

  // Create the Long and Short Description Attribute Projection for GEOMULTI's L1 Level
    this.setupAttributeProjection(_geomulti_l4, "Long Description", _geogmulti_LD);
    this.setupAttributeProjection(_geomulti_l4, "Short Description", _geogmulti_SD);

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_CONTINENT");
    _keys.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_AREA");
    _keys.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_CITY");
    _cols.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_CITY_LLABEL");
    _cols.add("XADEMO.XADEMO_GEOG_MULTIKEY.GEOG_STD_CITY_SLABEL");
    this.createLevelMap(_geomulti_l4, _keys, _cols);

//////////////////////////////////////////////////////////////////////////////
// Create the ANALYTIC CUBE and MESAURES
//////////////////////////////////////////////////////////////////////////////  
  this.clearCubeMapVectors();  

  Cube _analyticCube = xademo.createCube();
  _analyticCube.setName("ANALYTIC_CUBE_AW");

  _dimList.add(_channel);
  _dimList.add(_geography);
  _dimList.add(_product);
  _dimList.add(_time);    
  this.associateCubeDimensions(_analyticCube, _dimList);
  
  Measure _f_costs = _analyticCube.createMeasure();
  Measure _f_promo = _analyticCube.createMeasure();
  Measure _f_quota = _analyticCube.createMeasure();
  Measure _f_sales = _analyticCube.createMeasure();
  Measure _f_units = _analyticCube.createMeasure();

  _f_costs.setName("F_COSTS_AW");
  _f_costs.setLongName("Dollar Costs");
  _f_costs.setDataType("NUMBER");
  _measures.add(_f_costs);
  _measCols.add("XADEMO.XADEMO_ANALYTIC_FACTS.COSTS");
  
  _f_promo.setName("F_PROMO_AW");
  _f_promo.setDataType("NUMBER");
  _f_promo.setLongName("Promotion");
  _measures.add(_f_promo);
  _measCols.add("XADEMO.XADEMO_ANALYTIC_FACTS.PROMO");  
  
  _f_quota.setName("F_QUOTA_AW");
  _f_quota.setDataType("NUMBER");
  _f_quota.setLongName("Quota");
  _measures.add(_f_quota);
  _measCols.add("XADEMO.XADEMO_ANALYTIC_FACTS.QUOTA");  
  
  _f_sales.setName("F_SALES_AW");
  _f_sales.setDataType("NUMBER");
  _f_sales.setLongName("Dollar Sales");
  _measures.add(_f_sales);
  _measCols.add("XADEMO.XADEMO_ANALYTIC_FACTS.SALES");  
  
  _f_units.setName("F_UNITS_AW");
  _f_units.setDataType("NUMBER");
  _f_units.setLongName("Units sold");
  _measures.add(_f_units);
  _measCols.add("XADEMO.XADEMO_ANALYTIC_FACTS.UNITS");  

  DerivedMeasure _f_margin = _analyticCube.createDerivedMeasure();
  _f_margin.setName("F_MARGIN_AW");
  _f_margin.setDataType("NUMBER");
  _f_margin.setExpressionText("XADEMO.ANALYTIC_CUBE_AW.F_SALES_AW.MEASURE - XADEMO.ANALYTIC_CUBE_AW.F_COSTS_AW.MEASURE");
  
  _levels.add(_chan_lev_standard_1);
  _cols.add("XADEMO.XADEMO_ANALYTIC_FACTS.CHAN_LEAVES");
  _levels.add(_geography_l4);
  _cols.add("XADEMO.XADEMO_ANALYTIC_FACTS.GEOG_LEAVES");
  _levels.add(_product_l4);
  _cols.add("XADEMO.XADEMO_ANALYTIC_FACTS.PROD_LEAVES");  
  _levels.add(_time_l3);
  _cols.add("XADEMO.XADEMO_ANALYTIC_FACTS.TIME_LEAVES");    
  
  this.createCubeMap(_analyticCube, _levels, _cols, _measures, _measCols);

//////////////////////////////////////////////////////////////////////////////
// Create the ANALYTIC_VALUE CUBE and MESAURES
//////////////////////////////////////////////////////////////////////////////  
  this.clearCubeMapVectors();  

  Cube _analyticCube_Value = xademo.createCube();
  _analyticCube_Value.setName("ANALYTIC_CUBE_VALUE_AW");

  _dimList.add(_channel_value);
  _dimList.add(_geography_value);
  _dimList.add(_product_value);
  _dimList.add(_time_value);    
  this.associateCubeDimensions(_analyticCube_Value, _dimList);
  
  Measure _f_costs_val = _analyticCube_Value.createMeasure();
  Measure _f_promo_val = _analyticCube_Value.createMeasure();
  Measure _f_quota_val = _analyticCube_Value.createMeasure();
  Measure _f_sales_val = _analyticCube_Value.createMeasure();
  Measure _f_units_val = _analyticCube_Value.createMeasure();
  
  _f_costs_val.setName("F_COSTS_VALUE_AW");
  _f_costs_val.setDataType("NUMBER");
  _f_costs_val.setLongName("Dollar Costs");
  _measures.add(_f_costs_val);
  _measCols.add("XADEMO.XADEMO_ANALYTIC_FACTS.COSTS");
  
  _f_promo_val.setName("F_PROMO_VALUE_AW");
  _f_promo_val.setDataType("NUMBER");
  _f_promo_val.setLongName("Promotion");  
  _measures.add(_f_promo_val);
  _measCols.add("XADEMO.XADEMO_ANALYTIC_FACTS.PROMO");  
  
  _f_quota_val.setName("F_QUOTA_VALUE_AW");
  _f_quota_val.setDataType("NUMBER");
  _f_quota_val.setLongName("Quota");
  _measures.add(_f_quota_val);
  _measCols.add("XADEMO.XADEMO_ANALYTIC_FACTS.QUOTA");  
  
  _f_sales_val.setName("F_SALES_VALUE_AW");
  _f_sales_val.setDataType("NUMBER");
  _f_sales_val.setLongName("Dollar Sales");
  _measures.add(_f_sales_val);
  _measCols.add("XADEMO.XADEMO_ANALYTIC_FACTS.SALES");  
  
  _f_units_val.setName("F_UNITS_VALUE_AW");
  _f_units_val.setDataType("NUMBER");
  _f_units_val.setLongName("Units sold");
  _measures.add(_f_units_val);
  _measCols.add("XADEMO.XADEMO_ANALYTIC_FACTS.UNITS");  

  _levels.add(_chan_value_lev_standard_1);
  _cols.add("XADEMO.XADEMO_ANALYTIC_FACTS.CHAN_LEAVES");
  _levels.add(_geography_value_l4);
  _cols.add("XADEMO.XADEMO_ANALYTIC_FACTS.GEOG_LEAVES");
  _levels.add(_product_value_l4);
  _cols.add("XADEMO.XADEMO_ANALYTIC_FACTS.PROD_LEAVES");  
  _levels.add(_time_value_l3);
  _cols.add("XADEMO.XADEMO_ANALYTIC_FACTS.TIME_LEAVES");    
  
  this.createCubeMap(_analyticCube_Value, _levels, _cols, _measures, _measCols);
  
//////////////////////////////////////////////////////////////////////////////
// Create the ACTUAL CUBE and MESAURES
//////////////////////////////////////////////////////////////////////////////  
  this.clearCubeMapVectors();  
  
  Cube _actualCube = xademo.createCube();
  _actualCube.setName("XADEMO_ACTUAL_CUBE_AW");

  _dimList.add(_division);
  _dimList.add(_line);
  _dimList.add(_time);    
  this.associateCubeDimensions(_actualCube, _dimList);
  
  Measure _actual = _actualCube.createMeasure();
  
  _actual.setName("ACTUAL_AW");
  _actual.setDataType("NUMBER");
  _measures.add(_actual);
  _measCols.add("XADEMO.XADEMO_ACTUAL.ACTUAL_FACT");

  _levels.add(_divisionLev);
  _cols.add("XADEMO.XADEMO_ACTUAL.DIVISION");
  _levels.add(_lineLev);
  _cols.add("XADEMO.XADEMO_ACTUAL.LINE");
  _levels.add(_time_l3);
  _cols.add("XADEMO.XADEMO_ACTUAL.TIME_LEAVES");
  this.createCubeMap(_actualCube, _levels, _cols, _measures, _measCols);

//////////////////////////////////////////////////////////////////////////////
// Create the BUDGET CUBE and MESAURES
//////////////////////////////////////////////////////////////////////////////  
  this.clearCubeMapVectors();
  
  Cube _budgetCube = xademo.createCube();
  _budgetCube.setName("XADEMO_BUDGET_CUBE_AW");

  _dimList.add(_division);
  _dimList.add(_line);
  _dimList.add(_time);    
  this.associateCubeDimensions(_budgetCube, _dimList);
  
  Measure _budget = _budgetCube.createMeasure();
  
  _budget.setName("BUDGET_AW");
  _budget.setDataType("NUMBER");
  _measures.add(_budget);
  _measCols.add("XADEMO.XADEMO_BUDGET.BUDGET_FACT");

  _levels.add(_divisionLev);
  _cols.add("XADEMO.XADEMO_BUDGET.DIVISION");
  _levels.add(_lineLev);
  _cols.add("XADEMO.XADEMO_BUDGET.LINE");
  _levels.add(_time_l3);
  _cols.add("XADEMO.XADEMO_BUDGET.TIME_LEAVES");
  this.createCubeMap(_budgetCube, _levels, _cols, _measures, _measCols);

//////////////////////////////////////////////////////////////////////////////
// Create the XADEMO_SALES_MULTIKEY CUBE and MESAURES
//////////////////////////////////////////////////////////////////////////////  
  this.clearCubeMapVectors();
  
  Cube _salesMultiKeyCube = xademo.createCube();
  _salesMultiKeyCube.setName("XADEMO_SALES_MULTIKEY_CUBE_AW");

  _dimList.add(_channel);
  _dimList.add(_geogmulti);
  _dimList.add(_product);
  _dimList.add(_time);    
  this.associateCubeDimensions(_salesMultiKeyCube, _dimList);
  
  Measure _sales_mk = _salesMultiKeyCube.createMeasure();
  Measure _units_mk = _salesMultiKeyCube.createMeasure();
  
  _sales_mk.setName("SALES_MK_AW");
  _sales_mk.setDataType("NUMBER");
  _measures.add(_sales_mk);
  _measCols.add("XADEMO.XADEMO_MULTIKEY_FACTS.SALES_MK");
  
  _units_mk.setName("UNITS_MK_AW");
  _units_mk.setDataType("NUMBER");
  _measures.add(_units_mk);
  _measCols.add("XADEMO.XADEMO_MULTIKEY_FACTS.UNITS_MK");  
  
  _levels.add(_chan_lev_standard_1);
  _cols.add("XADEMO.XADEMO_MULTIKEY_FACTS.CHAN_LEAVES");
  _levels.add(_geomulti_l4);
  _cols.add("XADEMO.XADEMO_MULTIKEY_FACTS.GEOG_CONTINENT, XADEMO.XADEMO_MULTIKEY_FACTS.GEOG_AREA,
XADEMO.XADEMO_MULTIKEY_FACTS.GEOG_CITY");
  _levels.add(_product_l4);
  _cols.add("XADEMO.XADEMO_MULTIKEY_FACTS.PROD_LEAVES");  
  _levels.add(_time_l3);
  _cols.add("XADEMO.XADEMO_MULTIKEY_FACTS.TIME_LEAVES");    
  
  this.createCubeMap(_salesMultiKeyCube, _levels, _cols, _measures, _measCols);

  //////////////////////////////////////////////////////////////////////////////
// Create the STKPRICE CUBE and MESAURES
//////////////////////////////////////////////////////////////////////////////  
  this.clearCubeMapVectors();
  
  Cube _stkpriceCube = xademo.createCube();
  _stkpriceCube.setName("XADEMO_STKPRICE_CUBE_AW");

  _dimList.add(_day);
  _dimList.add(_stkmeas);
  _dimList.add(_stock);    
  this.associateCubeDimensions(_stkpriceCube, _dimList);
  
  Measure _stkprice = _stkpriceCube.createMeasure();
  
  _stkprice.setName("STKPRICE_AW");
  _stkprice.setDataType("NUMBER");
  _measures.add(_stkprice);
  _measCols.add("XADEMO.XADEMO_STKPRICE.STKPRICE_FACT");

  _levels.add(_dayLev);
  _cols.add("XADEMO.XADEMO_STKPRICE.DAY");
  _levels.add(_stkmeasLev);
  _cols.add("XADEMO.XADEMO_STKPRICE.STKMEAS");
  _levels.add(_stockLev);
  _cols.add("XADEMO.XADEMO_STKPRICE.STOCK");
  this.createCubeMap(_stkpriceCube, _levels, _cols, _measures, _measCols);
  
  ////////////////////////
  // Write the XML string    
  ////////////////////////  
    String XML = xademo.WriteToXML();
    System.out.println("output:\n " + XML);

/*****/
    AWConnection _conn = new AWConnection("xademo", "xademo", "twister12:1865:main1");
    try
    {
      _conn.executeCommand("aw delete " + xademo.getName());
    }
    catch(Exception e)
    {
      System.out.println("Failure to delete " + xademo.getName());
    }
   //xademo.Delete(_conn); not supported
   // xademo.Commit(_conn);
    xademo.Create(_conn);
    xademo.Commit(_conn);
    _conn.close();
   System.out.println("Done!");
/****/   
  }

  public void createChannelDim(Dimension _channel)
  {
    // Create the Long and Short Description Attributes for CHANNEL
    Attribute _channel_LD = createLongDescAttr(_channel);
    Attribute _channel_SD = createShortDescAttr(_channel);
    
  // Create the STANDARD_2 Level for CHANNEL
    Level _standard_2 = _channel.createLevel();
    _standard_2.setName("STANDARD_2");

  // Create the Long Description Attribute Projection for the STANDARD_2 Level
    this.setupAttributeProjection(_standard_2, "Long Description", _channel_LD);

  // Create the Short Description Attribute Projection for the STANDARD_2 Level
    this.setupAttributeProjection(_standard_2, "Short Description", _channel_SD);

  // The elements in the _keys vector are the key columns of the level.
  // The elements in the _cols vector are the attribute columns of the level. 
  // The order of the elements in the _cols vector is dependent on the order in 
  // which the attributes have been created above.
    clearLevelMapVectors(); 
    _keys.add("XADEMO.XADEMO_CHANNEL.CHAN_STD_TOP");
    _cols.add("XADEMO.XADEMO_CHANNEL.CHAN_STD_TOP_LLABEL");
    _cols.add("XADEMO.XADEMO_CHANNEL.CHAN_STD_TOP_SLABEL");
    
    this.createLevelMap(_standard_2, _keys, _cols);

  // Create the STANDARD_1 Level for CHANNEL
    Level _standard_1 = _channel.createLevel();
    _standard_1.setName("STANDARD_1");

  // Create the Long and Short Description Attribute Projection for Channel's STANDARD_1 Level
    this.setupAttributeProjection(_standard_1, "Long Description", _channel_LD);
    this.setupAttributeProjection(_standard_1, "Short Description", _channel_SD);

    clearLevelMapVectors(); 
    _keys.add("XADEMO.XADEMO_CHANNEL.CHAN_STD_CHANNEL");
    _cols.add("XADEMO.XADEMO_CHANNEL.CHAN_STD_CHANNEL_LLABEL");
    _cols.add("XADEMO.XADEMO_CHANNEL.CHAN_STD_CHANNEL_SLABEL");
    this.createLevelMap(_standard_1, _keys, _cols);   
    
   // Create the STANDARD Hierarchy
    Hierarchy _standard = _channel.createHierarchy();
    _standard.setName("STANDARD");

  // The following vectors represent the levels included
  // in the hierarchy.  The order is based on the hierarchical
  // tree in the AW starting at the top.
    clearHierarchyMapVectors();
    _levels.add(_standard_2);
    _levColumns.add("XADEMO.XADEMO_CHANNEL.CHAN_STD_TOP");
    _levels.add(_standard_1);
    _levColumns.add("XADEMO.XADEMO_CHANNEL.CHAN_STD_CHANNEL");  

  // Map the relational columns to the hierarchy.    
    this.createHierarchyMap(_standard, _levels, _levColumns);
  }

  public void createTimeDim(Dimension _time)
  {
  // Create the Long and Short Description Attributes for TIME
    Attribute _time_LD = createLongDescAttr(_time);
    Attribute _time_SD = createShortDescAttr(_time);

  // Create the End_Date and Time_Span Attributes
    Attribute _time_EndDate = _time.createAttribute();
    _time_EndDate.setName("End_Date");
    _time_EndDate.setClassification("END_DATE");
    Attribute _time_TimeSpan = _time.createAttribute();
    _time_TimeSpan.setName("Time_Span");
    _time_TimeSpan.setClassification("TIME_SPAN");

  // Create LAG Attributes
    Attribute _time_Yearago = _time.createAttribute();
    _time_Yearago.setName("YEARAGO");
    _time_Yearago.setDataType("INTEGER");
    Attribute _time_Periodago = _time.createAttribute();
    _time_Periodago.setName("PERIODAGO");
    _time_Periodago.setDataType("INTEGER");

  // Create the ORDERing attributes
    Attribute _time_std_order = _time.createAttribute();
    _time_std_order.setName("STD_ORDER");   
    _time_std_order.setDataType("INTEGER");

    Attribute _time_ytd_order = _time.createAttribute();
    _time_ytd_order.setName("YTD_ORDER");        
    _time_ytd_order.setDataType("INTEGER");

  // Create the L1 Level for TIME
    Level _time_l1 = _time.createLevel();
    _time_l1.setName("L1");

 // Create the Attribute Projections for TIME's L1 Level
     this.setupAttributeProjection(_time_l1, "End Date", _time_EndDate);
     this.setupAttributeProjection(_time_l1, "Long Description", _time_LD);
     this.setupAttributeProjection(_time_l1, "Short Description", _time_SD);
     this.setupAttributeProjection(_time_l1, "Time Span", _time_TimeSpan);
     this.setupAttributeProjection(_time_l1, "YEARAGO", _time_Yearago);
     this.setupAttributeProjection(_time_l1, "PERIODAGO", _time_Periodago);
     this.setupAttributeProjection(_time_l1, "STD_ORDER", _time_std_order);     

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_TIME.TIME_STD_YEAR");
    _cols.add("XADEMO.XADEMO_TIME.TIME_STD_YEAR_END_DATE");
    _cols.add("XADEMO.XADEMO_TIME.TIME_STD_YEAR_LLABEL");
    _cols.add("XADEMO.XADEMO_TIME.TIME_STD_YEAR_SLABEL");
    _cols.add("XADEMO.XADEMO_TIME.TIME_STD_YEAR_TIMESPAN");    
    _cols.add("XADEMO.XADEMO_TIME.YEARAGO_YEAR");    
    _cols.add("XADEMO.XADEMO_TIME.PERIODAGO_YEAR");    
    _cols.add("XADEMO.XADEMO_TIME.STD_ORDER_YEAR");        
    this.createLevelMap(_time_l1, _keys, _cols);

  // Create the L2 Level for TIME
    Level _time_l2 = _time.createLevel();
    _time_l2.setName("L2");

 // Create the Attribute Projections for TIME's L2 Level
     this.setupAttributeProjection(_time_l2, "End Date", _time_EndDate);
     this.setupAttributeProjection(_time_l2, "Long Description", _time_LD);
     this.setupAttributeProjection(_time_l2, "Short Description", _time_SD);
     this.setupAttributeProjection(_time_l2, "Time Span", _time_TimeSpan);
     this.setupAttributeProjection(_time_l2, "YEARAGO", _time_Yearago);
     this.setupAttributeProjection(_time_l2, "PERIODAGO", _time_Periodago);
     this.setupAttributeProjection(_time_l2, "STD_ORDER", _time_std_order);     
     
    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_TIME.TIME_STD_QUARTER");
    _cols.add("XADEMO.XADEMO_TIME.TIME_STD_QUARTER_END_DATE");
    _cols.add("XADEMO.XADEMO_TIME.TIME_STD_QUARTER_LLABEL");
    _cols.add("XADEMO.XADEMO_TIME.TIME_STD_QUARTER_SLABEL");
    _cols.add("XADEMO.XADEMO_TIME.TIME_STD_QUARTER_TIMESPAN");    
    _cols.add("XADEMO.XADEMO_TIME.YEARAGO_QUARTER");    
    _cols.add("XADEMO.XADEMO_TIME.PERIODAGO_QUARTER");   
    _cols.add("XADEMO.XADEMO_TIME.STD_ORDER_QUARTER");            
    this.createLevelMap(_time_l2, _keys, _cols);

  // Create the L3 Level for TIME
    Level _time_l3 = _time.createLevel();
    _time_l3.setName("L3");

 // Create the Attribute Projections for TIME's L3 Level
     this.setupAttributeProjection(_time_l3, "End Date", _time_EndDate);
     this.setupAttributeProjection(_time_l3, "Long Description", _time_LD);
     this.setupAttributeProjection(_time_l3, "Short Description", _time_SD);
     this.setupAttributeProjection(_time_l3, "Time Span", _time_TimeSpan);
     this.setupAttributeProjection(_time_l3, "YEARAGO", _time_Yearago);
     this.setupAttributeProjection(_time_l3, "PERIODAGO", _time_Periodago);
     this.setupAttributeProjection(_time_l3, "STD_ORDER", _time_std_order);          
     this.setupAttributeProjection(_time_l3, "YTD_ORDER", _time_ytd_order);               
     
    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_TIME.TIME_STD_MONTH");
    _cols.add("XADEMO.XADEMO_TIME.TIME_STD_MONTH_END_DATE");
    _cols.add("XADEMO.XADEMO_TIME.TIME_STD_MONTH_LLABEL");
    _cols.add("XADEMO.XADEMO_TIME.TIME_STD_MONTH_SLABEL");
    _cols.add("XADEMO.XADEMO_TIME.TIME_STD_MONTH_TIMESPAN");  
    _cols.add("XADEMO.XADEMO_TIME.YEARAGO_MONTH");    
    _cols.add("XADEMO.XADEMO_TIME.PERIODAGO_MONTH");  
    _cols.add("XADEMO.XADEMO_TIME.STD_ORDER_MONTH");                
    _cols.add("XADEMO.XADEMO_TIME.YTD_ORDER_MONTH");                    

    this.createLevelMap(_time_l3, _keys,_cols);

  // Create the L4 Level for TIME
    Level _time_l4 = _time.createLevel();
    _time_l4.setName("L4");

 // Create the Attribute Projections for TIME's L4 Level
     this.setupAttributeProjection(_time_l4, "End Date", _time_EndDate);
     this.setupAttributeProjection(_time_l4, "Long Description", _time_LD);
     this.setupAttributeProjection(_time_l4, "Short Description", _time_SD);
     this.setupAttributeProjection(_time_l4, "Time Span", _time_TimeSpan);
     this.setupAttributeProjection(_time_l4, "YEARAGO", _time_Yearago);
     this.setupAttributeProjection(_time_l4, "PERIODAGO", _time_Periodago);
     this.setupAttributeProjection(_time_l4, "YTD_ORDER", _time_ytd_order);               
     
    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_TIME.TIME_YTD_YEAR");
    _cols.add("XADEMO.XADEMO_TIME.TIME_YTD_YEAR_END_DATE");
    _cols.add("XADEMO.XADEMO_TIME.TIME_YTD_YEAR_LLABEL");
    _cols.add("XADEMO.XADEMO_TIME.TIME_YTD_YEAR_SLABEL");
    _cols.add("XADEMO.XADEMO_TIME.TIME_YTD_YEAR_TIMESPAN");  
    _cols.add("XADEMO.XADEMO_TIME.YEARAGO_YTD");    
    _cols.add("XADEMO.XADEMO_TIME.PERIODAGO_YTD");    
    _cols.add("XADEMO.XADEMO_TIME.YTD_ORDER_YTD");                

    this.createLevelMap(_time_l4, _keys,_cols);

   // Create the STANDARD Hierarchy
    Hierarchy _time_hier_standard = _time.createHierarchy();
    _time_hier_standard.setName("STANDARD");

  // The following vectors represent the levels included
  // in the hierarchy.  The order is based on the hierarchical
  // tree in the AW starting at the top.    
    clearHierarchyMapVectors();
    _levels.add(_time_l1);
    _levColumns.add("XADEMO.XADEMO_TIME.TIME_STD_YEAR");
    _levels.add(_time_l2);
    _levColumns.add("XADEMO.XADEMO_TIME.TIME_STD_QUARTER");
    _levels.add(_time_l3);
    _levColumns.add("XADEMO.XADEMO_TIME.TIME_STD_MONTH");
    
  // Map the relational columns to the hierarchy.    
    this.createHierarchyMap(_time_hier_standard, _levels, _levColumns);

   // Create the YTD Hierarchy
    Hierarchy _time_hier_ytd = _time.createHierarchy();
    _time_hier_ytd.setName("YTD");

  // The following vectors represent the levels included
  // in the hierarchy.  The order is based on the hierarchical
  // tree in the AW starting at the top.
    clearHierarchyMapVectors();
    _levels.add(_time_l4);
    _levColumns.add("XADEMO.XADEMO_TIME.TIME_YTD_YEAR");
    _levels.add(_time_l3);
    _levColumns.add("XADEMO.XADEMO_TIME.TIME_STD_MONTH");
    
  // Map the relational columns to the hierarchy.    
    this.createHierarchyMap(_time_hier_ytd, _levels, _levColumns);  
  }

  public void createGeographyDim(Dimension _geography)
  {
    // Create the Long and Short Description Attributes for GEOGRAPHY
    Attribute _geography_LD = createLongDescAttr(_geography);
    Attribute _geography_SD = createShortDescAttr(_geography);

  // Create the L1 Level for GEOGRAPHY
    Level _geography_l1 = _geography.createLevel();
    _geography_l1.setName("L1");

  // Create the Long and Short  Description Attribute Projection for GEOGRAPHY's L1 Level
    this.setupAttributeProjection(_geography_l1, "Long Description", _geography_LD);
    this.setupAttributeProjection(_geography_l1, "Short Description", _geography_SD);

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_TOP");
    _cols.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_TOP_LLABEL");
    _cols.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_TOP_SLABEL");
    this.createLevelMap(_geography_l1, _keys, _cols);

  // Create the L2 Level for GEOGRAPHY
    Level _geography_l2 = _geography.createLevel();
    _geography_l2.setName("L2");

  // Create the Long and Short  Description Attribute Projection for GEOGRAPHY's L2 Level
    this.setupAttributeProjection(_geography_l2, "Long Description", _geography_LD);
    this.setupAttributeProjection(_geography_l2, "Short Description", _geography_SD);

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_CONTINENT");
    _cols.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_CONTINENT_LLABEL");
    _cols.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_CONTINENT_SLABEL");
    this.createLevelMap(_geography_l2, _keys, _cols);

  // Create the L3 Level for GEOGRAPHY
    Level _geography_l3 = _geography.createLevel();
    _geography_l3.setName("L3");

  // Create the Long and Short  Description Attribute Projection for GEOGRAPHY's L3 Level
    this.setupAttributeProjection(_geography_l3, "Long Description", _geography_LD);
    this.setupAttributeProjection(_geography_l3, "Short Description", _geography_SD);

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_AREA");
    _cols.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_AREA_LLABEL");
    _cols.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_AREA_SLABEL");
    this.createLevelMap(_geography_l3, _keys, _cols);

  // Create the L4 Level for GEOGRAPHY
    Level _geography_l4 = _geography.createLevel();
    _geography_l4.setName("L4");

  // Create the Long and Short  Description Attribute Projection for GEOGRAPHY's L4 Level
    this.setupAttributeProjection(_geography_l4, "Long Description", _geography_LD);
    this.setupAttributeProjection(_geography_l4, "Short Description", _geography_SD);

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_CITY");
    _cols.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_CITY_LLABEL");
    _cols.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_CITY_SLABEL");
    this.createLevelMap(_geography_l4, _keys, _cols);

   // Create the STANDARD Hierarchy
    Hierarchy _geography_hier_standard = _geography.createHierarchy();
    _geography_hier_standard.setName("STANDARD");

  // The following vectors represent the levels included
  // in the hierarchy.  The order is based on the hierarchical
  // tree in the AW starting at the top.    
    clearHierarchyMapVectors();  
    _levels.add(_geography_l1);
    _levColumns.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_TOP");
    _levels.add(_geography_l2);
    _levColumns.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_CONTINENT");
    _levels.add(_geography_l3);
    _levColumns.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_AREA");
    _levels.add(_geography_l4);
    _levColumns.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_CITY");
    
  // Map the relational columns to the hierarchy.    
    this.createHierarchyMap(_geography_hier_standard, _levels, _levColumns);

   // Create the CONSOLIDATED Hierarchy
    Hierarchy _geography_hier_cons = _geography.createHierarchy();
    _geography_hier_cons.setName("CONSOLIDATED");

  // The following vectors represent the levels included
  // in the hierarchy.  The order is based on the hierarchical
  // tree in the AW starting at the top.
    clearHierarchyMapVectors();
    _levels.add(_geography_l2);
    _levColumns.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_CONTINENT");
    _levels.add(_geography_l3);
    _levColumns.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_AREA");
    _levels.add(_geography_l4);
    _levColumns.add("XADEMO.XADEMO_GEOGRAPHY.GEOG_STD_CITY");
    
  // Map the relational columns to the hierarchy.    
    this.createHierarchyMap(_geography_hier_cons, _levels, _levColumns);    
  }

  public void createProductDim(Dimension _product)
  {
    // Create the PRODUCT Attributes
    Attribute _product_C = _product.createAttribute();
    _product_C.setName("COLOR");
    Attribute _product_LD = createLongDescAttr(_product);
    Attribute _product_S = _product.createAttribute();
    _product_S.setName("SIZE");
    Attribute _product_SD = createShortDescAttr(_product);

  // Create the L1 Level for PRODUCT
    Level _product_l1 = _product.createLevel();
    _product_l1.setName("L1");

  // Create the Attribute Projections for the L1 Level
    this.setupAttributeProjection(_product_l1, "Long Description", _product_LD);
    this.setupAttributeProjection(_product_l1, "Short Description", _product_SD);

    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_PRODUCT.PROD_STD_TOP");
    _cols.add("XADEMO.XADEMO_PRODUCT.PROD_STD_TOP_LLABEL");
    _cols.add("XADEMO.XADEMO_PRODUCT.PROD_STD_TOP_SLABEL");
    this.createLevelMap(_product_l1, _keys,_cols);

  // Create the L2 Level for PRODUCT
    Level _product_l2 = _product.createLevel();
    _product_l2.setName("L2");

  // Create the Attribute Projections for the L2 Level
    this.setupAttributeProjection(_product_l2, "Long Description", _product_LD);
    this.setupAttributeProjection(_product_l2, "Short Description", _product_SD);
    
    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_PRODUCT.PROD_STD_DIVISION");
    _cols.add("XADEMO.XADEMO_PRODUCT.PROD_STD_DIVISION_LLABEL");
    _cols.add("XADEMO.XADEMO_PRODUCT.PROD_STD_DIVISION_SLABEL");
    this.createLevelMap(_product_l2, _keys,_cols);

  // Create the L3 Level for PRODUCT
    Level _product_l3 = _product.createLevel();
    _product_l3.setName("L3");

  // Create the Attribute Projections for the L2 Level
    this.setupAttributeProjection(_product_l3, "Long Description", _product_LD);
    this.setupAttributeProjection(_product_l3, "Short Description", _product_SD);
    
    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_PRODUCT.PROD_STD_GROUP");
    _cols.add("XADEMO.XADEMO_PRODUCT.PROD_STD_GROUP_LLABEL");
    _cols.add("XADEMO.XADEMO_PRODUCT.PROD_STD_GROUP_SLABEL");
    this.createLevelMap(_product_l3, _keys,_cols);

  // Create the L4 Level for PRODUCT
    Level _product_l4 = _product.createLevel();
    _product_l4.setName("L4");

  // Create the Attribute Projections for the L2 Level
    this.setupAttributeProjection(_product_l4, "COLOR", _product_C);
    this.setupAttributeProjection(_product_l4, "SIZE", _product_S);
    this.setupAttributeProjection(_product_l4, "Long Description", _product_LD);
    this.setupAttributeProjection(_product_l4, "Short Description", _product_SD);
    
    this.clearLevelMapVectors();
    _keys.add("XADEMO.XADEMO_PRODUCT.PROD_STD_PRODUCT");
    _cols.add("XADEMO.XADEMO_PRODUCT.PROD_COLOR");
    _cols.add("XADEMO.XADEMO_PRODUCT.PROD_SIZE");    
    _cols.add("XADEMO.XADEMO_PRODUCT.PROD_STD_PRODUCT_LLABEL");
    _cols.add("XADEMO.XADEMO_PRODUCT.PROD_STD_PRODUCT_SLABEL");
    this.createLevelMap(_product_l4, _keys,_cols);

   // Create the STANDARD Hierarchy
    Hierarchy _product_hier_standard = _product.createHierarchy();
    _product_hier_standard.setName("STANDARD");

  // The following vectors represent the levels included
  // in the hierarchy.  The order is based on the hierarchical
  // tree in the AW starting at the top.
    clearHierarchyMapVectors();  
    _levels.add(_product_l1);
    _levColumns.add("XADEMO.XADEMO_PRODUCT.PROD_STD_TOP");
    _levels.add(_product_l2);
    _levColumns.add("XADEMO.XADEMO_PRODUCT.PROD_STD_DIVISION");
    _levels.add(_product_l3);
    _levColumns.add("XADEMO.XADEMO_PRODUCT.PROD_STD_GROUP");
    _levels.add(_product_l4);
    _levColumns.add("XADEMO.XADEMO_PRODUCT.PROD_STD_PRODUCT");
    
  // Map the relational columns to the hierarchy.    
    this.createHierarchyMap(_product_hier_standard, _levels, _levColumns);    
  }
  
  public void associateCubeDimensions(Cube _cube, Vector _dimList)
  {
    for (int i=0; i < _dimList.size(); i++)
    {
      CubeDimRef _cdr = _cube.createCubeDimRef();
      _cdr.setDimension((Dimension)_dimList.elementAt(i));
    }
  }

  public void createCubeMap(Cube _cube, Vector _levels, Vector _columns,
                            Vector _measures, Vector _measCols)
  {
      CubeMapGroup _cmg = _cube.createSourceCubeMapGroup();

      // Create the primary key in the fact table
      for (int y=0; y < _levels.size(); y++)
      {
        CubeDimensionSourceExpression _cdse = _cmg.CreateKeyMap();
        _cdse.setLevel((Level)_levels.elementAt(y));

        // Loop through the associated comma delimeted 
        // FKey Columns in the Fact Table
        StringTokenizer _st = new StringTokenizer((String)_columns.elementAt(y), "," );
        while (_st.hasMoreTokens()) 
        {
          SourceColumn _keycol = _cdse.CreateSourceColumn();
          _keycol.setColumn(_st.nextToken());
        } 
      }

      for(int x=0; x < _measures.size(); x++)
      {
        Measure curMeasure = (Measure)_measures.elementAt(x);
        String  curMeascol = (String)_measCols.elementAt(x);
        MeasureSourceExpression _measMap = _cmg.CreateAttributeMap(); // Should be called CreateMeasureMap
        _measMap.setTargetObject(curMeasure);
        SourceColumn _meascol = _measMap.CreateSourceColumn();
        _meascol.setColumn(curMeascol);        
      }
  }

  public void createLevelMap(Level _lev, Vector _keys, Vector _columns)
  {
    // Map the key(s) (relational side) to the level
    DimensionMapGroup _dmg = _lev.createSourceDimensionMapGroup();
    DimensionKeySourceExpression _key = _dmg.CreateKeyMap();

    for (int y=0; y < _keys.size(); y++)
    {
      SourceColumn _keycol = _key.CreateSourceColumn();
      _keycol.setColumn((String)_keys.elementAt(y));
    }

    // Map the columns (relational side) to the attribute projections
    int i = 0;
    for(Iterator attrs = _lev.getAttributes().iterator(); attrs.hasNext();)
    {
      AttributeProjection _curAttr = (AttributeProjection)attrs.next();
      AttributeSourceExpression _attrMap = _dmg.CreateAttributeMap();
      _attrMap.setTargetObject(_curAttr); 
      SourceColumn _attrCol = _attrMap.CreateSourceColumn();
      _attrCol.setColumn((String)_columns.elementAt(i));
      i++;
    }
  }

    public void createHierarchyMap(Hierarchy _hier, Vector _levels, Vector columns)
    {
    // Create the associations between the levels and the hierarchy    
       int i = 0;
      for(Iterator _lev = _levels.iterator(); _lev.hasNext();)
      {
        Level _curLev = (Level)_lev.next();
        HierarchyLevelAssociation _hla = _hier.createHierarchyLevelAssociation();
        _hla.setName("STD_Hierarchy_Association");
        _hla.setLevel(_curLev);

        DimensionMapGroup _dmg = _hla.createSourceDimensionMapGroup();
        DimensionKeySourceExpression _dkse = _dmg.CreateKeyMap();
        SourceColumn _levColumn = _dkse.CreateSourceColumn();
        _levColumn.setColumn((String)columns.elementAt(i));

      // The first level has no parent. Subsequent levels will.  The order
      // of the vector MUST begin with the top most level
        if (i > 0)
        {
          HierarchialParentSourceExpression _hpse = _dmg.CreateParentMap();
          SourceColumn _hpsesc = _hpse.CreateSourceColumn();
          _hpsesc.setColumn((String)columns.elementAt(i-1));
        }
        i++;
      }
    }

  public Level setupSimpleDim(Dimension _dim)
  {
  // Create the Long and Short Description Attributes
    Attribute _attr_LD = createLongDescAttr(_dim);
    Attribute _attr_SD = createShortDescAttr(_dim);

   // Create the L0 Level
    Level _lev = _dim.createLevel();
    _lev.setName("L0");

  // Create the Long Description Attribute Projection for the L0 Level
    AttributeProjection _ap_LD = _lev.createAttributeProjection();
    _ap_LD.setName("Long Description");
    _ap_LD.setAttribute(_attr_LD);

  // Create the Short Description Attribute Projection for the L0 Level
    AttributeProjection _ap_SD = _lev.createAttributeProjection();
    _ap_SD.setName("Short Description");
    _ap_SD.setAttribute(_attr_SD);

    return _lev;
  }

  public void setupAttributeProjection(Level _lev, String _name, Attribute _attr)
  {
     AttributeProjection _ap = _lev.createAttributeProjection();
    _ap.setName(_name);
    _ap.setAttribute(_attr);
  }

  public Attribute createLongDescAttr(Dimension _dim)
  {
     Attribute _LD_attr = _dim.createAttribute();
    _LD_attr.setName("Long_Description");
    _LD_attr.setClassification("MEMBER_LONG_DESCRIPTION");

    return _LD_attr;
  }

  public Attribute createShortDescAttr(Dimension _dim)
  {
     Attribute _SD_attr = _dim.createAttribute();
    _SD_attr.setName("Short_Description");
    _SD_attr.setClassification("MEMBER_SHORT_DESCRIPTION");

    return _SD_attr;
  }

  public void clearLevelMapVectors()
  {
    _keys.removeAllElements();
    _cols.removeAllElements();    
  }

  public void clearHierarchyMapVectors()
  {
    _levels.removeAllElements();
    _levColumns.removeAllElements();    
  }
  
  public void clearCubeMapVectors()
  {
    _measures.removeAllElements();
    _measCols.removeAllElements();
    _levels.removeAllElements();
    _cols.removeAllElements();
    _dimList.removeAllElements();
  }
  
  public static void main(String[] args)
  {
    xml_create_xademo_aw runTest = new xml_create_xademo_aw();
  }
}

