public Object coerce(Object original, Class target) {
if (original instanceof CharSequence) {
String url = String.valueOf( original );
if (url.startsWith("file:/")) {
return url.endsWith("/") || IVirtualDirectory.class.isAssignableFrom(target) ? new SystemDirectory( url.substring(6) ) : new SystemFile( url.substring(6) );
} else if (url.startsWith(VirtualArtifactSystem.VAS_PROTOCOL + ":")) {
String host = url.split(":")[1];
String path = url.substring((VirtualArtifactSystem.VAS_PROTOCOL + ":" + host + ":").length());
VirtualArtifactSystem vas = VirtualArtifactSystem.get(host, true);
return url.endsWith("/") ? vas.getDirectory(new SimplePath(path), true) : vas.getFile(new SimplePath(path), true);
} else {
return url.endsWith("/") || IVirtualDirectory.class.isAssignableFrom(target) ? new SystemDirectory(url) : new SystemFile(url);
}
} else if (original instanceof IVirtualArtifact) {
String url = ((IVirtualArtifact)original).getURL().toExternalForm();
if (original instanceof IVirtualDirectory && !url.endsWith("/")) url += "/";