List Info

Thread: RE: polymorphism




RE: polymorphism
country flaguser name
United States
2007-04-12 18:21:52
Hi Radu,
Thanks for your help. Here's there updated code:

RoleType role =
RoleDocument.Factory.newInstance().addNewRole();
role.setRoleName("my role name");
System.out.println("role:n" + role);

ObjectWrapperType wrapper =
ObjectWrapperDocument.Factory.newInstance().addNewObjectWrap
per();
wrapper.setTop(role);
System.out.println("wrapper:n" + wrapper);

TopType top = wrapper.getTop();
System.out.println("top:n" + top.xmlText());

RoleType role2 = RoleType.Factory.parse(top.newDomNode());
System.out.println("role2:n" + role2);
System.out.println("role2.getRoleName(): " +
role2.getRoleName());

And here's the output:

role:
<roleName
xmlns="http://schemas.cmp.cisco.com/2006/07/Chameleon/R
oleP">my role
name</roleName>
wrapper:
<Top xmlns="http://schemas.cmp.cisco.com/2006/07/Chameleon/TopP&quo
t;
xmlns:rol="http://schemas.cmp.cisco.com/2006/07/Chameleon/Rol
eP">
  <rol:roleName>my role name</rol:roleName>
</Top>
top:
<rol:roleName
xmlns:rol="http://schemas.cmp.cisco.com/2006/07/Chameleon/R
oleP">my role
name</rol:roleName>
role2:
<topp:Top
xmlns:topp="http://schemas.cmp.cisco.com/2006/07/Chameleon/TopP
">
  <rol:roleName
xmlns:rol="http://schemas.cmp.cisco.com/2006/07/Chameleon/R
oleP">my role
name</rol:roleName>
</topp:Top>
role2.getRoleName(): null

 

-----Original Message-----
From: Radu Preotiuc-Pietro [mailto:radupbea.com]

Sent: Thursday, April 12, 2007 3:08 PM
To: userxmlbeans.apache.org
Subject: Re: polymorphism

I am assuming that going through DOM is a requirement,
otherwise there
is no need to do it...

Can you add a line 

System.out.println("top: " + top.xmlText());

before the line where you do newDomNode() to see what top
would look
like if serialized to text?

Thanks,
Radu

On Thu, 2007-04-12 at 14:47 -0700, Vinh Nguyen (vinguye2)
wrote:
> Hi all,
> I am trying to use XmlBeans for generating classes for
xsds that have 
> an "inheritence" hierarchy.  I may not be
using XmlBeans properly, so 
> any help is appreciated.
>  
> I have three object types.
> TopType is a base class for various objects.
> RoleType extends TopType.
> ObjectWrapperType stores a TopType and is used for
passing objects in 
> a generic way to/from the server.
>  
> When I set a RoleType into the ObjectWrapperType, I
later get it out 
> as a TopType and convert to a RoleType, but I can't get
the proper 
> role data.
>  
> Here's my test code:
>  
> RoleType role =
RoleDocument.Factory.newInstance().addNewRole();
> role.setRoleName("my role name");
> ObjectWrapperType wrapper =
>
ObjectWrapperDocument.Factory.newInstance().addNewObjectWrap
per();
> wrapper.setTop(role);
> TopType top = wrapper.getTop();
> RoleType role =
RoleType.Factory.parse(top.newDomNode());
> System.out.println("role:n" +
role.xmlText());
> System.out.println("role.getRoleName(): " +
role.getRoleName());
> 
> Here's my output:
>  
> role2:
> <topp:Top
> xmlns:topp="http://schemas.cmp.cisco.com/2006/07/Chameleon/TopP
">
>   <rol:roleName
> xmlns:rol="http://schemas.cmp.cisco.com/2006/07/Chameleon/R
oleP">my
> role name</rol:roleName>
> </topp:Top>
> role2.getRoleName(): null
>  
> I can clearly see that the final RoleType has data, but
I can't get 
> data out of it.  Perhaps I am not doing this the right
way?
> -Vinh

Notice:  This email message, together with any attachments,
may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and 
affiliated
entities,  that may be confidential,  proprietary, 
copyrighted  and/or
legally privileged, and is intended solely for the use of
the individual
or entity named in this message. If you are not the intended
recipient,
and have received this message in error, please immediately
return this
by email and then delete it.

------------------------------------------------------------
---------
To unsubscribe, e-mail: user-unsubscribexmlbeans.apache.org
For additional commands, e-mail: user-helpxmlbeans.apache.org

------------------------------------------------------------
---------
To unsubscribe, e-mail: user-unsubscribexmlbeans.apache.org
For additional commands, e-mail: user-helpxmlbeans.apache.org


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )