Class PersistentResourceToken

    • Field Detail

      • NoneToken

        public static final PersistentResourceToken NoneToken
        Represents none token to replace in more typing way the null keyword.
    • Constructor Detail

      • PersistentResourceToken

        protected PersistentResourceToken()
      • PersistentResourceToken

        protected PersistentResourceToken​(EntityReference resource,
                                          String value)
        Constructs a new persistent token for the specified resource and with the specified value.
        Parameters:
        resource - a reference to the resource for which this token is constructed.
        value - the token value.
    • Method Detail

      • createToken

        public static PersistentResourceToken createToken​(EntityReference resource)
                                                   throws TokenException
        Creates a token for the specified resource. If the specified resource has already a token, then renews it. Otherwise a new token is generated and persisted into the data source.
        Parameters:
        resource - the resource for which the token has to be generated.
        Returns:
        a token for the specified resource.
        Throws:
        TokenException
      • getOrCreateToken

        public static PersistentResourceToken getOrCreateToken​(EntityReference resource)
                                                        throws TokenException
        Gets a token for the specified resource and creates it if it doesn't exist. If the specified resource has already a token, then returns it. Otherwise a new token is generated and persisted into the data source.
        Parameters:
        resource - the resource for which the token has to be generated.
        Returns:
        a token for the specified resource.
        Throws:
        TokenException
      • getToken

        public static PersistentResourceToken getToken​(String token)
        Gets a the token from the specified value. If not token exist with the specified value, then NoneToken is returned.
        Parameters:
        token - the value of the token to get.
        Returns:
        the token that matches the specified value.
      • removeToken

        public static void removeToken​(EntityReference resource)
        Removes the token for the specified resource.
        Parameters:
        resource - the resource for which the token has to be removed.
      • exists

        public boolean exists()
        Indicates if the token is well registered
        Returns:
        a boolean indicating if this token exists in the data source.
      • notExists

        public boolean notExists()
        Indicates if the token isn't registered.
        Returns:
        a boolean indicating if this token doesn't exist in the data source.
      • setId

        public void setId​(Long id)
        Parameters:
        id - the id to set
      • getResource

        public <E,​R extends EntityReference<E>> R getResource​(Class<R> referenceClass)
        Gets a reference to the resource this token is for.
        Type Parameters:
        E - the concrete type of the entity.
        R - the concrete type of the reference to the entity.
        Parameters:
        referenceClass - the expected concrete class of the EntityReference. This class must be conform to the type of the resource.
        Returns:
        a reference to the resource that owns this token or null if there is neither no resource defined for this token nor no reference defined for the targeted type of resource.
      • setResource

        public void setResource​(EntityReference resource)
        Sets the resource to which this token belongs.
        Parameters:
        resource - an identifier of the resource for which this token is.
      • getValue

        public String getValue()
        Description copied from interface: Token
        Gets the String representation of this token.
        Specified by:
        getValue in interface Token
        Returns:
        the value
      • setValue

        public void setValue​(String value)
        Parameters:
        value - the value to set
      • getSaveCount

        public int getSaveCount()
        Returns:
        the saveCount
      • setSaveCount

        public void setSaveCount​(int saveCount)
        Parameters:
        saveCount - the saveCount to set
      • getSaveDate

        public Date getSaveDate()
        Returns:
        the saveDate
      • setSaveDate

        public void setSaveDate​(Date saveDate)
        Parameters:
        saveDate - the saveDate to set
      • isDefined

        public boolean isDefined()
        Description copied from interface: Token
        Is this token defined? A token is defined if it was generated and represents correctly a well-valued token. If it is empty (a none token), then it is considered as undefined. It is expected a token can be never null and a none-token concept is used instead. This method is to check the token is not a none-token, that is to say it is well initialized.
        Specified by:
        isDefined in interface Token
        Returns:
        true if this token is well-initialized, false otherwise.