Beispiel #1
0
        protected internal virtual bool doValidate(object submittedValue, FormFieldValidatorContext validatorContext)
        {
            FormFieldValidator validator;

            if (!string.ReferenceEquals(clazz, null))
            {
                // resolve validator using Fully Qualified Classname
                object validatorObject = ReflectUtil.instantiate(clazz);
                if (validatorObject is FormFieldValidator)
                {
                    validator = (FormFieldValidator)validatorObject;
                }
                else
                {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                    throw new ProcessEngineException("Validator class '" + clazz + "' is not an instance of " + typeof(FormFieldValidator).FullName);
                }
            }
            else
            {
                //resolve validator using expression
                object validatorObject = delegateExpression.getValue(validatorContext.Execution);
                if (validatorObject is FormFieldValidator)
                {
                    validator = (FormFieldValidator)validatorObject;
                }
                else
                {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                    throw new ProcessEngineException("Validator expression '" + delegateExpression + "' does not resolve to instance of " + typeof(FormFieldValidator).FullName);
                }
            }

            FormFieldValidatorInvocation invocation = new FormFieldValidatorInvocation(validator, submittedValue, validatorContext);

            try
            {
                Context.ProcessEngineConfiguration.DelegateInterceptor.handleInvocation(invocation);
            }
            catch (Exception e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new ProcessEngineException(e);
            }

            return(invocation.InvocationResult.Value);
        }
Beispiel #2
0
        public virtual bool validate(object submittedValue, FormFieldValidatorContext validatorContext)
        {
            if (submittedValue == null)
            {
                return(NullValid);
            }

            string configuration = validatorContext.Configuration;

            if (submittedValue is string)
            {
                return(validate((string)submittedValue, configuration));
            }

            throw new ProcessEngineException("String validator " + this.GetType().Name + " cannot be used on non-string value of type " + submittedValue.GetType());
        }
Beispiel #3
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: @Override public boolean validate(final Object submittedValue, final FormFieldValidatorContext validatorContext)
        public virtual bool validate(object submittedValue, FormFieldValidatorContext validatorContext)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.engine.delegate.DelegateExecution execution = validatorContext.getExecution();
            DelegateExecution execution = validatorContext.Execution;

            if (shouldPerformPaContextSwitch(validatorContext.Execution))
            {
                ProcessApplicationReference processApplicationReference = ProcessApplicationContextUtil.getTargetProcessApplication((ExecutionEntity)execution);

                return(Context.executeWithinProcessApplication(new CallableAnonymousInnerClass(this, submittedValue, validatorContext)
                                                               , processApplicationReference, new InvocationContext(execution)));
            }
            else
            {
                return(doValidate(submittedValue, validatorContext));
            }
        }
Beispiel #4
0
        public virtual bool validate(object submittedValue, FormFieldValidatorContext validatorContext)
        {
            if (submittedValue == null)
            {
                return(true);
            }

            if (submittedValue.Equals("A") || submittedValue.Equals("B"))
            {
                return(true);
            }

            if (submittedValue.Equals("C"))
            {
                // instead of returning false, use an exception to specify details about
                // what went wrong
                throw new FormFieldValidationException("EXPIRED", "Unable to validate " + submittedValue);
            }

            // return false in the generic case
            return(false);
        }
Beispiel #5
0
 public virtual bool validate(object submittedValue, FormFieldValidatorContext validatorContext)
 {
     // no value was submitted
     return(submittedValue == null);
 }
Beispiel #6
0
        public virtual bool validate(object submittedValue, FormFieldValidatorContext validatorContext)
        {
            if (submittedValue == null)
            {
                return(NullValid);
            }

            string configurationString = validatorContext.Configuration;

            // Double

            if (submittedValue is double?)
            {
                double?configuration = null;
                try
                {
                    configuration = double.Parse(configurationString);
                }
                catch (System.FormatException)
                {
                    throw new FormFieldConfigurationException(configurationString, "Cannot validate Double value " + submittedValue + ": configuration " + configurationString + " cannot be parsed as Double.");
                }
                return(validate((double?)submittedValue, configuration));
            }

            // Float

            if (submittedValue is float?)
            {
                float?configuration = null;
                try
                {
                    configuration = float.Parse(configurationString);
                }
                catch (System.FormatException)
                {
                    throw new FormFieldConfigurationException(configurationString, "Cannot validate Float value " + submittedValue + ": configuration " + configurationString + " cannot be parsed as Float.");
                }
                return(validate((float?)submittedValue, configuration));
            }

            // Long

            if (submittedValue is long?)
            {
                long?configuration = null;
                try
                {
                    configuration = long.Parse(configurationString);
                }
                catch (System.FormatException)
                {
                    throw new FormFieldConfigurationException(configurationString, "Cannot validate Long value " + submittedValue + ": configuration " + configurationString + " cannot be parsed as Long.");
                }
                return(validate((long?)submittedValue, configuration));
            }

            // Integer

            if (submittedValue is int?)
            {
                int?configuration = null;
                try
                {
                    configuration = int.Parse(configurationString);
                }
                catch (System.FormatException)
                {
                    throw new FormFieldConfigurationException(configurationString, "Cannot validate Integer value " + submittedValue + ": configuration " + configurationString + " cannot be parsed as Integer.");
                }
                return(validate((int?)submittedValue, configuration));
            }

            // Short

            if (submittedValue is short?)
            {
                short?configuration = null;
                try
                {
                    configuration = short.Parse(configurationString);
                }
                catch (System.FormatException)
                {
                    throw new FormFieldConfigurationException(configurationString, "Cannot validate Short value " + submittedValue + ": configuration " + configurationString + " cannot be parsed as Short.");
                }
                return(validate((short?)submittedValue, configuration));
            }

            throw new FormFieldValidationException("Numeric validator " + this.GetType().Name + " cannot be used on non-numeric value " + submittedValue);
        }
Beispiel #7
0
 public FormFieldValidatorInvocation(FormFieldValidator formFieldValidator, object submittedValue, FormFieldValidatorContext validatorContext) : base(null, null)
 {
     this.formFieldValidator = formFieldValidator;
     this.submittedValue     = submittedValue;
     this.validatorContext   = validatorContext;
 }