@Override public MSimpleParameter getUrlParameter(String name) { if(urlParameters != null){ for(int i=0;i<urlParameters.length;i++){ MSimpleParameter p = urlParameters[i]; if(p.getName().equals(name)){ return p; } } } throw new ObjectNotFoundException("Parameter '" + name + "' not found in this driver"); }
public Builder(MSimpleParameter p) { super(p); this.secret = p.isSecret(); this.type = (MSimpleType)p.type; this.defaultValue = p.defaultValue; this.minLength = p.minLength; this.maxLength = p.maxLength; this.minValue = p.minValue; this.maxValue = p.maxValue; this.pattern = p.pattern == null ? null : p.pattern.getName(); }
@Override public MSimpleParameter build() { MPattern p = !Strings.isEmpty(pattern) ? MD.getMPattern(pattern) : null; List<Validator> validators = new ArrayList<>(); if(null != minLength || null != maxLength){ validators.add(new LengthValidator(minLength == null ? 0 : minLength, maxLength == null ? Integer.MAX_VALUE : maxLength)); } if(null != minValue){ validators.add(new MinValidator(minValue)); } if(null != maxValue){ validators.add(new MaxValidator(maxValue)); } if(null != p){ validators.add(new PatternValidator(p.getName(),p.getPattern())); } return new MSimpleParameter(name, title, summary, description, secret, (MSimpleType)type, required, defaultValue, minLength,maxLength,minValue,maxValue,p,validators.toArray(new Validator[validators.size()])); } }
@Override public void localize(MessageSource ms, String localizeKey) { if(null != urlParameters){ String keyPrefix = "db.drivers.params"; for(int i=0;i<urlParameters.length;i++){ MSimpleParameter p = urlParameters[i]; MSimpleParameter.Builder lp = new MSimpleParameter.Builder(p); I18N.localize(ms, lp, keyPrefix + "." + p.getName()); urlParameters[i] = lp.build(); } } } }