private ValidatorInfo parseValidator(ComponentCtrl compCtrl, String propName) { final Collection<Annotation> annos = compCtrl.getAnnotations(propName, VALIDATOR_ANNO); if (annos.size() == 0) return null; if (annos.size() > 1) { throw new IllegalSyntaxException( "Allow only one validator for " + propName + " of " + compCtrl); } final Annotation anno = annos.iterator().next(); ValidatorInfo info = new ValidatorInfo(); Map<String, String[]> args = null; for (final Iterator<Entry<String, String[]>> it = anno.getAttributes().entrySet().iterator(); it.hasNext(); ) { final Entry<String, String[]> entry = it.next(); final String tag = entry.getKey(); final String[] tagExpr = entry.getValue(); if ("value".equals(tag)) { info.expr = testString(compCtrl, propName, tag, tagExpr); } else { // other unknown tag, keep as arguments if (args == null) { args = new HashMap<String, String[]>(); } args.put(tag, tagExpr); } } if (Strings.isBlank(info.expr)) { throw new IllegalSyntaxException( "Must specify a validator for " + propName + " of " + compCtrl); } info.args = args == null ? null : parsedArgs(args); return info; }
private void unsubscribeAll() { synchronized (lock) { initialized = false; if (validators == null) { return; } for (ValidatorInfo info : validators) { if (StringUtilities.isNotBlank(info.getUri())) { manager.unsubscribeFrom(info.getUri(), wadlListener); } } } }
@Override public void configurationUpdated(ConfigurationResource config) { LOG.info("WADL file changed: " + config.name()); synchronized (lock) { if (validators == null) { return; } boolean found = false; for (ValidatorInfo info : validators) { if (info.getUri() != null && getNormalizedPath(info.getUri()).equals(config.name())) { info.reinitValidator(); found = true; } } if (!found) { // If we couldn't match the particular config... be safe and clear // all fo the validators for (ValidatorInfo info : validators) { info.reinitValidator(); } } } isInitialized = true; }
void initialize() { synchronized (lock) { if (initialized || validatorConfiguration == null) { return; } validators = new ArrayList<ValidatorInfo>(validatorConfiguration.getValidator().size()); defaultValidator = null; multiRoleMatch = validatorConfiguration.isMultiRoleMatch(); for (ValidatorItem validatorItem : validatorConfiguration.getValidator()) { Config configuration = new ValidatorConfigurator(validatorItem, multiRoleMatch, configRoot).getConfiguration(); ValidatorInfo validator = validatorItem.getAny() != null ? new ValidatorInfo( validatorItem.getRole(), (Element) validatorItem.getAny(), getWadlPath(this.config), configuration) : new ValidatorInfo( validatorItem.getRole(), getWadlPath(validatorItem.getWadl()), configuration); validators.add(validator); if (validatorItem.isDefault() && defaultValidator == null) { defaultValidator = validator; } } for (ValidatorInfo validator : validators) { addListener(validator.getUri()); } initialized = true; } }