xml - Obtain Java Class name from QName -


suppose have qname represents type in .xsd document. how can find out name of class unmarshal into?

for example, i've got qname: {http://www.domain.com/service/things.xsd}customer

this gets unmarshalled com.domain.service.things.customer.

is there way can without parsing qname string representation?

edit:

i've got .xsd's defined being used create java classes. want select 1 of these java classes dynamically based on qname being passed in string on html form.

edit2:

since these classes' names being automatically generated, somewhere there must method generates names qname.

you leverage jaxbinstropector , following:

package example;  import java.util.hashmap; import java.util.map;  import javax.xml.bind.jaxbcontext; import javax.xml.bind.jaxbintrospector; import javax.xml.namespace.qname;  public class demo {      public static void main(string[] args) throws exception {         class[] classes = new class[3];         classes[0] = a.class;         classes[1] = b.class;         classes[2] = c.class;          jaxbcontext jc = jaxbcontext.newinstance(classes);          jaxbintrospector ji = jc.createjaxbintrospector();         map<qname, class> classbyqname = new hashmap<qname, class>(classes.length);         for(class clazz : classes) {             qname qname = ji.getelementname(clazz.newinstance());             if(null != qname) {                 classbyqname.put(qname, clazz);             }         }          qname qname = new qname("http://www.example.com", "eh");         system.out.println(classbyqname.get(qname));     }  } 

the following model classes:

a

package example;  import javax.xml.bind.annotation.xmlrootelement;  @xmlrootelement(name="eh", namespace="http://www.example.com") public class { } 

b

package example;  import javax.xml.bind.annotation.xmlrootelement;  @xmlrootelement(name="bee", namespace="urn:example") public class b { } 

c

package example;  public class c { } 

output

class example.a 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -