protected Bucket( BucketId id, Document bucketDoc, DocumentTranslator translator ) { assert id != null; assert bucketDoc != null; this.id = id; this.nameFactory = translator.getNameFactory(); this.stringValueFactory = translator.getStringFactory(); if (bucketDoc.isEmpty()) { this.childNamesByKey = Collections.emptyMap(); this.childKeysByName = Collections.emptyMap(); } else { int size = bucketDoc.size(); this.childNamesByKey = new LinkedHashMap<>(size); this.childKeysByName = new HashMap<>(size); for (Map.Entry<String, ?> entry : bucketDoc.toMap().entrySet()) { NodeKey nodeKey = new NodeKey(entry.getKey()); String name = entry.getValue().toString(); childNamesByKey.put(nodeKey, name); childKeysByName.put(name, nodeKey); } } }
protected Bucket( BucketId id, Document bucketDoc, DocumentTranslator translator ) { assert id != null; assert bucketDoc != null; this.id = id; this.nameFactory = translator.getNameFactory(); this.stringValueFactory = translator.getStringFactory(); if (bucketDoc.isEmpty()) { this.childNamesByKey = Collections.emptyMap(); this.childKeysByName = Collections.emptyMap(); } else { int size = bucketDoc.size(); this.childNamesByKey = new LinkedHashMap<>(size); this.childKeysByName = new HashMap<>(size); for (Map.Entry<String, ?> entry : bucketDoc.toMap().entrySet()) { NodeKey nodeKey = new NodeKey(entry.getKey()); String name = entry.getValue().toString(); childNamesByKey.put(nodeKey, name); childKeysByName.put(name, nodeKey); } } }
@Override protected void write(Document bson, Writer writer) throws IOException { if (bson.size() == 0) { writer.append("{ }"); return; } ++depth; writer.append('{').append('\n'); indent(writer); Iterator<Field> iter = bson.fields().iterator(); if (iter.hasNext()) { write(iter.next(), writer); while (iter.hasNext()) { writer.append(',').append('\n'); indent(writer); write(iter.next(), writer); } } writer.append('\n'); --depth; indent(writer); writer.append('}'); }
@Override protected void write(Document bson, Writer writer) throws IOException { if (bson.size() == 0) { writer.append("{ }"); return; } ++depth; writer.append('{').append('\n'); indent(writer); Iterator<Field> iter = bson.fields().iterator(); if (iter.hasNext()) { write(iter.next(), writer); while (iter.hasNext()) { writer.append(',').append('\n'); indent(writer); write(iter.next(), writer); } } writer.append('\n'); --depth; indent(writer); writer.append('}'); }
/** * Get the configuration information for the anonymous authentication provider. * * @return the anonymous provider configuration information; null if anonymous users are not allowed */ public AnonymousSecurity getAnonymous() { Document anonymous = security.getDocument(FieldName.ANONYMOUS); if (anonymous != null && anonymous.size() == 1) { // Check the 'roleNames' field ... List<?> roles = anonymous.getArray(FieldName.ANONYMOUS_ROLES); if (roles != null && roles.isEmpty()) { // Specified empty roles, so this is disabling anonymous logins ... return null; } } if (anonymous == null) anonymous = Schematic.newDocument(); return new AnonymousSecurity(anonymous); }
/** * Get the configuration information for the anonymous authentication provider. * * @return the anonymous provider configuration information; null if anonymous users are not allowed */ public AnonymousSecurity getAnonymous() { Document anonymous = security.getDocument(FieldName.ANONYMOUS); if (anonymous != null && anonymous.size() == 1) { // Check the 'roleNames' field ... List<?> roles = anonymous.getArray(FieldName.ANONYMOUS_ROLES); if (roles != null && roles.isEmpty()) { // Specified empty roles, so this is disabling anonymous logins ... return null; } } if (anonymous == null) anonymous = Schematic.newDocument(); return new AnonymousSecurity(anonymous); }
if (value instanceof List<?>) return (List<?>)value; Document doc = (Document)value; BasicArray array = new BasicArray(doc.size()); final Iterator<String> indexIter = IndexSequence.infiniteSequence(); for (Document.Field field : doc.fields()) {
if (value instanceof List<?>) return (List<?>)value; Document doc = (Document)value; BasicArray array = new BasicArray(doc.size()); final Iterator<String> indexIter = IndexSequence.infiniteSequence(); for (Document.Field field : doc.fields()) {
if (this.size() != that.size()) { return false;
if (this.size() != that.size()) { return false;
protected void addValidatorsForPatternProperties( Document parent, Path parentPath, Problems problems, CompositeValidator validators ) { Document properties = parent.getDocument("patternProperties"); if (properties != null && properties.size() != 0) { for (Field field : properties.fields()) { String name = field.getName(); Object value = field.getValue(); Path path = Paths.path(parentPath, "patternProperties", name); if (!(value instanceof Document)) { problems.recordError(path, "Expected a nested object"); } Document propertySchema = (Document)value; try { Pattern namePattern = Pattern.compile(name); Validator propertyValidator = create(propertySchema, path); if (propertyValidator != null) { validators.add(new PatternPropertyValidator(namePattern, propertyValidator)); } } catch (PatternSyntaxException e) { problems.recordError(path, "Expected the field name to be a regular expression"); } } } }
protected void addValidatorsForPatternProperties( Document parent, Path parentPath, Problems problems, CompositeValidator validators ) { Document properties = parent.getDocument("patternProperties"); if (properties != null && properties.size() != 0) { for (Field field : properties.fields()) { String name = field.getName(); Object value = field.getValue(); Path path = Paths.path(parentPath, "patternProperties", name); if (!(value instanceof Document)) { problems.recordError(path, "Expected a nested object"); } Document propertySchema = (Document)value; try { Pattern namePattern = Pattern.compile(name); Validator propertyValidator = create(propertySchema, path); if (propertyValidator != null) { validators.add(new PatternPropertyValidator(namePattern, propertyValidator)); } } catch (PatternSyntaxException e) { problems.recordError(path, "Expected the field name to be a regular expression"); } } } }
protected void assertMatch( Document doc1, Document doc2 ) { assertEquals(doc1.size(), doc2.size()); for (Document.Field field1 : doc1.fields()) { if (field1.getValue() instanceof Document) { assertMatch(field1.getValueAsDocument(), doc2.getDocument(field1.getName())); } else { Object value2 = doc2.get(field1.getName()); assertEquals(field1.getValue(), value2); } } }
if (doc == null) return null; Object value = null; int numFields = doc.size(); if (numFields == 0) return doc; try {
if (doc == null) return null; Object value = null; int numFields = doc.size(); if (numFields == 0) return doc; try {
Document properties = parent.getDocument("properties"); Set<String> propertiesWithSchemas = new HashSet<>(); if (properties != null && properties.size() != 0) { for (Field field : properties.fields()) { String name = field.getName();
Document properties = parent.getDocument("properties"); Set<String> propertiesWithSchemas = new HashSet<>(); if (properties != null && properties.size() != 0) { for (Field field : properties.fields()) { String name = field.getName();