001/* 002 * ModeShape (http://www.modeshape.org) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.modeshape.common.util; 017 018import org.modeshape.common.logging.Logger; 019import java.net.MalformedURLException; 020import java.net.URL; 021import java.net.URLClassLoader; 022import java.util.List; 023 024/** 025 * Extension of a {@link URLClassLoader} which accepts a list of strings instead of urls, trying to convert each string to an 026 * url. If a string cannot be converted to a URL, it is discarded. 027 * 028 * @author Horia Chiorean 029 */ 030public final class StringURLClassLoader extends URLClassLoader { 031 032 private static final Logger LOGGER = Logger.getLogger(StringURLClassLoader.class); 033 034 public StringURLClassLoader( List<String> urls ) { 035 super(new URL[0], null); 036 CheckArg.isNotNull(urls, "urls"); 037 for (String url : urls) { 038 try { 039 super.addURL(new URL(url)); 040 } catch (MalformedURLException e) { 041 LOGGER.debug("{0} is not a valid url ", url); 042 } 043 } 044 } 045}