Home » Modeling » EMF » Deserialization and missing EMF packages
Deserialization and missing EMF packages [message #398136] |
Mon, 30 January 2006 08:53  |
Eclipse User |
|
|
|
Originally posted by: mblech.exa.unicen.edu.ar
Hello,
Is there a way to deserialize an EMF file for which you don't have all the
packages? Suppose the following scenario:
- Plugin A: GEF/EMF graphical editor
EMF package: editormodel
class editormodel.Diagram has an EMap feature called additionalData.
This plugin handles serialization/deserialization of diagram files.
- Plugin B: adds some dialogs to the editor in Plugin A
EMF package: editoradditionaldata
puts additional data into Diagram's additionalData feature
Now, imagine someone that only has Plugin A tries to open a file that was
created by someone that has both plugins. It would be desirable to warn
the user about the model elements that couldn't be deserialized, but still
let him open the diagram that's contained in the file. Is that possible?
|
|
| | | |
Re: Deserialization and missing EMF packages [message #398153 is a reply to message #398145] |
Mon, 30 January 2006 12:05   |
Eclipse User |
|
|
|
Originally posted by: mblech.exa.unicen.edu.ar
Ed,
I'm using 2.1. It seems the exception isn't ignored, because I get it when
I call resourceSet.getResource(uri, true). I tried the code sample you
provided, but I still get the IllegalArgumentException because it's not an
IOException. I added an IllegalArgumentException catch clause and ignored
it, but the loaded EMF model still has some missing features that have
nothing to do with the missing EMF packages. What should I do?
Ed Merks wrote:
> Martín,
> Are you using 2.2? I expect that EMF will try to load a package from
> that URI, but I'd also expect the exception to be ignored:
> try
> {
> InputStream inputStream =
> getURIConverter().createInputStream(trimmedURI);
> resource = resourceSet.createResource(trimmedURI);
> if (resource == null)
> {
> inputStream.close();
> }
> else
> {
> resource.load(inputStream, resourceSet.getLoadOptions());
> }
> }
> catch (IOException exception)
> {
> }
> Martín Blech wrote:
>> Ed,
>>
>> Thank you for the tip. Anyway, I'm still getting the following
>> exception when I call resourceSet.getResource():
>>
>> java.lang.IllegalArgumentException: protocol = http host = null
>> at sun.net.spi.DefaultProxySelector.select(Unknown Source)
>> at
>> sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unk nown Source)
>> at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown
>> Source)
>> at
>> sun.net.www.protocol.http.HttpURLConnection.getInputStream(U nknown
>> Source)
>> at
>>
org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createU RLInputStream(URIConverterImpl.java:557)
>>
>> at
>>
org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:446)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:1659)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:1553)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromTy peName(XMLHandler.java:1281)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHa ndler.java:1241)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLH andler.java:1081)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:466)
>>
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:65)
>>
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:449)
>>
>> at
>> org.eclipse.emf.ecore.xmi.impl.SAXWrapper.startElement(SAXWr apper.java:73)
>>
>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
>> Source)
>> at
>>
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(Unknown
>> Source)
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
>> Source)
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDispatcher.dispatch(Unknown
>> Source)
>> at
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
>> Source)
>> at
>> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
>> Source)
>> at
>> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
>> Source)
>> at
>> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
>> Source)
>> at
>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
>> Source)
>> at javax.xml.parsers.SAXParser.parse(Unknown Source)
>> at
>> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:140)
>> at
>>
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:169)
>>
>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:977)
>>
>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:832)
>>
>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:249)
>>
>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:264)
>>
>> at
>>
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:349)
>>
>> ..
>> It seems the deserializer is trying to find the .ecore file in the
>> generated "http:///package/package.ecore" nsURI. How can I stop it
>> from doing that?
>>
>> Ed Merks wrote:
>>
>>> Martín,
>>
>>
>>> There the option XMLResource.OPTION_RECORD_UNKNOWN_FEATURE you can
>>> use so that unrecognized data is recorded and can even be saved
>>> again. EMF also supports dynamic models, so even if you have the
>>> additional models available just as .ecore files, those could be used
>>> to process the data dynamically.
>>
>>
>>
>>> Martín Blech wrote:
>>
>>
>>>> Hello,
>>>>
>>>> Is there a way to deserialize an EMF file for which you don't have
>>>> all the packages? Suppose the following scenario:
>>>> - Plugin A: GEF/EMF graphical editor
>>>> EMF package: editormodel
>>>> class editormodel.Diagram has an EMap feature called
>>>> additionalData. This plugin handles serialization/deserialization of
>>>> diagram files.
>>>> - Plugin B: adds some dialogs to the editor in Plugin A
>>>> EMF package: editoradditionaldata
>>>> puts additional data into Diagram's additionalData feature
>>>>
>>>> Now, imagine someone that only has Plugin A tries to open a file
>>>> that was created by someone that has both plugins. It would be
>>>> desirable to warn the user about the model elements that couldn't be
>>>> deserialized, but still let him open the diagram that's contained in
>>>> the file. Is that possible?
>>>>
|
|
|
Re: Deserialization and missing EMF packages [message #398157 is a reply to message #398153] |
Mon, 30 January 2006 13:44   |
Eclipse User |
|
|
|
Martín,
It seems odd that the getInputStream method declares it will throw an
IOException, but then it throws a different one instead... You could
try defining a URI mapping ( resourceSet.getURIConverter().getURIMap())
from the package's nsURI to some URI that will throw an IOException when
accessed.
Martín Blech wrote:
> Ed,
>
> I'm using 2.1. It seems the exception isn't ignored, because I get it
> when I call resourceSet.getResource(uri, true). I tried the code
> sample you provided, but I still get the IllegalArgumentException
> because it's not an IOException. I added an IllegalArgumentException
> catch clause and ignored it, but the loaded EMF model still has some
> missing features that have nothing to do with the missing EMF
> packages. What should I do?
>
> Ed Merks wrote:
>
>> Martín,
>
>
>> Are you using 2.2? I expect that EMF will try to load a package from
>> that URI, but I'd also expect the exception to be ignored:
>
>
>> try
>> {
>> InputStream inputStream =
>> getURIConverter().createInputStream(trimmedURI);
>> resource = resourceSet.createResource(trimmedURI);
>> if (resource == null)
>> {
>> inputStream.close();
>> }
>> else
>> {
>> resource.load(inputStream,
>> resourceSet.getLoadOptions());
>> }
>> }
>> catch (IOException exception)
>> {
>> }
>
>
>
>
>> Martín Blech wrote:
>
>
>>> Ed,
>>>
>>> Thank you for the tip. Anyway, I'm still getting the following
>>> exception when I call resourceSet.getResource():
>>>
>>> java.lang.IllegalArgumentException: protocol = http host = null
>>> at sun.net.spi.DefaultProxySelector.select(Unknown Source)
>>> at
>>> sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unk nown
>>> Source)
>>> at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown
>>> Source)
>>> at
>>> sun.net.www.protocol.http.HttpURLConnection.getInputStream(U nknown
>>> Source)
>>> at
>>
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createU RLInputStream(URIConverterImpl.java:557)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:446)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:1659)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:1553)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromTy peName(XMLHandler.java:1281)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHa ndler.java:1241)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLH andler.java:1081)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:466)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:65)
>
>
>>>
>>> at
>>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:449)
>>>
>>> at
>>> org.eclipse.emf.ecore.xmi.impl.SAXWrapper.startElement(SAXWr apper.java:73)
>>>
>>> at
>>
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
>
>
>>> Source)
>>> at
>>
> com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(Unknown
>
>
>>> Source)
>>> at
>>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
>
>
>>> Source)
>>> at
>>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDispatcher.dispatch(Unknown
>
>
>>> Source)
>>> at
>>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
>
>
>>> Source)
>>> at
>>> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
>>> Source)
>>> at
>>> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
>>> Source)
>>> at
>>> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
>>> Source)
>>> at
>>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
>>> Source)
>>> at javax.xml.parsers.SAXParser.parse(Unknown Source)
>>> at
>>> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:140)
>>> at
>>
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:169)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:977)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:832)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:249)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:264)
>
>
>>>
>>> at
>>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:349)
>
>
>>>
>>> ..
>>> It seems the deserializer is trying to find the .ecore file in the
>>> generated "http:///package/package.ecore" nsURI. How can I stop it
>>> from doing that?
>>>
>>> Ed Merks wrote:
>>>
>>>> Martín,
>>>
>>>
>>>
>>>> There the option XMLResource.OPTION_RECORD_UNKNOWN_FEATURE you can
>>>> use so that unrecognized data is recorded and can even be saved
>>>> again. EMF also supports dynamic models, so even if you have the
>>>> additional models available just as .ecore files, those could be
>>>> used to process the data dynamically.
>>>
>>>
>>>
>>>
>>>> Martín Blech wrote:
>>>
>>>
>>>
>>>>> Hello,
>>>>>
>>>>> Is there a way to deserialize an EMF file for which you don't have
>>>>> all the packages? Suppose the following scenario:
>>>>> - Plugin A: GEF/EMF graphical editor
>>>>> EMF package: editormodel
>>>>> class editormodel.Diagram has an EMap feature called
>>>>> additionalData. This plugin handles serialization/deserialization
>>>>> of diagram files.
>>>>> - Plugin B: adds some dialogs to the editor in Plugin A
>>>>> EMF package: editoradditionaldata
>>>>> puts additional data into Diagram's additionalData feature
>>>>>
>>>>> Now, imagine someone that only has Plugin A tries to open a file
>>>>> that was created by someone that has both plugins. It would be
>>>>> desirable to warn the user about the model elements that couldn't
>>>>> be deserialized, but still let him open the diagram that's
>>>>> contained in the file. Is that possible?
>>>>>
>
|
|
|
Re: Deserialization and missing EMF packages [message #398166 is a reply to message #398157] |
Mon, 30 January 2006 14:44   |
Eclipse User |
|
|
|
Originally posted by: mblech.exa.unicen.edu.ar
Ed,
Effectively, getInputStream() only declares IOException. But
IllegalArgumentException is a runtime exception, so it can be thrown
anyway, and sun.net.spi.DefaultProxySelector.select(URI) does so when it's
called by sun.net.www.protocol.http.HttpURLConnection.plainConnect() with
host = null. The problem is that nothing seems to be handling that runtime
exception anywhere in the call stack from ResourceSetImpl.getResource(URI,
boolean) to the problematic ProxySelector. When I catch the exception in
my client code it's too late; from that point it seems impossible recover
from the error and continue parsing the XMI file.
This all might be a bug in Sun's HttpURLConnection or DefaultProxySelector
(runtime exceptions should be treated internally). Or maybe the bug is in
URIConverterImpl, because createURLInputStream(URI) assumes the URI is an
URL (the method's javadoc says it does). Anyway, some kind of workaround
will be needed.
What can I do? Should I report this in EMF's bugzilla?
The URI workaround you propose in your last message wouldn't work in my
scenario: I can't know in advance the nsURIs of all the EMF packages that
might eventually contribute additional data to my file. Or I got it wrong,
but please let me know.
Thanks a lot.
Ed Merks wrote:
> Martín,
> It seems odd that the getInputStream method declares it will throw an
> IOException, but then it throws a different one instead... You could
> try defining a URI mapping ( resourceSet.getURIConverter().getURIMap())
> from the package's nsURI to some URI that will throw an IOException when
> accessed.
> Martín Blech wrote:
>> Ed,
>>
>> I'm using 2.1. It seems the exception isn't ignored, because I get it
>> when I call resourceSet.getResource(uri, true). I tried the code
>> sample you provided, but I still get the IllegalArgumentException
>> because it's not an IOException. I added an IllegalArgumentException
>> catch clause and ignored it, but the loaded EMF model still has some
>> missing features that have nothing to do with the missing EMF
>> packages. What should I do?
>>
>> Ed Merks wrote:
>>
>>> Martín,
>>
>>
>>> Are you using 2.2? I expect that EMF will try to load a package from
>>> that URI, but I'd also expect the exception to be ignored:
>>
>>
>>> try
>>> {
>>> InputStream inputStream =
>>> getURIConverter().createInputStream(trimmedURI);
>>> resource = resourceSet.createResource(trimmedURI);
>>> if (resource == null)
>>> {
>>> inputStream.close();
>>> }
>>> else
>>> {
>>> resource.load(inputStream,
>>> resourceSet.getLoadOptions());
>>> }
>>> }
>>> catch (IOException exception)
>>> {
>>> }
>>
>>
>>
>>
>>> Martín Blech wrote:
>>
>>
>>>> Ed,
>>>>
>>>> Thank you for the tip. Anyway, I'm still getting the following
>>>> exception when I call resourceSet.getResource():
>>>>
>>>> java.lang.IllegalArgumentException: protocol = http host = null
>>>> at sun.net.spi.DefaultProxySelector.select(Unknown Source)
>>>> at
>>>> sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unk nown
>>>> Source)
>>>> at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown
>>>> Source)
>>>> at
>>>> sun.net.www.protocol.http.HttpURLConnection.getInputStream(U nknown
>>>> Source)
>>>> at
>>>
>>
org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createU RLInputStream(URIConverterImpl.java:557)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:446)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:1659)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:1553)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromTy peName(XMLHandler.java:1281)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHa ndler.java:1241)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLH andler.java:1081)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:466)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:65)
>>
>>
>>>>
>>>> at
>>>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:449)
>>>>
>>>> at
>>>>
org.eclipse.emf.ecore.xmi.impl.SAXWrapper.startElement(SAXWr apper.java:73)
>>>>
>>>> at
>>>
>>
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
>>
>>
>>>> Source)
>>>> at
>>>
>>
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(Unknown
>>
>>
>>>> Source)
>>>> at
>>>
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
>>
>>
>>>> Source)
>>>> at
>>>
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDispatcher.dispatch(Unknown
>>
>>
>>>> Source)
>>>> at
>>>
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
>>
>>
>>>> Source)
>>>> at
>>>>
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
>>>> Source)
>>>> at
>>>>
com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
>>>> Source)
>>>> at
>>>> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
>>>> Source)
>>>> at
>>>>
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
>>>> Source)
>>>> at javax.xml.parsers.SAXParser.parse(Unknown Source)
>>>> at
>>>> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:140)
>>>> at
>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:169)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:977)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:832)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:249)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:264)
>>
>>
>>>>
>>>> at
>>>
>>
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:349)
>>
>>
>>>>
>>>> ..
>>>> It seems the deserializer is trying to find the .ecore file in the
>>>> generated "http:///package/package.ecore" nsURI. How can I stop it
>>>> from doing that?
>>>>
>>>> Ed Merks wrote:
>>>>
>>>>> Martín,
>>>>
>>>>
>>>>
>>>>> There the option XMLResource.OPTION_RECORD_UNKNOWN_FEATURE you can
>>>>> use so that unrecognized data is recorded and can even be saved
>>>>> again. EMF also supports dynamic models, so even if you have the
>>>>> additional models available just as .ecore files, those could be
>>>>> used to process the data dynamically.
>>>>
>>>>
>>>>
>>>>
>>>>> Martín Blech wrote:
>>>>
>>>>
>>>>
>>>>>> Hello,
>>>>>>
>>>>>> Is there a way to deserialize an EMF file for which you don't have
>>>>>> all the packages? Suppose the following scenario:
>>>>>> - Plugin A: GEF/EMF graphical editor
>>>>>> EMF package: editormodel
>>>>>> class editormodel.Diagram has an EMap feature called
>>>>>> additionalData. This plugin handles serialization/deserialization
>>>>>> of diagram files.
>>>>>> - Plugin B: adds some dialogs to the editor in Plugin A
>>>>>> EMF package: editoradditionaldata
>>>>>> puts additional data into Diagram's additionalData feature
>>>>>>
>>>>>> Now, imagine someone that only has Plugin A tries to open a file
>>>>>> that was created by someone that has both plugins. It would be
>>>>>> desirable to warn the user about the model elements that couldn't
>>>>>> be deserialized, but still let him open the diagram that's
>>>>>> contained in the file. Is that possible?
>>>>>>
|
|
|
Re: Deserialization and missing EMF packages [message #398169 is a reply to message #398166] |
Mon, 30 January 2006 15:04   |
Eclipse User |
|
|
|
Martín,
We could change our code to handle this case too, so opening a bugzilla
is reasonable. But it still seems like bad behavior. Creating a bad
URL should just fail, but opening a stream on a URL that you managed to
create already should fail with a reasonable IOException describing the
reason for failing. Note that you can always create your own derived
URIConverterImpl to capture exception this lower down before the Handler
sees it...
Martín Blech wrote:
> Ed,
>
> Effectively, getInputStream() only declares IOException. But
> IllegalArgumentException is a runtime exception, so it can be thrown
> anyway, and sun.net.spi.DefaultProxySelector.select(URI) does so when
> it's called by
> sun.net.www.protocol.http.HttpURLConnection.plainConnect() with host =
> null. The problem is that nothing seems to be handling that runtime
> exception anywhere in the call stack from
> ResourceSetImpl.getResource(URI, boolean) to the problematic
> ProxySelector. When I catch the exception in my client code it's too
> late; from that point it seems impossible recover from the error and
> continue parsing the XMI file.
> This all might be a bug in Sun's HttpURLConnection or
> DefaultProxySelector (runtime exceptions should be treated
> internally). Or maybe the bug is in URIConverterImpl, because
> createURLInputStream(URI) assumes the URI is an URL (the method's
> javadoc says it does). Anyway, some kind of workaround will be needed.
> What can I do? Should I report this in EMF's bugzilla?
> The URI workaround you propose in your last message wouldn't work in
> my scenario: I can't know in advance the nsURIs of all the EMF
> packages that might eventually contribute additional data to my file.
> Or I got it wrong, but please let me know.
> Thanks a lot.
>
> Ed Merks wrote:
>
>> Martín,
>
>
>> It seems odd that the getInputStream method declares it will throw an
>> IOException, but then it throws a different one instead... You could
>> try defining a URI mapping (
>> resourceSet.getURIConverter().getURIMap()) from the package's nsURI
>> to some URI that will throw an IOException when accessed.
>
>
>
>> Martín Blech wrote:
>
>
>>> Ed,
>>>
>>> I'm using 2.1. It seems the exception isn't ignored, because I get
>>> it when I call resourceSet.getResource(uri, true). I tried the code
>>> sample you provided, but I still get the IllegalArgumentException
>>> because it's not an IOException. I added an IllegalArgumentException
>>> catch clause and ignored it, but the loaded EMF model still has some
>>> missing features that have nothing to do with the missing EMF
>>> packages. What should I do?
>>>
>>> Ed Merks wrote:
>>>
>>>> Martín,
>>>
>>>
>>>
>>>> Are you using 2.2? I expect that EMF will try to load a package
>>>> from that URI, but I'd also expect the exception to be ignored:
>>>
>>>
>>>
>>>> try
>>>> {
>>>> InputStream inputStream =
>>>> getURIConverter().createInputStream(trimmedURI);
>>>> resource = resourceSet.createResource(trimmedURI);
>>>> if (resource == null)
>>>> {
>>>> inputStream.close();
>>>> }
>>>> else
>>>> {
>>>> resource.load(inputStream,
>>>> resourceSet.getLoadOptions());
>>>> }
>>>> }
>>>> catch (IOException exception)
>>>> {
>>>> }
>>>
>>>
>>>
>>>
>>>
>>>> Martín Blech wrote:
>>>
>>>
>>>
>>>>> Ed,
>>>>>
>>>>> Thank you for the tip. Anyway, I'm still getting the following
>>>>> exception when I call resourceSet.getResource():
>>>>>
>>>>> java.lang.IllegalArgumentException: protocol = http host = null
>>>>> at sun.net.spi.DefaultProxySelector.select(Unknown Source)
>>>>> at
>>>>> sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unk nown
>>>>> Source)
>>>>> at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown
>>>>> Source)
>>>>> at
>>>>> sun.net.www.protocol.http.HttpURLConnection.getInputStream(U nknown
>>>>> Source)
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createU RLInputStream(URIConverterImpl.java:557)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:446)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:1659)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:1553)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromTy peName(XMLHandler.java:1281)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHa ndler.java:1241)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLH andler.java:1081)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:466)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:65)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:449)
>
>
>>>>>
>>>>> at
>>>>
> org.eclipse.emf.ecore.xmi.impl.SAXWrapper.startElement(SAXWr apper.java:73)
>
>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
>
>
>>>
>>>
>>>>> Source)
>>>>> at
>>>>
>>>>
>>>
> com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(Unknown
>
>
>>>
>>>
>>>>> Source)
>>>>> at
>>>>
>>>>
>>>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
>
>
>>>
>>>
>>>>> Source)
>>>>> at
>>>>
>>>>
>>>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDispatcher.dispatch(Unknown
>
>
>>>
>>>
>>>>> Source)
>>>>> at
>>>>
>>>>
>>>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
>
>
>>>
>>>
>>>>> Source)
>>>>> at
>>>>
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
>
>
>>>>> Source)
>>>>> at
>>>>
> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
>
>
>>>>> Source)
>>>>> at
>>>>> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
>>>>> Source)
>>>>> at
>>>>
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
>
>
>>>>> Source)
>>>>> at javax.xml.parsers.SAXParser.parse(Unknown Source)
>>>>> at
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:140)
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:169)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:977)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:832)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:249)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:264)
>
>
>>>
>>>
>>>>>
>>>>> at
>>>>
>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:349)
>
>
>>>
>>>
>>>>>
>>>>> ..
>>>>> It seems the deserializer is trying to find the .ecore file in the
>>>>> generated "http:///package/package.ecore" nsURI. How can I stop it
>>>>> from doing that?
>>>>>
>>>>> Ed Merks wrote:
>>>>>
>>>>>> Martín,
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> There the option XMLResource.OPTION_RECORD_UNKNOWN_FEATURE you
>>>>>> can use so that unrecognized data is recorded and can even be
>>>>>> saved again. EMF also supports dynamic models, so even if you
>>>>>> have the additional models available just as .ecore files, those
>>>>>> could be used to process the data dynamically.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> Martín Blech wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> Is there a way to deserialize an EMF file for which you don't
>>>>>>> have all the packages? Suppose the following scenario:
>>>>>>> - Plugin A: GEF/EMF graphical editor
>>>>>>> EMF package: editormodel
>>>>>>> class editormodel.Diagram has an EMap feature called
>>>>>>> additionalData. This plugin handles
>>>>>>> serialization/deserialization of diagram files.
>>>>>>> - Plugin B: adds some dialogs to the editor in Plugin A
>>>>>>> EMF package: editoradditionaldata
>>>>>>> puts additional data into Diagram's additionalData feature
>>>>>>>
>>>>>>> Now, imagine someone that only has Plugin A tries to open a file
>>>>>>> that was created by someone that has both plugins. It would be
>>>>>>> desirable to warn the user about the model elements that
>>>>>>> couldn't be deserialized, but still let him open the diagram
>>>>>>> that's contained in the file. Is that possible?
>>>>>>>
>
|
|
|
Re: Deserialization and missing EMF packages [message #398235 is a reply to message #398169] |
Mon, 30 January 2006 16:00   |
Eclipse User |
|
|
|
Originally posted by: mblech.exa.unicen.edu.ar
Ed,
I managed to make it work using the following workaround URIConverterImpl:
public class WorkaroundURIConverter extends URIConverterImpl {
protected InputStream createURLInputStream(URI uri) throws IOException {
URL url = new URL(uri.toString());
if (url.getHost() == null || url.getHost().trim().equals(""))
throw new IOException("http host can't be null");
else
return super.createURLInputStream(uri);
}
}
If I set an instance of this class to the ResourceSet before calling
getResource, everything works fine. I agree with you, it seems like bad
behavior; an IOException would be much more reasonable.
Now, going back to your first reply, you said "There the option
XMLResource.OPTION_RECORD_UNKNOWN_FEATURE you can use so that unrecognized
data is recorded and can even be saved again". How can I make the "be
saved again" part work?
Ed Merks wrote:
> Martín,
> We could change our code to handle this case too, so opening a bugzilla
> is reasonable. But it still seems like bad behavior. Creating a bad
> URL should just fail, but opening a stream on a URL that you managed to
> create already should fail with a reasonable IOException describing the
> reason for failing. Note that you can always create your own derived
> URIConverterImpl to capture exception this lower down before the Handler
> sees it...
> Martín Blech wrote:
>> Ed,
>>
>> Effectively, getInputStream() only declares IOException. But
>> IllegalArgumentException is a runtime exception, so it can be thrown
>> anyway, and sun.net.spi.DefaultProxySelector.select(URI) does so when
>> it's called by
>> sun.net.www.protocol.http.HttpURLConnection.plainConnect() with host =
>> null. The problem is that nothing seems to be handling that runtime
>> exception anywhere in the call stack from
>> ResourceSetImpl.getResource(URI, boolean) to the problematic
>> ProxySelector. When I catch the exception in my client code it's too
>> late; from that point it seems impossible recover from the error and
>> continue parsing the XMI file.
>> This all might be a bug in Sun's HttpURLConnection or
>> DefaultProxySelector (runtime exceptions should be treated
>> internally). Or maybe the bug is in URIConverterImpl, because
>> createURLInputStream(URI) assumes the URI is an URL (the method's
>> javadoc says it does). Anyway, some kind of workaround will be needed.
>> What can I do? Should I report this in EMF's bugzilla?
>> The URI workaround you propose in your last message wouldn't work in
>> my scenario: I can't know in advance the nsURIs of all the EMF
>> packages that might eventually contribute additional data to my file.
>> Or I got it wrong, but please let me know.
>> Thanks a lot.
>>
>> Ed Merks wrote:
>>
>>> Martín,
>>
>>
>>> It seems odd that the getInputStream method declares it will throw an
>>> IOException, but then it throws a different one instead... You could
>>> try defining a URI mapping (
>>> resourceSet.getURIConverter().getURIMap()) from the package's nsURI
>>> to some URI that will throw an IOException when accessed.
>>
>>
>>
>>> Martín Blech wrote:
>>
>>
>>>> Ed,
>>>>
>>>> I'm using 2.1. It seems the exception isn't ignored, because I get
>>>> it when I call resourceSet.getResource(uri, true). I tried the code
>>>> sample you provided, but I still get the IllegalArgumentException
>>>> because it's not an IOException. I added an IllegalArgumentException
>>>> catch clause and ignored it, but the loaded EMF model still has some
>>>> missing features that have nothing to do with the missing EMF
>>>> packages. What should I do?
>>>>
>>>> Ed Merks wrote:
>>>>
>>>>> Martín,
>>>>
>>>>
>>>>
>>>>> Are you using 2.2? I expect that EMF will try to load a package
>>>>> from that URI, but I'd also expect the exception to be ignored:
>>>>
>>>>
>>>>
>>>>> try
>>>>> {
>>>>> InputStream inputStream =
>>>>> getURIConverter().createInputStream(trimmedURI);
>>>>> resource = resourceSet.createResource(trimmedURI);
>>>>> if (resource == null)
>>>>> {
>>>>> inputStream.close();
>>>>> }
>>>>> else
>>>>> {
>>>>> resource.load(inputStream,
>>>>> resourceSet.getLoadOptions());
>>>>> }
>>>>> }
>>>>> catch (IOException exception)
>>>>> {
>>>>> }
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>> Martín Blech wrote:
>>>>
>>>>
>>>>
>>>>>> Ed,
>>>>>>
>>>>>> Thank you for the tip. Anyway, I'm still getting the following
>>>>>> exception when I call resourceSet.getResource():
>>>>>>
>>>>>> java.lang.IllegalArgumentException: protocol = http host = null
>>>>>> at sun.net.spi.DefaultProxySelector.select(Unknown Source)
>>>>>> at
>>>>>> sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unk nown
>>>>>> Source)
>>>>>> at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown
>>>>>> Source)
>>>>>> at
>>>>>> sun.net.www.protocol.http.HttpURLConnection.getInputStream(U nknown
>>>>>> Source)
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createU RLInputStream(URIConverterImpl.java:557)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:446)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:1659)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:1553)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromTy peName(XMLHandler.java:1281)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHa ndler.java:1241)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLH andler.java:1081)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:466)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:65)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:449)
>>
>>
>>>>>>
>>>>>> at
>>>>>
>> org.eclipse.emf.ecore.xmi.impl.SAXWrapper.startElement(SAXWr apper.java:73)
>>
>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
>>
>>
>>>>
>>>>
>>>>>> Source)
>>>>>> at
>>>>>
>>>>>
>>>>
>>
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(Unknown
>>
>>
>>>>
>>>>
>>>>>> Source)
>>>>>> at
>>>>>
>>>>>
>>>>
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
>>
>>
>>>>
>>>>
>>>>>> Source)
>>>>>> at
>>>>>
>>>>>
>>>>
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDispatcher.dispatch(Unknown
>>
>>
>>>>
>>>>
>>>>>> Source)
>>>>>> at
>>>>>
>>>>>
>>>>
>>
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
>>
>>
>>>>
>>>>
>>>>>> Source)
>>>>>> at
>>>>>
>> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
>>
>>
>>>>>> Source)
>>>>>> at
>>>>>
>> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
>>
>>
>>>>>> Source)
>>>>>> at
>>>>>> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
>>>>>> Source)
>>>>>> at
>>>>>
>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
>>
>>
>>>>>> Source)
>>>>>> at javax.xml.parsers.SAXParser.parse(Unknown Source)
>>>>>> at
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:140)
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:169)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:977)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:832)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:249)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:264)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> at
>>>>>
>>>>>
>>>>
>>
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:349)
>>
>>
>>>>
>>>>
>>>>>>
>>>>>> ..
>>>>>> It seems the deserializer is trying to find the .ecore file in the
>>>>>> generated "http:///package/package.ecore" nsURI. How can I stop it
>>>>>> from doing that?
>>>>>>
>>>>>> Ed Merks wrote:
>>>>>>
>>>>>>> Martín,
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>> There the option XMLResource.OPTION_RECORD_UNKNOWN_FEATURE you
>>>>>>> can use so that unrecognized data is recorded and can even be
>>>>>>> saved again. EMF also supports dynamic models, so even if you
>>>>>>> have the additional models available just as .ecore files, those
>>>>>>> could be used to process the data dynamically.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>> Martín Blech wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> Is there a way to deserialize an EMF file for which you don't
>>>>>>>> have all the packages? Suppose the following scenario:
>>>>>>>> - Plugin A: GEF/EMF graphical editor
>>>>>>>> EMF package: editormodel
>>>>>>>> class editormodel.Diagram has an EMap feature called
>>>>>>>> additionalData. This plugin handles
>>>>>>>> serialization/deserialization of diagram files.
>>>>>>>> - Plugin B: adds some dialogs to the editor in Plugin A
>>>>>>>> EMF package: editoradditionaldata
>>>>>>>> puts additional data into Diagram's additionalData feature
>>>>>>>>
>>>>>>>> Now, imagine someone that only has Plugin A tries to open a file
>>>>>>>> that was created by someone that has both plugins. It would be
>>>>>>>> desirable to warn the user about the model elements that
>>>>>>>> couldn't be deserialized, but still let him open the diagram
>>>>>>>> that's contained in the file. Is that possible?
>>>>>>>>
>>
|
|
|
Re: Deserialization and missing EMF packages [message #398237 is a reply to message #398235] |
Mon, 30 January 2006 16:04  |
Eclipse User |
|
|
|
Martín,
The information is cached in XMLResource.getEObjectToExtensionMap() and
it should just be saved if that map is populated.
Martín Blech wrote:
> Ed,
>
> I managed to make it work using the following workaround
> URIConverterImpl:
> public class WorkaroundURIConverter extends URIConverterImpl {
> protected InputStream createURLInputStream(URI uri) throws
> IOException {
> URL url = new URL(uri.toString());
> if (url.getHost() == null || url.getHost().trim().equals(""))
> throw new IOException("http host can't be null");
> else
> return super.createURLInputStream(uri);
> }
> }
> If I set an instance of this class to the ResourceSet before calling
> getResource, everything works fine. I agree with you, it seems like
> bad behavior; an IOException would be much more reasonable.
> Now, going back to your first reply, you said "There the option
> XMLResource.OPTION_RECORD_UNKNOWN_FEATURE you can use so that
> unrecognized data is recorded and can even be saved again". How can I
> make the "be saved again" part work?
>
> Ed Merks wrote:
>
>> Martín,
>
>
>> We could change our code to handle this case too, so opening a
>> bugzilla is reasonable. But it still seems like bad behavior.
>> Creating a bad URL should just fail, but opening a stream on a URL
>> that you managed to create already should fail with a reasonable
>> IOException describing the reason for failing. Note that you can
>> always create your own derived URIConverterImpl to capture exception
>> this lower down before the Handler sees it...
>
>
>
>> Martín Blech wrote:
>
>
>>> Ed,
>>>
>>> Effectively, getInputStream() only declares IOException. But
>>> IllegalArgumentException is a runtime exception, so it can be thrown
>>> anyway, and sun.net.spi.DefaultProxySelector.select(URI) does so
>>> when it's called by
>>> sun.net.www.protocol.http.HttpURLConnection.plainConnect() with host
>>> = null. The problem is that nothing seems to be handling that
>>> runtime exception anywhere in the call stack from
>>> ResourceSetImpl.getResource(URI, boolean) to the problematic
>>> ProxySelector. When I catch the exception in my client code it's too
>>> late; from that point it seems impossible recover from the error and
>>> continue parsing the XMI file.
>>> This all might be a bug in Sun's HttpURLConnection or
>>> DefaultProxySelector (runtime exceptions should be treated
>>> internally). Or maybe the bug is in URIConverterImpl, because
>>> createURLInputStream(URI) assumes the URI is an URL (the method's
>>> javadoc says it does). Anyway, some kind of workaround will be needed.
>>> What can I do? Should I report this in EMF's bugzilla?
>>> The URI workaround you propose in your last message wouldn't work in
>>> my scenario: I can't know in advance the nsURIs of all the EMF
>>> packages that might eventually contribute additional data to my
>>> file. Or I got it wrong, but please let me know.
>>> Thanks a lot.
>>>
>>> Ed Merks wrote:
>>>
>>>> Martín,
>>>
>>>
>>>
>>>> It seems odd that the getInputStream method declares it will throw
>>>> an IOException, but then it throws a different one instead... You
>>>> could try defining a URI mapping (
>>>> resourceSet.getURIConverter().getURIMap()) from the package's nsURI
>>>> to some URI that will throw an IOException when accessed.
>>>
>>>
>>>
>>>
>>>> Martín Blech wrote:
>>>
>>>
>>>
>>>>> Ed,
>>>>>
>>>>> I'm using 2.1. It seems the exception isn't ignored, because I get
>>>>> it when I call resourceSet.getResource(uri, true). I tried the
>>>>> code sample you provided, but I still get the
>>>>> IllegalArgumentException because it's not an IOException. I added
>>>>> an IllegalArgumentException catch clause and ignored it, but the
>>>>> loaded EMF model still has some missing features that have nothing
>>>>> to do with the missing EMF packages. What should I do?
>>>>>
>>>>> Ed Merks wrote:
>>>>>
>>>>>> Martín,
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> Are you using 2.2? I expect that EMF will try to load a package
>>>>>> from that URI, but I'd also expect the exception to be ignored:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> try
>>>>>> {
>>>>>> InputStream inputStream =
>>>>>> getURIConverter().createInputStream(trimmedURI);
>>>>>> resource = resourceSet.createResource(trimmedURI);
>>>>>> if (resource == null)
>>>>>> {
>>>>>> inputStream.close();
>>>>>> }
>>>>>> else
>>>>>> {
>>>>>> resource.load(inputStream,
>>>>>> resourceSet.getLoadOptions());
>>>>>> }
>>>>>> }
>>>>>> catch (IOException exception)
>>>>>> {
>>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> Martín Blech wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>> Ed,
>>>>>>>
>>>>>>> Thank you for the tip. Anyway, I'm still getting the following
>>>>>>> exception when I call resourceSet.getResource():
>>>>>>>
>>>>>>> java.lang.IllegalArgumentException: protocol = http host = null
>>>>>>> at sun.net.spi.DefaultProxySelector.select(Unknown Source)
>>>>>>> at
>>>>>>> sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unk nown
>>>>>>> Source)
>>>>>>> at
>>>>>>> sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
>>>>>>> at
>>>>>>> sun.net.www.protocol.http.HttpURLConnection.getInputStream(U nknown
>>>>>>> Source)
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createU RLInputStream(URIConverterImpl.java:557)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.URIConverterImpl.createI nputStream(URIConverterImpl.java:446)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI(X MLHandler.java:1659)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.getFactoryForPrefi x(XMLHandler.java:1553)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromTy peName(XMLHandler.java:1281)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHa ndler.java:1241)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLH andler.java:1081)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XML Handler.java:466)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMI Handler.java:65)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>> org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHa ndler.java:449)
>>>
>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>> org.eclipse.emf.ecore.xmi.impl.SAXWrapper.startElement(SAXWr apper.java:73)
>>>
>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .startElement(Unknown
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>> Source)
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocume ntParser.emptyElement(Unknown
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>> Source)
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanStartElement(Unknown
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>> Source)
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl$FragmentContentDispatcher.dispatch(Unknown
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>> Source)
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentS cannerImpl.scanDocument(Unknown
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>> Source)
>>>>>>> at
>>>>>>
>>>>>>
>>> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
>>>
>>>
>>>>>>> Source)
>>>>>>> at
>>>>>>
>>>>>>
>>> com.sun.org.apache.xerces.internal.parsers.XML11Configuratio n.parse(Unknown
>>>
>>>
>>>>>>> Source)
>>>>>>> at
>>>>>>> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(U nknown
>>>>>>> Source)
>>>>>>> at
>>>>>>
>>>>>>
>>> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser .parse(Unknown
>>>
>>>
>>>>>>> Source)
>>>>>>> at javax.xml.parsers.SAXParser.parse(Unknown Source)
>>>>>>> at
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:140)
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:169)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:977)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:832)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo ad(ResourceSetImpl.java:249)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLo adHelper(ResourceSetImpl.java:264)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> at
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResou rce(ResourceSetImpl.java:349)
>
>
>>>
>>>
>>>>>
>>>>>
>>>>>>>
>>>>>>> ..
>>>>>>> It seems the deserializer is trying to find the .ecore file in
>>>>>>> the generated "http:///package/package.ecore" nsURI. How can I
>>>>>>> stop it from doing that?
>>>>>>>
>>>>>>> Ed Merks wrote:
>>>>>>>
>>>>>>>> Martín,
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> There the option XMLResource.OPTION_RECORD_UNKNOWN_FEATURE you
>>>>>>>> can use so that unrecognized data is recorded and can even be
>>>>>>>> saved again. EMF also supports dynamic models, so even if you
>>>>>>>> have the additional models available just as .ecore files,
>>>>>>>> those could be used to process the data dynamically.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> Martín Blech wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>> Hello,
>>>>>>>>>
>>>>>>>>> Is there a way to deserialize an EMF file for which you don't
>>>>>>>>> have all the packages? Suppose the following scenario:
>>>>>>>>> - Plugin A: GEF/EMF graphical editor
>>>>>>>>> EMF package: editormodel
>>>>>>>>> class editormodel.Diagram has an EMap feature called
>>>>>>>>> additionalData. This plugin handles
>>>>>>>>> serialization/deserialization of diagram files.
>>>>>>>>> - Plugin B: adds some dialogs to the editor in Plugin A
>>>>>>>>> EMF package: editoradditionaldata
>>>>>>>>> puts additional data into Diagram's additionalData feature
>>>>>>>>>
>>>>>>>>> Now, imagine someone that only has Plugin A tries to open a
>>>>>>>>> file that was created by someone that has both plugins. It
>>>>>>>>> would be desirable to warn the user about the model elements
>>>>>>>>> that couldn't be deserialized, but still let him open the
>>>>>>>>> diagram that's contained in the file. Is that possible?
>>>>>>>>>
>>>
>
|
|
|
Goto Forum:
Current Time: Tue Sep 23 16:52:07 EDT 2025
Powered by FUDForum. Page generated in 0.05398 seconds
|