Ed,
Thanks for prompt and excellent advice, as always!
Here is a revised code fragment:
public class RulesResourceFactoryImpl extends XMIResourceFactoryImpl {
public static final String RULES_100_NS_URI =
"http://www.ibm.com/vce/1.0.0/rules";
public static final String RULES_PLATFORM_URI =
"platform:/plugin/com.ibm.adt.vce.rules.model/model/Rules.ecore";
public static final String RULES_100_PLATFORM_URI =
"platform:/plugin/com.ibm.adt.vce.rules.model/model/Rules100_2_Rules.ecore2xml";
private ExtendedMetaData extendedMetaData;
/* (non-Javadoc)
* @see
org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl#createResource(org.eclipse.emf.common.util.URI)
*/
public Resource createResource(URI uri) {
XMIResource resource = (XMIResource) super.createResource(uri);
Map defaultLoadOptions = resource.getDefaultLoadOptions();
defaultLoadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA,
getExtendedMetaData());
defaultLoadOptions.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE,
Boolean.TRUE);
defaultLoadOptions.put(XMLResource.OPTION_RESOURCE_HANDLER,
new RulesResourceHandler());
return resource;
}
private ExtendedMetaData getExtendedMetaData() {
if(extendedMetaData == null) {
ResourceSet resourceSet = new ResourceSetImpl();
EPackage.Registry ePackageRegistry =
resourceSet.getPackageRegistry();
ePackageRegistry.put(RULES_100_NS_URI,
RulesPackage.eINSTANCE);
ePackageRegistry.put(RULES_PLATFORM_URI,
RulesPackage.eINSTANCE);
resourceSet.setPackageRegistry(ePackageRegistry);
Ecore2XMLRegistry ecore2xmlRegistry = new
Ecore2XMLRegistryImpl(Ecore2XMLRegistry.INSTANCE);
ecore2xmlRegistry.put(RULES_100_NS_URI,
EcoreUtil.getObjectByType(
resourceSet.getResource(URI.createURI(RULES_100_PLATFORM_URI),
true).getContents(),
Ecore2XMLPackage.Literals.XML_MAP));
extendedMetaData = new
Ecore2XMLExtendedMetaData(EPackage.Registry.INSTANCE,
ecore2xmlRegistry);
}
return extendedMetaData;
}
}
If this passes muster, I can consider making a recipe of it. I found it
distressingly hard to get this far by reading the various newsgroup
articles and
the EclipseCon 2006 slides.
Thanks again,
Mike