01: /**********************************************************************
02: Copyright (c) 2005 Andy Jefferson and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15:
16: Contributors:
17: ...
18: **********************************************************************/package org.jpox.store.poid;
19:
20: import java.util.Properties;
21:
22: import org.jpox.util.TypeConversionHelper;
23:
24: /**
25: * Poid generator for a UUID String format.
26: * Results in Strings of length 16 characters, containing the IP address of the local machine
27: * as per the JDO2 spec section 18.6.1.
28: *
29: * @version $Revision: 1.3 $
30: */
31: public class UUIDStringPoidGenerator extends AbstractUUIDPoidGenerator {
32: /**
33: * Constructor.
34: * @param name Symbolic name for this generator
35: * @param props Properties controlling its behaviour
36: */
37: public UUIDStringPoidGenerator(String name, Properties props) {
38: super (name, props);
39: }
40:
41: /**
42: * Create an identifier with the form "IIIIJJJJHHLLLLCC".
43: * Where IIII is the IP address, JJJJ is something unique across JVMs,
44: * HH is the High Time, LLLL is the low time, and CC is a count.
45: * @return The identifier
46: */
47: protected String getIdentifier() {
48: StringBuffer str = new StringBuffer(16);
49:
50: str.append(TypeConversionHelper.getStringFromInt(IP_ADDRESS));
51: str.append(TypeConversionHelper.getStringFromInt(JVM_UNIQUE));
52: short timeHigh = (short) (System.currentTimeMillis() >>> 32);
53: str.append(TypeConversionHelper.getStringFromShort(timeHigh));
54: int timeLow = (int) System.currentTimeMillis();
55: str.append(TypeConversionHelper.getStringFromInt(timeLow));
56: str.append(TypeConversionHelper.getStringFromShort(getCount()));
57:
58: return str.toString();
59: }
60: }
|