|
Re: Creating a new Resource Type [message #1726716 is a reply to message #1726687] |
Tue, 15 March 2016 21:30 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Comments below.
On 16.03.2016 02:04, aurel pestell wrote:
> Hi,
>
> In my project I have the following code:
> ResourceSet resourceSet = new ResourceSetImpl();
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> new ExecutableFamiliesResponseGENResourceFactoryImpl());
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,
> new ExecutableFamiliesErrorResponseGENResourceFactoryImpl());
The replaces the previous registration in the map.
>
> resourceSet.getPackageRegistry().put(ExecutableFamiliesResponseGENPackage.eNS_URI,
> ExecutableFamiliesResponseGENPackage.eINSTANCE);
>
> resourceSet.getPackageRegistry().put(ExecutableFamiliesErrorResponseGENPackage.eNS_URI,
> ExecutableFamiliesErrorResponseGENPackage.eINSTANCE);
>
> InputSource inputSource = new InputSource(new
> StringReader(xmlContent));
> XMLResource resource = (XMLResource)
> resourceSet.createResource(URI.createFileURI("xml"));
This isn't going to work is it? You'll generally want an absolute file
system path as the argument for createFileURI.
> resource.load(inputSource, null);
>
> How does EMF decide what type will be "resource" ?
It has several ways, but you've only registered based on file extension
and only a default (and of course these can be only one default).
> Because my input can be either
> "ExecutableFamiliesResponseGENResourceFactory" or
> "ExecutableFamiliesErrorResponseGENResourceFactory".
>
> (Sorry I don't have a deep understanding of EMF so my question might
> sound stupid but I can't find a good explanation)
If you need to use different resource factories for resources with a
common extension, e.g., *.xml, you should make use of EMF's content type
support. E.g., set the content type identifier in the GenPackage, and
regenerate. Also try generating the *.tests project and look at the
XyzExample.java to see how it's used standalone. In an Eclipse
application you should not write code like the above because the
plugin.xml registrations are sufficient.
>
> Thank you.
>
> A.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
|
|
|
|
Re: Creating a new Resource Type [message #1726824 is a reply to message #1726809] |
Wed, 16 March 2016 16:43 |
aurel pestell Messages: 90 Registered: October 2013 Location: Sweden |
Member |
|
|
Using existing resource does not seem to work unfortunately.
This code:
XMLResource resource = (XMLResource) resourceSet.getResource(URI.createFileURI("C:\\yappclipse_2016_01_21\\yapp.capp.api\\resources\\fakeResponse.xml"), true);
gives me:
Quote:org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'null' not found.
Doing the registration does not help:
resourceSet.getResourceFactoryRegistry().getContentTypeToFactoryMap().put(ExecutableFamiliesResponseGENPackage.eCONTENT_TYPE, new ExecutableFamiliesResponseGENResourceFactoryImpl());
resourceSet.getURIConverter().getContentHandlers().add(new RootXMLContentHandlerImpl(ExecutableFamiliesResponseGENPackage.eCONTENT_TYPE, null, null, (String) null, null));
resourceSet.getResourceFactoryRegistry().getContentTypeToFactoryMap().put(ExecutableFamiliesErrorResponseGENPackage.eCONTENT_TYPE, new ExecutableFamiliesErrorResponseGENResourceFactoryImpl());
resourceSet.getURIConverter().getContentHandlers().add(new RootXMLContentHandlerImpl(ExecutableFamiliesErrorResponseGENPackage.eCONTENT_TYPE, null, null, (String) null, null));
|
|
|
Re: Creating a new Resource Type [message #1726856 is a reply to message #1726824] |
Thu, 17 March 2016 04:10 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Aurel,
I can of course only guess at your specific details, but it seems
evident that a non-namespace schema is involved. If more than one such
is involved, it seems evident that you can't use the namespace (null
namespace) to distinguish the two cases.
I also don't think the arguments to RootXMLContentHandlerImpl are all
that sensible. E.g., the argument for the extensions should mention xml
has an extension shouldn't it.
And again, the plugin.xml registrations should handle this. Why do you
need to do it manually/programmatically?
On 17.03.2016 00:43, aurel pestell wrote:
> Using existing resource does not seem to work unfortunately.
> This code:
>
> XMLResource resource = (XMLResource)
> resourceSet.getResource(URI.createFileURI("C:\\yappclipse_2016_01_21\\yapp.capp.api\\resources\\fakeResponse.xml"),
> true);
>
> gives me:
>
> Quote:
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
>> org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri
>> 'null' not found.
>
>
> Doing the registration does not help:
> resourceSet.getResourceFactoryRegistry().getContentTypeToFactoryMap().put(ExecutableFamiliesResponseGENPackage.eCONTENT_TYPE,
> new ExecutableFamiliesResponseGENResourceFactoryImpl());
> resourceSet.getURIConverter().getContentHandlers().add(new
> RootXMLContentHandlerImpl(ExecutableFamiliesResponseGENPackage.eCONTENT_TYPE,
> null, null, (String) null, null));
>
> resourceSet.getResourceFactoryRegistry().getContentTypeToFactoryMap().put(ExecutableFamiliesErrorResponseGENPackage.eCONTENT_TYPE,
> new ExecutableFamiliesErrorResponseGENResourceFactoryImpl());
> resourceSet.getURIConverter().getContentHandlers().add(new
> RootXMLContentHandlerImpl(ExecutableFamiliesErrorResponseGENPackage.eCONTENT_TYPE,
> null, null, (String) null, null));
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04015 seconds