Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * This program is free software; you can redistribute it and/or modify it under the
    * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
    * Foundation.
    *
    * You should have received a copy of the GNU Lesser General Public License along with this
    * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
    * or from the Free Software Foundation, Inc.,
    * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   *
   * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
   * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   * See the GNU Lesser General Public License for more details.
   *
   * Copyright (c) 2006 - 2009 Pentaho Corporation..  All rights reserved.
   */
  package org.pentaho.pms.factory;
  
  import java.net.URL;
  import java.util.Date;
  import java.util.List;
  
  import  org.pentaho.di.core.NotePadMeta;
  import  org.pentaho.di.core.ProgressMonitorListener;
  import  org.pentaho.di.core.database.DatabaseMeta;
  import  org.pentaho.di.core.exception.KettleDatabaseException;
  import  org.pentaho.di.core.exception.KettleXMLException;
This class is responsible for converting between the Schema metadata and the CWM

Author(s):
Matt
 
 @SuppressWarnings("deprecation")
 public class CwmSchemaFactory implements CwmSchemaFactoryInterface
 {
   
   private static final Log logger = LogFactory.getLog(CwmSchemaFactory.class);
     public CwmSchemaFactory() {
       
     }
   
   
     /*
      ____       _                          __  __      _
     / ___|  ___| |__   ___ _ __ ___   __ _|  \/  | ___| |_ __ _
     \___ \ / __| '_ \ / _ \ '_ ` _ \ / _` | |\/| |/ _ \ __/ _` |
      ___) | (__| | | |  __/ | | | | | (_| | |  | |  __/ || (_| |
     |____/ \___|_| |_|\___|_| |_| |_|\__,_|_|  |_|\___|\__\__,_|     
 
      */
    
    
This method allows you to store a complete schema (model) into the CWM using the MDR

Parameters:
cwm The model to use
schemaMeta The meta-data to store into the cwm model
 
     public void storeSchemaMeta(CWM cwmSchemaMeta schemaMetathrows Exception
     {
         this.storeSchemaMeta(cwmschemaMetanull);
     }
    
    
This method allows you to store a complete schema (model) into the CWM using the MDR

Parameters:
cwm The model to use
schemaMeta The meta-data to store into the cwm model
 
     public void storeSchemaMeta(CWM cwmSchemaMeta schemaMeta, ProgressMonitorListener monitorthrows Exception
     {
           throw new CwmSchemaFactoryException(Messages.getString("CwmSchemaFactory.ERROR_0001_SCHEMA_ADMIN_ACCESS_DENIED")); //$NON-NLS-1$
         }
         try
         {
             cwm.beginTransaction();
             
             // Save the security service information
             if (monitor!=nullmonitor.subTask(Messages.getString("CwmSchemaFactory.INFO_STORING_SECURITY_INFO")); //$NON-NLS-1$
             storeSecurityService(cwmschemaMeta.getSecurityReference().getSecurityService());
             if (monitor!=nullmonitor.worked(1);
             
             // Save the databases first...
             //
             if (monitor!=nullmonitor.subTask(Messages.getString("CwmSchemaFactory.INFO_STORING_DATABASES")); //$NON-NLS-1$
             for (int i=0;i<schemaMeta.nrDatabases();i++)
             {
                 DatabaseMeta databaseMeta = schemaMeta.getDatabase(i);
                 storeDatabaseMeta(cwmdatabaseMeta);
                 if (monitor!=nullmonitor.worked(1);
             }
             
             // Save the concepts early as well...
             //
             if (monitor!=nullmonitor.subTask(Messages.getString("CwmSchemaFactory.INFO_STORING_CONCEPTS")); //$NON-NLS-1$
             for (int i=0;i<schemaMeta.nrConcepts();i++)
             {
                 ConceptInterface concept = schemaMeta.getConcept(i);
                 storeModelConcept(cwmconcept);
                 if (monitor!=nullmonitor.worked(1);
             }
             
             // Now save the physical tables...
             if (monitor!=nullmonitor.subTask(Messages.getString("CwmSchemaFactory.INFO_STORING_PHYSICAL_TABLES")); //$NON-NLS-1$
             for (int i=0;i<schemaMeta.nrTables();i++)
             {
                 PhysicalTable physicalTable = schemaMeta.getTable(i);
                 storePhysicalTable(cwmphysicalTable);
                 if (monitor!=nullmonitor.worked(1);
             }
     
             // Save the business models...
             //
             if (monitor!=nullmonitor.subTask(Messages.getString("CwmSchemaFactory.INFO_STORING_BUSINESS_MODELS")); //$NON-NLS-1$
             for (int i=0;i<schemaMeta.nrBusinessModels();i++)
             {
                 BusinessModel businessModel = schemaMeta.getModel(i);
                 storeBusinessModel(cwmbusinessModel);
                 if (monitor!=nullmonitor.worked(1);
             }
             
             // Save the defined locales...
             //
             if (monitor!=nullmonitor.subTask(Messages.getString("CwmSchemaFactory.INFO_STORING_LOCALES")); //$NON-NLS-1$
             Locales locales = schemaMeta.getLocales();
             for (int i=0;i<locales.nrLocales();i++)
             {
                 LocaleInterface locale = locales.getLocale(i);
                 storeLocale(cwmlocale);
                 if (monitor!=nullmonitor.worked(1);
             }
     
             cwm.endTransaction();
     
             if (monitor!=nullmonitor.subTask(Messages.getString("CwmSchemaFactory.INFO_FINISHED")); //$NON-NLS-1$
         }
         catch(Exception e)
         {
             cwm.rollback();
             throw e;
         }
     }

    
Load schema from a CWM model

Parameters:
cwm The model to load
Returns:
a newly created SchemaMeta object.
 
     public SchemaMeta getSchemaMeta(CWM cwm)
     {
         SchemaMeta schemaMeta = new SchemaMeta();
         
         SecurityService securityService = getSecurityService(cwm);
         
         // Load the security reference information from the server each time we run...
         SecurityReference securityReference;
         try
         {
             securityReference = new SecurityReference(securityService);
         }
         catch(Exception e)
         {
             securityReference = new SecurityReference();
             securityReference.setSecurityService(securityService);
         }
         
         schemaMeta.setSecurityReference(securityReference);
         
         // Set a sane default on the model name
         schemaMeta.setDomainNamecwm.getDomainName() );
         
         // Read all the database connections...
         //
         CwmCatalog[] catalogs = cwm.getCatalogs();
         for (int i=0;i<catalogs.length;i++)
         {
             CwmCatalog catalog = catalogs[i];
             
             DatabaseMeta databaseMeta = getDatabaseMeta(cwmcatalog);
             try
             {
                 schemaMeta.addDatabase(databaseMeta);
             }
             catch(ObjectAlreadyExistsException e)
             {
                 // Ignore the duplicates for now.
                 // TODO: figure out how to handle this error, the duplicate shouldn't be in the CWM in the first place!
                 // logger.error( Messages.getString("CwmSchemaFactory.ERROR_DUPLICATE_IN_CWM" ), e );
             }
 
         }
         
         // Read the model Concepts.
         // These are used as parents all over the place, make sure we load these early in the game
         //
         CwmClass[] cwmClasses = cwm.getClasses();
         
         // We actually load the concepts twice: once to load the data and once to set the parents.
         // The problem is that I'm not sure that the order in which they are loaded/saved is guaranteed.
         // It's a Quick&Dirty solution yes, but it should work.
         for (int repeat=0;repeat<2;repeat++)
         {
             for (int i=0;i<cwmClasses.length;i++)
             {
                 CwmClass cwmClass = cwmClasses[i];
     
                 ConceptInterface concept = getModelConcept(cwmcwmClassschemaMeta);
                 
                 // See if we already have this one.
                 ConceptInterface verify = schemaMeta.findConcept(concept.getName());
                 if (verify==null)
                 {
                     // add this one...
                     try
                     {
                         schemaMeta.addConcept(concept);
                     }
                     catch(ObjectAlreadyExistsException e)
                     {
                         // Ignore the duplicates for now.
                         // TODO: figure out how to handle this error, the duplicate shouldn't be in the CWM in the first place!
                         // logger.error( Messages.getString("CwmSchemaFactory.ERROR_DUPLICATE_IN_CWM" ), e );
                     }
                 }
                 else
                 {
                     // the concept is already in there, we are loading for the second time.
                     // If we have a parent now, it should be referenced OK.
                     verify.setParentInterface(concept.getParentInterface());
                 }
             }
         }
         
         // find all available tables and add them to the schema-metadata model...
         //
         CwmTable[] cwmTables = cwm.getTables();
         for (int i=0;i<cwmTables.length;i++)
         {
             CwmTable cwmTable = cwmTables[i];
 
             PhysicalTable physicalTable = getPhysicalTable(cwmcwmTableschemaMeta);
             try
             {
                 schemaMeta.addTable(physicalTable);
             }
             catch(ObjectAlreadyExistsException e)
             {
                 // Ignore the duplicates for now.
                 // TODO: figure out how to handle this error, the duplicate shouldn't be in the CWM in the first place!
                 // logger.error( Messages.getString("CwmSchemaFactory.ERROR_DUPLICATE_IN_CWM" ), e );
             }
         }
         
         // load all the business models
         //
         CwmSchema[] cwmSchemas = cwm.getSchemas();
         for (int i=0;i<cwmSchemas.length;i++)
         {
             CwmSchema cwmSchema = cwmSchemas[i];
             
             BusinessModel businessModel = getBusinessModel(cwmcwmSchemaschemaMeta);
             if (hasAccess(.businessModel)) 
             {
                 try
                 {
                     schemaMeta.addModel(businessModel);
                 }
                 catch(ObjectAlreadyExistsException e)
                 {
                     // Ignore the duplicates for now.
                     // TODO: figure out how to handle this error, the duplicate shouldn't be in the CWM in the first place!
                     // logger.error( Messages.getString("CwmSchemaFactory.ERROR_DUPLICATE_IN_CWM" ), e );
                 }
             }
         }
         
         // Load the locales
         //
         CwmParameter[] cwmParameters = cwm.getParameters();
         Locales locales = schemaMeta.getLocales();
         locales.getLocaleList().clear(); // remove any defined defaults...
         for (int i = 0; i < cwmParameters.lengthi++)
         {
             CwmParameter cwmParameter = cwmParameters[i];
             LocaleInterface locale = getLocale(cwmcwmParameter);
             locales.addLocale(locale);
         }
         locales.sortLocales();
 
         // Clear the changed flag all over the place...
         //
         schemaMeta.clearChanged();
         
         // Select the active business model if there is only one
         if (schemaMeta.nrBusinessModels()==1)
         {
             schemaMeta.setActiveModel(schemaMeta.getModel(0));
         }
         
         if (cwm.isReversingOrder())
         {
             Collections.reverse(schemaMeta.getTables().getList());
             Collections.reverse(schemaMeta.getBusinessModels().getList());
             Collections.reverse(schemaMeta.getConcepts().getList());
         }
 
         return schemaMeta;
     }
 
 
     /*
      ____                       _ _           ____                  _
     / ___|  ___  ___ _   _ _ __(_) |_ _   _  / ___|  ___ _ ____   _(_) ___ ___
     \___ \ / _ \/ __| | | | '__| | __| | | | \___ \ / _ \ '__\ \ / / |/ __/ _ \
      ___) |  __/ (__| |_| | |  | | |_| |_| |  ___) |  __/ |   \ V /| | (_|  __/
     |____/ \___|\___|\__,_|_|  |_|\__|\__, | |____/ \___|_|    \_/ |_|\___\___|
                                       |___/
     */

    
Store the security service parameters in the CWM model

Parameters:
cwm The CWM model to store in
securityService The security service to store
 
     public void storeSecurityService(CWM cwmSecurityService securityService)
     {
         throw new CwmSchemaFactoryException(Messages.getString("CwmSchemaFactory.ERROR_0001_SCHEMA_ADMIN_ACCESS_DENIED")); //$NON-NLS-1$
       }
         CwmEvent cwmEvent = cwm.createEvent(.);
         
         cwm.addTaggedValue(cwmEvent.securityService.getServiceURL());
         cwm.addTaggedValue(cwmEvent.securityService.getServiceName());
         cwm.addTaggedValue(cwmEvent.securityService.getDetailNameParameter());
         cwm.addTaggedValue(cwmEvent.securityService.getServiceTypeDesc());
         cwm.addTaggedValue(cwmEvent.securityService.getUsername());
         cwm.addTaggedValue(cwmEvent.securityService.getPassword());
 
         cwm.addTaggedValue(cwmEvent.securityService.getProxyHostname());
         cwm.addTaggedValue(cwmEvent.securityService.getProxyPort());
         cwm.addTaggedValue(cwmEvent.securityService.getNonProxyHosts());
 
         cwm.addTaggedValue(cwmEvent.securityService.getFilename());
 
         cwm.addTaggedValue(cwmEvent.securityService.getURL());
     }


    
Load the security service configuration information from the CWM model

Parameters:
cwm The CWM model
Returns:
a new security service object
 
     public SecurityService getSecurityService(CWM cwm)
     {
         SecurityService securityService = new SecurityService();
         
         CwmEvent cwmEvent = cwm.getFirstEventWithName(.); // there is one or none
         if (cwmEvent!=null)
         {
             securityService.setServiceURL(cwm.getFirstTaggedValue(cwmEvent.) );
             securityService.setServiceNamecwm.getFirstTaggedValue(cwmEvent. ) );
             securityService.setDetailNameParametercwm.getFirstTaggedValue(cwmEvent. ) );
             securityService.setDetailServiceType( SecurityService.getServiceTypecwm.getFirstTaggedValue(cwmEvent. ) ) );
             securityService.setUsernamecwm.getFirstTaggedValue(cwmEvent. ) );
             securityService.setPasswordcwm.getFirstTaggedValue(cwmEvent. ) );
 
             securityService.setProxyHostnamecwm.getFirstTaggedValue(cwmEvent. ) );
             securityService.setProxyPortcwm.getFirstTaggedValue(cwmEvent. ) );
             securityService.setNonProxyHostscwm.getFirstTaggedValue(cwmEvent. ) );
             
             securityService.setFilenamecwm.getFirstTaggedValue(cwmEvent. ) );
         }
         return securityService;
     }
     
     /*
     ____  _               _           _ _____     _     _
    |  _ \| |__  _   _ ___(_) ___ __ _| |_   _|_ _| |__ | | ___
    | |_) | '_ \| | | / __| |/ __/ _` | | | |/ _` | '_ \| |/ _ \
    |  __/| | | | |_| \__ \ | (_| (_| | | | | (_| | |_) | |  __/
    |_|   |_| |_|\__, |___/_|\___\__,_|_| |_|\__,_|_.__/|_|\___|
                 |___/     
     
     */
    
Stores the Kettle table metadata into the CWM model

Parameters:
cwm The CWM model
physicalTable the Kettle table metadata to store
Returns:
the created CwmTable
 
     public CwmTable storePhysicalTable(CWM cwmPhysicalTable physicalTable)
     {
         throw new CwmSchemaFactoryException(Messages.getString("CwmSchemaFactory.ERROR_0001_SCHEMA_ADMIN_ACCESS_DENIED")); //$NON-NLS-1$
       }
         CwmTable cwmTable = cwm.createTable(physicalTable.getId());
         
         // Store the concept properties
         storeConceptProperties(cwmcwmTablephysicalTable.getConcept());
         
         // Database : target database 
         if (physicalTable.getDatabaseMeta()!=null)
         {
             cwm.addTaggedValue(cwmTable.physicalTable.getDatabaseMeta().getName());
         }
         
         for (int i=0;i<physicalTable.nrPhysicalColumns();i++) 
         {
             PhysicalColumn physicalColumn = physicalTable.getPhysicalColumn(i);
             storePhysicalColumn(cwmcwmTablephysicalColumn);
         }
         
         return cwmTable;
     }

    
Load a physical table from a CWM model using a cwmTable reference and a list of available databases.

Parameters:
cwm
cwmTable
databases
Returns:
a new PhysicalTable object
 
     public PhysicalTable getPhysicalTable(CWM cwmCwmTable cwmTableSchemaMeta schemaMeta)
     {
         // Set the table name
         //
         PhysicalTable physicalTable = new PhysicalTable(cwmTable.getName());
         physicalTable.addIDChangedListener(ConceptUtilityBase.createIDChangedListener(schemaMeta.getTables()));
         
         // Link the database connection info...
         //
         String databaseName = cwm.getFirstTaggedValue(cwmTable.);
         physicalTable.setDatabaseMeta(schemaMeta.findDatabase(databaseName));
         
         // load the concept properties
         getConceptProperties(cwmcwmTablephysicalTable.getConcept(), schemaMeta);
 
         // Load the column data...
         //
         @SuppressWarnings("unchecked")
         Collection<CwmColumncolumnsCollection = cwmTable.getOwnedElement();
         if (columnsCollection!=null)
         {
             CwmColumn[] columns = (CwmColumn[]) columnsCollection.toArray(new CwmColumn[columnsCollection.size()]);
             for (int c=0;c<columns.length;c++)
             {
                 CwmColumn column = columns[c];
                 
                 PhysicalColumn physicalColumn = getPhysicalColumn(cwmcolumnphysicalTableschemaMeta);
                 
                 try
                 {
                     physicalTable.addPhysicalColumn(physicalColumn);
                 }
                 catch (ObjectAlreadyExistsException e)
                 {
                     // Ignore the duplicates for now.
                     // TODO: figure out how to handle this error, the duplicate shouldn't be in the CWM in the first place!
                     // logger.error( Messages.getString("CwmSchemaFactory.ERROR_DUPLICATE_IN_CWM" ), e );
                 }
             }
         }
         
         if (cwm.isReversingOrder())
         {
             Collections.reverse(physicalTable.getPhysicalColumns().getList());
         }
 
 
         return physicalTable;
     }
     
     /*
      ____  _               _           _  ____      _
     |  _ \| |__  _   _ ___(_) ___ __ _| |/ ___|___ | |_   _ _ __ ___  _ __
     | |_) | '_ \| | | / __| |/ __/ _` | | |   / _ \| | | | | '_ ` _ \| '_ \
     |  __/| | | | |_| \__ \ | (_| (_| | | |__| (_) | | |_| | | | | | | | | |
     |_|   |_| |_|\__, |___/_|\___\__,_|_|\____\___/|_|\__,_|_| |_| |_|_| |_|
                  |___/
      */
    
    
Store a physical column into the CWM metamodel

Parameters:
cwm The model to store in
cwmTable The parent table
physicalColumn the physical column to store
 
     public void storePhysicalColumn(CWM cwmCwmTable cwmTablePhysicalColumn physicalColumn)
     {
         throw new CwmSchemaFactoryException(Messages.getString("CwmSchemaFactory.ERROR_0001_SCHEMA_ADMIN_ACCESS_DENIED")); //$NON-NLS-1$
       }
         CwmColumn column = cwm.createColumn(physicalColumn.getId());
         
         // Store all properties...
         storeConceptProperties(cwmcolumnphysicalColumn.getConcept());
                         
         @SuppressWarnings("unchecked")
         Collection<CwmColumnc = cwmTable.getOwnedElement();
         c.add(column);    
     }
    
    
Load a physical column from the CWM metamodel

Parameters:
cwm the model to load from
column The CwmColumn to load the information from
physicalTable The physcial table to reference
schemaMeta The schema
Returns:
a new created Physical column, loaded from the cwm metamodel
 
     public PhysicalColumn getPhysicalColumn(CWM cwmCwmColumn columnPhysicalTable physicalTableSchemaMeta schemaMeta)
     {
         PhysicalColumn physicalColumn = new PhysicalColumn(column.getName());
         physicalColumn.addIDChangedListener(ConceptUtilityBase.createIDChangedListener(physicalTable.getPhysicalColumns()));
 
         // load all properties...
         getConceptProperties(cwmcolumnphysicalColumn.getConcept(), schemaMeta);
 
         // Finally, set a reference up to the parent table.
         physicalColumn.setTable(physicalTable);
         
         return physicalColumn;
     }
     
     /*
      ____        _        _                    __  __      _
     |  _ \  __ _| |_ __ _| |__   __ _ ___  ___|  \/  | ___| |_ __ _
     | | | |/ _` | __/ _` | '_ \ / _` / __|/ _ \ |\/| |/ _ \ __/ _` |
     | |_| | (_| | || (_| | |_) | (_| \__ \  __/ |  | |  __/ || (_| |
     |____/ \__,_|\__\__,_|_.__/ \__,_|___/\___|_|  |_|\___|\__\__,_|
     
      */

    
Uility method to store Kettle Database Metadata

Parameters:
cwm The model to store it in
databaseMeta The Kettle database connection metadata to use.
 
     public void storeDatabaseMeta(CWM cwm, DatabaseMeta databaseMeta)
     {
         throw new CwmSchemaFactoryException(Messages.getString("CwmSchemaFactory.ERROR_0001_SCHEMA_ADMIN_ACCESS_DENIED")); //$NON-NLS-1$
       }
         CwmCatalog catalog = cwm.createCatalog(databaseMeta.getName());
 
         catalog.setName(databaseMeta.getName());
         
         cwm.addTaggedValue(catalog.           , databaseMeta.getHostname());
         cwm.addTaggedValue(catalog.             , databaseMeta.getDatabaseTypeDesc());
         cwm.addTaggedValue(catalog.           , databaseMeta.getAccessTypeDesc());
         cwm.addTaggedValue(catalog.         , databaseMeta.getDatabaseName());
         cwm.addTaggedValue(catalog.             , databaseMeta.getDatabasePortNumberString());
         cwm.addTaggedValue(catalog.         , databaseMeta.getUsername());
         cwm.addTaggedValue(catalog.         , databaseMeta.getPassword());
         cwm.addTaggedValue(catalog.       , databaseMeta.getServername());
         cwm.addTaggedValue(catalog.  , databaseMeta.getDataTablespace());
         cwm.addTaggedValue(catalog. , databaseMeta.getIndexTablespace());
         
         // Save all the attributes as well...
         //
         List<Objectlist = new ArrayList<Object>( databaseMeta.getAttributes().keySet() );
         for (Iterator iter = list.iterator(); iter.hasNext();)
         {
             String key = (Stringiter.next();
             String attribute = (String)databaseMeta.getAttributes().get(key);
             
             if (!Const.isEmpty(attribute))
             {
                 cwm.addTaggedValue(catalog.+keyattribute);
             }
         }
 
         // Add the complete calculated URL for the pleasure of the other consumers besides Kettle
         //
         try
         {
             cwm.addTaggedValue(catalog.databaseMeta.getURL());
         }
         catch(KettleDatabaseException e// Data to make a URL is not valid, incomplete, etc.
         {
             cwm.addTaggedValue(catalog., Messages.getString("CwmSchemaFactory.ERROR_0002_INVALID_DATA")); // we don't read this back, it's only for 3rd party use. //$NON-NLS-1$
         }
     }
    
    
Read a DatabaseMeta from a CWM model by providing the catalog reference.

Parameters:
cwm
catalog
Returns:
a new DatabaseMeta instance, read from the specified CWM model.
Throws:
KettleXMLException
 
     public DatabaseMeta getDatabaseMeta(CWM cwmCwmCatalog catalog)
     {
         DatabaseMeta databaseMeta = new DatabaseMeta();
         
         databaseMeta.setName(catalog.getName());
         
         databaseMeta.setHostname( cwm.getFirstTaggedValue(catalog. ));
         databaseMeta.setDatabaseType( cwm.getFirstTaggedValue(catalog.   ));
         databaseMeta.setAccessType( DatabaseMeta.getAccessType( cwm.getFirstTaggedValue(catalog. )) );
         databaseMeta.setDBName( cwm.getFirstTaggedValue(catalog. ));
         databaseMeta.setDBPort( cwm.getFirstTaggedValue(catalog. ));
         databaseMeta.setUsername( cwm.getFirstTaggedValue(catalog. ));
         databaseMeta.setPassword( cwm.getFirstTaggedValue(catalog. ));
         databaseMeta.setServername( cwm.getFirstTaggedValue(catalog. ));
         databaseMeta.setDataTablespace( cwm.getFirstTaggedValue(catalog. ));
         databaseMeta.setIndexTablespace( cwm.getFirstTaggedValue(catalog. ));
 
         // And now load the attributes...
         CwmTaggedValue[] taggedValue = cwm.getTaggedValues(catalog);
         for (int i = 0; i < taggedValue.lengthi++)
         {
             if (taggedValue[i].getTag().startsWith(.))
             {
                 String key = taggedValue[i].getTag().substring(..length());
                 String attribute = taggedValue[i].getValue();
                 
                 // Add the attribute
                 databaseMeta.getAttributes().put(keyattribute);
             }
         }
         
         
         return databaseMeta;
     }
     
     /*
      ____            _                   __     ___
     | __ ) _   _ ___(_)_ __   ___  ___ __\ \   / (_) _____      __
     |  _ \| | | / __| | '_ \ / _ \/ __/ __\ \ / /| |/ _ \ \ /\ / /
     | |_) | |_| \__ \ | | | |  __/\__ \__ \\ V / | |  __/\ V  V /
     |____/ \__,_|___/_|_| |_|\___||___/___/ \_/  |_|\___| \_/\_/
     
     */

    
This method stores a business model in a CwmSchema. The schema then in turn contains a number of

Parameters:
cwm The model to store in
businessModel The business model to store into the selected CWM model.
 
     public void storeBusinessModel(CWM cwmBusinessModel businessModel)
     {
         throw new CwmSchemaFactoryException(Messages.getString("CwmSchemaFactory.ERROR_0001_SCHEMA_ADMIN_ACCESS_DENIED")); //$NON-NLS-1$
       }
         CwmSchema cwmSchema = cwm.createSchema(businessModel.getId());
         
         // Store the concept properties
         storeConceptProperties(cwmcwmSchemabusinessModel.getConcept());
         
         // Store the business tables...
         //
         for (int i=0;i<businessModel.nrBusinessTables();i++)
         {
             BusinessTable businessTable = businessModel.getBusinessTable(i);
             storeBusinessTable(cwmcwmSchemabusinessTable);
         }
         
         // Store the notes...
         //
         for (int i=0;i<businessModel.nrNotes();i++)
         {
             NotePadMeta notePadMeta = businessModel.getNote(i);
             storeNotePadMeta(cwmcwmSchemanotePadMeta);
         }
         
         // Store the relationships...
         for (int i=0;i<businessModel.nrRelationships();i++)
         {
             RelationshipMeta relationshipMeta = businessModel.getRelationship(i);
             storeRelationshipMeta(cwmrelationshipMetacwmSchema);
         }
         
         // Also store the categories...
         for (int i=0;i<businessModel.getRootCategory().nrBusinessCategories();i++)
         {
             BusinessCategory businessCategory = businessModel.getRootCategory().getBusinessCategory(i);
             storeBusinessCategory(cwmbusinessCategorynullcwmSchema);
         }
         // Save the olap information
         //
         // Create a CWM Schema first for this...
         org.pentaho.pms.cwm.pentaho.meta.olap.CwmSchema cwmOlapSchema = cwm.createOlapSchema(businessModel.getId());
         
         // Put the OLAP stuff in there.
         //
         // The dimensions
         List dimensions = businessModel.getOlapDimensions();
         for (int i=0;i<dimensions.size();i++)
         {
             OlapDimension dimension = (OlapDimensiondimensions.get(i);
             storeOlapDimension(cwmcwmOlapSchemadimension);
         }
         // And the cubes
         List cubes = businessModel.getOlapCubes();
         for (int i=0;i<cubes.size();i++)
         {
             OlapCube cube = (OlapCubecubes.get(i);
             storeOlapCube(cwmcwmOlapSchemacube);
         }
     }

    
Load a business model from a CWM model by loading it from the supplied CwmSchema and using the SchemaMeta object for reference.

Parameters:
cwm
cwmSchema
schemaMeta
Returns:
a newly created Business Model
 
     public BusinessModel getBusinessModel(CWM cwmCwmSchema cwmSchemaSchemaMeta schemaMeta
     {
         // The name?
         BusinessModel businessModel = new BusinessModel(cwmSchema.getName());
         businessModel.addIDChangedListener(ConceptUtilityBase.createIDChangedListener(schemaMeta.getBusinessModels()));
 
         // load the concept properties
         getConceptProperties(cwmcwmSchemabusinessModel.getConcept(), schemaMeta);
 
         // Load the business tables into this business model..
         //
         CwmDimension[] CwmDimensions = cwm.getDimensions(cwmSchema);
         for (int i = 0; i < CwmDimensions.lengthi++)
         {
             CwmDimension cwmDimension = CwmDimensions[i];
             BusinessTable businessTable = getBusinessTable(cwmcwmDimensionschemaMetabusinessModel);
             
             if (hasAccess(.,businessTable)) 
             {
                 try
                 {
                     businessModel.addBusinessTable(businessTable);
                 }
                 catch(ObjectAlreadyExistsException e)
                 {
                     // Ignore the duplicates for now.
                     // TODO: figure out how to handle this error, the duplicate shouldn't be in the CWM in the first place!
                     // logger.error( Messages.getString("CwmSchemaFactory.ERROR_DUPLICATE_IN_CWM" ), e );
                 }
             }
         }
         
         // Load the notes too
         //
         CwmDescription[] cwmDescriptions = cwm.getDescription(cwmSchema);
         for (int i=0;i<cwmDescriptions.length;i++)
         {
             CwmDescription cwmDescription = cwmDescriptions[i];
             if ( ..equals(cwmDescription.getType()) )
             {
                 NotePadMeta notePadMeta = getNotePadMeta(cwmcwmDescription);
                 businessModel.addNote(notePadMeta);
             }
         }
         
         // Load the relationships too...
         CwmKeyRelationship[] cwmKeyRelationships = cwm.getRelationships(cwmSchema);
         for (int i=0;i<cwmKeyRelationships.length;i++)
         {
             CwmKeyRelationship cwmKeyRelationship = cwmKeyRelationships[i];
             RelationshipMeta relationshipMeta = getRelationshipMeta(cwmcwmKeyRelationshipbusinessModel);
             businessModel.addRelationship(relationshipMeta);
         }
         
         // Load the categories...
         CwmExtent[] cwmExtents = cwm.getRootExtents(cwmSchema);
         for (int i=0;i<cwmExtents.length;i++)
         {
             CwmExtent cwmExtent = cwmExtents[i];
             BusinessCategory businessCategory = getBusinessCategory(cwmcwmExtentbusinessModelschemaMeta);
             if (hasAccess(.,businessCategory)) 
             {
                 try
                 {
                     businessModel.getRootCategory().addBusinessCategory(businessCategory);
                 }
                 catch(ObjectAlreadyExistsException e)
                 {
                     // Ignore the duplicates for now.
                     // TODO: figure out how to handle this error, the duplicate shouldn't be in the CWM in the first place!
                     // logger.error( Messages.getString("CwmSchemaFactory.ERROR_DUPLICATE_IN_CWM" ), e );
                 }
             }
         }
         
         // Load the OLAP information too
         org.pentaho.pms.cwm.pentaho.meta.olap.CwmSchema cwmOlapSchema = cwm.findOlapSchema(cwmSchema.getName()); // same name as business model
         
         if (cwmOlapSchema!=null)
         {
             // get the Olap Dimensions from this schema...
             Collection cwmOlapDimensions = cwmOlapSchema.getDimension();
             for (Iterator iter = cwmOlapDimensions.iterator(); iter.hasNext();)
             {
                 org.pentaho.pms.cwm.pentaho.meta.olap.CwmDimension cwmOlapDimension = (org.pentaho.pms.cwm.pentaho.meta.olap.CwmDimensioniter.next();
                 OlapDimension olapDimension = getOlapDimension(cwmcwmOlapDimensionbusinessModel);
                 businessModel.getOlapDimensions().add(0, olapDimension); // Inverse the load (MDR does it backward)
             }
             
             Collection cwmOlapCubes = cwmOlapSchema.getCube();
             for (Iterator iter = cwmOlapCubes.iterator(); iter.hasNext();)
             {
                 CwmCube cwmCube = (CwmCubeiter.next();
                 OlapCube olapCube = getOlapCube(cwmcwmCubebusinessModel);
                 businessModel.getOlapCubes().add(olapCube);
             }
         }
         
         if (cwm.isReversingOrder())
         {
             Collections.reverse(businessModel.getBusinessTables().getList());
             Collections.reverse(businessModel.getRootCategory().getBusinessCategories().getList());
         }
 
         return businessModel;
     }
 
     /*
      ____            _                    _____     _     _
     | __ ) _   _ ___(_)_ __   ___  ___ __|_   _|_ _| |__ | | ___
     |  _ \| | | / __| | '_ \ / _ \/ __/ __|| |/ _` | '_ \| |/ _ \
     | |_) | |_| \__ \ | | | |  __/\__ \__ \| | (_| | |_) | |  __/
     |____/ \__,_|___/_|_| |_|\___||___/___/|_|\__,_|_.__/|_|\___| 
 
      */
    
    
    
Store a business table in the MDR

Parameters:
cwm The model to store in
cwmSchema The CWM Schema to put the tables into.
businessTable The business table to store.
 
     public void storeBusinessTable(CWM cwmCwmSchema cwmSchemaBusinessTable businessTable)
     {
         throw new CwmSchemaFactoryException(Messages.getString("CwmSchemaFactory.ERROR_0001_SCHEMA_ADMIN_ACCESS_DENIED")); //$NON-NLS-1$
       }
         CwmDimension cwmDimension = cwm.createDimension(cwmSchemabusinessTable.getId());
         
         // The physical table name?
         String physicalTablename = businessTable.getPhysicalTable().getId();
         @SuppressWarnings("all")
         Collection<CwmTaggedValuecg = cwmDimension.getTaggedValue();
         cg.add(cwm.createTaggedValue(.physicalTablename));
         
         // The location, etc: GUI elements...
         //
         // Position
         cwm.setPosition(cwmDimensionbusinessTable.getLocation().x, businessTable.getLocation().y);
         // Drawn?
         cwm.addTaggedValue(cwmDimension.businessTable.isDrawn()?"Y":"N"); //$NON-NLS-1$ //$NON-NLS-2$
 
         // Store the properties...
         storeConceptProperties(cwmcwmDimensionbusinessTable.getConcept());
         
         // Store the business columns...
         // 
         for (int i=0;i<businessTable.nrBusinessColumns();i++)
         {
             BusinessColumn businessColumn = businessTable.getBusinessColumn(i);
             storeBusinessColumn(cwmcwmSchemacwmDimensionbusinessColumn);
         }
     }
    
    
Load a BusinessTable from a CWM model by taking information from a supplied CwmDimension

Parameters:
cwm
cwmDimension
schemaMeta
Returns:
a newly created BusinessTable
 
     public BusinessTable getBusinessTable(CWM cwmCwmDimension cwmDimensionSchemaMeta schemaMetaBusinessModel businessModel
     {
         BusinessTable businessTable = new BusinessTable(cwmDimension.getName());
         businessTable.addIDChangedListener(ConceptUtilityBase.createIDChangedListener(businessModel.getBusinessTables()));
         
         // load the properties...
         getConceptProperties(cwmcwmDimensionbusinessTable.getConcept(), schemaMeta);
 
         // Set the security parent to inherit from
         businessTable.getConcept().setSecurityParentInterface(businessModel.getConcept());
         
         // The physical table...
         //
         String physicalTableName = cwm.getFirstTaggedValue(cwmDimension.);
         PhysicalTable physicalTable = schemaMeta.findPhysicalTable(physicalTableName);
         businessTable.setPhysicalTablephysicalTable );
         
         // The location, etc: GUI elements...
         //
         // Location
         int x = cwm.getPositionX(cwmDimension);
         int y = cwm.getPositionY(cwmDimension);
         businessTable.setLocation(xy);
         // Drawn?
         boolean drawn = "Y".equalsIgnoreCasecwm.getFirstTaggedValue(cwmDimension.) ); //$NON-NLS-1$
         businessTable.setDrawn(drawn);
         
         // The physical columns...
         //
         List cwmDimensionedObjects = cwmDimension.getDimensionedObject();
         for (int i=0;i<cwmDimensionedObjects.size();i++)
         {
             CwmDimensionedObject cwmDimensionedObject = (CwmDimensionedObjectcwmDimensionedObjects.get(i);
             BusinessColumn businessColumn = getBusinessColumn(cwmcwmDimensionedObjectphysicalTablebusinessTableschemaMeta);
             
             if (hasAccess(.businessColumn)) 
             {
                try
                {
                    businessTable.addBusinessColumn(businessColumn);
                }
                catch (ObjectAlreadyExistsException e)
                {
                    // Ignore the duplicates for now.
                    // TODO: figure out how to handle this error, the duplicate shouldn't be in the CWM in the first place!
                    // logger.error( Messages.getString("CwmSchemaFactory.ERROR_DUPLICATE_IN_CWM" ), e );
                }
            }
        }
        
        return businessTable;
    }
    /*
     ____            _                      ____      _
    | __ ) _   _ ___(_)_ __   ___  ___ ___ / ___|___ | |_   _ _ __ ___  _ __
    |  _ \| | | / __| | '_ \ / _ \/ __/ __| |   / _ \| | | | | '_ ` _ \| '_ \
    | |_) | |_| \__ \ | | | |  __/\__ \__ \ |__| (_) | | |_| | | | | | | | | |
    |____/ \__,_|___/_|_| |_|\___||___/___/\____\___/|_|\__,_|_| |_| |_|_| |_|
     */
    
    
Store the information from a business column in a dimensioned object in the MDR

Parameters:
cwm the model to store in
cwmSchema The CWM schema this object belongs to
cwmDimension The owner of the business column
businessColumn The business column to store
    public void storeBusinessColumn(CWM cwmCwmSchema cwmSchemaCwmDimension cwmDimensionBusinessColumn businessColumn)
    {
        throw new CwmSchemaFactoryException(Messages.getString("CwmSchemaFactory.ERROR_0001_SCHEMA_ADMIN_ACCESS_DENIED")); //$NON-NLS-1$
      }
        CwmDimensionedObject cwmDimensionedObject = cwm.createDimensionedObject(businessColumn.getId());
        cwmDimensionedObject.setSchema(cwmSchema);
        
        @SuppressWarnings("all")
        Collection<CwmTaggedValuec = cwmDimensionedObject.getTaggedValue();
        
        // store the physical column name...
        if (businessColumn.getPhysicalColumn() == null) {
          .error(Messages.getErrorString("CwmSchemaFactory.ERROR_0004_MISSING_PHYSICAL_COLUMN"businessColumn.getBusinessTable().getId(), businessColumn.getId())); //$NON-NLS-1$
          // attempt a repair by selecting the first physical col
          businessColumn.setPhysicalColumn(businessColumn.getBusinessTable().getPhysicalTable().getPhysicalColumn(0));
        }
        String physicalColumnName = businessColumn.getPhysicalColumn().getId();
        c.add(cwm.createTaggedValue(.physicalColumnName));
        
        // Store the name of the business table as well, just for reference
        String businessTableName = businessColumn.getBusinessTable().getId();
        c.add(cwm.createTaggedValue(.businessTableName));
        
        // And store the business column properties
        storeConceptProperties(cwmcwmDimensionedObjectbusinessColumn.getConcept());
        
        // Add to the dimension
        @SuppressWarnings("all")
        Collection<CwmDimensionedObjectcd = cwmDimension.getDimensionedObject();
        
        cd.add(cwmDimensionedObject);
    }
    
    
Create a business column from a dimensioned object...

Parameters:
cwm
cwmDimensionedObject
physicalTable
Returns:
The newly created business column
    public BusinessColumn getBusinessColumn(CWM cwm
        CwmDimensionedObject cwmDimensionedObject
        PhysicalTable physicalTable
        BusinessTable businessTable
        SchemaMeta schemaMeta)
    {