Created
May 31, 2011 06:01
-
-
Save tfennelly/1000042 to your computer and use it in GitHub Desktop.
VFSPackageScanClassResolver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* JBoss, Home of Professional Open Source | |
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors | |
* as indicated by the @authors tag. All rights reserved. | |
* See the copyright.txt in the distribution for a | |
* full listing of individual contributors. | |
* * | |
* This copyrighted material is made available to anyone wishing to use, | |
* modify, copy, or redistribute it subject to the terms and conditions | |
* of the GNU Lesser General Public License, v. 2.1. | |
* This program is distributed in the hope that it will be useful, but WITHOUT A | |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | |
* You should have received a copy of the GNU Lesser General Public License, | |
* v.2.1 along with this distribution; if not, write to the Free Software | |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
* MA 02110-1301, USA. | |
*/ | |
package org.switchyard.component.camel.deploy; | |
import org.apache.camel.impl.DefaultPackageScanClassResolver; | |
import java.io.IOException; | |
import java.net.MalformedURLException; | |
import java.net.URI; | |
import java.net.URISyntaxException; | |
import java.net.URL; | |
/** | |
* JBoss VFS package scan Class resolver. | |
* | |
* @author <a href="mailto:[email protected]">[email protected]</a> | |
*/ | |
public class VFSPackageScanClassResolver extends DefaultPackageScanClassResolver { | |
private static final String VFS = "vfs"; | |
private static final String[] ARCHIVE_TYPES = new String[] {".jar", ".zip", ".sar", ".ear", ".war"}; | |
@Override | |
protected URL customResourceLocator(URL url) throws IOException { | |
try { | |
URI uri = url.toURI(); | |
if (VFS.equals(uri.getScheme())) { | |
return translate(uri).toURL(); | |
} else { | |
return super.customResourceLocator(url); | |
} | |
} catch (Exception e) { | |
return super.customResourceLocator(url); | |
} | |
} | |
/** | |
* Translate a VFS URI into a file based URI that can be understood by | |
* DefaultPackageScanClassResolver (super class). | |
* @param uri The URI to be translated. | |
* @return The translated URI. | |
* @throws URISyntaxException URI Syntax exception. | |
* @throws MalformedURLException badly formed URL exception. | |
*/ | |
protected static URI translate(URI uri) throws URISyntaxException, MalformedURLException { | |
if (VFS.equals(uri.getScheme())) { | |
String path = uri.getPath(); | |
for (String archiveType : ARCHIVE_TYPES) { | |
int indexOfResource = path.indexOf(archiveType + "/"); | |
if (indexOfResource != -1) { | |
path = path.substring(0, indexOfResource + archiveType.length()); | |
break; | |
} | |
} | |
return new URI("file:" + path); | |
} else { | |
throw new RuntimeException("Invalid URL scheme on URL '" + uri + "'. Must be a 'vfs' scheme."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment