Home » Modeling » EMF » NullPointerException in XMLSaveImpl.saveDataTypeMany
NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423245] |
Thu, 25 September 2008 12:36 |
ronald Mising name Messages: 52 Registered: July 2009 |
Member |
|
|
This error comes up when I run the XYZExample test code, disguised as/copied to a UnitTest in maven. (ie outside the eclipse editor).
It runs fine from within eclipse/junit. I figured it must have something to do with
http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
does it?
The error is
java.lang.NullPointerException
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
Code:
MyModel1Package.eINSTANCE.eClass();
MyModel2Package.eINSTANCE.eClass();
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
("ext1", new MyModel1ResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
(Resource.Factory.Registry.DEFAULT_EXTENSION,
new MyModel2ResourceFactoryImpl());
Resource resource = resourceSet.createResource(URI.createURI("http:///My.model.uri"));
DocumentRoot documentRoot = MyModel2Factory.eINSTANCE.createDocumentRoot();
// ---- Removing the next two lines makes it work from maven too.
ActivitiesType root = MyModel2Factory.eINSTANCE.createActivitiesType();
documentRoot.setActivities(root);
resource.getContents().add(documentRoot);
resource.save(System.out, null);
Many thanks,
Ronaldo
Ed Merks wrote:
> Ronaldo,
>
> Comments below.
>
> Ronaldo wrote:
>> Hi Ed,
>>
>> Thanks for the quick answer. Yes, I have 2 models in 2 different
>> eclipse projects.
>> They both use a null target namespace, in order to eliminate the
>> prefixes in the xml.
> :-(
>
> XML documents with at least a namespace for the root element are
> generally more consumable because they identify their schema...
>>
>> I was just wondering what (which setting) causes the code
>>
>> result.getDefaultSaveOptions().put(
>> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
> A null target namespace schema produces an annotation on the EPackage to
> indicate the package is not qualified.
>>
>> to be generated. (as opposed to
>>
>> result.getDefaultSaveOptions().put(
>> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
> This package doesn't have such an annotation.
>
> Note that you can't have two different packages that both want to be the
> one for the null namespace both working at the same time.
>> )
>>
>> Ronaldo
|
|
|
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423246 is a reply to message #423245] |
Thu, 25 September 2008 13:01 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Ronaldo wrote:
> This error comes up when I run the XYZExample test code, disguised
> as/copied to a UnitTest in maven. (ie outside the eclipse editor).
> It runs fine from within eclipse/junit. I figured it must have
> something to do with
> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>
> does it?
>
> The error is
>
> java.lang.NullPointerException
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>
It's dying because the data type doesn't have a containing package and
hence we get a null pointer exception trying to get the factory for that
package?
EDataType d = (EDataType)f.getEType();
EPackage ePackage = d.getEPackage();
EFactory fac = ePackage.getEFactoryInstance();
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>
>
> Code:
>
> MyModel1Package.eINSTANCE.eClass();
> MyModel2Package.eINSTANCE.eClass();
>
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
> ("ext1", new MyModel1ResourceFactoryImpl());
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
> (Resource.Factory.Registry.DEFAULT_EXTENSION,
> new MyModel2ResourceFactoryImpl());
>
> Resource resource =
> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
> DocumentRoot documentRoot =
> MyModel2Factory.eINSTANCE.createDocumentRoot();
>
> // ---- Removing the next two lines makes it work from maven too.
> ActivitiesType root = MyModel2Factory.eINSTANCE.createActivitiesType();
> documentRoot.setActivities(root);
>
> resource.getContents().add(documentRoot);
> resource.save(System.out, null);
This looks much like the generated XyzExample you get when you invoke
"Generate Test Code". Does that have the same problem?
>
> Many thanks,
> Ronaldo
>
> Ed Merks wrote:
> > Ronaldo,
> >
> > Comments below.
> >
> > Ronaldo wrote:
> >> Hi Ed,
> >>
> >> Thanks for the quick answer. Yes, I have 2 models in 2 different
> >> eclipse projects.
> >> They both use a null target namespace, in order to eliminate the
> >> prefixes in the xml.
> > :-(
> >
> > XML documents with at least a namespace for the root element are
> > generally more consumable because they identify their schema...
> >>
> >> I was just wondering what (which setting) causes the code
> >>
> >> result.getDefaultSaveOptions().put(
> >> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
> > A null target namespace schema produces an annotation on the
> EPackage to
> > indicate the package is not qualified.
> >>
> >> to be generated. (as opposed to
> >>
> >> result.getDefaultSaveOptions().put(
> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
> > This package doesn't have such an annotation.
> >
> > Note that you can't have two different packages that both want to be
> the
> > one for the null namespace both working at the same time.
> >> )
> >>
> >> Ronaldo
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423248 is a reply to message #423246] |
Thu, 25 September 2008 13:55 |
ronald Mising name Messages: 52 Registered: July 2009 |
Member |
|
|
Hi Ed,
I guess you're saying I'm messing around with a null namespace :0
Point is, it has worked and somehow I changed something and it doesn't work any more.
I feel I'm losing control ...
Anyway, I'll step back, and use proper namespaces ;)
My package is now only annotated with @model kind="package". (Unqualified is removed)
The generated XYZExample now generates
<?xml version="1.0" encoding="UTF-8"?>
<Activities/>
So the question is, which piece of code is responsible for hiding the namespace prefix?
I'd expect something like
<?xml version="1.0" encoding="UTF-8"?>
<prefix:Activities xmlns:prefix="yadiyadi" />
Fun part is, after unloading the created and saved resource,
I reload it using the same resourceSet. But then, I get the famous "Package with uri null not found" message...
because the prefix is missing...
Ronaldo
>
>
> Ronaldo wrote:
>> This error comes up when I run the XYZExample test code, disguised
>> as/copied to a UnitTest in maven. (ie outside the eclipse editor).
>> It runs fine from within eclipse/junit. I figured it must have
>> something to do with
>> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>>
>> does it?
>>
>> The error is
>>
>> java.lang.NullPointerException
>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>>
> It's dying because the data type doesn't have a containing package and
> hence we get a null pointer exception trying to get the factory for that
> package?
>
> EDataType d = (EDataType)f.getEType();
> EPackage ePackage = d.getEPackage();
> EFactory fac = ePackage.getEFactoryInstance();
>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>>
>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>>
>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>>
>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>>
>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>>
>>
>> Code:
>>
>> MyModel1Package.eINSTANCE.eClass();
>> MyModel2Package.eINSTANCE.eClass();
>> ResourceSet resourceSet = new ResourceSetImpl();
>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>> ("ext1", new MyModel1ResourceFactoryImpl());
>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>> new MyModel2ResourceFactoryImpl());
>>
>> Resource resource =
>> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
>> DocumentRoot documentRoot =
>> MyModel2Factory.eINSTANCE.createDocumentRoot();
>>
>> // ---- Removing the next two lines makes it work from maven too.
>> ActivitiesType root = MyModel2Factory.eINSTANCE.createActivitiesType();
>> documentRoot.setActivities(root);
>>
>> resource.getContents().add(documentRoot);
>> resource.save(System.out, null);
> This looks much like the generated XyzExample you get when you invoke
> "Generate Test Code". Does that have the same problem?
>>
>> Many thanks,
>> Ronaldo
>>
>> Ed Merks wrote:
>> > Ronaldo,
>> >
>> > Comments below.
>> >
>> > Ronaldo wrote:
>> >> Hi Ed,
>> >>
>> >> Thanks for the quick answer. Yes, I have 2 models in 2 different
>> >> eclipse projects.
>> >> They both use a null target namespace, in order to eliminate the
>> >> prefixes in the xml.
>> > :-(
>> >
>> > XML documents with at least a namespace for the root element are
>> > generally more consumable because they identify their schema...
>> >>
>> >> I was just wondering what (which setting) causes the code
>> >>
>> >> result.getDefaultSaveOptions().put(
>> >> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
>> > A null target namespace schema produces an annotation on the
>> EPackage to
>> > indicate the package is not qualified.
>> >>
>> >> to be generated. (as opposed to
>> >>
>> >> result.getDefaultSaveOptions().put(
>> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>> > This package doesn't have such an annotation.
>> >
>> > Note that you can't have two different packages that both want to be
>> the
>> > one for the null namespace both working at the same time.
>> >> )
>> >>
>> >> Ronaldo
|
|
|
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423251 is a reply to message #423248] |
Thu, 25 September 2008 14:13 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Ronaldo,
Comments below.
Ronaldo wrote:
> Hi Ed,
>
> I guess you're saying I'm messing around with a null namespace :0
> Point is, it has worked and somehow I changed something and it doesn't
> work any more.
> I feel I'm losing control ...
Something worked, but only you know what...
>
> Anyway, I'll step back, and use proper namespaces ;)
>
> My package is now only annotated with @model kind="package".
> (Unqualified is removed)
You've relaoaded the model?
> The generated XYZExample now generates
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Activities/>
>
> So the question is, which piece of code is responsible for hiding the
> namespace prefix?
And has the resource factory been regenerated so it's using "TRUE"? It
doesn't look that way...
>
> I'd expect something like
> <?xml version="1.0" encoding="UTF-8"?>
> <prefix:Activities xmlns:prefix="yadiyadi" />
Me too. What's the nsURI of your EPackage?
>
> Fun part is, after unloading the created and saved resource,
> I reload it using the same resourceSet. But then, I get the famous
> "Package with uri null not found" message...
> because the prefix is missing...
Something's is a little screwed up for sure... What does the resource
factory look like?
>
> Ronaldo
>
>
>
>>
>>
>> Ronaldo wrote:
>>> This error comes up when I run the XYZExample test code, disguised
>>> as/copied to a UnitTest in maven. (ie outside the eclipse editor).
>>> It runs fine from within eclipse/junit. I figured it must have
>>> something to do with
>>> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>>>
>>> does it?
>>>
>>> The error is
>>>
>>> java.lang.NullPointerException
>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>>>
>> It's dying because the data type doesn't have a containing package
>> and hence we get a null pointer exception trying to get the factory
>> for that package?
>>
>> EDataType d = (EDataType)f.getEType();
>> EPackage ePackage = d.getEPackage();
>> EFactory fac = ePackage.getEFactoryInstance();
>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>>>
>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>>>
>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>>>
>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
>>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>>>
>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>>>
>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>>>
>>>
>>> Code:
>>>
>>> MyModel1Package.eINSTANCE.eClass();
>>> MyModel2Package.eINSTANCE.eClass();
>>> ResourceSet resourceSet = new ResourceSetImpl();
>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>> ("ext1", new MyModel1ResourceFactoryImpl());
>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>> new MyModel2ResourceFactoryImpl());
>>>
>>> Resource resource =
>>> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
>>> DocumentRoot documentRoot =
>>> MyModel2Factory.eINSTANCE.createDocumentRoot();
>>>
>>> // ---- Removing the next two lines makes it work from maven too.
>>> ActivitiesType root = MyModel2Factory.eINSTANCE.createActivitiesType();
>>> documentRoot.setActivities(root);
>>>
>>> resource.getContents().add(documentRoot);
>>> resource.save(System.out, null);
>> This looks much like the generated XyzExample you get when you invoke
>> "Generate Test Code". Does that have the same problem?
>>>
>>> Many thanks,
>>> Ronaldo
>>>
>>> Ed Merks wrote:
>>> > Ronaldo,
>>> >
>>> > Comments below.
>>> >
>>> > Ronaldo wrote:
>>> >> Hi Ed,
>>> >>
>>> >> Thanks for the quick answer. Yes, I have 2 models in 2 different
>>> >> eclipse projects.
>>> >> They both use a null target namespace, in order to eliminate the
>>> >> prefixes in the xml.
>>> > :-(
>>> >
>>> > XML documents with at least a namespace for the root element are
>>> > generally more consumable because they identify their schema...
>>> >>
>>> >> I was just wondering what (which setting) causes the code
>>> >>
>>> >> result.getDefaultSaveOptions().put(
>>> >> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
>>> > A null target namespace schema produces an annotation on the
>>> EPackage to
>>> > indicate the package is not qualified.
>>> >>
>>> >> to be generated. (as opposed to
>>> >>
>>> >> result.getDefaultSaveOptions().put(
>>> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>>> > This package doesn't have such an annotation.
>>> >
>>> > Note that you can't have two different packages that both want to
>>> be the
>>> > one for the null namespace both working at the same time.
>>> >> )
>>> >>
>>> >> Ronaldo
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423257 is a reply to message #423251] |
Thu, 25 September 2008 14:41 |
ronald Mising name Messages: 52 Registered: July 2009 |
Member |
|
|
I have something that might be noteworthy:
Somehow, I noticed that my genmodel consists of 4 models:
Xpdl1 - Deprecated xpdl format
Xpdl2 - Current xpdl format
Ecore - (Icon contains a little arrow/referenced?)
XMLType - (Icon contains a little arrow/referenced?)
The util package also contains an Xpdl2XMLProcessor class:
public class Xpdl2XMLProcessor extends XMLProcessor {
public Xpdl2XMLProcessor() {
super((EPackage.Registry.INSTANCE));
Xpdl2Package.eINSTANCE.eClass();
}
@Override
protected Map<String, Resource.Factory> getRegistrations() {
if (registrations == null) {
super.getRegistrations();
registrations.put(XML_EXTENSION, new Xpdl2ResourceFactoryImpl());
registrations.put(STAR_EXTENSION, new Xpdl2ResourceFactoryImpl());
}
return registrations;
}
}
which seems a little odd. I hadn't noticed this before.
Here's the EPackage source:
public interface Xpdl2Package extends EPackage {
String eNS_URI = "http://www.wfmc.org/2008/XPDL2.1";
String eNS_PREFIX = "xpdl2";
Xpdl2Package eINSTANCE = org.wfmc.xpdl21.xpdl2.impl.Xpdl2PackageImpl.init();
}
And the resourceFactory source:
public class Xpdl2ResourceFactoryImpl extends ResourceFactoryImpl {
/**
* @generated
*/
public Xpdl2ResourceFactoryImpl() {
super();
}
/**
* @generated
*/
public Resource createResourceGen(URI uri) {
XMLResource result = new Xpdl2ResourceImpl(uri);
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE, Boolean.TRUE);
result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE, Boolean.TRUE);
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER, Boolean.TRUE);
return result;
}
@Override
public Resource createResource(URI uri) {
XMLResource result = (XMLResource)createResourceGen(uri);
result.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODI NG, "UTF-8");
result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODI NG, "UTF-8");
//
// // Where do we turn this off in the genmodel? What is the name of the option?
// result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION, Boolean.TRUE);
//
// result.getDefaultLoadOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING, Boolean.TRUE);
// result.getDefaultSaveOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING, Boolean.TRUE);
//
//result.getDefaultSaveOptions().put(XMLResource.OPTION_SKIP _ESCAPE, Boolean.TRUE);
// result.getDefaultSaveOptions().put(XMLResource.OPTION_ESCAPE _USING_CDATA, Boolean.TRUE);
// result.getDefaultSaveOptions().put(XMLResource.OPTION_FORMAT TED, Boolean.TRUE);
//
return result;
}
} //Xpdl2ResourceFactoryImpl
I hope this helps.
Ronaldo
Ed Merks wrote:
> Ronaldo,
>
> Comments below.
>
> Ronaldo wrote:
>> Hi Ed,
>>
>> I guess you're saying I'm messing around with a null namespace :0
>> Point is, it has worked and somehow I changed something and it doesn't
>> work any more.
>> I feel I'm losing control ...
> Something worked, but only you know what...
>>
>> Anyway, I'll step back, and use proper namespaces ;)
>>
>> My package is now only annotated with @model kind="package".
>> (Unqualified is removed)
> You've relaoaded the model?
>> The generated XYZExample now generates
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <Activities/>
>>
>> So the question is, which piece of code is responsible for hiding the
>> namespace prefix?
> And has the resource factory been regenerated so it's using "TRUE"? It
> doesn't look that way...
>>
>> I'd expect something like
>> <?xml version="1.0" encoding="UTF-8"?>
>> <prefix:Activities xmlns:prefix="yadiyadi" />
> Me too. What's the nsURI of your EPackage?
>>
>> Fun part is, after unloading the created and saved resource,
>> I reload it using the same resourceSet. But then, I get the famous
>> "Package with uri null not found" message...
>> because the prefix is missing...
> Something's is a little screwed up for sure... What does the resource
> factory look like?
>>
>> Ronaldo
>>
>>
>>
>>>
>>>
>>> Ronaldo wrote:
>>>> This error comes up when I run the XYZExample test code, disguised
>>>> as/copied to a UnitTest in maven. (ie outside the eclipse editor).
>>>> It runs fine from within eclipse/junit. I figured it must have
>>>> something to do with
>>>> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>>>>
>>>> does it?
>>>>
>>>> The error is
>>>>
>>>> java.lang.NullPointerException
>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>>>>
>>> It's dying because the data type doesn't have a containing package
>>> and hence we get a null pointer exception trying to get the factory
>>> for that package?
>>>
>>> EDataType d = (EDataType)f.getEType();
>>> EPackage ePackage = d.getEPackage();
>>> EFactory fac = ePackage.getEFactoryInstance();
>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>>>>
>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>>>>
>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>>>>
>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
>>>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>>>>
>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>>>>
>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>>>>
>>>>
>>>> Code:
>>>>
>>>> MyModel1Package.eINSTANCE.eClass();
>>>> MyModel2Package.eINSTANCE.eClass();
>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>> ("ext1", new MyModel1ResourceFactoryImpl());
>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>>> new MyModel2ResourceFactoryImpl());
>>>>
>>>> Resource resource =
>>>> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
>>>> DocumentRoot documentRoot =
>>>> MyModel2Factory.eINSTANCE.createDocumentRoot();
>>>>
>>>> // ---- Removing the next two lines makes it work from maven too.
>>>> ActivitiesType root = MyModel2Factory.eINSTANCE.createActivitiesType();
>>>> documentRoot.setActivities(root);
>>>>
>>>> resource.getContents().add(documentRoot);
>>>> resource.save(System.out, null);
>>> This looks much like the generated XyzExample you get when you invoke
>>> "Generate Test Code". Does that have the same problem?
>>>>
>>>> Many thanks,
>>>> Ronaldo
>>>>
>>>> Ed Merks wrote:
>>>> > Ronaldo,
>>>> >
>>>> > Comments below.
>>>> >
>>>> > Ronaldo wrote:
>>>> >> Hi Ed,
>>>> >>
>>>> >> Thanks for the quick answer. Yes, I have 2 models in 2 different
>>>> >> eclipse projects.
>>>> >> They both use a null target namespace, in order to eliminate the
>>>> >> prefixes in the xml.
>>>> > :-(
>>>> >
>>>> > XML documents with at least a namespace for the root element are
>>>> > generally more consumable because they identify their schema...
>>>> >>
>>>> >> I was just wondering what (which setting) causes the code
>>>> >>
>>>> >> result.getDefaultSaveOptions().put(
>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
>>>> > A null target namespace schema produces an annotation on the
>>>> EPackage to
>>>> > indicate the package is not qualified.
>>>> >>
>>>> >> to be generated. (as opposed to
>>>> >>
>>>> >> result.getDefaultSaveOptions().put(
>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>>>> > This package doesn't have such an annotation.
>>>> >
>>>> > Note that you can't have two different packages that both want to
>>>> be the
>>>> > one for the null namespace both working at the same time.
>>>> >> )
>>>> >>
>>>> >> Ronaldo
|
|
|
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423258 is a reply to message #423257] |
Thu, 25 September 2008 14:56 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Ronaldo,
What EAnnotations does the "activities" feature of the DocumentRoot have
on it?
Ronaldo wrote:
> I have something that might be noteworthy:
> Somehow, I noticed that my genmodel consists of 4 models:
>
> Xpdl1 - Deprecated xpdl format
> Xpdl2 - Current xpdl format
> Ecore - (Icon contains a little arrow/referenced?)
> XMLType - (Icon contains a little arrow/referenced?)
>
> The util package also contains an Xpdl2XMLProcessor class:
>
> public class Xpdl2XMLProcessor extends XMLProcessor {
> public Xpdl2XMLProcessor() {
> super((EPackage.Registry.INSTANCE));
> Xpdl2Package.eINSTANCE.eClass();
> }
>
> @Override
> protected Map<String, Resource.Factory> getRegistrations() {
> if (registrations == null) {
> super.getRegistrations();
> registrations.put(XML_EXTENSION, new
> Xpdl2ResourceFactoryImpl());
> registrations.put(STAR_EXTENSION, new
> Xpdl2ResourceFactoryImpl());
> }
> return registrations;
> }
> }
>
> which seems a little odd. I hadn't noticed this before.
>
> Here's the EPackage source:
>
> public interface Xpdl2Package extends EPackage {
> String eNS_URI = "http://www.wfmc.org/2008/XPDL2.1";
> String eNS_PREFIX = "xpdl2";
> Xpdl2Package eINSTANCE =
> org.wfmc.xpdl21.xpdl2.impl.Xpdl2PackageImpl.init();
> }
>
>
> And the resourceFactory source:
>
> public class Xpdl2ResourceFactoryImpl extends ResourceFactoryImpl {
> /**
> * @generated
> */
> public Xpdl2ResourceFactoryImpl() {
> super();
> }
> /**
> * @generated
> */
> public Resource createResourceGen(URI uri) {
> XMLResource result = new Xpdl2ResourceImpl(uri);
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
> Boolean.TRUE);
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
> Boolean.TRUE);
>
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
> Boolean.TRUE);
>
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
>
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
> Boolean.TRUE);
> return result;
> }
>
> @Override
> public Resource createResource(URI uri) {
> XMLResource result = (XMLResource)createResourceGen(uri);
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODI NG, "UTF-8");
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODI NG, "UTF-8");
> //
> // // Where do we turn this off in the genmodel? What is the
> name of the option?
> //
> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
> Boolean.TRUE);
> //
> //
> result.getDefaultLoadOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
> Boolean.TRUE);
> //
> result.getDefaultSaveOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
> Boolean.TRUE);
> //
>
> //result.getDefaultSaveOptions().put(XMLResource.OPTION_SKIP _ESCAPE,
> Boolean.TRUE);
> //
> result.getDefaultSaveOptions().put(XMLResource.OPTION_ESCAPE _USING_CDATA,
> Boolean.TRUE);
> //
> result.getDefaultSaveOptions().put(XMLResource.OPTION_FORMAT TED,
> Boolean.TRUE);
> //
> return result;
> }
>
> } //Xpdl2ResourceFactoryImpl
>
> I hope this helps.
> Ronaldo
>
> Ed Merks wrote:
>> Ronaldo,
>>
>> Comments below.
>>
>> Ronaldo wrote:
>>> Hi Ed,
>>>
>>> I guess you're saying I'm messing around with a null namespace :0
>>> Point is, it has worked and somehow I changed something and it
>>> doesn't work any more.
>>> I feel I'm losing control ...
>> Something worked, but only you know what...
>>>
>>> Anyway, I'll step back, and use proper namespaces ;)
>>>
>>> My package is now only annotated with @model kind="package".
>>> (Unqualified is removed)
>> You've relaoaded the model?
>>> The generated XYZExample now generates
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <Activities/>
>>>
>>> So the question is, which piece of code is responsible for hiding
>>> the namespace prefix?
>> And has the resource factory been regenerated so it's using "TRUE"?
>> It doesn't look that way...
>>>
>>> I'd expect something like
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <prefix:Activities xmlns:prefix="yadiyadi" />
>> Me too. What's the nsURI of your EPackage?
>>>
>>> Fun part is, after unloading the created and saved resource,
>>> I reload it using the same resourceSet. But then, I get the famous
>>> "Package with uri null not found" message...
>>> because the prefix is missing...
>> Something's is a little screwed up for sure... What does the resource
>> factory look like?
>>>
>>> Ronaldo
>>>
>>>
>>>
>>>>
>>>>
>>>> Ronaldo wrote:
>>>>> This error comes up when I run the XYZExample test code, disguised
>>>>> as/copied to a UnitTest in maven. (ie outside the eclipse editor).
>>>>> It runs fine from within eclipse/junit. I figured it must have
>>>>> something to do with
>>>>> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>>>>>
>>>>> does it?
>>>>>
>>>>> The error is
>>>>>
>>>>> java.lang.NullPointerException
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>>>>>
>>>> It's dying because the data type doesn't have a containing package
>>>> and hence we get a null pointer exception trying to get the factory
>>>> for that package?
>>>>
>>>> EDataType d = (EDataType)f.getEType();
>>>> EPackage ePackage = d.getEPackage();
>>>> EFactory fac = ePackage.getEFactoryInstance();
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>>>>>
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>>>>>
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>>>>>
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>>>>>
>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>>>>>
>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>>>>>
>>>>>
>>>>> Code:
>>>>>
>>>>> MyModel1Package.eINSTANCE.eClass();
>>>>> MyModel2Package.eINSTANCE.eClass();
>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>
>>>>> ("ext1", new MyModel1ResourceFactoryImpl());
>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>
>>>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>>>> new MyModel2ResourceFactoryImpl());
>>>>>
>>>>> Resource resource =
>>>>> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
>>>>> DocumentRoot documentRoot =
>>>>> MyModel2Factory.eINSTANCE.createDocumentRoot();
>>>>>
>>>>> // ---- Removing the next two lines makes it work from maven too.
>>>>> ActivitiesType root =
>>>>> MyModel2Factory.eINSTANCE.createActivitiesType();
>>>>> documentRoot.setActivities(root);
>>>>>
>>>>> resource.getContents().add(documentRoot);
>>>>> resource.save(System.out, null);
>>>> This looks much like the generated XyzExample you get when you
>>>> invoke "Generate Test Code". Does that have the same problem?
>>>>>
>>>>> Many thanks,
>>>>> Ronaldo
>>>>>
>>>>> Ed Merks wrote:
>>>>> > Ronaldo,
>>>>> >
>>>>> > Comments below.
>>>>> >
>>>>> > Ronaldo wrote:
>>>>> >> Hi Ed,
>>>>> >>
>>>>> >> Thanks for the quick answer. Yes, I have 2 models in 2 different
>>>>> >> eclipse projects.
>>>>> >> They both use a null target namespace, in order to eliminate the
>>>>> >> prefixes in the xml.
>>>>> > :-(
>>>>> >
>>>>> > XML documents with at least a namespace for the root element are
>>>>> > generally more consumable because they identify their schema...
>>>>> >>
>>>>> >> I was just wondering what (which setting) causes the code
>>>>> >>
>>>>> >> result.getDefaultSaveOptions().put(
>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
>>>>> > A null target namespace schema produces an annotation on the
>>>>> EPackage to
>>>>> > indicate the package is not qualified.
>>>>> >>
>>>>> >> to be generated. (as opposed to
>>>>> >>
>>>>> >> result.getDefaultSaveOptions().put(
>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>>>>> > This package doesn't have such an annotation.
>>>>> >
>>>>> > Note that you can't have two different packages that both want
>>>>> to be the
>>>>> > one for the null namespace both working at the same time.
>>>>> >> )
>>>>> >>
>>>>> >> Ronaldo
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423259 is a reply to message #423257] |
Thu, 25 September 2008 14:58 |
ronald Mising name Messages: 52 Registered: July 2009 |
Member |
|
|
And another observation:
I get:
<?xml version="1.0" encoding="UTF-8"?>
<xpdl2:Package xmlns:xpdl2="http://www.wfmc.org/2008/XPDL2.1" Id="1"/>
When adding the PackageType (a model element) directly to the resource.getContents(),
as in:
Resource resource = xpdl2ResourceSet.createResource(uri);
PackageType packageType = xpdl2Factory.createPackageType();
resource.getContents().add(packageType);
Before I used:
Resource resource = xpdl2ResourceSet.createResource(uri);
DocumentRoot documentRoot = xpdl2Factory.createDocumentRoot();
PackageType packageType = xpdl2Factory.createPackageType();
documentRoot.setPackage(packageType);
resource.getContents().add(documentRoot);
Ronaldo
Ronaldo wrote:
> I have something that might be noteworthy:
> Somehow, I noticed that my genmodel consists of 4 models:
>
> Xpdl1 - Deprecated xpdl format
> Xpdl2 - Current xpdl format
> Ecore - (Icon contains a little arrow/referenced?)
> XMLType - (Icon contains a little arrow/referenced?)
>
> The util package also contains an Xpdl2XMLProcessor class:
>
> public class Xpdl2XMLProcessor extends XMLProcessor {
> public Xpdl2XMLProcessor() {
> super((EPackage.Registry.INSTANCE));
> Xpdl2Package.eINSTANCE.eClass();
> }
>
> @Override
> protected Map<String, Resource.Factory> getRegistrations() {
> if (registrations == null) {
> super.getRegistrations();
> registrations.put(XML_EXTENSION, new
> Xpdl2ResourceFactoryImpl());
> registrations.put(STAR_EXTENSION, new
> Xpdl2ResourceFactoryImpl());
> }
> return registrations;
> }
> }
>
> which seems a little odd. I hadn't noticed this before.
>
> Here's the EPackage source:
>
> public interface Xpdl2Package extends EPackage {
> String eNS_URI = "http://www.wfmc.org/2008/XPDL2.1";
> String eNS_PREFIX = "xpdl2";
> Xpdl2Package eINSTANCE =
> org.wfmc.xpdl21.xpdl2.impl.Xpdl2PackageImpl.init();
> }
>
>
> And the resourceFactory source:
>
> public class Xpdl2ResourceFactoryImpl extends ResourceFactoryImpl {
> /**
> * @generated
> */
> public Xpdl2ResourceFactoryImpl() {
> super();
> }
> /**
> * @generated
> */
> public Resource createResourceGen(URI uri) {
> XMLResource result = new Xpdl2ResourceImpl(uri);
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
> Boolean.TRUE);
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
> Boolean.TRUE);
>
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
> Boolean.TRUE);
>
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
>
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
> Boolean.TRUE);
> return result;
> }
>
> @Override
> public Resource createResource(URI uri) {
> XMLResource result = (XMLResource)createResourceGen(uri);
> result.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODI NG,
> "UTF-8");
> result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODI NG,
> "UTF-8");
> //
> // // Where do we turn this off in the genmodel? What is the name
> of the option?
> //
> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
> Boolean.TRUE);
> //
> //
> result.getDefaultLoadOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
> Boolean.TRUE);
> //
> result.getDefaultSaveOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
> Boolean.TRUE);
> //
>
> //result.getDefaultSaveOptions().put(XMLResource.OPTION_SKIP _ESCAPE,
> Boolean.TRUE);
> //
> result.getDefaultSaveOptions().put(XMLResource.OPTION_ESCAPE _USING_CDATA,
> Boolean.TRUE);
> //
> result.getDefaultSaveOptions().put(XMLResource.OPTION_FORMAT TED,
> Boolean.TRUE);
> //
> return result;
> }
>
> } //Xpdl2ResourceFactoryImpl
>
> I hope this helps.
> Ronaldo
>
> Ed Merks wrote:
>> Ronaldo,
>>
>> Comments below.
>>
>> Ronaldo wrote:
>>> Hi Ed,
>>>
>>> I guess you're saying I'm messing around with a null namespace :0
>>> Point is, it has worked and somehow I changed something and it
>>> doesn't work any more.
>>> I feel I'm losing control ...
>> Something worked, but only you know what...
>>>
>>> Anyway, I'll step back, and use proper namespaces ;)
>>>
>>> My package is now only annotated with @model kind="package".
>>> (Unqualified is removed)
>> You've relaoaded the model?
>>> The generated XYZExample now generates
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <Activities/>
>>>
>>> So the question is, which piece of code is responsible for hiding the
>>> namespace prefix?
>> And has the resource factory been regenerated so it's using "TRUE"?
>> It doesn't look that way...
>>>
>>> I'd expect something like
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <prefix:Activities xmlns:prefix="yadiyadi" />
>> Me too. What's the nsURI of your EPackage?
>>>
>>> Fun part is, after unloading the created and saved resource,
>>> I reload it using the same resourceSet. But then, I get the famous
>>> "Package with uri null not found" message...
>>> because the prefix is missing...
>> Something's is a little screwed up for sure... What does the resource
>> factory look like?
>>>
>>> Ronaldo
>>>
>>>
>>>
>>>>
>>>>
>>>> Ronaldo wrote:
>>>>> This error comes up when I run the XYZExample test code, disguised
>>>>> as/copied to a UnitTest in maven. (ie outside the eclipse editor).
>>>>> It runs fine from within eclipse/junit. I figured it must have
>>>>> something to do with
>>>>> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>>>>>
>>>>> does it?
>>>>>
>>>>> The error is
>>>>>
>>>>> java.lang.NullPointerException
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>>>>>
>>>> It's dying because the data type doesn't have a containing package
>>>> and hence we get a null pointer exception trying to get the factory
>>>> for that package?
>>>>
>>>> EDataType d = (EDataType)f.getEType();
>>>> EPackage ePackage = d.getEPackage();
>>>> EFactory fac = ePackage.getEFactoryInstance();
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>>>>>
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>>>>>
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>>>>>
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
>>>>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>>>>>
>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>>>>>
>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>>>>>
>>>>>
>>>>> Code:
>>>>>
>>>>> MyModel1Package.eINSTANCE.eClass();
>>>>> MyModel2Package.eINSTANCE.eClass();
>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>
>>>>> ("ext1", new MyModel1ResourceFactoryImpl());
>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>
>>>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>>>> new MyModel2ResourceFactoryImpl());
>>>>>
>>>>> Resource resource =
>>>>> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
>>>>> DocumentRoot documentRoot =
>>>>> MyModel2Factory.eINSTANCE.createDocumentRoot();
>>>>>
>>>>> // ---- Removing the next two lines makes it work from maven too.
>>>>> ActivitiesType root =
>>>>> MyModel2Factory.eINSTANCE.createActivitiesType();
>>>>> documentRoot.setActivities(root);
>>>>>
>>>>> resource.getContents().add(documentRoot);
>>>>> resource.save(System.out, null);
>>>> This looks much like the generated XyzExample you get when you
>>>> invoke "Generate Test Code". Does that have the same problem?
>>>>>
>>>>> Many thanks,
>>>>> Ronaldo
>>>>>
>>>>> Ed Merks wrote:
>>>>> > Ronaldo,
>>>>> >
>>>>> > Comments below.
>>>>> >
>>>>> > Ronaldo wrote:
>>>>> >> Hi Ed,
>>>>> >>
>>>>> >> Thanks for the quick answer. Yes, I have 2 models in 2 different
>>>>> >> eclipse projects.
>>>>> >> They both use a null target namespace, in order to eliminate the
>>>>> >> prefixes in the xml.
>>>>> > :-(
>>>>> >
>>>>> > XML documents with at least a namespace for the root element are
>>>>> > generally more consumable because they identify their schema...
>>>>> >>
>>>>> >> I was just wondering what (which setting) causes the code
>>>>> >>
>>>>> >> result.getDefaultSaveOptions().put(
>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
>>>>> > A null target namespace schema produces an annotation on the
>>>>> EPackage to
>>>>> > indicate the package is not qualified.
>>>>> >>
>>>>> >> to be generated. (as opposed to
>>>>> >>
>>>>> >> result.getDefaultSaveOptions().put(
>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>>>>> > This package doesn't have such an annotation.
>>>>> >
>>>>> > Note that you can't have two different packages that both want to
>>>>> be the
>>>>> > one for the null namespace both working at the same time.
>>>>> >> )
>>>>> >>
>>>>> >> Ronaldo
|
|
|
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423261 is a reply to message #423258] |
Thu, 25 September 2008 15:07 |
ronald Mising name Messages: 52 Registered: July 2009 |
Member |
|
|
This is the generated code for the getActivities method in the DocumentRoot interface.
* @model containment="true" upper="-2" transient="true" volatile="true" derived="true"
* extendedMetaData="kind='element' name='Activities'"
* @generated
*/
ActivitiesType getActivities();
Ed Merks wrote:
> Ronaldo,
>
> What EAnnotations does the "activities" feature of the DocumentRoot have
> on it?
>
>
> Ronaldo wrote:
>> I have something that might be noteworthy:
>> Somehow, I noticed that my genmodel consists of 4 models:
>>
>> Xpdl1 - Deprecated xpdl format
>> Xpdl2 - Current xpdl format
>> Ecore - (Icon contains a little arrow/referenced?)
>> XMLType - (Icon contains a little arrow/referenced?)
>>
>> The util package also contains an Xpdl2XMLProcessor class:
>>
>> public class Xpdl2XMLProcessor extends XMLProcessor {
>> public Xpdl2XMLProcessor() {
>> super((EPackage.Registry.INSTANCE));
>> Xpdl2Package.eINSTANCE.eClass();
>> }
>>
>> @Override
>> protected Map<String, Resource.Factory> getRegistrations() {
>> if (registrations == null) {
>> super.getRegistrations();
>> registrations.put(XML_EXTENSION, new
>> Xpdl2ResourceFactoryImpl());
>> registrations.put(STAR_EXTENSION, new
>> Xpdl2ResourceFactoryImpl());
>> }
>> return registrations;
>> }
>> }
>>
>> which seems a little odd. I hadn't noticed this before.
>>
>> Here's the EPackage source:
>>
>> public interface Xpdl2Package extends EPackage {
>> String eNS_URI = "http://www.wfmc.org/2008/XPDL2.1";
>> String eNS_PREFIX = "xpdl2";
>> Xpdl2Package eINSTANCE =
>> org.wfmc.xpdl21.xpdl2.impl.Xpdl2PackageImpl.init();
>> }
>>
>>
>> And the resourceFactory source:
>>
>> public class Xpdl2ResourceFactoryImpl extends ResourceFactoryImpl {
>> /**
>> * @generated
>> */
>> public Xpdl2ResourceFactoryImpl() {
>> super();
>> }
>> /**
>> * @generated
>> */
>> public Resource createResourceGen(URI uri) {
>> XMLResource result = new Xpdl2ResourceImpl(uri);
>>
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>> Boolean.TRUE);
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>> Boolean.TRUE);
>>
>>
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>> Boolean.TRUE);
>>
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>> Boolean.TRUE);
>>
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>> Boolean.TRUE);
>>
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
>> Boolean.TRUE);
>> return result;
>> }
>> @Override
>> public Resource createResource(URI uri) {
>> XMLResource result = (XMLResource)createResourceGen(uri);
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODI NG, "UTF-8");
>>
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODI NG, "UTF-8");
>> // // // Where do we turn this off in the genmodel? What
>> is the name of the option?
>> //
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>> Boolean.TRUE);
>> // //
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>> Boolean.TRUE);
>> //
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>> Boolean.TRUE);
>> //
>>
>> //result.getDefaultSaveOptions().put(XMLResource.OPTION_SKIP _ESCAPE,
>> Boolean.TRUE);
>> //
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ESCAPE _USING_CDATA,
>> Boolean.TRUE);
>> //
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_FORMAT TED,
>> Boolean.TRUE);
>> // return result;
>> }
>>
>> } //Xpdl2ResourceFactoryImpl
>>
>> I hope this helps.
>> Ronaldo
>>
>> Ed Merks wrote:
>>> Ronaldo,
>>>
>>> Comments below.
>>>
>>> Ronaldo wrote:
>>>> Hi Ed,
>>>>
>>>> I guess you're saying I'm messing around with a null namespace :0
>>>> Point is, it has worked and somehow I changed something and it
>>>> doesn't work any more.
>>>> I feel I'm losing control ...
>>> Something worked, but only you know what...
>>>>
>>>> Anyway, I'll step back, and use proper namespaces ;)
>>>>
>>>> My package is now only annotated with @model kind="package".
>>>> (Unqualified is removed)
>>> You've relaoaded the model?
>>>> The generated XYZExample now generates
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <Activities/>
>>>>
>>>> So the question is, which piece of code is responsible for hiding
>>>> the namespace prefix?
>>> And has the resource factory been regenerated so it's using "TRUE"?
>>> It doesn't look that way...
>>>>
>>>> I'd expect something like
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <prefix:Activities xmlns:prefix="yadiyadi" />
>>> Me too. What's the nsURI of your EPackage?
>>>>
>>>> Fun part is, after unloading the created and saved resource,
>>>> I reload it using the same resourceSet. But then, I get the famous
>>>> "Package with uri null not found" message...
>>>> because the prefix is missing...
>>> Something's is a little screwed up for sure... What does the resource
>>> factory look like?
>>>>
>>>> Ronaldo
>>>>
>>>>
>>>>
>>>>>
>>>>>
>>>>> Ronaldo wrote:
>>>>>> This error comes up when I run the XYZExample test code, disguised
>>>>>> as/copied to a UnitTest in maven. (ie outside the eclipse editor).
>>>>>> It runs fine from within eclipse/junit. I figured it must have
>>>>>> something to do with
>>>>>> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>>>>>>
>>>>>> does it?
>>>>>>
>>>>>> The error is
>>>>>>
>>>>>> java.lang.NullPointerException
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>>>>>>
>>>>> It's dying because the data type doesn't have a containing package
>>>>> and hence we get a null pointer exception trying to get the factory
>>>>> for that package?
>>>>>
>>>>> EDataType d = (EDataType)f.getEType();
>>>>> EPackage ePackage = d.getEPackage();
>>>>> EFactory fac = ePackage.getEFactoryInstance();
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>>>>>>
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>>>>>>
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>>>>>>
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>>>>>>
>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>>>>>>
>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>>>>>>
>>>>>>
>>>>>> Code:
>>>>>>
>>>>>> MyModel1Package.eINSTANCE.eClass();
>>>>>> MyModel2Package.eINSTANCE.eClass();
>>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>
>>>>>> ("ext1", new MyModel1ResourceFactoryImpl());
>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>
>>>>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>>>>> new MyModel2ResourceFactoryImpl());
>>>>>>
>>>>>> Resource resource =
>>>>>> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
>>>>>> DocumentRoot documentRoot =
>>>>>> MyModel2Factory.eINSTANCE.createDocumentRoot();
>>>>>>
>>>>>> // ---- Removing the next two lines makes it work from maven too.
>>>>>> ActivitiesType root =
>>>>>> MyModel2Factory.eINSTANCE.createActivitiesType();
>>>>>> documentRoot.setActivities(root);
>>>>>>
>>>>>> resource.getContents().add(documentRoot);
>>>>>> resource.save(System.out, null);
>>>>> This looks much like the generated XyzExample you get when you
>>>>> invoke "Generate Test Code". Does that have the same problem?
>>>>>>
>>>>>> Many thanks,
>>>>>> Ronaldo
>>>>>>
>>>>>> Ed Merks wrote:
>>>>>> > Ronaldo,
>>>>>> >
>>>>>> > Comments below.
>>>>>> >
>>>>>> > Ronaldo wrote:
>>>>>> >> Hi Ed,
>>>>>> >>
>>>>>> >> Thanks for the quick answer. Yes, I have 2 models in 2 different
>>>>>> >> eclipse projects.
>>>>>> >> They both use a null target namespace, in order to eliminate the
>>>>>> >> prefixes in the xml.
>>>>>> > :-(
>>>>>> >
>>>>>> > XML documents with at least a namespace for the root element are
>>>>>> > generally more consumable because they identify their schema...
>>>>>> >>
>>>>>> >> I was just wondering what (which setting) causes the code
>>>>>> >>
>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
>>>>>> > A null target namespace schema produces an annotation on the
>>>>>> EPackage to
>>>>>> > indicate the package is not qualified.
>>>>>> >>
>>>>>> >> to be generated. (as opposed to
>>>>>> >>
>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>>>>>> > This package doesn't have such an annotation.
>>>>>> >
>>>>>> > Note that you can't have two different packages that both want
>>>>>> to be the
>>>>>> > one for the null namespace both working at the same time.
>>>>>> >> )
>>>>>> >>
>>>>>> >> Ronaldo
|
|
|
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423262 is a reply to message #423261] |
Thu, 25 September 2008 15:14 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------000904030009000904070908
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Ronaldo,
For the library mode it looks like this:
* @model containment="true" upper="-2" transient="true"
volatile="true" derived="true"
* extendedMetaData="kind='element' name='library'*
namespace='##targetNamespace'"*
I assume these models originated from a schema. Do that schema have a
target namespace?
Ronaldo wrote:
>
> This is the generated code for the getActivities method in the
> DocumentRoot interface.
>
> * @model containment="true" upper="-2" transient="true"
> volatile="true" derived="true"
> * extendedMetaData="kind='element' name='Activities'"
> * @generated
> */
> ActivitiesType getActivities();
>
>
>
> Ed Merks wrote:
>> Ronaldo,
>>
>> What EAnnotations does the "activities" feature of the DocumentRoot
>> have on it?
>>
>>
>> Ronaldo wrote:
>>> I have something that might be noteworthy:
>>> Somehow, I noticed that my genmodel consists of 4 models:
>>>
>>> Xpdl1 - Deprecated xpdl format
>>> Xpdl2 - Current xpdl format
>>> Ecore - (Icon contains a little arrow/referenced?)
>>> XMLType - (Icon contains a little arrow/referenced?)
>>>
>>> The util package also contains an Xpdl2XMLProcessor class:
>>>
>>> public class Xpdl2XMLProcessor extends XMLProcessor {
>>> public Xpdl2XMLProcessor() {
>>> super((EPackage.Registry.INSTANCE));
>>> Xpdl2Package.eINSTANCE.eClass();
>>> }
>>>
>>> @Override
>>> protected Map<String, Resource.Factory> getRegistrations() {
>>> if (registrations == null) {
>>> super.getRegistrations();
>>> registrations.put(XML_EXTENSION, new
>>> Xpdl2ResourceFactoryImpl());
>>> registrations.put(STAR_EXTENSION, new
>>> Xpdl2ResourceFactoryImpl());
>>> }
>>> return registrations;
>>> }
>>> }
>>>
>>> which seems a little odd. I hadn't noticed this before.
>>>
>>> Here's the EPackage source:
>>>
>>> public interface Xpdl2Package extends EPackage {
>>> String eNS_URI = "http://www.wfmc.org/2008/XPDL2.1";
>>> String eNS_PREFIX = "xpdl2";
>>> Xpdl2Package eINSTANCE =
>>> org.wfmc.xpdl21.xpdl2.impl.Xpdl2PackageImpl.init();
>>> }
>>>
>>>
>>> And the resourceFactory source:
>>>
>>> public class Xpdl2ResourceFactoryImpl extends ResourceFactoryImpl {
>>> /**
>>> * @generated
>>> */
>>> public Xpdl2ResourceFactoryImpl() {
>>> super();
>>> }
>>> /**
>>> * @generated
>>> */
>>> public Resource createResourceGen(URI uri) {
>>> XMLResource result = new Xpdl2ResourceImpl(uri);
>>>
>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>>> Boolean.TRUE);
>>>
>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>>> Boolean.TRUE);
>>>
>>>
>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>>> Boolean.TRUE);
>>>
>>>
>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>>> Boolean.TRUE);
>>>
>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>>> Boolean.TRUE);
>>>
>>>
>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
>>> Boolean.TRUE);
>>> return result;
>>> }
>>> @Override
>>> public Resource createResource(URI uri) {
>>> XMLResource result = (XMLResource)createResourceGen(uri);
>>>
>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODI NG,
>>> "UTF-8");
>>>
>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODI NG,
>>> "UTF-8");
>>> // // // Where do we turn this off in the genmodel?
>>> What is the name of the option?
>>> //
>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>>> Boolean.TRUE);
>>> // //
>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>>> Boolean.TRUE);
>>> //
>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>>> Boolean.TRUE);
>>> //
>>>
>>> //result.getDefaultSaveOptions().put(XMLResource.OPTION_SKIP _ESCAPE,
>>> Boolean.TRUE);
>>> //
>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ESCAPE _USING_CDATA,
>>> Boolean.TRUE);
>>> //
>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_FORMAT TED,
>>> Boolean.TRUE);
>>> // return result;
>>> }
>>>
>>> } //Xpdl2ResourceFactoryImpl
>>>
>>> I hope this helps.
>>> Ronaldo
>>>
>>> Ed Merks wrote:
>>>> Ronaldo,
>>>>
>>>> Comments below.
>>>>
>>>> Ronaldo wrote:
>>>>> Hi Ed,
>>>>>
>>>>> I guess you're saying I'm messing around with a null namespace :0
>>>>> Point is, it has worked and somehow I changed something and it
>>>>> doesn't work any more.
>>>>> I feel I'm losing control ...
>>>> Something worked, but only you know what...
>>>>>
>>>>> Anyway, I'll step back, and use proper namespaces ;)
>>>>>
>>>>> My package is now only annotated with @model kind="package".
>>>>> (Unqualified is removed)
>>>> You've relaoaded the model?
>>>>> The generated XYZExample now generates
>>>>>
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>> <Activities/>
>>>>>
>>>>> So the question is, which piece of code is responsible for hiding
>>>>> the namespace prefix?
>>>> And has the resource factory been regenerated so it's using
>>>> "TRUE"? It doesn't look that way...
>>>>>
>>>>> I'd expect something like
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>> <prefix:Activities xmlns:prefix="yadiyadi" />
>>>> Me too. What's the nsURI of your EPackage?
>>>>>
>>>>> Fun part is, after unloading the created and saved resource,
>>>>> I reload it using the same resourceSet. But then, I get the famous
>>>>> "Package with uri null not found" message...
>>>>> because the prefix is missing...
>>>> Something's is a little screwed up for sure... What does the
>>>> resource factory look like?
>>>>>
>>>>> Ronaldo
>>>>>
>>>>>
>>>>>
>>>>>>
>>>>>>
>>>>>> Ronaldo wrote:
>>>>>>> This error comes up when I run the XYZExample test code,
>>>>>>> disguised as/copied to a UnitTest in maven. (ie outside the
>>>>>>> eclipse editor).
>>>>>>> It runs fine from within eclipse/junit. I figured it must have
>>>>>>> something to do with
>>>>>>> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>>>>>>>
>>>>>>> does it?
>>>>>>>
>>>>>>> The error is
>>>>>>>
>>>>>>> java.lang.NullPointerException
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>>>>>>>
>>>>>> It's dying because the data type doesn't have a containing
>>>>>> package and hence we get a null pointer exception trying to get
>>>>>> the factory for that package?
>>>>>>
>>>>>> EDataType d = (EDataType)f.getEType();
>>>>>> EPackage ePackage = d.getEPackage();
>>>>>> EFactory fac = ePackage.getEFactoryInstance();
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>>>>>>>
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>>>>>>>
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>>>>>>>
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
>>>>>>>
>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>>>>>>>
>>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>>>>>>>
>>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>>>>>>>
>>>>>>>
>>>>>>> Code:
>>>>>>>
>>>>>>> MyModel1Package.eINSTANCE.eClass();
>>>>>>> MyModel2Package.eINSTANCE.eClass();
>>>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>>
>>>>>>> ("ext1", new MyModel1ResourceFactoryImpl());
>>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>>
>>>>>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>>>>>> new MyModel2ResourceFactoryImpl());
>>>>>>>
>>>>>>> Resource resource =
>>>>>>> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
>>>>>>> DocumentRoot documentRoot =
>>>>>>> MyModel2Factory.eINSTANCE.createDocumentRoot();
>>>>>>>
>>>>>>> // ---- Removing the next two lines makes it work from maven too.
>>>>>>> ActivitiesType root =
>>>>>>> MyModel2Factory.eINSTANCE.createActivitiesType();
>>>>>>> documentRoot.setActivities(root);
>>>>>>>
>>>>>>> resource.getContents().add(documentRoot);
>>>>>>> resource.save(System.out, null);
>>>>>> This looks much like the generated XyzExample you get when you
>>>>>> invoke "Generate Test Code". Does that have the same problem?
>>>>>>>
>>>>>>> Many thanks,
>>>>>>> Ronaldo
>>>>>>>
>>>>>>> Ed Merks wrote:
>>>>>>> > Ronaldo,
>>>>>>> >
>>>>>>> > Comments below.
>>>>>>> >
>>>>>>> > Ronaldo wrote:
>>>>>>> >> Hi Ed,
>>>>>>> >>
>>>>>>> >> Thanks for the quick answer. Yes, I have 2 models in 2 different
>>>>>>> >> eclipse projects.
>>>>>>> >> They both use a null target namespace, in order to eliminate the
>>>>>>> >> prefixes in the xml.
>>>>>>> > :-(
>>>>>>> >
>>>>>>> > XML documents with at least a namespace for the root element are
>>>>>>> > generally more consumable because they identify their schema...
>>>>>>> >>
>>>>>>> >> I was just wondering what (which setting) causes the code
>>>>>>> >>
>>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
>>>>>>> > A null target namespace schema produces an annotation on the
>>>>>>> EPackage to
>>>>>>> > indicate the package is not qualified.
>>>>>>> >>
>>>>>>> >> to be generated. (as opposed to
>>>>>>> >>
>>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>>>>>>> > This package doesn't have such an annotation.
>>>>>>> >
>>>>>>> > Note that you can't have two different packages that both want
>>>>>>> to be the
>>>>>>> > one for the null namespace both working at the same time.
>>>>>>> >> )
>>>>>>> >>
>>>>>>> >> Ronaldo
--------------000904030009000904070908
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Ronaldo,<br>
<br>
For the library mode it looks like this:<br>
<blockquote> * @model containment="true" upper="-2" transient="true"
volatile="true" derived="true"<br>
*   ; extendedMetaData="kind='element' name='library'<b>
namespace='##targetNamespace'"</b><br>
</blockquote>
I assume these models originated from a schema. Do that schema have a
target namespace?<br>
<br>
<br>
Ronaldo wrote:
<blockquote cite="mid:gbg9ga$r4s$1@build.eclipse.org" type="cite"><br>
This is the generated code for the getActivities method in the
DocumentRoot interface.
<br>
<br>
* @model containment="true" upper="-2" transient="true"
volatile="true" derived="true"
<br>
*   ; extendedMetaData="kind='element' name='Activities'"
<br>
* @generated
<br>
*/
<br>
ActivitiesType getActivities();
<br>
<br>
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Ronaldo,
<br>
<br>
What EAnnotations does the "activities" feature of the DocumentRoot
have on it?
<br>
<br>
<br>
Ronaldo wrote:
<br>
<blockquote type="cite">I have something that might be noteworthy:
<br>
Somehow, I noticed that my genmodel consists of 4 models:
<br>
<br>
Xpdl1 - Deprecated xpdl format
<br>
Xpdl2 - Current xpdl format
<br>
Ecore - (Icon contains a little arrow/referenced?)
<br>
XMLType - (Icon contains a little arrow/referenced?)
<br>
<br>
The util package also contains an Xpdl2XMLProcessor class:
<br>
<br>
public class Xpdl2XMLProcessor extends XMLProcessor {
<br>
public Xpdl2XMLProcessor() {
<br>
super((EPackage.Registry.INSTANCE));
<br>
Xpdl2Package.eINSTANCE.eClass();
<br>
}
<br>
<br>
@Override
<br>
protected Map<String, Resource.Factory> getRegistrations() {
<br>
if (registrations == null) {
<br>
super.getRegistrations();
<br>
registrations.put(XML_EXTENSION, new
Xpdl2ResourceFactoryImpl());
<br>
registrations.put(STAR_EXTENSION, new
Xpdl2ResourceFactoryImpl());
<br>
}
<br>
return registrations;
<br>
}
<br>
}
<br>
<br>
which seems a little odd. I hadn't noticed this before.
<br>
<br>
Here's the EPackage source:
<br>
<br>
public interface Xpdl2Package extends EPackage {
<br>
String eNS_URI = <a class="moz-txt-link-rfc2396E" href="http://www.wfmc.org/2008/XPDL2.1">"http://www.wfmc.org/2008/XPDL2.1"</a>;
<br>
String eNS_PREFIX = "xpdl2";
<br>
Xpdl2Package eINSTANCE =
org.wfmc.xpdl21.xpdl2.impl.Xpdl2PackageImpl.init();
<br>
}
<br>
<br>
<br>
And the resourceFactory source:
<br>
<br>
public class Xpdl2ResourceFactoryImpl extends ResourceFactoryImpl {
<br>
/**
<br>
* @generated
<br>
*/
<br>
public Xpdl2ResourceFactoryImpl() {
<br>
super();
<br>
}
<br>
/**
<br>
* @generated
<br>
*/
<br>
public Resource createResourceGen(URI uri) {
<br>
XMLResource result = new Xpdl2ResourceImpl(uri);
<br>
result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
Boolean.TRUE);
<br>
result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
Boolean.TRUE);
<br>
<br>
result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
Boolean.TRUE);
<br>
<br>
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
Boolean.TRUE);
<br>
result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
Boolean.TRUE);
<br>
<br>
result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
Boolean.TRUE);
<br>
return result;
<br>
}
<br>
@Override
<br>
public Resource createResource(URI uri) {
<br>
XMLResource result = (XMLResource)createResourceGen(uri);
<br>
result.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODI NG,
"UTF-8");
<br>
result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODI NG,
"UTF-8");
<br>
// &nbs p; // &nbs p; // Where do we turn this off in the genmodel? What
is the name of the option?
<br>
// &nbs p;
result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
Boolean.TRUE);
<br>
// &nbs p; // &nbs p;
result.getDefaultLoadOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
Boolean.TRUE);
<br>
// &nbs p;
result.getDefaultSaveOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
Boolean.TRUE);
<br>
//
<br>
//result.getDefaultSaveOptions().put(XMLResource.OPTION_SKIP _ESCAPE,
Boolean.TRUE);
<br>
// &nbs p;
result.getDefaultSaveOptions().put(XMLResource.OPTION_ESCAPE _USING_CDATA,
Boolean.TRUE);
<br>
// &nbs p;
result.getDefaultSaveOptions().put(XMLResource.OPTION_FORMAT TED,
Boolean.TRUE);
<br>
// &nbs p; &nbs p; return result;
<br>
}
<br>
<br>
} //Xpdl2ResourceFactoryImpl
<br>
<br>
I hope this helps.
<br>
Ronaldo
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Ronaldo,
<br>
<br>
Comments below.
<br>
<br>
Ronaldo wrote:
<br>
<blockquote type="cite">Hi Ed,
<br>
<br>
I guess you're saying I'm messing around with a null namespace :0
<br>
Point is, it has worked and somehow I changed something and it doesn't
work any more.
<br>
I feel I'm losing control ...
<br>
</blockquote>
Something worked, but only you know what...
<br>
<blockquote type="cite"><br>
Anyway, I'll step back, and use proper namespaces ;)
<br>
<br>
My package is now only annotated with @model kind="package".
(Unqualified is removed)
<br>
</blockquote>
You've relaoaded the model?
<br>
<blockquote type="cite">The generated XYZExample now generates
<br>
<br>
<?xml version="1.0" encoding="UTF-8"?>
<br>
<Activities/>
<br>
<br>
So the question is, which piece of code is responsible for hiding the
namespace prefix?
<br>
</blockquote>
And has the resource factory been regenerated so it's using "TRUE"?
It doesn't look that way...
<br>
<blockquote type="cite"><br>
I'd expect something like
<br>
<?xml version="1.0" encoding="UTF-8"?>
<br>
<prefix:Activities xmlns:prefix="yadiyadi" />
<br>
</blockquote>
Me too. What's the nsURI of your EPackage?
<br>
<blockquote type="cite"><br>
Fun part is, after unloading the created and saved resource,
<br>
I reload it using the same resourceSet. But then, I get the famous
"Package with uri null not found" message...
<br>
because the prefix is missing...
<br>
</blockquote>
Something's is a little screwed up for sure... What does the resource
factory look like?
<br>
<blockquote type="cite"><br>
Ronaldo
<br>
<br>
<br>
<br>
<blockquote type="cite"><br>
<br>
Ronaldo wrote:
<br>
<blockquote type="cite">This error comes up when I run the
XYZExample test code, disguised as/copied to a UnitTest in maven. (ie
outside the eclipse editor).
<br>
It runs fine from within eclipse/junit. I figured it must have
something to do with
<br>
<a class="moz-txt-link-freetext" href=" http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F"> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F</a>,
<br>
does it?
<br>
<br>
The error is
<br>
<br>
java.lang.NullPointerException
<br>
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
<br>
</blockquote>
It's dying because the data type doesn't have a containing package and
hence we get a null pointer exception trying to get the factory for
that package?
<br>
<br>
EDataType d = (EDataType)f.getEType();
<br>
EPackage ePackage = d.getEPackage();
<br>
EFactory fac = ePackage.getEFactoryInstance();
<br>
<blockquote type="cite"> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
<br>
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
<br>
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
<br>
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
<br>
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
<br>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
<br>
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
<br>
<br>
Code:
<br>
<br>
MyModel1Package.eINSTANCE.eClass();
<br>
MyModel2Package.eINSTANCE.eClass();
<br>
ResourceSet resourceSet = new ResourceSetImpl();
<br>
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
<br>
("ext1", new MyModel1ResourceFactoryImpl());
<br>
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
<br>
(Resource.Factory.Registry.DEFAULT_EXTENSION,
<br>
new MyModel2ResourceFactoryImpl());
<br>
<br>
Resource resource =
resourceSet.createResource(URI.createURI(<a class="moz-txt-link-rfc2396E" href="http:///My.model.uri">"http:///My.model.uri"</a>));
<br>
DocumentRoot documentRoot =
MyModel2Factory.eINSTANCE.createDocumentRoot();
<br>
<br>
// ---- Removing the next two lines makes it work from maven too.
<br>
ActivitiesType root = MyModel2Factory.eINSTANCE.createActivitiesType();
<br>
documentRoot.setActivities(root);
<br>
<br>
resource.getContents().add(documentRoot);
<br>
resource.save(System.out, null);
<br>
</blockquote>
This looks much like the generated XyzExample you get when you invoke
"Generate Test Code". Does that have the same problem?
<br>
<blockquote type="cite"><br>
Many thanks,
<br>
Ronaldo
<br>
<br>
Ed Merks wrote:
<br>
> Ronaldo,
<br>
>
<br>
> Comments below.
<br>
>
<br>
> Ronaldo wrote:
<br>
>> Hi Ed,
<br>
>>
<br>
>> Thanks for the quick answer. Yes, I have 2 models in 2
different
<br>
>> eclipse projects.
<br>
>> They both use a null target namespace, in order to eliminate
the
<br>
>> prefixes in the xml.
<br>
> :-(
<br>
>
<br>
> XML documents with at least a namespace for the root element are
<br>
> generally more consumable because they identify their schema...
<br>
>>
<br>
>> I was just wondering what (which setting) causes the code
<br>
>>
<br>
>> result.getDefaultSaveOptions().put(
<br>
>> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
<br>
> A null target namespace schema produces an annotation on the
EPackage to
<br>
> indicate the package is not qualified.
<br>
>>
<br>
>> to be generated. (as opposed to
<br>
>>
<br>
>> result.getDefaultSaveOptions().put(
<br>
>> & ;nbsp; XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
<br>
> This package doesn't have such an annotation.
<br>
>
<br>
> Note that you can't have two different packages that both want to
be the
<br>
> one for the null namespace both working at the same time.
<br>
>> )
<br>
>>
<br>
>> Ronaldo
<br>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</body>
</html>
--------------000904030009000904070908--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423263 is a reply to message #423259] |
Thu, 25 September 2008 15:16 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Ronaldo,
Class names are always qualified but element and attributes may or may
not be depending on things like elementForm/elementFormDefault...
If you just set the target namespace on the schema and reloaded that
schema, everything would be more consistent than messing with the Ecore
or the @model stuff...
Ronaldo wrote:
> And another observation:
>
> I get:
> <?xml version="1.0" encoding="UTF-8"?>
> <xpdl2:Package xmlns:xpdl2="http://www.wfmc.org/2008/XPDL2.1" Id="1"/>
>
> When adding the PackageType (a model element) directly to the
> resource.getContents(),
> as in:
>
> Resource resource = xpdl2ResourceSet.createResource(uri);
> PackageType packageType = xpdl2Factory.createPackageType();
> resource.getContents().add(packageType);
>
>
> Before I used:
> Resource resource = xpdl2ResourceSet.createResource(uri);
> DocumentRoot documentRoot = xpdl2Factory.createDocumentRoot();
> PackageType packageType = xpdl2Factory.createPackageType();
> documentRoot.setPackage(packageType);
> resource.getContents().add(documentRoot);
>
> Ronaldo
>
>
> Ronaldo wrote:
>> I have something that might be noteworthy:
>> Somehow, I noticed that my genmodel consists of 4 models:
>>
>> Xpdl1 - Deprecated xpdl format
>> Xpdl2 - Current xpdl format
>> Ecore - (Icon contains a little arrow/referenced?)
>> XMLType - (Icon contains a little arrow/referenced?)
>>
>> The util package also contains an Xpdl2XMLProcessor class:
>>
>> public class Xpdl2XMLProcessor extends XMLProcessor {
>> public Xpdl2XMLProcessor() {
>> super((EPackage.Registry.INSTANCE));
>> Xpdl2Package.eINSTANCE.eClass();
>> }
>>
>> @Override
>> protected Map<String, Resource.Factory> getRegistrations() {
>> if (registrations == null) {
>> super.getRegistrations();
>> registrations.put(XML_EXTENSION, new
>> Xpdl2ResourceFactoryImpl());
>> registrations.put(STAR_EXTENSION, new
>> Xpdl2ResourceFactoryImpl());
>> }
>> return registrations;
>> }
>> }
>>
>> which seems a little odd. I hadn't noticed this before.
>>
>> Here's the EPackage source:
>>
>> public interface Xpdl2Package extends EPackage {
>> String eNS_URI = "http://www.wfmc.org/2008/XPDL2.1";
>> String eNS_PREFIX = "xpdl2";
>> Xpdl2Package eINSTANCE =
>> org.wfmc.xpdl21.xpdl2.impl.Xpdl2PackageImpl.init();
>> }
>>
>>
>> And the resourceFactory source:
>>
>> public class Xpdl2ResourceFactoryImpl extends ResourceFactoryImpl {
>> /**
>> * @generated
>> */
>> public Xpdl2ResourceFactoryImpl() {
>> super();
>> }
>> /**
>> * @generated
>> */
>> public Resource createResourceGen(URI uri) {
>> XMLResource result = new Xpdl2ResourceImpl(uri);
>>
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>> Boolean.TRUE);
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>> Boolean.TRUE);
>>
>>
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>> Boolean.TRUE);
>>
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>> Boolean.TRUE);
>>
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>> Boolean.TRUE);
>>
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
>> Boolean.TRUE);
>> return result;
>> }
>> @Override
>> public Resource createResource(URI uri) {
>> XMLResource result = (XMLResource)createResourceGen(uri);
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODI NG,
>> "UTF-8");
>>
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODI NG,
>> "UTF-8");
>> // // // Where do we turn this off in the genmodel? What
>> is the name of the option?
>> //
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>> Boolean.TRUE);
>> // //
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>> Boolean.TRUE);
>> //
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>> Boolean.TRUE);
>> //
>>
>> //result.getDefaultSaveOptions().put(XMLResource.OPTION_SKIP _ESCAPE,
>> Boolean.TRUE);
>> //
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ESCAPE _USING_CDATA,
>> Boolean.TRUE);
>> //
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_FORMAT TED,
>> Boolean.TRUE);
>> // return result;
>> }
>>
>> } //Xpdl2ResourceFactoryImpl
>>
>> I hope this helps.
>> Ronaldo
>>
>> Ed Merks wrote:
>>> Ronaldo,
>>>
>>> Comments below.
>>>
>>> Ronaldo wrote:
>>>> Hi Ed,
>>>>
>>>> I guess you're saying I'm messing around with a null namespace :0
>>>> Point is, it has worked and somehow I changed something and it
>>>> doesn't work any more.
>>>> I feel I'm losing control ...
>>> Something worked, but only you know what...
>>>>
>>>> Anyway, I'll step back, and use proper namespaces ;)
>>>>
>>>> My package is now only annotated with @model kind="package".
>>>> (Unqualified is removed)
>>> You've relaoaded the model?
>>>> The generated XYZExample now generates
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <Activities/>
>>>>
>>>> So the question is, which piece of code is responsible for hiding
>>>> the namespace prefix?
>>> And has the resource factory been regenerated so it's using
>>> "TRUE"? It doesn't look that way...
>>>>
>>>> I'd expect something like
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <prefix:Activities xmlns:prefix="yadiyadi" />
>>> Me too. What's the nsURI of your EPackage?
>>>>
>>>> Fun part is, after unloading the created and saved resource,
>>>> I reload it using the same resourceSet. But then, I get the famous
>>>> "Package with uri null not found" message...
>>>> because the prefix is missing...
>>> Something's is a little screwed up for sure... What does the
>>> resource factory look like?
>>>>
>>>> Ronaldo
>>>>
>>>>
>>>>
>>>>>
>>>>>
>>>>> Ronaldo wrote:
>>>>>> This error comes up when I run the XYZExample test code,
>>>>>> disguised as/copied to a UnitTest in maven. (ie outside the
>>>>>> eclipse editor).
>>>>>> It runs fine from within eclipse/junit. I figured it must have
>>>>>> something to do with
>>>>>> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>>>>>>
>>>>>> does it?
>>>>>>
>>>>>> The error is
>>>>>>
>>>>>> java.lang.NullPointerException
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>>>>>>
>>>>> It's dying because the data type doesn't have a containing package
>>>>> and hence we get a null pointer exception trying to get the
>>>>> factory for that package?
>>>>>
>>>>> EDataType d = (EDataType)f.getEType();
>>>>> EPackage ePackage = d.getEPackage();
>>>>> EFactory fac = ePackage.getEFactoryInstance();
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>>>>>>
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>>>>>>
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>>>>>>
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
>>>>>>
>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>>>>>>
>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>>>>>>
>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>>>>>>
>>>>>>
>>>>>> Code:
>>>>>>
>>>>>> MyModel1Package.eINSTANCE.eClass();
>>>>>> MyModel2Package.eINSTANCE.eClass();
>>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>
>>>>>> ("ext1", new MyModel1ResourceFactoryImpl());
>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>
>>>>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>>>>> new MyModel2ResourceFactoryImpl());
>>>>>>
>>>>>> Resource resource =
>>>>>> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
>>>>>> DocumentRoot documentRoot =
>>>>>> MyModel2Factory.eINSTANCE.createDocumentRoot();
>>>>>>
>>>>>> // ---- Removing the next two lines makes it work from maven too.
>>>>>> ActivitiesType root =
>>>>>> MyModel2Factory.eINSTANCE.createActivitiesType();
>>>>>> documentRoot.setActivities(root);
>>>>>>
>>>>>> resource.getContents().add(documentRoot);
>>>>>> resource.save(System.out, null);
>>>>> This looks much like the generated XyzExample you get when you
>>>>> invoke "Generate Test Code". Does that have the same problem?
>>>>>>
>>>>>> Many thanks,
>>>>>> Ronaldo
>>>>>>
>>>>>> Ed Merks wrote:
>>>>>> > Ronaldo,
>>>>>> >
>>>>>> > Comments below.
>>>>>> >
>>>>>> > Ronaldo wrote:
>>>>>> >> Hi Ed,
>>>>>> >>
>>>>>> >> Thanks for the quick answer. Yes, I have 2 models in 2 different
>>>>>> >> eclipse projects.
>>>>>> >> They both use a null target namespace, in order to eliminate the
>>>>>> >> prefixes in the xml.
>>>>>> > :-(
>>>>>> >
>>>>>> > XML documents with at least a namespace for the root element are
>>>>>> > generally more consumable because they identify their schema...
>>>>>> >>
>>>>>> >> I was just wondering what (which setting) causes the code
>>>>>> >>
>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
>>>>>> > A null target namespace schema produces an annotation on the
>>>>>> EPackage to
>>>>>> > indicate the package is not qualified.
>>>>>> >>
>>>>>> >> to be generated. (as opposed to
>>>>>> >>
>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>>>>>> > This package doesn't have such an annotation.
>>>>>> >
>>>>>> > Note that you can't have two different packages that both want
>>>>>> to be the
>>>>>> > one for the null namespace both working at the same time.
>>>>>> >> )
>>>>>> >>
>>>>>> >> Ronaldo
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423284 is a reply to message #423262] |
Fri, 26 September 2008 09:31 |
ronald Mising name Messages: 52 Registered: July 2009 |
Member |
|
|
Nope most elements didn't have a target namespace... I guess I'll have to add them manually to every element.
A little background might be usefull:
I started out with the xpdl2.1 XSD (http://www.wfmc.org/standards/bpmnxpdl_31.xsd) and created a model and generated java from that.
However, I have little experience with XSD's and decided it might be easier to reload from java annotations from that point on.
That might explain why I do have a DocumentRoot generated, a thing I don't have when generating the model from java annotations directly.
When it all seemed to work, I read posts like http://www.eclipsezone.com/eclipse/forums/t91748.html to eliminate the prefixes.
(Well I guess I misinterpreted them).
I also noted that all my interfaces are now annotated with a name='*_._type' in the extended metadata annotation.
I'd swear this was not the case earlier on.
I'm not sure if this is good or bad, as I read that this should be ok when using a DocumentRoot... (?)
( http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg2 6745.html)
But, as I'm not modifing the xsd but the java annotations instead and reloading the genmodel from these java annotations, do I still need that
(old?) documentroot?
I created a new testproject from java and indeed no documentroot was generated.
That would also explain why adding an element directly to the resource.getContents() did serialize ok,
while using an (old?) documentroot did not serialize ok.
I assumed that starting with an xsd, would create the same model as when you're starting from java...
But the documentroot thing shows that's not the case?
Ronaldo
Ed Merks wrote:
> Ronaldo,
>
> For the library mode it looks like this:
>
> * @model containment="true" upper="-2" transient="true"
> volatile="true" derived="true"
> * extendedMetaData="kind='element' name='library'*
> namespace='##targetNamespace'"*
>
> I assume these models originated from a schema. Do that schema have a
> target namespace?
>
>
> Ronaldo wrote:
>>
>> This is the generated code for the getActivities method in the
>> DocumentRoot interface.
>>
>> * @model containment="true" upper="-2" transient="true"
>> volatile="true" derived="true"
>> * extendedMetaData="kind='element' name='Activities'"
>> * @generated
>> */
>> ActivitiesType getActivities();
>>
>>
>>
>> Ed Merks wrote:
>>> Ronaldo,
>>>
>>> What EAnnotations does the "activities" feature of the DocumentRoot
>>> have on it?
>>>
>>>
>>> Ronaldo wrote:
>>>> I have something that might be noteworthy:
>>>> Somehow, I noticed that my genmodel consists of 4 models:
>>>>
>>>> Xpdl1 - Deprecated xpdl format
>>>> Xpdl2 - Current xpdl format
>>>> Ecore - (Icon contains a little arrow/referenced?)
>>>> XMLType - (Icon contains a little arrow/referenced?)
>>>>
>>>> The util package also contains an Xpdl2XMLProcessor class:
>>>>
>>>> public class Xpdl2XMLProcessor extends XMLProcessor {
>>>> public Xpdl2XMLProcessor() {
>>>> super((EPackage.Registry.INSTANCE));
>>>> Xpdl2Package.eINSTANCE.eClass();
>>>> }
>>>>
>>>> @Override
>>>> protected Map<String, Resource.Factory> getRegistrations() {
>>>> if (registrations == null) {
>>>> super.getRegistrations();
>>>> registrations.put(XML_EXTENSION, new
>>>> Xpdl2ResourceFactoryImpl());
>>>> registrations.put(STAR_EXTENSION, new
>>>> Xpdl2ResourceFactoryImpl());
>>>> }
>>>> return registrations;
>>>> }
>>>> }
>>>>
>>>> which seems a little odd. I hadn't noticed this before.
>>>>
>>>> Here's the EPackage source:
>>>>
>>>> public interface Xpdl2Package extends EPackage {
>>>> String eNS_URI = "http://www.wfmc.org/2008/XPDL2.1";
>>>> String eNS_PREFIX = "xpdl2";
>>>> Xpdl2Package eINSTANCE =
>>>> org.wfmc.xpdl21.xpdl2.impl.Xpdl2PackageImpl.init();
>>>> }
>>>>
>>>>
>>>> And the resourceFactory source:
>>>>
>>>> public class Xpdl2ResourceFactoryImpl extends ResourceFactoryImpl {
>>>> /**
>>>> * @generated
>>>> */
>>>> public Xpdl2ResourceFactoryImpl() {
>>>> super();
>>>> }
>>>> /**
>>>> * @generated
>>>> */
>>>> public Resource createResourceGen(URI uri) {
>>>> XMLResource result = new Xpdl2ResourceImpl(uri);
>>>>
>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>>>> Boolean.TRUE);
>>>>
>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>>>> Boolean.TRUE);
>>>>
>>>>
>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>>>> Boolean.TRUE);
>>>>
>>>>
>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>>>> Boolean.TRUE);
>>>>
>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>>>> Boolean.TRUE);
>>>>
>>>>
>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
>>>> Boolean.TRUE);
>>>> return result;
>>>> }
>>>> @Override
>>>> public Resource createResource(URI uri) {
>>>> XMLResource result = (XMLResource)createResourceGen(uri);
>>>>
>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODI NG,
>>>> "UTF-8");
>>>>
>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODI NG,
>>>> "UTF-8");
>>>> // // // Where do we turn this off in the genmodel?
>>>> What is the name of the option?
>>>> //
>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>>>> Boolean.TRUE);
>>>> // //
>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>>>> Boolean.TRUE);
>>>> //
>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>>>> Boolean.TRUE);
>>>> //
>>>>
>>>> //result.getDefaultSaveOptions().put(XMLResource.OPTION_SKIP _ESCAPE,
>>>> Boolean.TRUE);
>>>> //
>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ESCAPE _USING_CDATA,
>>>> Boolean.TRUE);
>>>> //
>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_FORMAT TED,
>>>> Boolean.TRUE);
>>>> // return result;
>>>> }
>>>>
>>>> } //Xpdl2ResourceFactoryImpl
>>>>
>>>> I hope this helps.
>>>> Ronaldo
>>>>
>>>> Ed Merks wrote:
>>>>> Ronaldo,
>>>>>
>>>>> Comments below.
>>>>>
>>>>> Ronaldo wrote:
>>>>>> Hi Ed,
>>>>>>
>>>>>> I guess you're saying I'm messing around with a null namespace :0
>>>>>> Point is, it has worked and somehow I changed something and it
>>>>>> doesn't work any more.
>>>>>> I feel I'm losing control ...
>>>>> Something worked, but only you know what...
>>>>>>
>>>>>> Anyway, I'll step back, and use proper namespaces ;)
>>>>>>
>>>>>> My package is now only annotated with @model kind="package".
>>>>>> (Unqualified is removed)
>>>>> You've relaoaded the model?
>>>>>> The generated XYZExample now generates
>>>>>>
>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>> <Activities/>
>>>>>>
>>>>>> So the question is, which piece of code is responsible for hiding
>>>>>> the namespace prefix?
>>>>> And has the resource factory been regenerated so it's using
>>>>> "TRUE"? It doesn't look that way...
>>>>>>
>>>>>> I'd expect something like
>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>> <prefix:Activities xmlns:prefix="yadiyadi" />
>>>>> Me too. What's the nsURI of your EPackage?
>>>>>>
>>>>>> Fun part is, after unloading the created and saved resource,
>>>>>> I reload it using the same resourceSet. But then, I get the famous
>>>>>> "Package with uri null not found" message...
>>>>>> because the prefix is missing...
>>>>> Something's is a little screwed up for sure... What does the
>>>>> resource factory look like?
>>>>>>
>>>>>> Ronaldo
>>>>>>
>>>>>>
>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Ronaldo wrote:
>>>>>>>> This error comes up when I run the XYZExample test code,
>>>>>>>> disguised as/copied to a UnitTest in maven. (ie outside the
>>>>>>>> eclipse editor).
>>>>>>>> It runs fine from within eclipse/junit. I figured it must have
>>>>>>>> something to do with
>>>>>>>> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>>>>>>>>
>>>>>>>> does it?
>>>>>>>>
>>>>>>>> The error is
>>>>>>>>
>>>>>>>> java.lang.NullPointerException
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>>>>>>>>
>>>>>>> It's dying because the data type doesn't have a containing
>>>>>>> package and hence we get a null pointer exception trying to get
>>>>>>> the factory for that package?
>>>>>>>
>>>>>>> EDataType d = (EDataType)f.getEType();
>>>>>>> EPackage ePackage = d.getEPackage();
>>>>>>> EFactory fac = ePackage.getEFactoryInstance();
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>>>>>>>>
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>>>>>>>>
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>>>>>>>>
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
>>>>>>>>
>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>>>>>>>>
>>>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>>>>>>>>
>>>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>>>>>>>>
>>>>>>>>
>>>>>>>> Code:
>>>>>>>>
>>>>>>>> MyModel1Package.eINSTANCE.eClass();
>>>>>>>> MyModel2Package.eINSTANCE.eClass();
>>>>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>>>
>>>>>>>> ("ext1", new MyModel1ResourceFactoryImpl());
>>>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>>>
>>>>>>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>>>>>>> new MyModel2ResourceFactoryImpl());
>>>>>>>>
>>>>>>>> Resource resource =
>>>>>>>> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
>>>>>>>> DocumentRoot documentRoot =
>>>>>>>> MyModel2Factory.eINSTANCE.createDocumentRoot();
>>>>>>>>
>>>>>>>> // ---- Removing the next two lines makes it work from maven too.
>>>>>>>> ActivitiesType root =
>>>>>>>> MyModel2Factory.eINSTANCE.createActivitiesType();
>>>>>>>> documentRoot.setActivities(root);
>>>>>>>>
>>>>>>>> resource.getContents().add(documentRoot);
>>>>>>>> resource.save(System.out, null);
>>>>>>> This looks much like the generated XyzExample you get when you
>>>>>>> invoke "Generate Test Code". Does that have the same problem?
>>>>>>>>
>>>>>>>> Many thanks,
>>>>>>>> Ronaldo
>>>>>>>>
>>>>>>>> Ed Merks wrote:
>>>>>>>> > Ronaldo,
>>>>>>>> >
>>>>>>>> > Comments below.
>>>>>>>> >
>>>>>>>> > Ronaldo wrote:
>>>>>>>> >> Hi Ed,
>>>>>>>> >>
>>>>>>>> >> Thanks for the quick answer. Yes, I have 2 models in 2 different
>>>>>>>> >> eclipse projects.
>>>>>>>> >> They both use a null target namespace, in order to eliminate the
>>>>>>>> >> prefixes in the xml.
>>>>>>>> > :-(
>>>>>>>> >
>>>>>>>> > XML documents with at least a namespace for the root element are
>>>>>>>> > generally more consumable because they identify their schema...
>>>>>>>> >>
>>>>>>>> >> I was just wondering what (which setting) causes the code
>>>>>>>> >>
>>>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
>>>>>>>> > A null target namespace schema produces an annotation on the
>>>>>>>> EPackage to
>>>>>>>> > indicate the package is not qualified.
>>>>>>>> >>
>>>>>>>> >> to be generated. (as opposed to
>>>>>>>> >>
>>>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>>>>>>>> > This package doesn't have such an annotation.
>>>>>>>> >
>>>>>>>> > Note that you can't have two different packages that both want
>>>>>>>> to be the
>>>>>>>> > one for the null namespace both working at the same time.
>>>>>>>> >> )
>>>>>>>> >>
>>>>>>>> >> Ronaldo
|
|
|
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423291 is a reply to message #423284] |
Fri, 26 September 2008 11:33 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Ronaldo,
Comments below.
Ronaldo wrote:
> Nope most elements didn't have a target namespace... I guess I'll have
> to add them manually to every element.
>
> A little background might be usefull:
> I started out with the xpdl2.1 XSD
> (http://www.wfmc.org/standards/bpmnxpdl_31.xsd) and created a model
> and generated java from that.
That one had a target namespace.
> However, I have little experience with XSD's and decided it might be
> easier to reload from java annotations from that point on.
Did you know you can export your Ecore to XSD? Keep in mind though that
XSD -> Ecore -> XSD is not a round trip because XSD -> Ecore is slightly
lossy. But Ecore -> XSD -> Ecore is supposed to be a round trip because
we generate all the necessary ecore:* annotations to make it roundtrip.
Using this mechanism, you could discover what you needed to change in
the original XSD to produce the desired Ecore...
>
> That might explain why I do have a DocumentRoot generated, a thing I
> don't have when generating the model from java annotations directly.
We, given sufficient annotations of the right form, you'll get the same
thing. The Ecore -> Java with @model -> Ecore is supposed to be a round
trip after all...
> When it all seemed to work, I read posts like
> http://www.eclipsezone.com/eclipse/forums/t91748.html to eliminate the
> prefixes.
> (Well I guess I misinterpreted them).
A better way to have eliminated the prefixes is to use
DocumentRoot.getXMLNSPrefixMap().put("", XyzPackage.eNS_URI). This way
you end up with an xmlns="<nsURI>" in the document and all elements will
be implicitly qualified by this namespace. Of course attributes will
still need explicit qualification, so I'm not sure you'd be totally
happy with the result. But given that I assume you want the
serialization to conform to the schema and the schema requires qualified
local elements and attributes, I don't think you have all that much choice.
>
> I also noted that all my interfaces are now annotated with a
> name='*_._type' in the extended metadata annotation.
This comes from anonymous type definitions.
> I'd swear this was not the case earlier on.
> I'm not sure if this is good or bad, as I read that this should be ok
> when using a DocumentRoot... (?)
> ( http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg2 6745.html)
An anonymous type can never be used in an xsi:type. Sometimes that fact
can be used to deduce a more appropriate element name...
> But, as I'm not modifing the xsd but the java annotations instead and
> reloading the genmodel from these java annotations, do I still need
> that (old?) documentroot?
The document root determines the appropriate element name at the root of
the document. Without a document root, the name of the type will be
used as the root element name, but that's not going to conform to the
schema since a schema will always specify a global element to use for
the root.
> I created a new testproject from java and indeed no documentroot was
> generated.
Not sure about that. The DocumentRoot interface has @model on it, so I
assume you'd have to delete that for it to just disappear...
>
>
> That would also explain why adding an element directly to the
> resource.getContents() did serialize ok,
> while using an (old?) documentroot did not serialize ok.
If you're okay with a serialization that doesn't conform to the schema
then it's okay. The document root serialization issue was a result of
inconsistent annotations (annotations that would never have been
produced from a real schema).
>
> I assumed that starting with an xsd, would create the same model as
> when you're starting from java...
Given the corresponding annotations, yes.
> But the documentroot thing shows that's not the case?
I'm sure you've left out a little detail. After all, you've already
mentioned reloading the model from the @model changes and that didn't
make the DocumentRoot disappear... When reading the newsgroups for a
long time you start to learn that people leave out tiny but little
important details. :-P
>
>
> Ronaldo
>
>
> Ed Merks wrote:
>> Ronaldo,
>>
>> For the library mode it looks like this:
>>
>> * @model containment="true" upper="-2" transient="true"
>> volatile="true" derived="true"
>> * extendedMetaData="kind='element' name='library'*
>> namespace='##targetNamespace'"*
>>
>> I assume these models originated from a schema. Do that schema have
>> a target namespace?
>>
>>
>> Ronaldo wrote:
>>>
>>> This is the generated code for the getActivities method in the
>>> DocumentRoot interface.
>>>
>>> * @model containment="true" upper="-2" transient="true"
>>> volatile="true" derived="true"
>>> * extendedMetaData="kind='element' name='Activities'"
>>> * @generated
>>> */
>>> ActivitiesType getActivities();
>>>
>>>
>>>
>>> Ed Merks wrote:
>>>> Ronaldo,
>>>>
>>>> What EAnnotations does the "activities" feature of the DocumentRoot
>>>> have on it?
>>>>
>>>>
>>>> Ronaldo wrote:
>>>>> I have something that might be noteworthy:
>>>>> Somehow, I noticed that my genmodel consists of 4 models:
>>>>>
>>>>> Xpdl1 - Deprecated xpdl format
>>>>> Xpdl2 - Current xpdl format
>>>>> Ecore - (Icon contains a little arrow/referenced?)
>>>>> XMLType - (Icon contains a little arrow/referenced?)
>>>>>
>>>>> The util package also contains an Xpdl2XMLProcessor class:
>>>>>
>>>>> public class Xpdl2XMLProcessor extends XMLProcessor {
>>>>> public Xpdl2XMLProcessor() {
>>>>> super((EPackage.Registry.INSTANCE));
>>>>> Xpdl2Package.eINSTANCE.eClass();
>>>>> }
>>>>>
>>>>> @Override
>>>>> protected Map<String, Resource.Factory> getRegistrations() {
>>>>> if (registrations == null) {
>>>>> super.getRegistrations();
>>>>> registrations.put(XML_EXTENSION, new
>>>>> Xpdl2ResourceFactoryImpl());
>>>>> registrations.put(STAR_EXTENSION, new
>>>>> Xpdl2ResourceFactoryImpl());
>>>>> }
>>>>> return registrations;
>>>>> }
>>>>> }
>>>>>
>>>>> which seems a little odd. I hadn't noticed this before.
>>>>>
>>>>> Here's the EPackage source:
>>>>>
>>>>> public interface Xpdl2Package extends EPackage {
>>>>> String eNS_URI = "http://www.wfmc.org/2008/XPDL2.1";
>>>>> String eNS_PREFIX = "xpdl2";
>>>>> Xpdl2Package eINSTANCE =
>>>>> org.wfmc.xpdl21.xpdl2.impl.Xpdl2PackageImpl.init();
>>>>> }
>>>>>
>>>>>
>>>>> And the resourceFactory source:
>>>>>
>>>>> public class Xpdl2ResourceFactoryImpl extends ResourceFactoryImpl {
>>>>> /**
>>>>> * @generated
>>>>> */
>>>>> public Xpdl2ResourceFactoryImpl() {
>>>>> super();
>>>>> }
>>>>> /**
>>>>> * @generated
>>>>> */
>>>>> public Resource createResourceGen(URI uri) {
>>>>> XMLResource result = new Xpdl2ResourceImpl(uri);
>>>>>
>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>>>>> Boolean.TRUE);
>>>>>
>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>>>>> Boolean.TRUE);
>>>>>
>>>>>
>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>>>>> Boolean.TRUE);
>>>>>
>>>>>
>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>>>>> Boolean.TRUE);
>>>>>
>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>>>>> Boolean.TRUE);
>>>>>
>>>>>
>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
>>>>> Boolean.TRUE);
>>>>> return result;
>>>>> }
>>>>> @Override
>>>>> public Resource createResource(URI uri) {
>>>>> XMLResource result = (XMLResource)createResourceGen(uri);
>>>>>
>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODI NG,
>>>>> "UTF-8");
>>>>>
>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODI NG,
>>>>> "UTF-8");
>>>>> // // // Where do we turn this off in the genmodel?
>>>>> What is the name of the option?
>>>>> //
>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>>>>> Boolean.TRUE);
>>>>> // //
>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>>>>> Boolean.TRUE);
>>>>> //
>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>>>>> Boolean.TRUE);
>>>>> //
>>>>>
>>>>> //result.getDefaultSaveOptions().put(XMLResource.OPTION_SKIP _ESCAPE,
>>>>> Boolean.TRUE);
>>>>> //
>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ESCAPE _USING_CDATA,
>>>>> Boolean.TRUE);
>>>>> //
>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_FORMAT TED,
>>>>> Boolean.TRUE);
>>>>> // return result;
>>>>> }
>>>>>
>>>>> } //Xpdl2ResourceFactoryImpl
>>>>>
>>>>> I hope this helps.
>>>>> Ronaldo
>>>>>
>>>>> Ed Merks wrote:
>>>>>> Ronaldo,
>>>>>>
>>>>>> Comments below.
>>>>>>
>>>>>> Ronaldo wrote:
>>>>>>> Hi Ed,
>>>>>>>
>>>>>>> I guess you're saying I'm messing around with a null namespace :0
>>>>>>> Point is, it has worked and somehow I changed something and it
>>>>>>> doesn't work any more.
>>>>>>> I feel I'm losing control ...
>>>>>> Something worked, but only you know what...
>>>>>>>
>>>>>>> Anyway, I'll step back, and use proper namespaces ;)
>>>>>>>
>>>>>>> My package is now only annotated with @model kind="package".
>>>>>>> (Unqualified is removed)
>>>>>> You've relaoaded the model?
>>>>>>> The generated XYZExample now generates
>>>>>>>
>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>> <Activities/>
>>>>>>>
>>>>>>> So the question is, which piece of code is responsible for
>>>>>>> hiding the namespace prefix?
>>>>>> And has the resource factory been regenerated so it's using
>>>>>> "TRUE"? It doesn't look that way...
>>>>>>>
>>>>>>> I'd expect something like
>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>> <prefix:Activities xmlns:prefix="yadiyadi" />
>>>>>> Me too. What's the nsURI of your EPackage?
>>>>>>>
>>>>>>> Fun part is, after unloading the created and saved resource,
>>>>>>> I reload it using the same resourceSet. But then, I get the
>>>>>>> famous "Package with uri null not found" message...
>>>>>>> because the prefix is missing...
>>>>>> Something's is a little screwed up for sure... What does the
>>>>>> resource factory look like?
>>>>>>>
>>>>>>> Ronaldo
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Ronaldo wrote:
>>>>>>>>> This error comes up when I run the XYZExample test code,
>>>>>>>>> disguised as/copied to a UnitTest in maven. (ie outside the
>>>>>>>>> eclipse editor).
>>>>>>>>> It runs fine from within eclipse/junit. I figured it must have
>>>>>>>>> something to do with
>>>>>>>>> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>>>>>>>>>
>>>>>>>>> does it?
>>>>>>>>>
>>>>>>>>> The error is
>>>>>>>>>
>>>>>>>>> java.lang.NullPointerException
>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>>>>>>>>>
>>>>>>>> It's dying because the data type doesn't have a containing
>>>>>>>> package and hence we get a null pointer exception trying to get
>>>>>>>> the factory for that package?
>>>>>>>>
>>>>>>>> EDataType d = (EDataType)f.getEType();
>>>>>>>> EPackage ePackage = d.getEPackage();
>>>>>>>> EFactory fac = ePackage.getEFactoryInstance();
>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>>>>>>>>>
>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>>>>>>>>>
>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>>>>>>>>>
>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
>>>>>>>>>
>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>>>>>>>>>
>>>>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>>>>>>>>>
>>>>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Code:
>>>>>>>>>
>>>>>>>>> MyModel1Package.eINSTANCE.eClass();
>>>>>>>>> MyModel2Package.eINSTANCE.eClass();
>>>>>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>>>>
>>>>>>>>> ("ext1", new MyModel1ResourceFactoryImpl());
>>>>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>>>>
>>>>>>>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>>>>>>>> new MyModel2ResourceFactoryImpl());
>>>>>>>>>
>>>>>>>>> Resource resource =
>>>>>>>>> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
>>>>>>>>>
>>>>>>>>> DocumentRoot documentRoot =
>>>>>>>>> MyModel2Factory.eINSTANCE.createDocumentRoot();
>>>>>>>>>
>>>>>>>>> // ---- Removing the next two lines makes it work from maven too.
>>>>>>>>> ActivitiesType root =
>>>>>>>>> MyModel2Factory.eINSTANCE.createActivitiesType();
>>>>>>>>> documentRoot.setActivities(root);
>>>>>>>>>
>>>>>>>>> resource.getContents().add(documentRoot);
>>>>>>>>> resource.save(System.out, null);
>>>>>>>> This looks much like the generated XyzExample you get when you
>>>>>>>> invoke "Generate Test Code". Does that have the same problem?
>>>>>>>>>
>>>>>>>>> Many thanks,
>>>>>>>>> Ronaldo
>>>>>>>>>
>>>>>>>>> Ed Merks wrote:
>>>>>>>>> > Ronaldo,
>>>>>>>>> >
>>>>>>>>> > Comments below.
>>>>>>>>> >
>>>>>>>>> > Ronaldo wrote:
>>>>>>>>> >> Hi Ed,
>>>>>>>>> >>
>>>>>>>>> >> Thanks for the quick answer. Yes, I have 2 models in 2
>>>>>>>>> different
>>>>>>>>> >> eclipse projects.
>>>>>>>>> >> They both use a null target namespace, in order to
>>>>>>>>> eliminate the
>>>>>>>>> >> prefixes in the xml.
>>>>>>>>> > :-(
>>>>>>>>> >
>>>>>>>>> > XML documents with at least a namespace for the root element
>>>>>>>>> are
>>>>>>>>> > generally more consumable because they identify their
>>>>>>>>> schema...
>>>>>>>>> >>
>>>>>>>>> >> I was just wondering what (which setting) causes the code
>>>>>>>>> >>
>>>>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
>>>>>>>>> > A null target namespace schema produces an annotation on the
>>>>>>>>> EPackage to
>>>>>>>>> > indicate the package is not qualified.
>>>>>>>>> >>
>>>>>>>>> >> to be generated. (as opposed to
>>>>>>>>> >>
>>>>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>>>>>>>>> > This package doesn't have such an annotation.
>>>>>>>>> >
>>>>>>>>> > Note that you can't have two different packages that both
>>>>>>>>> want to be the
>>>>>>>>> > one for the null namespace both working at the same time.
>>>>>>>>> >> )
>>>>>>>>> >>
>>>>>>>>> >> Ronaldo
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423294 is a reply to message #423291] |
Fri, 26 September 2008 12:04 |
ronald Mising name Messages: 52 Registered: July 2009 |
Member |
|
|
Hi Ed,
Thanks for the extensive answers. Yes, I'm sure I've left out something, if I only knew what...
I decided to take a step back, create a new project and reload the xsd again.
Then, step by step I'll try to find the solution.
Unfortunately, importing the xsd (http://www.wfmc.org/standards/bpmnxpdl_31.xsd) shows errors, see attachment.
I cannot tell if the xsd is not ok or if there's an error somewhere in emf.
Ronaldo
Ed Merks wrote:
> Ronaldo,
>
> Comments below.
>
> Ronaldo wrote:
>> Nope most elements didn't have a target namespace... I guess I'll have
>> to add them manually to every element.
>>
>> A little background might be usefull:
>> I started out with the xpdl2.1 XSD
>> (http://www.wfmc.org/standards/bpmnxpdl_31.xsd) and created a model
>> and generated java from that.
> That one had a target namespace.
>> However, I have little experience with XSD's and decided it might be
>> easier to reload from java annotations from that point on.
> Did you know you can export your Ecore to XSD? Keep in mind though that
> XSD -> Ecore -> XSD is not a round trip because XSD -> Ecore is slightly
> lossy. But Ecore -> XSD -> Ecore is supposed to be a round trip because
> we generate all the necessary ecore:* annotations to make it roundtrip.
> Using this mechanism, you could discover what you needed to change in
> the original XSD to produce the desired Ecore...
>>
>> That might explain why I do have a DocumentRoot generated, a thing I
>> don't have when generating the model from java annotations directly.
> We, given sufficient annotations of the right form, you'll get the same
> thing. The Ecore -> Java with @model -> Ecore is supposed to be a round
> trip after all...
>> When it all seemed to work, I read posts like
>> http://www.eclipsezone.com/eclipse/forums/t91748.html to eliminate the
>> prefixes.
>> (Well I guess I misinterpreted them).
> A better way to have eliminated the prefixes is to use
> DocumentRoot.getXMLNSPrefixMap().put("", XyzPackage.eNS_URI). This way
> you end up with an xmlns="<nsURI>" in the document and all elements will
> be implicitly qualified by this namespace. Of course attributes will
> still need explicit qualification, so I'm not sure you'd be totally
> happy with the result. But given that I assume you want the
> serialization to conform to the schema and the schema requires qualified
> local elements and attributes, I don't think you have all that much choice.
>>
>> I also noted that all my interfaces are now annotated with a
>> name='*_._type' in the extended metadata annotation.
> This comes from anonymous type definitions.
>> I'd swear this was not the case earlier on.
>> I'm not sure if this is good or bad, as I read that this should be ok
>> when using a DocumentRoot... (?)
>> ( http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg2 6745.html)
> An anonymous type can never be used in an xsi:type. Sometimes that fact
> can be used to deduce a more appropriate element name...
>> But, as I'm not modifing the xsd but the java annotations instead and
>> reloading the genmodel from these java annotations, do I still need
>> that (old?) documentroot?
> The document root determines the appropriate element name at the root of
> the document. Without a document root, the name of the type will be
> used as the root element name, but that's not going to conform to the
> schema since a schema will always specify a global element to use for
> the root.
>> I created a new testproject from java and indeed no documentroot was
>> generated.
> Not sure about that. The DocumentRoot interface has @model on it, so I
> assume you'd have to delete that for it to just disappear...
>>
>>
>> That would also explain why adding an element directly to the
>> resource.getContents() did serialize ok,
>> while using an (old?) documentroot did not serialize ok.
> If you're okay with a serialization that doesn't conform to the schema
> then it's okay. The document root serialization issue was a result of
> inconsistent annotations (annotations that would never have been
> produced from a real schema).
>>
>> I assumed that starting with an xsd, would create the same model as
>> when you're starting from java...
> Given the corresponding annotations, yes.
>> But the documentroot thing shows that's not the case?
> I'm sure you've left out a little detail. After all, you've already
> mentioned reloading the model from the @model changes and that didn't
> make the DocumentRoot disappear... When reading the newsgroups for a
> long time you start to learn that people leave out tiny but little
> important details. :-P
>>
>>
>> Ronaldo
>>
>>
>> Ed Merks wrote:
>>> Ronaldo,
>>>
>>> For the library mode it looks like this:
>>>
>>> * @model containment="true" upper="-2" transient="true"
>>> volatile="true" derived="true"
>>> * extendedMetaData="kind='element' name='library'*
>>> namespace='##targetNamespace'"*
>>>
>>> I assume these models originated from a schema. Do that schema have
>>> a target namespace?
>>>
>>>
>>> Ronaldo wrote:
>>>>
>>>> This is the generated code for the getActivities method in the
>>>> DocumentRoot interface.
>>>>
>>>> * @model containment="true" upper="-2" transient="true"
>>>> volatile="true" derived="true"
>>>> * extendedMetaData="kind='element' name='Activities'"
>>>> * @generated
>>>> */
>>>> ActivitiesType getActivities();
>>>>
>>>>
>>>>
>>>> Ed Merks wrote:
>>>>> Ronaldo,
>>>>>
>>>>> What EAnnotations does the "activities" feature of the DocumentRoot
>>>>> have on it?
>>>>>
>>>>>
>>>>> Ronaldo wrote:
>>>>>> I have something that might be noteworthy:
>>>>>> Somehow, I noticed that my genmodel consists of 4 models:
>>>>>>
>>>>>> Xpdl1 - Deprecated xpdl format
>>>>>> Xpdl2 - Current xpdl format
>>>>>> Ecore - (Icon contains a little arrow/referenced?)
>>>>>> XMLType - (Icon contains a little arrow/referenced?)
>>>>>>
>>>>>> The util package also contains an Xpdl2XMLProcessor class:
>>>>>>
>>>>>> public class Xpdl2XMLProcessor extends XMLProcessor {
>>>>>> public Xpdl2XMLProcessor() {
>>>>>> super((EPackage.Registry.INSTANCE));
>>>>>> Xpdl2Package.eINSTANCE.eClass();
>>>>>> }
>>>>>>
>>>>>> @Override
>>>>>> protected Map<String, Resource.Factory> getRegistrations() {
>>>>>> if (registrations == null) {
>>>>>> super.getRegistrations();
>>>>>> registrations.put(XML_EXTENSION, new
>>>>>> Xpdl2ResourceFactoryImpl());
>>>>>> registrations.put(STAR_EXTENSION, new
>>>>>> Xpdl2ResourceFactoryImpl());
>>>>>> }
>>>>>> return registrations;
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> which seems a little odd. I hadn't noticed this before.
>>>>>>
>>>>>> Here's the EPackage source:
>>>>>>
>>>>>> public interface Xpdl2Package extends EPackage {
>>>>>> String eNS_URI = "http://www.wfmc.org/2008/XPDL2.1";
>>>>>> String eNS_PREFIX = "xpdl2";
>>>>>> Xpdl2Package eINSTANCE =
>>>>>> org.wfmc.xpdl21.xpdl2.impl.Xpdl2PackageImpl.init();
>>>>>> }
>>>>>>
>>>>>>
>>>>>> And the resourceFactory source:
>>>>>>
>>>>>> public class Xpdl2ResourceFactoryImpl extends ResourceFactoryImpl {
>>>>>> /**
>>>>>> * @generated
>>>>>> */
>>>>>> public Xpdl2ResourceFactoryImpl() {
>>>>>> super();
>>>>>> }
>>>>>> /**
>>>>>> * @generated
>>>>>> */
>>>>>> public Resource createResourceGen(URI uri) {
>>>>>> XMLResource result = new Xpdl2ResourceImpl(uri);
>>>>>>
>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>>>>>> Boolean.TRUE);
>>>>>>
>>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>>>>>> Boolean.TRUE);
>>>>>>
>>>>>>
>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>>>>>> Boolean.TRUE);
>>>>>>
>>>>>>
>>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>>>>>> Boolean.TRUE);
>>>>>>
>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>>>>>> Boolean.TRUE);
>>>>>>
>>>>>>
>>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
>>>>>> Boolean.TRUE);
>>>>>> return result;
>>>>>> }
>>>>>> @Override
>>>>>> public Resource createResource(URI uri) {
>>>>>> XMLResource result = (XMLResource)createResourceGen(uri);
>>>>>>
>>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODI NG,
>>>>>> "UTF-8");
>>>>>>
>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODI NG,
>>>>>> "UTF-8");
>>>>>> // // // Where do we turn this off in the genmodel?
>>>>>> What is the name of the option?
>>>>>> //
>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>>>>>> Boolean.TRUE);
>>>>>> // //
>>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>>>>>> Boolean.TRUE);
>>>>>> //
>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>>>>>> Boolean.TRUE);
>>>>>> //
>>>>>>
>>>>>> //result.getDefaultSaveOptions().put(XMLResource.OPTION_SKIP _ESCAPE,
>>>>>> Boolean.TRUE);
>>>>>> //
>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ESCAPE _USING_CDATA,
>>>>>> Boolean.TRUE);
>>>>>> //
>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_FORMAT TED,
>>>>>> Boolean.TRUE);
>>>>>> // return result;
>>>>>> }
>>>>>>
>>>>>> } //Xpdl2ResourceFactoryImpl
>>>>>>
>>>>>> I hope this helps.
>>>>>> Ronaldo
>>>>>>
>>>>>> Ed Merks wrote:
>>>>>>> Ronaldo,
>>>>>>>
>>>>>>> Comments below.
>>>>>>>
>>>>>>> Ronaldo wrote:
>>>>>>>> Hi Ed,
>>>>>>>>
>>>>>>>> I guess you're saying I'm messing around with a null namespace :0
>>>>>>>> Point is, it has worked and somehow I changed something and it
>>>>>>>> doesn't work any more.
>>>>>>>> I feel I'm losing control ...
>>>>>>> Something worked, but only you know what...
>>>>>>>>
>>>>>>>> Anyway, I'll step back, and use proper namespaces ;)
>>>>>>>>
>>>>>>>> My package is now only annotated with @model kind="package".
>>>>>>>> (Unqualified is removed)
>>>>>>> You've relaoaded the model?
>>>>>>>> The generated XYZExample now generates
>>>>>>>>
>>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>> <Activities/>
>>>>>>>>
>>>>>>>> So the question is, which piece of code is responsible for
>>>>>>>> hiding the namespace prefix?
>>>>>>> And has the resource factory been regenerated so it's using
>>>>>>> "TRUE"? It doesn't look that way...
>>>>>>>>
>>>>>>>> I'd expect something like
>>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>> <prefix:Activities xmlns:prefix="yadiyadi" />
>>>>>>> Me too. What's the nsURI of your EPackage?
>>>>>>>>
>>>>>>>> Fun part is, after unloading the created and saved resource,
>>>>>>>> I reload it using the same resourceSet. But then, I get the
>>>>>>>> famous "Package with uri null not found" message...
>>>>>>>> because the prefix is missing...
>>>>>>> Something's is a little screwed up for sure... What does the
>>>>>>> resource factory look like?
>>>>>>>>
>>>>>>>> Ronaldo
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Ronaldo wrote:
>>>>>>>>>> This error comes up when I run the XYZExample test code,
>>>>>>>>>> disguised as/copied to a UnitTest in maven. (ie outside the
>>>>>>>>>> eclipse editor).
>>>>>>>>>> It runs fine from within eclipse/junit. I figured it must have
>>>>>>>>>> something to do with
>>>>>>>>>> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>>>>>>>>>>
>>>>>>>>>> does it?
>>>>>>>>>>
>>>>>>>>>> The error is
>>>>>>>>>>
>>>>>>>>>> java.lang.NullPointerException
>>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>>>>>>>>>>
>>>>>>>>> It's dying because the data type doesn't have a containing
>>>>>>>>> package and hence we get a null pointer exception trying to get
>>>>>>>>> the factory for that package?
>>>>>>>>>
>>>>>>>>> EDataType d = (EDataType)f.getEType();
>>>>>>>>> EPackage ePackage = d.getEPackage();
>>>>>>>>> EFactory fac = ePackage.getEFactoryInstance();
>>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>>>>>>>>>>
>>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>>>>>>>>>>
>>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>>>>>>>>>>
>>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
>>>>>>>>>>
>>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>>>>>>>>>>
>>>>>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>>>>>>>>>>
>>>>>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Code:
>>>>>>>>>>
>>>>>>>>>> MyModel1Package.eINSTANCE.eClass();
>>>>>>>>>> MyModel2Package.eINSTANCE.eClass();
>>>>>>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>>>>>
>>>>>>>>>> ("ext1", new MyModel1ResourceFactoryImpl());
>>>>>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>>>>>
>>>>>>>>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>>>>>>>>> new MyModel2ResourceFactoryImpl());
>>>>>>>>>>
>>>>>>>>>> Resource resource =
>>>>>>>>>> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
>>>>>>>>>>
>>>>>>>>>> DocumentRoot documentRoot =
>>>>>>>>>> MyModel2Factory.eINSTANCE.createDocumentRoot();
>>>>>>>>>>
>>>>>>>>>> // ---- Removing the next two lines makes it work from maven too.
>>>>>>>>>> ActivitiesType root =
>>>>>>>>>> MyModel2Factory.eINSTANCE.createActivitiesType();
>>>>>>>>>> documentRoot.setActivities(root);
>>>>>>>>>>
>>>>>>>>>> resource.getContents().add(documentRoot);
>>>>>>>>>> resource.save(System.out, null);
>>>>>>>>> This looks much like the generated XyzExample you get when you
>>>>>>>>> invoke "Generate Test Code". Does that have the same problem?
>>>>>>>>>>
>>>>>>>>>> Many thanks,
>>>>>>>>>> Ronaldo
>>>>>>>>>>
>>>>>>>>>> Ed Merks wrote:
>>>>>>>>>> > Ronaldo,
>>>>>>>>>> >
>>>>>>>>>> > Comments below.
>>>>>>>>>> >
>>>>>>>>>> > Ronaldo wrote:
>>>>>>>>>> >> Hi Ed,
>>>>>>>>>> >>
>>>>>>>>>> >> Thanks for the quick answer. Yes, I have 2 models in 2
>>>>>>>>>> different
>>>>>>>>>> >> eclipse projects.
>>>>>>>>>> >> They both use a null target namespace, in order to
>>>>>>>>>> eliminate the
>>>>>>>>>> >> prefixes in the xml.
>>>>>>>>>> > :-(
>>>>>>>>>> >
>>>>>>>>>> > XML documents with at least a namespace for the root element
>>>>>>>>>> are
>>>>>>>>>> > generally more consumable because they identify their
>>>>>>>>>> schema...
>>>>>>>>>> >>
>>>>>>>>>> >> I was just wondering what (which setting) causes the code
>>>>>>>>>> >>
>>>>>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);
>>>>>>>>>> > A null target namespace schema produces an annotation on the
>>>>>>>>>> EPackage to
>>>>>>>>>> > indicate the package is not qualified.
>>>>>>>>>> >>
>>>>>>>>>> >> to be generated. (as opposed to
>>>>>>>>>> >>
>>>>>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>>>>>>>>>> > This package doesn't have such an annotation.
>>>>>>>>>> >
>>>>>>>>>> > Note that you can't have two different packages that both
>>>>>>>>>> want to be the
>>>>>>>>>> > one for the null namespace both working at the same time.
>>>>>>>>>> >> )
>>>>>>>>>> >>
>>>>>>>>>> >> Ronaldo
|
|
| |
Re: NullPointerException in XMLSaveImpl.saveDataTypeMany [message #423297 is a reply to message #423294] |
Fri, 26 September 2008 12:43 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Ronaldo,
Comments below.
Ronaldo wrote:
> Hi Ed,
>
> Thanks for the extensive answers. Yes, I'm sure I've left out
> something, if I only knew what...
> I decided to take a step back, create a new project and reload the xsd
> again.
> Then, step by step I'll try to find the solution.
>
> Unfortunately, importing the xsd
> (http://www.wfmc.org/standards/bpmnxpdl_31.xsd) shows errors, see
> attachment.
> I cannot tell if the xsd is not ok or if there's an error somewhere in
> emf.
The XML Schema for schemas has a regular expression for validating that
XPaths are well formed and that regular expression doesn't allow
spaces. This schema has spaces in their regular expressions though.
You can just ignore these errors since key/keyref and unique are ignored
in XSD -> Ecore mapping.
>
> Ronaldo
>
> Ed Merks wrote:
>> Ronaldo,
>>
>> Comments below.
>>
>> Ronaldo wrote:
>>> Nope most elements didn't have a target namespace... I guess I'll
>>> have to add them manually to every element.
>>>
>>> A little background might be usefull:
>>> I started out with the xpdl2.1 XSD
>>> (http://www.wfmc.org/standards/bpmnxpdl_31.xsd) and created a model
>>> and generated java from that.
>> That one had a target namespace.
>>> However, I have little experience with XSD's and decided it might be
>>> easier to reload from java annotations from that point on.
>> Did you know you can export your Ecore to XSD? Keep in mind though
>> that XSD -> Ecore -> XSD is not a round trip because XSD -> Ecore is
>> slightly lossy. But Ecore -> XSD -> Ecore is supposed to be a round
>> trip because we generate all the necessary ecore:* annotations to
>> make it roundtrip. Using this mechanism, you could discover what you
>> needed to change in the original XSD to produce the desired Ecore...
>>>
>>> That might explain why I do have a DocumentRoot generated, a thing I
>>> don't have when generating the model from java annotations directly.
>> We, given sufficient annotations of the right form, you'll get the
>> same thing. The Ecore -> Java with @model -> Ecore is supposed to be
>> a round trip after all...
>>> When it all seemed to work, I read posts like
>>> http://www.eclipsezone.com/eclipse/forums/t91748.html to eliminate
>>> the prefixes.
>>> (Well I guess I misinterpreted them).
>> A better way to have eliminated the prefixes is to use
>> DocumentRoot.getXMLNSPrefixMap().put("", XyzPackage.eNS_URI). This
>> way you end up with an xmlns="<nsURI>" in the document and all
>> elements will be implicitly qualified by this namespace. Of course
>> attributes will still need explicit qualification, so I'm not sure
>> you'd be totally happy with the result. But given that I assume you
>> want the serialization to conform to the schema and the schema
>> requires qualified local elements and attributes, I don't think you
>> have all that much choice.
>>>
>>> I also noted that all my interfaces are now annotated with a
>>> name='*_._type' in the extended metadata annotation.
>> This comes from anonymous type definitions.
>>> I'd swear this was not the case earlier on.
>>> I'm not sure if this is good or bad, as I read that this should be
>>> ok when using a DocumentRoot... (?)
>>> ( http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg2 6745.html)
>> An anonymous type can never be used in an xsi:type. Sometimes that
>> fact can be used to deduce a more appropriate element name...
>>> But, as I'm not modifing the xsd but the java annotations instead
>>> and reloading the genmodel from these java annotations, do I still
>>> need that (old?) documentroot?
>> The document root determines the appropriate element name at the root
>> of the document. Without a document root, the name of the type will
>> be used as the root element name, but that's not going to conform to
>> the schema since a schema will always specify a global element to use
>> for the root.
>>> I created a new testproject from java and indeed no documentroot was
>>> generated.
>> Not sure about that. The DocumentRoot interface has @model on it, so
>> I assume you'd have to delete that for it to just disappear...
>>>
>>>
>>> That would also explain why adding an element directly to the
>>> resource.getContents() did serialize ok,
>>> while using an (old?) documentroot did not serialize ok.
>> If you're okay with a serialization that doesn't conform to the
>> schema then it's okay. The document root serialization issue was a
>> result of inconsistent annotations (annotations that would never have
>> been produced from a real schema).
>>>
>>> I assumed that starting with an xsd, would create the same model as
>>> when you're starting from java...
>> Given the corresponding annotations, yes.
>>> But the documentroot thing shows that's not the case?
>> I'm sure you've left out a little detail. After all, you've already
>> mentioned reloading the model from the @model changes and that didn't
>> make the DocumentRoot disappear... When reading the newsgroups for a
>> long time you start to learn that people leave out tiny but little
>> important details. :-P
>>>
>>>
>>> Ronaldo
>>>
>>>
>>> Ed Merks wrote:
>>>> Ronaldo,
>>>>
>>>> For the library mode it looks like this:
>>>>
>>>> * @model containment="true" upper="-2" transient="true"
>>>> volatile="true" derived="true"
>>>> * extendedMetaData="kind='element' name='library'*
>>>> namespace='##targetNamespace'"*
>>>>
>>>> I assume these models originated from a schema. Do that schema
>>>> have a target namespace?
>>>>
>>>>
>>>> Ronaldo wrote:
>>>>>
>>>>> This is the generated code for the getActivities method in the
>>>>> DocumentRoot interface.
>>>>>
>>>>> * @model containment="true" upper="-2" transient="true"
>>>>> volatile="true" derived="true"
>>>>> * extendedMetaData="kind='element' name='Activities'"
>>>>> * @generated
>>>>> */
>>>>> ActivitiesType getActivities();
>>>>>
>>>>>
>>>>>
>>>>> Ed Merks wrote:
>>>>>> Ronaldo,
>>>>>>
>>>>>> What EAnnotations does the "activities" feature of the
>>>>>> DocumentRoot have on it?
>>>>>>
>>>>>>
>>>>>> Ronaldo wrote:
>>>>>>> I have something that might be noteworthy:
>>>>>>> Somehow, I noticed that my genmodel consists of 4 models:
>>>>>>>
>>>>>>> Xpdl1 - Deprecated xpdl format
>>>>>>> Xpdl2 - Current xpdl format
>>>>>>> Ecore - (Icon contains a little arrow/referenced?)
>>>>>>> XMLType - (Icon contains a little arrow/referenced?)
>>>>>>>
>>>>>>> The util package also contains an Xpdl2XMLProcessor class:
>>>>>>>
>>>>>>> public class Xpdl2XMLProcessor extends XMLProcessor {
>>>>>>> public Xpdl2XMLProcessor() {
>>>>>>> super((EPackage.Registry.INSTANCE));
>>>>>>> Xpdl2Package.eINSTANCE.eClass();
>>>>>>> }
>>>>>>>
>>>>>>> @Override
>>>>>>> protected Map<String, Resource.Factory> getRegistrations() {
>>>>>>> if (registrations == null) {
>>>>>>> super.getRegistrations();
>>>>>>> registrations.put(XML_EXTENSION, new
>>>>>>> Xpdl2ResourceFactoryImpl());
>>>>>>> registrations.put(STAR_EXTENSION, new
>>>>>>> Xpdl2ResourceFactoryImpl());
>>>>>>> }
>>>>>>> return registrations;
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> which seems a little odd. I hadn't noticed this before.
>>>>>>>
>>>>>>> Here's the EPackage source:
>>>>>>>
>>>>>>> public interface Xpdl2Package extends EPackage {
>>>>>>> String eNS_URI = "http://www.wfmc.org/2008/XPDL2.1";
>>>>>>> String eNS_PREFIX = "xpdl2";
>>>>>>> Xpdl2Package eINSTANCE =
>>>>>>> org.wfmc.xpdl21.xpdl2.impl.Xpdl2PackageImpl.init();
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> And the resourceFactory source:
>>>>>>>
>>>>>>> public class Xpdl2ResourceFactoryImpl extends ResourceFactoryImpl {
>>>>>>> /**
>>>>>>> * @generated
>>>>>>> */
>>>>>>> public Xpdl2ResourceFactoryImpl() {
>>>>>>> super();
>>>>>>> }
>>>>>>> /**
>>>>>>> * @generated
>>>>>>> */
>>>>>>> public Resource createResourceGen(URI uri) {
>>>>>>> XMLResource result = new Xpdl2ResourceImpl(uri);
>>>>>>>
>>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>>>>>>> Boolean.TRUE);
>>>>>>>
>>>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTEND ED_META_DATA,
>>>>>>> Boolean.TRUE);
>>>>>>>
>>>>>>>
>>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>>>>>>> Boolean.TRUE);
>>>>>>>
>>>>>>>
>>>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>>>>>>> Boolean.TRUE);
>>>>>>>
>>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_EN CODED_ATTRIBUTE_STYLE,
>>>>>>> Boolean.TRUE);
>>>>>>>
>>>>>>>
>>>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LE XICAL_HANDLER,
>>>>>>> Boolean.TRUE);
>>>>>>> return result;
>>>>>>> }
>>>>>>> @Override
>>>>>>> public Resource createResource(URI uri) {
>>>>>>> XMLResource result = (XMLResource)createResourceGen(uri);
>>>>>>>
>>>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_ENCODI NG,
>>>>>>> "UTF-8");
>>>>>>>
>>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ENCODI NG,
>>>>>>> "UTF-8");
>>>>>>> // // // Where do we turn this off in the genmodel?
>>>>>>> What is the name of the option?
>>>>>>> //
>>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA _LOCATION,
>>>>>>> Boolean.TRUE);
>>>>>>> // //
>>>>>>> result.getDefaultLoadOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>>>>>>> Boolean.TRUE);
>>>>>>> //
>>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_LAX_FE ATURE_PROCESSING,
>>>>>>> Boolean.TRUE);
>>>>>>> //
>>>>>>>
>>>>>>> //result.getDefaultSaveOptions().put(XMLResource.OPTION_SKIP _ESCAPE,
>>>>>>> Boolean.TRUE);
>>>>>>> //
>>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_ESCAPE _USING_CDATA,
>>>>>>> Boolean.TRUE);
>>>>>>> //
>>>>>>> result.getDefaultSaveOptions().put(XMLResource.OPTION_FORMAT TED,
>>>>>>> Boolean.TRUE);
>>>>>>> // return result;
>>>>>>> }
>>>>>>>
>>>>>>> } //Xpdl2ResourceFactoryImpl
>>>>>>>
>>>>>>> I hope this helps.
>>>>>>> Ronaldo
>>>>>>>
>>>>>>> Ed Merks wrote:
>>>>>>>> Ronaldo,
>>>>>>>>
>>>>>>>> Comments below.
>>>>>>>>
>>>>>>>> Ronaldo wrote:
>>>>>>>>> Hi Ed,
>>>>>>>>>
>>>>>>>>> I guess you're saying I'm messing around with a null namespace :0
>>>>>>>>> Point is, it has worked and somehow I changed something and it
>>>>>>>>> doesn't work any more.
>>>>>>>>> I feel I'm losing control ...
>>>>>>>> Something worked, but only you know what...
>>>>>>>>>
>>>>>>>>> Anyway, I'll step back, and use proper namespaces ;)
>>>>>>>>>
>>>>>>>>> My package is now only annotated with @model kind="package".
>>>>>>>>> (Unqualified is removed)
>>>>>>>> You've relaoaded the model?
>>>>>>>>> The generated XYZExample now generates
>>>>>>>>>
>>>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>> <Activities/>
>>>>>>>>>
>>>>>>>>> So the question is, which piece of code is responsible for
>>>>>>>>> hiding the namespace prefix?
>>>>>>>> And has the resource factory been regenerated so it's using
>>>>>>>> "TRUE"? It doesn't look that way...
>>>>>>>>>
>>>>>>>>> I'd expect something like
>>>>>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>>>>>> <prefix:Activities xmlns:prefix="yadiyadi" />
>>>>>>>> Me too. What's the nsURI of your EPackage?
>>>>>>>>>
>>>>>>>>> Fun part is, after unloading the created and saved resource,
>>>>>>>>> I reload it using the same resourceSet. But then, I get the
>>>>>>>>> famous "Package with uri null not found" message...
>>>>>>>>> because the prefix is missing...
>>>>>>>> Something's is a little screwed up for sure... What does the
>>>>>>>> resource factory look like?
>>>>>>>>>
>>>>>>>>> Ronaldo
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Ronaldo wrote:
>>>>>>>>>>> This error comes up when I run the XYZExample test code,
>>>>>>>>>>> disguised as/copied to a UnitTest in maven. (ie outside the
>>>>>>>>>>> eclipse editor).
>>>>>>>>>>> It runs fine from within eclipse/junit. I figured it must
>>>>>>>>>>> have something to do with
>>>>>>>>>>> http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_use_EMF_i n_standalone_applications_.28such_as_an_ordinary_main.29.3F,
>>>>>>>>>>>
>>>>>>>>>>> does it?
>>>>>>>>>>>
>>>>>>>>>>> The error is
>>>>>>>>>>>
>>>>>>>>>>> java.lang.NullPointerException
>>>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>>>>>>>>>>>
>>>>>>>>>> It's dying because the data type doesn't have a containing
>>>>>>>>>> package and hence we get a null pointer exception trying to
>>>>>>>>>> get the factory for that package?
>>>>>>>>>>
>>>>>>>>>> EDataType d = (EDataType)f.getEType();
>>>>>>>>>> EPackage ePackage = d.getEPackage();
>>>>>>>>>> EFactory fac = ePackage.getEFactoryInstance();
>>>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>>>>>>>>>>>
>>>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>>>>>>>>>>>
>>>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
>>>>>>>>>>>
>>>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
>>>>>>>>>>>
>>>>>>>>>>> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>>>>>>>>>>>
>>>>>>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1344)
>>>>>>>>>>>
>>>>>>>>>>> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:986)
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Code:
>>>>>>>>>>>
>>>>>>>>>>> MyModel1Package.eINSTANCE.eClass();
>>>>>>>>>>> MyModel2Package.eINSTANCE.eClass();
>>>>>>>>>>> ResourceSet resourceSet = new ResourceSetImpl();
>>>>>>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>>>>>>
>>>>>>>>>>> ("ext1", new MyModel1ResourceFactoryImpl());
>>>>>>>>>>> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
>>>>>>>>>>>
>>>>>>>>>>> (Resource.Factory.Registry.DEFAULT_EXTENSION,
>>>>>>>>>>> new MyModel2ResourceFactoryImpl());
>>>>>>>>>>>
>>>>>>>>>>> Resource resource =
>>>>>>>>>>> resourceSet.createResource(URI.createURI("http:///My.model.uri"));
>>>>>>>>>>>
>>>>>>>>>>> DocumentRoot documentRoot =
>>>>>>>>>>> MyModel2Factory.eINSTANCE.createDocumentRoot();
>>>>>>>>>>>
>>>>>>>>>>> // ---- Removing the next two lines makes it work from maven
>>>>>>>>>>> too.
>>>>>>>>>>> ActivitiesType root =
>>>>>>>>>>> MyModel2Factory.eINSTANCE.createActivitiesType();
>>>>>>>>>>> documentRoot.setActivities(root);
>>>>>>>>>>>
>>>>>>>>>>> resource.getContents().add(documentRoot);
>>>>>>>>>>> resource.save(System.out, null);
>>>>>>>>>> This looks much like the generated XyzExample you get when
>>>>>>>>>> you invoke "Generate Test Code". Does that have the same
>>>>>>>>>> problem?
>>>>>>>>>>>
>>>>>>>>>>> Many thanks,
>>>>>>>>>>> Ronaldo
>>>>>>>>>>>
>>>>>>>>>>> Ed Merks wrote:
>>>>>>>>>>> > Ronaldo,
>>>>>>>>>>> >
>>>>>>>>>>> > Comments below.
>>>>>>>>>>> >
>>>>>>>>>>> > Ronaldo wrote:
>>>>>>>>>>> >> Hi Ed,
>>>>>>>>>>> >>
>>>>>>>>>>> >> Thanks for the quick answer. Yes, I have 2 models in 2
>>>>>>>>>>> different
>>>>>>>>>>> >> eclipse projects.
>>>>>>>>>>> >> They both use a null target namespace, in order to
>>>>>>>>>>> eliminate the
>>>>>>>>>>> >> prefixes in the xml.
>>>>>>>>>>> > :-(
>>>>>>>>>>> >
>>>>>>>>>>> > XML documents with at least a namespace for the root
>>>>>>>>>>> element are
>>>>>>>>>>> > generally more consumable because they identify their
>>>>>>>>>>> schema...
>>>>>>>>>>> >>
>>>>>>>>>>> >> I was just wondering what (which setting) causes the code
>>>>>>>>>>> >>
>>>>>>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA,
>>>>>>>>>>> extendedMetaData);
>>>>>>>>>>> > A null target namespace schema produces an annotation on
>>>>>>>>>>> the EPackage to
>>>>>>>>>>> > indicate the package is not qualified.
>>>>>>>>>>> >>
>>>>>>>>>>> >> to be generated. (as opposed to
>>>>>>>>>>> >>
>>>>>>>>>>> >> result.getDefaultSaveOptions().put(
>>>>>>>>>>> >> XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>>>>>>>>>>> > This package doesn't have such an annotation.
>>>>>>>>>>> >
>>>>>>>>>>> > Note that you can't have two different packages that both
>>>>>>>>>>> want to be the
>>>>>>>>>>> > one for the null namespace both working at the same time.
>>>>>>>>>>> >> )
>>>>>>>>>>> >>
>>>>>>>>>>> >> Ronaldo
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Wed Apr 24 22:52:28 GMT 2024
Powered by FUDForum. Page generated in 0.04331 seconds
|