public final class ReferenceResolver
extends java.lang.Object
Constructor and Description |
---|
ReferenceResolver()
The default constructor initializes the list of References.
|
Modifier and Type | Method and Description |
---|---|
void |
addReference(Reference ref)
Add a Reference object to the list - these References will
be resolved after unmarshalling is complete.
|
Reference |
getReference(ObjectReferenceMapping mapping,
java.lang.Object sourceObject)
Retrieve the reference for a given mapping instance.
|
Reference |
getReference(ObjectReferenceMapping mapping,
java.lang.Object sourceObject,
Field xmlField)
Return a reference for the given mapping and source object, that doesn't already
contain an entry for the provided field.
|
void |
putValue(java.lang.Class clazz,
java.lang.Object key,
java.lang.Object object)
Store an instance by key based on a mapped class.
|
void |
resolveReferences(CoreAbstractSession session,
IDResolver userSpecifiedResolver,
org.xml.sax.ErrorHandler handler)
INTERNAL:
Iterates through all references.
|
public ReferenceResolver()
public final void addReference(Reference ref)
############################# # Strategy - Hash Collision # ############################# Suppose that hashing function is h(k) = k % 9; __________Input 9 entries_________________________ Key k | 0, 8, 7, 5, 5, 5, 1, 14, 3 | Position# p | 0, 1, 2, 3, 4, 5, 6, 7, 8 | Value = p * 3 | 0, 3, 6, 9, 12, 15, 18, 21, 24 | -------------------------------------------------- e.g. eighth entry is Entry#7{ key = 14, value = 21 } #################################### # Insert element - O(1) guaranteed # #################################### Processing the 9th key: 1. Attempt to insert Entry#7 with key '14' into map of references. > h(14) = 5; HashMap buckets: position | 0 1 2 3 4 5 6 7 8 entry(key) | 0 1 3 5 7 8 ^ > Bucket 5 is taken. 2. Store the entry in a separate list. List for unlucky references: position | 0 1 2 entry(key) | 5 5 ^ position | 0 1 2 entry(key) | 5 5 14 ^ 3. Store the position # p of this element, i.e. what spot it would have taken if all entries were stored in a position list, counting from zero. List storing position # of unlucky references: position | 0 1 2 entry # (p) | 4 5 ^ position | 0 1 2 entry # (p) | 4 5 7 ^ ##################################################### # Retrieve element - O(1) expected, O(n) worst case # ##################################################### Retrieve entry with key '14' 1. Attempt to retrieve it from map > h(14) = 5; HashMap buckets: position | 0 1 2 3 4 5 6 7 8 entry(key) | 0 1 3 5 7 8 ^ Hash function points to bucket # 5. Stored key is 5. > key 5 != 14. 2. Iterate through list of unluckyReferences, comparing key to all keys in the list. position | 0 1 2 entry(key) | 5 5 14 ^ > key 5 != 14 position | 0 1 2 entry(key) | 5 5 14 ^ > key 5 != 14 position | 0 1 2 entry(key) | 5 5 14 ^ > key 14 = 14, retrieve entry. ################################################## # Iterate through all elements - O(n) guaranteed # ################################################## 1. Create boolean array of size n that keeps track of unlucky positions: > boolean[] a = new boolean[lastPosition + 1]; 2. Set a[p] = true for elements that did not fit into hash map, p = position # of element. > for (Integer p : unluckyRefPositions) { > a[p] = true; > } 3. Iterate through LinkedMap and List as if they were one joined collection of size s = map.size() + list.size(), ordered by p = position # of element: > for (p = 0; p < s; p ++) { > if a[p] = false, take next element from linked map iterator, > if a[p] = true, take next element from list iterator, > }
public final Reference getReference(ObjectReferenceMapping mapping, java.lang.Object sourceObject)
public final Reference getReference(ObjectReferenceMapping mapping, java.lang.Object sourceObject, Field xmlField)
public final void putValue(java.lang.Class clazz, java.lang.Object key, java.lang.Object object)
public final void resolveReferences(CoreAbstractSession session, IDResolver userSpecifiedResolver, org.xml.sax.ErrorHandler handler)
session
- typically will be a unit of workuserSpecifiedResolver
- a user-provided subclass of IDResolver, may be nullEclipseLink 2.6.3, "build v20160428-59c81c5" API Reference