public static java.util.Collection getValidatorVars(
final ModelElementFacade element,
final ClassifierFacade type,
final ParameterFacade ownerParameter)
{
final Map vars = new LinkedHashMap();
if (element != null && type != null)
{
final String format = JSFUtils.getInputFormat(element);
if (format != null)
{
final boolean isRangeFormat = JSFUtils.isRangeFormat(format);
if (isRangeFormat)
{
final String min = "min";
final String max = "max";
vars.put(
min,
Arrays.asList(new Object[] {min, JSFUtils.getRangeStart(format)}));
vars.put(
max,
Arrays.asList(new Object[] {max, JSFUtils.getRangeEnd(format)}));
}
else
{
final Collection formats = element.findTaggedValues(JSFProfile.TAGGEDVALUE_INPUT_FORMAT);
for (final Iterator formatIterator = formats.iterator(); formatIterator.hasNext();)
{
final String additionalFormat = String.valueOf(formatIterator.next());
final String minlength = "minlength";
final String maxlength = "maxlength";
final String mask = "mask";
if (JSFUtils.isMinLengthFormat(additionalFormat))
{
vars.put(
minlength,
Arrays.asList(new Object[] {minlength, JSFUtils.getMinLengthValue(additionalFormat)}));
}
else if (JSFUtils.isMaxLengthFormat(additionalFormat))
{
vars.put(
maxlength,
Arrays.asList(new Object[] {maxlength, JSFUtils.getMaxLengthValue(additionalFormat)}));
}
else if (JSFUtils.isPatternFormat(additionalFormat))
{
vars.put(
mask,
Arrays.asList(new Object[] {mask, JSFUtils.getPatternValue(additionalFormat)}));
}
}
}
}
String inputFormat;
if (element instanceof JSFAttribute)
{
inputFormat = ((JSFAttribute)element).getFormat();
}
else if (element instanceof JSFParameter)
{
inputFormat = ((JSFParameter)element).getFormat();
}
else
{
throw new RuntimeException("'element' is an invalid type, it must be either an instance of '" +
JSFAttribute.class.getName() + "' or '" + JSFParameter.class.getName() + "'");
}
if (JSFUtils.isDate(type))
{
final String datePatternStrict = "datePatternStrict";
if (format != null && JSFUtils.isStrictDateFormat(format))
{
vars.put(
datePatternStrict,
Arrays.asList(new Object[] {datePatternStrict, inputFormat}));
}
else
{
final String datePattern = "datePattern";
vars.put(
datePattern,
Arrays.asList(new Object[] {datePattern, inputFormat}));
}
}
if (JSFUtils.isTime(type))
{
final String timePattern = "timePattern";
vars.put(
timePattern,
Arrays.asList(new Object[] {timePattern, inputFormat}));
}
final String validWhen = JSFUtils.getValidWhen(element);
if (validWhen != null)
{
final String test = "test";
vars.put(
test,
Arrays.asList(new Object[] {test, validWhen}));
}
final String equal = JSFUtils.getEqual(element, ownerParameter);
if (equal != null)
{
final String fieldName = "fieldName";
vars.put(
fieldName,
Arrays.asList(new Object[] {fieldName, equal}));
}
}
// - custom (parameterized) validators are allowed here
// in this case we will reuse the validator arg values
final Collection taggedValues = element.findTaggedValues(JSFProfile.TAGGEDVALUE_INPUT_VALIDATORS);
for (final Iterator iterator = taggedValues.iterator(); iterator.hasNext();)
{
final String validator = String.valueOf(iterator.next());
// - guaranteed to be of the same length
final List validatorVars = JSFUtils.parseValidatorVars(validator);
final List validatorArgs = JSFUtils.parseValidatorArgs(validator);
for (int ctr = 0; ctr < validatorVars.size(); ctr++)
{
final String validatorVar = (String)validatorVars.get(ctr);
final String validatorArg = (String)validatorArgs.get(ctr);
vars.put(
validatorVar,
Arrays.asList(new Object[] {validatorVar, validatorArg}));
}
}
return vars.values();
}