com.openharbor.beck.id
Class SerialNumber

java.lang.Object
  extended bycom.openharbor.beck.id.SerialNumber
All Implemented Interfaces:
Identifier

public class SerialNumber
extends java.lang.Object
implements Identifier

Assigns serial numbers to objects, regardless of their content or ancestry. Uses an 'sn' attribute as an ID, and an 'snref' attribute as an IDREF. This is sufficient to pack an object graph into a simple XML tree. But the serial numbers are useful only within the scope of a single XML document; they're not useful for inter-document references or correlating multiple XML documents that contain copies of an object.


Field Summary
protected  XMLName idName
           
protected  XMLName idRefName
           
protected  org.apache.commons.logging.Log log
           
 
Fields inherited from interface com.openharbor.beck.id.Identifier
IDREF_TO_DANGLING_REFERENCES, IDREF_TO_REFERENT
 
Constructor Summary
SerialNumber()
           
 
Method Summary
 XMLThing getIdReference(java.lang.Object parent, Getter getter, java.lang.Object source, XMLThing referent, XMLWriter writer)
          Construct an XML reference to the given XML element or attribute.
 XMLThing getIdReferent(java.lang.Object parent, Getter getter, java.lang.Object source, XMLThing referent, XMLWriter writer)
          Add anchor data to the XML element or attribute for a given Java object.
 XMLThing getReferenceKey(Unmarshaller reference)
          Extract the essential data of the given XML reference to an XML element or attribute.
 XMLThing getReferentKey(Unmarshaller referent)
          Extract the essential data of a given XML element or attribute.
 java.lang.Class getUnmarshallerClass(MapFromXML mapper, Unmarshaller parent, XMLThing source, XMLContext context)
          If the given source is a cross-reference, return the class of Unmarshaller for it.
protected  java.lang.String newId(java.lang.Object parent, Getter getter, java.lang.Object source, XMLThing referent, XMLWriter writer)
           
static void setGenerator(long n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log

idName

protected XMLName idName

idRefName

protected XMLName idRefName
Constructor Detail

SerialNumber

public SerialNumber()
Method Detail

setGenerator

public static void setGenerator(long n)

newId

protected java.lang.String newId(java.lang.Object parent,
                                 Getter getter,
                                 java.lang.Object source,
                                 XMLThing referent,
                                 XMLWriter writer)

getIdReferent

public XMLThing getIdReferent(java.lang.Object parent,
                              Getter getter,
                              java.lang.Object source,
                              XMLThing referent,
                              XMLWriter writer)
Description copied from interface: Identifier
Add anchor data to the XML element or attribute for a given Java object.

If the returned thing is an element with a null value, the caller should output the element and also additional attributes and/or content mapped from the source object. If the returned thing is an attribute or an element with a non-null value, the caller should output the returned thing without additions.

The implementation can and should simply return the given referent, if it can't be referred to or already contains the necessary anchor data. The parameters provide enough context to enable sophisticated algorithms, but many implementations won't need them.

Specified by:
getIdReferent in interface Identifier
Parameters:
parent - the object that contains source, or null if source is the root object
getter - the relationship from parent to source
source - the Java object to be marshalled
referent - the caller's choice of XML (from a MapToXML, usually)
writer - whither this object will be marshalled
Returns:
the XML thing for this object, or null to indicate that this object should not be marshalled.

getIdReference

public XMLThing getIdReference(java.lang.Object parent,
                               Getter getter,
                               java.lang.Object source,
                               XMLThing referent,
                               XMLWriter writer)
Description copied from interface: Identifier
Construct an XML reference to the given XML element or attribute. The reference should uniquely identify the object, among all objects that have been or could be marshalled to the given writer's current XML document.

Specified by:
getIdReference in interface Identifier
Returns:
an element or attribute that refers to the given referent, or null to indicate it's not possible to refer to the given referent.

getReferenceKey

public XMLThing getReferenceKey(Unmarshaller reference)
Description copied from interface: Identifier
Extract the essential data of the given XML reference to an XML element or attribute. The returned object must be uniquely a function of the referent, among all XML that has been or could be unmarshalled from the current XML document (assuming the document is valid).

Specified by:
getReferenceKey in interface Identifier

getReferentKey

public XMLThing getReferentKey(Unmarshaller referent)
Description copied from interface: Identifier
Extract the essential data of a given XML element or attribute. The returned object must be uniquely a function of the referent, among all XML that has been or could be unmarshalled from the current XML document (assuming the document is valid).

Specified by:
getReferentKey in interface Identifier

getUnmarshallerClass

public java.lang.Class getUnmarshallerClass(MapFromXML mapper,
                                            Unmarshaller parent,
                                            XMLThing source,
                                            XMLContext context)
Description copied from interface: Identifier
If the given source is a cross-reference, return the class of Unmarshaller for it. The parameters provide enough context to enable sophisticated algorithms, but many implementations won't need them.

Specified by:
getUnmarshallerClass in interface Identifier
Parameters:
mapper -
parent -
source -
context -
Returns:
the class of Unmarshaller to use, or null to indicate that this source is not a reference.