//Source file: H:\\TEMP\\generated\\ispuml\\mdaTransformation\\model\\factory\\NsUmlModelFactory.java
package modTransf.model.factory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.IOException;
import javax.jmi.reflect.RefPackage;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.File;
import ru.novosoft.mdf.impl.MDFOutermostPackageImpl;
/**
* Implementation of the MM Helper for NsUml.
*/
public class NsUmlModelFactory extends ModelFactoryBase
{
protected String mmOutermostExtentClassname;
/** The extent implementation class name for mof14 */
public static final String MOF14_EXTENTIMPL_PKG = "ru.novosoft.mdf.mof.impl.model.MOFModelPackageImpl";
/** The extent implementation class name */
public static final String ISPUML_EXTENTIMPL_PKG = "ispuml.model.impl.IspUMLPackageImpl";
/** XMI version used */
protected static String xmiVersion = "1.1";
public NsUmlModelFactory()
{
}
/**
* Access method for the mmOutermostExtentClassname property.
*
* @return the current value of the mmOutermostExtentClassname property
*/
public String getMmOutermostExtentClassname()
{
return mmOutermostExtentClassname;
}
/**
* Sets the value of the mmOutermostExtentClassname property.
*
* @param aMmOutermostExtentClassname the new value of the mmOutermostExtentClassname property
*/
public void setMmOutermostExtentClassname(String aMmOutermostExtentClassname)
{
mmOutermostExtentClassname = aMmOutermostExtentClassname;
}
/**
* @return Object
*/
public Object createEmptyNativeModel()
throws ModelFactoryException
{
if (mmOutermostExtentClassname==null)
throw new ModelFactoryException("Classname of outermost metamodel package should be set.");
try {
return (RefPackage)Class.forName(mmOutermostExtentClassname).newInstance();
}
catch (Exception ex) {
throw new ModelFactoryException(ex);
}
}
/**
* Release the model container.
* Called when the application don't need to use the model anymore.
* The container implementation can collect and free all the model resources.
* @return Object
*/
public void releaseNativeModel(Object container)
{
}
/**
* Read model from the specified reader and store it into the container .
* @param input
* @param container
*/
public void readNativeModel(InputStream input, Object container)
throws IOException, ModelFactoryException
{
RefPackage extent = (RefPackage)container;
try
{
MDFOutermostPackageImpl extentImpl = getModelImpl(extent);
extentImpl.getXMIReader( xmiVersion ).read( extentImpl, input );
}
catch( java.lang.Exception ex )
{
throw new ModelFactoryException(ex);
}
}
/**
* Read model from the specified filename and store it into the container .
* The container should be adapted to the model to be read.
* @param filereader
* @param container
*/
public void readNativeModel(String filename, Object container)
throws IOException, ModelFactoryException
{
RefPackage extent = (RefPackage)container;
try
{
MDFOutermostPackageImpl extentImpl = getModelImpl(extent);
FileInputStream fis = new FileInputStream( new File(filename) );
extentImpl.getXMIReader( xmiVersion ).read( extentImpl, fis );
}
catch( java.lang.Exception ex )
{
throw new ModelFactoryException(ex);
}
}
/**
* Write the model contained in the container to the specified writer.
* Do not close the stream
* @param filewriter
* @param container
*/
public void writeNativeModel(OutputStream out, Object container)
throws IOException, ModelFactoryException
{
RefPackage extent = (RefPackage)container;
throw new UnsupportedOperationException("Not yet implemented");
}
/**
* Write the model contained in the container to the specified filename.
* @param filewriter
* @param container
*/
public void writeNativeModel(String filename, Object container)
throws IOException, ModelFactoryException
{
RefPackage extent = (RefPackage)container;
try
{
MDFOutermostPackageImpl extentImpl = getModelImpl(extent);
FileOutputStream fos = new FileOutputStream( new File(filename) );
extentImpl.getXMIWriter(xmiVersion).write( extentImpl, fos);
}
catch( java.lang.Exception ex )
{
throw new ModelFactoryException(ex);
}
}
/**
* Get the underlying implementation of the extent.
* @param extent
* @return
*/
public static MDFOutermostPackageImpl getModelImpl(RefPackage extent)
{
return (MDFOutermostPackageImpl)extent;
}
}