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("");
  }
Пример #2
0
  public boolean isInitialized() {
    for (Iterator it = m_type.getKeyProperties(); it.hasNext(); ) {
      if (!m_values.containsKey(((Property) it.next()).getName())) {
        return false;
      }
    }

    return true;
  }
Пример #3
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);
  }