[jboss-cvs] JBossAS SVN: r88015 - projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 29 12:35:08 EDT 2009


Author: ctomc
Date: 2009-04-29 12:35:08 -0400 (Wed, 29 Apr 2009)
New Revision: 88015

Added:
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/BaseService.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ContextBinder.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ContextBinderMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/Cp2ConfigurationService.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/Cp2ConfigurationServiceMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/DummyService.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/DummyServiceMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JNDICtxBinder.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JNDICtxBinderMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JavaBeanBinderService.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JavaBeanBinderServiceMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/NamingBinder.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/NamingBinderMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/PoolService.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/PoolServiceMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RegistryNamingBinder.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RegistryNamingBinderMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RootVFSService.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RootVFSServiceMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ServiceAlreadyStartedException.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ServiceModule.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ServiceModuleMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ShellExecutorService.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ShellExecutorServiceMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/SystemShellService.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/SystemShellServiceMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSFileService.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSFileServiceMBean.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSService.java
   projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSServiceMBean.java
Log:
deployers

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/BaseService.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/BaseService.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/BaseService.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,34 @@
+package org.jboss.fresh.deployer;
+
+import javax.management.ObjectName;
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+
+public class BaseService implements MBeanRegistration {
+
+	private ObjectName mbname;
+
+	// override this method if you want to perform something or you want to override ObjectName of the mbean
+	public ObjectName preRegister(MBeanServer server, ObjectName name) throws java.lang.Exception {
+		mbname = name;
+		return mbname;
+	}
+
+	public void postRegister(Boolean registrationDone) {
+	}
+
+	public void preDeregister() throws java.lang.Exception {
+	}
+
+	public void postDeregister() {
+	}
+	
+	public ObjectName getObjectName() {
+		return mbname;
+	}
+
+	// you can call this method from extended constructor to set mbname
+	protected void setObjectName(ObjectName oname) {
+		mbname = oname;
+	}
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ContextBinder.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ContextBinder.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ContextBinder.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,41 @@
+/*
+ * Created on 2004.10.25
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.jboss.fresh.deployer;
+
+import org.jboss.fresh.ctx.FlatContext;
+
+/**
+ * @author strukelj
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class ContextBinder extends RegistryNamingBinder implements ContextBinderMBean {
+
+	/**
+	 * 
+	 */
+	public ContextBinder() {
+		super();
+		// TODO Auto-generated constructor stub
+	}
+
+	/* (non-Javadoc)
+	 * @see com.parsek.deployer.modules.RegistryNamingBinder#classToInstance(java.lang.Class)
+	 */
+	protected Object classToInstance(Class c) {
+		return new FlatContext();
+	}
+
+	/* (non-Javadoc)
+	 * @see com.parsek.deployer.modules.RegistryNamingBinder#getBindClass()
+	 */
+	protected String getBindClass() {
+		return "com.parsek.ctx.Context";
+	}
+
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ContextBinderMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ContextBinderMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ContextBinderMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,17 @@
+/*
+ * Created on 2004.10.25
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.jboss.fresh.deployer;
+
+/**
+ * @author strukelj
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public interface ContextBinderMBean extends RegistryNamingBinderMBean {
+
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/Cp2ConfigurationService.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/Cp2ConfigurationService.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/Cp2ConfigurationService.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,100 @@
+package org.jboss.fresh.deployer;
+
+import org.jboss.fresh.parsek.cpii.Cp2Configuration;
+
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+public class Cp2ConfigurationService extends RegistryNamingBinder implements Cp2ConfigurationServiceMBean {
+
+    private String jndiName;
+    private Properties props;
+
+    public Cp2ConfigurationService() {
+    }
+
+    public Cp2ConfigurationService(String properties) {
+
+        props = new Properties();
+        Cp2Configuration.updateConfiguration(props);
+        StringTokenizer st = new StringTokenizer(properties, "|");
+        while (st.hasMoreTokens()) {
+            String line = st.nextToken();
+            StringTokenizer lineTokenizer = new StringTokenizer(line, "=");
+            String name = lineTokenizer.nextToken().trim();
+            String value = lineTokenizer.nextToken().trim();
+            props.setProperty(name, value);
+        }
+    }
+
+
+    public void setProperties(Properties properties) {
+        props = properties;
+    }
+
+
+    public Properties getProperties() {
+        return props;
+    }
+
+
+    public String getName() {
+        return "Cp2ConfigurationService";
+    }
+
+
+    public void setProperty(String name, String value) {
+        props.setProperty(name, value);
+    }
+
+
+    public String removeProperty(String name) {
+        String value = (String) props.remove(name);
+        return ("Property named " + name + " had a value >" + value + "<.</BR>");
+    }
+
+
+    protected String getBindClass() {
+        return java.util.Map.class.getName();
+    }
+
+
+    protected Object classToInstance(Class c) {
+
+        // instaliraj se kot NotificationListener
+
+        // create pool instance.
+        // set factory
+
+        try {
+            Cp2Configuration.updateConfiguration(props);
+            Cp2Configuration.diagnoseJNDIConf();
+
+            System.out.println(Cp2Configuration.getString(Cp2Configuration.GLOBAL_CONFIGURATION_JNDI_NAME));
+            System.out.println(Cp2Configuration.getString(Cp2Configuration.USER_TRANSACTION_JNDI_NAME_PROPERTY));
+            System.out.println(Cp2Configuration.getBoolean(Cp2Configuration.JNDI_BIND_REFERENCES_PROPERTY));
+            System.out.println(Cp2Configuration.getBoolean(Cp2Configuration.JNDI_SUPPORTS_NON_SERIALIZABLE));
+            System.out.println(Cp2Configuration.getBoolean(Cp2Configuration.JNDI_SUPPORTS_SUBCONTEXTS));
+
+            setServiceObject(props);
+            return props;
+
+        } catch (Exception ex) {
+            throw new RuntimeException(ex.toString());
+        }
+    }
+
+
+    public String viewConfiguration() {
+        StringBuffer buf = new StringBuffer();
+        Iterator names = props.keySet().iterator();
+        while (names.hasNext()) {
+            String name = (String) names.next();
+            buf.append(name + " = >" + props.getProperty(name) + "<</BR>");
+        }
+
+        return buf.toString();
+    }
+
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/Cp2ConfigurationServiceMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/Cp2ConfigurationServiceMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/Cp2ConfigurationServiceMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,13 @@
+package org.jboss.fresh.deployer;
+
+import java.util.Properties;
+
+
+public interface Cp2ConfigurationServiceMBean extends RegistryNamingBinderMBean {
+    
+	public void setProperty( String name, String value );
+	public String removeProperty( String name );	
+	public String viewConfiguration();
+	public void setProperties(Properties props);
+	public Properties getProperties();
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/DummyService.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/DummyService.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/DummyService.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,9 @@
+package org.jboss.fresh.deployer;
+
+
+public class DummyService extends ServiceModule implements DummyServiceMBean {
+
+    public String getName() {
+        return "DummyService";
+    }
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/DummyServiceMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/DummyServiceMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/DummyServiceMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,5 @@
+package org.jboss.fresh.deployer;
+
+
+public interface DummyServiceMBean extends ServiceModuleMBean {
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JNDICtxBinder.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JNDICtxBinder.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JNDICtxBinder.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,70 @@
+package org.jboss.fresh.deployer;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.jboss.fresh.ctx.FlatContext;
+import org.jboss.fresh.ctx.JNDICtx;
+
+public class JNDICtxBinder extends RegistryNamingBinder implements JNDICtxBinderMBean {
+
+    private String mappings;
+    private Map map = new HashMap();
+
+    public String getName() {
+        return "JNDICtxBinder";
+    }
+
+    public void setMappings(String str) {
+        try {
+            this.mappings = str;
+
+            InputStream in = new ByteArrayInputStream(str.getBytes());
+            Properties p = new Properties();
+            p.load(in);
+
+            Enumeration enom = p.propertyNames();
+            while (enom.hasMoreElements()) {
+                String key = (String) enom.nextElement();
+                map.put(key, p.getProperty(key));
+            }
+        } catch (Exception ex) {
+            throw new RuntimeException("Error configuring mappings: " + ex.toString());
+        }
+    }
+
+    public String getMappings() {
+        return mappings;
+    }
+
+    protected String getBindClass() {
+        return "com.parsek.ctx.Context";
+    }
+
+    protected Object classToInstance(Class c) {
+
+        // create it
+        // set mappings
+        // return
+
+        FlatContext ctx = new FlatContext();
+
+        JNDICtx jctx = new JNDICtx();
+        jctx.setMappings(map);
+        ctx.registerDelegate(jctx);
+        
+        setServiceObject(ctx);
+        return ctx;
+
+    }
+
+    protected boolean bindByReference() {
+	return true;
+    }
+
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JNDICtxBinderMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JNDICtxBinderMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JNDICtxBinderMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,12 @@
+package org.jboss.fresh.deployer;
+
+
+public interface JNDICtxBinderMBean extends RegistryNamingBinderMBean {
+
+    public void setMappings(String str);
+
+    public String getMappings();
+
+}
+
+

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JavaBeanBinderService.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JavaBeanBinderService.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JavaBeanBinderService.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,54 @@
+package org.jboss.fresh.deployer;
+
+/**
+ * @author strukelj
+ * @version $Revision$
+ * @created 11.11.2005, 12:16:59
+ * @date $Date$
+ * @source $Source$
+ * @modified $Author$
+ */
+public class JavaBeanBinderService extends RegistryNamingBinder implements JavaBeanBinderServiceMBean {
+    public static final String VERSION = "$Header$";
+    private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(JavaBeanBinderService.class);
+
+    private String cname;
+    private String cnameImpl;
+    
+    protected String getBindClass() {
+        return cname;
+    }
+
+    protected Object classToInstance(Class c) {
+        try {
+        	if(cnameImpl != null) {
+        		ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        		Class clazz = cl.loadClass(cnameImpl);
+        		return clazz.newInstance();
+        	} else {
+        		return c.newInstance();
+        	}
+        } catch(RuntimeException ex) {
+            throw ex;
+        } catch(Exception ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
+    public void setClassName(String cname) {
+        this.cname = cname;
+    }
+
+    public String getClassName() {
+        return cname;
+    }
+
+    public void setImplClassName(String cname) {
+        this.cnameImpl = cname;
+    }
+
+    public String getImplClassName() {
+        return cnameImpl;
+    }
+
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JavaBeanBinderServiceMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JavaBeanBinderServiceMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/JavaBeanBinderServiceMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,17 @@
+package org.jboss.fresh.deployer;
+
+/**
+ * @author strukelj
+ * @version $Revision$
+ * @created 11.11.2005, 12:23:42
+ * @date $Date$
+ * @source $Source$
+ * @modified $Author$
+ */
+public interface JavaBeanBinderServiceMBean extends RegistryNamingBinderMBean {
+    public static final String VERSION = "$Header$";
+
+    public void setClassName(String cname);
+    public String getClassName();
+    
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/NamingBinder.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/NamingBinder.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/NamingBinder.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,136 @@
+package org.jboss.fresh.deployer;
+
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.Name;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+
+import org.jboss.fresh.parsek.cpii.Cp2Configuration;
+import org.jboss.fresh.naming.StaticObjectStore;
+
+public abstract class NamingBinder extends ServiceModule implements NamingBinderMBean {
+	// Attributes ----------------------------------------------------
+	private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(NamingBinder.class);
+	private String m_jndiName;
+	private String m_bindName;
+	private String bindClassName;
+	private Object sobj;
+
+	public String getName() {
+		return "CP2 Binder Service";
+	}
+
+	public void setJNDIName(String name) {
+		m_jndiName = name;
+	}
+
+	public String getJNDIName() {
+		return m_jndiName;
+	}
+
+	public void setServiceObject(Object obj) {
+		this.sobj = obj;
+	}
+
+	public Object getServiceObject() {
+		return sobj;
+	}
+
+	public void doStart() throws Exception {
+		try {
+			bind();
+		} catch (NamingException x) {
+			log.error("Bind failed!", x);
+			throw x;
+		}
+	}
+
+	public void doStop() {
+		try {
+			unbind();
+		} catch (NamingException x) {
+			log.error("Unbind failed!", x);
+		}
+	}
+
+	abstract protected String getBindClass();
+
+	abstract protected Object classToInstance(Class c);
+
+	protected Object getBindInstance() {
+		ClassLoader cl = Thread.currentThread().getContextClassLoader();
+		Class clazz = null;
+		String bindClassName = getBindClass();
+		if (bindClassName != null) {
+			try {
+				clazz = cl.loadClass(bindClassName);
+				return classToInstance(clazz);
+			} catch (ClassNotFoundException e) {
+				throw new RuntimeException("No such class: " + bindClassName + " : " + e.toString());
+			}
+		}
+		return null;
+	}
+
+	private void bind() throws NamingException {
+		Context cx = new InitialContext();
+		String name = getJNDIName();
+		if (name == null)
+			return;
+		m_bindName = name;
+		log.debug("bindName: "+name);
+		Name n = cx.getNameParser("").parse(m_bindName);
+		Context ctx = null;
+		while (n.size() > 1) {
+			String ctxName = n.get(0);
+			log.debug("CtxName: "+ctxName);
+			try {
+				ctx = (Context) cx.lookup(ctxName);
+				if (ctx==null){//to workaround resin bug!
+					log.debug("Lookup retured null, will create new subcontext");
+					ctx = cx.createSubcontext(ctxName);
+				}
+			} catch (NameNotFoundException e) {
+				log.warn("Could not lookup for ctx ",e);
+				ctx = cx.createSubcontext(ctxName);
+				log.debug("ctx after create subcontext: "+ctx);
+			}
+			n = n.getSuffix(1);
+		}
+		if (ctx==null)ctx=cx;
+		Object binst = getBindInstance();
+		log.info("supports non-serializable ? " + Cp2Configuration.jndiSupportsNonSerializable());
+		log.info("bindByReference() ? " + bindByReference());
+		log.info("bindInstance() ? " + binst + " [" + (binst == null ? "" : binst.getClass().getName()) + "]");
+		log.debug("NameParser: " + n);
+		log.debug("Ctx: "+ctx);
+		log.debug("binst: "+binst);
+		if (Cp2Configuration.jndiSupportsNonSerializable()) {
+			ctx.bind(n.get(0), binst);
+		} else if (bindByReference()) {
+			StringRefAddr addr = new StringRefAddr("nns", m_bindName);
+			Reference ref = new Reference(getBindClass(), addr, StaticObjectStore.class.getName(), null);
+			StaticObjectStore.put(m_bindName, binst);
+			ctx.bind(n.get(0), ref);
+		} else {
+			ctx.bind(n.get(0), binst);
+		}
+		log.info(getName() + ": '" + getJNDIName() + "' bound to '" + m_bindName + "'");
+	}
+
+	private void unbind() throws NamingException {
+		if (m_bindName != null) {
+			new InitialContext().unbind(m_bindName);
+			StaticObjectStore.remove(m_bindName);
+			log.info(getName() + ": '" + getJNDIName() + "' removed from JNDI.");
+		}
+	}
+
+	protected boolean bindByReference() {
+		return false;
+	}
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/NamingBinderMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/NamingBinderMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/NamingBinderMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,13 @@
+package org.jboss.fresh.deployer;
+
+public interface NamingBinderMBean extends ServiceModuleMBean {
+
+    public void setJNDIName(String name);
+
+    public String getJNDIName();
+
+    public void setServiceObject(Object obj);
+
+    public Object getServiceObject();
+
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/PoolService.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/PoolService.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/PoolService.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,140 @@
+package org.jboss.fresh.deployer;
+
+import org.jboss.fresh.pool.pool.Pool;
+import org.jboss.fresh.pool.pool.PoolFactory;
+import org.jboss.fresh.pool.pool.impl.PoolImpl;
+
+
+/**
+ * This is a simple service that sustains a file on the disk. It it it simply puts an integer specifying the number of invocations made from beginning of its running.
+ */
+public class PoolService extends RegistryNamingBinder implements PoolServiceMBean {
+
+	private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(PoolService.class);
+	private String poolname;
+	private String factoryName;
+	//private String factoryName="com.parsek.cpii.services.PoolRunnerFactory";
+
+
+	private int minsize = 0;			// default: 0
+	private int maxsize = 100;			// default: 100
+	private boolean isBlocking = true;		// default: true
+	private long blockingTimeout = 30000;	// default: 30 secs - even this is unacceptible - who will wait this long !!!
+
+
+	public void setFactoryName(String name) {
+		factoryName = name;
+	}
+
+	public String getFactoryName() {
+		return factoryName;
+	}
+
+	public void setPoolName(String name) {
+		poolname = name;
+	}
+
+	public String getPoolName() {
+		return poolname;
+	}
+
+	public void setMinSize(int val) {
+		minsize = val;
+	}
+
+	public int getMinSize() {
+		return minsize;
+	}
+
+	public void setMaxSize(int i) {
+		maxsize = i;
+	}
+
+	public int getMaxSize() {
+		return maxsize;
+	}
+
+	public void setBlocking(boolean val) {
+		isBlocking = val;
+	}
+
+	public boolean getBlocking() {
+		return isBlocking;
+	}
+
+	public void setBlockingTimeout(long val) {
+		blockingTimeout = val;
+	}
+
+	public long getBlockingTimeout() {
+		return blockingTimeout;
+	}
+
+	// pretty generic code comes here
+
+	public String getName() {
+		return "Generic Pool MBean";
+	}
+
+
+	protected String getBindClass() {
+		return Pool.class.getName();
+	}
+
+
+	protected Object classToInstance(Class c) {
+
+		// instaliraj se kot NotificationListener
+
+		// create pool instance.
+		// set factory
+
+		try {
+
+			PoolImpl pool = (PoolImpl) getServiceObject();
+
+			if (pool != null) pool.stop();
+
+			String fname = getFactoryName();
+			ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+			Class fc = cl.loadClass(fname);
+			PoolFactory f = (PoolFactory) fc.newInstance();
+
+			pool = new PoolImpl(poolname, f);
+			pool.setMinSize(minsize);
+			pool.setMaxSize(maxsize);
+			pool.setNonBlocking(!isBlocking);
+			pool.setTimeout(blockingTimeout); // why is it int ???
+
+			pool.start();
+
+			setServiceObject(pool);
+
+			return pool;
+
+		} catch (Exception ex) {
+			throw new RuntimeException(ex.toString());
+		}
+	}
+
+	protected boolean bindByReference() {
+		return true;
+	}
+
+	public void doStop() {
+		try {
+			log.debug("doStop() called");
+			super.doStop();
+		} finally {
+			try {
+				PoolImpl pool = (PoolImpl) getServiceObject();
+				log.info("pool: " + pool);
+				if (pool != null) pool.stop();
+			} catch (Exception ex) {
+				log.error("Exception while stopping the pool: ", ex);
+				throw new RuntimeException(ex.toString());
+			}
+		}
+	}
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/PoolServiceMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/PoolServiceMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/PoolServiceMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,31 @@
+package org.jboss.fresh.deployer;
+
+
+public interface PoolServiceMBean extends RegistryNamingBinderMBean {
+
+    public void setFactoryName(String name);
+
+    public String getFactoryName();
+
+    public void setPoolName(String name);
+
+    public String getPoolName();
+
+    public void setMinSize(int val);
+
+    public int getMinSize();
+
+    public void setMaxSize(int i);
+
+    public int getMaxSize();
+
+    public void setBlocking(boolean val);
+
+    public boolean getBlocking();
+
+    public void setBlockingTimeout(long val);
+
+    public long getBlockingTimeout();
+
+
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RegistryNamingBinder.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RegistryNamingBinder.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RegistryNamingBinder.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,222 @@
+package org.jboss.fresh.deployer;
+
+import javax.naming.*;
+import org.jboss.fresh.registry.RegistryContext;
+import org.jboss.fresh.naming.StaticObjectStore;
+
+public abstract class RegistryNamingBinder extends ServiceModule implements RegistryNamingBinderMBean {
+
+    private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(RegistryNamingBinder.class);
+
+    private String m_jndiName;
+    private String m_bindName;
+
+	private boolean doBindNative = true;
+	private String nativeJNDIName;
+	
+	private Object sobj;
+	
+	private boolean doBindByReference = true;
+
+    public String getName() {
+        return "CP2 Registry Binder Service";
+    }
+
+    public void setJNDIName(String name) {
+        m_jndiName = name;
+    }
+
+    public String getJNDIName() {
+        return m_jndiName;
+    }
+
+	public void setServiceObject(Object obj) {
+		this.sobj = obj;
+	}
+
+	public Object getServiceObject() {
+		return sobj;
+	}
+
+    public void doStart() throws Exception {
+        try {
+            bind();
+        } catch (NamingException x) {
+            log.error("Bind failed!", x);
+            throw x;
+        }
+    }
+
+    public void doStop() {
+        try {
+            unbind();
+        } catch (NamingException x) {
+            log.error("Unbind failed!", x);
+        }
+
+    }
+
+
+    abstract protected String getBindClass();
+
+    abstract protected Object classToInstance(Class c);
+
+
+    protected Object getBindInstance() {
+
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        Class clazz = null;
+
+        String bindClassName = getBindClass();
+        if (bindClassName != null) {
+            try {
+                clazz = cl.loadClass(bindClassName);
+                return classToInstance(clazz);
+            } catch (ClassNotFoundException e) {
+                throw new RuntimeException("No such class: " + bindClassName + " : " + e.toString());
+            }
+        }
+
+        return null;
+
+    }
+
+    private void bind() throws NamingException {
+        Context ctx = new RegistryContext();
+        String name = getJNDIName();
+        if (name == null)
+            return;
+
+        // if (!name.startsWith("java:/")) {
+        //    name = "java:/" + name;
+        // }
+	
+        m_bindName = name;
+
+		// Ah ! This class isn't serializable, so we use a helper class
+		// Make this work - oneliner for binding
+		//ctx.bind(m_bindName, getBindInstance());
+
+		Name n = ctx.getNameParser("").parse(m_bindName);
+		while (n.size() > 1) {
+			String ctxName = n.get(0);
+			try {
+				ctx = (Context) ctx.lookup(ctxName);
+			} catch (NameNotFoundException e) {
+				ctx = ctx.createSubcontext(ctxName);
+			}
+			n = n.getSuffix(1);
+		}
+
+		Object bindInstance = getBindInstance();
+		ctx.bind(n.get(0), bindInstance);
+
+		log.info(getName() + ": '" + getJNDIName() + "' bound to '" + m_bindName + "' in registry");
+    
+		icBind(bindInstance);
+    }
+
+
+    private void icBind(Object bindInstance) throws NamingException {
+		Context cx = new InitialContext();
+		String name = getNativeBindName();
+		if (name == null)
+			return;
+
+		log.debug("native bindName: " + name);
+		Name n = cx.getNameParser("").parse(name);
+		Context ctx = cx;
+		while (n.size() > 1) {
+			String ctxName = n.get(0);
+			log.debug("native CtxName: " + ctxName);
+			try {
+				cx = (Context) ctx.lookup(ctxName);
+				if (cx == null){ //to workaround resin bug!
+					log.debug("Lookup retured null, will create new subcontext");
+					cx = ctx.createSubcontext(ctxName);
+				}
+			} catch (NameNotFoundException e) {
+				log.debug("Creating subcontext: " + ctxName);
+				cx = ctx.createSubcontext(ctxName);
+			}
+
+			ctx = cx;
+			n = n.getSuffix(1);
+		}
+		
+		Object binst = bindInstance;
+		log.info("bindInstance() ? " + binst + " [" + (binst == null ? "" : binst.getClass().getName()) + "]");
+
+		// each service decides how it's gonna bind 
+		// - default is by value
+		if(doBindByReference) {  
+			StringRefAddr addr = new StringRefAddr("nns", name);
+			Reference ref = new Reference(getBindClass(), addr, StaticObjectStore.class.getName(), null);
+			StaticObjectStore.put(name, binst);
+			ctx.bind(n.get(0), ref);
+		} else {
+			ctx.bind(n.get(0), binst);
+		}
+		
+		log.info(getName() + ": '" + getJNDIName() + "' bound to '" + name + "' in JNDI");		
+	}
+
+	private void unbind() throws NamingException {
+        if (m_bindName != null) {
+            new RegistryContext().unbind(m_bindName);
+            log.info(getName() + ": '" + getJNDIName() + "' removed from registry");
+        
+        }
+        
+        icUnbind();        
+    }
+
+	private void icUnbind() throws NamingException {
+		String name = getNativeBindName();
+		if (name != null) {
+			new InitialContext().unbind(name);
+			StaticObjectStore.remove(name);
+			log.info(getName() + ": '" + getNativeBindName() + "' removed from JNDI.");
+		}
+		
+	}
+
+
+	public String getNativeBindName() {
+		if(!doBindNative)
+			return null;
+		else if(nativeJNDIName != null)
+			return nativeJNDIName;
+		else
+			return m_jndiName;
+	}
+
+
+	public void setBindNative(boolean bnat) {
+		this.doBindNative = bnat;
+	}
+
+	public boolean getBindNative() {
+		return this.doBindNative;
+	}
+
+	
+	public void setNativeJNDIName(String jndiName) {
+		this.nativeJNDIName = jndiName;
+	}
+	
+	public String getNativeJNDIName() {
+		return nativeJNDIName;
+	}
+	
+	
+	
+	public boolean getBindByReference() {
+		return doBindByReference;
+	}
+
+	public void setBindByReference(boolean val) {
+		this.doBindByReference = val;
+	}
+
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RegistryNamingBinderMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RegistryNamingBinderMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RegistryNamingBinderMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,18 @@
+package org.jboss.fresh.deployer;
+
+
+public interface RegistryNamingBinderMBean extends ServiceModuleMBean {
+
+    public void setJNDIName(String name);
+    public String getJNDIName();
+
+	public void setBindNative(boolean bnat);
+	public boolean getBindNative();
+
+	public void setNativeJNDIName(String jndiName);
+	public String getNativeJNDIName();
+	
+	public boolean getBindByReference();
+	public void setBindByReference(boolean val);
+
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RootVFSService.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RootVFSService.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RootVFSService.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,71 @@
+package org.jboss.fresh.deployer;
+
+
+import org.apache.log4j.Logger;
+import org.jboss.fresh.registry.RegistryContext;
+import org.jboss.fresh.vfs.RootVFS;
+import org.jboss.fresh.vfs.VFS;
+import org.jboss.fresh.vfs.impl.DefaultRootVFS;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * @author uros
+ * @version $Revision: 3032 $
+ * @modified $Author: strukelj $
+ */
+public class RootVFSService extends RegistryNamingBinder implements RootVFSServiceMBean {
+
+
+    private static Logger log = Logger.getLogger(RootVFSService.class);
+    private RootVFS vfs;
+    private Properties props;
+
+    protected String getBindClass() {
+        return RootVFS.class.getName();
+    }
+
+    public void setAutomount(Properties p) {
+        props = p;
+    }
+
+    public Properties getAutomount() {
+        return props;
+    }
+
+    protected Object classToInstance(Class c) {
+
+        vfs = new DefaultRootVFS();
+        return vfs;
+    }
+
+    protected boolean bindByReference() {
+        return true;
+    }
+
+    public void doStart() throws Exception {
+        super.doStart();
+        if (props != null) {
+            RegistryContext ctx = new RegistryContext();
+            Set set = props.entrySet();
+            Iterator it = set.iterator();
+            while (it.hasNext()) {
+                Map.Entry ent = (Map.Entry) it.next();
+                String path = (String) ent.getKey();
+                String jndi = (String) ent.getValue();
+
+                VFS mvfs = (VFS) ctx.lookup(jndi);
+                vfs.mount(path, mvfs);
+            }
+        }
+    }
+
+    public String getName() {
+        return "CP2 Root VFS Binder Service";
+    }
+
+}
+

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RootVFSServiceMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RootVFSServiceMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/RootVFSServiceMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,9 @@
+package org.jboss.fresh.deployer;
+
+import java.util.Properties;
+
+
+public interface RootVFSServiceMBean extends RegistryNamingBinderMBean {
+	public void setAutomount(Properties p);
+	public Properties getAutomount();
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ServiceAlreadyStartedException.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ServiceAlreadyStartedException.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ServiceAlreadyStartedException.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,13 @@
+package org.jboss.fresh.deployer;
+
+public class ServiceAlreadyStartedException extends RuntimeException {
+
+	public ServiceAlreadyStartedException() {
+		super();
+	}
+
+	public ServiceAlreadyStartedException(String message) {
+		super(message);
+	}
+
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ServiceModule.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ServiceModule.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ServiceModule.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,90 @@
+package org.jboss.fresh.deployer;
+
+import java.util.Date;
+
+public class ServiceModule extends BaseService implements ServiceModuleMBean {
+
+	public static final String STARTING = "Starting";
+	public static final String STARTED = "Started";
+	public static final String STOPPING = "Stopping";
+	public static final String STOPPED = "Stopped";
+
+	private String status = STOPPED;
+	private long startTime = 0;
+
+	public synchronized void start() throws Exception {
+
+		if(status==STARTED) throw new ServiceAlreadyStartedException("The service has already been started. If you want to restart it call stop() first or call restart().");
+
+		//if(state==STARTING) throw new RuntimeException("The service is already starting up. Wait for it to reach STARTED or STOPPED state.");
+		//if(state==STOPPING) throw new RuntimeException("The service is being stopped. Wait for it to reach STARTED or STOPPED state.");
+
+		status = STARTING;
+
+		try {
+			doStart();
+			status = STARTED;
+			startTime = System.currentTimeMillis();
+		} catch(Exception ex) {
+			status = STOPPED;
+			startTime = 0;
+			throw ex;
+		} catch(Throwable th) {
+			status = STOPPED;
+			startTime = 0;
+			throw new RuntimeException(th);
+		}
+	}
+
+	public synchronized void stop() throws Exception {
+
+		if(status==STOPPED) return;
+
+		status = STOPPING;
+
+		try {
+			doStop();
+			status = STOPPED;
+			startTime = 0;
+		} catch(Exception ex) {
+			status = STARTED;
+			throw ex;
+		} catch(Throwable th) {
+			status = STARTED;
+			throw new RuntimeException(th);
+		}
+	}
+
+	public synchronized void restart() throws Exception {
+		if(status==STOPPED) throw new RuntimeException("The service is not running.");
+
+		stop();
+		start();
+	}
+
+	public String getStatus() {
+		return status;
+	}
+
+
+	public Date getStartTime() {
+		if(startTime == 0) return null;
+		return new Date(startTime);
+	}
+
+
+	/**
+	 *  Override this methods to perform any startup actions
+	 *  (like binding objects into naming or starting a service thread)
+	 */ 
+	public void doStart() throws Exception {
+	}
+
+	/**
+	 *  Override this methods to perform any shutdown actions
+	 *  (like unbinding objects from naming or stopping a service thread)
+	 */ 
+	public void doStop() throws Exception {
+	}
+
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ServiceModuleMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ServiceModuleMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ServiceModuleMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,11 @@
+package org.jboss.fresh.deployer;
+
+import java.util.Date;
+
+public interface ServiceModuleMBean {
+	public void start() throws Exception;
+	public void stop() throws Exception;
+	public void restart() throws Exception;
+	public String getStatus();
+	public Date getStartTime();
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ShellExecutorService.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ShellExecutorService.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ShellExecutorService.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,393 @@
+package org.jboss.fresh.deployer;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+
+import javax.naming.InitialContext;
+
+import org.jboss.fresh.registry.RegistryContext;
+import org.jboss.fresh.shell.*;
+import org.jboss.fresh.shell.ejb.RemoteShellHome;
+import org.jboss.fresh.shell.ejb.RemoteShell;
+import org.jboss.fresh.io.IOUtils;
+import org.jboss.fresh.util.TextLayout;
+
+/** This is a simple service that sustains a file on the disk. It it it simply puts an integer specifying the number of invocations made from beginning of its running. */
+
+public class ShellExecutorService extends ServiceModule implements ShellExecutorServiceMBean {
+    
+    private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(ShellExecutorService.class);
+
+    private static SimpleDateFormat sdf = new SimpleDateFormat("'['dd.MM' 'HH:mm:ss']'");
+
+    private String bfile;
+    private boolean qoe = false;
+    private String flog;
+    private String svcname;
+    private boolean exeOnStart;
+    private boolean useLocal;
+
+    private String bcode;
+
+    // Attributes ----------------------------------------------------
+
+    public String getName() {
+        return "Shell Exe Service";
+    }
+
+
+    public void setBatchFile(String file) {
+        bfile = file;
+    }
+
+    public String getBatchFile() {
+        return bfile;
+    }
+
+    public void setBatchCode(String code) {
+        bcode = code;
+    }
+
+    public String getBatchCode() {
+        return bcode;
+    }
+
+    public void setExecuteOnStart(boolean val) {
+        exeOnStart = val;
+    }
+
+    public boolean getExecuteOnStart() {
+        return exeOnStart;
+    }
+
+    public void setStopOnError(Boolean val) {
+        qoe = val.booleanValue();
+    }
+
+    public Boolean getStopOnError() {
+        return new Boolean(qoe);
+    }
+
+    public void setLogFile(String val) {
+        flog = val;
+    }
+
+    public String getLogFile() {
+        return flog;
+    }
+
+
+    public void setSvcName(String val) {
+        svcname = val;
+    }
+
+    public String getSvcName() {
+        return svcname;
+    }
+
+    public void setUseLocal(boolean val) {
+        useLocal = val;
+    }
+
+    public boolean getUseLocal() {
+        return useLocal;
+    }
+
+
+    public void doStart() throws Exception {
+
+        if (exeOnStart) execute();
+    }
+
+    private class Executor {
+        
+        private boolean stopOnError = false;
+        private String eSvcname = "SystemShell";
+        private boolean eUseLocal = true;
+
+        public Executor() {
+            super();
+            this.stopOnError = qoe;
+            this.eUseLocal = useLocal;
+            this.eSvcname = svcname;
+            if (eSvcname == null) {
+                eSvcname = eUseLocal ? "SystemShell": "ShellSession";
+            }
+        }
+
+        // we open a log file
+        BufferedOutputStream bos = null;
+        // we open a batch file
+        BufferedReader in = null;
+
+        public void execute() throws Exception {
+        	PrintWriter out = null;
+        	if(bos != null)
+        		out = new PrintWriter(new OutputStreamWriter(bos));
+
+        	try {
+
+                if (eUseLocal) {
+                    RegistryContext ctx = new RegistryContext();
+                    SystemShell sysshell = (SystemShell) ctx.lookup(eSvcname);
+                    Shell shell = sysshell.startSession(null, false);
+
+                    try {
+                        // now line by line
+                        // And put all exceptions to log too.
+                        String cmd = in.readLine();
+                        while (cmd != null) {
+                            cmd = cmd.trim();
+                        	if(out!=null) {
+                            	out.println(getTime() + " Executing: " + cmd);
+                            	out.flush();
+                            }
+                            
+                        	if(! "".equals(cmd)) {
+	                            ProcessInfo pinf = shell.execute(cmd, true);
+	                            	                            
+	                            BufferedInputStream bin = new BufferedInputStream(new ShellConsoleInputStream(new ShellObjectReader(shell, pinf.procid)));
+	                            try {
+	                                IOUtils.copy(bin, bos, 50000);
+	                            } catch (Exception ex) {
+	                                try {
+	                                    if(out != null) {
+	                                    	out.println(getTime() + " Exception has occured:");
+	                                    	ex.printStackTrace(out);
+	                                    }
+	                                } catch (Exception e) {
+	                                    e.printStackTrace();
+	                                }
+	
+	                                if (stopOnError) {
+	                                    throw ex;
+	                                }
+	                            }
+	                            	                            
+                        	}
+                            cmd = in.readLine();
+                        }
+                    } finally {
+                        try {
+                            shell.close();
+                        } catch (ShellException e) {
+                        }
+                    }
+                } else {
+                    // we get RemoteShell
+                    InitialContext ctx = new InitialContext();
+                    RemoteShellHome home = (RemoteShellHome) ctx.lookup(eSvcname);
+                    RemoteShell shell = home.create();
+
+                    try {
+                        // now line by line
+                        // And put all exceptions to log too.
+                        String cmd = in.readLine();
+                        while (cmd != null) {
+                            
+                        	cmd = cmd.trim();
+                        	
+                        	if(out != null) {
+                            	out.println(getTime() + " Executing: " + cmd);
+                            	out.flush();
+                            }
+
+                        	if(! "".equals(cmd)) {
+	                        	ProcessInfo pinf = shell.execute(cmd);
+	                            BufferedInputStream bin = new BufferedInputStream(new ShellConsoleInputStream(new ShellObjectReader(shell, pinf.procid)));
+	                            try {
+	                                IOUtils.copy(bin, bos, 50000);
+	                            } catch (Exception ex) {
+	                                try {
+	                                    if(out!=null) {
+	                                    	out.println(getTime() + " Exception has occured:");
+	                                    	ex.printStackTrace(out);
+	                                    }
+	                                } catch (Exception e) {
+	                                    e.printStackTrace();
+	                                }
+	                                if (stopOnError) {
+	                                    throw ex;
+	                                }
+	                            }
+                        	}
+                            cmd = in.readLine();
+                        }
+                    } finally {
+                        shell.remove();
+                    }
+                }
+            } finally {
+                try {
+                    in.close();
+                } catch (Exception ex) {
+                }
+                try {
+                    if(out != null)
+                    	out.close();
+                } catch (Exception ex) {
+                }
+            } 
+        }
+    }
+    
+    public void execute() throws Exception {
+        // we open a log file
+        BufferedOutputStream bos = null;
+
+        if (flog != null) {
+            if (flog.equals("console")) {
+                bos = new BufferedOutputStream(System.out);
+            } else {
+                bos = new BufferedOutputStream(new FileOutputStream(flog, true));
+            }
+        }
+
+        if(bcode != null && bcode.length() > 1 && bfile != null) {
+            log.warn("Both batch file and batch code parameters are set. Using batch file!");
+            if(bos!=null) {
+                PrintWriter out = new PrintWriter(bos);
+                try {
+                    out.println(getTime() + " Both batch file and batch code parameters are set. Using batch file!");
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                try {
+                    out.close();
+                } catch (Exception e) {
+                }
+            }
+        }
+
+        BufferedReader in = null;
+
+        if(bfile != null) {
+            // we open a batch file
+            try {
+                in = new BufferedReader(new FileReader(bfile));
+            } catch (Exception ex) {
+                if(bos!=null) {
+                    PrintWriter out = new PrintWriter(bos);
+                    try {
+                        out.println(getTime() + " Exception has occured:");
+                        ex.printStackTrace(out);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                    try {
+                        out.close();
+                    } catch (Exception e) {
+                    }
+                }
+
+                throw ex;
+            }
+        } else if(bcode != null) {
+            in = new BufferedReader(new StringReader(bcode));
+        }
+         
+        Executor exe = new Executor();
+        exe.bos = bos;
+        exe.in = in;
+        
+        exe.execute();
+    }
+
+
+    public void execute(Map params) throws Exception {
+        // we open a log file
+        BufferedOutputStream bos = null;
+
+        if (flog != null) {
+            if (flog.equals("console")) {
+                bos = new BufferedOutputStream(System.out);
+            } else {
+                bos = new BufferedOutputStream(new FileOutputStream(flog, true));
+            }
+        }
+
+        if(bcode != null && bcode.length() > 1 && bfile != null) {
+            log.warn("Both batch file and batch code parameters are set. Using batch file!");
+            if(bos!=null) {
+                PrintWriter out = new PrintWriter(bos);
+                try {
+                    out.println(getTime() + " Both batch file and batch code parameters are set. Using batch file!");
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                try {
+                    out.close();
+                } catch (Exception e) {
+                }
+            }
+        }
+
+        // we open a batch file
+        BufferedReader in = null;
+        if(bfile != null) {
+
+            try {
+                in = populate(new BufferedReader(new FileReader(bfile)), params);
+             } catch (Exception ex) {
+                if(bos != null) {
+                    PrintWriter out = new PrintWriter(bos);
+                    try {
+                        out.println(getTime() + " Exception has occured:");
+                        ex.printStackTrace(out);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                    try {
+                        out.close();
+                    } catch (Exception e) {
+                    }
+                }
+                throw ex;
+            }
+        } else if(bcode != null) {
+            in = populate(new BufferedReader(new StringReader(bcode)), params);
+        }
+
+        Executor exe = new Executor();
+        exe.bos = bos;
+        exe.in = in;
+        
+        exe.execute();
+    }
+
+	private BufferedReader populate(BufferedReader job, Map params) throws IOException {
+	    if (params != null && !params.isEmpty()) {
+	        StringBuffer sb = new StringBuffer();
+	        for (String line = job.readLine(); line != null; line = job.readLine()) {
+	            sb.append(line).append("\r\n");	            
+	        }
+			TextLayout tl = new TextLayout("{","}");
+			tl.setPattern(sb.toString());
+			StringWriter sw = new StringWriter();
+			tl.bind(sw, params);
+			return new BufferedReader(new StringReader(sw.toString()));
+	    }
+	    return job;
+	}
+    
+    protected static String getTime() {
+        return sdf.format(new Date());
+    }
+
+
+}
+
+
+
+

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ShellExecutorServiceMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ShellExecutorServiceMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/ShellExecutorServiceMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,39 @@
+package org.jboss.fresh.deployer;
+
+import java.util.Map;
+
+public interface ShellExecutorServiceMBean extends ServiceModuleMBean {
+
+    public void setBatchFile(String file);
+
+    public String getBatchFile();
+
+    public void setBatchCode(String code);
+
+    public String getBatchCode();
+
+    public void setStopOnError(Boolean val);
+
+    public Boolean getStopOnError();
+
+    public void setLogFile(String val);
+
+    public String getLogFile();
+
+    public void setSvcName(String val);
+
+    public String getSvcName();
+
+    public void setExecuteOnStart(boolean val);
+
+    public boolean getExecuteOnStart();
+
+    public void setUseLocal(boolean val);
+
+    public boolean getUseLocal();
+
+    public void execute() throws Exception;
+
+    public void execute(Map params) throws Exception;
+    
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/SystemShellService.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/SystemShellService.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/SystemShellService.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,82 @@
+package org.jboss.fresh.deployer;
+
+import org.jboss.fresh.shell.SystemShell;
+import org.jboss.fresh.shell.impl.SystemShellImpl;
+
+public class SystemShellService extends RegistryNamingBinder implements SystemShellServiceMBean {
+
+    // Attributes ----------------------------------------------------
+
+    private String tpName;
+    private String vfsName;
+
+    private long gcInterval = 10000L;
+    private SystemShellImpl ss;
+
+
+    public String getName() {
+        return "CP2 SystemShell Binder Service";
+    }
+
+
+    public void setThreadPoolJNDIName(String name) {
+
+        tpName = name;
+    }
+
+
+    public String getThreadPoolJNDIName() {
+        return tpName;
+    }
+
+    public void setVFSJNDIName(String name) {
+
+        vfsName = name;
+    }
+
+
+    public String getVFSJNDIName() {
+        return vfsName;
+    }
+
+
+    public void setGCInterval(long val) {
+        gcInterval = val;
+        if (ss != null)
+            ss.setGCInterval(val);
+    }
+
+    public long getGCInterval() {
+        if (ss == null) return gcInterval;
+        return ss.getGCInterval();
+    }
+
+    protected String getBindClass() {
+        return SystemShell.class.getName();
+    }
+
+    protected Object classToInstance(Class c) {
+
+        try {
+            ss = new SystemShellImpl(tpName, vfsName);
+            ss.setGCInterval(gcInterval);
+
+            SystemShell ssold = (SystemShell) getServiceObject();
+            if (ssold != null) ssold.shutdown();
+
+            setServiceObject(ss);
+
+            //SystemShellJMXProxy proxy = new SystemShellJMXProxy(getRegisteredName());
+            //return proxy;
+            return ss;
+
+        } catch (Exception ex) {
+            throw new RuntimeException(ex.toString());
+        }
+    }
+
+    protected boolean bindByReference() {
+        return true;
+    }
+
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/SystemShellServiceMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/SystemShellServiceMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/SystemShellServiceMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,17 @@
+package org.jboss.fresh.deployer;
+
+public interface SystemShellServiceMBean extends RegistryNamingBinderMBean {
+
+    public void setThreadPoolJNDIName(String name);
+
+    public String getThreadPoolJNDIName();
+
+    public void setVFSJNDIName(String name);
+
+    public String getVFSJNDIName();
+
+    public void setGCInterval(long val);
+
+    public long getGCInterval();
+
+}
\ No newline at end of file

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSFileService.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSFileService.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSFileService.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,278 @@
+package org.jboss.fresh.deployer;
+
+import java.io.*;
+import java.net.URL;
+import javax.naming.InitialContext;
+import javax.naming.Context;
+
+import org.jboss.fresh.shell.ejb.RemoteShell;
+import org.jboss.fresh.shell.ejb.RemoteShellHome;
+import org.jboss.fresh.shell.Shell;
+import org.jboss.fresh.shell.ShellOutputStream;
+import org.jboss.fresh.shell.SystemShell;
+import org.jboss.fresh.shell.ProcessInfo;
+import org.jboss.fresh.registry.RegistryContext;
+import org.jboss.fresh.io.IOUtils;
+
+/**
+ * Service creates a file in VFS.
+ **/
+public class VFSFileService extends ServiceModule implements VFSFileServiceMBean {
+	private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(VFSFileService.class);
+	static final org.apache.log4j.Level TRACE = new ApacheLevel(5000, "TRACE", 7);
+	static final org.apache.log4j.Level NOTICE = new ApacheLevel(25000, "NOTICE", 5);
+
+	static class ApacheLevel extends org.apache.log4j.Level {
+		protected ApacheLevel(int level, String levelStr, int syslogEquivalent) {
+			super(level, levelStr, syslogEquivalent);
+		}
+	}
+
+
+    private String file;
+	 private String content;
+	 private String sourceFile;
+	 private String classpathFile;
+	 private URL url;
+
+    public String getName() {
+		return "VFS File Service";
+    }
+
+    public void setFile(String file) {
+		this.file = file;
+    }
+
+    public String getFile() {
+		return file;
+    }
+
+    public void setContent(String content) {
+		this.content = content;
+    }
+
+    public String getContent() {
+		return content;
+    }
+
+	 public void setFilePath(String sourceFile) {
+	 	this.sourceFile = sourceFile;
+	 }
+	 
+	 public String getFilePath() {
+	 	return sourceFile;
+	 }
+
+	 public void setResourcePath(String classpathFile) {
+	 	this.classpathFile = classpathFile;
+	 }
+	 
+	 public String getResourcePath() {
+	 	return classpathFile;
+	 }
+
+	 public void setUrl(String url) throws java.net.MalformedURLException {
+	 	this.url = new URL(url);
+	 }
+	 
+	 public String getUrl() {
+	 	return url == null ? null : url.toString();
+	 }
+
+
+    public void doStart() throws Exception {
+			if(file == null || file.trim().length() == 0) {
+				throw new Exception("File name not defined. Please define VFS file name.");
+			}
+
+			Context ctx = null;
+			Shell shell = null;
+			RemoteShell rshell = null;
+			ShellOutputStream sos = null;
+			OutputStreamWriter osw = null;
+			try {
+				ctx = new RegistryContext();
+
+				try {
+					SystemShell sysshell = (SystemShell) ctx.lookup("SystemShell");
+					log.log(TRACE, "Retrieved SystemShell from RegistryContext: 'SystemShell'.");
+					shell = sysshell.startSession(null, false);
+				} catch (javax.naming.NameNotFoundException nnfe) {
+					ctx.close();
+					ctx = new InitialContext();
+					RemoteShellHome home = null;
+					try {
+						home = (RemoteShellHome) ctx.lookup("ShellSession");
+						log.log(TRACE, "Retrieved RemoteShellHome from InitialContext: 'ShellSession'.");
+						rshell = home.create();
+					} catch (javax.naming.NameNotFoundException nnfe2) {
+						try {
+							home = (RemoteShellHome) ctx.lookup("java:/CP2/ShellSession");
+							log.log(TRACE, "Retrieved RemoteShellHome from InitialContext: 'java:/CP2/ShellSession'.");
+							rshell = home.create();
+						} catch (javax.naming.NameNotFoundException nnfe3) {
+							SystemShell sysshell = (SystemShell) ctx.lookup("java:/CP2/SystemShell");
+							log.log(TRACE, "Retrieved SystemShell from InitialContext: 'java:/CP2/SystemShell'.");
+							shell = sysshell.startSession(null, false);
+						}
+					}
+				}
+				log.debug("Using shell: " + shell);
+
+				String path = "";
+				String[] parts = file.split("/");
+				for(int i = 0; i < parts.length - 1; i++) {
+					path = path + "/" + parts[i];
+					String cmd = "mkdir " + path;
+					log.debug(cmd);
+					if(shell != null) {
+						shell.executeAsObject(cmd);
+					} else {
+						rshell.executeAsObject(cmd);
+					}
+				} 
+	
+				log.info("Creating file " + file);
+				String cmd;
+
+				boolean create = true;
+				if(classpathFile != null && classpathFile.length() > 0) {
+					url = this.getClass().getResource(classpathFile);
+					if(url != null) {
+						log.debug("Located resource using class.getResource(): " + url.toExternalForm());
+						content = null;
+					} else {
+						url = Thread.currentThread().getContextClassLoader().getResource(classpathFile);
+						if(url != null) {
+							log.debug("Located using context class loader: " + url.toExternalForm());
+							content = null;
+						} else {
+							log.warn("ClassPath file defined to '" + classpathFile + "' but not found using getResource() mechanism.");
+							create = false;
+						}
+					}
+				}
+				
+				// content over matter
+				if(content != null && content.length() > 0) {
+				
+					java.io.StringReader sr = null;
+					java.io.BufferedReader br = null;
+
+					try {
+						sr = new java.io.StringReader(content);
+						br = new java.io.BufferedReader(sr);
+						
+						// let's style it a bit
+						if(br.readLine().trim().length() == 0) {
+							log.debug("Whitespace removal activated.");
+
+							StringBuffer result = new StringBuffer(content.length());
+							String whitespace = null;
+							boolean first = true;
+							String line = br.readLine();
+							while(line != null) {
+								if(first) {
+									int i = 0;
+									while(i < line.length() && Character.isWhitespace(line.charAt(i))) {}
+
+									if(i == line.length() - 1) {
+										whitespace = "";
+									} else {
+										whitespace = line.substring(0, i);
+										log.log(TRACE, "Removing " + whitespace.length() + " whitespace characters from lines.");
+									}
+									first = false;
+								}
+								if(line.startsWith(whitespace)) {
+									line = line.substring(whitespace.length());
+								}
+								result.append(line).append("\r\n");
+							
+								line = br.readLine();
+							}
+
+							content = result.toString();
+						}
+						
+					} finally {
+						if(br!= null) { try { br.close(); } catch (Exception e) { } }
+						if(sr!= null) { try { sr.close(); } catch (Exception e) { } }
+					}
+				
+					ProcessInfo pinf = null;
+					cmd = "cat > " + file;
+					log.debug(cmd);
+					if(shell != null) {
+						pinf = shell.execute(cmd);
+						sos = new ShellOutputStream(shell, pinf.procid);
+					} else {
+						pinf = rshell.execute(cmd);
+						sos = new ShellOutputStream(rshell, pinf.procid);
+					}
+					osw = new OutputStreamWriter(sos, "UTF-8");
+					osw.write(content);
+					log.log(NOTICE, "Created file " + file + ", processed " + content.length() + " characters.");
+				} else if(sourceFile != null && sourceFile.length() > 0) {
+					java.io.File f = new java.io.File(sourceFile);
+					if(!f.exists()) {
+						log.error("File " + f.getAbsolutePath() + " does not exist! Will not create VFS file: " + file);
+						return;
+					}
+					if(!f.isFile()) {
+						log.error("Path " + f.getAbsolutePath() + " is not a file! Will not create VFS file: " + file);
+						return;
+					}
+					cmd = "cat > " + file + " &< " + f.getAbsolutePath();
+					log.debug(cmd);
+					if(shell != null) {
+						shell.execute(cmd);
+					} else {
+						rshell.execute(cmd);
+					}
+					log.log(NOTICE, "Created file " + file + ", wrote " + f.length() + " bytes.");
+				} else if (url != null) {
+					InputStream is = null;
+					try {
+						java.net.URLConnection uc = url.openConnection();
+						uc.setConnectTimeout(30 * 1000);
+						uc.setReadTimeout(60 * 1000);
+						is = uc.getInputStream();
+
+						ProcessInfo pinf = null;
+						cmd = "cat > " + file;
+						log.debug(cmd);
+						if(shell != null) {
+							pinf = shell.execute(cmd);
+							sos = new ShellOutputStream(shell, pinf.procid);
+						} else {
+							pinf = rshell.execute(cmd);
+							sos = new ShellOutputStream(rshell, pinf.procid);
+						}
+
+						long size = IOUtils.copy(is, sos);
+
+						log.log(NOTICE, "Created file " + file + ", processed " + size + " bytes.");
+					} finally {
+						if(is!= null) { try { is.close(); } catch (Exception e) { } }
+					}
+				} else if(create) {
+					cmd = "touch " + file;
+					log.debug(cmd);
+					if(shell != null) {
+						shell.execute(cmd);
+					} else {
+						rshell.execute(cmd);
+					}
+					log.log(NOTICE, "Created empty file " + file + ".");
+				}
+				
+			} finally {
+				if(ctx    != null) { try { ctx.close();     } catch (Exception e) { } }
+				// should not close shells. if(shell  != null) { try { shell.close();   } catch (Exception e) { } }
+				if(rshell != null) { try { rshell.remove(); } catch (Exception e) { } }
+				if(osw    != null) { try { osw.close();     } catch (Exception e) { } }
+				if(sos    != null) { try { sos.close();     } catch (Exception e) { } }
+			}
+    }
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSFileServiceMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSFileServiceMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSFileServiceMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,45 @@
+package org.jboss.fresh.deployer;
+
+/**
+ * This Mbean will upon firing create a file in VFS (creating folders as neccessary) and fill it
+ * with specified content. Content can either be given as a <tt>content</tt> parameter or as an
+ * external, on-disk file which will be read upon startup. 
+ */   
+public interface VFSFileServiceMBean extends ServiceModuleMBean {
+
+	 /**
+	  * File name in VFS
+	  */	  	 
+	 public void setFile(String file);
+
+	 public String getFile();
+	 
+	 /**
+	  * Content of the file
+	  */	  	 
+	 public void setContent(String content);
+	 
+	 public String getContent();
+
+	 /**
+	  * Fill with contents from this file.
+	  */	  	 
+	 public void setFilePath(String FilePath);
+	 
+	 public String getFilePath();
+
+	 /**
+	  * Find the file using standard classpath search mechanism.
+	  */	  	 
+	 public void setResourcePath(String ResourcePath);
+	 
+	 public String getResourcePath();
+
+	 /**
+	  * Load content from any valid URL.
+	  */	  	 
+	 public void setUrl(String url) throws java.net.MalformedURLException;
+	 
+	 public String getUrl();
+
+}

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSService.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSService.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSService.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,241 @@
+package org.jboss.fresh.deployer;
+
+
+import org.apache.log4j.Logger;
+import org.jboss.fresh.vfs.*;
+import org.jboss.fresh.vfs.impl.DefaultVFS;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.lang.reflect.Constructor;
+
+/**
+ * @author uros
+ * @modified $Author: strukelj $
+ * @version $Revision: 3554 $
+ */
+public class VFSService extends RegistryNamingBinder implements VFSServiceMBean {
+
+	// Attributes ----------------------------------------------------
+	private String metaClassName;
+	private String storeClassName;
+	private String tagFactoryName;
+	private String vfsImpl;
+
+
+	private String metapropStr;
+	private String storepropStr;
+	private Properties metaProps;
+	private Properties storeProps;
+
+	private VFS vfs;
+
+	private static Logger log = Logger.getLogger(VFSService.class);
+
+	protected String getBindClass() {
+		return VFS.class.getName();
+	}
+
+
+	protected Object classToInstance(Class c) {
+
+		VFSMeta meta = null;
+		VFSStore store = null;
+		TagFactory tagfactory = null;
+
+		ClassLoader cl = Thread.currentThread().getContextClassLoader();
+		Class clazz = null;
+
+		if (metaClassName != null) {
+			try {
+				clazz = cl.loadClass(metaClassName);
+			} catch (ClassNotFoundException e) {
+				throw new RuntimeException("No such class: " + metaClassName + " : " + e.toString());
+			}
+
+			try {
+				meta = ((VFSMetaFactory) clazz.newInstance()).create(metaProps);
+			} catch (InstantiationException e) {
+				throw new RuntimeException("Could not instantiate class: " + clazz, e);
+			} catch (IllegalAccessException e) {
+				throw new RuntimeException("Not allowed to instantiate class: " + clazz, e);
+			} catch (Exception ex) {
+				throw new RuntimeException("Exception while instanciating: " + clazz, ex);
+			}
+
+			// bind meta class to naming so store can look it up
+			// debilno - to moramo spremeniti
+			/*
+			try {
+				RegistryContext ctx = new RegistryContext();
+				try {
+					ctx.createSubcontext("java:");
+				} catch(NamingException ex) {
+				}
+	
+				try {
+					ctx.createSubcontext("java:/CP2");
+				} catch(NamingException ex) {
+				}
+	
+				ctx.bind("java:/CP2/VFSMeta", meta);
+			} catch(Exception ex) {
+				throw new RuntimeException("Failed to bind meta: ", ex);
+			}
+			*/
+		}
+
+		if (storeClassName != null) {
+			try {
+				clazz = cl.loadClass(storeClassName);
+			} catch (ClassNotFoundException e) {
+				throw new RuntimeException("No such class: " + storeClassName + " : " + e.toString());
+			}
+
+			try {
+				store = ((VFSStoreFactory) clazz.newInstance()).create(meta, storeProps);
+			} catch (InstantiationException e) {
+				throw new RuntimeException("Could not instantiate class: " + clazz, e);
+			} catch (IllegalAccessException e) {
+				throw new RuntimeException("Not allowed to instantiate class: " + clazz, e);
+			} catch (Exception ex) {
+				throw new RuntimeException("Exception while instanciating: " + clazz, ex);
+			}
+		}
+
+		if (tagFactoryName != null) {
+			try {
+				clazz = cl.loadClass(tagFactoryName);
+			} catch (ClassNotFoundException e) {
+				throw new RuntimeException("No such class: " + tagFactoryName + " : " + e.toString());
+			}
+
+			try {
+				tagfactory = (TagFactory) clazz.newInstance();
+			} catch (InstantiationException e) {
+				throw new RuntimeException("Could not instantiate class: " + clazz);
+			} catch (IllegalAccessException e) {
+				throw new RuntimeException("Not allowed to instantiate class: " + clazz);
+			}
+		}
+
+		if (vfsImpl != null) {
+			try {
+				clazz = cl.loadClass(vfsImpl);
+			} catch (ClassNotFoundException e) {
+				throw new RuntimeException("No such class: " + vfsImpl + " : " + e.toString());
+			}
+
+			try {
+				Constructor cons = clazz.getConstructor(new Class[]{VFSMeta.class, VFSStore.class, TagFactory.class});
+				vfs = (VFS) cons.newInstance(new Object[]{meta, store, tagfactory});
+			} catch (InstantiationException e) {
+				throw new RuntimeException("Could not instantiate class: " + clazz);
+			} catch (IllegalAccessException e) {
+				throw new RuntimeException("Not allowed to instantiate class: " + clazz);
+			} catch (Exception e) {
+				throw new RuntimeException(e);
+			}
+		}
+
+		//vfs = new CachedDefaultVFS( meta, store, tagfactory );
+		//vfs = new DefaultVFS(meta, store, tagfactory);
+		if (vfs == null) {
+			log.warn("VFSImpl not specified. Using DefaultVFS");
+			vfs = new DefaultVFS(meta, store, tagfactory);
+		}
+
+
+		setServiceObject(vfs);
+
+		//return new VFSJMXProxy(getRegisteredName());
+		return vfs;
+	}
+
+
+	protected boolean bindByReference() {
+		return true;
+	}
+
+
+	public void setMetaClassFactory(String name) {
+		log.info("setMetaClassFactory: " + name);
+		metaClassName = name;
+	}
+
+
+	public void setStoreClassFactory(String name) {
+		log.info("setStoreClassFactory: " + name);
+		storeClassName = name;
+	}
+
+
+	public void setMetaPropertyString(String val) {
+		log.info("setMetaPropertyString: " + val);
+
+		Properties p = new Properties();
+
+		try {
+			p.load(new ByteArrayInputStream(val.getBytes()));
+		} catch (IOException ex) {
+			log.error("Could not load properties from StringInputStream.", ex);
+		}
+		metapropStr = val;
+		metaProps = p;
+	}
+
+	public void setStorePropertyString(String val) {
+		log.info("setStorePropertyString: " + val);
+
+		Properties p = new Properties();
+
+		try {
+			p.load(new ByteArrayInputStream(val.getBytes()));
+		} catch (IOException ex) {
+			log.error("Could not load properties from StringInputStream.", ex);
+		}
+		storepropStr = val;
+		storeProps = p;
+	}
+
+	public void setTagFactory(String val) {
+		log.info("setTagFactory: " + val);
+		tagFactoryName = val;
+	}
+
+	public void setVFSImpl(String name) {
+		log.info("setVFSImpl: " + name);
+		vfsImpl = name;
+	}
+
+	public String getName() {
+		return "CP2 VFS Binder Service";
+	}
+
+
+	public String getMetaClassFactory() {
+		return metaClassName;
+	}
+
+	public String getStoreClassFactory() {
+		return storeClassName;
+	}
+
+	public String getMetaPropertyString() {
+		return metapropStr;
+	}
+
+	public String getStorePropertyString() {
+		return storepropStr;
+	}
+
+	public String getTagFactory() {
+		return tagFactoryName;
+	}
+
+	public String getVFSImpl() {
+		return vfsImpl;
+	}
+}
+

Added: projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSServiceMBean.java
===================================================================
--- projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSServiceMBean.java	                        (rev 0)
+++ projects/fresh/trunk/fresh-shell/src/main/java/org/jboss/fresh/deployer/VFSServiceMBean.java	2009-04-29 16:35:08 UTC (rev 88015)
@@ -0,0 +1,29 @@
+package org.jboss.fresh.deployer;
+
+
+public interface VFSServiceMBean extends RegistryNamingBinderMBean {
+
+	public void setMetaClassFactory( String val );
+
+	public String getMetaClassFactory();
+
+	public void setStoreClassFactory( String val );
+
+	public String getStoreClassFactory();
+
+	public void setMetaPropertyString( String val );
+
+	public String getMetaPropertyString();
+
+	public void setStorePropertyString( String val );
+
+	public String getStorePropertyString();
+
+	public void setTagFactory( String val );
+
+	public String getTagFactory();
+
+	public void setVFSImpl( String name );
+
+	public String getVFSImpl();
+}




More information about the jboss-cvs-commits mailing list