You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@locus.apache.org on 2000/06/30 03:19:51 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/action ActionForwards.java ActionMapping.java ActionMappingBase.java ActionMappings.java ActionServlet.java
craigmcc 00/06/29 18:19:49
Modified: src/share/org/apache/struts/action ActionForwards.java
ActionMapping.java ActionMappingBase.java
ActionMappings.java ActionServlet.java
Log:
Link the ActionForwards lookups of a mapping to the corresponding global
ActionForwards collection. Now, an Action can simply call
mapping.findForward("abc") and not care whether a particular forwarding
was registered locally or globally.
At configuration time (in action.xml), this also lets you set up defaults
and then selectively override them on a per-mapping basis if you want.
Revision Changes Path
1.2 +23 -4 jakarta-struts/src/share/org/apache/struts/action/ActionForwards.java
Index: ActionForwards.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionForwards.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ActionForwards.java 2000/06/30 00:46:35 1.1
+++ ActionForwards.java 2000/06/30 01:19:32 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionForwards.java,v 1.1 2000/06/30 00:46:35 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/06/30 00:46:35 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionForwards.java,v 1.2 2000/06/30 01:19:32 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/06/30 01:19:32 $
*
* ====================================================================
*
@@ -63,7 +63,9 @@
package org.apache.struts.action;
+import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Vector;
/**
@@ -71,7 +73,7 @@
* administered and searched, while hiding the internal implementation.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/06/30 00:46:35 $
+ * @version $Revision: 1.2 $ $Date: 2000/06/30 01:19:32 $
*/
public class ActionForwards {
@@ -110,6 +112,23 @@
public ActionForward findForward(String name) {
return ((ActionForward) forwards.get(name));
+
+ }
+
+
+ /**
+ * Return the set of logical names for forwards defined in this collection.
+ * If there are no such forwards, a zero-length array is returned.
+ */
+ public String[] findForwards() {
+
+ Vector names = new Vector();
+ Enumeration keys = forwards.keys();
+ while (keys.hasMoreElements())
+ names.addElement(keys.nextElement());
+ String results[] = new String[names.size()];
+ names.copyInto(results);
+ return (results);
}
1.5 +30 -5 jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java
Index: ActionMapping.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ActionMapping.java 2000/06/20 16:34:05 1.4
+++ ActionMapping.java 2000/06/30 01:19:32 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java,v 1.4 2000/06/20 16:34:05 craigmcc Exp $
- * $Revision: 1.4 $
- * $Date: 2000/06/20 16:34:05 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java,v 1.5 2000/06/30 01:19:32 craigmcc Exp $
+ * $Revision: 1.5 $
+ * $Date: 2000/06/30 01:19:32 $
*
* ====================================================================
*
@@ -97,7 +97,7 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.4 $ $Date: 2000/06/20 16:34:05 $
+ * @version $Revision: 1.5 $ $Date: 2000/06/30 01:19:32 $
*/
public interface ActionMapping {
@@ -177,6 +177,20 @@
/**
+ * Return the global forwards collection associated with this mapping.
+ */
+ public ActionForwards getForwards();
+
+
+ /**
+ * Set the global forwards collection associated with this mapping.
+ *
+ * @param forwards The associated forwards collection
+ */
+ public void setForwards(ActionForwards forwards);
+
+
+ /**
* Return the input form URI for this mapping.
*/
public String getInputForm();
@@ -231,11 +245,22 @@
/**
* Return the <code>ActionForward</code> with the specified name,
- * if any; otherwise return <code>null</code>.
+ * if any; otherwise return <code>null</code>. If there is no locally
+ * defined forwarding for the specified name, but a global forwards
+ * collection has been associated with this mapping, the global
+ * collection will also be searched before returning.
*
* @param name Name of the forward entry to be returned
*/
public ActionForward findForward(String name);
+
+
+ /**
+ * Return the logical names of all locally defined forwards for this
+ * mapping. If there are no such forwards, a zero-length array
+ * is returned.
+ */
+ public String[] findForwards();
/**
1.6 +52 -6 jakarta-struts/src/share/org/apache/struts/action/ActionMappingBase.java
Index: ActionMappingBase.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMappingBase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ActionMappingBase.java 2000/06/30 00:46:35 1.5
+++ ActionMappingBase.java 2000/06/30 01:19:32 1.6
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMappingBase.java,v 1.5 2000/06/30 00:46:35 craigmcc Exp $
- * $Revision: 1.5 $
- * $Date: 2000/06/30 00:46:35 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMappingBase.java,v 1.6 2000/06/30 01:19:32 craigmcc Exp $
+ * $Revision: 1.6 $
+ * $Date: 2000/06/30 01:19:32 $
*
* ====================================================================
*
@@ -72,7 +72,7 @@
* subclassing this class and adding new "getter" and "setter" methods.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.5 $ $Date: 2000/06/30 00:46:35 $
+ * @version $Revision: 1.6 $ $Date: 2000/06/30 01:19:32 $
*/
public class ActionMappingBase implements ActionMapping {
@@ -136,6 +136,12 @@
/**
+ * The global ActionForwards collection associated with this mapping.
+ */
+ protected ActionForwards globals = null;
+
+
+ /**
* The input form URI for this mapping.
*/
protected String inputForm = null;
@@ -262,6 +268,28 @@
/**
+ * Return the global forwards collection associated with this mapping.
+ */
+ public ActionForwards getForwards() {
+
+ return (this.globals);
+
+ }
+
+
+ /**
+ * Set the global forwards collection associated with this mapping.
+ *
+ * @param forwards The associated forwards collection
+ */
+ public void setForwards(ActionForwards forwards) {
+
+ this.globals = forwards;
+
+ }
+
+
+ /**
* Return the input form URI for this mapping.
*/
public String getInputForm() {
@@ -363,13 +391,31 @@
/**
* Return the <code>ActionForward</code> with the specified name,
- * if any; otherwise return <code>null</code>.
+ * if any; otherwise return <code>null</code>. If there is no locally
+ * defined forwarding for the specified name, but a global forwards
+ * collection has been associated with this mapping, the global
+ * collection will also be searched before returning.
*
* @param name Name of the forward entry to be returned
*/
public ActionForward findForward(String name) {
+
+ ActionForward forward = forwards.findForward(name);
+ if ((forward == null) && (globals != null))
+ forward = globals.findForward(name);
+ return (forward);
+
+ }
+
+
+ /**
+ * Return the logical names of all locally defined forwards for this
+ * mapping. If there are no such forwards, a zero-length array
+ * is returned.
+ */
+ public String[] findForwards() {
- return (forwards.findForward(name));
+ return (forwards.findForwards());
}
1.2 +23 -4 jakarta-struts/src/share/org/apache/struts/action/ActionMappings.java
Index: ActionMappings.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMappings.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ActionMappings.java 2000/06/30 00:46:36 1.1
+++ ActionMappings.java 2000/06/30 01:19:32 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMappings.java,v 1.1 2000/06/30 00:46:36 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/06/30 00:46:36 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMappings.java,v 1.2 2000/06/30 01:19:32 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/06/30 01:19:32 $
*
* ====================================================================
*
@@ -63,7 +63,9 @@
package org.apache.struts.action;
+import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Vector;
/**
@@ -71,7 +73,7 @@
* administered and searched, while hiding the internal implementation.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/06/30 00:46:36 $
+ * @version $Revision: 1.2 $ $Date: 2000/06/30 01:19:32 $
*/
public class ActionMappings {
@@ -110,6 +112,23 @@
public ActionMapping findMapping(String path) {
return ((ActionMapping) mappings.get(path));
+
+ }
+
+
+ /**
+ * Return the set of paths for mappings defined in this collection.
+ * If there are no such mappings, a zero-length array is returned.
+ */
+ public String[] findMappings() {
+
+ Vector paths = new Vector();
+ Enumeration keys = mappings.keys();
+ while (keys.hasMoreElements())
+ paths.addElement(keys.nextElement());
+ String results[] = new String[paths.size()];
+ paths.copyInto(results);
+ return (results);
}
1.15 +11 -4 jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
Index: ActionServlet.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ActionServlet.java 2000/06/30 00:46:36 1.14
+++ ActionServlet.java 2000/06/30 01:19:32 1.15
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.14 2000/06/30 00:46:36 craigmcc Exp $
- * $Revision: 1.14 $
- * $Date: 2000/06/30 00:46:36 $
+ * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.15 2000/06/30 01:19:32 craigmcc Exp $
+ * $Revision: 1.15 $
+ * $Date: 2000/06/30 01:19:32 $
*
* ====================================================================
*
@@ -164,7 +164,7 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.14 $ $Date: 2000/06/30 00:46:36 $
+ * @version $Revision: 1.15 $ $Date: 2000/06/30 01:19:32 $
*/
public class ActionServlet
@@ -594,6 +594,13 @@
} catch (SAXException e) {
throw new ServletException
(internal.getMessage("configParse", config), e);
+ }
+
+ // Connect all of our defined mappings to the global forwards
+ String paths[] = mappings.findMappings();
+ for (int i = 0; i < paths.length; i++) {
+ ActionMapping mapping = mappings.findMapping(paths[i]);
+ mapping.setForwards(forwards);
}
}