16345

ObjectFactory methods generated by jaxb

Question:

I am trying to make web services but there are two situations I am getting.

There are two types of xsd file 1st one is:

<xsd:element name="signupRequest"> <xsd:complexType> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="email" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element <xsd:element name="signupResponse"> <xsd:complexType> <xsd:sequence> <xsd:element name="signup" type="tns:Signup"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:simpleType name="Signup"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="Success"/> <xsd:enumeration value="DuplicateEmail"/> </xsd:restriction> </xsd:simpleType>

in that case jaxb generates signuprequest signupresponse and signup classes so i can easily make services for example in this case:

public Signup signupResponse(String name,String mobile);

but if I set signupresponse directly like this:

<xsd:element name="signupResponse"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:enumeration value="Success"/> <xsd:enumeration value="DuplicateMail"/> </xsd:restriction> </xsd:simpleType> </xsd:element>

jaxb only generate sinuprequest class and do not generate signupresponse and signup classes instead it makes entry in ObjectFactory class like this

private final static QName _SignupResponse_QNAME = new QName("http://www.example.com", "signupResponse");

and method is:

@XmlElementDecl(namespace = "http://www.example.com", name = "signupResponse") public JAXBElement<String> createSignupResponse(String value) { return new JAXBElement<String>(_SignupResponse_QNAME, String.class, null, value);

so please guide me how to make services for these types of xsd architecture.

Answer1:

The element signupResponse is considered as simple type of String.class, for this reason you haven't a Class generates.

If you want generated the enumeration you should change the XSD

<xs:element name="signupResponse" type="signupResponse" /> <xs:simpleType name="signupResponse"> <xs:restriction base="xs:string"> <xs:enumeration value="Success" /> <xs:enumeration value="DuplicateMail" /> </xs:restriction> </xs:simpleType>

in order to generate

@XmlType(name = "signupResponse") @XmlEnum public enum SignupResponse { @XmlEnumValue("Success") SUCCESS("Success"), @XmlEnumValue("DuplicateMail") DUPLICATE_MAIL("DuplicateMail"); private final String value; SignupResponse(String v) { value = v; } public String value() { return value; } public static SignupResponse fromValue(String v) { for (SignupResponse c: SignupResponse.values()) { if (c.value.equals(v)) { return c; } } throw new IllegalArgumentException(v); } }

and ObjectFactory

@XmlElementDecl(namespace = "http://www.example.com", name = "signupResponse") public JAXBElement<SignupResponse> createSignupResponse(SignupResponse value) { return new JAXBElement<SignupResponse>(_SignupResponse_QNAME, SignupResponse.class, null, value); }

Recommend

  • Why can't I define a two-dimensional array larger than 300*300? [duplicate]
  • How does agda's inspect function work?
  • XSD schema only one element appears multiple times while xs:all
  • How to use ASTRewrite to replace a particular SimpleType with a PrimitiveType?
  • Unexpected element while unmarshalling
  • jaxb2-maven-plugin generates invalid source for doubles with default value =INF
  • Reading Element attribute value using XStream
  • Use of Multiple Inheritance in EclipseLink MOXy
  • Co-Occurre​nce Constraint​
  • file_get_contents(): open_basedir restriction in effect
  • Java Socket Reuse
  • Spring RestTemplate slow response time
  • C++ Boost ptr_map serialization error
  • Is there a limit on how long a cfquery with cfqueryparam can get?
  • Dependency Injection and Code Obfuscation
  • Usage of local dart library
  • Google App Engine - SSL InsecurePlatformWarning
  • PHP: Very simple Encode/Decode string
  • Swift string variables localization
  • Django - can't get highchart to display data
  • Messed up characters in webpages (especially social media)
  • Error while using PDF Kit
  • HighCharts - Show tooltip on column where value is 0 or null
  • c++ using primitive types as a base class
  • Generic classes with Collection getter of other types
  • iOS Localization Doesn't Work with More Than 63 Files
  • Wrapping a c#/WPF GUI around c++/cli around native c++
  • triggering user space with kernel
  • Ruby 1.8.6 Array#uniq not removing duplicate hashes
  • Change Checkbox value without raising event
  • Get localized short date pattern as String?
  • In matplotlib, how do you change the fontsize of a single figure?
  • Spring: No transaction manager has been configured
  • accepts_nested_attributes_for practical form use for in Rails 3
  • Object and struct member access and address offset calculation
  • JSON with duplicate key names losing information when parsed
  • How to make Safari send if-modified-since header?
  • How to pass list parameters for each object using Spring MVC?
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • JaxB to read class hierarchy