Hello,

I often run into the situation where I want to use a custom (non-built in)
simple type in an XML document that would be well translated to a Java
class. A UUID is a good example:

    <xs:simpleType name="uuid">

        <xs:restriction base="xs:string">

        <xs:pattern
value="[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"/>

</xs:restriction>
 
    </xs:simpleType>

Here, xs:string is the base class, obviously. What would be nice is to
indicate in the xsdconfig a handler to convert the base class into a UUID
and have any xmlbeans generated interfaces return and set a UUID in the
convenience getters and setters. The xget and xset would obviously remain
the same.



A simple encoder/decoder for the UUID example would look like this:

    String encodeUuid(XmlObject xmlObj, UUID obj)

    UUID decodeUuid(XmlObject xmlObj, String str)

Where in general the signature would have to be:

  SomeXmlSimpleType encodeUserTypeName(XmlObject xmlObj, JavaUserType obj)

  JavaUserType decodeUserTypeName(XmlObject xmlObj, SomeXmlSimpleType type)


Question: In the signature should it be String (the java convenience type)
or the XML type (e.g., XmlString)? Or perhaps the actual derived simple type
(the type returned by the matching xget)?


The xsdconfig would generally look like the following:


   <xb:usertype name="uuid" javaname="java.util.UUID">
     <xb:staticHandler>com.example.UUIDType</xb:staticHandler>
   </xb:usertype>
    

So, operationally, that would be my proposal. Obviously I am looking for any
input on that aspect.

Additionally, I would like any advice on the implementation approach I
should take.

As for the actual generated code, the biggest problem I have with the
extensions interface stuff is that it statically compiles in references to
the static handlers, which is a pain for circular dependencies. I'm planning
on using reflection to get a handle on the static handler, and wonder if
there are any major objections here. Obviously it's less efficient at
runtime and can result in runtime linking problems, but for my use this is
not going to be a problem. The only reason I mention it is to question
whether it's so objectionable to the general population that I need to add
some sort of scomp flag that allows use of reflection to be optional.


Some other thoughts:

Why can't I just use extensions interface? Extensions interface is to much
of a kludge. It acts on elements, when I just need to extend the type
system.

I was originally thinking of attaching this sort of functionality to
individual elements or attributes, but I changed my mind and decided that
this is really a type system thing.


Thanks for any input.

Wesley Leggette
Cleversafe, Inc.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@xmlbeans.apache.org
For additional commands, e-mail: dev-h...@xmlbeans.apache.org

Reply via email to