[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Model Migration

I've figured out how to use the ecore2xml method for migrating a
serialized model from a prior version. I hacked the code into the
generated Editor.createModel() method to get the basic method working.
Now I want to refactor that code so the migration occurs no matter how
the model is loaded.

I think the right approach is to create and register a ResourceFactory.
I created a subclass of XMIResourceFactoryImpl and overrode
createResource(URI uri):

	public Resource createResource(URI uri) {
		EPackage.Registry ePackageRegistry = new EPackageRegistryImpl(EPackage.Registry.INSTANCE);
		ePackageRegistry.put("http://www.ibm.com/vce/1.0.0/rules";, RulesPackage.eINSTANCE);
		ePackageRegistry.put("platform:/plugin/com.ibm.adt.vce.rules.model/model/Rules.ecore", RulesPackage.eINSTANCE);
		ResourceSet resourceSet = new ResourceSetImpl();
		resourceSet.setPackageRegistry(ePackageRegistry);
		Ecore2XMLRegistry ecore2xmlRegistry = new Ecore2XMLRegistryImpl(Ecore2XMLRegistry.INSTANCE);
		ecore2xmlRegistry.put("http://www.ibm.com/vce/1.0.0/rules";,
				EcoreUtil.getObjectByType(
						resourceSet.getResource(URI.createURI("platform:/plugin/com.ibm.adt.vce.rules.model/model/Rules100_2_Rules.ecore2xml"),
								true).getContents(),
								Ecore2XMLPackage.Literals.XML_MAP));
		ExtendedMetaData extendedMetaData = new Ecore2XMLExtendedMetaData(EPackage.Registry.INSTANCE, ecore2xmlRegistry);
		Map defaultLoadOptions = resourceSet.getLoadOptions();
		defaultLoadOptions.put(XMLResource.OPTION_EXTENDED_META_DATA,
				extendedMetaData);
		defaultLoadOptions.put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE,
				Boolean.TRUE);
		defaultLoadOptions.put(XMLResource.OPTION_RESOURCE_HANDLER,
				new RulesResourceHandler());
		Resource resource = super.createResource(uri);
		
		return resource;
	}

It isn't working -- my resource handler never gets invoked and none of substitutions are made.

So, what is the best way to package this so the migration occurs whenever the resource is loaded?

Thanks,
Mike Gering