Skip to main content
IBM  
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : XML : Education - Tutorials
XML Schema Infoset Model, Part 1
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPrevious
Next Section
5. Working with XML Schema resources in Eclipse
  


XSDResourceFactory and XSDResource page 3 of 3


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.


Next Section
Main menuSection menuFeedbackPrevious
About IBM | Privacy | Legal | Contact