Esempio n. 1
0
  private void removeEntityInternal(Entity entity) {
    entities.removeValue(entity, true);

    if (!entity.getFamilyBits().isEmpty()) {
      for (Entry<Family, Array<Entity>> entry : families.entries()) {
        Family family = entry.key;
        Array<Entity> entities = entry.value;

        if (family.matches(entity)) {
          entities.removeValue(entity, true);
          entity.getFamilyBits().clear(family.getIndex());
          notifyFamilyListenersRemove(family, entity);
        }
      }
    }

    entity.componentAdded.remove(componentAdded);
    entity.componentRemoved.remove(componentRemoved);

    Object[] items = listeners.begin();
    for (int i = 0, n = listeners.size; i < n; i++) {
      EntityListener listener = (EntityListener) items[i];
      listener.entityRemoved(entity);
    }
    listeners.end();
  }
Esempio n. 2
0
  /**
   * @since 3.0
   * @deprecated since 4.0 unused, as listeners are no longer mapped in a DataMap.
   */
  @Deprecated
  public EntityListener getEntityListener(String className) {
    for (EntityListener next : entityListeners) {
      if (className.equals(next.getClassName())) {
        return next;
      }
    }

    return null;
  }
Esempio n. 3
0
  /**
   * Adds a new EntityListener.
   *
   * @since 3.0
   * @throws IllegalArgumentException if a listener for the same class name is already registered.
   * @deprecated since 4.0 unused, as listeners are no longer mapped in a DataMap.
   */
  @Deprecated
  public void addEntityListener(EntityListener listener) {
    for (EntityListener next : entityListeners) {
      if (listener.getClassName().equals(next.getClassName())) {
        throw new IllegalArgumentException("Duplicate listener for " + next.getClassName());
      }
    }

    entityListeners.add(listener);
  }
  /**
   * Called before an entity is updated to the database.
   *
   * @param entity the entity to update
   */
  public void preUpdate(Object entity) {
    if (!(entity instanceof Datatype)) {
      logger.warning("Entity to update is not of type Datatype.");
      return;
    }

    for (EntityListener listener : delegates) {
      listener.postPersist((Datatype) entity);
    }
  }
  /**
   * Called after an entity is load from the database.
   *
   * @param entity the loaded entity
   */
  public void postLoad(Object entity) {
    if (!(entity instanceof Datatype)) {
      logger.warning("Loaded entity is not of type Datatype.");
      return;
    }

    for (EntityListener listener : delegates) {
      listener.postLoad((Datatype) entity);
    }
  }
Esempio n. 6
0
 /**
  * Removes a listener matching class name.
  *
  * @since 3.0
  * @deprecated since 4.0 unused, as listeners are no longer mapped in a DataMap.
  */
 @Deprecated
 public void removeEntityListener(String className) {
   Iterator<EntityListener> it = entityListeners.iterator();
   while (it.hasNext()) {
     EntityListener next = it.next();
     if (className.equals(next.getClassName())) {
       it.remove();
       break;
     }
   }
 }
Esempio n. 7
0
  private void notifyFamilyListenersRemove(Family family, Entity entity) {
    SnapshotArray<EntityListener> listeners = familyListeners.get(family);

    if (listeners != null) {
      Object[] items = listeners.begin();
      for (int i = 0, n = listeners.size; i < n; i++) {
        EntityListener listener = (EntityListener) items[i];
        listener.entityRemoved(entity);
      }
      listeners.end();
    }
  }
Esempio n. 8
0
  /** Adds an entity to this Engine. */
  public void addEntity(Entity entity) {
    entities.add(entity);

    updateFamilyMembership(entity);

    entity.componentAdded.add(componentAdded);
    entity.componentRemoved.add(componentRemoved);
    entity.componentOperationHandler = componentOperationHandler;

    Object[] items = listeners.begin();
    for (int i = 0, n = listeners.size; i < n; i++) {
      EntityListener listener = (EntityListener) items[i];
      listener.entityAdded(entity);
    }
    listeners.end();
  }
Esempio n. 9
0
  /**
   * Prints itself as XML to the provided XMLEncoder.
   *
   * @since 1.1
   */
  @Override
  public void encodeAsXML(XMLEncoder encoder) {
    encoder.print("<obj-entity name=\"");
    encoder.print(getName());

    // additionally validate that superentity exists
    if (getSuperEntityName() != null && getSuperEntity() != null) {
      encoder.print("\" superEntityName=\"");
      encoder.print(getSuperEntityName());
    }

    if (isAbstract()) {
      encoder.print("\" abstract=\"true");
    }

    if (isServerOnly()) {
      encoder.print("\" serverOnly=\"true");
    }

    if (getClassName() != null) {
      encoder.print("\" className=\"");
      encoder.print(getClassName());
    }

    if (getClientClassName() != null) {
      encoder.print("\" clientClassName=\"");
      encoder.print(getClientClassName());
    }

    if (isReadOnly()) {
      encoder.print("\" readOnly=\"true");
    }

    if (getDeclaredLockType() == LOCK_TYPE_OPTIMISTIC) {
      encoder.print("\" lock-type=\"optimistic");
    }

    if (getDbEntityName() != null && getDbEntity() != null) {

      // not writing DbEntity name if sub entity has same DbEntity
      // as super entity, see CAY-1477
      if (!(getSuperEntity() != null && getSuperEntity().getDbEntity() == getDbEntity())) {
        encoder.print("\" dbEntityName=\"");
        encoder.print(Util.encodeXmlAttribute(getDbEntityName()));
      }
    }

    if (getSuperEntityName() == null && getSuperClassName() != null) {
      encoder.print("\" superClassName=\"");
      encoder.print(getSuperClassName());
    }

    if (getSuperEntityName() == null && getClientSuperClassName() != null) {
      encoder.print("\" clientSuperClassName=\"");
      encoder.print(getClientSuperClassName());
    }

    // deprecated
    if (isExcludingSuperclassListeners()) {
      encoder.print("\" exclude-superclass-listeners=\"true");
    }

    // deprecated
    if (isExcludingDefaultListeners()) {
      encoder.print("\" exclude-default-listeners=\"true");
    }

    encoder.println("\">");
    encoder.indent(1);

    if (qualifier != null) {
      encoder.print("<qualifier>");
      qualifier.encodeAsXML(encoder);
      encoder.println("</qualifier>");
    }

    // store attributes
    encoder.print(getDeclaredAttributes());

    for (Map.Entry<String, String> override : attributeOverrides.entrySet()) {
      encoder.print("<attribute-override name=\"" + override.getKey() + '\"');
      encoder.print(" db-attribute-path=\"");
      encoder.print(Util.encodeXmlAttribute(override.getValue()));
      encoder.print('\"');
      encoder.println("/>");
    }

    // deprecated
    // write entity listeners
    for (EntityListener entityListener : entityListeners) {
      entityListener.encodeAsXML(encoder);
    }

    // write entity-level callbacks
    getCallbackMap().encodeCallbacksAsXML(encoder);

    encoder.indent(-1);
    encoder.println("</obj-entity>");
  }