Add field rules from either a Jpf.ValidationField or a Jpf.ValidationLocaleRules annotation.
415
private void addFieldRules( AnnotationInstance rulesContainerAnnotation, RuleInfo ruleInfo,
                                boolean applyToAllLocales )
    {
        //
        // First parse the locale from the wrapper annotation.  This will apply to all rules inside.
        //
        Locale locale = null;

        if ( ! applyToAllLocales )
        {
            String language = CompilerUtils.getString( rulesContainerAnnotation, LANGUAGE_ATTR, true );

            //
            // If there's no language specified, then this rule will only apply for the default ruleset
            // (i.e., if there are explicit rules for the requested locale, this rule will not be run).
            //
            if ( language != null )
            {
                String country = CompilerUtils.getString( rulesContainerAnnotation, COUNTRY_ATTR, true );
                String variant = CompilerUtils.getString( rulesContainerAnnotation, VARIANT_ATTR, true );

                language = language.trim();
                if ( country != null ) country = country.trim();
                if ( variant != null ) variant = variant.trim();

                if ( country != null && variant != null ) locale = new Locale( language, country, variant );
                else if ( country != null ) locale = new Locale( language, country );
                else locale = new Locale( language );
            }
        }

        Map valuesPresent = rulesContainerAnnotation.getElementValues();

        for ( Iterator ii = valuesPresent.entrySet().iterator(); ii.hasNext(); )
        {
            Map.Entry entry = ( Map.Entry ) ii.next();
            AnnotationValue value = ( AnnotationValue ) entry.getValue();
            Object val = value.getValue();

            if ( val instanceof AnnotationInstance )
            {
                addFieldRuleFromAnnotation( ruleInfo, ( AnnotationInstance ) val, locale, applyToAllLocales );
            }
            else if ( val instanceof List )
            {
                List annotations = CompilerUtils.getAnnotationArray( value );

                for ( Iterator i3 = annotations.iterator(); i3.hasNext(); )
                {
                    AnnotationInstance i = ( AnnotationInstance ) i3.next();
                    addFieldRuleFromAnnotation( ruleInfo, i, locale, applyToAllLocales );
                }
            }
        }

        setEmpty( false );  // this ValidationModel is only "empty" if there are no rules.
    }
578397
def _validate_annotation(self, annotation):
        ''''''
        required_keys = set(self._required_keys)
        keys = set(key for key, val in annotation.items() if val)
        missing_keys = required_keys.difference(keys)
        if missing_keys:
            error = 'Annotation missing required fields: {0}'.format(
                missing_keys)
            raise AnnotationError(error)
1281879
@Override
    public boolean validate(Field f) throws RuleValidationException
    {

        boolean checkvalidation = true;
        for (Annotation annotate : f.getDeclaredAnnotations())
        {
            RelationType eruleType = getRuleType(annotate.annotationType().getSimpleName());

            if (eruleType != null)
            {

                switch (eruleType)
                {
                case MANY_TO_MANY:
                    checkvalidation = validateManyToMany(f, annotate);
                    break;
                case MANY_TO_ONE:
                    checkvalidation = validateManyToOne(f, annotate);
                    break;
                case ONE_TO_MANY:
                    checkvalidation = validateOneToMany(f, annotate);
                    break;
                case ONE_TO_ONE:
                    checkvalidation = validateOneToOne(f, annotate);
                    break;

                }

            }
        }

        return checkvalidation;
    }
1098654
public AnnotatedTypeBuilder<X> addToField(AnnotatedField<? super X> field, Annotation annotation) {
       return addToField(field.getJavaMember(), annotation);
   }
1267685
def add_translation_field(self, field, translation_field):
        
        self.local_fields[field].add(translation_field)
        self.fields[field].add(translation_field)
717965
def add_single_rule(field, key_or_klass, params = nil)
      klass = if key_or_klass.respond_to?(:new)
        key_or_klass
      else
        get_rule_class_by_name(key_or_klass)
      end

      args = [params].compact
      rule = klass.new(*args)
      rule.obj = @obj if rule.respond_to?(:obj=)
      rules[field] << rule
    end
1027718
@Override
    public void validate() {

        if (entityClass == null) {
            throw new IllegalArgumentException("testentity class cannot be null");
        }

        if (!entityClass.isAnnotationPresent(DeepEntity.class)) {
            throw new AnnotationTypeMismatchException(null, entityClass.getCanonicalName());
        }

        super.validate();

        /* let's validate fieldNames in @DeepField annotations */
        Field[] deepFields = AnnotationUtils.filterDeepFields(entityClass);

        Map<String, Cell> colDefs = super.columnDefinitions();

        /* colDefs is null if table does not exist. I.E. this configuration will be used as an output configuration
         object, and the output table is dynamically created */
        if (colDefs == null) {
            return;
        }

        for (Field field : deepFields) {
            String annotationFieldName = AnnotationUtils.deepFieldName(field);

            if (!colDefs.containsKey(annotationFieldName)) {
                throw new DeepNoSuchFieldException("Unknown column name \'" + annotationFieldName + "\' specified for" +
                        " field " + entityClass.getCanonicalName() + "#" + field.getName() + ". Please, " +
                        "make sure the field name you specify in @DeepField annotation matches _exactly_ the column " +
                        "name " +
                        "in the database");
            }
        }
    }
1038023
def validate_field(field, allowed_keys, allowed_types):
    """"""
    for key, value in field.items():
        if key not in allowed_keys:
            raise exceptions.ParametersFieldError(key, "property")
        if key == defs.TYPE:
            if value not in allowed_types:
                raise exceptions.ParametersFieldError(value, key)
        if key == defs.VALUE:
            if not is_valid_field_name(value):
                raise exceptions.ParametersFieldError(value, "field name")
1014434
def add_translation_fields(model, opts):
    
    model_empty_values = getattr(opts, 'empty_values', NONE)
    for field_name in opts.local_fields.keys():
        field_empty_value = parse_field(model_empty_values, field_name, NONE)
        for l in mt_settings.AVAILABLE_LANGUAGES:
            # Create a dynamic translation field
            translation_field = create_translation_field(
                model=model, field_name=field_name, lang=l, empty_value=field_empty_value)
            # Construct the name for the localized field
            localized_field_name = build_localized_fieldname(field_name, l)
            # Check if the model already has a field by that name

            if hasattr(model, localized_field_name):
                # Check if are not dealing with abstract field inherited.
                for cls in model.__mro__:
                    if hasattr(cls, '_meta') and cls.__dict__.get(localized_field_name, None):
                        cls_opts = translator._get_options_for_model(cls)
                        if not cls._meta.abstract or field_name not in cls_opts.local_fields:
                            raise ValueError("Error adding translation field. Model '%s' already"
                                             " contains a field named '%s'." %
                                             (model._meta.object_name, localized_field_name))
            # This approach implements the translation fields as full valid
            # django model fields and therefore adds them via add_to_class
            model.add_to_class(localized_field_name, translation_field)
            opts.add_translation_field(field_name, translation_field)

    # Rebuild information about parents fields. If there are opts.local_fields, field cache would be
    # invalidated (by model._meta.add_field() function). Otherwise, we need to do it manually.
    if len(opts.local_fields) == 0:
        model._meta._expire_cache()
        model._meta.get_fields()
770352
def validateField(self, field) :
        """"""
        if field not in self.validators and not self.collection._validation['allow_foreign_fields'] :
            raise SchemaViolation(self.collection.__class__, field)

        if field in self.store:
            if isinstance(self.store[field], DocumentStore) :
                return self[field].validate()
            
            if field in self.patchStore :
                return self.validators[field].validate(self.patchStore[field])
            else :
                try :
                    return self.validators[field].validate(self.store[field])
                except ValidationError as e:
                    raise ValidationError( "'%s' -> %s" % ( field, str(e)) )
                except AttributeError:
                    if isinstance(self.validators[field], dict) and not isinstance(self.store[field], dict) :
                        raise ValueError("Validator expected a sub document for field '%s', got '%s' instead" % (field, self.store[field]) )
                    else :
                        raise
        return True
837632
private void validateFields(List<String> fields) {
        if (fields == null) {
            return;
        }
        List<String> badFields = new ArrayList<String>();
        for (String field: fields) {
            if (field.contains(".")) {
                badFields.add(field);
            }
        }

        if (!badFields.isEmpty()) {
            String msg = String.format("Projection field(s) cannot use dotted notation: %s",
                    Misc.join(", ", badFields));
            logger.log(Level.SEVERE, msg);
            throw new IllegalArgumentException(msg);
        }
    }
883277
public void checkLonelyValidatorAnnotation(Field field, Map<String, Class<?>> genericMap) {
        doCheckLonelyValidatorAnnotation(field, deriveFieldType(field, genericMap));
    }
767151
public AnnotatedTypeBuilder<X> addToField(Field field, Annotation annotation) {
       if (fields.get(field) == null) {
           fields.put(field, new AnnotationBuilder());
       }
       fields.get(field).add(annotation);
       return this;
   }
816965
private void annotateOptions(Properties properties) throws IOException {

    String ruleBasedOption = properties.getProperty("ruleBasedOption");
    String dictOption = properties.getProperty("dictTag");
    String dictPath = properties.getProperty("dictPath");

    if (!dictOption.equals(Flags.DEFAULT_DICT_OPTION)) {
      if (dictPath.equals(Flags.DEFAULT_DICT_PATH)) {
        Flags.dictionaryException();
      }
      if (!ruleBasedOption.equals(Flags.DEFAULT_LEXER)) {
        lexerTagger = true;
      }
      if (!dictPath.equals(Flags.DEFAULT_DICT_PATH)) {
        if (dictionaries == null) {
          dictionaries = new Dictionaries(dictPath);
          nerTaggerDict = new DictionariesNERTagger(dictionaries);
        }
        if (dictOption.equalsIgnoreCase("tag")) {
          dictTag = true;
          postProcess = false;
          statistical = false;
        } else if (dictOption.equalsIgnoreCase("post")) {
          nerTagger = new StatisticalSequenceLabeler(properties);
          statistical = true;
          postProcess = true;
          dictTag = false;
        } else {
          nerTagger = new StatisticalSequenceLabeler(properties);
          statistical = true;
          dictTag = false;
          postProcess = false;
        }
      }
    } else if (!ruleBasedOption.equals(Flags.DEFAULT_LEXER)) {
      lexerTagger = true;
      statistical = true;
      dictTag = false;
      postProcess = false;
      nerTagger = new StatisticalSequenceLabeler(properties);
    } else {
      lexerTagger = false;
      statistical = true;
      dictTag = false;
      postProcess = false;
      nerTagger = new StatisticalSequenceLabeler(properties);
    }
  }
1209197
protected function replaceFieldKeyPlaceholderInValidationRules(ModelFormFieldDataInterface $field, array $rules)
    {
        foreach ($rules as $rule) {

            // Prepare field prefix with locale placeholder if relevant
            $fieldPrefix = $field->key();

            if ($rule->isTranslated() && $rule->localeIndex() < 2) {
                $fieldPrefix .= '.' . $this->getLocalePlaceholder();
            }

            // For each rule, if it is a string, replace the field placeholder with this prefix
            $rule->setRules(
                array_map(function ($rule) use ($fieldPrefix) {

                    if ( ! is_string($rule)) {
                        return $rule;
                    }

                    return str_replace(static::FIELD_KEY_PLACEHOLDER, $fieldPrefix, $rule);

                }, $rule->rules())
            );
        }

        return $rules;
    }
118774
def formfield(self, **kwargs):
        """"""

        defaults = dict(
            form_class=LocalizedFieldForm,
            required=False if self.blank else self.required
        )
        defaults.update(kwargs)
        return super().formfield(**defaults)
1203149
public static TextFieldInfo create(@NotNull final Field field, @NotNull final Locale locale) {

        final TextField textField = field.getAnnotation(TextField.class);
        if (textField == null) {
            return null;
        }
        return new TextFieldInfo(field, textField.width());

    }