actionmapping.java
来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 1,000 行 · 第 1/2 页
JAVA
1,000 行
package Jt.wizard.struts;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import Jt.JtContext;
import Jt.JtFactory;
import Jt.JtMessage;
import Jt.JtObject;
import Jt.wizard.WizardConfig;
import Jt.xml.JDOMAdapter;
import org.apache.struts.action.ActionForm;
import org.jdom.Element;
/**
* Open an Action mapping (Internal JtWizard Class).
*/
public class ActionMapping extends JtObject {
private static final long serialVersionUID = 1L;
public static final String READ = "READ";
public static final String DELETE = "DELETE";
public static final String UPDATE = "UPDATE";
public static final String CREATE = "CREATE";
private JtFactory factory = new JtFactory ();
private WizardConfig config;
String path;
String type;
String name;
String input;
String parameter;
String scope;
String forwardSuccess;
String forwardFailure;
String forwardCancel;
String delete;
String cancellable;
public String getCancellable() {
return cancellable;
}
public void setCancellable(String cancellable) {
this.cancellable = cancellable;
}
public String getDelete() {
return "delete";
}
public void setDelete(String delete) {
this.delete = this.delete; // null
}
public String getForwardCancel() {
return forwardCancel;
}
public void setForwardCancel(String forwardCancel) {
this.forwardCancel = forwardCancel;
}
public String getForwardFailure() {
return forwardFailure;
}
public void setForwardFailure(String forwardFailure) {
this.forwardFailure = forwardFailure;
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getParameter() {
return parameter;
}
public void setParameter(String parameter) {
this.parameter = parameter;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public String getName() {
return name;
}
public String getForwardSuccess() {
return forwardSuccess;
}
public void setForwardSuccess(String forwardSuccess) {
this.forwardSuccess = forwardSuccess;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
private void handleUIError (String error) {
Collection col;
if (error == null)
return;
col = (Collection) this.getObjErrors();
if (col == null) {
col = new LinkedList ();
setObjErrors (col);
}
col.add(error);
}
/*
public Object generateStrutsAction (ActionMappingForm form) {
JDOMAdapter adapter;
Element element;
JtMessage msg = new JtMessage (JDOMAdapter.ADD_ELEMENT);
//JtFactory factory = new JtFactory ();
if (form == null) {
return (null);
}
path = (String) form.getPath ();
if (path == null || path.equals ("")) {
handleUIError ("Please enter a path.");
//return (null);
}
type = (String) form.getType ();
if (type == null || type.equals ("")) {
handleUIError ("Please enter a type.");
//return (null);
}
name = (String) form.getName ();
if (name == null || name.equals ("")) {
handleUIError ("Please enter the name of the form bean.");
//return (null);
}
input = (String) form.getInput ();
if (input == null || input.equals ("")) {
handleUIError ("Please enter the name of the input form.");
//return (null);
}
scope = (String) form.getScope ();
if ( scope == null || scope.equals ("")) {
handleUIError ("Please enter the scope");
//return (null);
}
parameter = (String) form.getParameter ();
if (parameter == null || parameter.equals ("")) {
handleUIError ("Please enter the parameter");
//return (null);
}
forwardSuccess = (String) form.getForwardSuccess ();
if (forwardSuccess == null || forwardSuccess.equals ("")) {
handleUIError ("Please enter the forward (success).");
//return (null);
}
forwardFailure = (String) form.getForwardFailure ();
if (forwardFailure == null || forwardFailure.equals ("")) {
handleUIError ("Please enter the forward (failure).");
//return (null);
}
forwardCancel = (String) form.getForwardCancel ();
cancellable = (String) form.getCancellable ();
if (findActionMapping (path) != null) {
handleUIError ("Action Mapping already exists (same path).");
}
if (getObjErrors() != null) {
return (null);
}
adapter = (JDOMAdapter) factory.createObject (JDOMAdapter.JtCLASS_NAME);
element = new Element ("action");
element.setAttribute("path", path);
element.setAttribute("name", name);
element.setAttribute("type", type);
element.setAttribute("input", input);
element.setAttribute("parameter", parameter);
element.setAttribute("scope", scope);
if (cancellable != null && cancellable.equals("true"))
element.setAttribute("cancellable", cancellable);
msg.setMsgContent (element);
factory.sendMessage(adapter, msg);
element = new Element ("forward");
element.setAttribute("name", "success");
element.setAttribute("path", forwardSuccess);
msg.setMsgContent (element);
msg.setMsgData ("action");
factory.sendMessage(adapter, msg);
element = new Element ("forward");
element.setAttribute("name", "failure");
element.setAttribute("path", forwardFailure);
msg.setMsgContent (element);
msg.setMsgData ("action");
factory.sendMessage(adapter, msg);
if (forwardCancel!= null && !forwardCancel.equals ("")) {
element = new Element ("forward");
element.setAttribute("name", "cancel");
element.setAttribute("path", forwardCancel);
msg.setMsgContent (element);
msg.setMsgData ("action");
factory.sendMessage(adapter, msg);
}
return (adapter.getContent());
}
*/
private Object buildActionMapping (ActionMappingForm form) {
JDOMAdapter adapter;
Element element, actionElem;
JtMessage msg = new JtMessage (JDOMAdapter.ADD_ELEMENT);
//JtFactory factory = new JtFactory ();
String tmp;
if (form == null) {
return (null);
}
path = (String) form.getPath ();
if (path == null || path.equals ("")) {
handleUIError ("Please enter a path.");
}
type = (String) form.getType ();
if (type == null || type.equals ("")) {
handleUIError ("Please enter a type.");
}
name = (String) form.getName ();
/*
if (name == null || name.equals ("")) {
handleUIError ("Please enter the name of the form bean.");
}
*/
input = (String) form.getInput ();
/*
if (input == null || input.equals ("")) {
handleUIError ("Please enter the name of the input form.");
//return (null);
}
*/
scope = (String) form.getScope ();
if ( scope == null || scope.equals ("")) {
handleUIError ("Please enter the scope");
}
parameter = (String) form.getParameter ();
/*
if (parameter == null || parameter.equals ("")) {
handleUIError ("Please enter the parameter");
//return (null);
}
*/
forwardSuccess = (String) form.getForwardSuccess ();
/*
if (forwardSuccess == null || forwardSuccess.equals ("")) {
handleUIError ("Please enter the forward (success).");
}
*/
forwardFailure = (String) form.getForwardFailure ();
/*
if (forwardFailure == null || forwardFailure.equals ("")) {
handleUIError ("Please enter the forward (failure).");
}
*/
forwardCancel = (String) form.getForwardCancel ();
cancellable = (String) form.getCancellable ();
tmp = (String) form.getValidate();
if (getObjErrors() != null) {
return (null);
}
adapter = (JDOMAdapter) factory.createObject (JDOMAdapter.JtCLASS_NAME);
element = new Element ("action");
actionElem = element;
if (path != null && !path.equals(""))
element.setAttribute("path", path);
if (name != null && !name.equals(""))
element.setAttribute("name", name);
if (input != null && !input.equals(""))
element.setAttribute("input", input);
element.setAttribute("type", type);
if (parameter != null && !parameter.equals(""))
element.setAttribute("parameter", parameter);
element.setAttribute("scope", scope);
if (cancellable != null && cancellable.equals("true"))
element.setAttribute("cancellable", cancellable);
if (tmp != null && tmp.equals("false"))
element.setAttribute("validate", tmp);
msg.setMsgContent (element);
factory.sendMessage(adapter, msg);
if (forwardSuccess!= null && !forwardSuccess.equals ("")) {
element = new Element ("forward");
element.setAttribute("name", "success");
element.setAttribute("path", forwardSuccess);
msg.setMsgContent (element);
msg.setMsgData ("action");
factory.sendMessage(adapter, msg);
}
if (forwardFailure!= null && !forwardFailure.equals ("")) {
element = new Element ("forward");
element.setAttribute("name", "failure");
element.setAttribute("path", forwardFailure);
msg.setMsgContent (element);
msg.setMsgData ("action");
factory.sendMessage(adapter, msg);
}
if (forwardCancel!= null && !forwardCancel.equals ("")) {
element = new Element ("forward");
element.setAttribute("name", "cancel");
element.setAttribute("path", forwardCancel);
msg.setMsgContent (element);
msg.setMsgData ("action");
factory.sendMessage(adapter, msg);
}
return (actionElem);
}
private Object findActionMapping (String name) {
JDOMAdapter adapter = new JDOMAdapter ();
JtMessage msg = new JtMessage (JDOMAdapter.GET_CHILDREN);
JtFactory factory = new JtFactory ();
Element elem;
List children;
int i;
String tmp;
if (name == null)
return null;
config = (WizardConfig) factory.createObject(WizardConfig.JtCLASS_NAME);
if (config == null) {
handleError ("Unable to create configuration class");
return (null);
}
factory.sendMessage(config, new JtMessage (JtObject.JtINITIALIZE));
adapter.setPath(config.getConfigPath());
msg.setMsgContent("struts-config/action-mappings");
//adapter.setPath("c:/tmp/test.xml");
factory.sendMessage (adapter, new JtMessage (JDOMAdapter.READ_FILE));
children = (List) factory.sendMessage (adapter, msg);
if (children == null)
return (null);
for (i = 0; i < children.size(); i++) {
elem = (Element) children.get(i);
tmp = elem.getAttributeValue("path");
if (name.equals(tmp)) {
//elem.getParentElement();
//elem.detach ();
//factory.sendMessage (adapter, msg1);
return (elem);
}
}
return (null);
}
/*
private Object elementToDynaForm (Element elem, Object obj) {
JtMessage msg = new JtMessage (JtFactory.JtGET_ATTRIBUTES);
JtMessage msg1 = new JtMessage (JtFactory.JtCREATE_OBJECT);
JtFactory factory = new JtFactory ();
JtHashTable attributes;
JtIterator iterator;
String attName;
String attValue;
Object instance;
if (elem == null || obj == null)
return (null);
msg1.setMsgContent(obj.getClass().getName());
instance = factory.processMessage(msg1);
if (instance == null)
return (null);
msg.setMsgContent(instance);
attributes = (JtHashTable) factory.processMessage(msg);
if (attributes == null)
return (null);
iterator = (JtIterator) attributes.processMessage
(new JtMessage (JtHashTable.JtGET_KEYS));
if (iterator == null)
return (null);
for (;;) {
attName = (String) iterator.processMessage(new JtMessage (JtIterator.JtNEXT));
if (attName == null)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?