Added ability to update individual elements of an array field. The objects
have helper functions named set<field>At() for such a purpose. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1134 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
//
|
||||
// $Id: DOMTest.java,v 1.7 2002/02/09 07:50:04 mdb Exp $
|
||||
// $Id: DOMTest.java,v 1.8 2002/03/19 01:10:03 mdb Exp $
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.presents.Log;
|
||||
import com.threerings.presents.dobj.*;
|
||||
|
||||
@@ -13,7 +15,7 @@ import com.threerings.presents.dobj.*;
|
||||
* A simple test case for the dobjmgr.
|
||||
*/
|
||||
public class DOMTest extends TestCase
|
||||
implements Subscriber, AttributeChangeListener
|
||||
implements Subscriber, AttributeChangeListener, ElementUpdateListener
|
||||
{
|
||||
public DOMTest ()
|
||||
{
|
||||
@@ -26,6 +28,7 @@ public class DOMTest extends TestCase
|
||||
object.addListener(this);
|
||||
|
||||
TestObject to = (TestObject)object;
|
||||
_test = to;
|
||||
|
||||
// test transactions
|
||||
to.startTransaction();
|
||||
@@ -33,6 +36,14 @@ public class DOMTest extends TestCase
|
||||
to.setBar("hoopie");
|
||||
to.commitTransaction();
|
||||
|
||||
// set some elements
|
||||
to.setIntsAt(15, 3);
|
||||
to.setIntsAt(5, 2);
|
||||
to.setIntsAt(1, 0);
|
||||
to.setStringsAt("Hello", 0);
|
||||
to.setStringsAt("Goodbye", 1);
|
||||
to.setStringsAt(null, 1);
|
||||
|
||||
// now set some values straight up
|
||||
to.setFoo(25);
|
||||
to.setBar("howdy");
|
||||
@@ -56,6 +67,13 @@ public class DOMTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public void elementUpdated (ElementUpdatedEvent event)
|
||||
{
|
||||
// Log.info("Element updated " + event);
|
||||
// Log.info(StringUtil.toString(_test.ints));
|
||||
// Log.info(StringUtil.toString(_test.strings));
|
||||
}
|
||||
|
||||
public void runTest ()
|
||||
{
|
||||
// request that a new TestObject be created
|
||||
@@ -80,6 +98,7 @@ public class DOMTest extends TestCase
|
||||
}
|
||||
|
||||
protected int _fcount = 0;
|
||||
protected TestObject _test;
|
||||
|
||||
// the fields that will change in attribute changed events
|
||||
protected Object[] fields = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TestObject.dobj,v 1.7 2002/02/08 23:17:38 mdb Exp $
|
||||
// $Id: TestObject.dobj,v 1.8 2002/03/19 01:10:03 mdb Exp $
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
@@ -12,5 +12,7 @@ public class TestObject extends DObject
|
||||
{
|
||||
public int foo;
|
||||
public String bar;
|
||||
public int[] ints = new int[5];
|
||||
public String[] strings = new String[5];
|
||||
public OidList list = new OidList();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TestObject.java,v 1.2 2002/02/20 23:35:42 mdb Exp $
|
||||
// $Id: TestObject.java,v 1.3 2002/03/19 01:10:03 mdb Exp $
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
@@ -16,11 +16,19 @@ public class TestObject extends DObject
|
||||
/** The field name of the <code>bar</code> field. */
|
||||
public static final String BAR = "bar";
|
||||
|
||||
/** The field name of the <code>ints</code> field. */
|
||||
public static final String INTS = "ints";
|
||||
|
||||
/** The field name of the <code>strings</code> field. */
|
||||
public static final String STRINGS = "strings";
|
||||
|
||||
/** The field name of the <code>list</code> field. */
|
||||
public static final String LIST = "list";
|
||||
|
||||
public int foo;
|
||||
public String bar;
|
||||
public int[] ints = new int[5];
|
||||
public String[] strings = new String[5];
|
||||
public OidList list = new OidList();
|
||||
|
||||
/**
|
||||
@@ -51,6 +59,62 @@ public class TestObject extends DObject
|
||||
requestAttributeChange(BAR, bar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>ints</code> field be set to the specified
|
||||
* value. The local value will be updated immediately and an event
|
||||
* will be propagated through the system to notify all listeners that
|
||||
* the attribute did change. Proxied copies of this object (on
|
||||
* clients) will apply the value change when they received the
|
||||
* attribute changed notification.
|
||||
*/
|
||||
public void setInts (int[] ints)
|
||||
{
|
||||
this.ints = ints;
|
||||
requestAttributeChange(INTS, ints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>index</code>th element of
|
||||
* <code>ints</code> field be set to the specified value. The local
|
||||
* value will be updated immediately and an event will be propagated
|
||||
* through the system to notify all listeners that the attribute did
|
||||
* change. Proxied copies of this object (on clients) will apply the
|
||||
* value change when they received the attribute changed notification.
|
||||
*/
|
||||
public void setIntsAt (int value, int index)
|
||||
{
|
||||
this.ints[index] = value;
|
||||
requestElementUpdate(INTS, new Integer(value), index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>strings</code> field be set to the specified
|
||||
* value. The local value will be updated immediately and an event
|
||||
* will be propagated through the system to notify all listeners that
|
||||
* the attribute did change. Proxied copies of this object (on
|
||||
* clients) will apply the value change when they received the
|
||||
* attribute changed notification.
|
||||
*/
|
||||
public void setStrings (String[] strings)
|
||||
{
|
||||
this.strings = strings;
|
||||
requestAttributeChange(STRINGS, strings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>index</code>th element of
|
||||
* <code>strings</code> field be set to the specified value. The local
|
||||
* value will be updated immediately and an event will be propagated
|
||||
* through the system to notify all listeners that the attribute did
|
||||
* change. Proxied copies of this object (on clients) will apply the
|
||||
* value change when they received the attribute changed notification.
|
||||
*/
|
||||
public void setStringsAt (String value, int index)
|
||||
{
|
||||
this.strings[index] = value;
|
||||
requestElementUpdate(STRINGS, value, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the specified oid be added to the
|
||||
* <code>list</code> oid list. The list will not change until the
|
||||
|
||||
Reference in New Issue
Block a user