Sergey,

On Thu July 2 2009 12:59:10 pm Sergey Beryozkin wrote:
> I have problems with the JAXB schema generation.
>
> Consider this bean :
>
> @XmlRootElement(name="thebook", namespace="http://books";)
> public class Book {
>   private int id;
>   public Book() { }
>   public int getId() { return id; }
>   public void setId(int ident) { id = ident; }
> }
>

I think you should just add an 
@XmlType(name = "book", namespace="http://books";)
Attribute to it as well.    The XmlRootElement defines a root element, but 
doesn't do anything to specify how the type is mapped in.    The XmlType 
annotation does that.

Dan




> JAXBContext generates these 2 schemas :
>
> <!-- Schema 1 -->
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; version="1.0"
> targetNamespace="http://books";> <xs:import schemaLocation="schema2.xsd" />
> <xs:element name="thebook" type="book" />
> </xs:schema>
>
> <!-- Schema 2 -->
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; version="1.0">
> <xs:complexType name="book">
> <xs:sequence>
> <xs:element name="id" type="xs:int" />
> </xs:sequence>
> </xs:complexType>
> </xs:schema>
>
> The first problem I guess is to check if <import> in the first schema has
> no 'namespace' attribute in which case I can have 'book' complex type
> injected directly into the first schema. with the whole <import> being
> removed. It can get quiote hairy if 'book' type improts some other types,
> but it can be handled.
>
> What I'm sure about is how to figure out that when we have say a method
>
> public Resource() {
>    public Book getBook() {}
> }
>
> then how to ensure that Book is represented by {http://books}thebook
> qualified name in the generated doc such as wadl...
>
> it's not obvious to me how a link between Book and 'thebook' element can be
> established given that this info (in XmlRootElement at the moment) may come
> from various sources
>
> thanks, Sergey

-- 
Daniel Kulp
dk...@apache.org
http://www.dankulp.com/blog

Reply via email to