Skip to content

Commit 9104f59

Browse files
committed
Renamed CodecSource to CodecProvider, and changed suffix for all implementations as well.
1 parent ae0368f commit 9104f59

16 files changed

Lines changed: 57 additions & 56 deletions

File tree

bson/src/main/org/bson/codecs/BsonArrayCodec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void encode(final BsonWriter writer, final BsonArray array) {
5858
writer.writeStartArray();
5959

6060
for (BsonValue value : array) {
61-
Codec codec = registry.get(BsonValueCodecSource.getClassForBsonType(value.getBsonType()));
61+
Codec codec = registry.get(BsonValueCodecProvider.getClassForBsonType(value.getBsonType()));
6262
codec.encode(writer, value);
6363
}
6464

@@ -78,7 +78,7 @@ public Class<BsonArray> getEncoderClass() {
7878
* @return the non-null value read from the reader
7979
*/
8080
protected BsonValue readValue(final BsonReader reader) {
81-
return registry.get(BsonValueCodecSource.getClassForBsonType(reader.getCurrentBsonType())).decode(reader);
81+
return registry.get(BsonValueCodecProvider.getClassForBsonType(reader.getCurrentBsonType())).decode(reader);
8282
}
8383

8484
}

bson/src/main/org/bson/codecs/BsonDocumentCodec.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import org.bson.BsonReader;
2020
import org.bson.BsonType;
2121
import org.bson.BsonWriter;
22+
import org.bson.codecs.configuration.CodecProvider;
2223
import org.bson.codecs.configuration.CodecRegistry;
23-
import org.bson.codecs.configuration.CodecSource;
2424
import org.bson.codecs.configuration.RootCodecRegistry;
2525
import org.bson.types.BsonDocument;
2626
import org.bson.types.BsonElement;
@@ -37,7 +37,7 @@
3737
* @since 3.0
3838
*/
3939
public class BsonDocumentCodec implements Codec<BsonDocument> {
40-
private static final CodecRegistry DEFAULT_REGISTRY = new RootCodecRegistry(Arrays.<CodecSource>asList(new BsonValueCodecSource()));
40+
private static final CodecRegistry DEFAULT_REGISTRY = new RootCodecRegistry(Arrays.<CodecProvider>asList(new BsonValueCodecProvider()));
4141

4242
private final CodecRegistry codecRegistry;
4343

@@ -84,7 +84,7 @@ public BsonDocument decode(final BsonReader reader) {
8484
* @return the non-null value read from the reader
8585
*/
8686
protected BsonValue readValue(final BsonReader reader) {
87-
return codecRegistry.get(BsonValueCodecSource.getClassForBsonType(reader.getCurrentBsonType())).decode(reader);
87+
return codecRegistry.get(BsonValueCodecProvider.getClassForBsonType(reader.getCurrentBsonType())).decode(reader);
8888
}
8989

9090
@Override
@@ -101,7 +101,7 @@ public void encode(final BsonWriter writer, final BsonDocument value) {
101101

102102
@SuppressWarnings({"unchecked", "rawtypes"})
103103
private void writeValue(final BsonWriter writer, final BsonValue value) {
104-
Codec codec = codecRegistry.get(BsonValueCodecSource.getClassForBsonType(value.getBsonType()));
104+
Codec codec = codecRegistry.get(BsonValueCodecProvider.getClassForBsonType(value.getBsonType()));
105105
codec.encode(writer, value);
106106
}
107107

bson/src/main/org/bson/codecs/BsonValueCodecSource.java renamed to bson/src/main/org/bson/codecs/BsonValueCodecProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package org.bson.codecs;
1818

1919
import org.bson.BsonType;
20+
import org.bson.codecs.configuration.CodecProvider;
2021
import org.bson.codecs.configuration.CodecRegistry;
21-
import org.bson.codecs.configuration.CodecSource;
2222
import org.bson.types.Binary;
2323
import org.bson.types.BsonArray;
2424
import org.bson.types.BsonBoolean;
@@ -47,19 +47,19 @@
4747
import java.util.Map;
4848

4949
/**
50-
* A CodecSource for all subclass of BsonValue.
50+
* A {@code CodecProvider} for all subclass of BsonValue.
5151
*
5252
* @since 3.0
5353
*/
54-
public class BsonValueCodecSource implements CodecSource {
54+
public class BsonValueCodecProvider implements CodecProvider {
5555
private static final Map<BsonType, Class<? extends BsonValue>> DEFAULT_BSON_TYPE_CLASS_MAP;
5656

5757
private final Map<Class<?>, Codec<?>> codecs = new HashMap<Class<?>, Codec<?>>();
5858

5959
/**
6060
* Construct a new instance with the default codec for each BSON type.
6161
*/
62-
public BsonValueCodecSource() {
62+
public BsonValueCodecProvider() {
6363
addCodecs();
6464
}
6565

bson/src/main/org/bson/codecs/configuration/CodecSource.java renamed to bson/src/main/org/bson/codecs/configuration/CodecProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
import org.bson.codecs.Codec;
2020

2121
/**
22-
* A source for {@code Codec} instances. Typically, an instance of a class implementing this interface would be used to construct a
22+
* A provider of {@code Codec} instances. Typically, an instance of a class implementing this interface would be used to construct a
2323
* {@code CodecRegistry}.
2424
*
2525
* @since 3.0
2626
*/
27-
public interface CodecSource {
27+
public interface CodecProvider {
2828

2929
/**
3030
* Get a {@code Codec} using the given context, which includes, most importantly, the Class for which a {@code Codec} is required.

bson/src/main/org/bson/codecs/configuration/RootCodecRegistry.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@
3434
public class RootCodecRegistry implements CodecRegistry {
3535

3636
private final ConcurrentMap<Class<?>, Codec<?>> codecs = new ConcurrentHashMap<Class<?>, Codec<?>>();
37-
private final List<CodecSource> sources;
37+
private final List<CodecProvider> sources;
3838

3939
/**
40-
* Construct a new {@code CodecRegistry} from the given list if {@code CodecSource} instances. The registry will use the codec sources
41-
* to find Codec instances, consulting each source in order, and return the first Codec found. Therefore,
42-
* care should be taken to order the codec sources to achieve the desired behavior.
40+
* Construct a new {@code CodecRegistry} from the given list if {@code CodecProvider} instances. The registry will use the codec
41+
* providers to find Codec instances, consulting each provider in order, and return the first Codec found. Therefore,
42+
* care should be taken to order the codec providers to achieve the desired behavior.
4343
*
44-
* @param codecSources the list of codec sources
44+
* @param codecProviders the list of codec providers
4545
*/
46-
public RootCodecRegistry(final List<CodecSource> codecSources) {
47-
this.sources = new ArrayList<CodecSource>(codecSources);
46+
public RootCodecRegistry(final List<CodecProvider> codecProviders) {
47+
this.sources = new ArrayList<CodecProvider>(codecProviders);
4848
}
4949

5050
/**
@@ -80,7 +80,7 @@ <T> Codec<T> get(final ChildCodecRegistry context) {
8080
}
8181

8282
private <T> Codec<T> getCodecFromSources(final ChildCodecRegistry<T> context) {
83-
for (CodecSource source : sources) {
83+
for (CodecProvider source : sources) {
8484
Codec<T> result = source.get(context.getCodecClass(), context);
8585
if (result != null) {
8686
return result;

bson/src/test/org/bson/codecs/configuration/CodecRegistrySpecification.groovy

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CodecRegistrySpecification extends Specification {
4646
def 'get should return registered codec'() {
4747
given:
4848
def minKeyCodec = new MinKeyCodec()
49-
def registry = new RootCodecRegistry([new SimpleCodecSource(minKeyCodec)])
49+
def registry = new RootCodecRegistry([new SimpleCodecProvider(minKeyCodec)])
5050

5151
expect:
5252
registry.get(MinKey) is minKeyCodec
@@ -56,15 +56,15 @@ class CodecRegistrySpecification extends Specification {
5656
given:
5757
def minKeyCodec1 = new MinKeyCodec()
5858
def minKeyCodec2 = new MinKeyCodec()
59-
def registry = new RootCodecRegistry([new SimpleCodecSource(minKeyCodec1), new SimpleCodecSource(minKeyCodec2)])
59+
def registry = new RootCodecRegistry([new SimpleCodecProvider(minKeyCodec1), new SimpleCodecProvider(minKeyCodec2)])
6060

6161
expect:
6262
registry.get(MinKey) is minKeyCodec1
6363
}
6464

6565
def 'should handle cycles'() {
6666
given:
67-
def registry = new RootCodecRegistry([new ClassModelCodecSource()])
67+
def registry = new RootCodecRegistry([new ClassModelCodecProvider()])
6868

6969
when:
7070
Codec<Top> topCodec = registry.get(Top)
@@ -88,7 +88,7 @@ class CodecRegistrySpecification extends Specification {
8888

8989
def 'should throw CodecConfigurationException when a codec requires another codec that can not be found'() {
9090
given:
91-
def registry = new RootCodecRegistry([new ClassModelCodecSource([Top])]);
91+
def registry = new RootCodecRegistry([new ClassModelCodecProvider([Top])]);
9292

9393
when:
9494
registry.get(Top)
@@ -98,11 +98,11 @@ class CodecRegistrySpecification extends Specification {
9898
}
9999
}
100100

101-
class SimpleCodecSource implements CodecSource {
101+
class SimpleCodecProvider implements CodecProvider {
102102

103103
private final Codec<?> codec
104104

105-
SimpleCodecSource(final Codec<?> codec) {
105+
SimpleCodecProvider(final Codec<?> codec) {
106106
this.codec = codec
107107
}
108108

@@ -116,15 +116,15 @@ class SimpleCodecSource implements CodecSource {
116116
}
117117
}
118118

119-
class ClassModelCodecSource implements CodecSource {
119+
class ClassModelCodecProvider implements CodecProvider {
120120

121121
private final List<Class<?>> supportedClasses
122122

123-
ClassModelCodecSource() {
123+
ClassModelCodecProvider() {
124124
this(asList(Top.class, Nested.class))
125125
}
126126

127-
ClassModelCodecSource(List<Class<?>> supportedClasses) {
127+
ClassModelCodecProvider(List<Class<?>> supportedClasses) {
128128
this.supportedClasses = supportedClasses
129129
}
130130

driver-compat/src/main/com/mongodb/DB.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public class DB {
8383
this.documentCodec = documentCodec;
8484
this.collectionCache = new ConcurrentHashMap<String, DBCollection>();
8585
this.optionHolder = new Bytes.OptionHolder(mongo.getOptionHolder());
86-
this.commandCodec = new DBObjectCodec(this, null, getMongo().getCodecRegistry(), DBObjectCodecSource.getDefaultBsonTypeClassMap());
86+
this.commandCodec = new DBObjectCodec(this, null, getMongo().getCodecRegistry(),
87+
DBObjectCodecProvider.getDefaultBsonTypeClassMap());
8788
}
8889

8990
/**

driver-compat/src/main/com/mongodb/DBCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,7 @@ <T> T execute(final ReadOperation<T> operation, final ReadPreference readPrefere
18281828

18291829
DBObjectCodec getDefaultDBObjectCodec() {
18301830
return new DBObjectCodec(getDB(), getObjectFactory(), getDB().getMongo().getCodecRegistry(),
1831-
DBObjectCodecSource.getDefaultBsonTypeClassMap());
1831+
DBObjectCodecProvider.getDefaultBsonTypeClassMap());
18321832
}
18331833

18341834
private Index toIndex(final DBObject keys, final DBObject options) {

driver-compat/src/main/com/mongodb/DBObjectCodecSource.java renamed to driver-compat/src/main/com/mongodb/DBObjectCodecProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import org.bson.codecs.ObjectIdCodec;
2727
import org.bson.codecs.RegularExpressionCodec;
2828
import org.bson.codecs.UndefinedCodec;
29+
import org.bson.codecs.configuration.CodecProvider;
2930
import org.bson.codecs.configuration.CodecRegistry;
30-
import org.bson.codecs.configuration.CodecSource;
3131
import org.bson.types.BSONTimestamp;
3232
import org.bson.types.Binary;
3333
import org.bson.types.Code;
@@ -54,7 +54,7 @@
5454
import java.util.Map;
5555
import java.util.regex.Pattern;
5656

57-
class DBObjectCodecSource implements CodecSource {
57+
class DBObjectCodecProvider implements CodecProvider {
5858
private static final Map<BsonType, Class<?>> bsonTypeClassMap = createDefaultBsonTypeClassMap();
5959

6060
private final Map<Class<?>, Codec<?>> codecs = new HashMap<Class<?>, Codec<?>>();
@@ -63,7 +63,7 @@ public static Map<BsonType, Class<?>> getDefaultBsonTypeClassMap() {
6363
return bsonTypeClassMap;
6464
}
6565

66-
public DBObjectCodecSource() {
66+
public DBObjectCodecProvider() {
6767
addCodecs();
6868
}
6969

driver-compat/src/main/com/mongodb/DBObjects.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
package com.mongodb;
1818

1919
import org.bson.BsonDocumentReader;
20-
import org.bson.codecs.configuration.CodecSource;
20+
import org.bson.codecs.configuration.CodecProvider;
2121
import org.bson.codecs.configuration.RootCodecRegistry;
2222
import org.bson.types.BsonDocument;
2323

2424
import java.util.Arrays;
2525

2626
final class DBObjects {
2727
private static final DBObjectCodec codec =
28-
new DBObjectCodec(null, new BasicDBObjectFactory(), new RootCodecRegistry(Arrays.<CodecSource>asList(new DBObjectCodecSource())),
29-
DBObjectCodecSource.createDefaultBsonTypeClassMap());
28+
new DBObjectCodec(null, new BasicDBObjectFactory(), new RootCodecRegistry(Arrays.<CodecProvider>asList(new DBObjectCodecProvider())),
29+
DBObjectCodecProvider.createDefaultBsonTypeClassMap());
3030

3131
public static DBObject toDBObject(final BsonDocument document) {
3232
return codec.decode(new BsonDocumentReader(document));

0 commit comments

Comments
 (0)