Java 版 (精华区)
发信人: thering (没完没了), 信区: Java
标 题: struts源码分析=====ForwardConfig
发信站: 哈工大紫丁香 (2003年05月17日18:26:35 星期六), 站内信件
www.javasoft.cn出品
package org.apache.struts.config
ForwardConfig
2003-5-17日
package org.apache.struts.config;
import java.io.Serializable;
这是一个配置类,主要功能就是纪录相关的信息,代码非常简单
public class ForwardConfig implements Serializable {
//配置标志,当这个标志为true,这个实例就会被冻结(freeze),所有的属性就变为只
读
protected boolean configured = false;
//下面四个属性可以从字面看出他们的意义
protected boolean contextRelative = false;
protected String name = null;
protected String path = null;
protected boolean redirect = false;
public ForwardConfig() {
super();
}
public ForwardConfig(String name, String path, boolean redirect) {
super();
setName(name);
setPath(path);
setRedirect(redirect);
}
public ForwardConfig(String name, String path, boolean redirect,boolean
contextRelative) {
super();
setName(name);
setPath(path);
setRedirect(redirect);
setContextRelative(contextRelative);
}
public boolean getContextRelative() {
return (this.contextRelative);
}
public void setContextRelative(boolean contextRelative) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.contextRelative = contextRelative;
}
public String getName() {
return (this.name);
}
public void setName(String name) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.name = name;
}
public String getPath() {
return (this.path);
}
public void setPath(String path) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.path = path;
}
public boolean getRedirect() {
return (this.redirect);
}
public void setRedirect(boolean redirect) {
if (configured) {
throw new IllegalStateException("Configuration is frozen");
}
this.redirect = redirect;
}
public void freeze() {
configured = true;
}
public String toString() {
StringBuffer sb = new StringBuffer("ForwardConfig[");
sb.append("name=");
sb.append(this.name);
sb.append(",path=");
sb.append(this.path);
sb.append(",redirect=");
sb.append(this.redirect);
sb.append(",contextRelative=");
sb.append(this.contextRelative);
sb.append("]");
return (sb.toString());
}
}
总结:看过上面的代码,也许你就会知道如何freeze一个对象了吧,确实非常简单,但是
以前自己就没实现:)
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.228.151]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.078毫秒