KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > struts > actions > EdgeAction


1 package hero.struts.actions;
2
3 import java.io.IOException JavaDoc;
4 import javax.servlet.ServletException JavaDoc;
5 import javax.servlet.http.HttpServletRequest JavaDoc;
6 import javax.servlet.http.HttpSession JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
8 import org.apache.struts.action.ActionError;
9 import org.apache.struts.action.ActionErrors;
10 import org.apache.struts.action.ActionForm;
11 import org.apache.struts.action.ActionMapping;
12 import org.apache.struts.action.ActionForward;
13
14 import hero.interfaces.*;
15
16
17 /**
18  * <strong>EdgeAction</strong>
19  * Action that allows the user to add a new edge in the current project
20  *
21  *@author Miguel Valdes Faura
22  */

23 public class EdgeAction extends AbstStrutsActionBase
24 {
25
26   public boolean authenticate(String JavaDoc username, String JavaDoc password)
27   {
28     return(true);
29   }
30
31     /**
32      * @param mapping The ActionMapping used to select this instance
33      * @param actionForm The optional AbstActionFormBase bean for this request (if any)
34      * @param request The HTTP request we are processing
35      * @param response The HTTP response we are creating
36      * @exception IOException if an input/output error occurs
37      * @exception ServletException if a servlet exception occurs
38      */

39     public ActionForward perform(ActionMapping mapping, ActionForm form,
40         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws IOException JavaDoc, ServletException JavaDoc
41     {
42
43         ActionForward actionForward = mapping.findForward(PROJECT);
44         // Create the container for any errors that occur
45
ActionErrors errors = new ActionErrors();
46
47     String JavaDoc action = request.getParameter("edgeAction");
48     HttpSession JavaDoc session = request.getSession();
49     String JavaDoc project = (String JavaDoc)session.getAttribute("projectname");
50
51     try
52     {
53         hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome)hero.interfaces.ProjectSessionUtil.getLocalHome();
54         hero.interfaces.ProjectSessionLocal projectsession = projecth.create();
55         projectsession.initProject(project);
56         
57         if (!isCancelled(request))
58         {
59         if (action.equals("Edit"))
60         {
61             // Forward control to the specified 'success' URI specified in the structs-config.xml
62
actionForward = mapping.findForward(PROJECT);
63         }
64         if (action.equals("Add"))
65         {
66
67             String JavaDoc in = request.getParameter("nodeIn");
68             String JavaDoc out = request.getParameter("nodeOut");
69             projectsession.addEdge(in, out);
70             request.getSession(true).setAttribute("project", projectsession);
71             
72             // Forward control to the specified 'success' URI specified in the structs-config.xml
73
actionForward = mapping.findForward(PROJECT);
74         }
75         if (action.equals("Delete"))
76         {
77             try {
78             String JavaDoc edgeName = request.getParameter("name");
79             projectsession.deleteEdge(edgeName);
80             }catch(Exception JavaDoc e3){errors.add("edge_error", new ActionError("error.deleteedge.mismatch"));}
81             request.getSession(true).setAttribute("project", projectsession);
82             
83             // Forward control to the specified 'success' URI specified in the structs-config.xml
84
actionForward = mapping.findForward(PROJECT);
85         }
86         }
87         // }catch(DuplicatedEdgeException e){errors.add("edge_error", new ActionError("error.duplicateedge.mismatch"));
88
//}catch(NodeStartedException e1){errors.add("edge_error", new ActionError("error.startededge.mismatch"));
89
}catch(Exception JavaDoc e2){errors.add("edge_error", new ActionError("error.edge.mismatch"));}
90     
91     if (!errors.empty()) {
92         saveErrors(request, errors);
93         }
94     
95     // Forward control to the appropriate URI as determined by the action.
96
return (actionForward);
97     }
98     
99 }
100
Popular Tags