Hi Keith,
Please find attached the changes I have made to MappingTool for your
review/comment/inclusion/derision. It is a cvs-diff: hope that's ok.
There are two changes:
1) allow the -i option to be a list of classnames (handy for things like
soap interfaces where there are a number of messages I want to bundle
together as a single interface). Separator is comma, semicolon or space.
2) make sure the namespaces are handled. I generate namespace prefixes as
ns1,ns2...
Regards
Dean
> -----Original Message-----
> From: Keith Visco [mailto:[EMAIL PROTECTED]
> Sent: Friday, 18 July 2003 10:54 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] Mapping generated Castor classes
>
>
>
>
> "Chalker, Dean" wrote:
> >
> > Cool. I am happy to use MappingTool, warts and all.
> Being a Castor-newbie
> > (as you can tell from my postings) I wasn't sure whether I
> was seeing a
> > short coming of the tool, or whether I just misunderstood again.
> >
> > Would you encourage me to look at fixing the cst:ns-prefix
> and xsd:choice
> > issues? I would be happy to do so (assuming I can find
> the time :-), but
> > perhaps not so interesting if you think my problems are
> not relevant to
> > others.
>
> Any improvements over current limitations or bug fixes are always
> welcome.
>
> --Keith
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
Index: main/org/exolab/castor/tools/MappingTool.java
===================================================================
RCS file: D:/CvsRepo/Main/castor/src/main/org/exolab/castor/tools/MappingTool.ja
va,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 MappingTool.java
71a72
> import org.exolab.castor.xml.util.XMLFieldDescriptorImpl;
82a84
> import java.util.StringTokenizer;
132a135,144
> /**
> * Counter used for generate namespaces
> **/
> private int _nsPrefixCount = 0;
>
> /**
> * Map of namespace URI to prefix
> **/
> private Hashtable _nsPrefixTable = new Hashtable();
>
189c201,207
< tool.addClass( classname );
---
>
> //-- support list of classes
> //-- (dchalker - 20030721)
> StringTokenizer tok = new StringTokenizer(classname, ",; ");
> while (tok.hasMoreTokens()) {
> tool.addClass(tok.nextToken());
> }
329a348,354
> //-- generate a namespace prefix if necessary
> //-- (dchalker - 20030721)
> if (mapTo.getNsPrefix() == null && mapTo.getNsUri() != null
> && !mapTo.getNsUri().equals("http://castor.exolab.org/")
) {
> generateNsPrefix(mapTo);
> }
>
348a374,383
> // impose namespace prefix if required
> //-- (dchalker - 20030721)
> if (mapTo.getNsPrefix() != null) {
> XMLFieldDescriptorImpl xfd = (XMLFieldDescriptorImpl)fdesc;
> if (xfd.getNameSpacePrefix() == null) {
> xfd.setNameSpacePrefix(mapTo.getNsPrefix());
> xfd.setXMLName(mapTo.getNsPrefix() + ":" + xfd.getXMLNam
e());
> }
> }
>
441a477
>
460a497,511
> /**
> * Generate a namespace prefix for a mapping.
> *
> * @param mapTo MapTo to generate a namespace instance for
> **/
> private void generateNsPrefix(MapTo mapTo) {
> String nsUri = mapTo.getNsUri();
> String nsPrefix = (String)_nsPrefixTable.get(nsUri);
> if (nsPrefix == null) {
> nsPrefix = "ns" + ++_nsPrefixCount;
> _nsPrefixTable.put(nsUri, nsPrefix);
> }
> mapTo.setNsPrefix(nsPrefix);
> }
>
481a533,540
> //-- include mapping namespaces
> //-- (dchalker - 20030722)
> enum = _nsPrefixTable.keys();
> while ( enum.hasMoreElements() ) {
> String nsUri = (String)enum.nextElement();
> String nsPrefix = (String)_nsPrefixTable.get(nsUri);
> marshal.setNamespaceMapping(nsPrefix, nsUri);
> }