Print an EObject ?

Posted by tul on Stack Overflow See other posts from Stack Overflow or by tul
Published on 2011-01-09T15:45:31Z Indexed on 2011/01/09 15:53 UTC
Read the original article Hit count: 184

Filed under:
|

I am writing some eclipse emf code and would like to print the content of an EObject (not store it to disk).

Here is what I try:

  public static void print(EObject obj) {
    Resource eResource = obj.eResource();
    try {
      eResource.save(System.out, null);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

but that gives a NullPointerException. I have tried this instead:

  public static void print(EObject obj) {
    ResourceSet resourceSet = new ResourceSetImpl();
    resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap()
        .put("*", new XMIResourceFactoryImpl());
    Resource resource = resourceSet.createResource(URI.createURI("dummyfile.xml"));
    resource.getContents().add(obj);
    try {
      resource.save(System.out, null);
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }

This works, but is it not possible to print to screen without specifying a dummy URI??

© Stack Overflow or respective owner

Related posts about eclipse

Related posts about emf

  • How to use EMF to read XML file?

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I have to use EMF in one of my class projects. I am trying to understand how to use EMF to do the following: Read XML, Get the values into objects. Use ORM to persist the values in objects to database. - Done Get data from database using ORM and generate XML. I need to do all of that using: EMF… >>> More

  • DPI for EMF files

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Do EMF files have a DPI that can be set? I have an application that allows saving an image in multiple formats (including EMF). I allow the user to specify the resolution/DPI for the image(s). However, I cannot find a way to do this for a MetaFile in C#. Is this possible or does EMF not have a DPI… >>> More

  • Recursion in Ecore-File?!

    as seen on Stack Overflow - Search for 'Stack Overflow'
    Hey guys, just tried to convert towards a Ecore-Model from a given UML-Model. After this I am trying to create a Generator Model. Everytime I try to do this I get the Error Message, that there is a "Unhandled event loop exception" with this log: org.eclipse.swt.SWTException: Failed to execute… >>> More

  • EMF to EPS Converter

    as seen on Super User - Search for 'Super User'
    I'm looking for (free) tools for converting images stored in EMF (Enhanced Metafile Format) format to EPS (Encapsulated Postscript). What features make your recommendation stand out? Edit: can you recommendation be used for batch processing? >>> More

  • AXway/tumbleweed EMF in exchange 2007

    as seen on Server Fault - Search for 'Server Fault'
    Looking for someone who has implemented an axway EMF recently. I'm about to implement an axway SM product for company wide email encryption. I current have an edge transport server and an exchange 2007 server. I want to route email like the follow: the edge picks up internet email to exchange and… >>> More