The Eclipse Modeling Framework loads resources by first
tying to find a ResourceFactory based on the file
extension of the file being loaded. This is done by
first looking in the
org.eclipse.emf.ecore.resource.Resource.Factory.Registry,
and if the extension is registered, then it uses that
ResourceFactory.
If the extension is not found, then the
default ResourceFactory is used. The default is
XMIResourceFactory, which clearly would
never load XML Schema models because XML Schema is not
written in XMI.
So, what do you do if you want to load a resource that
contains an XML Schema model that has an extension other
than "xsd"?
Globally register the extension using either of these methods:
- org.eclipse.emf.ecore.resource.Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().
put("myxsd", new
org.eclipse.xsd.util.XSDResourceFactoryImpl());
- Add the following extension point in your
plugin.xml file
<extension point =
"org.eclipse.emf.ecore.extension_parser">
<parser type="myxsd"
class="org.eclipse.xsd.util.XSDResourceFactoryImpl"/>
</extension>
or
Locally register the extension using this method:
-
org.eclipse.emf.ecore.resource.ResourceSet
resourceSet = new org.
eclipse.emf.ecore.resource.impl.ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().
put("myxsd", new
org.eclipse.xsd.util.XSDResourceFactoryImpl());
Then use the above resourceSet to load all of
your XML Schema files.