Saturday, July 3, 2010

JAXB generate Java classes from xsd

Using Excel, I have mapped a MFL to a XSD; now I want to generate the Java classes corresponding to the XSDs. JAX-WS uses JAXB as data binding, so:

http://java.sun.com/webservices/docs/1.6/jaxb/xjc.html

I use xjc.bat to generate the Java classes.

The alternative is: create a WebLogic WebService project, copy there your XSD, right click and "WebLogic WebServices / generate JAXB types", which internally invokes the XJC2Task Ant task.



XSD, specify sequence of OPTIONAL elements in ANY order

<xs:element name="GEOMQFeed">
 <xs:complexType>
  <xs:all>
   <xs:element ref="HEADER" minOccurs="1" maxOccurs="1"/>
   <xs:element ref="TAGA" minOccurs="0" maxOccurs="1"/>
   <xs:element ref="TAGB" minOccurs="0" maxOccurs="1"/>
   <xs:element ref="TAGC" minOccurs="0" maxOccurs="1"/>
  </xs:all>
 </xs:complexType>
</xs:element>


xs:all allows you to specify TAGA,TAGB,TAGC as well as TAGC,TAGB as well as TAGB,TAGA.
HEADER is the only compulsory element

The only problem, with xs:all, maxOccurs can be either 0 or 1!

If you want maxOccurs to be unbounded, you will have to use some workaround, as explained here:
http://xsd.stylusstudio.com/2003Mar/post09004.htm

The easiest one IMHO is to introduce a new type TAGAList defined as a unbounded sequence of TAGA. GEOMQFeed will be made by a xs:all of TAG?List.
Reality is that expressing a true arbitrary formal grammar in XSD is wishful thinking.


In other words..... with XSD you are only allowed to do what the XSD designers had in mind, not what you actually need :o(

In future I will look into http://www.relaxng.org/  which seems a more flexible language than XSD.

Friday, July 2, 2010

Windows Explorer cannot find files

http://support.microsoft.com/default.aspx?scid=kb;en-us;309173


set the FilterFilesWithUnknownExtensions DWORD value to 1 in the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex

Remember also to enable the "find hidden files" advanced option.

This is one of those jaw-dropping things ... why on earth would you NOT want to find files with unregistered extension...