Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 327750

Summary: MWE2 Writer cannot handle models without feature "name"
Product: [Modeling] EMFT Reporter: Jens Von Pilgrim <developer>
Component: MWEAssignee: Project Inbox <emft-mwe-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3    
Version: 1.0.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Jens Von Pilgrim CLA 2010-10-14 06:11:40 EDT
org.eclipse.emf.mwe.utils.Writer throws a NullPointerException if the model to be saved does not have a feature "name", i.e. if model.eClass().getEStructuralFeature("name") returns null.

This problem can be solved in case of a single model/resource by adding a new attribute "modelName", which can then be configured in the workflow. In case of multiple models/resources, this does not work. But it may help if the feature name is configurable, e.g.

String nameFeature = "name"; // default is ok
public void setNameFeature(String i_nameFeature) {
	nameFeature = i_nameFeature;
}
protected String getName(final EObject model) {
	return (String) model.eGet(model.eClass().getEStructuralFeature(nameFeature));
}

In this context it would be nice to change the visibility of createResourceName and getName to protected, in order to simplify subclassing of the writer class (why are these methods declared private, anyway).

Related bugs (concerning Writer extension):
https://bugs.eclipse.org/bugs/show_bug.cgi?id=290733 
    Writer: Make encoding and file extension user configureable options
https://bugs.eclipse.org/bugs/show_bug.cgi?id=310077
    EType reference of EReference serialization, relative paths do not resolve into absolute ones

Jens