Hi Steve,
See inline comments... Steve Shabino wrote: > > Greetings - > > I am trying to use the new location attribute in the > mapping file to add a wrapper element that is not > represented in my externally generated Java objects > and am experiencing problems. > > Here is a snippet from my mapping file: > > <cbf:class access="shared" auto-complete="false" > name="com.mycompany.QuoteBean"> > <cbf:map-to ns-prefix="wcm" > ns-uri="http://mycompany.com/QuoteNS" xml="Quote"/> > <cbf:field collection="array" > > handler="com.mycompany.fieldhandlers.ArrayFieldHandler" > name="drivers" type="com.myCompany.DriverBean"> > <cbf:bind-xml location="Drivers" name="Driver"/> > </cbf:field> > > [Note: The fieldhandler is necessary because our > existing Java objects do not quite follow bean > conventions for arrays of objects; we have Foo[] > getFoo() and addToFoo(Foo foo).] Actually you don't need a custom field handler for this case, because your *add* method begins with "add". Castor supports "add" methods by using the set-method and get-method attributes. Just specify them on your field mapping as such: <field name="foo" set-method="addToFoo" get-method="getFoo" collection="array"/> > > And, here is a piece of XML generated via Castor: > > <wcm:Quote agencyCode="ABC123" agencyPartyId="123" > xmlns:wcm="http://mycompany.com/QuoteNS"> > <Drivers> > <wcm:Driver driverDriverLicenseNumber="1234"/> > <wcm:Driver driverDriverLicenseNumber="4321"/> > </Drivers> > </wcm:Quote> > > I have two objects, a QuoteBean and a DriverBean. The > quote bean may contain one or more drivers. For > various reasons, we want to preserve the getter/setter > method name (or at least its meaning) as an XML > element wrapper. > > The above description excludes a lot of details--the > actual schema/object model is much more complex. > > Here are the issues I am experiencing: > > 1. Namespace awareness. I can produce XML using the > above set-up. However, the wrapper elements are not > given a namespace. using location="wcm:Drivers" in my > mapping file produces a good result when marshalling > but clearly (via an examination of the > Unmarshaller.java source) is not by design and will > fail when marshalling. What is the proper way to add > namespace to wrapper elements? I checked in a simple patch I created for this issue. It's not complete fix which I am working on along with another location issue. There are two items related to the location attribute that I didn't get finished before releasing 0.9.5, which I hope to have available soon. The first is namespace awareness with the location attribute, the second is preventing multiple wrappers from being output when more than one field uses a given wrapper. For now, if you can grab the latest cvs version you'll be able to use the marshalling fix which I checked in. The location attribute will use the namespace of the parent class in which it is described. In the future you'll be able to specify a separate namespace for the location the way you tried to do it above in your example. But for now this should allow you to produce the correct XML. For more information about the second issue, see here: http://www.mail-archive.com/[EMAIL PROTECTED]/msg13447.html > > 2. When unmarshalling the above XML, I get the > following exception: > > org.xml.sax.SAXException: unable to find > FieldDescriptor for 'Driver' in ClassDescriptor of > Drivers This one is strange, it might be related to using the FieldHandler. Try removing the FieldHandler and see if that helps. The Handler is not needed for your case as I mentioned above, just add your set-method and get-method attributes and you should be ok. --Keith ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev
