01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/citations/tags/sakai_2-4-1/citations-osid/web2bridge/src/java/edu/indiana/lib/osid/component/id/Id.java $
03: * $Id: Id.java 22658 2007-03-15 13:24:38Z jimeng@umich.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package edu.indiana.lib.osid.component.id;
21:
22: import java.util.Random;
23:
24: /**
25: * @inheritDoc
26: */
27: public class Id implements org.osid.shared.Id {
28: private static org.apache.commons.logging.Log _log = edu.indiana.lib.twinpeaks.util.LogUtils
29: .getLog(Id.class);
30:
31: private static long idBase = System.currentTimeMillis();
32: private String idString = null;
33:
34: private synchronized long getIdBase() {
35: return idBase++;
36: }
37:
38: private void log(String entry)
39: throws org.osid.shared.SharedException {
40: _log.debug("Id: " + entry);
41: }
42:
43: protected Id() throws org.osid.shared.SharedException {
44: long base;
45: Random random;
46:
47: base = getIdBase();
48: random = new Random(base);
49:
50: idString = String.valueOf(base) + "-"
51: + String.valueOf(random.nextLong());
52: random = null;
53: }
54:
55: protected Id(String idString)
56: throws org.osid.shared.SharedException {
57: if (idString == null) {
58: throw new org.osid.shared.SharedException(
59: org.osid.id.IdException.NULL_ARGUMENT);
60: }
61: this .idString = idString;
62: }
63:
64: public String getIdString() throws org.osid.shared.SharedException {
65: return this .idString;
66: }
67:
68: public boolean isEqual(org.osid.shared.Id id)
69: throws org.osid.shared.SharedException {
70: return id.getIdString().equals(this.idString);
71: }
72: }
|