That's really good news, thank you very much!

regards,

Robin.


Radu Preotiuc-Pietro wrote:
It's no difference. You actually should use

 if (x instanceof Z) {
    Z z = (Z)x;
    ...

whenever possible.
But sometimes x may be instanceof X and you want a new z which is instanceof Z, 
but with all the data that x had and, since this is XML, the same position in 
the XML tree that x had. That's when .changeType() (and .substitute()) become 
useful.

As far as that phrase in the doc, it means that when performing a .changeType() 
operation, XmlBeans normally checks that the new type is valid for that 
element, in the parent's context. But since the root has no parent, this check 
always succeeds, so you can type the root docuement whichever way you want (of 
course, if the real document doesn't match the type you set, the APIs won't 
return any useful thing, as if the doc was invalid).

Radu
-----Original Message-----
From: Robin Sander [mailto:[EMAIL PROTECTED]
Sent: Friday, July 08, 2005 6:29 AM
To: [email protected]
Subject: difference between changeType and a direct cast?



Hello,

I'm currently using XMLBeans 1.0.4 to parse a rather complex schema with
lots of abstract types, type-inheritance and use of substitution-groups.
After the parsing process all XmlObject instances are then tranformed
into POJOs for serialization reasons.
Because of a complex type-hierarchy the transformation code has a lot
of code like this:

  if (Y.type.isAssignableFrom(x.schemaType())) {
    Y y = (Y)x.changeType(Y.type)
    ...
  } else if (Z.type.isAssignableFrom(x.schemaType())) {
    Z z = (Z)x.changeType(Z.type)
    ...
  } else if { ...

Why is changeType() necessary at all? If I print the class of 'x' in
the example above, I get 'ZImpl' in the second case.
So when XMLBeans already creates the right class instance *before*
calling changeType(), where is the difference between

  Z z = (Z)x.changeType(T.type);

and a simple

  if (x instanceof Z) {
    Z z = (Z)x;
    ...
  }

I don't understand the javadoc comment on changeType() so well,
especially this part:
  "..., but there are no constraints at the roottype changes are never
   prohibited at the root of an xml tree."

What does this mean? Under which circumstances can I rely on using a direct cast delivering the same result as a call to changeType()?

Thanks in advance,

Robin.


PS: I will use XMLBeans 2.0 soon (substitution-groups!), so any answer
     based on 2.0 would be equally appreciated!





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to