Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.uuid.Uuid"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.uuid.Uuid"] = true;
3
dojo.provide("dojox.uuid.Uuid");
4
dojo.require("dojox.uuid");
5
 
6
dojox.uuid.Uuid = function(/*String?*/ input){
7
	// summary:
8
	//		This is the constructor for the Uuid class.  The Uuid class offers
9
	//		methods for inspecting existing UUIDs.
10
	// input: A 36-character string that conforms to the UUID spec.
11
	// examples:
12
	//		var uuid;
13
	//		uuid = new dojox.uuid.Uuid("3b12f1df-5232-4804-897e-917bf397618a");
14
	//		uuid = new dojox.uuid.Uuid(); // "00000000-0000-0000-0000-000000000000"
15
	//		uuid = new dojox.uuid.Uuid(dojox.uuid.generateRandomUuid());
16
	//		uuid = new dojox.uuid.Uuid(dojox.uuid.generateTimeBasedUuid());
17
	//		dojox.uuid.Uuid.setGenerator(dojox.uuid.generateRandomUuid);
18
	//		uuid = new dojox.uuid.Uuid();
19
	//		dojox.uuid.assert(!uuid.isEqual(dojox.uuid.NIL_UUID));
20
	this._uuidString = dojox.uuid.NIL_UUID;
21
	if(input){
22
		dojox.uuid.assert(dojo.isString(input));
23
		this._uuidString = input.toLowerCase();
24
		dojox.uuid.assert(this.isValid());
25
	}else{
26
		var ourGenerator = dojox.uuid.Uuid.getGenerator();
27
		if(ourGenerator){
28
			this._uuidString = ourGenerator();
29
			dojox.uuid.assert(this.isValid());
30
		}
31
	}
32
};
33
 
34
dojox.uuid.Uuid.compare = function(/*dojox.uuid.Uuid*/ uuidOne, /*dojox.uuid.Uuid*/ uuidTwo){
35
	// summary:
36
	//		Given two UUIDs to compare, this method returns 0, 1, or -1.
37
	// description:
38
	//		This method is designed to be used by sorting routines, like the
39
	//		JavaScript built-in Array sort() method. This implementation is
40
	//		intended to match the sample implementation in IETF RFC 4122:
41
	//		http://www.ietf.org/rfc/rfc4122.txt
42
	// uuidOne: Any object that has toString() method that returns a 36-character string that conforms to the UUID spec.
43
	// uuidTwo: Any object that has toString() method that returns a 36-character string that conforms to the UUID spec.
44
 
45
	// examples:
46
	//		var uuid;
47
	//		var generator = dojox.uuid.TimeBasedGenerator;
48
	//		var a = new dojox.uuid.Uuid(generator);
49
	//		var b = new dojox.uuid.Uuid(generator);
50
	//		var c = new dojox.uuid.Uuid(generator);
51
	//		var array = new Array(a, b, c);
52
	//		array.sort(dojox.uuid.Uuid.compare);
53
	var uuidStringOne = uuidOne.toString();
54
	var uuidStringTwo = uuidTwo.toString();
55
	if (uuidStringOne > uuidStringTwo) return 1;   // integer
56
	if (uuidStringOne < uuidStringTwo) return -1;  // integer
57
	return 0; // integer (either 0, 1, or -1)
58
};
59
 
60
dojox.uuid.Uuid.setGenerator = function(/*Function?*/ generator){
61
	// summary:
62
	//		Sets the default generator, which will be used by the
63
	//		"new dojox.uuid.Uuid()" constructor if no parameters
64
	//		are passed in.
65
	// generator: A UUID generator function, such as dojox.uuid.generateTimeBasedUuid.
66
	dojox.uuid.assert(!generator || dojo.isFunction(generator));
67
	dojox.uuid.Uuid._ourGenerator = generator;
68
};
69
 
70
dojox.uuid.Uuid.getGenerator = function(){
71
	// summary:
72
	//		Returns the default generator.  See setGenerator().
73
	return dojox.uuid.Uuid._ourGenerator; // generator (A UUID generator, such as dojox.uuid.TimeBasedGenerator).
74
};
75
 
76
dojox.uuid.Uuid.prototype.toString = function(){
77
	// summary:
78
	//		This method returns a standard 36-character string representing
79
	//		the UUID, such as "3b12f1df-5232-4804-897e-917bf397618a".
80
	return this._uuidString; // string
81
};
82
 
83
dojox.uuid.Uuid.prototype.compare = function(/*dojox.uuid.Uuid*/ otherUuid){
84
	// summary:
85
	//		Compares this UUID to another UUID, and returns 0, 1, or -1.
86
	// description:
87
	//		This implementation is intended to match the sample implementation
88
	//		in IETF RFC 4122: http://www.ietf.org/rfc/rfc4122.txt
89
	// otherUuid: Any object that has toString() method that returns a 36-character string that conforms to the UUID spec.
90
	return dojox.uuid.Uuid.compare(this, otherUuid); // integer (either 0, 1, or -1)
91
};
92
 
93
dojox.uuid.Uuid.prototype.isEqual = function(/*dojox.uuid.Uuid*/ otherUuid){
94
	// summary:
95
	//		Returns true if this UUID is equal to the otherUuid, or false otherwise.
96
	// otherUuid: Any object that has toString() method that returns a 36-character string that conforms to the UUID spec.
97
	return (this.compare(otherUuid) == 0); // boolean
98
};
99
 
100
dojox.uuid.Uuid.prototype.isValid = function(){
101
	// summary:
102
	//		Returns true if the UUID was initialized with a valid value.
103
	return dojox.uuid.isValid(this);
104
};
105
 
106
dojox.uuid.Uuid.prototype.getVariant = function(){
107
	// summary:
108
	//		Returns a variant code that indicates what type of UUID this is.
109
	//		Returns one of the enumerated dojox.uuid.variant values.
110
 
111
	// example:
112
	//		var uuid = new dojox.uuid.Uuid("3b12f1df-5232-4804-897e-917bf397618a");
113
	//		var variant = uuid.getVariant();
114
	//		dojox.uuid.assert(variant == dojox.uuid.variant.DCE);
115
	// example:
116
	// "3b12f1df-5232-4804-897e-917bf397618a"
117
	//                     ^
118
	//                     |
119
	//         (variant "10__" == DCE)
120
	return dojox.uuid.getVariant(this);
121
};
122
 
123
dojox.uuid.Uuid.prototype.getVersion = function(){
124
	// summary:
125
	//		Returns a version number that indicates what type of UUID this is.
126
	//		Returns one of the enumerated dojox.uuid.version values.
127
	// example:
128
	//		var uuid = new dojox.uuid.Uuid("b4308fb0-86cd-11da-a72b-0800200c9a66");
129
	//		var version = uuid.getVersion();
130
	//		dojox.uuid.assert(version == dojox.uuid.version.TIME_BASED);
131
	// exceptions:
132
	//		Throws an Error if this is not a DCE Variant UUID.
133
	if(!this._versionNumber){
134
		this._versionNumber = dojox.uuid.getVersion(this);
135
	}
136
	return this._versionNumber; // dojox.uuid.version
137
};
138
 
139
dojox.uuid.Uuid.prototype.getNode = function(){
140
	// summary:
141
	//		If this is a version 1 UUID (a time-based UUID), getNode() returns a
142
	//		12-character string with the "node" or "pseudonode" portion of the UUID,
143
	//		which is the rightmost 12 characters.
144
	// exceptions:
145
	//		Throws an Error if this is not a version 1 UUID.
146
	if (!this._nodeString) {
147
		this._nodeString = dojox.uuid.getNode(this);
148
	}
149
	return this._nodeString; // String (a 12-character string, which will look something like "917bf397618a")
150
};
151
 
152
dojox.uuid.Uuid.prototype.getTimestamp = function(/*String?*/ returnType){
153
	// summary:
154
	//		If this is a version 1 UUID (a time-based UUID), this method returns
155
	//		the timestamp value encoded in the UUID.  The caller can ask for the
156
	//		timestamp to be returned either as a JavaScript Date object or as a
157
	//		15-character string of hex digits.
158
	// returnType: Any of these five values: "string", String, "hex", "date", Date
159
	// returns:
160
	//		Returns the timestamp value as a JavaScript Date object or a 15-character string of hex digits.
161
	// examples:
162
	//		var uuid = new dojox.uuid.Uuid("b4308fb0-86cd-11da-a72b-0800200c9a66");
163
	//		var date, string, hexString;
164
	//		date   = uuid.getTimestamp();         // returns a JavaScript Date
165
	//		date   = uuid.getTimestamp(Date);     //
166
	//		string = uuid.getTimestamp(String);   // "Mon, 16 Jan 2006 20:21:41 GMT"
167
	//		hexString = uuid.getTimestamp("hex"); // "1da86cdb4308fb0"
168
	// exceptions:
169
	//		Throws an Error if this is not a version 1 UUID.
170
	if(!returnType){returnType = null};
171
	switch(returnType){
172
		case "string":
173
		case String:
174
			return this.getTimestamp(Date).toUTCString(); // String (e.g. "Mon, 16 Jan 2006 20:21:41 GMT")
175
			break;
176
		case "hex":
177
			// Return a 15-character string of hex digits containing the
178
			// timestamp for this UUID, with the high-order bits first.
179
			if (!this._timestampAsHexString) {
180
				this._timestampAsHexString = dojox.uuid.getTimestamp(this, "hex");
181
			}
182
			return this._timestampAsHexString; // String (e.g. "1da86cdb4308fb0")
183
			break;
184
		case null: // no returnType was specified, so default to Date
185
		case "date":
186
		case Date:
187
			// Return a JavaScript Date object.
188
			if (!this._timestampAsDate) {
189
				this._timestampAsDate = dojox.uuid.getTimestamp(this, Date);
190
			}
191
			return this._timestampAsDate; // Date
192
			break;
193
		default:
194
			// we got passed something other than a valid returnType
195
			dojox.uuid.assert(false, "The getTimestamp() method dojox.uuid.Uuid was passed a bogus returnType: " + returnType);
196
			break;
197
	}
198
};
199
 
200
}