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());
  }
  private void setDefaultProperties(DataObject data, DataObject associatedObject) throws Exception {

    final ObjectType type = data.getObjectType();
    s_log.info("");
    s_log.info("Making new object for: " + type.getQualifiedName());
    KeyGenerator.setKeyValues(data);

    ObjectType associated = (associatedObject == null) ? null : associatedObject.getObjectType();

    for (Iterator it = type.getKeyProperties(); it.hasNext(); ) {
      Property prop = (Property) it.next();
      if (prop.isAttribute()) {
        continue;
      }

      DataType propType = prop.getType();
      if (propType.equals(associated)) {
        data.set(prop.getName(), associatedObject);
      } else {
        makeChild(prop, data);
      }
    }

    PropertyManipulator.NonKeyManipulator manip =
        new PropertyManipulator.NonKeyManipulator(type) {
          public void manipulate(Property p, DataObject dataInner) throws Exception {
            m_manipulator.setDefaultProperty(p, dataInner);
          }
        };

    PropertyManipulator.manipulateProperties(data, manip);
    s_log.info("END new object.");
    s_log.info("");
    s_log.info("");
  }
  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);
  }
Exemplo n.º 4
0
 /**
  * Indicates if two OIDs have the same base type and contain the same values. Note that if values
  * are null this isn't an ideal distinction; it's best to check "arePropertiesNull" before relying
  * on this equals method (see DomainObject's equals method for an example).
  */
 public boolean equals(Object obj) {
   if (obj instanceof OID) {
     OID oid = (OID) obj;
     // we rely on the toString ecause the HashMap.equals does not
     // give us what we need
     return m_type.getBasetype().equals(oid.m_type.getBasetype()) && m_values.equals(oid.m_values);
   }
   return false;
 }
Exemplo n.º 5
0
  public boolean isInitialized() {
    for (Iterator it = m_type.getKeyProperties(); it.hasNext(); ) {
      if (!m_values.containsKey(((Property) it.next()).getName())) {
        return false;
      }
    }

    return true;
  }
Exemplo n.º 6
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);
  }
Exemplo n.º 7
0
  /**
   * Creates an OID with a single attribute for the key. To create a multi-valued OID, use a single
   * arg OID constructor, and add individual properties with the set method. This constructor should
   * be used when the object type being instantiated has a single primary key. For instance, if the
   * object type is <code>com.arsdigita.kernel.ACSObject</code> then the value should be the <code>
   * object_id</code>. So, if developers wanted to create the OID for ID zero, they would call
   * <code>new OID(acsObjectType, new BigDecimal(0))</code>. A <code>BigDecimal</code> is passed in
   * because the "id" attribute for the ACSObject type is declared as <code>BigDecimal</code> in the
   * PDL file.
   *
   * @param type The ObjectType of the ID
   * @param value The value of the ID
   * @exception PersistenceException will be thrown if the given object type does not have exactly a
   *     single key (if <code>type.getObjectMap().getObjectKey().getCount()
   *            != 1</code>).
   * @pre type != null
   * @pre type.getObjectMap().getObjectKey().getCount() == 1
   */
  public OID(ObjectType type, Object value) {
    this(type);
    Iterator it = type.getKeyProperties();
    if (!it.hasNext()) {
      throw new PersistenceException("Empty object key: " + type);
    }

    Property prop = (Property) it.next();

    if (it.hasNext()) {
      throw new PersistenceException("This object type has a compound key.");
    }

    String attr = prop.getName();
    set(attr, value);
  }
Exemplo n.º 8
0
 public static final com.redhat.persistence.metadata.ObjectType type(Root root, ObjectType type) {
   return type(root, type.getQualifiedName());
 }
Exemplo n.º 9
0
 /**
  * Simple hashcode method to calculate hashcode based on the information used in the equals
  * method. Needed because we overrode equals; two equivalent objects must hash to the same value.
  */
 public int hashCode() {
   // here we rely on the values collection's hashcode method
   // to base its hashcode on the hashcodes of the contained values.
   return (m_type.getBasetype().hashCode() + m_values.hashCode());
 }
Exemplo n.º 10
0
 /** Serializes the OID. */
 public String toString() {
   String fullType = m_type.getQualifiedName();
   Object[] args = {fullType, getProperties().toString()};
   return m_format.format(args);
 }
Exemplo n.º 11
0
 void specialize(ObjectType subtype) {
   ObjectType.verifySubtype(m_type, subtype);
   m_type = subtype;
 }
 private static boolean isNonKeyAttribute(Property p, ObjectType type) {
   return p.isAttribute() && !type.isKeyProperty(p);
 }
  private void checkUpdates(DataObject data, final DataObject parent) throws Exception {

    final ObjectType type = data.getObjectType();

    try {
      PropertyManipulator.NonKeyManipulator manip =
          new PropertyManipulator.NonKeyManipulator(type) {

            public void manipulate(Property p, DataObject dataInner) throws Exception {
              m_manipulator.updateAllPropertyCombinations(p, dataInner);
            }
          };

      PropertyManipulator.manipulateProperties(data, manip);

      PropertyManipulator.PredicateManipulator childManip =
          new PropertyManipulator.ComponentManipulator() {
            public void manipulate(Property p, DataObject dataInner) throws Exception {

              if (p.isCollection()) {
                DataAssociation children = (DataAssociation) dataInner.get(p.getName());
                DataAssociationCursor cursor = children.cursor();
                while (cursor.next()) {
                  DataObject child = cursor.getDataObject();
                  s_log.debug("checkUpdates on child: " + child.getObjectType().getQualifiedName());
                  checkUpdates(child, dataInner);
                }
              } else {
                DataObject child = (DataObject) dataInner.get(p.getName());
                s_log.debug("checkUpdates on child: " + child.getObjectType().getQualifiedName());
                checkUpdates(child, dataInner);
              }
            }
          };

      PropertyManipulator.manipulateProperties(data, childManip);

      PropertyManipulator.AssociationManipulator assocManip =
          new PropertyManipulator.AssociationManipulator() {
            public void manipulate(Property p, DataObject dataInner) throws Exception {

              if (p.isCollection()) {
                DataAssociation associations = (DataAssociation) dataInner.get(p.getName());
                DataAssociationCursor cursor = associations.cursor();
                while (cursor.next()) {
                  DataObject assoc = cursor.getDataObject();
                  if (!assoc.equals(parent)) {
                    s_log.debug(
                        "checkUpdates on assoc: " + assoc.getObjectType().getQualifiedName());
                    checkUpdates(assoc, dataInner);
                  }
                }
              } else {
                DataObject assoc = (DataObject) dataInner.get(p.getName());
                if (null != assoc && !assoc.equals(parent)) {
                  s_log.debug("checkUpdates on assoc: " + assoc.getObjectType().getQualifiedName());
                  checkUpdates(assoc, dataInner);
                }
              }
            }
          };

      PropertyManipulator.manipulateProperties(data, assocManip);
    } catch (UndefinedEventException e) {
      s_log.info(
          "Update event undefined for type: "
              + type.getQualifiedName()
              + " Update tests cannot be performed.");
      s_log.info("UndefinedEventException: " + e.getMessage());
    }
  }