jQuery in Action, 3rd edition
The moose likes Groovy and the fly likes XMLBeans and Groovy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "XMLBeans and Groovy" Watch "XMLBeans and Groovy" New topic

XMLBeans and Groovy

Robert Harvey

Joined: Nov 18, 2011
Posts: 8
I am developing in Netbeans and have 2 XMLBean libraries (Schemas1.jar, Schemas2.jar). One of my XMLBeans, Class A, is defined in Schemas1.jar. Class A contains a type, Class B, defined in Schemas2.jar. I have a Groovy class, Class MyGroovy, that operates on Class A to obtain a reference to Class B. My compilation works, but runtime produces a nullpointer exception:

at org.apache.xmlbeans.impl.schema.SchemaPropertyImpl.getType(SchemaPropertyImpl.java:92)
at org.apache.xmlbeans.impl.schema.SchemaTypeImpl.createElementType(SchemaTypeImpl.java:965)
at org.apache.xmlbeans.impl.values.XmlObjectBase.create_element_user(XmlObjectBase.java:924)
at org.apache.xmlbeans.impl.store.Xobj.getUser(Xobj.java:1669)
at org.apache.xmlbeans.impl.store.Xobj.find_element_user(Xobj.java:2074)
at schemas1.model.impl.ClassAImpl.getClassB(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl$GetBeanMethodMetaProperty.getProperty(MetaClassImpl.java:3460)
at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:61)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:237)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetPropertySafe(AbstractCallSite.java:343)

I posted a question to the XMLBean folks, but they have not responded in over 2 weeks. Thought I would post this at CodeRanch to help me solve this. If I operate on ClassA and ClassB from a normal Java class, the nullpointer is not observed. Seems to be tied to how groovy handles "aggregate" XMLBeans objects.

Any help is much appreciated,
Paul Clapham

Joined: Oct 14, 2005
Posts: 19739

Sounds like a Groovy question to me, and we have a Groovy forum. Moving...
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3151

May be you could show us the code?

Mohamed Sanaulla | My Blog
I agree. Here's the link: http://aspose.com/file-tools
subject: XMLBeans and Groovy
jQuery in Action, 3rd edition