|
Re: loading of sub model element fails ? [message #420446 is a reply to message #420439] |
Mon, 30 June 2008 16:28 |
Ed Merks Messages: 33162 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------000107080503020806020508
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
SeB,
Comments below.
SeB.fr wrote:
> Hello,
> I am building an import/export feature in my RCP app in order to
> export/import single elements from my models.
> My model has a rootdocument containing a list containing Middlewares.
>
> here is how I serialize one Middleware
> Resource resource = new
> MiddlewaresResourceFactoryImpl().createResource(URI.createFi leURI(middlewareXmlFilePath.toOSString()));
> //$NON-NLS-1$
> //create a copy before adding it to the resource otherwise the
> middleware container (ep) would be removed as a parent of the
> middleware Middleware mCopy = (Middleware)
> crossReferencesCopy(middleware);
> resource.getContents().add(mCopy);
> resource.save(Collections.EMPTY_MAP);
>
> and here is the result : <?xml version="1.0" encoding="ASCII"?>
> <middlewares:Middleware
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:middlewares=" http:///com.nds.france.mhdk.middlewares.model/model/middlewa res.xsd"
> name="middleware fusion">
> <engine>
> <StbsRunParameters Version="1">
> <middlewares:Parameters
> xsi:type="middlewares:FusionParametersTypeV1" MiddlewareFamily="4097">
> <middlewares:InitProcessPath>Middlewares/middleware
> fusion1/vmmreg32.dll</middlewares:InitProcessPath>
> <middlewares:NdsFileSystemPath>Middlewares/middleware
> fusion1/nds file system</middlewares:NdsFileSystemPath>
> </middlewares:Parameters>
> </StbsRunParameters>
> </engine>
> </middlewares:Middleware>
>
> when I try to load this file using the following code I have an
> exception during the loading of the xml file.
> Resource middResource = new
> MiddlewaresResourceFactoryImpl().createResource(URI.createFi leURI(middlewareXmlFilePath.toOSString()));
>
> middResource.load(Collections.EMPTY_MAP);
> System.out.println(middResource.getContents().get(0));
>
> the above code throws
> org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature
> 'Middleware' not found.
> (file:/D:/snapshot/stbs%20avec%20espace/Middlewares/middlewa re%20fusion1/middleware%20fusion.middlewares,
> 2, 192)
>
> And I do not know why ? Do you see anything wrong in here.
If you have a model that's derived from a schema, the serialization must
conform to the schema. There's probably no root element named
"middleware" which is probably the name of the complex type. In order
to produce a valid serialization, it's important to create a
DocumentRoot instance for that schema and set the appropriate feature
that allows a Middleware instance. You might find this option useful as
an alternative approach to copying...
/**
* Write only the subtree starting at the specified list of EObjects,
* which must be objects contained by the resource.
*/
String OPTION_ROOT_OBJECTS = "ROOT_OBJECTS";
>
> SeB.
>
> PS : I have done that with another model and everything works fine
> this is why I am puzzled.
>
--------------000107080503020806020508
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
SeB,<br>
<br>
Comments below.<br>
<br>
SeB.fr wrote:
<blockquote
cite="mid:6d5c8859f7a921189c6e7bca35b064b8$1@www.eclipse.org"
type="cite">Hello,
<br>
I am building an import/export feature in my RCP app in order to
export/import single elements from my models.
<br>
My model has a rootdocument containing a list containing Middlewares.
<br>
<br>
here is how I serialize one Middleware
<br>
Resource resource = new
MiddlewaresResourceFactoryImpl().createResource(URI.createFi leURI(middlewareXmlFilePath.toOSString()));
//$NON-NLS-1$
<br>
//create a copy before adding it to the resource otherwise the
middleware container (ep) would be removed as a parent of the
middleware Middleware mCopy = (Middleware)
crossReferencesCopy(middleware);
<br>
resource.getContents().add(mCopy);
<br>
resource.save(Collections.EMPTY_MAP);
<br>
<br>
and here is the result : <?xml version="1.0" encoding="ASCII"?>
<br>
<middlewares:Middleware
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns:middlewares=<a class="moz-txt-link-rfc2396E" href=" http:///com.nds.france.mhdk.middlewares.model/model/middlewa res.xsd">" http:///com.nds.france.mhdk.middlewares.model/model/middlewa res.xsd"</a>
name="middleware fusion">
<br>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Re: loading of sub model element fails ? [message #420484 is a reply to message #420482] |
Tue, 01 July 2008 14:23 |
Ed Merks Messages: 33162 Registered: July 2009 |
Senior Member |
|
|
SeB,
Comments below.
SeB.fr wrote:
> Thanks Ed,
> as usual you made my day a little less sad.
And I did that on my Canada Day vacation no less. :-P
> The exception is solved.
> I still have trouble in what I want to acheive. that is import
> elements in my models.
> Actually I have 2 models and of course one referencing the other (not
> to make it simple ;)
> there is a Middlewares model holding a list of middleware(s) (base on
> a schema)
> and a ExecProfiles model holding a list of ExecProfile(s) each
> ExecProfile instance referencing a Middleware instance.
> I have 2 Resources into which I'd like to put both imported elements
> from xml files.
> So I load the ExecProfile xml and get an instance that reference proxy
> to a middleware.
> So What I need to do is to resolve the proxy and place both instance
> in my existing resources.
I noticed earlier snippets that you were creating resources that are not
in a resource set. You won't get cross resource references working with
that approach since proxy resolution relies on the resource set's
support for ResourceSet.getEObject.
>
> This does work(ish caus my model does not get dirty ???) at the first
> import but if I re-import it the EcoreUtil.Resolve does not resolve
> the middleware
> ------------------------------------------------------------ -----------
> final Middleware resolvedMiddleware = (Middleware)
> EcoreUtil.resolve(execProf.getMiddleware(), findModelMiddlewaresList());
>
> //add the middleware to the model and the exection profile as well
> TransactionalEditingDomain domain =
> TransactionalEditingDomain.Registry.INSTANCE.getEditingDomai n(MhdkCommons.MHDK_EDITING_DOMAIN_KEY);
>
> domain.getCommandStack().execute(new RecordingCommand(domain) {
> protected void doExecute() {
> findModelMiddlewaresList().getMiddleware().add(resolvedMiddl eware);
> execProf.setMiddleware(resolvedMiddleware);
> findModelExecutionProfileList().getList().add(execProf);
> }
> });
> ------------------------------------------------------------ ----------
> This would suggest my approach is not correct, what do I miss in those
> steps?
I expect that not using a resource set is the cause of your problem.
>
> Thank you.
>
> SeB.
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04194 seconds