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