Class Code

java.lang.Object
overit.geocall.util.Code

public class Code extends Object
Definition of a generic Code, useful most of all for error codes. The static part of this class has a in-memory sotage capabilitiy of Code objects. It is possible to register Codes with the register(java.lang.String, overit.geocall.util.Code) or with the file codes.xml in the root of the application layer, with the following format:
<code id = "100" code = "undefined" description = "undefined error, can not continue" type = "" httpStatus = "404"/>
This in-meomry capability is deprecated so don't use it if not for backward capabilities. Each Code can be defined as a public static final obect inside a global-use file.
  • Field Details

    • code

      protected final String code
    • description

      protected final String description
    • type

      protected final String type
    • httpStatus

      protected Integer httpStatus
  • Constructor Details

    • Code

      public Code(String code, String description, String type)
      Constructor method for Code
      Parameters:
      code - The code attribute of the Code
      description - The description of the Code
      type - The type (that is optional) of the Code
    • Code

      public Code(Code c)
      Copy Constructor
      Parameters:
      c - An instance of Code
  • Method Details

    • withHttpStatus

      public Code withHttpStatus(Integer n)
      Creates a copy of Code with the HttpStatus passed as parameter
      Parameters:
      n - The HttpStatus
      Returns:
      A copy of Code with the HttpStatus passed as parameter
    • getCode

      public static Code getCode(String id)
      Starting from the name of a Code it returns the Code object registered in memory. It first searches from the Code objects registered vie the register(java.lang.String, overit.geocall.util.Code) method. If the code is not found, it searches on all the public static final Code objects registered with registerClass(java.lang.Class).
      Parameters:
      id - The unique identifier of the Code
      Returns:
      The Code associated with the specific id
    • getCode

      @Deprecated public static Code getCode(String id, Identity identity)
      Deprecated.
      Starting from the name of a Code and the Identity, it returns the Code object registered inside the in-memory table. It searches first of all the Code objects loaded from the codes.xml file. Secondly it searches on all the public static final Code objects registered with registerClass(java.lang.Class). If the code is not found, it searches from the Code objects registered vie the register(java.lang.String, overit.geocall.util.Code) method.
      Parameters:
      id - The unique identifier of the Code
      identity - The Identity of the user currently logged in the application
      Returns:
      The Code associated with the specific id
    • getCode

      public static Code getCode(Class clz, String code)
      Extracts error Code objects from a class publishing public static final Code objects.
      Parameters:
      clz - the class to be inspected for codes
      code - the name of the code
      Returns:
      the Code if present, null otherwise
    • parseCodes

      protected static ConcurrentHashMap<String,Code> parseCodes(Identity identity)
    • register

      @Deprecated public static Code register(String id, Code code)
      Deprecated.
      This is only for backward compatibility. If a Code is registered i/e then it will be searchable git the getCode(java.lang.String, overit.geocall.util.Identity) method, otherwise it won't. Stop using it and define a public static final Code instead.
      Parameters:
      id - The global identificator for the Code
      code - The Code
      Returns:
      The Code associated with the specific id if the registration was successfull, otherwise the already registered code
    • registerClass

      public static void registerClass(Class<?> c)
      Registers a Class providing error codes in the form of public static final Code objects.
      Parameters:
      c - the Class providing codes in the form of public static final Code objects.
    • getCode

      public String getCode()
      Returns the code attribute of the Code
      Returns:
      The code attribute of the Code
    • code

      @Deprecated public String code()
      Deprecated.
      @return The code attribute of the Code
    • getHttpStatus

      public Integer getHttpStatus()
      Returns the httpStatus attribute of the Code
      Returns:
      The httpStatus attribute of the Code
    • getDescription

      public String getDescription()
      Returns the description of the Code
      Returns:
      The description of the Code
    • description

      @Deprecated public String description()
      Deprecated.
      use getDescription() instead
      Returns:
      The description of the Code
    • getType

      public String getType()
      Returns the type (that is optional) of the Code
      Returns:
      The type of the Code