You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by David Bloom <ya...@gmail.com> on 2004/09/28 21:36:38 UTC
verification of schema document
I have used JaxMe to unmarshall (schema doc to java classes).
The code is generated and compiles fine but it is not doing what I expected.
I want some kind of error kicked out if the
user does not supply (see below) correct number of chars for machine
type in the xml file. .
JaxME gives it a type of String :
public java.lang.String getMachineType();
public void
setMachineType(java.lang.String pMachineType);
I have considered binding in a verify function like:
unmarshaller.setValidating(true);
Validator v = context.createValidator();
MyHandler veh = new MyHandler();
v.setEventHandler(veh);
But, I thought that Jaxme would do this verification as built in since
the schema specifies a format of exactly 4 digit characters.
When I apply the xml to schema document, my IDE recognizes an error
when I place more than the specified number of digits. I was expecting
the same behavior
out of this jaxb implementation. Am I missing something?
Thanks in advance,
David
Below is a snippet of a schema doc:
<complexType name="sat_incidents">
<sequence>
<element name="sat_incident" minOccurs="0" maxOccurs="unbounded">
<complexType>
<sequence>
<element name="productName" type="string"/>
<element name="score" type="decimal"/>
</sequence>
<attribute name="machineType" type="sat:mtype"
use="required"/>
<attribute name="timestamp" type="sat:ts_format"
use="required"/>
</complexType>
</element>
</sequence>
</complexType>
..
<simpleType name="ts_format">
<restriction base="string">
<pattern value="\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}"/>
</restriction>
</simpleType>
<simpleType name="mtype">
<restriction base="string">
<pattern value="\d{4}" />
</restriction>
</simpleType>
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org
Re: verification of schema document
Posted by Jochen Wiedmann <jo...@freenet.de>.
David Bloom wrote:
> The code is generated and compiles fine but it is not doing what I expected.
> I want some kind of error kicked out if the
> user does not supply (see below) correct number of chars for machine
> type in the xml file. .
You are right, that such validation is not yet implemented. In fact, you
are the first one who asked for it. (About time! :-)
To add such a validation, have a look into the class AtomicTypeSGImpl,
method getCastFromString(String): This is the method generating the code
that unmarshals a string into the actual data type. This method could be
prefixed with code looking like this:
Facet patternFacet = pController.getFacet(Facet.PATTERN);
if (patternFacet != null) {
// Add code, that compares pValue against a regular expression
// compiled from patternFacet.getValues().
// Note: There may be multiple patterns to apply, do not use
// patternFacet.getValue()!
...
}
Patches are very welcome.
Jochen
--
http://lilypie.com/baby1/050423/1/5/1/+1
---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org