@Override public BsonMinKey encode(MinKey object) { return new BsonMinKey(); }
public static boolean checkType(Optional<BsonValue> o, String type) { if (!o.isPresent() && !"null".equals(type) && !"notnull".equals(type)) { return false; } switch (type.toLowerCase().trim()) { case "null": return !o.isPresent(); case "notnull": return o.isPresent(); case "object": return o.get().isDocument(); case "array": return o.get().isArray(); case "string": return o.get().isString(); case "number": return o.get().isNumber(); case "boolean": return o.get().isBoolean(); case "objectid": return o.get().isObjectId(); case "objectidstring": return o.get().isString() && ObjectId.isValid(o.get().asString().getValue()); case "date": return o.get().isDateTime(); case "timestamp": return o.get().isTimestamp(); case "maxkey": return o.get() instanceof BsonMaxKey; case "minkey": return o.get() instanceof BsonMinKey; case "symbol": return o.get().isSymbol(); case "code": return o.get() instanceof BsonJavaScript; default: return false; } }
/** * Gets the id as object from its string representation in the document URI * NOTE: for POST the special string id are checked by * BodyInjectorHandler.checkSpecialStringId() * * @param id * @param type * @return * @throws UnsupportedDocumentIdException */ public static BsonValue getDocumentIdFromURI(String id, DOC_ID_TYPE type) throws UnsupportedDocumentIdException { if (id == null) { return null; } if (type == null) { type = DOC_ID_TYPE.STRING_OID; } // MaxKey can be also determined from the _id if (RequestContext.MAX_KEY_ID.equalsIgnoreCase(id)) { return new BsonMaxKey(); } // MaxKey can be also determined from the _id if (RequestContext.MIN_KEY_ID.equalsIgnoreCase(id)) { return new BsonMinKey(); } // null can be also determined from the _id if (RequestContext.NULL_KEY_ID.equalsIgnoreCase(id)) { return new BsonNull(); } // true can be also determined from the _id if (RequestContext.TRUE_KEY_ID.equalsIgnoreCase(id)) { return new BsonBoolean(true); } // false can be also determined from the _id if (RequestContext.FALSE_KEY_ID.equalsIgnoreCase(id)) { return new BsonBoolean(false); } try { switch (type) { case STRING_OID: return getIdAsStringOrObjectId(id); case OID: return getIdAsObjectId(id); case STRING: return new BsonString(id); case NUMBER: return getIdAsNumber(id); case MINKEY: return new BsonMinKey(); case MAXKEY: return new BsonMaxKey(); case DATE: return getIdAsDate(id); case BOOLEAN: return getIdAsBoolean(id); } } catch (IllegalArgumentException iar) { throw new UnsupportedDocumentIdException(iar); } return new BsonString(id); }