java.lang.Object
de.iip_ecosphere.platform.services.spring.descriptor.Validator

public class Validator extends Object
A simple validator for deployment descriptors.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • Validator

      public Validator()
  • Method Details

    • hasMessages

      public boolean hasMessages()
      Returns whether there are validation (error) messages.
      Returns:
      true for messages, false for no messages/everything is ok
    • getMessages

      public String getMessages()
      Returns all messages as string.
      Returns:
      all messages
    • messages

      public Iterable<String> messages()
      Returns the validation messages.
      Returns:
      the individual messages
    • clear

      public void clear()
      Clears this instance for re-use.
    • validate

      public void validate(Artifact artifact)
      Validates the given artifact (and contained descriptor elements).
      Parameters:
      artifact - the artifact to validate
    • validate

      public void validate(Service service, List<? extends Type> types)
      Validates the given service (and contained descriptor elements).
      Parameters:
      service - the service to validate
      types - the declared types
    • validate

      private void validate(Service service, Map<String,Type> types, String msgContext)
      Validates the given service (and contained descriptor elements).
      Parameters:
      service - the service to validate
      types - the declared types
      msgContext - nested context information for location of unnamed elements in validation messages
    • toMap

      public static Map<String,Type> toMap(List<? extends Type> types)
      Turns the given types into a map, mapping the type name to its type descriptor.
      Parameters:
      types - the types to map
      Returns:
      the mapped types
    • validate

      public void validate(Relation relation, Map<String,Type> types)
      Validates the given relation (and contained descriptor elements).
      Parameters:
      relation - the relation to validate
      types - the declared types
    • validate

      private void validate(TypedData typed, Map<String,Type> types, String msgContext)
      Validates the given typed data (and contained descriptor elements).
      Parameters:
      typed - the typed data to validate
      types - the declared types
      msgContext - nested context information for location of unnamed elements in validation messages
    • validate

      private void validate(Relation relation, Map<String,Type> types, String msgContext)
      Validates the given relation (and contained descriptor elements).
      Parameters:
      relation - the relation to validate
      types - the declared types
      msgContext - nested context information for location of unnamed elements in validation messages
    • validate

      public void validate(ProcessSpec process)
      Validates the given process (and contained descriptor elements).
      Parameters:
      process - the process to validate
    • validate

      private void validate(ProcessSpec process, String msgContext)
      Validates the given process (and contained descriptor elements).
      Parameters:
      process - the process to validate
      msgContext - nested context information for location of unnamed elements in validation messages
    • appendToContext

      private String appendToContext(String context, String text)
      Appends text to context considering that context may be empty or null.
      Parameters:
      context - the context to append, may be empty or null
      text - the text to append
      Returns:
      the appended context information
    • validate

      public void validate(Endpoint endpoint)
      Validates the given endpoint (and contained descriptor elements).
      Parameters:
      endpoint - the endpoint to validate
    • validate

      private void validate(Endpoint endpoint, String msgContext)
      Validates the given endpoint (and contained descriptor elements).
      Parameters:
      endpoint - the endpoint to validate
      msgContext - nested context information for location of unnamed elements in validation messages
    • assertType

      private boolean assertType(String type, Map<String,Type> types, String field, String msgContext)
      Asserts that type is a known type, either in primitives, types or as a Java type.
      Parameters:
      type - the type name to check
      types - the declared types
      field - the field the string is taken from for composing an error message
      msgContext - the context of the message/validate element for better location by the caller, ignored if empty or null
      Returns:
      true if successful, false if failed
    • assertJavaIdentifier

      private boolean assertJavaIdentifier(String name, String field, String msgContext)
      Asserts that name in a field is not null, not empty and a Java identifier.
      Parameters:
      name - the name to check
      field - the field the string is taken from for composing an error message
      msgContext - the context of the message/validate element for better location by the caller, ignored if empty or null
      Returns:
      true if successful, false if failed
    • assertFieldNotNull

      private boolean assertFieldNotNull(Object object, String field, String msgContext)
      Asserts that object in a field is not null.
      Parameters:
      object - the object to check
      field - the field the string is taken from for composing an error message
      msgContext - the context of the message/validate element for better location by the caller, ignored if empty or null
      Returns:
      true if successful, false if failed
    • assertVersion

      private boolean assertVersion(Object object, String field, String msgContext)
      Asserts that object in a field is a version.
      Parameters:
      object - the object to check
      field - the field the string is taken from for composing an error message
      msgContext - the context of the message/validate element for better location by the caller, ignored if empty or null
      Returns:
      true if successful, false if failed
    • assertList

      private <O> boolean assertList(List<O> list, boolean fieldNotNull, String field, String msgContext, Validator.ValidatorFunction<O> func)
      Asserts a list of objects that can be validated.
      Type Parameters:
      O - the type of objects
      Parameters:
      list - the list of objects to be asserted
      fieldNotNull - if true, apply assertFieldNotNull(Object, String, String) to list and return its result, else return always true
      field - the field the string is taken from for composing an error message
      msgContext - the context of the message/validate element for better location by the caller, ignored if empty or null
      func - if list as object/field is considered to be ok, apply func to each element with respective iterative context set
      Returns:
      true if successful, false if failed
    • assertStringList

      private boolean assertStringList(List<String> list, String field, String entry, String msgContext)
      Asserts that the given string list is either empty or strings are not empty.
      Parameters:
      list - the command line argument list
      field - the field the string is taken from for composing an error message
      entry - the symbolic name of an entry for composing an error message
      msgContext - the context of the message/validate element for better location by the caller, ignored if empty or null
      Returns:
      true if successful, false if failed
    • assertStringNotEmpty

      private boolean assertStringNotEmpty(String string, String field, String msgContext)
      Asserts that string is not empty, in particular not null.
      Parameters:
      string - the string to check
      field - the field the string is taken from for composing an error message
      msgContext - the context of the message/validate element for better location by the caller, ignored if empty or null
      Returns:
      true if successful, false if failed
    • assertCondition

      private boolean assertCondition(boolean condition, String msg, String msgContext)
      Asserts a condition.
      Parameters:
      condition - the evaluated condition
      msg - the message if condition does not hold. A missing trailing "." is added.
      msgContext - the context of the message/validate element for better location by the caller, ignored if empty or null
      Returns:
      true if successful, false if failed
    • appendContext

      private String appendContext(String msg, String msgContext)
      Appends the msgContext to msg for output.
      Parameters:
      msg - the message
      msgContext - the message context
      Returns:
      msg with appende context