More juicy goodness. Event dispatch seems to work now.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@20 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: AttributeChangedEvent.java,v 1.2 2001/06/01 19:56:13 mdb Exp $
|
||||
// $Id: AttributeChangedEvent.java,v 1.3 2001/06/01 20:35:39 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.dobj;
|
||||
|
||||
@@ -101,18 +101,17 @@ public class AttributeChangedEvent extends DEvent
|
||||
public boolean applyToObject (DObject target)
|
||||
throws ObjectAccessException
|
||||
{
|
||||
// look up the setter for this object
|
||||
Method setter = DEventUtil.getSetter(target.getClass(), _name);
|
||||
|
||||
try {
|
||||
setter.invoke(target, new Object[] { _value });
|
||||
} catch (Exception e) {
|
||||
throw new ObjectAccessException("Reflection error: " + e);
|
||||
}
|
||||
|
||||
// pass the new value on to the object
|
||||
target.setAttribute(_name, _value);
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString ()
|
||||
{
|
||||
return "[CHANGE:targetOid=" + _toid + ", name=" + _name +
|
||||
", value=" + _value + "]";
|
||||
}
|
||||
|
||||
protected String _name;
|
||||
protected Object _value;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: DEventUtil.java,v 1.1 2001/06/01 19:56:13 mdb Exp $
|
||||
// $Id: DEventUtil.java,v 1.2 2001/06/01 20:35:39 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.dobj;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class DEventUtil
|
||||
protected static String setterName (String name)
|
||||
{
|
||||
StringBuffer sname = new StringBuffer();
|
||||
sname.append("get");
|
||||
sname.append("set");
|
||||
sname.append(Character.toUpperCase(name.charAt(0)));
|
||||
sname.append(name.substring(1));
|
||||
return sname.toString();
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//
|
||||
// $Id: DObject.java,v 1.7 2001/06/01 19:56:13 mdb Exp $
|
||||
// $Id: DObject.java,v 1.8 2001/06/01 20:35:39 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.dobj;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -180,6 +181,26 @@ public class DObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the named attribute to the specified value. This is only used
|
||||
* by the internals of the event dispatch mechanism and should not be
|
||||
* called directly by users. Use the generated attribute setter
|
||||
* methods instead.
|
||||
*/
|
||||
public void setAttribute (String name, Object value)
|
||||
throws ObjectAccessException
|
||||
{
|
||||
try {
|
||||
Field field = getClass().getField(name);
|
||||
field.set(this, value);
|
||||
|
||||
} catch (Exception e) {
|
||||
String errmsg = "Attribute setting failure [name=" + name +
|
||||
", value=" + value + ", error=" + e + "].";
|
||||
throw new ObjectAccessException(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
protected int _oid;
|
||||
protected DObjectManager _mgr;
|
||||
protected ArrayList _subscribers = new ArrayList();
|
||||
|
||||
Reference in New Issue
Block a user