private void reportPropertyTypes(DataObject data) throws Exception {
    ObjectType type = data.getObjectType();
    Iterator keys = type.getProperties();
    s_log.info("Properties for type: " + type.getName());
    while (keys.hasNext()) {
      Property p = (Property) keys.next();
      if (p.isAttribute()) {
        String msg = "Property " + p.getName() + " is attribute. Class is: " + p.getJavaClass();
        if (type.isKeyProperty(p)) {
          msg += " is key property.";
        }
        msg += " value is: " + data.get(p.getName());
        s_log.info(msg);

      } else {
        s_log.info(
            "Property "
                + p.getName()
                + "  is component: "
                + p.isComponent()
                + " is collection: "
                + p.isCollection()
                + " is role: "
                + p.isRole());
        s_log.info("ObjectType is is: " + p.getType().getName());
      }
    }

    s_log.info("END Properties for type: " + type.getName());
  }
  public void testGetObjectType() {

    DataCollection allItems = getDefaultCollection();
    int count = 0;
    while (allItems.next()) {
      ObjectType type = allItems.getObjectType();
      s_log.info("Type: " + type.getQualifiedName());
      assertEquals("Somehow failed to retrieve a Node?", "Node", type.getName());
      count++;
    }

    assertTrue("No data objects?", count > 0);
  }
Esempio n. 3
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);
  }