Update of
/cvsroot/xdoclet-plugins/xdoclet-plugins/plugin-xwork/src/main/java/org/xdoclet/plugin/xwork
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12273/src/main/java/org/xdoclet/plugin/xwork
Modified Files:
XWorkXMLPlugin.java XWorkXMLPlugin.jelly
Log Message:
action mapping plugin is ready to be testeed
Index: XWorkXMLPlugin.java
===================================================================
RCS file:
/cvsroot/xdoclet-plugins/xdoclet-plugins/plugin-xwork/src/main/java/org/xdoclet/plugin/xwork/XWorkXMLPlugin.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** XWorkXMLPlugin.java 8 Feb 2005 03:48:46 -0000 1.5
--- XWorkXMLPlugin.java 12 Apr 2006 18:18:11 -0000 1.6
***************
*** 7,78 ****
import java.io.File;
!
! import java.util.Collection;
!
! import org.apache.commons.collections.CollectionUtils;
import org.generama.JellyTemplateEngine;
import org.generama.QDoxCapableMetadataProvider;
- import org.generama.defaults.QDoxPlugin;
import org.generama.WriterMapper;
!
import org.xdoclet.plugin.xwork.qtags.TagLibrary;
! import org.xdoclet.predicate.IsA;
/**
! * plugin producing xwork mapping declarations
! *
* @author Jose Peleteiro
* @version $Revision$
*/
public class XWorkXMLPlugin extends QDoxPlugin {
-
- private static final String ACTION_CLASSNAME =
"com.opensymphony.xwork.Action";
- private Collection actionClasses;
! // plugin params
! private File mergeFile = null;
! private String fileName = "xwork.xml";
! public XWorkXMLPlugin(JellyTemplateEngine jellyTemplateEngine,
QDoxCapableMetadataProvider metadataProvider,
! WriterMapper writerMapper) {
! super(jellyTemplateEngine, metadataProvider, writerMapper);
! // setup tags
! new TagLibrary(metadataProvider);
! // it generates just one file, classes by default xwork.xml
! this.setMultioutput(false);
! }
! public Collection getActionClasses() {
! if (actionClasses == null) {
! this.actionClasses =
CollectionUtils.select(metadataProvider.getMetadata(), new
IsA(ACTION_CLASSNAME));
! }
! return this.actionClasses;
! }
! public void setFilename(String value) {
! this.fileName = value;
! }
! public String getFilename() {
! return this.fileName;
! }
! public void setMergefile(File value) {
! this.mergeFile = value;
! }
! public File getMergefile() {
! return this.mergeFile;
! }
! public void start() {
! this.setFilereplace(this.getFilename());
! super.start();
! }
}
\ No newline at end of file
--- 7,240 ----
import java.io.File;
! import java.util.ArrayList;
! import java.util.Iterator;
! import java.util.List;
import org.generama.JellyTemplateEngine;
import org.generama.QDoxCapableMetadataProvider;
import org.generama.WriterMapper;
! import org.generama.defaults.QDoxPlugin;
! import org.xdoclet.plugin.xwork.model.Action;
! import org.xdoclet.plugin.xwork.model.ExceptionMapping;
! import org.xdoclet.plugin.xwork.model.InterceptorRef;
! import org.xdoclet.plugin.xwork.model.Parametrizable;
! import org.xdoclet.plugin.xwork.model.Result;
import org.xdoclet.plugin.xwork.qtags.TagLibrary;
+ import org.xdoclet.plugin.xwork.qtags.XworkActionTag;
+ import org.xdoclet.plugin.xwork.qtags.XworkExceptionMappingTag;
+ import org.xdoclet.plugin.xwork.qtags.XworkInterceptorRefTag;
+ import org.xdoclet.plugin.xwork.qtags.XworkParamTag;
+ import org.xdoclet.plugin.xwork.qtags.XworkResultTag;
! import com.thoughtworks.qdox.model.AbstractInheritableJavaEntity;
! import com.thoughtworks.qdox.model.DocletTag;
! import com.thoughtworks.qdox.model.JavaClass;
! import com.thoughtworks.qdox.model.JavaMethod;
/**
! * plugin producing xwork mapping declarations.
! *
! * this plugin will produce mapping declarations for single package. resulting
! * xml file can be included into master configuration.
! *
! * for now it processes only action classes ( which are just a POJOs and do
not
! * require any superclasses / interfaces )
! *
! * interceptor stuff etc shall be merged in.
! *
* @author Jose Peleteiro
+ * @author Konstantin Pribluda
* @version $Revision$
*/
public class XWorkXMLPlugin extends QDoxPlugin {
! boolean _abstract;
! private String _extends;
! String _package;
! private List actions = new ArrayList();
! private String fileName = "xwork.xml";
! // plugin params
! private File mergeFile = null;
! String namespace;
! public XWorkXMLPlugin(JellyTemplateEngine jellyTemplateEngine,
! QDoxCapableMetadataProvider metadataProvider,
! WriterMapper writerMapper) {
! super(jellyTemplateEngine, metadataProvider, writerMapper);
! // setup tags
! new TagLibrary(metadataProvider);
! // it generates just one file, classes by default xwork.xml
! this.setMultioutput(false);
! }
! void processEntity(AbstractInheritableJavaEntity entity) {
! DocletTag tag;
! Object currentConfigObject = null;
! Action currentAction = null;
! for (int i = 0; i < entity.getTags().length; i++) {
! tag = entity.getTags()[i];
! // in this case we initialize action config
! // and wire it to package
! if (tag instanceof XworkActionTag) {
!
! currentAction = new
Action(entity,(XworkActionTag) tag);
!
! // check whether we like this action in our
package
! // we take it if package matches ( or not
specified )
! if (currentAction.getPackageName() == null
! ||
currentAction.getPackageName().equals(
! getPackage())) {
! // fine, we take this action
! actions.add(currentAction);
! }
! currentConfigObject = currentAction;
! } else if (tag instanceof XworkResultTag) {
! // result applies to an action
! if (currentAction != null) {
! Result result = new
Result((XworkResultTag) tag);
! currentAction.addResult(result);
! currentConfigObject = result;
! }
! } else if (tag instanceof XworkParamTag) {
! // param tag generally applies to current
paramtetrizable
! // object
! if (currentConfigObject instanceof
Parametrizable) {
! ((Parametrizable)
currentConfigObject).addParam(
! ((XworkParamTag)
tag).getName_(),
! ((XworkParamTag)
tag).getValue_());
! }
! } else if( tag instanceof XworkInterceptorRefTag ){
! if(currentAction != null) {
!
! InterceptorRef ref = new
InterceptorRef((XworkInterceptorRefTag) tag);
! currentAction.addInterceptorRef(ref);
! currentConfigObject = ref;
! }
! } else if( tag instanceof XworkExceptionMappingTag ){
! if(currentAction != null) {
! ExceptionMapping mapping = new
ExceptionMapping((XworkExceptionMappingTag) tag);
!
currentAction.addExceptionMapping(mapping);
! currentConfigObject = mapping;
! }
! }
!
! }
! }
! /**
! * create package model from metadata provider
! */
! void buildModel() {
! // walk through classes and see whether they are our actions
! // (belong to our package)
! JavaClass clazz;
! JavaMethod method;
! for (Iterator iter = getMetadata().iterator(); iter.hasNext();)
{
! clazz = (JavaClass) iter.next();
! processEntity(clazz);
!
! for(int i = 0; i < clazz.getMethods().length; i++) {
! method = clazz.getMethods()[i];
!
System.err.println(method.getReturns().getJavaClass().getName());
!
if(method.getReturns().getJavaClass().getName().equals("String") &&
method.getParameters().length == 0) {
! // our candidate methods return string
and have no parameters
! processEntity(method);
! }
! }
! }
! }
!
! public List getActions() {
! return actions;
! }
!
! /**
! * parent of this package
! * @return
! */
! public String getExtends() {
! return _extends;
! }
!
! /**
! * destination file name
! *
! * @return
! */
! public String getFilename() {
! return this.fileName;
! }
!
! /**
! * merge file for basic setings
! * @return
! */
! public File getMergefile() {
! return this.mergeFile;
! }
!
! /**
! * namespace of pckage
! * @return
! */
! public String getNamespace() {
! return namespace;
! }
!
! /**
! * package name
! * @return
! */
! public String getPackage() {
! return _package;
! }
!
! /**
! * whether generated package shall be declared as abstract
! * @return
! */
! public boolean getAbstract() {
! return _abstract;
! }
! public void setAbstract(boolean _abstract) {
! this._abstract = _abstract;
! }
!
! public void setActions(List actions) {
! this.actions = actions;
! }
!
! public void setExtends(String _extends) {
! this._extends = _extends;
! }
!
! public void setFilename(String value) {
! this.fileName = value;
! }
!
! public void setMergefile(File value) {
! this.mergeFile = value;
! }
!
! public void setNamespace(String namespace) {
! this.namespace = namespace;
! }
!
! public void setPackage(String _package) {
! this._package = _package;
! }
!
! public void start() {
! this.setFilereplace(this.getFilename());
! buildModel();
! super.start();
! }
}
\ No newline at end of file
Index: XWorkXMLPlugin.jelly
===================================================================
RCS file:
/cvsroot/xdoclet-plugins/xdoclet-plugins/plugin-xwork/src/main/java/org/xdoclet/plugin/xwork/XWorkXMLPlugin.jelly,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** XWorkXMLPlugin.jelly 28 Nov 2004 19:44:24 -0000 1.2
--- XWorkXMLPlugin.jelly 12 Apr 2006 18:18:11 -0000 1.3
***************
*** 1,58 ****
<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml" xmlns:jsl="jelly:jsl">
<!--
!
! Read the merge xml or just fake one.
-->
! <x:parse var="mergeData">
! <xwork/>
! </x:parse>
! <j:if test="${plugin.getMergefile().exists()}">
! <x:parse var="mergeData" xml="${plugin.getMergefile()}"/>
! </j:if>
! <!--
- Add package declarations to packages that wan't declared on merge file,
if it exists,
- or just create all the package declarations.-->
- <j:import uri="org/xdoclet/plugin/xwork/xworkxml/packages.jelly"
inherit="true"/>
- <!--
! Add complete action declarations -->
! <jsl:stylesheet select="$mergeData">
! <jsl:template match="//package">
! <jsl:copy>
! <jsl:applyTemplates/>
! <j:forEach var="actionClass"
items="${plugin.getActionClasses()}">
! <j:set var="classTags" value="${actionClass.getTags()}"/>
! <j:set var="packageNamespace">
! <x:expr select="@namespace"/>
! </j:set>
! <j:forEach var="classTag" items="${classTags}">
! <j:if test="${classTag.name == 'xwork.action'}">
! <j:set var="actionTag" value="${classTag}"/>
! <j:if test="${packageNamespace ==
classTag.namespace}">
! <action name="${actionTag.name_}"
class="${actionClass.getFullyQualifiedName()}">
! <j:set var="isItOnTheActionContext"
value="false"/>
! <j:forEach var="classTag"
items="${classTags}">
! <j:if test="${classTag.name ==
'xwork.action'}">
! <j:set
var="isItOnTheActionContext" value="${classTag.name_ == actionTag.name_}"/>
! </j:if>
! <j:if
test="${isItOnTheActionContext}">
! <j:import
uri="org/xdoclet/plugin/xwork/xworkxml/result.jelly" inherit="true"/>
! <j:import
uri="org/xdoclet/plugin/xwork/xworkxml/interceptor.jelly" inherit="true"/>
! </j:if>
! </j:forEach>
! </action>
! </j:if>
! </j:if>
</j:forEach>
! </j:forEach>
! </jsl:copy>
! </jsl:template>
! <jsl:template match="*" trim="false">
! <jsl:copy>
! <jsl:applyTemplates/>
! </jsl:copy>
! </jsl:template>
! <jsl:template match="@*" trim="false"/>
! </jsl:stylesheet>
</j:jelly>
--- 1,75 ----
+ <?xml version="1.0" encoding="UTF-8"?>
<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml" xmlns:jsl="jelly:jsl">
+
+ <x:doctype name="xwork" publicId="-//OpenSymphony Group//XWork 1.1.1//EN"
systemId="http://www.opensymphony.com/xwork/xwork-1.1.1.dtd" trim="true" />
+ <xwork>
<!--
! Read the merge file if there is any
-->
! <j:choose>
! <j:when test="${plugin.getMergefile().exists()}">
! <x:parse var="merge" xml="${plugin.getMergefile()}"/>
! <jsl:stylesheet select="$merge">
! <!-- Matches all nodes -->
! <jsl:template match="*" trim="false">
! <jsl:copy>
! <jsl:applyTemplates/>
! </jsl:copy>
! </jsl:template>
! <!-- Bypass top element; "/" select document node, parent of
top node -->
! <jsl:template match="/" trim="false">
! <jsl:applyTemplates select="child::*/child::*" />
! </jsl:template>
!
! </jsl:stylesheet>
! </j:when>
! <j:otherwise>
! <x:comment>
! To add default configuration specify "mergefile"
parameter. Root node of
! document will be ignored
! </x:comment>
! </j:otherwise>
! </j:choose>
! <!--
! our package declaration comes from plugin
! -->
! <package name="${plugin.package}" namespace="${plugin.namespace}"
! extends="${plugin.extends}" abstract="${plugin.abstract}">
! <j:forEach var="action" items="${plugin.actions}">
! <action name="${action.name}" class="${action.className}"
method="${action.method}">
! <!-- action parameters -->
! <j:forEach var="name" items="${action.params.keySet()}">
! <param
name="${name}">${action.params.get(name)}</param>
</j:forEach>
! <!-- result definition -->
! <j:forEach var="result" items="${action.results}">
!
! <result name="${result.name}" type="${result.type}">
! ${result.value}
! <!-- result parameters -->
! <j:forEach var="name"
items="${result.params.keySet()}">
! <param
name="${name}">${result.params.get(name)}</param>
! </j:forEach>
! </result>
! </j:forEach>
! <j:forEach var="interceptorRef"
items="${action.interceptorRefs}">
! <interceptor-ref name="${interceptorRef.name}">
! <j:forEach var="name"
items="${interceptorRef.params.keySet()}">
! <param
name="${name}">${interceptorRef.params.get(name)}</param>
! </j:forEach>
! </interceptor-ref>
! </j:forEach>
! <j:forEach var="exceptionMapping"
items="${action.exceptionMappings}">
! <exception-mapping
exception="${exceptionMapping.exception}" result="${exceptionMapping.result}">
! <j:forEach var="name"
items="${exceptionMapping.params.keySet()}">
! <param
name="${name}">${exceptionMapping.params.get(name)}</param>
! </j:forEach>
! </exception-mapping>
! </j:forEach>
! </action>
! </j:forEach>
! </package>
! </xwork>
</j:jelly>
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
xdoclet-plugins-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xdoclet-plugins-commits