Source Code Cross Referenced for Util.java in  » ESB » open-esb » com » sun » jbi » ui » common » 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 » ESB » open esb » com.sun.jbi.ui.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)Util.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.ui.common;
030:
031:        import java.lang.reflect.Constructor;
032:        import java.lang.reflect.InvocationTargetException;
033:        import java.net.InetAddress;
034:        import java.util.logging.Level;
035:        import java.util.logging.Logger;
036:
037:        /**
038:         * This object provides utility methods common for client or server side code for tools.
039:         * @author  Sun Microsystems, Inc.
040:         */
041:        public class Util {
042:            /**
043:             * resource bundle
044:             */
045:            private static I18NBundle sI18NBundle = null;
046:
047:            /** gives the I18N bundle
048:             *@return I18NBundle object
049:             */
050:            public static I18NBundle getCommonI18NBundle() {
051:                // lazzy initialize the JBI Client
052:                if (sI18NBundle == null) {
053:                    sI18NBundle = new I18NBundle("com.sun.jbi.ui.common");
054:                }
055:                return sI18NBundle;
056:            }
057:
058:            /**
059:             * prints the string to debug output
060:             * @param msg text to print
061:             */
062:            public static void logDebug(String msg) {
063:                ToolsLogManager.getCommonLogger().log(Level.FINER, msg);
064:            }
065:
066:            /**
067:             * logs the message
068:             * @param logger logger
069:             * @param ex exception
070:             */
071:            public static void logDebug(Logger logger, Exception ex) {
072:                logger.log(Level.FINER, ex.getMessage(), ex);
073:            }
074:
075:            /**
076:             * logs the message
077:             * @param ex exception
078:             */
079:            public static void logDebug(Exception ex) {
080:                logDebug(ToolsLogManager.getCommonLogger(), ex);
081:            }
082:
083:            /**
084:             * This method creates a new object of specified type using the reflection apis. It
085:             * instantiate the object using its constructor that takes String as a argument.
086:             * This is mainly used to convert the string value to a specified object type.
087:             * @param type the fully qualified name of the desired class
088:             * @param arg String value to be passed to the class constructor
089:             * @throws java.lang.ClassNotFoundException on error
090:             * @throws java.lang.NoSuchMethodException on error
091:             * @throws java.lang.InstantiationException on error
092:             * @throws java.lang.IllegalAccessException on error
093:             * @throws java.lang.reflect.InvocationTargetException on error
094:             * @return constrcuted object of the type specified with the string value
095:             */
096:            public static Object newInstance(String type, String arg)
097:                    throws ClassNotFoundException, NoSuchMethodException,
098:                    InstantiationException, IllegalAccessException,
099:                    InvocationTargetException {
100:                Class objClass = null;
101:                Object instance = null;
102:
103:                // check for the primitive types
104:                // boolean, byte, char, short, int, long, float, double and void
105:                if (type.equals("boolean")) {
106:                    objClass = Boolean.class;
107:                } else if (type.equals("byte")) {
108:                    objClass = Byte.class;
109:                } else if (type.equals("char")) {
110:                    objClass = Character.class;
111:                } else if (type.equals("short")) {
112:                    objClass = Short.class;
113:                } else if (type.equals("int")) {
114:                    objClass = Integer.class;
115:                } else if (type.equals("long")) {
116:                    objClass = Long.class;
117:                } else if (type.equals("float")) {
118:                    objClass = Float.class;
119:                } else if (type.equals("double")) {
120:                    objClass = Double.class;
121:                } else if (type.equals("void")) {
122:                    objClass = Void.class;
123:                } else {
124:                    objClass = Class.forName(type);
125:                }
126:
127:                Class[] argClass = new Class[] { String.class };
128:                Constructor objConstructor = objClass.getConstructor(argClass);
129:                String[] argValue = { arg };
130:                instance = objConstructor.newInstance(argValue);
131:                return instance;
132:            }
133:
134:            /**
135:             * This method checks that the host name is a localhost or a remote host. This method
136:             * compares the host name on which this method is getting executes with the host name
137:             * that is passed to this method. if the comparison matches it returns true.
138:             * @param host host name to check for local or remote host.
139:             * @throws java.net.UnknownHostException on errror.
140:             * @return true if the host name passed is a localhost else false.
141:             */
142:            public static boolean isLocalHost(String host)
143:                    throws java.net.UnknownHostException {
144:
145:                String localhostName = "localhost";
146:                String loopbackIP = "127.0.0.1";
147:
148:                String remoteHost = null;
149:
150:                if (host != null) {
151:                    remoteHost = host.trim().toLowerCase();
152:                }
153:
154:                logDebug("Checking for Remote HOST " + remoteHost);
155:
156:                if (remoteHost == null || remoteHost.length() == 0
157:                        || remoteHost.equalsIgnoreCase(localhostName)
158:                        || remoteHost.equalsIgnoreCase(loopbackIP)) {
159:                    return true;
160:                }
161:
162:                InetAddress localInetAddr = InetAddress.getLocalHost();
163:                String localHostIP = localInetAddr.getHostAddress();
164:
165:                // logDebug("Local Host IP " + localHostIP);
166:
167:                InetAddress[] remoteInetAddrs = InetAddress
168:                        .getAllByName(remoteHost);
169:                // logDebug("Remote InetAddress Size " + remoteInetAddrs.length);
170:
171:                for (int i = 0; i < remoteInetAddrs.length; ++i) {
172:                    String remoteHostIP = remoteInetAddrs[i].getHostAddress();
173:                    // logDebug("Comapring with Remote Host IP : " + remoteHostIP);
174:                    if (localHostIP.equalsIgnoreCase(remoteHostIP)) {
175:                        return true;
176:                    }
177:                }
178:                return false;
179:            }
180:
181:            /**
182:             * This method will return the return the host address information for the given
183:             * host name in the format of <host name> / <host ip address>.
184:             * @param host the name of the host (ip address string or name of host).
185:             * @throws java.net.UnknownHostException on error.
186:             * @return the host name in the format of <host name> / <host ip address>
187:             */
188:            public static String getHostName(String aHostName)
189:                    throws java.net.UnknownHostException {
190:                InetAddress ia = null;
191:                if ((aHostName.equalsIgnoreCase("localhost"))
192:                        || (aHostName.equals(""))) {
193:                    ia = InetAddress.getLocalHost();
194:                } else {
195:                    ia = InetAddress.getByName(aHostName);
196:                }
197:                String hostName = ia.getHostName();
198:                String hostAddress = ia.getHostAddress();
199:                String returnStr = hostName + "/" + hostAddress;
200:                return returnStr;
201:            }
202:
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.