You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mu...@apache.org on 2008/06/05 15:29:26 UTC
svn commit: r663603 - in /struts/struts2/trunk/plugins:
codebehind/src/main/java/ codebehind/src/main/java/org/apache/struts2/config/
codebehind/src/main/resources/ rest/
rest/src/main/java/org/apache/struts2/rest/ rest/src/main/resources/
Author: musachy
Date: Thu Jun 5 06:29:25 2008
New Revision: 663603
URL: http://svn.apache.org/viewvc?rev=663603&view=rev
Log:
WW-2667 REST should not extend Codebehind
Removed:
struts/struts2/trunk/plugins/rest/src/main/java/org/apache/struts2/rest/ControllerClasspathPackageProvider.java
Modified:
struts/struts2/trunk/plugins/codebehind/src/main/java/ (props changed)
struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java
struts/struts2/trunk/plugins/codebehind/src/main/resources/struts-plugin.xml
struts/struts2/trunk/plugins/rest/pom.xml
struts/struts2/trunk/plugins/rest/src/main/resources/struts-plugin.xml
Propchange: struts/struts2/trunk/plugins/codebehind/src/main/java/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jun 5 06:29:25 2008
@@ -0,0 +1 @@
+META-INF
Modified: struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java?rev=663603&r1=663602&r2=663603&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java (original)
+++ struts/struts2/trunk/plugins/codebehind/src/main/java/org/apache/struts2/config/ClasspathPackageProvider.java Thu Jun 5 06:29:25 2008
@@ -84,7 +84,7 @@
* to use in place of "struts-default".
*/
protected static final String DEFAULT_PARENT_PACKAGE = "struts.configuration.classpath.defaultParentPackage";
-
+
/**
* A setting to disable action scanning.
*/
@@ -109,10 +109,25 @@
*/
private boolean forceLowerCase = true;
+ protected static final String CLASS_SUFFIX = "struts.codebehind.classSuffix";
/**
* Default suffix that can be used to indicate POJO "Action" classes.
*/
- private static final String ACTION = "Action";
+ protected String classSuffix = "Action";
+
+ protected static final String CHECK_IMPLEMENTS_ACTION = "struts.codebehind.checkImplementsAction";
+
+ /**
+ * When testing a class, check that it implements Action
+ */
+ protected boolean checkImplementsAction = true;
+
+ protected static final String CHECK_ANNOTATION = "struts.codebehind.checkAnnotation";
+
+ /**
+ * When testing a class, check that it has an @Action annotation
+ */
+ protected boolean checkAnnotation = true;
/**
* Helper class to scan class path for server pages.
@@ -126,7 +141,7 @@
* @see #needsReload
*/
private boolean initialized = false;
-
+
private boolean disableActionScanning = false;
private PackageLoader packageLoader;
@@ -165,12 +180,12 @@
return ClassLoaderUtil.getResource(path, getClass());
}
}
-
+
@Inject("actionPackages")
public void setActionPackages(String packages) {
this.actionPackages = packages;
}
-
+
public void setServletContext(ServletContext ctx) {
this.servletContext = ctx;
}
@@ -184,7 +199,27 @@
public void setDisableActionScanning(String disableActionScanning) {
this.disableActionScanning = "true".equals(disableActionScanning);
}
-
+
+ /**
+ * Check that the class implements Action
+ *
+ * @param checkImplementsAction True to check
+ */
+ @Inject(value=CHECK_IMPLEMENTS_ACTION, required=false)
+ public void setCheckImplementsAction(String checkImplementsAction) {
+ this.checkImplementsAction = "true".equals(checkImplementsAction);
+ }
+
+ /**
+ * Check that the class has an @Action annotation
+ *
+ * @param checkImplementsAction True to check
+ */
+ @Inject(value=CHECK_ANNOTATION, required=false)
+ public void setCheckAnnotation(String checkAnnotation) {
+ this.checkAnnotation = "true".equals(checkAnnotation);
+ }
+
/**
* Register a default parent package for the actions.
*
@@ -214,10 +249,20 @@
public void setDefaultPagePrefix(String defaultPagePrefix) {
this.defaultPagePrefix = defaultPagePrefix;
}
-
+
+ /**
+ * Default suffix that can be used to indicate POJO "Action" classes.
+ *
+ * @param defaultPagePrefix the defaultPagePrefix to set
+ */
+ @Inject(value=CLASS_SUFFIX, required=false)
+ public void setClassSuffix(String classSuffix) {
+ this.classSuffix = classSuffix;
+ }
+
/**
* Whether to use a lowercase letter as the initial letter of an action.
- *
+ *
* @param force If false, actions will retain the initial uppercase letter from the Action class.
* (<code>view.action</code> (true) versus <code>View.action</code> (false)).
*/
@@ -268,16 +313,16 @@
// Match Action implementations and classes ending with "Action"
public boolean matches(Class type) {
// TODO: should also find annotated classes
- return (Action.class.isAssignableFrom(type) ||
+ return ((checkImplementsAction && Action.class.isAssignableFrom(type)) ||
type.getSimpleName().endsWith(getClassSuffix()) ||
- type.getAnnotation(org.apache.struts2.config.Action.class) != null);
+ (checkAnnotation && type.getAnnotation(org.apache.struts2.config.Action.class) != null));
}
};
}
-
+
protected String getClassSuffix() {
- return ACTION;
+ return classSuffix;
}
/**
@@ -295,8 +340,8 @@
String actionPackage = cls.getPackage().getName();
String actionNamespace = null;
String actionName = null;
-
- org.apache.struts2.config.Action actionAnn =
+
+ org.apache.struts2.config.Action actionAnn =
(org.apache.struts2.config.Action) cls.getAnnotation(org.apache.struts2.config.Action.class);
if (actionAnn != null) {
actionName = actionAnn.name();
@@ -312,7 +357,7 @@
LOG.debug("ClasspathPackageProvider: Processing class "+name);
}
name = name.substring(pkg.length() + 1);
-
+
actionNamespace = "";
actionName = name;
int pos = name.lastIndexOf('.');
@@ -360,6 +405,7 @@
}
}
+
ResultTypeConfig defaultResultType = packageLoader.getDefaultResultType(pkgConfig);
ActionConfig actionConfig = new ActionConfig.Builder(actionPackage, actionName, cls.getName())
.addResultConfigs(new ResultMap<String,ResultConfig>(cls, actionName, defaultResultType))
@@ -388,10 +434,10 @@
parent = loadPackageConfig(actionNamespace, actionPackage, null);
actionNamespace = ns.value();
actionPackage = actionClass.getName();
-
- // See if the namespace has been overridden by the @Action annotation
+
+ // See if the namespace has been overridden by the @Action annotation
} else {
- org.apache.struts2.config.Action actionAnn =
+ org.apache.struts2.config.Action actionAnn =
(org.apache.struts2.config.Action) actionClass.getAnnotation(org.apache.struts2.config.Action.class);
if (actionAnn != null && !actionAnn.DEFAULT_NAMESPACE.equals(actionAnn.namespace())) {
// we pass null as the namespace in case the parent package hasn't been loaded yet
@@ -401,7 +447,7 @@
}
}
-
+
PackageConfig.Builder pkgConfig = packageLoader.getPackage(actionPackage);
if (pkgConfig == null) {
pkgConfig = new PackageConfig.Builder(actionPackage);
@@ -429,7 +475,7 @@
}
System.out.println("class:"+actionClass+" parent:"+parent+" current:"+(pkgConfig != null ? pkgConfig.getName() : ""));
-
+
return pkgConfig;
}
Modified: struts/struts2/trunk/plugins/codebehind/src/main/resources/struts-plugin.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/codebehind/src/main/resources/struts-plugin.xml?rev=663603&r1=663602&r2=663603&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/codebehind/src/main/resources/struts-plugin.xml (original)
+++ struts/struts2/trunk/plugins/codebehind/src/main/resources/struts-plugin.xml Thu Jun 5 06:29:25 2008
@@ -34,5 +34,5 @@
<constant name="struts.mapper.alwaysSelectFullNamespace" value="true" />
<package name="codebehind-default" extends="struts-default">
- </package>
+ </package>
</struts>
Modified: struts/struts2/trunk/plugins/rest/pom.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/rest/pom.xml?rev=663603&r1=663602&r2=663603&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/rest/pom.xml (original)
+++ struts/struts2/trunk/plugins/rest/pom.xml Thu Jun 5 06:29:25 2008
@@ -35,11 +35,6 @@
<dependencies>
<dependency>
- <groupId>org.apache.struts</groupId>
- <artifactId>struts2-codebehind-plugin</artifactId>
- <version>${pom.version}</version>
- </dependency>
- <dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.2.2</version>
Modified: struts/struts2/trunk/plugins/rest/src/main/resources/struts-plugin.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/rest/src/main/resources/struts-plugin.xml?rev=663603&r1=663602&r2=663603&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/rest/src/main/resources/struts-plugin.xml (original)
+++ struts/struts2/trunk/plugins/rest/src/main/resources/struts-plugin.xml Thu Jun 5 06:29:25 2008
@@ -24,13 +24,11 @@
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
-
+
<struts>
<bean type="com.opensymphony.xwork2.ActionProxyFactory" name="rest" class="org.apache.struts2.rest.RestActionProxyFactory" />
<bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="rest" class="org.apache.struts2.rest.RestActionMapper" />
-
- <bean type="com.opensymphony.xwork2.config.PackageProvider" name="rest" class="org.apache.struts2.rest.ControllerClasspathPackageProvider" />
<bean class="org.apache.struts2.rest.ContentTypeHandlerManager" />
@@ -43,13 +41,14 @@
<constant name="struts.mapper.class" value="rest" />
<constant name="struts.mapper.idParameterName" value="id" />
<constant name="struts.action.extension" value="xhtml,,xml,json" />
-
+
<!-- Disable the scanning by the codebehind plugin to prevent duplicates -->
- <constant name="struts.configuration.classpath.disableActionScanning" value="true" />
-
- <constant name="struts.configuration.rest.disableControllerScanning" value="false" />
+ <constant name="struts.codebehind.classSuffix" value="Controller"/>
+ <constant name="struts.codebehind.action.checkImplementsAction" value="false"/>
+ <constant name="struts.codebehind.action.checkAnnotation" value="false"/>
+
<constant name="struts.configuration.classpath.defaultParentPackage" value="rest-default" />
-
+
<package name="rest-default" extends="struts-default">
<result-types>
<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult">
@@ -108,7 +107,7 @@
<param name="excludeMethods">input,back,cancel,browse,index,show,edit,editNew</param>
</interceptor-ref>
</interceptor-stack>
-
+
</interceptors>
<default-interceptor-ref name="restDefaultStack"/>