10
10
import java .util .List ;
11
11
12
12
import com .fasterxml .jackson .core .io .*;
13
+ import com .fasterxml .jackson .core .json .JsonFactory ;
13
14
import com .fasterxml .jackson .core .sym .FieldNameMatcher ;
14
15
import com .fasterxml .jackson .core .sym .SimpleNameMatcher ;
15
16
import com .fasterxml .jackson .core .util .BufferRecycler ;
@@ -137,6 +138,139 @@ public static int collectDefaults() {
137
138
public int getMask () { return (1 << ordinal ()); }
138
139
}
139
140
141
+ /**
142
+ * Since factory instances are immutable, a Builder class is needed for creating
143
+ * configurations for differently configured factory instances.
144
+ *
145
+ * @since 3.0
146
+ */
147
+ public abstract static class TSFBuilder <F extends TokenStreamFactory ,
148
+ T extends TSFBuilder <F ,T >>
149
+ {
150
+ /**
151
+ * Set of {@link TokenStreamFactory.Feature}s enabled, as bitmask.
152
+ */
153
+ protected int _factoryFeatures ;
154
+
155
+ /**
156
+ * Set of {@link JsonParser.Feature}s enabled, as bitmask.
157
+ */
158
+ protected int _parserFeatures ;
159
+
160
+ /**
161
+ * Set of {@link JsonGenerator.Feature}s enabled, as bitmask.
162
+ */
163
+ protected int _generatorFeatures ;
164
+
165
+ // // // Construction
166
+
167
+ protected TSFBuilder () {
168
+ _factoryFeatures = DEFAULT_FACTORY_FEATURE_FLAGS ;
169
+ _parserFeatures = DEFAULT_PARSER_FEATURE_FLAGS ;
170
+ _generatorFeatures = DEFAULT_GENERATOR_FEATURE_FLAGS ;
171
+ }
172
+
173
+ protected TSFBuilder (TokenStreamFactory base )
174
+ {
175
+ this (base ._factoryFeatures ,
176
+ base .getParserFeatures (), base .getGeneratorFeatures ());
177
+ }
178
+
179
+ protected TSFBuilder (int factoryFeatures ,
180
+ int parserFeatures , int generatorFeatures )
181
+ {
182
+ _factoryFeatures = factoryFeatures ;
183
+ _parserFeatures = parserFeatures ;
184
+ _generatorFeatures = generatorFeatures ;
185
+ }
186
+
187
+ // // // Accessors
188
+
189
+ public int factoryFeaturesMask () { return _factoryFeatures ; }
190
+ public int parserFeaturesMask () { return _parserFeatures ; }
191
+ public int generatorFeaturesMask () { return _generatorFeatures ; }
192
+
193
+ // // // Factory features
194
+
195
+ public T with (TokenStreamFactory .Feature f ) {
196
+ _factoryFeatures |= f .getMask ();
197
+ return _this ();
198
+ }
199
+
200
+ public T without (TokenStreamFactory .Feature f ) {
201
+ _factoryFeatures &= ~f .getMask ();
202
+ return _this ();
203
+ }
204
+
205
+ // // // Parser features
206
+
207
+ public T with (JsonParser .Feature f ) {
208
+ _parserFeatures |= f .getMask ();
209
+ return _this ();
210
+ }
211
+
212
+ public T with (JsonParser .Feature first , JsonParser .Feature ... other ) {
213
+ _parserFeatures |= first .getMask ();
214
+ for (JsonParser .Feature f : other ) {
215
+ _parserFeatures |= f .getMask ();
216
+ }
217
+ return _this ();
218
+ }
219
+
220
+ public T without (JsonParser .Feature f ) {
221
+ _parserFeatures &= ~f .getMask ();
222
+ return _this ();
223
+ }
224
+
225
+ public T without (JsonParser .Feature first , JsonParser .Feature ... other ) {
226
+ _parserFeatures &= ~first .getMask ();
227
+ for (JsonParser .Feature f : other ) {
228
+ _parserFeatures &= ~f .getMask ();
229
+ }
230
+ return _this ();
231
+ }
232
+
233
+ // // // Generator features
234
+
235
+ public T with (JsonGenerator .Feature f ) {
236
+ _generatorFeatures |= f .getMask ();
237
+ return _this ();
238
+ }
239
+
240
+ public T with (JsonGenerator .Feature first , JsonGenerator .Feature ... other ) {
241
+ _generatorFeatures |= first .getMask ();
242
+ for (JsonGenerator .Feature f : other ) {
243
+ _parserFeatures |= f .getMask ();
244
+ }
245
+ return _this ();
246
+ }
247
+
248
+ public T without (JsonGenerator .Feature f ) {
249
+ _generatorFeatures &= ~f .getMask ();
250
+ return _this ();
251
+ }
252
+
253
+ public T without (JsonGenerator .Feature first , JsonGenerator .Feature ... other ) {
254
+ _generatorFeatures &= ~first .getMask ();
255
+ for (JsonGenerator .Feature f : other ) {
256
+ _generatorFeatures &= ~f .getMask ();
257
+ }
258
+ return _this ();
259
+ }
260
+
261
+ // // // Other methods
262
+
263
+ /**
264
+ * Method for constructing actual {@link TokenStreamFactory} instance, given
265
+ * configuration.
266
+ */
267
+ protected abstract F build ();
268
+
269
+ // silly convenience cast method we need
270
+ @ SuppressWarnings ("unchecked" )
271
+ protected final T _this () { return (T ) this ; }
272
+ }
273
+
140
274
/*
141
275
/**********************************************************
142
276
/* Constants
@@ -199,6 +333,22 @@ public static int collectDefaults() {
199
333
*/
200
334
public TokenStreamFactory () { }
201
335
336
+ /**
337
+ * Constructors used by {@link TSFBuilder} for instantiation. Base builder is
338
+ * passed as-is to try to make interface between base types and implementations
339
+ * less likely to change (given that sub-classing is a fragile way to do it):
340
+ * if and when new general-purpose properties are added, implementation classes
341
+ * do not have to use different constructors.
342
+ *
343
+ * @since 3.0
344
+ */
345
+ protected TokenStreamFactory (TSFBuilder <?,?> baseBuilder )
346
+ {
347
+ _factoryFeatures = baseBuilder .factoryFeaturesMask ();
348
+ _parserFeatures = baseBuilder .parserFeaturesMask ();
349
+ _generatorFeatures = baseBuilder .generatorFeaturesMask ();
350
+ }
351
+
202
352
/**
203
353
* Constructor used when copy()ing a factory instance.
204
354
*/
@@ -217,6 +367,14 @@ protected TokenStreamFactory(TokenStreamFactory src)
217
367
*/
218
368
public abstract TokenStreamFactory copy ();
219
369
370
+ /**
371
+ * Method that can be used to create differently configured stream factories.
372
+ *
373
+ * @since 3.0
374
+ */
375
+ public abstract TSFBuilder <?,?> rebuild ();
376
+ // public abstract <F extends TokenStreamFactory, T extends TSFBuilder<F,T>> TSFBuilder<F,T> rebuild();
377
+
220
378
/*
221
379
/**********************************************************
222
380
/* Capability introspection
@@ -600,46 +758,73 @@ public abstract JsonParser createParser(ObjectReadContext readCtxt,
600
758
/**********************************************************
601
759
*/
602
760
761
+ /**
762
+ * @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,java.io.File)}
763
+ */
603
764
@ Deprecated
604
765
public JsonParser createParser (File src ) throws IOException {
605
766
return createParser (ObjectReadContext .empty (), src );
606
767
}
607
768
769
+ /**
770
+ * @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,java.net.URL)}
771
+ */
608
772
@ Deprecated
609
773
public JsonParser createParser (URL src ) throws IOException {
610
774
return createParser (ObjectReadContext .empty (), src );
611
775
}
612
776
777
+ /**
778
+ * @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,java.io.InputStream)}
779
+ */
613
780
@ Deprecated
614
781
public JsonParser createParser (InputStream in ) throws IOException {
615
782
return createParser (ObjectReadContext .empty (), in );
616
783
}
617
784
785
+ /**
786
+ * @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,java.io.Reader)}
787
+ */
618
788
@ Deprecated
619
789
public JsonParser createParser (Reader r ) throws IOException {
620
790
return createParser (ObjectReadContext .empty (), r );
621
791
}
622
792
793
+ /**
794
+ * @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,byte[])}
795
+ */
623
796
@ Deprecated
624
797
public JsonParser createParser (byte [] data ) throws IOException {
625
798
return createParser (ObjectReadContext .empty (), data , 0 , data .length );
626
799
}
627
800
801
+ /**
802
+ * @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,byte[],int,int)}
803
+ */
628
804
@ Deprecated
629
805
public JsonParser createParser (byte [] data , int offset , int len ) throws IOException {
630
806
return createParser (ObjectReadContext .empty (), data , offset , len );
631
807
}
632
808
809
+ /**
810
+ * @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,String)}
811
+ */
633
812
@ Deprecated
634
813
public JsonParser createParser (String content ) throws IOException {
635
814
return createParser (ObjectReadContext .empty (), content );
636
815
}
637
816
817
+ /**
818
+ * @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,char[])}
819
+ */
638
820
@ Deprecated
639
821
public JsonParser createParser (char [] content ) throws IOException {
640
822
return createParser (ObjectReadContext .empty (), content , 0 , content .length );
641
823
}
642
824
825
+ /**
826
+ * @deprecated Since 3.0 use {@link #createParser(ObjectReadContext,char[],int,int)}
827
+ */
643
828
@ Deprecated
644
829
public JsonParser createParser (char [] content , int offset , int len ) throws IOException {
645
830
return createParser (ObjectReadContext .empty (), content , offset , len );
0 commit comments