org.restlet.ext.emf
Class EmfRepresentation<T extends EObject>

java.lang.Object
  extended by org.restlet.representation.Variant
      extended by org.restlet.representation.RepresentationInfo
          extended by org.restlet.representation.Representation
              extended by org.restlet.representation.StreamRepresentation
                  extended by org.restlet.representation.OutputRepresentation
                      extended by org.restlet.ext.emf.EmfRepresentation<T>
Type Parameters:
T - The type to wrap.

public class EmfRepresentation<T extends EObject>
extends OutputRepresentation

Representation based on the EMF library. By default, it can serialize and deserialize automatically in either XML, XMI or ECore.

Author:
Jerome Louvel
See Also:
EMF project

Field Summary
 
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
EmfRepresentation(MediaType mediaType, T object)
          Constructor.
EmfRepresentation(Representation representation)
          Constructor.
 
Method Summary
protected  Resource createEmfResource(MediaType mediaType)
          Creates and configure an EMF resource.
protected  XMLResource createEmfXmlResource(MediaType mediaType)
          Creates and configure an EMF resource.
 int getLineWidth()
          Returns the maximum number of characters per line.
protected  Map<?,?> getLoadOptions()
          Returns the loading options.
 T getObject()
          Returns the wrapped object either parsed from the representation or to be formatted.
protected  Map<?,?> getSaveOptions()
          Returns the saving options.
 boolean isUsingEncodedAttributeStyle()
          Indicates if EMF references should be written as URI anchors.
 void setLineWidth(int lineWidth)
          Sets the maximum number of characters per line.
 void setUsingEncodedAttributeStyle(boolean usingEncodedAttributeStyle)
          Indicates if EMF references should be written as URI anchors.
 void write(EObject object, OutputStream outputStream)
          Writes the representation based on a given EMF object.
 void write(OutputStream outputStream)
          If this representation wraps an EObject, then it tries to write it as either XML, XMI or ECore/EMOF depending on the media type set.
 
Methods inherited from class org.restlet.representation.OutputRepresentation
getChannel, getStream
 
Methods inherited from class org.restlet.representation.StreamRepresentation
getReader, write, write
 
Methods inherited from class org.restlet.representation.Representation
append, exhaust, getAvailableSize, getDigest, getDisposition, getExpirationDate, getRange, getRegistration, getSize, getText, hasKnownSize, isAvailable, isEmpty, isSelectable, isTransient, release, setAvailable, setDigest, setDisposition, setExpirationDate, setListener, setRange, setSize, setTransient
 
Methods inherited from class org.restlet.representation.RepresentationInfo
getModificationDate, getTag, setModificationDate, setTag
 
Methods inherited from class org.restlet.representation.Variant
createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EmfRepresentation

public EmfRepresentation(MediaType mediaType,
                         T object)
Constructor.

Parameters:
mediaType - The target media type. Supported values are MediaType.APPLICATION_XMI, MediaType.APPLICATION_ECORE and XML media types.
object - The object to format.

EmfRepresentation

public EmfRepresentation(Representation representation)
Constructor.

Parameters:
representation - The representation to parse.
Method Detail

createEmfResource

protected Resource createEmfResource(MediaType mediaType)
Creates and configure an EMF resource. Not to be confused with a Restlet resource. By default, it calls createEmfXmlResource(MediaType).

Parameters:
mediaType - The associated media type.
Returns:
A new configured EMF resource.

createEmfXmlResource

protected XMLResource createEmfXmlResource(MediaType mediaType)
Creates and configure an EMF resource. Not to be confused with a Restlet resource.

Parameters:
mediaType - The associated media type (ECore, XMI or XML).
Returns:
A new configured EMF resource.

getLineWidth

public int getLineWidth()
Returns the maximum number of characters per line. Defaults to 80.

Returns:
The maximum number of characters per line.

getLoadOptions

protected Map<?,?> getLoadOptions()
Returns the loading options. Null by default.

Returns:
The loading options.

getObject

public T getObject()
                            throws IOException
Returns the wrapped object either parsed from the representation or to be formatted.

Returns:
The wrapped object.
Throws:
IOException

getSaveOptions

protected Map<?,?> getSaveOptions()
Returns the saving options. Null by default.

Returns:
The saving options.

isUsingEncodedAttributeStyle

public boolean isUsingEncodedAttributeStyle()
Indicates if EMF references should be written as URI anchors.

Returns:
True if EMF references should be written as URI anchors.

setLineWidth

public void setLineWidth(int lineWidth)
Sets the maximum number of characters per line.

Parameters:
lineWidth - The maximum number of characters per line.

setUsingEncodedAttributeStyle

public void setUsingEncodedAttributeStyle(boolean usingEncodedAttributeStyle)
Indicates if EMF references should be written as URI anchors.

Parameters:
usingEncodedAttributeStyle - True if EMF references should be written as URI anchors.

write

public void write(EObject object,
                  OutputStream outputStream)
           throws IOException
Writes the representation based on a given EMF object.

Parameters:
object - The EMF object to serialize.
outputStream - The target output stream.
Throws:
IOException

write

public void write(OutputStream outputStream)
           throws IOException
If this representation wraps an EObject, then it tries to write it as either XML, XMI or ECore/EMOF depending on the media type set. Note that in order to write this EObject, an EMF resource is created, configured for proper serialization and the EObject is then added to the content of this resource. This could has a side effect of removing it from a previous resource/container.

Specified by:
write in class Representation
Throws:
IOException


Copyright © 2005-2013 Restlet.