private List < ValidatorMetaData > extractMetaDataFromString ( Class < ? > clazz , String propertyName , String unparsedString ) { String propertyKey = clazz . getName ( ) + "." + propertyName ; /* See if we parsed this bad boy already. */ List < ValidatorMetaData > validatorMetaDataList = metaDataCache . get ( propertyKey ) ; /* If we did not find the list, then we have some work to do.*/ if ( validatorMetaDataList == null ) { /* Initialize a new list. */ validatorMetaDataList = new ArrayList < ValidatorMetaData > ( ) ; /* Remember we have a string that looks like this: * required; length min=10, max=100 * So we need to split on semi-colon. */ String [ ] validatorsParts = unparsedString . split ( "[;]" ) ; /* Now we have the two strings as follows: * ["required", * ["length min=10, max=100"] * */ for ( String validatorString : validatorsParts ) { ValidatorMetaData validatorMetaData = new ValidatorMetaData ( ) ; validatorMetaDataList . add ( validatorMetaData ) ; /* Now we split one of the string (we will use length) * as follows: * parts=["length", "min=10", "max=100"] * */ String [ ] parts = validatorString . trim ( ) . split ( "[ ,]" ) ; /* The first part is the name of the validation, * e.g., "length". * */ validatorMetaData . setName ( parts [ 0 ] ) ; /* If the string has more than one part, then there must * be arguments as in: ["min=10", "max=100"] * * Parse the arguments and addObject them to the list as well. */ if ( parts . length > 1 ) { /* This line converts: * * ["length", "min=10", "max=100"] * * into: * * ["min=10", "max=100"] */ List < String > values = Arrays . asList ( parts ) . subList ( 1 , parts . length ) ; /* For each value convert it into name value pairs. */ for ( String value : values ) { if ( value . indexOf ( "=" ) != - 1 ) { /* Split "min=10" into ["min", "10"] */ String [ ] valueParts = value . split ( "[=]" ) ; /* Stick this value into validatorMetaData's * list of properties. */ validatorMetaData . getProperties ( ) . put ( valueParts [ 0 ] , valueParts [ 1 ] ) ; } } } } metaDataCache . put ( propertyKey , validatorMetaDataList ) ; } return validatorMetaDataList ; }
This method extracts meta - data from a string .