Anonymous avatar Anonymous committed da28fae

Add default-class-ref element

Issue number: XW-432
Submitted by: Jason Parrott

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1215 e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (4)

src/java/com/opensymphony/xwork2/config/entities/PackageConfig.java

     private String defaultInterceptorRef;
     private String defaultActionRef;
     private String defaultResultType;
+    private String defaultClassRef;
     private String name;
     private String namespace = "";
     private boolean isAbstract = false;
         return defaultActionRef;
     }
 
+    public void setDefaultClassRef( String defaultClassRef ) {
+       this.defaultClassRef = defaultClassRef;
+    }
+    
+    public String getDefaultClassRef() {
+       return defaultClassRef;
+    }
+    
     /**
      * sets the default Result type for this package
      *
             return false;
         }
 
+        if ((defaultClassRef != null) ? (!defaultClassRef.equals(packageConfig.defaultClassRef)) : (packageConfig.defaultClassRef != null))
+        {
+            return false;
+        }
+
         if ((globalResultConfigs != null) ? (!globalResultConfigs.equals(packageConfig.globalResultConfigs)) : (packageConfig.globalResultConfigs != null))
         {
             return false;
         result = (29 * result) + ((resultTypeConfigs != null) ? resultTypeConfigs.hashCode() : 0);
         result = (29 * result) + ((globalExceptionMappingConfigs != null) ? globalExceptionMappingConfigs.hashCode() : 0);
         result = (29 * result) + ((defaultResultType != null) ? defaultResultType.hashCode() : 0);
+        result = (29 * result) + ((defaultClassRef != null) ? defaultClassRef.hashCode() : 0);
         result = (29 * result) + ((namespace != null) ? namespace.hashCode() : 0);
         result = (29 * result) + (isAbstract ? 1 : 0);
 

src/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java

         //methodName should be null if it's not set
         methodName = (methodName.trim().length() > 0) ? methodName.trim() : null;
 
-        // if you don't specify a class on <action/>, it defaults to ActionSupport
+        // if there isnt a class name specified for an <action/> then try to
+        // use the default-class-ref from the <package/>
         if (!TextUtils.stringSet(className)) {
-            className = ActionSupport.class.getName();
+           // if there is a package default-class-ref use that, otherwise use action support
+           if (TextUtils.stringSet(packageContext.getDefaultClassRef())) {
+               className = packageContext.getDefaultClassRef();
+           } else {
+               className = ActionSupport.class.getName();
+           }   
         }
 
         if (!verifyAction(className, name, location)) {
         // load the default interceptor reference for this package
         loadDefaultInterceptorRef(newPackage, packageElement);
 
+        // load the default class ref for this package
+        loadDefaultClassRef(newPackage, packageElement);
+        
         // load the global result list for this package
         loadGlobalResults(newPackage, packageElement);
 
         }
     }
 
+    protected void loadDefaultClassRef(PackageConfig packageContext, Element element) {
+       NodeList defaultClassRefList = element.getElementsByTagName("default-class-ref");
+       if ( defaultClassRefList.getLength() > 0 ) {
+           Element defaultClassRefElement = (Element) defaultClassRefList.item(0);
+           packageContext.setDefaultClassRef(defaultClassRefElement.getAttribute("class"));
+       }
+    }
     /**
      * Load all of the global results for this package from the XML element.
      */

src/java/xwork-2.0.dtd

    Use the following DOCTYPE
    
    <!DOCTYPE xwork PUBLIC 
-	"-//OpenSymphony Group//XWork 1.2//EN"
-	"http://www.opensymphony.com/xwork/xwork-1.2.dtd">
+	"-//OpenSymphony Group//XWork 2.0//EN"
+	"http://www.opensymphony.com/xwork/xwork-2.0.dtd">
 -->
 
 <!ELEMENT xwork (package|include|bean|constant)*>
 
-<!ELEMENT package (result-types?, interceptors?, default-interceptor-ref?, default-action-ref?, global-results?, global-exception-mappings?, action*)>
+<!ELEMENT package (result-types?, interceptors?, default-interceptor-ref?, default-action-ref?, default-class-ref?, global-results?, global-exception-mappings?, action*)>
 <!ATTLIST package
     name CDATA #REQUIRED
     extends CDATA #IMPLIED
     name CDATA #REQUIRED
 >
 
+<!ELEMENT default-class-ref (param*)>
+<!ATTLIST default-class-ref
+   class CDATA #REQUIRED
+>
+
 <!ELEMENT global-results (result+)>
 
 <!ELEMENT global-exception-mappings (exception-mapping+)>

src/java/xwork-default.xml

-<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
+<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 2.0//EN" "http://www.opensymphony.com/xwork/xwork-2.0.dtd">
 
 <xwork>
     <package name="xwork-default">
             <!-- END SNIPPET: xwork2-default-interceptor-stack -->
             
         </interceptors>
+        
+        <default-class-ref class="com.opensymphony.xwork2.ActionSupport" />
+        
     </package>
 </xwork>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.