Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Loading Enum from other ecore file
Loading Enum from other ecore file [message #1234706] Wed, 22 January 2014 16:25 Go to next message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 244
Registered: July 2009
Senior Member
Hello,

i have one ecore with enums (states) and a other ecore uses the 1st ecore

so the enum in 1st ecore file is e.g.

State implements Enumerator

ACTIVE(0, "ACTIVE", "ACTIVE"),
INACTIVE(1, "INACTIVE", "INACTIVE");

the 2nd ecore file is e.g.

public class AImpl extends EObjectImpl implements A

State state;

Now i can save A, but i cannot load it:


public void saveModelWorks()
{
Resource resource = createResource();

A a = ...
a.setState(State.ACTIVE)
resource.getContents().add(a);
try
{
resource.save(Collections.EMPTY_MAP);
}
catch (IOException e)
{

}
}


public Master loadModelDoesntWork()
{
Resource resource = createResource();
try
{
resource.load(Collections.EMPTY_MAP);
}
catch (IOException e)
{
LOGGER.error("Error loading", e);
}

}
private Resource createResource()
{

final ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry()
.put(StateModelPackage.eNS_URI, StateModelPackage.eINSTANCE);

resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put("binary", new ResourceFactoryImpl()
{
@Override
public Resource createResource(URI uri)
{
return new BinaryResourceImpl(uri);
}
});

return resourceSet.createResource(URI.createFileURI("bla.binary"));
}

java.lang.IllegalArgumentException: The value 'ACTIVE' is invalid.
at org.eclipse.emf.ecore.impl.EFactoryImpl.createFromString(EFactoryImpl.java:471)
at AFactoryImpl.createEnumFromString(ModelFactoryImpl.java:227)

So what could i do?

Thanks
Re: Loading Enum from other ecore file [message #1240939 is a reply to message #1234706] Fri, 07 February 2014 08:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Comments below.

On 22/01/2014 5:25 PM, Sir Wayne wrote:
> Hello,
>
> i have one ecore with enums (states) and a other ecore uses the 1st ecore
>
> so the enum in 1st ecore file is e.g.
>
> State implements Enumerator
>
> ACTIVE(0, "ACTIVE", "ACTIVE"), INACTIVE(1, "INACTIVE",
> "INACTIVE");
> the 2nd ecore file is e.g.
>
> public class AImpl extends EObjectImpl implements A
>
> State state;
>
> Now i can save A, but i cannot load it:
>
>
> public void saveModelWorks()
> {
> Resource resource = createResource();
>
> A a = ...
> a.setState(State.ACTIVE)
> resource.getContents().add(a);
> try
> {
> resource.save(Collections.EMPTY_MAP);
> }
> catch (IOException e)
> {
> }
> }
>
>
> public Master loadModelDoesntWork()
> {
> Resource resource = createResource();
> try
> {
> resource.load(Collections.EMPTY_MAP);
> }
> catch (IOException e)
> {
> LOGGER.error("Error loading", e);
> }
>
> }
> private Resource createResource()
> {
>
> final ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getPackageRegistry()
> .put(StateModelPackage.eNS_URI,
> StateModelPackage.eINSTANCE);
>
> resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
> .put("binary", new ResourceFactoryImpl()
> {
> @Override
> public Resource createResource(URI uri)
> {
> return new BinaryResourceImpl(uri);
> }
> });
>
> return
> resourceSet.createResource(URI.createFileURI("bla.binary"));
> }
>
> java.lang.IllegalArgumentException: The value 'ACTIVE' is invalid.
> at
> org.eclipse.emf.ecore.impl.EFactoryImpl.createFromString(EFactoryImpl.java:471)
> at AFactoryImpl.createEnumFromString(ModelFactoryImpl.java:227)
>
> So what could i do?
Do you have an EDataType/EEnum called "Enum"? The method name
createEnumFromString appears to imply that's the case...
>
> Thanks


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Loading Enum from other ecore file [message #1274331 is a reply to message #1240939] Fri, 21 March 2014 10:01 Go to previous message
Dennis Melzer is currently offline Dennis MelzerFriend
Messages: 244
Registered: July 2009
Senior Member
Thanks for reply, after debbuging is saw my case doesn't work
Previous Topic:Editing maps in property sheets
Next Topic:EMF filter EList
Goto Forum:
  


Current Time: Thu Apr 25 07:58:54 GMT 2024

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

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

Back to the top