473,508 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML JAXB Binding to Vector not List

I am attempting to create a JAXB Object that returns the
CollectionType as a List. In my schema file, I used the following:

<jxb:globalBindings>
collectionType="java.util.Vector"
</jxb:globalBindings>

This changed the initialization in the impl stub from the following:

protected com.sun.xml.bind.util.ListImpl _MyList = new
com.sun.xml.bind.util.ListImpl(new java.util.ArrayList());

to:
protected com.sun.xml.bind.util.ListImpl _MyList = new
com.sun.xml.bind.util.ListImpl(new java.util.Vector());

This looks better, but when I use the MyObject.getMyList() function,
it returns a java.util.List object. Not a java.util.Vector.

Is there anyway that I can cast it or change the function signature to
return a Vector?
Jul 17 '05 #1
1 6645

"Scott Bates" <sa*****@slocrusade.com> wrote in message
news:70**************************@posting.google.c om...
I am attempting to create a JAXB Object that returns the
CollectionType as a List. In my schema file, I used the following:

<jxb:globalBindings>
collectionType="java.util.Vector"
</jxb:globalBindings>

This changed the initialization in the impl stub from the following:

protected com.sun.xml.bind.util.ListImpl _MyList = new
com.sun.xml.bind.util.ListImpl(new java.util.ArrayList());

to:
protected com.sun.xml.bind.util.ListImpl _MyList = new
com.sun.xml.bind.util.ListImpl(new java.util.Vector());

This looks better, but when I use the MyObject.getMyList() function,
it returns a java.util.List object. Not a java.util.Vector.

Is there anyway that I can cast it or change the function signature to
return a Vector?


Is it returning a Vector.
It is returning a java.util.List reference to the Vector object.
This is the correct way to use the Collections API.
You should never (loosely speaking) create a reference to a List, Set or Map
implementation class (such as java.util.Vector).

You *can* cast it, but chances are, you don't want you.
Or ... you think you want to, but you don't understand that you would be
writing poor code.

The fact that you are changing List implementations (from ArrayList to
Vector) is a perfect example of why you want to handle the returned List
reference transparently (to the implementation).

Perhaps this will help:
http://java.sun.com/docs/books/tutor...tro/index.html

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5334
by: jesper | last post by:
Hi I am currently following the tutorial from IBM (http://www-106.ibm.com/developerworks/xml/edu/x-dw-xjaxb-i.html) I have three problems at the moment. 1. It says else where that when the...
0
2321
by: Mark | last post by:
I'm betting it me. Here is the simple schema I'm using: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"...
13
5632
by: Christoph Brunner | last post by:
Hi, on the sun homepage i had submit to the bugparade a request for feature enhancement for the JAXB API. After a period of time sun called me to post my request to a newsgroup an get comments...
0
2634
by: Brett Selleck | last post by:
We have an issue where the JAXB generated classes are creating an interface which references itself. The Schema is valid, and I have not seen this ran into before. The code is below. What is...
0
1537
by: Mark | last post by:
I'm betting it me. Here is the simple schema I'm using: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"...
0
1496
by: ciaran.mchale | last post by:
I used Google to find information about JAXB 2.0 and I ended up downloading a document called "The Java Architecture for XML Binding (JAXB) 2.0: Proposed Final Draft September 30, 2005". ...
1
2482
by: =?Utf-8?B?VGVjaGVlaw==?= | last post by:
I am using JAXB for parsing the XML file. When any validation error occurs like a particular tag value in the XML file is not in sync with what is defined in the schema, the JAXB is not displaying...
0
5059
by: mnsh | last post by:
Hello, I am new to JAXB. So I would like somebody to help me solve this problem. I have a class say Test which contains only a List which has some 6 to 7 user defined objects. I am able to...
0
3204
by: malsh1358 | last post by:
Hi I need check required elements and attributes in JAXB java classes , if there are any value for them place it , otherwise place default value in xml file , because of it I upgrade JAXB2.0 to...
0
7135
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.