Resource resource = (Resource)notification.getNotifier(); ResourceChange change = getResourceChange(resource);
Resource resource = null; ResourceChange change = null; if (isRecording()) { resource = (Resource)notification.getNotifier(); change = getResourceChange(resource); }
  protected void handleResource(Notification notification)  {    Resource resource = (Resource)notification.getNotifier();    ResourceChange change = getResourceChange(resource);    int eventType = notification.getEventType();    switch (eventType)    {      case Notification.SET:      case Notification.UNSET:      {        if (change == null && isRecording())        {          EList oldValue = new BasicEList(resource.getContents());          int index = notification.getPosition();          if (index != Notification.NO_INDEX)          {            oldValue.set(index, notification.getOldValue());          }          change = createResourceChange(resource, oldValue);          getResourceChanges().add(change);          Notifier newValue = (Notifier)notification.getNewValue();          if (newValue != null)          {            addAdapter(newValue);          }        }        break;      }      case Notification.ADD:      {        if (change == null && isRecording())        {          EList oldValue = new BasicEList(resource.getContents());          oldValue.remove(notification.getPosition());          change = createResourceChange(resource, oldValue);          getResourceChanges().add(change);        }        Notifier newValue = (Notifier)notification.getNewValue();        addAdapter(newValue);        break;      }      case Notification.ADD_MANY:      {        if (change == null && isRecording())        {          EList oldValue = new BasicEList(resource.getContents());          int position = notification.getPosition();          for (int i = ((Collection)notification.getNewValue()).size(); --i >= 0;)          {            oldValue.remove(position);          }          change = createResourceChange(resource, oldValue);          getResourceChanges().add(change);        }        Collection newValues = (Collection)notification.getNewValue();        for (Iterator i = newValues.iterator(); i.hasNext();)        {          Notifier newValue = (Notifier)i.next();          addAdapter(newValue);        }        break;      }      case Notification.REMOVE:      {        if (change == null && isRecording())        {          EList oldValue = new BasicEList(resource.getContents());          // If there's no position, the list is being cleared.          //          int position = notification.getPosition();          if (position == Notification.NO_INDEX)          {            position = 0;          }          oldValue.add(position, notification.getOldValue());          change = createResourceChange(resource, oldValue);          getResourceChanges().add(change);        }        break;      }      case Notification.REMOVE_MANY:      {        if (change == null && isRecording())        {          List removedValues = (List)notification.getOldValue();          EList oldValue = new BasicEList(resource.getContents());          int[] positions = (int[])notification.getNewValue();          if (positions == null)          {            oldValue.addAll(removedValues);          }          else          {            for (int i = 0; i < positions.length; ++i)            {              oldValue.add(positions[i], removedValues.get(i));            }          }          change = createResourceChange(resource, oldValue);          getResourceChanges().add(change);        }        break;      }      case Notification.MOVE:      {        if (change == null && isRecording())        {          EList oldValue = new BasicEList(resource.getContents());          int position = notification.getPosition();          int oldPosition = ((Integer)notification.getOldValue()).intValue();          oldValue.move(oldPosition, position);          change = createResourceChange(resource, oldValue);          getResourceChanges().add(change);        }        break;      }    }  }