unsw.cse.mica.tools.proxy
Class Proxy

java.lang.Object
  extended by java.util.Observable
      extended by unsw.cse.mica.tools.proxy.Proxy

public class Proxy
extends java.util.Observable

A Proxy represents the client-side version of information that lives somewhere on the Swarm server. It is essentially a wrapper for a Mob. However, since Mobs are considered immutable on the server-side, editing a Mob basically involves deleting the old Mob and writing a new one. We need some way to have a single client-side object that tracks an edit as a shift from one Mob to another. A Proxy does just that, it holds onto a single Mob and allows the editing of its fields and the ability to apply the edits to the server-side. This apply action deletes the current Mob (by ID) from the server, writes the current information as a new Mob and updates the Mob ID it now refers to.

Author:
Mark Reid

Method Summary
 boolean applyChanges()
          Transmit the current state of this Proxy to the server.
 boolean equals(java.lang.Object proxyObj)
          Two proxies are considered to be equal if their names are not null and are equal.
 Mob getMob()
          Return a Mob representation of this Proxy.
 java.lang.String getMobName()
          Convenience method for getting the name of the Mob under this Proxy.
 int hashCode()
          The contract for a hash code for an object requires that if two objects are equal() their hash codes must be the same.
 void setMob(Mob mob)
          Update this Proxy's fields using the information in the given Mob
 void setMobName(java.lang.String mobName)
          Convenience method for setting the name of the underlying mob
 java.lang.String toString()
           
 void update()
          Get the contents of this proxy from the server.
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

setMob

public void setMob(Mob mob)
Update this Proxy's fields using the information in the given Mob

Parameters:
mob - The new information for this Proxy

getMob

public Mob getMob()
Return a Mob representation of this Proxy.

Returns:
The information in this Proxy in a format suitable for the Swarm server

getMobName

public java.lang.String getMobName()
Convenience method for getting the name of the Mob under this Proxy.

Returns:
The name of the Mob shadowed by this Proxy.

setMobName

public void setMobName(java.lang.String mobName)
Convenience method for setting the name of the underlying mob

Parameters:
mobName - The new name for the Mob shadowed by this Proxy

equals

public boolean equals(java.lang.Object proxyObj)
Two proxies are considered to be equal if their names are not null and are equal. This is because Proxies shadow Mobs, which are considered unique by name.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
The contract for a hash code for an object requires that if two objects are equal() their hash codes must be the same. Since equality of proxies is based only on the mob name they stand in for, the hash code must only be a function of this name.

Overrides:
hashCode in class java.lang.Object
Returns:
The hashCode of the string returned by getMobName() or 0 if this string is null.

applyChanges

public boolean applyChanges()
                     throws MicaException
Transmit the current state of this Proxy to the server.

Returns:
true iff the changes were successfully made on the server.
Throws:
MicaException

update

public void update()
            throws MicaException
Get the contents of this proxy from the server.

Throws:
MicaException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object