Source Code Cross Referenced for UcmClassURLHelper.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » ui » util » ucm » 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 » cbesb 1.2 » com.bostechcorp.cbesb.ui.util.ucm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.bostechcorp.cbesb.ui.util.ucm;
002:
003:        import java.io.File;
004:        import java.io.FileFilter;
005:        import java.io.IOException;
006:        import java.net.MalformedURLException;
007:        import java.net.URL;
008:        import java.net.URLClassLoader;
009:        import java.util.HashMap;
010:        import java.util.Vector;
011:
012:        import org.apache.commons.logging.Log;
013:        import org.apache.commons.logging.LogFactory;
014:
015:        import com.bostechcorp.cbesb.common.util.EsbPathHelper;
016:
017:        public class UcmClassURLHelper {
018:            private static URL[] runtimeUrls = null;
019:            private static final Log log = LogFactory
020:                    .getLog(UcmClassURLHelper.class);
021:            private static Vector<URL> runtimeUrlsList = new Vector<URL>();
022:            public final static String SUFFIX = "cbesb-core-1.0";//$NON-NLS-1$
023:            private static HashMap<String, Vector<URL>> saUrlsMap = new HashMap<String, Vector<URL>>();
024:
025:            /*
026:             * Extract the runtime URLs from the environment variable.
027:             *
028:             */
029:            static {
030:
031:                String home = EsbPathHelper.getCbesbHomeDir();
032:                String libPath = "";
033:                if (home != null) {
034:                    libPath = home + "/lib/ext/" + SUFFIX;
035:
036:                    File libDir = new File(libPath);//$NON-NLS-1$ //$NON-NLS-2$
037:
038:                    // Lists every modules in the lib dir
039:                    File[] jars = libDir.listFiles(new FileFilter() {
040:                        public boolean accept(File file) {
041:                            return (file.toString().endsWith(".jar"));//$NON-NLS-1$
042:                        }
043:                    });
044:
045:                    if (jars != null) {
046:
047:                        runtimeUrls = new URL[jars.length];
048:
049:                        for (int i = 0; i < jars.length; i++) {
050:                            File jarFile = jars[i];
051:                            try {
052:                                runtimeUrls[i] = jarFile.toURL();
053:
054:                                runtimeUrlsList.add(runtimeUrls[i]);
055:                            } catch (IOException ioe) {
056:                                //TODO handle Exception
057:                                Log log = LogFactory
058:                                        .getLog(UcmClassURLHelper.class);
059:                                log
060:                                        .error("environment variable CBESB is malformed: "
061:                                                + ioe);
062:                            }
063:
064:                        }
065:                    }
066:                }
067:            }
068:
069:            public static void addProjectLibExtToPath(String saName,
070:                    String saLocation) {
071:                File libDir = new File(saLocation + "/lib/optional");//$NON-NLS-1$ //$NON-NLS-2$
072:
073:                // Lists every modules in the lib dir
074:                File[] jars = libDir.listFiles(new FileFilter() {
075:                    public boolean accept(File file) {
076:                        return (file.toString().endsWith(".jar"));//$NON-NLS-1$
077:                    }
078:                });
079:
080:                if (jars != null) {
081:
082:                    for (int i = 0; i < jars.length; i++) {
083:                        File jarFile = jars[i];
084:                        addToPath(saName, jarFile.getAbsolutePath());
085:
086:                    }
087:                }
088:            }
089:
090:            public static void addUcmJarToPath(String saName, String saLocation) {
091:
092:                File ucmJar = new File(saLocation
093:                        + "/lib/CBESB_ucm_" + saName + ".jar");//$NON-NLS-1$ //$NON-NLS-2$
094:
095:                if (ucmJar.exists()) {
096:                    addToPath(saName, ucmJar.getAbsolutePath());
097:                }
098:
099:            }
100:
101:            /*
102:             * Add to the SA URL list
103:             */
104:            public static void addToPath(String saName, String newPath) {
105:                log.debug("addToPath(" + saName + ", " + newPath + ")\n\n");
106:
107:                try {
108:                    URL newUrl = null;
109:                    try {
110:                        newUrl = new URL(newPath);
111:                    } catch (MalformedURLException e) {
112:                        // if its malformed then try to evaluate it as a file
113:                        newUrl = new File(newPath).toURL();
114:                    }
115:                    Vector<URL> saList = saUrlsMap.get(saName);
116:                    if (saList == null) {
117:                        saList = new Vector<URL>();
118:                        saUrlsMap.put(saName, saList);
119:                    }
120:                    if (!saList.contains(newUrl))
121:                        saList.add(newUrl);
122:                } catch (Exception e) {
123:                    Log log = LogFactory.getLog(UcmClassURLHelper.class);
124:                    log.error("error in RuntimeClassLoader addToPath("
125:                            + newPath + ") " + e);
126:                }
127:            }
128:
129:            /*
130:             * Contructs a URLClassLoader from the CBESB_CLASSPATH environment variable.
131:             *
132:             * @param  parent  An object to use as the source of the parent class loader
133:             * @return a URLClassLoader to use for runtime objects such as translates and parsers.
134:             */
135:            public static URL[] getURL() {
136:                // add the system class path to the runtime URL list
137:                URLClassLoader systemLoader = (URLClassLoader) ClassLoader
138:                        .getSystemClassLoader();
139:                URL[] sysUrls = systemLoader.getURLs();
140:
141:                URL[] newUrls = new URL[runtimeUrlsList.size() + sysUrls.length];
142:                runtimeUrlsList.toArray(newUrls);
143:                int dest = runtimeUrlsList.size();
144:                for (int i = 0; i < sysUrls.length; i++) {
145:                    newUrls[dest++] = sysUrls[i];
146:                }
147:                return newUrls;
148:
149:            }
150:
151:            /*
152:             * Contructs a service assembly specific URLClassLoader from the CBESB_CLASSPATH environment
153:             * variable and the SA URL list.
154:             *
155:             * @param  saName The service assembly name
156:             * @param  parent  An object to use as the source of the parent class loader
157:             * @return a URLClassLoader to use for runtime objects such as translates and parsers.
158:             */
159:            public static URL[] getURL(String saName, String saLocation) {
160:                if (saName == null)
161:                    return getURL();
162:
163:                addUcmJarToPath(saName, saLocation);
164:                addProjectLibExtToPath(saName, saLocation);
165:                // calculate the total url list size
166:                int urlCount = runtimeUrlsList.size();
167:                Vector<URL> saUrlsList = saUrlsMap.get(saName);
168:                if (saUrlsList != null)
169:                    urlCount += saUrlsList.size();
170:                // add the system class path to the runtime URL list
171:                URLClassLoader systemLoader = (URLClassLoader) ClassLoader
172:                        .getSystemClassLoader();
173:                URL[] sysUrls = systemLoader.getURLs();
174:                urlCount += sysUrls.length;
175:
176:                URL[] newUrls = new URL[urlCount];
177:                // populate the url list
178:                runtimeUrlsList.toArray(newUrls);
179:                int dest = runtimeUrlsList.size();
180:                if (saUrlsList != null) {
181:                    int src = 0;
182:                    for (; src < saUrlsList.size(); src++)
183:                        newUrls[dest++] = saUrlsList.elementAt(src);
184:                }
185:                for (int i = 0; i < sysUrls.length; i++)
186:                    newUrls[dest++] = sysUrls[i];
187:
188:                return newUrls;
189:            }
190:
191:            public static void clearSaPath(String saName) {
192:                saUrlsMap.remove(saName);
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.