Class Validator
- java.lang.Object
-
- de.iip_ecosphere.platform.services.spring.descriptor.Validator
-
public class Validator extends java.lang.ObjectA simple validator for deployment descriptors.- Author:
- Holger Eichelberger, SSE
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interfaceValidator.ValidatorFunction<O>A validation function, to point generically to the private validation functions defined by this class.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.String>messagesprivate java.util.Set<java.lang.String>serviceIds
-
Constructor Summary
Constructors Constructor Description Validator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.StringappendContext(java.lang.String msg, java.lang.String msgContext)Appends themsgContexttomsgfor output.private java.lang.StringappendToContext(java.lang.String context, java.lang.String text)Appendstexttocontextconsidering thatcontextmay be empty or null.private booleanassertCondition(boolean condition, java.lang.String msg, java.lang.String msgContext)Asserts a condition.private booleanassertFieldNotNull(java.lang.Object object, java.lang.String field, java.lang.String msgContext)Asserts thatobjectin a field is not null.private booleanassertJavaIdentifier(java.lang.String name, java.lang.String field, java.lang.String msgContext)Asserts thatnamein a field is not null, not empty and a Java identifier.private <O> booleanassertList(java.util.List<O> list, boolean fieldNotNull, java.lang.String field, java.lang.String msgContext, Validator.ValidatorFunction<O> func)Asserts a list of objects that can be validated.private booleanassertStringList(java.util.List<java.lang.String> list, java.lang.String field, java.lang.String entry, java.lang.String msgContext)Asserts that the given string list is either empty or strings are not empty.private booleanassertStringNotEmpty(java.lang.String string, java.lang.String field, java.lang.String msgContext)Asserts thatstringis not empty, in particular not null.private booleanassertType(java.lang.String type, java.util.Map<java.lang.String,Type> types, java.lang.String field, java.lang.String msgContext)private booleanassertVersion(java.lang.Object object, java.lang.String field, java.lang.String msgContext)Asserts thatobjectin a field is a version.voidclear()Clears this instance for re-use.java.lang.StringgetMessages()Returns all messages as string.booleanhasMessages()Returns whether there are validation (error) messages.java.lang.Iterable<java.lang.String>messages()Returns the validation messages.static java.util.Map<java.lang.String,Type>toMap(java.util.List<? extends Type> types)Turns the giventypesinto a map, mapping the type name to its type descriptor.voidvalidate(Artifact artifact)Validates the given artifact (and contained descriptor elements).voidvalidate(Endpoint endpoint)Validates the given endpoint (and contained descriptor elements).private voidvalidate(Endpoint endpoint, java.lang.String msgContext)Validates the given endpoint (and contained descriptor elements).voidvalidate(ProcessSpec process)Validates the given process (and contained descriptor elements).private voidvalidate(ProcessSpec process, java.lang.String msgContext)Validates the given process (and contained descriptor elements).voidvalidate(Relation relation, java.util.Map<java.lang.String,Type> types)Validates the given relation (and contained descriptor elements).private voidvalidate(Relation relation, java.util.Map<java.lang.String,Type> types, java.lang.String msgContext)Validates the given relation (and contained descriptor elements).voidvalidate(Service service, java.util.List<? extends Type> types)Validates the given service (and contained descriptor elements).private voidvalidate(Service service, java.util.Map<java.lang.String,Type> types, java.lang.String msgContext)Validates the given service (and contained descriptor elements).private voidvalidate(TypedData typed, java.util.Map<java.lang.String,Type> types, java.lang.String msgContext)Validates the given typed data (and contained descriptor elements).
-
-
-
Method Detail
-
hasMessages
public boolean hasMessages()
Returns whether there are validation (error) messages.- Returns:
truefor messages,falsefor no messages/everything is ok
-
getMessages
public java.lang.String getMessages()
Returns all messages as string.- Returns:
- all messages
-
messages
public java.lang.Iterable<java.lang.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, java.util.List<? extends Type> types)
Validates the given service (and contained descriptor elements).- Parameters:
service- the service to validatetypes- the declared types
-
validate
private void validate(Service service, java.util.Map<java.lang.String,Type> types, java.lang.String msgContext)
Validates the given service (and contained descriptor elements).- Parameters:
service- the service to validatetypes- the declared typesmsgContext- nested context information for location of unnamed elements in validation messages
-
toMap
public static java.util.Map<java.lang.String,Type> toMap(java.util.List<? extends Type> types)
Turns the giventypesinto 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, java.util.Map<java.lang.String,Type> types)
Validates the given relation (and contained descriptor elements).- Parameters:
relation- the relation to validatetypes- the declared types
-
validate
private void validate(TypedData typed, java.util.Map<java.lang.String,Type> types, java.lang.String msgContext)
Validates the given typed data (and contained descriptor elements).- Parameters:
typed- the typed data to validatemsgContext- nested context information for location of unnamed elements in validation messagestypes- the declared types
-
validate
private void validate(Relation relation, java.util.Map<java.lang.String,Type> types, java.lang.String msgContext)
Validates the given relation (and contained descriptor elements).- Parameters:
relation- the relation to validatemsgContext- nested context information for location of unnamed elements in validation messagestypes- the declared types
-
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, java.lang.String msgContext)
Validates the given process (and contained descriptor elements).- Parameters:
process- the process to validatemsgContext- nested context information for location of unnamed elements in validation messages
-
appendToContext
private java.lang.String appendToContext(java.lang.String context, java.lang.String text)Appendstexttocontextconsidering thatcontextmay be empty or null.- Parameters:
context- the context to append, may be empty or nulltext- 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, java.lang.String msgContext)
Validates the given endpoint (and contained descriptor elements).- Parameters:
endpoint- the endpoint to validatemsgContext- nested context information for location of unnamed elements in validation messages
-
assertType
private boolean assertType(java.lang.String type, java.util.Map<java.lang.String,Type> types, java.lang.String field, java.lang.String msgContext)- Parameters:
type- the type name to checktypes- the declared typesfield- the field the string is taken from for composing an error messagemsgContext- the context of the message/validate element for better location by the caller, ignored if empty or null- Returns:
trueif successful,falseif failed
-
assertJavaIdentifier
private boolean assertJavaIdentifier(java.lang.String name, java.lang.String field, java.lang.String msgContext)Asserts thatnamein a field is not null, not empty and a Java identifier.- Parameters:
name- the name to checkfield- the field the string is taken from for composing an error messagemsgContext- the context of the message/validate element for better location by the caller, ignored if empty or null- Returns:
trueif successful,falseif failed
-
assertFieldNotNull
private boolean assertFieldNotNull(java.lang.Object object, java.lang.String field, java.lang.String msgContext)Asserts thatobjectin a field is not null.- Parameters:
object- the object to checkfield- the field the string is taken from for composing an error messagemsgContext- the context of the message/validate element for better location by the caller, ignored if empty or null- Returns:
trueif successful,falseif failed
-
assertVersion
private boolean assertVersion(java.lang.Object object, java.lang.String field, java.lang.String msgContext)Asserts thatobjectin a field is a version.- Parameters:
object- the object to checkfield- the field the string is taken from for composing an error messagemsgContext- the context of the message/validate element for better location by the caller, ignored if empty or null- Returns:
trueif successful,falseif failed
-
assertList
private <O> boolean assertList(java.util.List<O> list, boolean fieldNotNull, java.lang.String field, java.lang.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 assertedfieldNotNull- iftrue, applyassertFieldNotNull(Object, String, String)tolistand return its result, else return alwaystruefield- the field the string is taken from for composing an error messagemsgContext- the context of the message/validate element for better location by the caller, ignored if empty or nullfunc- iflistas object/field is considered to be ok, applyfuncto each element with respective iterative context set- Returns:
trueif successful,falseif failed
-
assertStringList
private boolean assertStringList(java.util.List<java.lang.String> list, java.lang.String field, java.lang.String entry, java.lang.String msgContext)Asserts that the given string list is either empty or strings are not empty.- Parameters:
list- the command line argument listfield- the field the string is taken from for composing an error messageentry- the symbolic name of an entry for composing an error messagemsgContext- the context of the message/validate element for better location by the caller, ignored if empty or null- Returns:
trueif successful,falseif failed
-
assertStringNotEmpty
private boolean assertStringNotEmpty(java.lang.String string, java.lang.String field, java.lang.String msgContext)Asserts thatstringis not empty, in particular not null.- Parameters:
string- the string to checkfield- the field the string is taken from for composing an error messagemsgContext- the context of the message/validate element for better location by the caller, ignored if empty or null- Returns:
trueif successful,falseif failed
-
assertCondition
private boolean assertCondition(boolean condition, java.lang.String msg, java.lang.String msgContext)Asserts a condition.- Parameters:
condition- the evaluated conditionmsg- the message ifconditiondoes 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:
trueif successful,falseif failed
-
appendContext
private java.lang.String appendContext(java.lang.String msg, java.lang.String msgContext)Appends themsgContexttomsgfor output.- Parameters:
msg- the messagemsgContext- the message context- Returns:
- msg with appende context
-
-