This is an automated email from the git hooks/post-receive script. tjaalton pushed a commit to branch master in repository jackson-annotations.
commit 35a2ace0dc7f29bf7662c7b647edf74920a5987e Author: Tatu <[email protected]> Date: Tue Feb 7 17:17:25 2012 -0800 ... --- .../jackson/annotation/ObjectIdGenerator.java | 59 ++++++++++++++++-- .../jackson/annotation/ObjectIdGenerators.java | 71 +++++++++++++--------- 2 files changed, 96 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/annotation/ObjectIdGenerator.java b/src/main/java/com/fasterxml/jackson/annotation/ObjectIdGenerator.java index d4b0dac..0b86233 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/ObjectIdGenerator.java +++ b/src/main/java/com/fasterxml/jackson/annotation/ObjectIdGenerator.java @@ -10,19 +10,39 @@ package com.fasterxml.jackson.annotation; */ public abstract class ObjectIdGenerator<T> { + /* + /********************************************************** + /* Accessors + /********************************************************** + */ + + public abstract Class<?> getScope(); + + /* + /********************************************************** + /* Factory methods + /********************************************************** + */ + + /** + * Factory method to create a blueprint instance for specified + * scope. Generator that do not use scope may return 'this'. + */ + public abstract ObjectIdGenerator<T> forScope(Class<?> scope); + /** * Factory method called to create a new instance to use for * serialization. This includes initializing storage for keeping * track of serialized instances, along with id used. */ - public abstract ObjectIdGenerator<T> newForSerialization(Class<?> scope); + public abstract ObjectIdGenerator<T> newForSerialization(); /** * Factory method called to create a new instance to use for * serialization. This includes initializing storage for keeping * track of deserialized instances, along with id used. */ - public abstract ObjectIdGenerator<T> newForDeserialization(Class<?> scope); + public abstract ObjectIdGenerator<T> newForDeserialization(); /** * Method called to check whether this generator instance can @@ -31,10 +51,22 @@ public abstract class ObjectIdGenerator<T> * * @return True if this instance can be used as-is; false if not */ - public abstract boolean canUseFor(ObjectIdGenerator<?> gen, Class<?> scope); + public abstract boolean canUseFor(ObjectIdGenerator<?> gen); + + /* + /********************************************************** + /* Methods for serialization + /********************************************************** + */ /** - * Method used for generating an Object Identifier to serialize + * Method used during serialization, to try to find an Object Id for given already serialized + * Object: if none found, returns null. + */ + public abstract T findId(Object forPojo); + + /** + * Method used for generating a new Object Identifier to serialize * for given POJO. * * @param forPojo POJO for which identifier is needed @@ -42,4 +74,23 @@ public abstract class ObjectIdGenerator<T> * @return Object Identifier to use. */ public abstract T generateId(Object forPojo); + + /* + /********************************************************** + /* Methods for deserialization + /********************************************************** + */ + + /** + * Method used during deserialization, to try to find an item for which given + * id was used. + */ + public abstract Object findItem(T id); + + /** + * Method called during deserialization to establishing mapping between + * given item, and the id it was using. + */ + public abstract void addItem(Object item, T id); + } diff --git a/src/main/java/com/fasterxml/jackson/annotation/ObjectIdGenerators.java b/src/main/java/com/fasterxml/jackson/annotation/ObjectIdGenerators.java index 31280d6..9cceb3d 100644 --- a/src/main/java/com/fasterxml/jackson/annotation/ObjectIdGenerators.java +++ b/src/main/java/com/fasterxml/jackson/annotation/ObjectIdGenerators.java @@ -34,22 +34,25 @@ public class ObjectIdGenerators } @Override - public boolean canUseFor(ObjectIdGenerator<?> gen, Class<?> scope) { - return (gen.getClass() == getClass()) && (scope == _scope); + public final Class<?> getScope() { + return _scope; } - public Class<?> getScope() { - return _scope; + @Override + public boolean canUseFor(ObjectIdGenerator<?> gen) { + return (gen.getClass() == getClass()) && (gen.getScope() == _scope); } - protected T findId(Object item) { + @Override + public T findId(Object item) { if (_ids == null) { return null; } return _ids.get(item); } - protected Object findItem(T id) { + @Override + public Object findItem(T id) { if (_items == null) { return null; } @@ -57,26 +60,24 @@ public class ObjectIdGenerators } /** - * Method called during serialization to keep track of ids we have - * used. - */ - protected void addId(Object item, T id) { - if (_ids == null) { - _ids = new IdentityHashMap<Object, T>(16); - } - _ids.put(item, id); - } - - /** * Method called during deserialization to keep track of items we have * deserialized, along with ids they had. */ - protected void addItem(Object item, T id) { + @Override + public void addItem(Object item, T id) { if (_items == null) { _items = new IdentityHashMap<T, Object>(16); } _ids.put(item, id); } + + protected void addId(Object item, T id) { + if (_ids == null) { + _ids = new IdentityHashMap<Object, T>(16); + } + _ids.put(item, id); + } + } /* @@ -106,21 +107,27 @@ public class ObjectIdGenerators { protected int _nextValue; - public IntSequenceGenerator() { this(Object.class, 1); } + public IntSequenceGenerator() { this(Object.class, -1); } public IntSequenceGenerator(Class<?> scope, int fv) { super(scope); _nextValue = fv; } + protected int initialValue() { return 1; } + @Override - public ObjectIdGenerator<Integer> newForSerialization(Class<?> scope) { - return new IntSequenceGenerator(scope, _nextValue); + public ObjectIdGenerator<Integer> forScope(Class<?> scope) { + return (_scope == scope) ? this : new IntSequenceGenerator(scope, _nextValue); + } + + @Override + public ObjectIdGenerator<Integer> newForSerialization() { + return new IntSequenceGenerator(_scope, initialValue()); } - // we don't really need value for deserialization but... @Override - public ObjectIdGenerator<Integer> newForDeserialization(Class<?> scope) { - return new IntSequenceGenerator(scope, _nextValue); + public ObjectIdGenerator<Integer> newForDeserialization() { + return new IntSequenceGenerator(_scope, initialValue()); } @Override @@ -142,22 +149,27 @@ public class ObjectIdGenerators public UUIDGenerator(Class<?> scope) { super(scope); } + + @Override + public ObjectIdGenerator<UUID> forScope(Class<?> scope) { + return (_scope == scope) ? this : new UUIDGenerator(scope); + } @Override - public ObjectIdGenerator<UUID> newForSerialization(Class<?> scope) { - return new UUIDGenerator(scope); + public ObjectIdGenerator<UUID> newForSerialization() { + return new UUIDGenerator(_scope); } @Override - public ObjectIdGenerator<UUID> newForDeserialization(Class<?> scope) { - return new UUIDGenerator(scope); + public ObjectIdGenerator<UUID> newForDeserialization() { + return new UUIDGenerator(_scope); } /** * Since UUIDs are always unique, let's fully ignore scope definition */ @Override - public boolean canUseFor(ObjectIdGenerator<?> gen, Class<?> scope) { + public boolean canUseFor(ObjectIdGenerator<?> gen) { return (gen.getClass() == getClass()); } @@ -166,5 +178,4 @@ public class ObjectIdGenerators return UUID.randomUUID(); } } - } -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jackson-annotations.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

