Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Edapt] Own EDataType and Factory
[Edapt] Own EDataType and Factory [message #1647891] Tue, 03 March 2015 17:05 Go to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 244
Registered: July 2009
Senior Member
Hello,

I override the createFromString in the EFactory Methode to instantiate a own EDataType. But if Edapt load a resourceset and overrides the registered package and use instead of my efactory the normal EFactory and cannot instantiate the own EDataTyp


	public Foo  createFooObjectFromString(EDataType eDataType, String initialValue)
	{
		return new Foo(initialValue);
	}



ResourceSet for the Migrator

    private static class XMLResourceSetFactory implements IResourceSetFactory {

        @Override
        public ResourceSet createResourceSet() {
            ResourceSet resourceSet = new ResourceSetImpl();

            resourceSet.getPackageRegistry().put("OldPackageUri", ConfigPackage.eINSTANCE);

            resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
                    .put("xml", new ConfigResourceFactoryImpl());
            return resourceSet;
        }
    }


Edapt Code ResourceUtils:
		ResourceSet resourceSet = resourceSetFactory.createResourceSet();

		// Do not register ePackages if not set.
		if (ePackages != null)
			register(ePackages, resourceSet.getPackageRegistry());
...



	private static void register(List<EPackage> ePackages, Registry registry,
			Map<String, EPackage> backup) {
		for (EPackage p : ePackages) {
			String nsURI = p.getNsURI();
			EPackage old = (EPackage) registry.put(nsURI, p); --> override my package impl
			backup.put(nsURI, old);
			register(p.getESubpackages(), registry, backup);
		}
	}


How can i set the right (own) Factory for Edapt when the migrator loads the model?

Thanks

Dennis
Re: [Edapt] Own EDataType and Factory [message #1651518 is a reply to message #1647891] Thu, 05 March 2015 10:50 Go to previous messageGo to next message
Johannes Faltermeier is currently offline Johannes FaltermeierFriend
Messages: 68
Registered: December 2013
Member
Hi Dennis,

We added an extension point to register custom efactories for a specific ns-uris recently.
This should work for use case. You have to pay attention that the switch made in createFromString is not based on the classifierId however, because the ids might be different in the dynamic EPackage created by Edapt.

The extension point id is org.eclipse.emf.edapt.factories
   <extension
         point="org.eclipse.emf.edapt.factories">
      <factory
            class="org.example.MyEcoreFactory"
            nsURI="http://www.eclipse.org/emf/2002/Ecore">
      </factory>
   </extension>


Best regards
Johannes


Johannes Faltermeier

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: [Edapt] Own EDataType and Factory [message #1664528 is a reply to message #1651518] Tue, 10 March 2015 23:00 Go to previous messageGo to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 244
Registered: July 2009
Senior Member
ok thx Smile
Re: [Edapt] Own EDataType and Factory [message #1728466 is a reply to message #1664528] Mon, 04 April 2016 14:28 Go to previous messageGo to next message
Matthias Juchmes is currently offline Matthias JuchmesFriend
Messages: 22
Registered: March 2015
Junior Member
I registered my custom factory for my package and overrode createFromString so that it isn't based on the classifierId anymore. However, I now run into problems in other methods that rely on the classifier (e.g. create(EClass)). Is there a setting so that the generated code is not based on classifiers or do I have to override everything?
Re: [Edapt] Own EDataType and Factory [message #1728542 is a reply to message #1728466] Tue, 05 April 2016 10:07 Go to previous messageGo to next message
Johannes Faltermeier is currently offline Johannes FaltermeierFriend
Messages: 68
Registered: December 2013
Member
Hi,

if you extend EFactoryImpl to implement your custom factory and simply override createFromString/convertToString the default implementation of create(EClass) should only create DynamicEObjects. This code should not perform any switching on the classifier id, as far as I know. Could you share an example on how to reproduce this issue?

Thanks and regards
Johannes


Johannes Faltermeier

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: [Edapt] Own EDataType and Factory [message #1728545 is a reply to message #1647891] Tue, 05 April 2016 10:34 Go to previous messageGo to next message
Matthias Juchmes is currently offline Matthias JuchmesFriend
Messages: 22
Registered: March 2015
Junior Member
My model containes some datatypes FooObject and OtherObject. The generated code has a ModelFactoryImpl which extends EFactoryImpl and contains Methods like
@Override
	public Object createFromString(EDataType eDataType, String initialValue)
	{
		switch (eDataType.getClassifierID())
		{
			case ModelPackage.FOO_OBJECT:
				return createFooObjectFromString(eDataType, initialValue);
			case ModelPackage.OTHER_OBJECT:
				return createOtherObjectFromString(eDataType, initialValue);
			default:
				throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier"); //$NON-NLS-1$ //$NON-NLS-2$
		}
	}

	@Override
	public EObject create(EClass eClass)
	{
		switch (eClass.getClassifierID())
		{
			case ModelPackage.MY_CLASS: return createMyClass();
			case ModelPackage.MY_OTHER_CLASS: return createMyOtherClass();
			default:
				throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); //$NON-NLS-1$ //$NON-NLS-2$
		}
	}


My ModelFactoryImplCustom overrides the createFooObjectFromString method which is also needed during migration of other models, so I want to declare this one in the edapt.factories extension point. To make this work, I also need to override the other methods which use classifierIDs.

I could create another extension of EFactoryImpl (without extending ModelFactoryImpl) that also has the custom createFooObjectFromString implementation, but I would also need to override the createFromString here. But I'm not sure I see the benefit of having two different Factory implementations that essentially do the same thing.

So my question was if there is a setting so that the generated ModelFactoryImpl doesn't have the classifierID dependent code.
Re: [Edapt] Own EDataType and Factory [message #1728678 is a reply to message #1728545] Wed, 06 April 2016 11:59 Go to previous message
Johannes Faltermeier is currently offline Johannes FaltermeierFriend
Messages: 68
Registered: December 2013
Member
As far as I know there is no such EMF feature.

Johannes Faltermeier

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Previous Topic:[EMFStore] Creating a Workspace causes certificate path issues
Next Topic:[EMF Forms 1.7.2] Reference fields is not shown
Goto Forum:
  


Current Time: Fri Sep 22 17:17:06 GMT 2017

Powered by FUDForum. Page generated in 0.02050 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software