Java XSD file generates Integer instad of Long - java

XSD file generates Integer instad of Long
XSD file contains:
<xsd:attribute name="test" name="Long1000000To99999999999"/>
Other file contains simpleType
<xsd:simpleType name="Long1000000To99999999999">
<xsd:restriction base="xsd:long">
<xsd:minInclusive value="1000000"/>
<xsd:maxInclusive value="99999999999"/>
</xsd:restriction>
</xsd:simpleType>
the result of generateing it is wrong type of test field jaxb2 generates test field as a Integer instaed of Long
Does someone know how to generate filed as a Long and not as a Integer?

Related

Translate enum value to Apache Axis SimpleType

I have programmed a method that translates a normal java enum value to a value of a class generated from a SimpleType in an xsd file. The enum and the SimpleType are identical in content. Unfortunately my method returns null.
public enum Type {
VALUE_A, VALUE_B;
public static com.name.phi.framework.ws.mediaScanner.Type convertToWSDL(Type type) {
return com.name.phi.framework.ws.mediaScanner.Type.Factory.fromValue(type.toString());
}
}
In the xsd file the SimpleType is defined as follows:
<xsd:simpleType name="Type">
<xsd:annotation>
<xsd:documentation>Type definition<br/>
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="VALUE_A"/>
<xsd:enumeration value="VALUE_B"/>
</xsd:restriction>
</xsd:simpleType>
Using the following plugin to generate the java classes:
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
Does anyone have an idea how I can translate the enum value?. Thanks in advance.

Issue with generating sources from xsd schema

I'm getting the following error when generating sources for my project. I have extracted a few common types to a schema called CommonTypes.xsd and I get the following error:
org.xml.sax.SAXParseException: src-resolve.4.1: Error resolving component 'nonEmptyString'. It was detected that 'nonEmptyString' has no namespace, but components with no target namesp
ace are not referenceable from schema document 'file:/C:/Workspace/CommonTypes.xsd'. If 'nonEmptyString' is
intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'nonEmptyString' has no namespace, then an 'import' without a "namespace" attribute should
be added to 'file:/C:/Workspace/lps-performance-calculation-service/pcs-data/src/main/resources/xsd/calc/lps/CommonTypes.xsd'.
The following simple type is defined in my CommonTypes.xsd schema as below:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:unit="http://www.mywebsite.com/unit"
xmlns:types="http://www.mywebsite.com/types"
elementFormDefault="qualified" attributeFormDefault="unqualified"
targetNamespace="http://www.mywebsite.com//types">
<!-- import types -->
<xsd:import namespace="http://www.mywebsite.com/unit"/>
<!-- other common types -->
<xsd:simpleType name="nonEmptyString">
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
<xsd:pattern value=".*[^\s].*"/>
</xsd:restriction>
</xsd:simpleType>
And line 241 which causes the error is below:
<xsd:complexType name="Message">
<xsd:simpleContent>
<xsd:extension base="nonEmptyString">
<xsd:attribute type="xsd:string" name="code" use="required"/>
<xsd:attribute name="category" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:token">
<xsd:enumeration value="Error"/>
<xsd:enumeration value="Info"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute type="xsd:string" name="component" use="required"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
Do you have any idea what may cause the error? I've tried searching through StackOverflow and experimenting with the targetNamespace and xmlns, but with no success.
You are trying to refer to a simple type which has
name 'nonEmptyString'
namespace ""
But the simple type 'nonEmptyString' is defined in this XSD, which has targetNamespace="http://www.mywebsite.com//types". So you should be referring to a simple type which has
name 'nonEmptyString'
namespace "http://www.mywebsite.com//types"
You simply need to change this:
<xsd:extension base="nonEmptyString">
to this:
<xsd:extension base="types:nonEmptyString">
You need to import your nonEmptyString in the corresponding namespace and make this namespace referenceable via the prefix.
To do this, add xmlns:types="http://www.mywebsite.com/types" to xsd:schema of the importing schema.
Also provide the namespace in xsd:import of the importing schema. Should be something like:
<xsd:import
namespace="http://www.mywebsite.com/types"
schemaLocation="calc/lps/CommonTypes.xsd"/>
Then you should be able to reference your nonEmptyString type as types:nonEmptyString.

wsimport not generating type class

I have the following element in my web service request and used wsimport to generate client. I also have other enum types which get classes generated. As this particular type contains values like 1-Critical I think it fails to generate enum type but treats it as String.
<xsd:element type="s0:UrgencyType" name="Urgency" nillable="true" minOccurs="0" maxOccurs="1"/>
<xsd:simpleType name="UrgencyType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="1-Critical"/>
<xsd:enumeration value="2-High"/>
<xsd:enumeration value="3-Medium"/>
<xsd:enumeration value="4-Low"/>
</xsd:restriction>
</xsd:simpleType>
The generated parameter as below.
#WebParam(name = "Urgency", targetNamespace = "urn:GIL:Create_WS")
String urgency,
I want the variable urgency type to be UrgencyType.

How to generate case sensitive fields in java from wsdl using cxf-codegen-plugin?

I'm using cxf-codegen-plugin and try to generate java from wsdl.
In my xsd schema I have following element
<xsd:element name="SomeElement">
<xsd:complexType>
<xsd:attribute name="version" type="xsd:string" use="optional">
</xsd:attribute>
<xsd:attribute name="Version" type="xsd:string" use="optional">
</xsd:attribute>
</xsd:complexType>
</xsd:element>
CXF tries to generate both attributes into field version and throws exception that property already exists.
Is there any way to generate properties as they described in XML? e.g.
protected String version;
protected String Version;
I know, that I can define binding and rename one of the properties, but I have ~100 wsdl, so I don't want write bindings for each file.
I also tried to add -autoNameResolution argument, but it didn't help.

Element#getAttribute not returning default value when attribute isn't present

I have the following XML file:
<el id="el1">content</el>
The part of my file which defines the element above is as follows:
<xsd:element name="el" type="myns:el" />
<xsd:simpleType name="state">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="enabled" />
<xsd:enumeration value="disabled" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="el">
<xsd:attribute name="id" type="xsd:string" use="required" />
<xsd:attribute name="state" type="myns:state"
default="enabled" />
</xsd:complexType>
My Java code which is supposed to obtain the default value for state looks like the following:
Element e = (Element) ns.getElementsByTagName("el").item(0);
System.out.println(e.getAttribute("state"));
The code above always prints an empty string if I don't set the state attribute in the XML file. Why is that the case? According to the Java documentation, getAttribute returns
The Attr value as a string, or the empty string if that attribute does
not have a specified or default value.
My question is: why doesn't getAttribute return the default value when a value is not specified?

Categories