public class Demo2 implements PropertyChangeListener{
PropertyChangeSupport support = new PropertyChangeSupport(this);
private String name;
public String getName() {
return name;
}
public Demo2()
{
this.name = "apple";
addListenProperty(this);
}
public void setName(String name) {
String oldName = this.name;
this.name = name;
support.firePropertyChange("name", oldName, this.name);
}
public void addListenProperty(PropertyChangeListener li)
{
support.addPropertyChangeListener(li);
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
System.out.println("--------------------------------");
System.out.println(evt.getOldValue());
System.out.println(evt.getNewValue());
System.out.println(evt.getPropertyName());
((Demo2)evt.getSource()).gotoSchool();
System.out.println("--------------------------------");
}
public void gotoSchool()
{
System.out.println("welcome to MIT !");
}
}
Test测试类
public class Demo {
public static void main(String[] args) {
Demo2 t = new Demo2();
t.setName("jobs");
System.out.println("~~~~~~~~~~~~~~~~");
t.setName("steven");
}
}
测试结果
--------------------------------
apple
jobs
name
welcome to MIT !
--------------------------------
~~~~~~~~~~~~~~~~
--------------------------------
jobs
steven
name
welcome to MIT !
-------------------------------- 学习二
接口Pipeline 流水线功能学习有点类似于过滤器构造。它有一个Value数组。使用 System.arraycopy() 来扩展流水线阀门个数。
invoke方法传递到下一个。阀门全部通过之后有一个basic方法。就是warpper包装器了。
这时候开始加载Servlet.class。执行service方法。阀门可以用来HeaderLoggerValve,ClientIPLoggerValve记录日志。
public interface Pipeline {
public Valve getBasic();
public void setBasic(Valve valve);
public void addValve(Valve valve);
public Valve[] getValves();
public void removeValve(Valve valve);
public Valve getFirst();
}