Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [geclipse-dev] parsing a string into a model

Hi Harald,

If it is possible for you to write this String into a regular Java file - this can be done. Here's the method from new JSDLJobDescription (IResource independent) class (not committed yet). It takes java.io.file and reads EMF model from it:

public void loadModel( final File file ) throws IOWrappedException {
    if( file.length() != 0 ) {
      //STEP 1: creation of EMF resource needed to load the EMF model
      String filePath = file.getAbsolutePath();
org.eclipse.emf.common.util.URI uri = org.eclipse.emf.common.util.URI.createFileURI( filePath );
      ResourceSet resourceSet = new ResourceSetImpl();
      Resource resourceA = resourceSet.createResource( uri );
      //STEP 2: setting EMF model options
      XMLMapImpl xmlmap = new XMLMapImpl();
      xmlmap.setNoNamespacePackage( JsdlPackage.eINSTANCE );
      Map<String, Object> options = new HashMap<String, Object>();
      options.put( XMLResource.OPTION_XML_MAP, xmlmap );
      options.put( XMLResource.OPTION_ENCODING, "UTF8" ); //$NON-NLS-1$
      try {
        //STEP 3: loading the EMF model
        resourceA.load( options );
        //STEP 4: accessing the EMF model (depends on your model)
this.documentRoot = ( DocumentRoot )resourceA.getContents().get( 0 );
        this.jobDefinition = this.documentRoot.getJobDefinition();
        this.jobDescription = this.jobDefinition.getJobDescription();
        this.jobIdentification = this.documentRoot.getJobIdentification();
      } catch( IOException ioEx ) {
        if( ioEx instanceof IOWrappedException ) {
          IOWrappedException ioWEx = ( IOWrappedException )ioEx;
          throw ioWEx;
        }
      }
    }
  }

Is this solution with java.io.file OK or do you need the one for not serialized String?

Cheers,
Kasia

On Thu, 25 Sep 2008 15:09:32 +0200, Harald Kornmayer <kornmayer@xxxxxxxxxxxx> wrote:

Hi all

I have the following problem:

1. I have a String representation of a XML document, which should be parsed
into a EMF model.

2. With EMF, I can get the model when opening an editor. For opening an
editor, I need a resource somewhere in the workspace. Based on the file
extension, the model will be created. This is managed via extension points.

Does anybody have an idea how to input a "string" into a EMF model?

Harald

==========================================
Dr. Harald Kornmayer
Senior researcher

NEC Laboratories Europe
IT Research Division
Rathausallee 10
D-53757 Sankt Augustin
Germany

Phone: +49 2241 92 52 57
Fax:   +49 2241 92 52 99
Email: harald.kornmayer@xxxxxxxxxxxx

NEC Europe Ltd., Registered Office: NEC House,
1 Victoria Road, London W3 6bL,
Registered in England 2832014
==========================================


_______________________________________________
geclipse-dev mailing list
geclipse-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/geclipse-dev




Back to the top