001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.visualweb.j2ee15classloaderprovider;
043:
044: import java.io.File;
045: import java.net.MalformedURLException;
046: import java.net.URL;
047: import java.net.URLClassLoader;
048: import java.util.ArrayList;
049: import java.util.List;
050: import java.util.Properties;
051:
052: import org.netbeans.modules.visualweb.classloaderprovider.CommonClassloaderProvider;
053: import org.openide.ErrorManager;
054: import org.openide.filesystems.FileObject;
055: import org.openide.filesystems.FileUtil;
056: import org.openide.filesystems.URLMapper;
057:
058: /**
059: * This Common ClassLaoder provider simply return its ClassLoader which happens
060: * to be the module ClassLoader. This module declares dependencies on the
061: * modules that wrap the J2EE 1.5 platform libraries that are shared between the
062: * IDE implementation and the user project. This provider is available through
063: * the lookup.
064: * <p>
065: * The user project's meta data is be used to determine which J2EE platform it is using.
066: *
067: * @author Sandip V. Chitale (Sandip.Chitale@Sun.Com)
068: */
069: public class J2EE15CommonClassloaderProvider implements
070: CommonClassloaderProvider {
071: private String[] designtimeJars = {
072: // XXX Need to add these jars here so that META-INF/faces-config.xml files can be
073: // discovered and loaded by the JSF1.2 RI. Ideally thin jars containing
074: // the META-INF/faces-config.xml should be used. The classes should be loded
075: // from the modules themselves.
076: "jar:nbinst:///modules/org-netbeans-modules-visualweb-jsfsupport-designtime.jar!/",
077: "jar:nbinst:///modules/org-netbeans-modules-visualweb-jsfsupport-designtime_1_2.jar!/",
078: "jar:nbinst:///modules/ext/webui-jsf-dt.jar!/", };
079:
080: private URLClassLoader urlClassLoader;
081:
082: public J2EE15CommonClassloaderProvider() {
083: }
084:
085: public ClassLoader getClassLoader() {
086: synchronized (this ) {
087: if (urlClassLoader == null) {
088: List normalizedUrls = new ArrayList();
089:
090: for (int i = 0; i < designtimeJars.length; i++) {
091: try {
092: URL url = new URL(designtimeJars[i]);
093: FileObject fileObject = URLMapper
094: .findFileObject(url);
095:
096: //file inside library is broken
097: if (fileObject == null)
098: continue;
099:
100: if ("jar".equals(url.getProtocol())) { //NOI18N
101: fileObject = FileUtil
102: .getArchiveFile(fileObject);
103: }
104: File f = FileUtil.toFile(fileObject);
105: if (f != null) {
106:
107: URL entry = f.toURI().toURL();
108: if (FileUtil.isArchiveFile(entry)) {
109: entry = FileUtil.getArchiveRoot(entry);
110: } else if (!f.exists()) {
111: // if file does not exist (e.g. build/classes folder
112: // was not created yet) then corresponding File will
113: // not be ended with slash. Fix that.
114: assert !entry.toExternalForm()
115: .endsWith("/") : f; // NOI18N
116: entry = new URL(entry.toExternalForm()
117: + "/"); // NOI18N
118: }
119: normalizedUrls.add(entry);
120:
121: }
122: } catch (MalformedURLException mue) {
123: ErrorManager.getDefault().notify(
124: ErrorManager.INFORMATIONAL, mue);
125: }
126: }
127: urlClassLoader = new URLClassLoader(
128: (URL[]) normalizedUrls.toArray(new URL[0]),
129: getClass().getClassLoader());
130: }
131: }
132: return urlClassLoader;
133: }
134:
135: public boolean isCapableOf(Properties capabilities) {
136: if (JAVA_EE_5.equals(capabilities.getProperty(J2EE_PLATFORM))) {
137: return true;
138: }
139: return false;
140: }
141: }
|