Class CmsEntity

  • All Implemented Interfaces:
    com.google.gwt.event.logical.shared.HasValueChangeHandlers<CmsEntity>, com.google.gwt.event.shared.HasHandlers, java.io.Serializable

    public class CmsEntity
    extends java.lang.Object
    implements com.google.gwt.event.logical.shared.HasValueChangeHandlers<CmsEntity>, java.io.Serializable
    Serializable entity implementation.

    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  CmsEntity.EntityChangeHandler
      Handles child entity changes.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected CmsEntity()
      Constructor.
        CmsEntity​(java.lang.String id, java.lang.String typeName)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAttributeValue​(java.lang.String attributeName, java.lang.String value)
      Adds the given attribute value.
      void addAttributeValue​(java.lang.String attributeName, CmsEntity value)
      Adds the given attribute value.
      protected <H extends com.google.gwt.event.shared.EventHandler>
      com.google.gwt.event.shared.HandlerRegistration
      addHandler​(H handler, com.google.gwt.event.shared.GwtEvent.Type<H> type)
      Adds this handler to the widget.
      com.google.gwt.event.shared.HandlerRegistration addValueChangeHandler​(com.google.gwt.event.logical.shared.ValueChangeHandler<CmsEntity> handler)  
      CmsEntity cloneEntity()
      Clones the given entity keeping all entity ids.
      CmsEntity createDeepCopy​(java.lang.String entityId)
      Creates a deep copy of this entity.
      void ensureChangeHandlers()
      Ensures that the change event is also fired on child entity change.
      boolean equals​(java.lang.Object obj)  
      void fireEvent​(com.google.gwt.event.shared.GwtEvent<?> event)  
      CmsEntityAttribute getAttribute​(java.lang.String attributeName)
      Returns an attribute.
      java.util.List<CmsEntityAttribute> getAttributes()
      Returns all entity attributes.
      CmsEntity getEntityById​(java.lang.String entityId)
      Returns this or a child entity with the given id.
      java.lang.String getId()
      Returns the entity id.
      java.lang.String getTypeName()
      Returns the entity type name.
      static java.lang.String getValueForPath​(CmsEntity entity, java.lang.String[] pathElements)
      Returns the value of a simple attribute for the given path or null, if the value does not exist.
      static java.util.List<java.lang.Object> getValuesForPath​(java.lang.Object baseObject, java.lang.String[] pathComponents)
      Gets the list of values reachable from the given base object with the given path.
      static java.util.List<java.lang.Object> getValuesForPathComponent​(java.lang.Object entityOrString, java.lang.String pathComponent)
      Gets the values reachable from a given object (an entity or a string) with a single XPath component.
      boolean hasAttribute​(java.lang.String attributeName)
      Returns if the entity has the given attribute.
      int hashCode()  
      void insertAttributeValue​(java.lang.String attributeName, java.lang.String value, int index)
      Inserts a new attribute value at the given index.
      void insertAttributeValue​(java.lang.String attributeName, CmsEntity value, int index)
      Inserts a new attribute value at the given index.
      void removeAttribute​(java.lang.String attributeName)
      Removes the given attribute.
      void removeAttributeSilent​(java.lang.String attributeName)
      Removes the attribute without triggering any change events.
      void removeAttributeValue​(java.lang.String attributeName, int index)
      Removes a specific attribute value.
      void setAttributeValue​(java.lang.String attributeName, java.lang.String value)
      Sets the given attribute value.
      void setAttributeValue​(java.lang.String attributeName, java.lang.String value, int index)
      Sets the given attribute value at the given index.
      void setAttributeValue​(java.lang.String attributeName, CmsEntity value)
      Sets the given attribute value.
      void setAttributeValue​(java.lang.String attributeName, CmsEntity value, int index)
      Sets the given attribute value at the given index.
      java.lang.String toJSON()
      Returns the JSON string representation of this entity.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • CmsEntity

        public CmsEntity​(java.lang.String id,
                         java.lang.String typeName)
        Constructor.

        Parameters:
        id - the entity id/URI
        typeName - the entity type name
      • CmsEntity

        protected CmsEntity()
        Constructor. For serialization only.

    • Method Detail

      • getValueForPath

        public static java.lang.String getValueForPath​(CmsEntity entity,
                                                       java.lang.String[] pathElements)
        Returns the value of a simple attribute for the given path or null, if the value does not exist.

        Parameters:
        entity - the entity to get the value from
        pathElements - the path elements
        Returns:
        the value
      • getValuesForPath

        public static java.util.List<java.lang.Object> getValuesForPath​(java.lang.Object baseObject,
                                                                        java.lang.String[] pathComponents)
        Gets the list of values reachable from the given base object with the given path.

        Parameters:
        baseObject - the base object (a CmsEntity or a string)
        pathComponents - the path components
        Returns:
        the list of values for the given path (either of type String or CmsEntity)
      • getValuesForPathComponent

        public static java.util.List<java.lang.Object> getValuesForPathComponent​(java.lang.Object entityOrString,
                                                                                 java.lang.String pathComponent)
        Gets the values reachable from a given object (an entity or a string) with a single XPath component.

        If entityOrString is a string, and pathComponent is "VALUE", a list containing only entityOrString is returned. Otherwise, entityOrString is assumed to be an entity, and the pathComponent is interpreted as a field of the entity (possibly with an index).

        Parameters:
        entityOrString - the entity or string from which to get the values for the given path component
        pathComponent - the path component
        Returns:
        the list of reachable values
      • addAttributeValue

        public void addAttributeValue​(java.lang.String attributeName,
                                      CmsEntity value)
        Adds the given attribute value.

        Parameters:
        attributeName - the attribute name
        value - the attribute value
      • addAttributeValue

        public void addAttributeValue​(java.lang.String attributeName,
                                      java.lang.String value)
        Adds the given attribute value.

        Parameters:
        attributeName - the attribute name
        value - the attribute value
      • addValueChangeHandler

        public com.google.gwt.event.shared.HandlerRegistration addValueChangeHandler​(com.google.gwt.event.logical.shared.ValueChangeHandler<CmsEntity> handler)
        Specified by:
        addValueChangeHandler in interface com.google.gwt.event.logical.shared.HasValueChangeHandlers<CmsEntity>
        See Also:
        HasValueChangeHandlers.addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler)
      • cloneEntity

        public CmsEntity cloneEntity()
        Clones the given entity keeping all entity ids.

        Returns:
        returns the cloned instance
      • createDeepCopy

        public CmsEntity createDeepCopy​(java.lang.String entityId)
        Creates a deep copy of this entity.

        Parameters:
        entityId - the id of the new entity, if null a generic id will be used
        Returns:
        the entity copy
      • ensureChangeHandlers

        public void ensureChangeHandlers()
        Ensures that the change event is also fired on child entity change.

      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
        See Also:
        Object.equals(java.lang.Object)
      • fireEvent

        public void fireEvent​(com.google.gwt.event.shared.GwtEvent<?> event)
        Specified by:
        fireEvent in interface com.google.gwt.event.shared.HasHandlers
        See Also:
        HasHandlers.fireEvent(com.google.gwt.event.shared.GwtEvent)
      • getAttribute

        public CmsEntityAttribute getAttribute​(java.lang.String attributeName)
        Returns an attribute.

        Parameters:
        attributeName - the attribute name
        Returns:
        the attribute value
      • getEntityById

        public CmsEntity getEntityById​(java.lang.String entityId)
        Returns this or a child entity with the given id.

        Will return null if no entity with the given id is present.

        Parameters:
        entityId - the entity id
        Returns:
        the entity
      • getId

        public java.lang.String getId()
        Returns the entity id.

        Returns:
        the id
      • getTypeName

        public java.lang.String getTypeName()
        Returns the entity type name.

        Returns:
        the entity type name
      • hasAttribute

        public boolean hasAttribute​(java.lang.String attributeName)
        Returns if the entity has the given attribute.

        Parameters:
        attributeName - the attribute name
        Returns:
        true if the entity has the given attribute
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        Object.hashCode()
      • insertAttributeValue

        public void insertAttributeValue​(java.lang.String attributeName,
                                         CmsEntity value,
                                         int index)
        Inserts a new attribute value at the given index.

        Parameters:
        attributeName - the attribute name
        value - the attribute value
        index - the value index
      • insertAttributeValue

        public void insertAttributeValue​(java.lang.String attributeName,
                                         java.lang.String value,
                                         int index)
        Inserts a new attribute value at the given index.

        Parameters:
        attributeName - the attribute name
        value - the attribute value
        index - the value index
      • removeAttribute

        public void removeAttribute​(java.lang.String attributeName)
        Removes the given attribute.

        Parameters:
        attributeName - the attribute name
      • removeAttributeSilent

        public void removeAttributeSilent​(java.lang.String attributeName)
        Removes the attribute without triggering any change events.

        Parameters:
        attributeName - the attribute name
      • removeAttributeValue

        public void removeAttributeValue​(java.lang.String attributeName,
                                         int index)
        Removes a specific attribute value.

        Parameters:
        attributeName - the attribute name
        index - the value index
      • setAttributeValue

        public void setAttributeValue​(java.lang.String attributeName,
                                      CmsEntity value)
        Sets the given attribute value. Will remove all previous attribute values.

        Parameters:
        attributeName - the attribute name
        value - the attribute value
      • setAttributeValue

        public void setAttributeValue​(java.lang.String attributeName,
                                      CmsEntity value,
                                      int index)
        Sets the given attribute value at the given index.

        Parameters:
        attributeName - the attribute name
        value - the attribute value
        index - the value index
      • setAttributeValue

        public void setAttributeValue​(java.lang.String attributeName,
                                      java.lang.String value)
        Sets the given attribute value. Will remove all previous attribute values.

        Parameters:
        attributeName - the attribute name
        value - the attribute value
      • setAttributeValue

        public void setAttributeValue​(java.lang.String attributeName,
                                      java.lang.String value,
                                      int index)
        Sets the given attribute value at the given index.

        Parameters:
        attributeName - the attribute name
        value - the attribute value
        index - the value index
      • toJSON

        public java.lang.String toJSON()
        Returns the JSON string representation of this entity.

        Returns:
        the JSON string representation of this entity
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()
      • addHandler

        protected final <H extends com.google.gwt.event.shared.EventHandler> com.google.gwt.event.shared.HandlerRegistration addHandler​(H handler,
                                                                                                                                        com.google.gwt.event.shared.GwtEvent.Type<H> type)
        Adds this handler to the widget.
        Type Parameters:
        H - the type of handler to add
        Parameters:
        type - the event type
        handler - the handler
        Returns:
        HandlerRegistration used to remove the handler