package org.jboss.fresh.shell.commands;
import org.jboss.fresh.vfs.RootVFS;
import org.jboss.fresh.vfs.VFS;
import org.jboss.fresh.io.BufferWriter;
import org.jboss.fresh.io.PrintWriter2;
import org.jboss.fresh.registry.RegistryContext;
import org.jboss.fresh.shell.AbstractExecutable;
import java.util.Iterator;
import java.util.Map;
import javax.naming.NameNotFoundException;
// EX OK
public class MountExe extends AbstractExecutable {
private static transient org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(MountExe.class);
/**
Sets the new system property value.
*/
public void process(String exepath, String[] params) throws Exception {
log.debug("entered");
PrintWriter2 out = new PrintWriter2(new BufferWriter(getStdOut()));
if (helpRequested() || (params.length != 2 && params.length != 0)) {
out = new PrintWriter2(new BufferWriter(getStdOut()));
out.println("Usage: mount [--help] [<path> <vfs>]");
out.println(" path : mount point");
out.println(" vfs : pointer to vfs bound in registry");
out.println(" --help : this help");
out.println();
out.println(" Run without parameters it shows a list of mounts");
out.close();
log.debug("done");
return;
}
RootVFS rootfs = null;
RegistryContext ctx = new RegistryContext();
try {
rootfs = (RootVFS) ctx.lookup("java:/CP2/VFS");
} catch(ClassCastException ex) {
error("VFS bound at java:/CP2/VFS is not RootVFS");
return;
} catch(NameNotFoundException ex) {
error("Root VFS not bound (should be at: java:/CP2/VFS)");
return;
}
if(params.length == 0) {
Iterator it = rootfs.listMounts().entrySet().iterator();
while(it.hasNext()) {
Map.Entry ent = (Map.Entry) it.next();
out.println(ent.getKey() + "\t\t" + ent.getValue());
}
out.flush();
return;
}
String path = params[0];
String jndi = params[1];
VFS vfs = null;
try {
vfs = (VFS) ctx.lookup(jndi);
} catch(NameNotFoundException ex) {
error("No VFS bound at: " + jndi);
return;
}
if(rootfs instanceof RootVFS) {
rootfs.mount(path, vfs);
} else {
error("Root VFS does not implement RootVFS - doesn't support mounting");
return;
}
log.debug("done");
}
}