Esempio n. 1
0
  public synchronized Object getObjectValue(KeyValueCoding inspectable)
      throws AccessorInvocationException {
    if (inspectable == null) {
      if (logger.isLoggable(Level.WARNING)) {
        logger.warning(
            "Inspectable object is null for key "
                + name
                + ". We should definitely investigate this.");
      }
      return null;
    }

    try {
      KeyValueCoding target = getTargetObject(inspectable);
      if (target != null) {
        return target.objectForKey(getLastAccessor());
      } else {
        return null;
      }
    } catch (AccessorInvocationException e) {
      throw e;
    } catch (Exception e) {
      if (logger.isLoggable(Level.WARNING)) {
        logger.warning(
            "getObjectValue() failed for property "
                + name
                + " for object "
                + inspectable.getClass().getName()
                + " : exception "
                + e.getMessage());
      }
      return null;
    }
  }
Esempio n. 2
0
  public synchronized boolean hasObjectValue(KeyValueCoding inspectable)
      throws AccessorInvocationException {
    if (inspectable == null) {
      return false;
    }
    try {
      KeyValueCoding target = getTargetObject(inspectable);
      if (target != null) {
        target.objectForKey(getLastAccessor());
        return true;
      } else {
        return false;
      }

    } catch (InvalidObjectSpecificationException e) {
      return false;
    } catch (AccessorInvocationException e) {
      throw e;
    } catch (Exception e) {
      e.printStackTrace();
      if (logger.isLoggable(Level.WARNING)) {
        logger.warning(
            "getObjectValue() failed for property "
                + name
                + " for object "
                + inspectable.getClass().getName()
                + " : exception "
                + e.getMessage());
      }
      return false;
    }
  }
Esempio n. 3
0
  /**
   * This method can be called to store the newValue in the model.
   *
   * @param newValue
   */
  public synchronized void setObjectValue(KeyValueCoding inspectable, Object newValue)
      throws AccessorInvocationException {
    if (inspectable == null) {
      if (logger.isLoggable(Level.WARNING)) {
        logger.warning(
            "Inspectable object is null for key "
                + name
                + ". We should definitely investigate this.");
      }
      return;
    }

    Object oldValue = getObjectValue(inspectable);
    // logger.info("Old value="+oldValue+" New value="+newValue);
    if (oldValue == null) {
      if (newValue == null) {
        if (logger.isLoggable(Level.FINE)) {
          logger.fine("Same null value. Ignored.");
        }
        return;
      }
    } else if ((newValue != null) && (oldValue.equals(newValue))) {
      if (logger.isLoggable(Level.FINE)) {
        logger.fine("Same value. Ignored.");
      }
      return;
    }

    try {
      KeyValueCoding target = getTargetObject(inspectable);
      if (target != null) {
        target.setObjectForKey(newValue, getLastAccessor());
      } else if (logger.isLoggable(Level.WARNING)) {
        logger.warning(
            "Target object is null for key " + name + ". We should definitely investigate this.");
      }
      return;
    } catch (AccessorInvocationException e) {
      throw e;
    } catch (Exception e) {
      e.printStackTrace();
      if (logger.isLoggable(Level.WARNING)) {
        logger.warning(
            "setObjectValue() with "
                + newValue
                + " failed for property "
                + name
                + " for object "
                + inspectable.getClass().getName()
                + " : exception "
                + e.getMessage());
      }
    }
  }