Beispiel #1
0
  /**
   * Adds a property to the OID. Is used as part of the key for the Object ID.
   *
   * @param propertyName Name of the property
   * @param value The property
   */
  public void set(String propertyName, Object value) {
    Property prop = m_type.getProperty(propertyName);

    // We do some type-checking here, to ensure that OIDs are being
    // created with legit types of values.
    if (prop == null) {
      throw new PersistenceException(
          "no such property: " + propertyName + " for type " + m_type.getName());
    }

    // null has no type
    // if prop isn't an attribute, not sure what to do with it.
    if (prop.isAttribute() && value != null) {
      // we can be sure this is a simpletype because
      // isAttribute was true.
      SimpleType expectedType = (SimpleType) prop.getType();
      if (!expectedType.getJavaClass().isAssignableFrom(value.getClass())) {
        throw new PersistenceException(
            "expected " + expectedType.getJavaClass() + "actual type " + value.getClass());
      }
    } else if (value != null) {
      if (value instanceof DataObject) {
        ObjectType ot = (ObjectType) prop.getType();
        DataObject dobj = (DataObject) value;
        ObjectType.verifySubtype(ot, dobj.getObjectType());
      } else {
        throw new PersistenceException(
            "expected DataObject for property " + propertyName + " but got " + value.getClass());
      }
    }

    if (hasProperty(propertyName)) {
      throw new PersistenceException(propertyName + " is already set to " + get(propertyName));
    }

    m_values.put(propertyName, value);
  }