Package modTransf.model.factory

Source Code of modTransf.model.factory.ModelFactoryRepository

//Source file: H:\\TEMP\\generated\\ispuml\\mdaTransformation\\model\\factory\\ModelFactoryRepository.java

package modTransf.model.factory;

import java.io.FileReader;
import java.util.Map;
import java.util.HashMap;

import java.io.InputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import modTransf.model.NotFoundException;

/**
* ModelFactory repository.
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Dream Factory</p>
* @author Cedric Dumoulin
* @version 1.0
*/
public class ModelFactoryRepository
{

  protected Map helpers = new HashMap();

  protected RepositoryConfigReader configReader;


   public ModelFactoryRepository()
   {

   }

   /**
    * Get the helper associated to the MM uri.
    * Throws NotFoundException if no helper is found.
    * @return modTransf.model.factory.ModelFactory
    */
   public ModelFactory getModelFactory(String mmUri)
     throws NotFoundException
   {
   ModelFactory helper = (ModelFactory)helpers.get(mmUri);
   if(helper==null)
     throw new NotFoundException("No registered metamodel helper found for '" + mmUri + "'.");

    return helper;
   }

   /**
    * Add an helper to the factory.
    * @param helper
    */
   public void addModelFactory(ModelFactory factory)
   {
   helpers.put( factory.getMmURI(), factory);
   }

   /**
    * Remove specified factory.
    * @param mmUri
    * @return modTransf.model.factory.ModelFactory
    */
   public ModelFactory removeModelFactory(String mmUri)
   {
   return (ModelFactory)helpers.remove( mmUri);
   }

   /**
    * Remove specified factory.
    * @param factory
    */
   public void removeModelFactory(ModelFactory factory)
   {
   helpers.remove( factory.getMmURI());
   }

   /**
    * Read the specified configuration. Any declared factory will be added to the
    * factory.
    * @param reader
    */
   public void readConfigFile(InputStream input)
     throws ModelFactoryException
   {
   if( configReader == null )
     configReader = new RepositoryConfigReader();

   configReader.readConfigFile( this, input );

   }

   /**
    * Read the specified config file. Any declared factory will be added to the
    * factory.
    * @param filename
    */
   public void readConfigFile(String filename)
     throws FileNotFoundException, ModelFactoryException
   {
   if( configReader == null )
     configReader = new RepositoryConfigReader();

   configReader.readConfigFile( this, filename );
   }

   /**
    * Set the parameter in the reader.
    * Usage reserved for expert.
    * @param useContextClassLoader boolean
    */
   public void setConfigFileReaderUseContextClassLoader(boolean useContextClassLoader)
   {
     if( configReader == null )
       configReader = new RepositoryConfigReader();
     configReader.setUseContextClassLoader(useContextClassLoader);
   }

  static protected ModelFactoryRepository instance;

    /**
     * Get the common instance.
     * @return
     */
  static public ModelFactoryRepository getInstance()
  {
  if( instance != null )
    return instance;

    // create the instance
  instance = new ModelFactoryRepository();
    // populate the instance with default helpers
  /*
  instance.addModelFactory( new MDRModelFactory("uml14", "model/uml14-01-02-15_Diff.xml", "UML", "modTransf.model.jmi.JmiUML14ModelContext") );
  instance.addModelFactory( new MDRModelFactory("extMof14", "model/extMof14.xml", "Model", "modTransf.model.jmi.JmiModelContext") );
  instance.addModelFactory( new MDRModelFactory("mof14", "model/mof14.xml", "Model", "modTransf.model.jmi.JmiModelContext") );
  instance.addModelFactory( new MDRModelFactory("infra", "model/Infrastructure_MOF_Diff.xml", "InfrastructureLibrary", "modTransf.model.jmi.JmiModelContext") );
  */

  return instance;
  }


}
TOP

Related Classes of modTransf.model.factory.ModelFactoryRepository

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.