org.activemath.omdocjdom
Class ID

java.lang.Object
  extended by org.activemath.omdocjdom.ID
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
IID

public class ID
extends Object
implements Serializable

This implements the ID interface in the simplest manner. As the whole subject of object oriented IDs in OMdoc is rather unprecise, the implementation is perfectly candid and based on the following convention for a globally unique URI:

Version:
See Also:
Serialized Form

Nested Class Summary
protected static class ID.PoolableRE
           
 
Field Summary
 String collection
           
static org.apache.regexp.REProgram fullURIPatternProgram
          This initailizes the pattern
 String mid
           
 String name
           
protected static SimplePool rePool
           
 String theory
           
 
Constructor Summary
ID(ID baseID, String path)
          Reads the ID using the pattern and the baseID to make a relative ID.
ID(ID baseID, String theory, String name)
          Tries to return the ID of the node with the same collection but with given theory and name.
ID(String absolutePath)
          Makes an ID by extracting the informations from the string given which is supposed to be a properly formatted mbase URI obeying the patther mbase://collection/theory/name.
ID(String baseCollection, String collectionAbsolute)
           
ID(String collection, String theory, String name, String mid)
          Plain constructor acting as a record constructor (stores the fields, period).
 
Method Summary
 Object clone()
           
 boolean equals(ID id)
          A central piece in the storage facilities of IDs.
 boolean equals(Object id)
          Dispatches to equals(ID).
 String expressShortestRef(ID toID)
           
static String expressShortestRef(OJElement from, OJElement to)
          Computes the shortest-possible value for a reference contained as an attribute or a child's attribute of the from element to the to element.
 String getCollection()
          The first of the fields of this record.
 String getFullyQualifiedID()
          Returns mbase://collection/theoryID/name or, if the theory is null, mbase://collection/name:mid
 String getMID()
          The fourth of the fields of this record.
 String getName()
          The third of the fields of this record.
 String getRelativePart()
          Returns the part after the collection, that is theory/name or /name
 String getTheory()
          The second of the fields of this record.
 ID getTheoryID()
          Returns the ID made of the same collection and theory, or null if no theory exists.
 int hashCode()
          Takes the or of all hashcodes.
 IID internStrings()
          Computes an equal id with all components interned string.
 boolean isAbsolute()
          Evaluates wether the id thus built is absolute, that is, has non-null collection and (name or theory).
static ID makeAbsoluteID(String simply)
          This supports "mbase://" or "http://"
static ID makeCollectionRelativeID(String collectionName, String path)
          Splits the path given with slahes, if any, then creates a link that follows the policy given under makeRelativeID(org.activemath.omdocjdom.ID, java.lang.String) but with the given collection.
static org.apache.regexp.RE makePattern()
          Prepares a ID.PoolableRE regular expression object to parse a string URL.
static ID makeRelativeID(ID base, String path)
          Produces an ID that is relative to the base.
 String toString()
          Returns a representative (long) text describing all the fields, including its null fields.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

collection

public final String collection

theory

public final String theory

name

public final String name

mid

public final String mid

fullURIPatternProgram

public static org.apache.regexp.REProgram fullURIPatternProgram
This initailizes the pattern


rePool

protected static SimplePool rePool
Constructor Detail

ID

public ID(ID baseID,
          String path)
Reads the ID using the pattern and the baseID to make a relative ID. Leaves the mid field null.

Throws:
IllegalArgumentException - if the syntax is not correct though not all checks are made !

ID

public ID(ID baseID,
          String theory,
          String name)
Tries to return the ID of the node with the same collection but with given theory and name.

Parameters:
baseID - Can't be null
theory - may be null in which case the reference is understood to be in the no-theory world
name - can't be null (as part of the normal specification of IDs).

ID

public ID(String absolutePath)
Makes an ID by extracting the informations from the string given which is supposed to be a properly formatted mbase URI obeying the patther mbase://collection/theory/name. It does so using the regexp pattern ((mbase://)([^/]+)/)?(/?([^/]+)/)?([^/]+) and extracts corresponding informations from the parenthesized contents numbered 3, 5 and 6.

Throws:
IllegalArgumentException - if the syntax is not correct (though not all checks are made).

ID

public ID(String baseCollection,
          String collectionAbsolute)

ID

public ID(String collection,
          String theory,
          String name,
          String mid)
Plain constructor acting as a record constructor (stores the fields, period). It however also checks for nullity and will throw an IllegalArgumentException if all three last parameters are null.

Method Detail

makePattern

public static org.apache.regexp.RE makePattern()
Prepares a ID.PoolableRE regular expression object to parse a string URL. Is only used by constructors who need it without keeping this in store. The REProgram which is kernel of such regular expressions is stored in fullURIPatternProgram, a static variable, and is re-used when it is not null.

The regular expression has the syntax ((mbase://)([^/]+)/)?(/?([^/]+)/)?([^/:]+)?(:(.+))* which should match all possible ID string representations.

This method is made public mostly for debugging purposes. If having these objects is expensive, one should consier a more factory way with some pooling of RE's.

We need to move to OMDoc 1.1 references:

Using the following Regepx ? (([^#]*)#byctx\x28([^@]+)@(.+)\x28)


makeAbsoluteID

public static ID makeAbsoluteID(String simply)
This supports "mbase://" or "http://"


internStrings

public IID internStrings()
Computes an equal id with all components interned string.

Returns:
an IID with the same components, interned.

makeRelativeID

public static ID makeRelativeID(ID base,
                                String path)
Produces an ID that is relative to the base. This is made according to the following specification: This form doesn't seem to support a notion of mid... hence IDs built here have a null mid.


makeCollectionRelativeID

public static ID makeCollectionRelativeID(String collectionName,
                                          String path)
Splits the path given with slahes, if any, then creates a link that follows the policy given under makeRelativeID(org.activemath.omdocjdom.ID, java.lang.String) but with the given collection.

This method is a handcrafted parsing method... it may be fragile.


getFullyQualifiedID

public String getFullyQualifiedID()
Returns mbase://collection/theoryID/name or, if the theory is null, mbase://collection/name:mid


toString

public String toString()
Returns a representative (long) text describing all the fields, including its null fields.

Overrides:
toString in class Object

getRelativePart

public String getRelativePart()
Returns the part after the collection, that is theory/name or /name


getCollection

public String getCollection()
The first of the fields of this record.


getTheory

public String getTheory()
The second of the fields of this record.


getTheoryID

public ID getTheoryID()
Returns the ID made of the same collection and theory, or null if no theory exists.


getName

public String getName()
The third of the fields of this record.


getMID

public String getMID()
The fourth of the fields of this record.


isAbsolute

public boolean isAbsolute()
Evaluates wether the id thus built is absolute, that is, has non-null collection and (name or theory).

Returns:
wether it's absolute

expressShortestRef

public static String expressShortestRef(OJElement from,
                                        OJElement to)
Computes the shortest-possible value for a reference contained as an attribute or a child's attribute of the from element to the to element. The to element is supposed to have an ID.

Returns:
null if there is no ID to give to the to element.

expressShortestRef

public String expressShortestRef(ID toID)

equals

public boolean equals(Object id)
Dispatches to equals(ID).

Overrides:
equals in class Object

equals

public boolean equals(ID id)
A central piece in the storage facilities of IDs. This equals returns true if and only if the collection, theory and name are equals in the sense that they are either null or equals using String.equals(java.lang.Object) method.


hashCode

public int hashCode()
Takes the or of all hashcodes. Ignores MID.

Overrides:
hashCode in class Object

clone

public Object clone()
Overrides:
clone in class Object