Class Descriptor

java.lang.Object
org.pipservices3.commons.refer.Descriptor

public class Descriptor extends Object
Locator type that most often used in PipServices toolkit. It locates components using several fields:
  • Group: a package or just named group of components like "pip-services3"
  • Type: logical component type that defines it's contract like "persistence"
  • Kind: physical implementation type like "mongodb"
  • Name: unique component name like "default"
  • Version: version of the component contract like "1.0"

The locator matching can be done by all or only few selected fields. The fields that shall be excluded from the matching must be set to "*" or null. That approach allows to implement many interesting scenarios. For instance:

  • Locate all loggers (match by type and version)
  • Locate persistence components for a microservice (match by group and type)
  • Locate specific component by its name (match by name)

### Example ###

 
 Descriptor locator1 = new Descriptor("mygroup", "connector", "aws", "default", "1.0");
 Descriptor locator2 = Descriptor.fromString("mygroup:connector:*:*:1.0");

 locator1.match(locator2);        // Result: true
 locator1.equal(locator2);        // Result: true
 locator1.exactMatch(locator2);	// Result: false
 
 
  • Constructor Details

    • Descriptor

      public Descriptor(String group, String type, String kind, String name, String version)
      Creates a new instance of the descriptor.
      Parameters:
      group - a logical component group
      type - a logical component type or contract
      kind - a component implementation type
      name - a unique component name
      version - a component implementation version
  • Method Details

    • getGroup

      public String getGroup()
      Gets the component's logical group.
      Returns:
      the component's logical group
    • getType

      public String getType()
      Gets the component's logical type.
      Returns:
      the component's logical type.
    • getKind

      public String getKind()
      Gets the component's implementation type.
      Returns:
      the component's implementation type.
    • getName

      public String getName()
      Gets the unique component's name.
      Returns:
      the unique component's name.
    • getVersion

      public String getVersion()
      Gets the component's implementation version.
      Returns:
      the component's implementation version.
    • match

      public boolean match(Descriptor descriptor)
      Partially matches this descriptor to another descriptor. Fields that contain "*" or null are excluded from the match.
      Parameters:
      descriptor - the descriptor to match this one against.
      Returns:
      true if descriptors match and false otherwise
      See Also:
    • exactMatch

      public boolean exactMatch(Descriptor descriptor)
      Matches this descriptor to another descriptor by all fields. No exceptions are made.
      Parameters:
      descriptor - the descriptor to match this one against.
      Returns:
      true if descriptors match and false otherwise.
      See Also:
    • isComplete

      public boolean isComplete()
      Checks whether all descriptor fields are set. If descriptor has at least one "*" or null field it is considered "incomplete",
      Returns:
      true if all descriptor fields are defined and false otherwise.
    • equals

      public boolean equals(Object value)
      Compares this descriptor to a value. If value is a Descriptor it tries to match them, otherwise the method returns false.
      Overrides:
      equals in class Object
      Parameters:
      value - the value to match against this descriptor.
      Returns:
      true if the value is matching descriptor and false otherwise.
      See Also:
    • toString

      public String toString()
      Gets a string representation of the object. The result is a colon-separated list of descriptor fields as "mygroup:connector:aws:default:1.0"
      Overrides:
      toString in class Object
      Returns:
      a string representation of the object.
    • fromString

      public static Descriptor fromString(String value) throws ConfigException
      Parses colon-separated list of descriptor fields and returns them as a Descriptor.
      Parameters:
      value - colon-separated descriptor fields to initialize Descriptor.
      Returns:
      a newly created Descriptor.
      Throws:
      ConfigException - if the descriptor string is of a wrong format.