Source Code Cross Referenced for TierUtil.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jtests » beans » relation » tier » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.jtests.beans.relation.tier 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.jonas.jtests.beans.relation.tier;
002:
003:        /**
004:         * Utility class for Tier.
005:         */
006:        public class TierUtil {
007:
008:            private static Object lookupHome(java.util.Hashtable environment,
009:                    String jndiName, Class narrowTo)
010:                    throws javax.naming.NamingException {
011:                // Obtain initial context
012:                javax.naming.InitialContext initialContext = new javax.naming.InitialContext(
013:                        environment);
014:                try {
015:                    Object objRef = initialContext.lookup(jndiName);
016:                    // only narrow if necessary
017:                    if (narrowTo.isInstance(java.rmi.Remote.class))
018:                        return javax.rmi.PortableRemoteObject.narrow(objRef,
019:                                narrowTo);
020:                    else
021:                        return objRef;
022:                } finally {
023:                    initialContext.close();
024:                }
025:            }
026:
027:            // Home interface lookup methods
028:
029:            /**
030:             * Obtain local home interface from default initial context
031:             * @return Local home interface for Tier. Lookup using COMP_NAME
032:             */
033:            public static TierLocalHome getLocalHome()
034:                    throws javax.naming.NamingException {
035:                return (TierLocalHome) lookupHome(null,
036:                        TierLocalHome.COMP_NAME, TierLocalHome.class);
037:            }
038:
039:            /** Cached per JVM server IP. */
040:            private static String hexServerIP = null;
041:
042:            // initialise the secure random instance
043:            private static final java.security.SecureRandom seeder = new java.security.SecureRandom();
044:
045:            /**
046:             * A 32 byte GUID generator (Globally Unique ID). These artificial keys
047:             * SHOULD <strong>NOT </strong> be seen by the user, not even touched by the
048:             * DBA but with very rare exceptions, just manipulated by the database and
049:             * the programs. Usage: Add an id field (type java.lang.String) to your EJB,
050:             * and add setId(XXXUtil.generateGUID(this)); to the ejbCreate method.
051:             */
052:            public static final String generateGUID(Object o) {
053:                StringBuffer tmpBuffer = new StringBuffer(16);
054:                if (hexServerIP == null) {
055:                    java.net.InetAddress localInetAddress = null;
056:                    try {
057:                        // get the inet address
058:
059:                        localInetAddress = java.net.InetAddress.getLocalHost();
060:                    } catch (java.net.UnknownHostException uhe) {
061:                        System.err
062:                                .println("TierUtil: Could not get the local IP address using InetAddress.getLocalHost()!");
063:                        // todo: find better way to get around this...
064:                        uhe.printStackTrace();
065:                        return null;
066:                    }
067:                    byte serverIP[] = localInetAddress.getAddress();
068:                    hexServerIP = hexFormat(getInt(serverIP), 8);
069:                }
070:
071:                String hashcode = hexFormat(System.identityHashCode(o), 8);
072:                tmpBuffer.append(hexServerIP);
073:                tmpBuffer.append(hashcode);
074:
075:                long timeNow = System.currentTimeMillis();
076:                int timeLow = (int) timeNow & 0xFFFFFFFF;
077:                int node = seeder.nextInt();
078:
079:                StringBuffer guid = new StringBuffer(32);
080:                guid.append(hexFormat(timeLow, 8));
081:                guid.append(tmpBuffer.toString());
082:                guid.append(hexFormat(node, 8));
083:                return guid.toString();
084:            }
085:
086:            private static int getInt(byte bytes[]) {
087:                int i = 0;
088:                int j = 24;
089:                for (int k = 0; j >= 0; k++) {
090:                    int l = bytes[k] & 0xff;
091:                    i += l << j;
092:                    j -= 8;
093:                }
094:                return i;
095:            }
096:
097:            private static String hexFormat(int i, int j) {
098:                String s = Integer.toHexString(i);
099:                return padHex(s, j) + s;
100:            }
101:
102:            private static String padHex(String s, int i) {
103:                StringBuffer tmpBuffer = new StringBuffer();
104:                if (s.length() < i) {
105:                    for (int j = 0; j < i - s.length(); j++) {
106:                        tmpBuffer.append('0');
107:                    }
108:                }
109:                return tmpBuffer.toString();
110:            }
111:
112:        }
w_w___w._ja__va___2___s___.c___om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.