KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > pim > ejb > session > UserManagerUtil


1 /*
2  * Generated file - Do not edit!
3  */

4 package org.enhydra.pim.ejb.session;
5
6 /**
7  * Utility class for UserManager.
8  * @generated
9  * @lomboz generated
10  */

11 public class UserManagerUtil
12 {
13
14    /** Cached local home (EJBLocalHome). Uses lazy loading to obtain its value (loaded by getLocalHome() methods). */
15    private static org.enhydra.pim.ejb.session.UserManagerLocalHome cachedLocalHome = null;
16
17    private static Object JavaDoc lookupHome(java.util.Hashtable JavaDoc environment, String JavaDoc jndiName, Class JavaDoc narrowTo) throws javax.naming.NamingException JavaDoc {
18       // Obtain initial context
19
javax.naming.InitialContext JavaDoc initialContext = new javax.naming.InitialContext JavaDoc(environment);
20       try {
21          Object JavaDoc objRef = initialContext.lookup(jndiName);
22          // only narrow if necessary
23
if (narrowTo.isInstance(java.rmi.Remote JavaDoc.class))
24             return javax.rmi.PortableRemoteObject.narrow(objRef, narrowTo);
25          else
26             return objRef;
27       } finally {
28          initialContext.close();
29       }
30    }
31
32    // Home interface lookup methods
33

34
35    /**
36     * Obtain local home interface from default initial context
37     * @return Local home interface for UserManager. Lookup using JNDI_NAME
38     */

39    public static org.enhydra.pim.ejb.session.UserManagerLocalHome getLocalHome() throws javax.naming.NamingException JavaDoc
40    {
41       if (cachedLocalHome == null) {
42             cachedLocalHome = (org.enhydra.pim.ejb.session.UserManagerLocalHome) lookupHome(null, org.enhydra.pim.ejb.session.UserManagerLocalHome.JNDI_NAME, org.enhydra.pim.ejb.session.UserManagerLocalHome.class);
43       }
44       return cachedLocalHome;
45    }
46
47    /** Cached per JVM server IP. */
48    private static String JavaDoc hexServerIP = null;
49
50    // initialise the secure random instance
51
private static final java.security.SecureRandom JavaDoc seeder = new java.security.SecureRandom JavaDoc();
52
53    /**
54     * A 32 byte GUID generator (Globally Unique ID). These artificial keys SHOULD <strong>NOT </strong> be seen by the user,
55     * not even touched by the DBA but with very rare exceptions, just manipulated by the database and the programs.
56     *
57     * Usage: Add an id field (type java.lang.String) to your EJB, and add setId(XXXUtil.generateGUID(this)); to the ejbCreate method.
58     */

59    public static final String JavaDoc generateGUID(Object JavaDoc o) {
60        StringBuffer JavaDoc tmpBuffer = new StringBuffer JavaDoc(16);
61        if (hexServerIP == null) {
62            java.net.InetAddress JavaDoc localInetAddress = null;
63            try {
64                // get the inet address
65
localInetAddress = java.net.InetAddress.getLocalHost();
66            }
67            catch (java.net.UnknownHostException JavaDoc uhe) {
68                System.err.println("UserManagerUtil: Could not get the local IP address using InetAddress.getLocalHost()!");
69                // todo: find better way to get around this...
70
uhe.printStackTrace();
71                return null;
72            }
73            byte serverIP[] = localInetAddress.getAddress();
74            hexServerIP = hexFormat(getInt(serverIP), 8);
75        }
76        String JavaDoc hashcode = hexFormat(System.identityHashCode(o), 8);
77        tmpBuffer.append(hexServerIP);
78        tmpBuffer.append(hashcode);
79
80        long timeNow = System.currentTimeMillis();
81        int timeLow = (int)timeNow & 0xFFFFFFFF;
82        int node = seeder.nextInt();
83
84        StringBuffer JavaDoc guid = new StringBuffer JavaDoc(32);
85        guid.append(hexFormat(timeLow, 8));
86        guid.append(tmpBuffer.toString());
87        guid.append(hexFormat(node, 8));
88        return guid.toString();
89    }
90
91    private static int getInt(byte bytes[]) {
92        int i = 0;
93        int j = 24;
94        for (int k = 0; j >= 0; k++) {
95            int l = bytes[k] & 0xff;
96            i += l << j;
97            j -= 8;
98        }
99        return i;
100    }
101
102    private static String JavaDoc hexFormat(int i, int j) {
103        String JavaDoc s = Integer.toHexString(i);
104        return padHex(s, j) + s;
105    }
106
107    private static String JavaDoc padHex(String JavaDoc s, int i) {
108        StringBuffer JavaDoc tmpBuffer = new StringBuffer JavaDoc();
109        if (s.length() < i) {
110            for (int j = 0; j < i - s.length(); j++) {
111                tmpBuffer.append('0');
112            }
113        }
114        return tmpBuffer.toString();
115    }
116
117 }
Popular Tags