This is an automated email from the git hooks/post-receive script. tjaalton pushed a commit to branch master in repository jackson-jaxrs-providers.
commit 3d1f24dfbc26cfbc69aa572ead736ebdd1d243eb Author: Tatu Saloranta <[email protected]> Date: Fri Mar 15 20:10:50 2013 -0700 refactoring --- .../jaxrs/base/cfg/MapperConfiguratorBase.java | 93 ++++++++++++++++++++++ .../jackson/jaxrs/json/cfg/MapperConfigurator.java | 66 +++++---------- .../jaxrs/smile/cfg/MapperConfigurator.java | 63 ++++----------- .../jackson/jaxrs/xml/cfg/MapperConfigurator.java | 60 +++----------- 4 files changed, 141 insertions(+), 141 deletions(-) diff --git a/base/src/main/java/com/fasterxml/jackson/jaxrs/base/cfg/MapperConfiguratorBase.java b/base/src/main/java/com/fasterxml/jackson/jaxrs/base/cfg/MapperConfiguratorBase.java new file mode 100644 index 0000000..976074c --- /dev/null +++ b/base/src/main/java/com/fasterxml/jackson/jaxrs/base/cfg/MapperConfiguratorBase.java @@ -0,0 +1,93 @@ +package com.fasterxml.jackson.jaxrs.base.cfg; + +import com.fasterxml.jackson.core.*; + +import com.fasterxml.jackson.databind.*; + +/** + * Helper class used to encapsulate details of configuring an + * {@link ObjectMapper} instance to be used for data binding, as + * well as accessing it. + */ +public abstract class MapperConfiguratorBase<IMPL extends MapperConfiguratorBase<IMPL,MAPPER>, + MAPPER extends ObjectMapper> +{ + /** + * Mapper provider was constructed with if any, or that was constructed + * due to a call to explicitly configure mapper. + * If defined (explicitly or implicitly) it will be used, instead + * of using provider-based lookup. + */ + protected MAPPER _mapper; + + /** + * If no mapper was specified when constructed, and no configuration + * calls are made, a default mapper is constructed. The difference + * between default mapper and regular one is that default mapper + * is only used if no mapper is found via provider lookup. + */ + protected MAPPER _defaultMapper; + + /** + * To support optional dependency to Jackson JAXB annotations module + * (needed iff JAXB annotations are used for configuration) + */ + protected Class<? extends AnnotationIntrospector> _jaxbIntrospectorClass; + + /* + /********************************************************** + /* Construction + /********************************************************** + */ + + public MapperConfiguratorBase(MAPPER mapper) + { + _mapper = mapper; + } + + /* + /********************************************************** + /* Abstract methods to implement + /*********************************************************** + */ + + /** + * Method that locates, configures and returns {@link ObjectMapper} to use + */ + public abstract MAPPER getConfiguredMapper(); + + public abstract MAPPER getDefaultMapper(); + + /** + * Helper method that will ensure that there is a configurable non-default + * mapper (constructing an instance if one didn't yet exit), and return + * that mapper. + */ + protected abstract MAPPER mapper(); + + /* + /*********************************************************** + /* Configuration methods + /*********************************************************** + */ + + public synchronized final void setMapper(MAPPER m) { + _mapper = m; + } + + public synchronized final void configure(DeserializationFeature f, boolean state) { + mapper().configure(f, state); + } + + public synchronized final void configure(SerializationFeature f, boolean state) { + mapper().configure(f, state); + } + + public synchronized final void configure(JsonParser.Feature f, boolean state) { + mapper().configure(f, state); + } + + public synchronized final void configure(JsonGenerator.Feature f, boolean state) { + mapper().configure(f, state); + } +} diff --git a/json/src/main/java/com/fasterxml/jackson/jaxrs/json/cfg/MapperConfigurator.java b/json/src/main/java/com/fasterxml/jackson/jaxrs/json/cfg/MapperConfigurator.java index f23dd2a..e30614c 100644 --- a/json/src/main/java/com/fasterxml/jackson/jaxrs/json/cfg/MapperConfigurator.java +++ b/json/src/main/java/com/fasterxml/jackson/jaxrs/json/cfg/MapperConfigurator.java @@ -2,10 +2,9 @@ package com.fasterxml.jackson.jaxrs.json.cfg; import java.util.*; -import com.fasterxml.jackson.core.*; - import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; +import com.fasterxml.jackson.jaxrs.base.cfg.MapperConfiguratorBase; import com.fasterxml.jackson.jaxrs.json.Annotations; import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; @@ -15,22 +14,8 @@ import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; * well as accessing it. */ public class MapperConfigurator + extends MapperConfiguratorBase<MapperConfigurator, ObjectMapper> { - /** - * Mapper provider was constructed with if any, or that was constructed - * due to a call to explicitly configure mapper. - * If defined (explicitly or implicitly) it will be used, instead - * of using provider-based lookup. - */ - protected ObjectMapper _mapper; - - /** - * If no mapper was specified when constructed, and no configuration - * calls are made, a default mapper is constructed. The difference - * between default mapper and regular one is that default mapper - * is only used if no mapper is found via provider lookup. - */ - protected ObjectMapper _defaultMapper; /** * Annotations set to use by default; overridden by explicit call @@ -52,13 +37,14 @@ public class MapperConfigurator public MapperConfigurator(ObjectMapper mapper, Annotations[] defAnnotations) { - _mapper = mapper; + super(mapper); _defaultAnnotationsToUse = defAnnotations; } /** * Method that locates, configures and returns {@link ObjectMapper} to use */ + @Override public synchronized ObjectMapper getConfiguredMapper() { /* important: should NOT call mapper(); needs to return null * if no instance has been passed or constructed @@ -66,6 +52,7 @@ public class MapperConfigurator return _mapper; } + @Override public synchronized ObjectMapper getDefaultMapper() { if (_defaultMapper == null) { _defaultMapper = new ObjectMapper(); @@ -75,46 +62,27 @@ public class MapperConfigurator } /* - *********************************************************** - * Configuration methods - *********************************************************** - */ - - public synchronized void setMapper(ObjectMapper m) { - _mapper = m; - } + /********************************************************** + /* Configuration methods + /********************************************************** + */ public synchronized void setAnnotationsToUse(Annotations[] annotationsToUse) { _setAnnotations(mapper(), annotationsToUse); } - public synchronized void configure(DeserializationFeature f, boolean state) { - mapper().configure(f, state); - } - - public synchronized void configure(SerializationFeature f, boolean state) { - mapper().configure(f, state); - } - - public synchronized void configure(JsonParser.Feature f, boolean state) { - mapper().configure(f, state); - } - - public synchronized void configure(JsonGenerator.Feature f, boolean state) { - mapper().configure(f, state); - } - /* - *********************************************************** - * Internal methods - *********************************************************** - */ + /********************************************************** + /* Abstract method impl + /********************************************************** + */ /** * Helper method that will ensure that there is a configurable non-default * mapper (constructing an instance if one didn't yet exit), and return * that mapper. */ + @Override protected ObjectMapper mapper() { if (_mapper == null) { @@ -124,6 +92,12 @@ public class MapperConfigurator return _mapper; } + /* + /********************************************************** + /* Internal methods + /********************************************************** + */ + protected void _setAnnotations(ObjectMapper mapper, Annotations[] annotationsToUse) { AnnotationIntrospector intr; diff --git a/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile/cfg/MapperConfigurator.java b/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile/cfg/MapperConfigurator.java index fcebffc..ad00d2d 100644 --- a/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile/cfg/MapperConfigurator.java +++ b/smile/src/main/java/com/fasterxml/jackson/jaxrs/smile/cfg/MapperConfigurator.java @@ -2,38 +2,24 @@ package com.fasterxml.jackson.jaxrs.smile.cfg; import java.util.*; -import com.fasterxml.jackson.core.*; - import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; import com.fasterxml.jackson.dataformat.smile.SmileFactory; -import com.fasterxml.jackson.jaxrs.smile.Annotations; + +import com.fasterxml.jackson.jaxrs.base.cfg.MapperConfiguratorBase; import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; +import com.fasterxml.jackson.jaxrs.smile.Annotations; + /** * Helper class used to encapsulate details of configuring an * {@link ObjectMapper} instance to be used for data binding, as * well as accessing it. */ public class MapperConfigurator + extends MapperConfiguratorBase<MapperConfigurator, ObjectMapper> { /** - * Mapper provider was constructed with if any, or that was constructed - * due to a call to explicitly configure mapper. - * If defined (explicitly or implicitly) it will be used, instead - * of using provider-based lookup. - */ - protected ObjectMapper _mapper; - - /** - * If no mapper was specified when constructed, and no configuration - * calls are made, a default mapper is constructed. The difference - * between default mapper and regular one is that default mapper - * is only used if no mapper is found via provider lookup. - */ - protected ObjectMapper _defaultMapper; - - /** * Annotations set to use by default; overridden by explicit call * to {@link #setAnnotationsToUse} */ @@ -53,7 +39,7 @@ public class MapperConfigurator public MapperConfigurator(ObjectMapper mapper, Annotations[] defAnnotations) { - _mapper = mapper; + super(mapper); _defaultAnnotationsToUse = defAnnotations; } @@ -76,46 +62,27 @@ public class MapperConfigurator } /* - *********************************************************** - * Configuration methods - *********************************************************** - */ - - public synchronized void setMapper(ObjectMapper m) { - _mapper = m; - } + /*********************************************************** + /* Configuration methods + /*********************************************************** + */ public synchronized void setAnnotationsToUse(Annotations[] annotationsToUse) { _setAnnotations(mapper(), annotationsToUse); } - public synchronized void configure(DeserializationFeature f, boolean state) { - mapper().configure(f, state); - } - - public synchronized void configure(SerializationFeature f, boolean state) { - mapper().configure(f, state); - } - - public synchronized void configure(JsonParser.Feature f, boolean state) { - mapper().configure(f, state); - } - - public synchronized void configure(JsonGenerator.Feature f, boolean state) { - mapper().configure(f, state); - } - /* - *********************************************************** - * Internal methods - *********************************************************** - */ + /*********************************************************** + /* Internal methods + /*********************************************************** + */ /** * Helper method that will ensure that there is a configurable non-default * mapper (constructing an instance if one didn't yet exit), and return * that mapper. */ + @Override protected ObjectMapper mapper() { if (_mapper == null) { diff --git a/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml/cfg/MapperConfigurator.java b/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml/cfg/MapperConfigurator.java index 9129d53..8437c82 100644 --- a/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml/cfg/MapperConfigurator.java +++ b/xml/src/main/java/com/fasterxml/jackson/jaxrs/xml/cfg/MapperConfigurator.java @@ -2,8 +2,6 @@ package com.fasterxml.jackson.jaxrs.xml.cfg; import java.util.*; -import com.fasterxml.jackson.core.*; - import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.dataformat.xml.JacksonXmlAnnotationIntrospector; @@ -11,6 +9,8 @@ import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.xml.jaxb.XmlJaxbAnnotationIntrospector; +import com.fasterxml.jackson.jaxrs.base.cfg.MapperConfiguratorBase; + import com.fasterxml.jackson.jaxrs.xml.Annotations; /** @@ -19,24 +19,9 @@ import com.fasterxml.jackson.jaxrs.xml.Annotations; * well as accessing it. */ public class MapperConfigurator + extends MapperConfiguratorBase<MapperConfigurator, XmlMapper> { /** - * Mapper provider was constructed with if any, or that was constructed - * due to a call to explicitly configure mapper. - * If defined (explicitly or implicitly) it will be used, instead - * of using provider-based lookup. - */ - protected XmlMapper _mapper; - - /** - * If no mapper was specified when constructed, and no configuration - * calls are made, a default mapper is constructed. The difference - * between default mapper and regular one is that default mapper - * is only used if no mapper is found via provider lookup. - */ - protected XmlMapper _defaultMapper; - - /** * Annotations set to use by default; overridden by explicit call * to {@link #setAnnotationsToUse} */ @@ -56,7 +41,7 @@ public class MapperConfigurator public MapperConfigurator(XmlMapper mapper, Annotations[] defAnnotations) { - _mapper = mapper; + super(mapper); _defaultAnnotationsToUse = defAnnotations; } @@ -87,46 +72,27 @@ public class MapperConfigurator } /* - *********************************************************** - * Configuration methods - *********************************************************** - */ - - public synchronized void setMapper(XmlMapper m) { - _mapper = m; - } + /*********************************************************** + /* Configuration methods + /*********************************************************** + */ public synchronized void setAnnotationsToUse(Annotations[] annotationsToUse) { _setAnnotations(mapper(), annotationsToUse); } - public synchronized void configure(DeserializationFeature f, boolean state) { - mapper().configure(f, state); - } - - public synchronized void configure(SerializationFeature f, boolean state) { - mapper().configure(f, state); - } - - public synchronized void configure(JsonParser.Feature f, boolean state) { - mapper().configure(f, state); - } - - public synchronized void configure(JsonGenerator.Feature f, boolean state) { - mapper().configure(f, state); - } - /* - *********************************************************** - * Internal methods - *********************************************************** - */ + /*********************************************************** + /* Internal methods + /*********************************************************** + */ /** * Helper method that will ensure that there is a configurable non-default * mapper (constructing an instance if one didn't yet exit), and return * that mapper. */ + @Override protected XmlMapper mapper() { if (_mapper == null) { -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jackson-jaxrs-providers.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

