Class ContextBean

java.lang.Object
org.gcube.common.security.ContextBean

public class ContextBean extends Object
A data object model representing a hierarchical scope.

This class provides a structured representation for scopes that are defined in a linear, path-like syntax (e.g., "/INFRASTRUCTURE/VO/VRE"). It supports three types of scopes: ContextBean.Type.INFRASTRUCTURE, ContextBean.Type.VO, and ContextBean.Type.VRE. The class allows for navigating the scope hierarchy and provides utility methods for comparison and string representation.

Author:
Fabio Simeoni
  • Field Details

    • separator

      protected static String separator
      Separator used in the linear syntax of scopes.
  • Constructor Details

    • ContextBean

      public ContextBean(String scope) throws IllegalArgumentException
      Constructs a new ContextBean from a linear string representation. The constructor parses the string to determine the scope's name, type, and its enclosing scope.
      Parameters:
      scope - The linear string representing the scope (e.g., "/INFRASTRUCTURE/VO/VRE").
      Throws:
      IllegalArgumentException - if the provided scope string is malformed or does not conform to the expected hierarchy.
  • Method Details

    • name

      public String name()
      Returns the name of this scope level.
      Returns:
      The name of the scope.
    • is

      public boolean is(ContextBean.Type type)
      Checks if the scope has a specific ContextBean.Type.
      Parameters:
      type - The ContextBean.Type to check against.
      Returns:
      true if the scope's type matches the given type, otherwise false.
    • type

      public ContextBean.Type type()
      Returns the ContextBean.Type of this scope.
      Returns:
      The type of the scope.
    • enclosingScope

      public ContextBean enclosingScope()
      Returns the enclosing scope in the hierarchy.
      Returns:
      The parent ContextBean object, or null if this is a top-level scope (type is INFRASTRUCTURE).
    • toString

      public String toString()
      Returns the linear string representation of the scope. This method reconstructs the path from the current scope to the top-level.
      Overrides:
      toString in class Object
      Returns:
      The linear string representation (e.g., "/INFRASTRUCTURE/VO").
    • hashCode

      public int hashCode()
      Calculates the hash code for this object based on its name, type, and enclosing scope.
      Overrides:
      hashCode in class Object
      Returns:
      A hash code value for this object.
    • equals

      public boolean equals(Object obj)
      Compares this object with another object for equality.
      Overrides:
      equals in class Object
      Parameters:
      obj - The object to compare with.
      Returns:
      true if the objects are the same or have the same name, type, and enclosing scope; false otherwise.