Java Code Examples for org.bson.BsonType#STRING

The following examples show how to use org.bson.BsonType#STRING . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnumCodec.java    From core-ng-project with Apache License 2.0 6 votes vote down vote up
public T read(BsonReader reader, String field) {
    BsonType currentType = reader.getCurrentBsonType();
    if (currentType == BsonType.NULL) {
        reader.readNull();
        return null;
    } else if (currentType == BsonType.STRING) {
        String enumValue = reader.readString();
        T value = decodingMappings.get(enumValue);
        if (value == null) throw new Error(format("can not decode value to enum, enumClass={}, value={}", enumClass.getCanonicalName(), enumValue));
        return value;
    } else {
        logger.warn("unexpected field type, field={}, type={}", field, currentType);
        reader.skipValue();
        return null;
    }
}
 
Example 2
Source File: AbstractJsonCodec.java    From vertx-mongo-client with Apache License 2.0 6 votes vote down vote up
protected BsonType getBsonType(Object value) {
  if (value == null) {
    return BsonType.NULL;
  } else if (value instanceof Boolean) {
    return BsonType.BOOLEAN;
  } else if (value instanceof Double) {
    return BsonType.DOUBLE;
  } else if (value instanceof Integer) {
    return BsonType.INT32;
  } else if (value instanceof Long) {
    return BsonType.INT64;
  } else if (value instanceof String) {
    return BsonType.STRING;
  } else if (isObjectIdInstance(value)) {
    return BsonType.OBJECT_ID;
  } else if (isObjectInstance(value)) {
    return BsonType.DOCUMENT;
  } else if (isArrayInstance(value)) {
    return BsonType.ARRAY;
  } else {
    return null;
  }
}
 
Example 3
Source File: BsonReaderWrapper.java    From core-ng-project with Apache License 2.0 5 votes vote down vote up
public String readString(String field) {
    BsonType currentType = reader.getCurrentBsonType();
    if (currentType == BsonType.NULL) {
        reader.readNull();
        return null;
    } else if (currentType == BsonType.STRING) {
        return reader.readString();
    } else {
        logger.warn("unexpected field type, field={}, type={}", field, currentType);
        reader.skipValue();
        return null;
    }
}
 
Example 4
Source File: MongoQueryService.java    From epcis with Apache License 2.0 5 votes vote down vote up
private boolean isExtensionFilterPassed(String type, BsonArray paramArray, BsonDocument ext, boolean isTopLevel) {
	type = MongoWriterUtil.encodeMongoObjectKey(type);
	Iterator<String> keyIterator = ext.keySet().iterator();
	while (keyIterator.hasNext()) {
		String key = keyIterator.next();
		BsonValue sub = ext.get(key);
		if (isTopLevel == false) {
			if (key.equals(type)) {
				for (int i = 0; i < paramArray.size(); i++) {
					BsonValue param = paramArray.get(i);
					if (sub.getBsonType() == param.getBsonType() && sub.toString().equals(param.toString())) {
						return true;
					}
					if (param.getBsonType() == BsonType.REGULAR_EXPRESSION
							&& sub.getBsonType() == BsonType.STRING) {
						if (Pattern.matches(param.asRegularExpression().getPattern(), sub.asString().getValue()))
							return true;
					}
				}
				return false;
			}
		}
		if (sub.getBsonType() == BsonType.DOCUMENT) {
			if (isExtensionFilterPassed(type, paramArray, sub.asDocument(), false) == true) {
				return true;
			}
		}
	}
	return false;
}
 
Example 5
Source File: MongoQueryService.java    From epcis with Apache License 2.0 5 votes vote down vote up
private boolean isExtensionFilterPassed(String type, BsonArray paramArray, BsonDocument ext, boolean isTopLevel) {
	type = MongoWriterUtil.encodeMongoObjectKey(type);
	Iterator<String> keyIterator = ext.keySet().iterator();
	while (keyIterator.hasNext()) {
		String key = keyIterator.next();
		BsonValue sub = ext.get(key);
		if (isTopLevel == false) {
			if (key.equals(type)) {
				for (int i = 0; i < paramArray.size(); i++) {
					BsonValue param = paramArray.get(i);
					if (sub.getBsonType() == param.getBsonType() && sub.toString().equals(param.toString())) {
						return true;
					}
					if (param.getBsonType() == BsonType.REGULAR_EXPRESSION
							&& sub.getBsonType() == BsonType.STRING) {
						if (Pattern.matches(param.asRegularExpression().getPattern(), sub.asString().getValue()))
							return true;
					}
				}
				return false;
			}
		}
		if (sub.getBsonType() == BsonType.DOCUMENT) {
			if (isExtensionFilterPassed(type, paramArray, sub.asDocument(), false) == true) {
				return true;
			}
		}
	}
	return false;
}
 
Example 6
Source File: BsonParser.java    From immutables with Apache License 2.0 5 votes vote down vote up
@Override
public String getText() throws IOException {
  final BsonType type = type();
  if (type == BsonType.SYMBOL) {
    return reader.readSymbol();
  }
  if (type == BsonType.STRING) {
    return reader.readString();
  }

  throw new IllegalStateException(String.format("Bad BSON type: %s expected String or Symbol", type));
}