History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CASTOR-1995
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Herman
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
castor

Can not map attributes to multiple XML elements within the same class

Created: 04/Jun/07 09:44 AM   Updated: 08/Jun/07 04:42 AM
Component/s: XML code generator
Affects Version/s: 1.0.5, 1.1.1
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive BugReportFiles.zip (6 kb)

Environment: Bug noticed on Windows XP, Eclipse IDE

Testcase included: yes


 Description  « Hide
When using the location attribute in the Castor Mapping XML file, only one element with an attribute can be specified in any class. If another attribute is specified, Castor does not map the attribute and ignores it. If I specify another class, then I can place one more attribute in a element belonging to this class.

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Margarita Costa Matos - 06/Jun/07 06:17 PM
Hi.

I had a similar issue and the following worked for me, assuming your multiple xml elements have the same mapping (XML Field) to (Java Field) , i.e. You have a book object that can accommodate xml elements MysteryBook, ReferenceBook:

Create the class with the mappings but no bind-xml element.
For example:
<class name="mypackage.Book"
<field name="ISBN" type="java.lang.String">
<bind-xml name="ISBNNUMBER" />
</field>
...

Then, have a single object that holds all of your Book objects under a collection (setMysteryBookList(Collection<Book> my books):
<class name="mypackage.BookShelf"
<field name="MysteryBookList" type="mypackage.Book" collection="collection">
<bind-xml name="MysteryBook" />
</field>
<field name="ReferenceBookList" type="mypackage.Book" collection="collection">
<bind-xml name="ReferenceBook" />
</field>
</class>

Your Book class would look like:
public class Book {
private String ISBN = null;

public void setISBN (String isbn) { this.ISBN = isbn; }

public String getISBN () { return this.ISBN; }

...
}

Your BookShelf class would look like:
public class BookShelf {
private Collection<Book> mysteryBooks = null;
private Collection<Book> referenceBooks = null;

public void setMysteryBooks (Collection<Book> books) { this.mysteryBooks = books; }

public void setReferenceBooks (Collection<Book> books { this.referenceBooks = books; }

}

Hope this helps. Good luck!!

  • Margarita

Herman - 08/Jun/07 04:42 AM
Hi Margarita,

Thanks for the suggestion, but I don't think it would work on our case because we don't know the different types an element could have until runtime. So it's not something that we could hard code into our solution.