1 package com.mongodb.internal.validator;
\r 
   3 //copy from https://github.com/mongodb/mongo-java-driver/blob/master/driver-core/src/main/com/mongodb/internal/validator/CollectibleDocumentFieldNameValidator.java
\r 
   4 //allow inserting name with dot
\r 
   6 * ============LICENSE_START=======================================================
\r 
   8 * ================================================================================
\r 
   9 * Copyright 2018 China Mobile
\r 
  10 *=================================================================================
\r 
  11 * Licensed under the Apache License, Version 2.0 (the "License");
\r 
  12 * you may not use this file except in compliance with the License.
\r 
  13 * You may obtain a copy of the License at
\r 
  15 *     http://www.apache.org/licenses/LICENSE-2.0
\r 
  17 * Unless required by applicable law or agreed to in writing, software
\r 
  18 * distributed under the License is distributed on an "AS IS" BASIS,
\r 
  19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r 
  20 * See the License for the specific language governing permissions and
\r 
  21 * limitations under the License.
\r 
  22 * ============LICENSE_END=========================================================
\r 
  24 import org.bson.FieldNameValidator;
\r 
  26 import java.util.Arrays;
\r 
  27 import java.util.List;
\r 
  30  * A field name validator for document that are meant for storage in MongoDB collections.  It ensures that no fields contain a '.',
\r 
  31  * or start with '$' (with the exception of "$db", "$ref", and "$id", so that DBRefs are not rejected).
\r 
  33  * <p>This class should not be considered a part of the public API.</p>
\r 
  35 public class CollectibleDocumentFieldNameValidator implements FieldNameValidator {
\r 
  36     // Have to support DBRef fields
\r 
  37     private static final List<String> EXCEPTIONS = Arrays.asList("$db", "$ref", "$id");
\r 
  40     public boolean validate(final String fieldName) {
\r 
  41         if (fieldName == null) {
\r 
  42             throw new IllegalArgumentException("Field name can not be null");
\r 
  46         if (fieldName.contains(".")) {
\r 
  50         if (fieldName.startsWith("$") && !EXCEPTIONS.contains(fieldName)) {
\r 
  57     public FieldNameValidator getValidatorForField(final String fieldName) {
\r