users@jaxb.java.net

How to declare/retrieve declared namespaces?

From: fgeller <fgeller_at_gmail.com>
Date: Tue, 13 May 2008 05:31:52 -0700 (PDT)

Hi,

    I'm trying to implement a Web Service using an EJB and JAXB. The
types/classes and binding are generated automatically from the WSDL and the
respective schemata. Now, I fail to manage namespace declaration within a
given element. Here are the interesting bits of the annotated class that the
element is mapped to:

[code]
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "TopicExpressionType", propOrder = { "content" })
public class TopicExpressionType {

    @XmlMixed
    @XmlAnyElement(lax = true)
    protected List content;

    @XmlAttribute(name = "Dialect", required = true)
    protected String dialect;

    @XmlAnyAttribute
    private Map<QName, String> otherAttributes = new HashMap<QName,
String>();

    public List getContent () {
        if (content == null) {
            content = new ArrayList();
        }
        return this.content;
    }

    public String getDialect () {
        return dialect;
    }

    public void setDialect (String value) {
        this.dialect = value;
    }

    public Map<QName, String> getOtherAttributes () {
        return otherAttributes;
    }
}
[/code]

Here is the relevant part of the client code:

[code]
            TopicExpressionType tet = new TopicExpressionType();
            Map<QName, String> tet_atts = tet.getOtherAttributes();

            QName eve = new QName("http://www.w3.org/2000/xmlns/", "eve");
            tet_atts.put(eve, "http://www.example.com/");

            QName test_att = new QName("test-att");
            tet_atts.put(test_att, "foo");
[/code]

And here the server part:

[code]
            Map<QName, String> atts = tet.getOtherAttributes();
 
            for (QName qn : atts.keySet()) {
                System.out.println("qn: ["+qn+"] value["+atts.get(qn)+"]");
            }
[/code]

will print: "qn: [test-att] value[foo]"

I take it using attributes isn't the regular way to declare namespaces, if
so - what is the correct way to do so? Furthermore, what changes are
required to my annotated class in order to be able to retrieve declared
namespaces?

If I marshall the "tet" object, I get all the namespace declaration that
the element inherited from the schema defining the type, but not the one I
added manually to the element. However, the "test-att" attribute is added
and marshalled fine.

Please let me know what other pieces of information would be required in
order to resolve this issue. Thank you for your help in advance!

Cheers,
Felixfgeller bei gmail
-- 
View this message in context: http://www.nabble.com/How-to-declare-retrieve-declared-namespaces--tp17207270p17207270.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.