Hi all,

I've made some initial steps towards adding better websphere support to 
xdoclet.  These are by no means complete, but I would appreciate feedback, 
as this is the first attempt I've made at extending XDoclet.  Basically, I 
was just looking to make sure that I could get servlets and resource 
references defined properly.

Basically, what I did is this.  At Ara's suggestion, I've modified 
IdTagsHandler a little bit to provide a functionality for prefixed unique 
identifiers like the ones that WebSphere's AAT uses.  I've added a 
parameter to the deploymentdescriptor task called 'useIds' which will 
toggle the generation of these unique element id's on or off for certain 
components in the web.xml file (with the appropriate changes to 
web_xml.j). 

I've also created another task (webSphereWebBndXmi) to create the 
ibm-web-bnd.xmi deployment descriptor.  It scans for tags like 
@websphere:res-ref to map servlet resource references to jndi names.  (due 
to the indexed id stuff, there is a caveat that the @servlet:resource-ref 
tags and the @websphere:res-ref tags must be in the same order -- I'm 
still thinking this one through --- I'm sure it's solvable with a smarter 
indexed id method --- maybe in a new class specific for websphere -- we'll 
see)  You can also set the virtual host to be deployed on via the ant task 
with the 'virtualHost' parameter (defaults to the WAS 4.0 default of 
'default_host').

I've attached the diffs for the 3 files I modified, and the two additional 
files I created.  I hope this helps a little, I'd like to extend this to 
include all of the servlet options (including generation of 
ibm-web-ext.xmi), and then continue on to the ejb generation stuff 
(schemas, etc.)

thanks,
jason


Index: core/resources/xdoclet/web/web_xml.j
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/resources/xdoclet/web/web_xml.j,v
retrieving revision 1.28
diff -r1.28 web_xml.j
2a3,5
> <XDtId:resetPrefixId />
> 
> <web-app<XDtConfig:ifConfigParamEquals paramName="useIds" value="true"> 
>id="WebApp_ID"</XDtConfig:ifConfigParamEquals>>
4d6
< <web-app>
106c108
<    <servlet>
---
>    <servlet<XDtConfig:ifConfigParamEquals paramName="useIds" value="true"> 
>id="<XDtId:prefixId prefix="Servlet"/>"</XDtConfig:ifConfigParamEquals>>
160c162
<    <servlet-mapping>
---
>    <servlet-mapping<XDtConfig:ifConfigParamEquals paramName="useIds" value="true"> 
>id="<XDtId:prefixId prefix="ServletMapping"/>"</XDtConfig:ifConfigParamEquals>>
235c237
<    <resource-ref>
---
>    <resource-ref<XDtConfig:ifConfigParamEquals paramName="useIds" value="true"> 
>id="<XDtId:prefixId prefix="ResourceRef"/>"</XDtConfig:ifConfigParamEquals>>
Index: core/src/xdoclet/tags/IdTagsHandler.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/tags/IdTagsHandler.java,v
retrieving revision 1.7
diff -r1.7 IdTagsHandler.java
13a14
> import java.util.Hashtable;
21a23,24
>       private static Hashtable prefixHash = new Hashtable();
> 
44a48,101
> 
>       /**
>        * Resets the hashtable which backs the prefixId tag.
>        *
>        * @exception XDocletException  Description of Exception
>        * @doc:tag                     type="content"
>        */
>       public void resetPrefixId() throws XDocletException
>       {
>               prefixHash = new Hashtable();
>       }
> 
>       /**
>        * Generates an id attribute based on the given prefix. This is used for
>        * generating id attribute for XML elements.
>        *
>        * @param attributes            The attributes of the template tag
>        * @return                      An id in the form of &lt;prefix&gt;_&lt;num&gt;
>        * @exception XDocletException  Description of Exception
>        * @doc:tag                     type="content"
>        * @doc:param                   name="prefix" optional="false" description="The
>        *      tag from which the value of the id is calculated."
>        */
>       public String prefixId( Properties attributes ) throws XDocletException
>       {
>               String prefix_name = attributes.getProperty( "prefix" );
> 
>               if( prefix_name != null )
>               {
>                       String retval = null;
> 
>                       if( prefixHash.containsKey( prefix_name ) )
>                       {
> 
>                               Integer val = ( Integer ) prefixHash.get( prefix_name 
>);
>                               Integer valPlusOne = new Integer( ( val.intValue() ) + 
>1 );
> 
>                               prefixHash.put( prefix_name, valPlusOne );
>                               retval = prefix_name + "_" + valPlusOne;
>                       }
>                       else
>                       {
>                               prefixHash.put( prefix_name, new Integer( 1 ) );
>                               retval = prefix_name + "_1";
>                       }
>                       return retval;
>               }
>               else
>               {
>                       System.out.println( Translator.getString( 
>"attribute_not_set_erro", new String[]{"prefix"} ) );
>                       return "";
>               }
>       }
> 
Index: core/src/xdoclet/web/WebDocletTask.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/web/WebDocletTask.java,v
retrieving revision 1.14
diff -r1.14 WebDocletTask.java
7a8
> import xdoclet.web.vendor.WebSphereWebBndXmiSubTask;
26a28
>       protected WebSphereWebBndXmiSubTask webspherewebbndxmi;
69a72,77
>       public WebSphereWebBndXmiSubTask createWebSphereWebBndXmi()
>       {
>               webspherewebbndxmi = new WebSphereWebBndXmiSubTask();
>               return webspherewebbndxmi;
>       }
> 
80a89
>               subtasks.addElement( this.webspherewebbndxmi );
Index: core/src/xdoclet/web/WebXmlSubTask.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/web/WebXmlSubTask.java,v
retrieving revision 1.13
diff -r1.13 WebXmlSubTask.java
38a39,40
>       protected boolean  useIds = false;
> 
94a97,101
>       public boolean getUseIds()
>       {
>               return useIds;
>       }
> 
137a145,149
>       }
> 
>       public void setUseIds( boolean useIds )
>       {
>               this.useIds = useIds;

Attachment: WebSphereWebBndXmiSubTask.java
Description: Binary data

Attachment: websphere_web_bnd_xmi.j
Description: Binary data

Reply via email to