com.sodius.mdw.core.model.emf
Class EMFModelWriter

java.lang.Object
  extended by com.sodius.mdw.core.model.emf.EMFModelWriter
All Implemented Interfaces:
ModelWriter
Direct Known Subclasses:
EMFXMIModelWriter, EMFXMLModelWriter

public abstract class EMFModelWriter
extends Object
implements ModelWriter

Provides a skeletal implementation for EMF based model writers.

This class acts as a bridge between EMF Resource and MDWorkbench ModelWriter. Subclasses are required to implement the createResource method. This class will delegate the writing to the created resource.

A default implementation is available to handle XMI uris.

Clients may subclass this class.


Field Summary
static String MDW_CONNECTOR_CONTEXT
          Option that gives access to the connector context.
 
Constructor Summary
EMFModelWriter()
           
 
Method Summary
protected  Map<String,Object> createOptions(ConnectorContext context)
          Create options to pass to the created resource.
protected abstract  Resource createResource(URI uri, ConnectorContext context)
          Creates a resource that is able to handle the specified uri.
protected  Collection<EObject> getDirectContents(Model model, ConnectorContext context)
          Returns the model elements to attach to the create resource.
protected  void logError(ConnectorContext context, Resource.Diagnostic error)
          Logs the specified diagnostic to the registered logger.
 void write(String filepath, Model model, ConnectorContext context)
          Writes the specified model to the specified uri.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MDW_CONNECTOR_CONTEXT

public static final String MDW_CONNECTOR_CONTEXT
Option that gives access to the connector context. A resource save method can retrieve the connector context this way :
ConnectorContext context = (ConnectorContext) options.get(EMFModelWriter.MDW_CONNECTOR_CONTEXT);

See Also:
Constant Field Values
Constructor Detail

EMFModelWriter

public EMFModelWriter()
Method Detail

write

public void write(String filepath,
                  Model model,
                  ConnectorContext context)
           throws CoreException
Writes the specified model to the specified uri. This implementation writes a model in three steps :

The context can be used to access a variery of properties and is to be used to check for cancellation.

Specified by:
write in interface ModelWriter
Parameters:
filepath - the location of a resource to write.
model - the model to be persisted.
context - the context in which this writer runs.
Throws:
CoreException - if anything prevents the connector to write the model.
See Also:
ConnectorDescriptor.getKind()

createResource

protected abstract Resource createResource(URI uri,
                                           ConnectorContext context)
Creates a resource that is able to handle the specified uri.

Parameters:
uri - the URI to write.
context - the context in which the connector runs
Returns:
the created resource.

getDirectContents

protected Collection<EObject> getDirectContents(Model model,
                                                ConnectorContext context)
Returns the model elements to attach to the create resource. The default implementation returns every EObject that has no container.

Parameters:
model - the model to be persisted.
context - the context in which this writer runs.
Returns:
the model elements to attach to the create resource.

createOptions

protected Map<String,Object> createOptions(ConnectorContext context)
Create options to pass to the created resource. The default implementation set as option every property defined on the connector context, and add MDW_CONNECTOR_CONTEXT to give access to the context.

Parameters:
context - the context in which the connector runs
Returns:
the options to pass to the resource.

logError

protected void logError(ConnectorContext context,
                        Resource.Diagnostic error)
Logs the specified diagnostic to the registered logger.