|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.ceryle.util.IDFactory
public class IDFactory
IDFactory produces a unique String identifier (ID) upon
demand. All are suitable as XML IDs.
The class uses either an int value provided in the constructor or a preset System property to determine the type of IDs to generate (as noted above). If the System property is set, its value will take priority and the parameter values provided during construction are ignored.
The recognized property values for the type property:
http://purl.org/ceryle/prop/#idfactory
are as follows (case insensitive):
The structure of the generated ID is in four parts, depending on the factory type and whether the prefix is supplied at construction time and/or method call:
prefix + initialValue + '-' + generated_value
The prefix is used when a prefix value has been set prior to construction
using setPrefix(String), so that context-specific IDs can be generated,
such as "topic-[generated_value]" or "assoc-[generated_value]".
The initialValue is an option long value that can be used to create a
unique numeric context, such as generated by a timestamp. The constructor will
check if the parameter is larger than the millisecond count at the millenium
(ID64Generator.MILLENIUM_MILLIS), and if so convert the parameter to a
base 64 value.
This class implements the TM4J IDGenerator interface; hence it can be used wherever implementations of that interface are called for. The default constructor creates an IDFactory (whose type is TYPE_TIMESTAMP), which produces output similar to the TM4J IDGeneratorImpl class.
| Field Summary | |
|---|---|
static boolean |
FORCE_FIRSTCHAR_LOWERCASE
When true, the first character of autogenerated IDs will be lowercased. |
static int |
ID_MAXLENGTH
A recommended maximum length for ID values. |
protected int |
m_factory_type
A member variable indicating which format of output this IDFactory will generate. |
static String |
PROPERTY_FACTORY_TYPE
The property name for the ID factory type. |
static String |
PROPERTY_VALUE_INCREMENTAL
The property value for the ID factory type incremental. |
static String |
PROPERTY_VALUE_RANDOMWORD
The property value for the ID factory type random word. |
static String |
PROPERTY_VALUE_TIMESTAMP
The property value for the ID factory type time stamp. |
static int |
RADIX
Used as the radix value for the incremental counter for timestamped IDs. |
static int |
TYPE_INCREMENTAL
An enumerated type contant indicating that this IDFactory IDFactory will generate incremental values. |
static int |
TYPE_RANDOM_WORD
An enumerated type contant indicating that this IDFactory IDFactory will generate random word values. |
static int |
TYPE_TIMESTAMP
An enumerated type contant indicating that this IDFactory IDFactory will generate timestamp-based values. |
| Constructor Summary | |
|---|---|
IDFactory()
Default constructor creating a timestamp IDFactory, similar to the output of org.tm4j.topicmap.util.IDGeneratorImpl. |
|
IDFactory(int factoryType,
String prefix,
long initialValue)
Full constructor with an int type factoryType (see PROPERTY_FACTORY_TYPE), an ID prefix String
prefix, and an initial ID value initialValue. |
|
IDFactory(String prefix)
Constructor with an ID prefix String prefix. |
|
| Method Summary | |
|---|---|
String |
getID()
Generate a unique ID. |
String |
getID(String prefix)
Generate a unique ID, depending on factory type. |
String |
getIDFromName_old(String name)
Generate a unique ID as a transform of a provided String name. |
String |
getIDFromName(String name)
Generate a unique ID as a transform of a provided String name. |
static String |
getPrefix()
Returns the ID prefix String. |
String |
getRandomWord()
Generate a random nonsense word. |
String |
getUniqueID(String id,
Collection list,
int max)
Given a String id, removes any whitespace or disallowed XML Name characters, then provides an alternate rendition by appending or incrementing an existing end-number. |
static boolean |
isID(String s)
Returns true if the provided String is a valid ID. |
static boolean |
isName(String s)
Returns true if the provided String is a valid XML Name. |
boolean |
registerID(String id)
Register a foreign-generated ID with this IDFactory. |
boolean |
registerIDs(Collection ids,
boolean clear)
Register a Set of foreign-generated IDs with this IDFactory. |
void |
reset()
Resets the counter to its initial value. |
static void |
setPrefix(String prefix)
Sets the ID prefix String used by this IDFactory. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String PROPERTY_FACTORY_TYPE
public static final String PROPERTY_VALUE_INCREMENTAL
TYPE_INCREMENTAL.
The value is "incremental".
public static final String PROPERTY_VALUE_RANDOMWORD
TYPE_RANDOM_WORD.
The value is "randomword".
public static final String PROPERTY_VALUE_TIMESTAMP
TYPE_TIMESTAMP.
The value is "timestamp".
public static int ID_MAXLENGTH
public static final int TYPE_INCREMENTAL
PROPERTY_FACTORY_TYPE,
Constant Field Valuespublic static final int TYPE_RANDOM_WORD
PROPERTY_FACTORY_TYPE,
Constant Field Valuespublic static final int TYPE_TIMESTAMP
PROPERTY_FACTORY_TYPE,
Constant Field Valuesprotected int m_factory_type
public static int RADIX
public static boolean FORCE_FIRSTCHAR_LOWERCASE
| Constructor Detail |
|---|
public IDFactory()
IDGeneratorImplpublic IDFactory(String prefix)
public IDFactory(int factoryType,
String prefix,
long initialValue)
PROPERTY_FACTORY_TYPE), an ID prefix String
prefix, and an initial ID value initialValue. Note
that if the System property is set prior to construction, the value
provided here will be ignored.
factoryType - the type of factory to createprefix - the optional prefix string (if null, no prefix is used)initialValue - the optional initial numeric value (used as part of the prefix)| Method Detail |
|---|
public static boolean isID(String s)
public static boolean isName(String s)
public boolean registerID(String id)
public boolean registerIDs(Collection ids,
boolean clear)
public String getID()
getID in interface IDGeneratorIDGeneratorpublic String getID(String prefix)
public String getIDFromName_old(String name)
public String getIDFromName(String name)
public static void setPrefix(String prefix)
public static String getPrefix()
public void reset()
public String getRandomWord()
public String getUniqueID(String id,
Collection list,
int max)
The maximum length of the base String (i.e, not including the end number) is set by max, with a max value less than one interpreted as no maximum. For example, provided "abc", returns "abc1"; provided "abc77", returns "abc78"; provided "the Cat in the Hat 77" with max of 5, returns "theCat78". If the provided String does not begin with an XML Name start character, the IDFactory prefix String (default "id") is prepended. Also, this will strip out colons and removes the first three characters of the String if they case-insensitively match "xml" (since that's a disallowed ID).
id - a source for the generated IDlist - the list of existing IDs to compare againstmax - the maximum length in characters of the generated ID
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||