com.ibm.ia.extension

Class EntityInitializer<T extends Entity>

  • java.lang.Object
    • com.ibm.ia.common.BaseComponent
      • com.ibm.ia.extension.EntityInitializer<T>
  • Type Parameters:
    T - The type of the entity. This must match the entityType property of the EntityInitializerDescriptor annotation.
    All Implemented Interfaces:
    com.ibm.ia.common.BaseComponentService, Extension, SolutionComponent, com.ibm.ia.extension.spi.EntityInitializerService


    public abstract class EntityInitializer<T extends Entity>
    extends com.ibm.ia.common.BaseComponent
    implements com.ibm.ia.extension.spi.EntityInitializerService

    The abstract class for entity initializer implementations.

    At most one entity initializer is called for a new entity instance. The implementation is responsible for initializing all the attributes that are necessary, including the attributes of parent types.

    • Field Summary

      • Fields inherited from class com.ibm.ia.common.BaseComponent

        dataProviderResolver, defTimeService, entityResolver, eventResolver, localQueryService, modelFactory, objEntityResolver, objEventResolver, requiredEngineVersion, solInfo
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      T createEntityFromEvent(Event event)
      Entry point of the first phase of the entity initializer in response to an event.
      void emit(Event event)
      Emit an event.
      java.lang.String getEntityId()
      Returns the ID of the entity to be initialized.
      java.lang.String getEntityType()
      Returns the type of the entity to be initialized.
      void initializeEntity(T entity)
      Entry point of the second phase of the entity initializer in response to an event, or in response to creating an entity using the REST API.
      • Methods inherited from class com.ibm.ia.common.BaseComponent

        createRelationship, createRelationship, deactivated, emit, getConceptFactory, getEventInstance, getEventResolver, getLocalQueryService, getModelFactory, getModelSerializer, getObjectEntityResolver, getObjectEventResolver, getRequiredEngineVersion, getSolutionDescriptor, getSolutionProperties, getSolutionProperty, getSolutionProperty, getTimeService, getTimeService, processOutboundEvents, resetResolvers, setEntityResolver, setEntityScopedQS, setModelFactory, setObjectEntityResolver, setRequiredEngineVersion, setSolutionDescriptor
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createEntityFromEvent

        public T createEntityFromEvent(Event event)
                                               throws ComponentException

        Entry point of the first phase of the entity initializer in response to an event.

        The default implementation creates an instance of the bound entity using the entity type returned by getEntityType(). The attribute that contains the entity ID is set automatically but any other attributes are uninitialized. You can override this method to initialize attributes of the entity using the value of the event.

        This method can veto the request to initialize the entity by returning a null value, in which case the entity is not created. Agents that are bound to the entity will receive a null value.

        If this method returns a non-null value, the runtime will invoke initializeEntity() to complete this phase of the entity initialization.

        Throws:
        ComponentException
        Parameters:
        event - The current event.
        Returns:
        T A partially initialized entity instance, or null to veto entity initialization.
      • initializeEntity

        public void initializeEntity(T entity)
                              throws ComponentException

        Entry point of the second phase of the entity initializer in response to an event, or in response to creating an entity using the REST API.

        The default implementation does not modify the entity. You can override this method to retrieve information from external systems to initialize the attributes of the entity, create or update related entities, or emit events.

        Throws:
        ComponentException
        Parameters:
        entity - The entity to be initialized.
      • getEntityType

        public final java.lang.String getEntityType()
                                             throws ComponentException
        Returns the type of the entity to be initialized. If the initialization is in response to an event, the returned value is the entity type stated in the initialization statement in the object model. Otherwise, the returned value is the type of the entity instance.
        Throws:
        ComponentException
        java.lang.UnsupportedOperationException - if called outside a valid execution context.
        Returns:
        Fully qualified entity type name.
      • getEntityId

        public final java.lang.String getEntityId()
                                           throws ComponentException
        Returns the ID of the entity to be initialized.
        Throws:
        ComponentException
        java.lang.UnsupportedOperationException - if called outside a valid execution context.
        Returns:
        The entity ID.
      • emit

        public final void emit(Event event)
                        throws ComponentException
        Emit an event. The default event time is assumed to be the current time.
        Throws:
        ComponentException
        java.lang.UnsupportedOperationException - if called outside a valid execution context.
        Parameters:
        event - The event to emit.

© Copyright IBM 2016