1
2
3
4 package org.rcfaces.core.internal.config;
5
6 import java.beans.BeanInfo;
7 import java.beans.IntrospectionException;
8 import java.beans.Introspector;
9 import java.beans.PropertyDescriptor;
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Locale;
14 import java.util.Map;
15 import java.util.TimeZone;
16
17 import javax.faces.FacesException;
18 import javax.faces.application.Application;
19 import javax.faces.component.UIComponent;
20 import javax.faces.context.FacesContext;
21 import javax.faces.convert.Converter;
22 import javax.faces.validator.DoubleRangeValidator;
23 import javax.faces.validator.LengthValidator;
24 import javax.faces.validator.LongRangeValidator;
25 import javax.faces.validator.Validator;
26
27 import org.apache.commons.digester.Digester;
28 import org.apache.commons.digester.Rule;
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.rcfaces.core.internal.lang.StringAppender;
32 import org.rcfaces.core.internal.renderkit.IRenderContext;
33 import org.rcfaces.core.internal.renderkit.IScriptRenderContext;
34 import org.rcfaces.core.internal.tools.BindingTools;
35 import org.rcfaces.core.internal.util.ClassLocator;
36 import org.rcfaces.core.internal.util.Convertor;
37 import org.rcfaces.core.internal.validator.IClientValidatorDescriptor;
38 import org.rcfaces.core.internal.validator.IClientValidatorsRegistry;
39 import org.rcfaces.core.internal.validator.IServerConverter;
40 import org.rcfaces.core.internal.validator.ITaskDescriptor;
41 import org.rcfaces.core.internal.validator.impl.RegExpFilter;
42 import org.rcfaces.core.lang.IParametredConverter;
43 import org.rcfaces.core.validator.IClientValidatorTask;
44 import org.rcfaces.core.validator.IParameter;
45 import org.xml.sax.Attributes;
46
47
48
49
50
51
52 public class ClientValidatorsRegistryImpl extends AbstractRenderKitRegistryImpl
53 implements IClientValidatorsRegistry {
54 private static final String REVISION = "$Revision: 1.18 $";
55
56 private static final Log LOG = LogFactory
57 .getLog(ClientValidatorsRegistryImpl.class);
58
59 private static final IParameter[] PARAMETER_EMPTY_ARRAY = new IParameter[0];
60
61 private static final String[] STRING_EMPTY_ARRAY = new String[0];
62
63 public IClientValidatorDescriptor getClientValidatorById(
64 FacesContext facesContext, String validatorId, Locale locale,
65 TimeZone timeZone) {
66
67 RenderKit renderKit = (RenderKit) getRenderKit(facesContext, null);
68 if (renderKit == null) {
69 return null;
70 }
71
72 return renderKit.getValidatorById(validatorId, locale, timeZone);
73 }
74
75
76
77
78
79
80
81
82
83
84
85 public void configureRules(Digester digester) {
86
87 digester.addRule("rcfaces-config/clientValidators/render-kit",
88 new Rule() {
89 private static final String REVISION = "$Revision: 1.18 $";
90
91 public void begin(String namespace, String name,
92 Attributes attributes) throws Exception {
93
94 String renderKitId = attributes
95 .getValue("render-kit-id");
96
97 RenderKit renderKit = (RenderKit) allocate(renderKitId);
98
99 super.digester.push(renderKit);
100 }
101
102 public void end(String namespace, String name)
103 throws Exception {
104 super.digester.pop();
105 }
106 });
107
108 digester.addObjectCreate(
109 "rcfaces-config/clientValidators/render-kit/clientValidator",
110 ClientValidator.class);
111 digester.addSetProperties(
112 "rcfaces-config/clientValidators/render-kit/clientValidator",
113 "id", "id");
114 digester.addSetProperties(
115 "rcfaces-config/clientValidators/render-kit/clientValidator",
116 "package", "packageName");
117
118 digester.addRule(
119 "rcfaces-config/clientValidators/render-kit/clientValidator",
120 new Rule() {
121
122 public void end(String namespace, String name)
123 throws Exception {
124 ClientValidator clientValidator = (ClientValidator) getDigester()
125 .peek();
126
127 clientValidator.prepare();
128 }
129
130 });
131
132 digester
133 .addRule(
134 "rcfaces-config/clientValidators/render-kit/clientValidator/filter",
135 new Rule() {
136 private static final String REVISION = "$Revision: 1.18 $";
137
138 public void begin(String namespace, String name,
139 Attributes attributes) throws Exception {
140 ClientValidator clientValidator = (ClientValidator) getDigester()
141 .peek();
142
143 clientValidator.setFilter(new TaskDescriptor(
144 attributes) {
145
146 protected IClientValidatorTask computeClientValidatorTask(
147 String serverTaskClassName,
148 Attributes attributes) {
149 if (serverTaskClassName == null
150 && clientTaskExpression != null
151 && clientTaskExpression
152 .length() > 1) {
153
154 if (clientTaskExpression
155 .startsWith("/")
156 && clientTaskExpression
157 .endsWith("/")) {
158
159 return new RegExpFilter(
160 clientTaskExpression
161 .substring(
162 1,
163 clientTaskExpression
164 .length() - 1));
165 }
166 }
167 return super
168 .computeClientValidatorTask(
169 serverTaskClassName,
170 attributes);
171 }
172
173 });
174 }
175 });
176
177 digester
178 .addRule(
179 "rcfaces-config/clientValidators/render-kit/clientValidator/translator",
180 new Rule() {
181 private static final String REVISION = "$Revision: 1.18 $";
182
183 public void begin(String namespace, String name,
184 Attributes attributes) throws Exception {
185 ClientValidator clientValidator = (ClientValidator) getDigester()
186 .peek();
187
188 clientValidator
189 .setTranslator(new TaskDescriptor(
190 attributes));
191 }
192 });
193
194 digester
195 .addRule(
196 "rcfaces-config/clientValidators/render-kit/clientValidator/checker",
197 new Rule() {
198 private static final String REVISION = "$Revision: 1.18 $";
199
200 public void begin(String namespace, String name,
201 Attributes attributes) throws Exception {
202 ClientValidator clientValidator = (ClientValidator) getDigester()
203 .peek();
204
205 clientValidator.setChecker(new TaskDescriptor(
206 attributes));
207 }
208 });
209 digester
210 .addRule(
211 "rcfaces-config/clientValidators/render-kit/clientValidator/formatter",
212 new Rule() {
213 private static final String REVISION = "$Revision: 1.18 $";
214
215 public void begin(String namespace, String name,
216 Attributes attributes) throws Exception {
217 ClientValidator clientValidator = (ClientValidator) getDigester()
218 .peek();
219
220 clientValidator
221 .setFormatter(new TaskDescriptor(
222 attributes));
223 }
224 });
225 digester
226 .addRule(
227 "rcfaces-config/clientValidators/render-kit/clientValidator/behavior",
228 new Rule() {
229 private static final String REVISION = "$Revision: 1.18 $";
230
231 public void begin(String namespace, String name,
232 Attributes attributes) throws Exception {
233 ClientValidator clientValidator = (ClientValidator) getDigester()
234 .peek();
235
236 clientValidator.setBehavior(new TaskDescriptor(
237 attributes));
238 }
239 });
240 digester
241 .addRule(
242 "rcfaces-config/clientValidators/render-kit/clientValidator/onerror",
243 new Rule() {
244 private static final String REVISION = "$Revision: 1.18 $";
245
246 public void begin(String namespace, String name,
247 Attributes attributes) throws Exception {
248 ClientValidator clientValidator = (ClientValidator) getDigester()
249 .peek();
250
251 clientValidator.setOnerror(new TaskDescriptor(
252 attributes));
253 }
254 });
255 digester
256 .addRule(
257 "rcfaces-config/clientValidators/render-kit/clientValidator/oncheckerror",
258 new Rule() {
259 private static final String REVISION = "$Revision: 1.18 $";
260
261 public void begin(String namespace, String name,
262 Attributes attributes) throws Exception {
263 ClientValidator clientValidator = (ClientValidator) getDigester()
264 .peek();
265
266 clientValidator
267 .setOncheckerror(new TaskDescriptor(
268 attributes));
269 }
270 });
271 digester
272 .addRule(
273 "rcfaces-config/clientValidators/render-kit/clientValidator/processor",
274 new Rule() {
275 private static final String REVISION = "$Revision: 1.18 $";
276
277 public void begin(String namespace, String name,
278 Attributes attributes) throws Exception {
279 ClientValidator clientValidator = (ClientValidator) getDigester()
280 .peek();
281
282 clientValidator
283 .setProcessor(new TaskDescriptor(
284 attributes));
285 }
286 });
287 digester
288 .addRule(
289 "rcfaces-config/clientValidators/render-kit/clientValidator/required-class",
290 new Rule() {
291 private static final String REVISION = "$Revision: 1.18 $";
292
293 public void begin(String namespace, String name,
294 Attributes attributes) throws Exception {
295 ClientValidator clientValidator = (ClientValidator) getDigester()
296 .peek();
297
298 String className = attributes.getValue("name");
299 if (className == null) {
300 throw new IllegalStateException(
301 "Name attribute is not defined for required-class element.");
302 }
303
304 clientValidator.addRequiredClass(className);
305 }
306 });
307
308 digester
309 .addSetProperties(
310 "rcfaces-config/clientValidators/render-kit/clientValidator/converter",
311 "object", "converter");
312
313 digester
314 .addObjectCreate(
315 "rcfaces-config/clientValidators/render-kit/clientValidator/parameter",
316 Parameter.class);
317 digester
318 .addSetProperties(
319 "rcfaces-config/clientValidators/render-kit/clientValidator/parameter",
320 "name", "name");
321 digester
322 .addSetProperties(
323 "rcfaces-config/clientValidators/render-kit/clientValidator/parameter",
324 "value", "value");
325 digester
326 .addSetNext(
327 "rcfaces-config/clientValidators/render-kit/clientValidator/parameter",
328 "addParameter");
329
330 digester
331 .addObjectCreate(
332 "rcfaces-config/clientValidators/render-kit/clientValidator/server-converter",
333 ServerConverter.class);
334 digester
335 .addSetProperties(
336 "rcfaces-config/clientValidators/render-kit/clientValidator/server-converter",
337 "id", "id");
338 digester
339 .addSetProperties(
340 "rcfaces-config/clientValidators/render-kit/clientValidator/server-converter",
341 "class", "className");
342
343 digester
344 .addObjectCreate(
345 "rcfaces-config/clientValidators/render-kit/clientValidator/server-converter/parameter",
346 Parameter.class);
347 digester
348 .addSetProperties(
349 "rcfaces-config/clientValidators/render-kit/clientValidator/server-converter/parameter",
350 "name", "name");
351 digester
352 .addSetProperties(
353 "rcfaces-config/clientValidators/render-kit/clientValidator/server-converter/parameter",
354 "value", "value");
355 digester
356 .addSetNext(
357 "rcfaces-config/clientValidators/render-kit/clientValidator/server-converter/parameter",
358 "addParameter");
359
360 digester
361 .addSetNext(
362 "rcfaces-config/clientValidators/render-kit/clientValidator/server-converter",
363 "setServerConverter");
364
365 digester.addSetNext(
366 "rcfaces-config/clientValidators/render-kit/clientValidator",
367 "addclientValidator");
368
369 }
370
371 protected AbstractRenderKitRegistryImpl.RenderKit createRenderKit() {
372 return new RenderKit();
373 }
374
375
376
377
378
379
380 public static class RenderKit extends
381 AbstractRenderKitRegistryImpl.RenderKit {
382 private static final String REVISION = "$Revision: 1.18 $";
383
384 private final Map clientValidatorsById = new HashMap(128);
385
386 private final Map stringAdaptersById = new HashMap(128);
387
388 public RenderKit() {
389 }
390
391
392
393
394
395
396
397
398
399
400
401
402 public final IClientValidatorDescriptor getValidatorById(
403 String validatorId, Locale locale, TimeZone timeZone) {
404
405 StringAppender sa = new StringAppender(validatorId, 24);
406 if (locale != null) {
407 sa.append('$');
408 sa.append(locale.toString());
409
410 if (timeZone != null) {
411 sa.append('$');
412 sa.append(timeZone.toString());
413 }
414
415 IClientValidatorDescriptor clientValidatorDescriptor = (IClientValidatorDescriptor) clientValidatorsById
416 .get(sa.toString());
417 if (clientValidatorDescriptor != null) {
418 return clientValidatorDescriptor;
419 }
420
421 sa.setLength(0);
422 sa.append(validatorId);
423
424 if (timeZone != null) {
425 sa.append('$');
426 sa.append(locale.toString());
427
428 clientValidatorDescriptor = (IClientValidatorDescriptor) clientValidatorsById
429 .get(sa.toString());
430 if (clientValidatorDescriptor != null) {
431 return clientValidatorDescriptor;
432 }
433
434 sa.setLength(0);
435 sa.append(validatorId);
436 }
437 } else if (timeZone != null) {
438 sa.append('$');
439 sa.append(timeZone.toString());
440
441 IClientValidatorDescriptor clientValidatorDescriptor = (IClientValidatorDescriptor) clientValidatorsById
442 .get(sa.toString());
443 if (clientValidatorDescriptor != null) {
444 return clientValidatorDescriptor;
445 }
446
447 sa.setLength(0);
448 sa.append(validatorId);
449 }
450
451 IClientValidatorDescriptor clientValidatorDescriptor = (IClientValidatorDescriptor) clientValidatorsById
452 .get(sa.toString());
453 return clientValidatorDescriptor;
454 }
455
456 public final void addclientValidator(ClientValidator validator) {
457 validator.commitParameters();
458
459 LOG.trace("addclientValidator(" + validator.getId() + ", "
460 + validator + ")");
461
462 clientValidatorsById.put(validator.getId(), validator);
463 }
464 }
465
466
467
468
469
470
471 public static class ClientValidator extends ParametersContainer implements
472 IClientValidatorDescriptor {
473 private static final String REVISION = "$Revision: 1.18 $";
474
475 private String id;
476
477 private List requiredClassesList;
478
479 private String requiredClasses[] = STRING_EMPTY_ARRAY;
480
481 private ITaskDescriptor filter;
482
483 private ITaskDescriptor translator;
484
485 private ITaskDescriptor checker;
486
487 private ITaskDescriptor formatter;
488
489 private ITaskDescriptor behavior;
490
491 private ITaskDescriptor processor;
492
493 private ITaskDescriptor onerror;
494
495 private ITaskDescriptor oncheckerror;
496
497 private String converter;
498
499 private IServerConverter serverConverter;
500
501 public final ITaskDescriptor getBehaviorTask() {
502 return behavior;
503 }
504
505 public void addRequiredClass(String className) {
506 if (requiredClassesList == null) {
507 requiredClassesList = new ArrayList();
508 }
509
510 requiredClassesList.add(className);
511 }
512
513 public final ITaskDescriptor getCheckerTask() {
514 return checker;
515 }
516
517 public final ITaskDescriptor getFilterTask() {
518 return filter;
519 }
520
521 public final ITaskDescriptor getFormatterTask() {
522 return formatter;
523 }
524
525 public final ITaskDescriptor getOnCheckErrorTask() {
526 return oncheckerror;
527 }
528
529 public final ITaskDescriptor getOnErrorTask() {
530 return onerror;
531 }
532
533 public final String[] listRequiredClasses() {
534 return requiredClasses;
535 }
536
537 public final ITaskDescriptor getTranslatorTask() {
538 return translator;
539 }
540
541 public ITaskDescriptor getProcessorTask() {
542 return processor;
543 }
544
545 public void setProcessor(ITaskDescriptor processor) {
546 this.processor = processor;
547 }
548
549 public final void setBehavior(ITaskDescriptor behavior) {
550 this.behavior = behavior;
551 }
552
553 public final void setChecker(ITaskDescriptor checker) {
554 this.checker = checker;
555 }
556
557 public final void setFilter(ITaskDescriptor filter) {
558 this.filter = filter;
559 }
560
561 public final void setFormatter(ITaskDescriptor formatter) {
562 this.formatter = formatter;
563 }
564
565 public final void setOncheckerror(ITaskDescriptor oncheckerror) {
566 this.oncheckerror = oncheckerror;
567 }
568
569 public final void setOnerror(ITaskDescriptor onerror) {
570 this.onerror = onerror;
571 }
572
573 public final void setRequiredClasses(String requiredClasses[]) {
574 this.requiredClasses = requiredClasses;
575 }
576
577 public final void setTranslator(ITaskDescriptor translator) {
578 this.translator = translator;
579 }
580
581 public final String getId() {
582 return id;
583 }
584
585 public final void setId(String id) {
586 this.id = id;
587 }
588
589 public final String getConverter() {
590 return converter;
591 }
592
593 public final void setConverter(String converter) {
594 this.converter = converter;
595 }
596
597 public final IServerConverter getServerConverter() {
598 return serverConverter;
599 }
600
601 public final void setServerConverter(ServerConverter serverConverter) {
602 serverConverter.commitParameters();
603
604 this.serverConverter = serverConverter;
605 }
606
607 public void prepare() {
608 if (requiredClassesList != null) {
609 requiredClasses = (String[]) requiredClassesList
610 .toArray(new String[requiredClassesList.size()]);
611 requiredClassesList = null;
612 }
613 }
614 }
615
616
617
618
619
620
621 public static class TaskDescriptor implements ITaskDescriptor {
622 private static final String REVISION = "$Revision: 1.18 $";
623
624 protected final String clientTaskExpression;
625
626 private final IClientValidatorTask clientValidatorTask;
627
628 public TaskDescriptor(Attributes attributes) {
629 clientTaskExpression = attributes.getValue("call");
630
631 String serverTaskClassName = attributes.getValue("class");
632
633 clientValidatorTask = computeClientValidatorTask(
634 serverTaskClassName, attributes);
635 }
636
637 protected IClientValidatorTask computeClientValidatorTask(
638 String serverTaskClassName, Attributes attributes) {
639
640 if (serverTaskClassName != null) {
641 LOG.debug("Instanciate filter '" + serverTaskClassName + "'.");
642
643 Class clazz;
644 try {
645 clazz = ClassLocator.load(serverTaskClassName, null,
646 FacesContext.getCurrentInstance());
647
648 } catch (Throwable th) {
649 LOG.error("Can not load client validator task class '"
650 + serverTaskClassName + "'.", th);
651
652 throw new FacesException(
653 "Can not initialize server filter.", th);
654 }
655
656 try {
657 return (IClientValidatorTask) clazz.newInstance();
658
659 } catch (Throwable th) {
660 LOG.error("Can not instanciate client validator task '"
661 + clazz + "'.", th);
662
663 throw new FacesException(
664 "Can not initialize server filter.", th);
665 }
666
667 }
668
669 return null;
670 }
671
672 public String getClientTaskExpression() {
673 return clientTaskExpression;
674 }
675
676 public String getClientTaskExpressionType() {
677 return null;
678 }
679
680 public IClientValidatorTask getServerTask() {
681 return clientValidatorTask;
682 }
683 }
684
685
686
687
688
689
690 public static class ParametersContainer {
691 private static final String REVISION = "$Revision: 1.18 $";
692
693 private IParameter[] parameters;
694
695 private List parametersList;
696
697 public IParameter[] listParameters() {
698 return parameters;
699 }
700
701 public void commitParameters() {
702 if (parametersList == null) {
703 parameters = PARAMETER_EMPTY_ARRAY;
704 return;
705 }
706
707 parameters = (IParameter[]) parametersList
708 .toArray(new IParameter[parametersList.size()]);
709 parametersList = null;
710 }
711
712 public void addParameter(Parameter parameter) {
713 if (parameters != null) {
714 throw new IllegalStateException();
715 }
716
717 if (parametersList == null) {
718 parametersList = new ArrayList(8);
719 }
720
721 parametersList.add(parameter);
722 }
723
724 }
725
726
727
728
729
730
731 public static class Parameter implements IParameter {
732 private static final String REVISION = "$Revision: 1.18 $";
733
734 private String name;
735
736 private String value;
737
738 public final String getName() {
739 return name;
740 }
741
742 public final void setName(String name) {
743 this.name = name;
744 }
745
746 public final String getValue() {
747 return value;
748 }
749
750 public final void setValue(String value) {
751 this.value = value;
752 }
753
754 }
755
756
757
758
759
760
761 public static class ServerConverter extends ParametersContainer implements
762 IServerConverter {
763 private String id;
764
765 private String className;
766
767 public final String getClassName() {
768 return className;
769 }
770
771 public final void setClassName(String className) {
772 this.className = className;
773 }
774
775 public final String getId() {
776 return id;
777 }
778
779 public final void setId(String id) {
780 this.id = id;
781 }
782
783 public Converter getInstance(FacesContext facesContext,
784 UIComponent component) {
785
786 Converter converter = null;
787
788 boolean setParameters = false;
789
790 String id = getId();
791 if (id != null && id.length() > 0) {
792 Application application = facesContext.getApplication();
793
794 if (BindingTools.isBindingExpression(id)) {
795 converter = (Converter) BindingTools.evalBinding(
796 facesContext, id, Converter.class);
797
798 } else {
799 converter = application.createConverter(id);
800
801 setParameters = true;
802 }
803 }
804
805 if (converter == null) {
806 String className = getClassName();
807 if (className != null) {
808 try {
809 Class clazz = ClassLocator.load(className, null,
810 facesContext);
811 converter = (Converter) clazz.newInstance();
812
813 setParameters = true;
814
815 } catch (Throwable th) {
816 LOG.error("Can not instanciate converter class='"
817 + className + "'.", th);
818
819 throw new FacesException(th);
820 }
821 }
822 }
823
824 if (converter == null) {
825 return converter;
826 }
827
828 IParameter parameters[] = listParameters();
829
830 if (setParameters == false) {
831 if (parameters.length > 1) {
832 throw new FacesException(
833 "Can not set parameters to a 'value binding' Converter.");
834 }
835 return converter;
836 }
837
838 BeanInfo beanInfo;
839 try {
840 beanInfo = Introspector.getBeanInfo(converter.getClass());
841
842 } catch (IntrospectionException e) {
843 throw new FacesException(
844 "Can not introspect bean from validator id='" + getId()
845 + "' className='" + getClassName() + "'.", e);
846 }
847
848 Map listProperties = propertyDescriptorsByName(beanInfo);
849
850 IParametredConverter parametredConverter = null;
851
852 for (int i = 0; i < parameters.length; i++) {
853 IParameter parameter = parameters[i];
854
855 String name = parameter.getName();
856
857 PropertyDescriptor propertyDescriptor = (PropertyDescriptor) listProperties
858 .get(name);
859
860 if (propertyDescriptor != null) {
861 Class propertyType = propertyDescriptor.getPropertyType();
862
863 Object value = Convertor.convert(parameter.getValue(),
864 propertyType);
865
866 if (LOG.isDebugEnabled()) {
867 LOG.debug("Set parameter '" + name
868 + "', converted value='" + value
869 + "' to converter " + converter
870 + " [IParametredConverter method]");
871 }
872
873 try {
874 propertyDescriptor.getWriteMethod().invoke(converter,
875 new Object[] { value });
876
877 } catch (Throwable th) {
878 LOG.error("Can not set property '" + name
879 + "' converted value='" + value
880 + "' to converter " + converter, th);
881 }
882
883 continue;
884 }
885
886 if (parametredConverter != null) {
887 if (LOG.isDebugEnabled()) {
888 LOG.debug("Set parameter '" + name + "' value='"
889 + parameter.getValue() + "' to converter "
890 + converter + " [IParametredConverter method]");
891 }
892
893 try {
894 parametredConverter.setParameter(name, parameter
895 .getValue());
896
897 } catch (Throwable th) {
898 LOG.error("Can not set parameter '" + name + "' to "
899 + parameter.getValue(), th);
900 }
901 continue;
902 }
903
904 if (LOG.isDebugEnabled()) {
905 LOG.debug("Can not set parameter '" + name + "' ("
906 + parameter.getValue() + ") to converter "
907 + converter);
908 }
909 }
910
911 return converter;
912 }
913
914 private Map propertyDescriptorsByName(BeanInfo beanInfo) {
915
916 PropertyDescriptor propertyDescriptors[] = beanInfo
917 .getPropertyDescriptors();
918
919 Map map = new HashMap(propertyDescriptors.length);
920
921 for (int j = 0; j < propertyDescriptors.length; j++) {
922 PropertyDescriptor p = propertyDescriptors[j];
923
924 map.put(p.getName(), p);
925 }
926
927 return map;
928 }
929 }
930
931 public String convertFromValidatorToExpression(
932 IRenderContext renderContext, Validator validator) {
933
934 if (validator instanceof LongRangeValidator) {
935 return getLongRangeValidatorExpression(renderContext,
936 (LongRangeValidator) validator);
937 }
938
939 if (validator instanceof DoubleRangeValidator) {
940 return getDoubleRangeValidatorExpression(renderContext,
941 (DoubleRangeValidator) validator);
942 }
943
944 if (validator instanceof LengthValidator) {
945 return getLengthValidatorExpression(renderContext,
946 (LengthValidator) validator);
947 }
948
949 return null;
950 }
951
952 private String getLengthValidatorExpression(IRenderContext renderContext,
953 LengthValidator validator) {
954 StringAppender sa = new StringAppender(64);
955
956 return convertValidatorExpression(renderContext, "f_validator",
957 "LengthValidator", sa.toString());
958 }
959
960 private String getDoubleRangeValidatorExpression(
961 IRenderContext renderContext, DoubleRangeValidator validator) {
962 StringAppender sa = new StringAppender(64);
963
964 return convertValidatorExpression(renderContext, "f_validator",
965 "DoubleRangeValidator", sa.toString());
966 }
967
968 private String getLongRangeValidatorExpression(
969 IRenderContext renderContext, LongRangeValidator validator) {
970 StringAppender sa = new StringAppender(64);
971
972 return convertValidatorExpression(renderContext, "f_validator",
973 "LongRangeValidator", sa.toString());
974 }
975
976 private String convertValidatorExpression(IRenderContext renderContext,
977 String clazz, String method, String params) {
978
979 IScriptRenderContext scriptRenderContext = renderContext
980 .getScriptRenderContext();
981
982 StringAppender sa = new StringAppender(clazz.length() + 1
983 + method.length() + params.length());
984
985 if (clazz != null) {
986 if (scriptRenderContext != null) {
987 clazz = scriptRenderContext.convertSymbol(null, clazz);
988 }
989
990 sa.append(clazz);
991 sa.append('.');
992 }
993
994 if (scriptRenderContext != null) {
995 method = scriptRenderContext.convertSymbol(clazz, method);
996 }
997 sa.append(method);
998
999 sa.append('(');
1000 sa.append(params);
1001 sa.append(')');
1002
1003 return sa.toString();
1004 }
1005 }