32.2. Simple Types Defined by Restriction
Overview
simpleType
element.
Procedure
- Determine the base type for your new simple type.
- Determine what restrictions define the new type based on the available facets for the chosen base type.
- Using the syntax shown in this section, enter the appropriate
simpleType
element into the types section of your contract.
Defining a simple type in XML Schema
Example 32.1. Simple type syntax
<simpleType name="typeName"> <restriction base="baseType"> <facet value="value" /> <facet value="value" /> ... </restriction> </simpleType>
simpleType
element and identified by the value of the name
attribute. The base type from which the new simple type is being defined is specified by the base
attribute of the xsd:restriction
element. Each facet element is specified within the restriction
element. The available facets and their valid settings depend on the base type. For example, xsd:string has a number of facets including:
length
minLength
maxLength
pattern
whitespace
TX
is a valid value, but tx
or tX
are not valid values.
Example 32.2. Postal Code Simple Type
<xsd:simpleType name="postalCode"> <xsd:restriction base="xsd:string"> <xsd:pattern value="[A-Z]{2}" /> </xsd:restriction> </xsd:simpleType>
Mapping to Java
String
because the base type of postalCode is xsd:string. For example, the WSDL fragment shown in Example 32.3, “Credit Request with Simple Types” results in a Java method, state()
, that takes a parameter, postalCode
, of String
.
Example 32.3. Credit Request with Simple Types
<message name="stateRequest"> <part name="postalCode" type="postalCode" /> </message> ... <portType name="postalSupport"> <operation name="state"> <input message="tns:stateRequest" name="stateRec" /> <output message="tns:stateResponse" name="credResp" /> </operation> </portType>
Enforcing facets
true
. Example 32.4, “Service Provider Configured to Use Schema Validation” shows the configuration for a service provider that uses schema validation
Example 32.4. Service Provider Configured to Use Schema Validation
<jaxws:endpoint name="{http://apache.org/hello_world_soap_http}SoapPort"
wsdlLocation="wsdl/hello_world.wsdl"
createdFromAPI="true">
<jaxws:properties>
<entry key="schema-validation-enabled" value="BOTH" />
</jaxws:properties>
</jaxws:endpoint>