LinkPropertiespublic class LinkProperties extends Object implements PropertyChangeListener
Fields Summary |
---|
protected Object | target | protected String | sourceFieldName | protected Method | writer | protected Object[] | args |
Constructors Summary |
---|
public LinkProperties(Object target, String commonName)Creates new LinkFields
this.target = target;
sourceFieldName = commonName;
writer = PropertyUtils.getWriter(target,commonName);
// reader = PropertyUtils.getWriter(target,commonName);
| public LinkProperties(Object target, String srcName, String destName)Creates new LinkFields
this.target = target;
sourceFieldName = srcName;
writer = PropertyUtils.getWriter(target,destName);
// reader = PropertyUtils.getWriter(target,destName);
|
Methods Summary |
---|
public static void | main(java.lang.String[] args)
Reporter.setSeverityLevel(0); //NOI18N
TestObject a = new TestObject("foo");//NOI18N
TestObject b = new TestObject("bar");//NOI18N
java.beans.PropertyChangeSupport propWrap = new java.beans.PropertyChangeSupport(a);
System.out.println(a); //NOI18N
System.out.println(b); //NOI18N
try {
propWrap.addPropertyChangeListener(new LinkProperties(b,"fOne"));//NOI18N
propWrap.addPropertyChangeListener(new LinkProperties(b,"fOne", "fTwo"));//NOI18N
a.setFOne("baz");//NOI18N
a.setFTwo("Blah");//NOI18N
propWrap.firePropertyChange("fOne","foo","baz");//NOI18N
propWrap.firePropertyChange("fTwo", "foo", "Blah");//NOI18N
System.out.println(a); //NOI18N
System.out.println(b); //NOI18N
}
catch(Throwable t) {
t.printStackTrace();
}
| public void | propertyChange(java.beans.PropertyChangeEvent pce)
Reporter.info(pce); //NOI18N
String changedProperty = pce.getPropertyName();
Reporter.info(changedProperty); //NOI18N
Reporter.info(pce.getOldValue()); //NOI18N
Reporter.info(pce.getNewValue()); //NOI18N
Reporter.info(sourceFieldName); //NOI18N
try {
// Object targetValue = reader.invoke(target, null);
if (changedProperty.equals(sourceFieldName)) {
Reporter.info("case one");//NOI18N
Reporter.verbose(pce); //NOI18N
args[0] = pce.getNewValue();
writer.invoke(target, args);
}
// this is a hack for forte which has really strange property names...
// for example:
// the /WebApp/ResourceRef.51/Description is the description
// of a WebStandardData.ResourceRefData.
/*else if (changedProperty.endsWith(sourceFieldName.substring(1))) {
Reporter.info("case two");//NOI18N
args[0] = pce.getNewValue();
writer.invoke(target, args);
}*/
}
catch (Throwable t) {
try {
args[0] = pce.getNewValue().toString();
writer.invoke(target, args);
}
catch (Throwable tt) {
Reporter.critical(new StackTrace(t)); //NOI18N
}
}
|
|