[jboss-cvs] jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server ...

Robert Stryker rawblem at gmail.com
Thu Nov 9 19:26:25 EST 2006


  User: rawb    
  Date: 06/11/09 19:26:25

  Modified:    as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server          
                        JBossServer.java JBossServerBehavior.java
                        ServerAttributeHelper.java
  Added:       as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server          
                        JBossServerLaunchConfiguration.java
                        TwiddleLauncher.java
  Removed:     as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server          
                        ServerStateChecker.java ServerProcessEvent.java
                        IServerProcessListener.java IServerLogListener.java
                        JBossLaunchConfigurationDelegate.java
  Log:
  Rewrote Core entirley. It's clean and spiffy now. 
  
  Revision  Changes    Path
  1.15      +76 -72    jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServer.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JBossServer.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServer.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- JBossServer.java	6 Oct 2006 18:21:45 -0000	1.14
  +++ JBossServer.java	10 Nov 2006 00:26:25 -0000	1.15
  @@ -21,34 +21,30 @@
    */
   package org.jboss.ide.eclipse.as.core.server;
   
  +import java.io.File;
  +import java.util.Map;
  +
   import org.eclipse.core.runtime.CoreException;
   import org.eclipse.core.runtime.IProgressMonitor;
   import org.eclipse.core.runtime.IStatus;
   import org.eclipse.core.runtime.NullProgressMonitor;
  +import org.eclipse.core.runtime.Path;
   import org.eclipse.core.runtime.Status;
   import org.eclipse.debug.core.ILaunchConfiguration;
  -import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
  +import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
   import org.eclipse.wst.server.core.IModule;
   import org.eclipse.wst.server.core.IRuntime;
   import org.eclipse.wst.server.core.IServerWorkingCopy;
  -import org.eclipse.wst.server.core.ServerPort;
   import org.eclipse.wst.server.core.internal.Server;
   import org.eclipse.wst.server.core.model.ServerDelegate;
   import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
  -import org.jboss.ide.eclipse.as.core.model.DescriptorModel;
  -import org.jboss.ide.eclipse.as.core.model.ServerProcessModel;
  -import org.jboss.ide.eclipse.as.core.model.SimpleTreeItem;
  -import org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel;
  -import org.jboss.ide.eclipse.as.core.model.ServerProcessModel.ServerProcessModelEntity;
  -import org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper.SimpleXPathPreferenceTreeItem;
  -import org.jboss.ide.eclipse.as.core.server.ServerAttributeHelper.XPathPreferenceTreeItem;
  -import org.jboss.ide.eclipse.as.core.server.runtime.JBossServerRuntime;
  -import org.jboss.ide.eclipse.as.core.util.ASDebug;
  -
  -public class JBossServer extends ServerDelegate {
  +import org.jboss.ide.eclipse.as.core.runtime.IJBossServerLaunchDefaults;
  +import org.jboss.ide.eclipse.as.core.runtime.IJBossServerRuntime;
  +import org.jboss.ide.eclipse.as.core.runtime.server.ServerLaunchDefaults;
  +import org.jboss.ide.eclipse.as.core.server.attributes.IServerStartupParameters;
  +import org.jboss.ide.eclipse.as.core.util.ArgsUtil;
   
  -	
  -	private JBossServerRuntime runtime;
  +public class JBossServer extends ServerDelegate implements IServerStartupParameters {
   	
   	
   	public JBossServer() {
  @@ -59,13 +55,6 @@
   		
   	}
   	
  -	public void debug( String s ) {
  -		ASDebug.p(s, this);
  -	}
  -	
  -	/*
  -	 * OVERRIDES
  -	 */
   
   	public void setDefaults(IProgressMonitor monitor) {
   	}
  @@ -74,50 +63,17 @@
   	}
   
   	public void saveConfiguration(IProgressMonitor monitor) throws CoreException {
  -		// Saving a change in server properties (via server editor)
  -		try {
  -			String newHost = getServer().getHost();
  -			
  -			ILaunchConfiguration launchConfig = 
  -				((Server)getServer()).getLaunchConfiguration(false, new NullProgressMonitor());
  -	
  -			if( launchConfig != null ) 
  -				JBossLaunchConfigurationDelegate.setHost(launchConfig, newHost, getDescriptorModel().getJNDIPort());
  -		} catch( Exception e ) {
  -			
  -		}
   	}
   
   	public void configurationChanged() {
   	}
   
   
  -	/*
  -	 * Other
  -	 */
  -	public void setRuntime(JBossServerRuntime run) {
  -		runtime = run;
  -	}
  -	
  -	public JBossServerRuntime getJBossRuntime() {
  -		if( runtime == null ) {
  -			runtime = (JBossServerRuntime) getServer().getRuntime().loadAdapter(JBossServerRuntime.class, null);
  -		}
  -		return runtime;
  -		
  +	public IJBossServerLaunchDefaults getLaunchDefaults() {
  +		return new ServerLaunchDefaults(getServer());
   	}
   
   	
  -	public ServerAttributeHelper getAttributeHelper() {
  -//		IServer server = ServerCore.findServer(getServer().getId());
  -//		IServerWorkingCopy copy = server.createWorkingCopy();
  -		IServerWorkingCopy copy = getServerWorkingCopy();
  -		if( copy == null ) {
  -			copy = getServer().createWorkingCopy();
  -		}
  -		return new ServerAttributeHelper(this, copy);
  -	}
  -	
   	
   	/*
   	 * Abstracts to implement
  @@ -127,39 +83,87 @@
   	}
   
   	public IModule[] getChildModules(IModule[] module) {
  -		//debug("*****  getChildModules");
   		return null;
   	}
   
   	// As of now none of my modules are implementing the parent / child nonesense
   	public IModule[] getRootModules(IModule module) throws CoreException {
  -		//debug("***** getRootModules");
   		return new IModule[] { module };
   	}
   
   	
   	public void modifyModules(IModule[] add, IModule[] remove,
   			IProgressMonitor monitor) throws CoreException {
  +	}
  +	
  +	public boolean equals(Object o2) {
  +		if( !(o2 instanceof JBossServer)) 
  +			return false;
  +		JBossServer o2Server = (JBossServer)o2;
  +		return o2Server.getServer().getId().equals(getServer().getId());
  +	}
  +	
  +	
   		
  -		// Do nothing for now, just display to know I've been called. 
  +	public ServerAttributeHelper getAttributeHelper() {
  +		IServerWorkingCopy copy = getServerWorkingCopy();
  +		if( copy == null ) {
  +			copy = getServer().createWorkingCopy();
   	}
  +		return new ServerAttributeHelper(getServer(), copy);
  +	}
  +
  +	
   	
  -	public ServerPort[] getServerPorts() {
  -		return getAttributeHelper().getServerPorts();
  +	
  +	// TODO: PUT SOMEWHERE ELSE
  +	public String getDeployDirectory() {
  +		String deployDir = getLaunchConfigDeployDir();
  +		if( deployDir == null )  
  +			return getRuntimeDeployDirectory();
  +
  +		File f = new File(deployDir);
  +		if( !f.exists() || !f.canRead() || !f.isDirectory())
  +			return getRuntimeDeployDirectory();
  +
  +		return deployDir;
   	}
   
  -	public ServerProcessModelEntity getProcessModel() {
  -		return ServerProcessModel.getDefault().getModel(getServer().getId());
  +	protected String getLaunchConfigDeployDir() {
  +		try {
  +			Server s = (Server)getServer();
  +			ILaunchConfiguration lc = s.getLaunchConfiguration(true, new NullProgressMonitor());
  +			String startArgs = lc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS 
  +					+ JBossServerLaunchConfiguration.PRGM_ARGS_START_SUFFIX, (String)null);
  +			Map map = ArgsUtil.getSystemProperties(startArgs);
  +			
  +			if( map.get(JBOSS_SERVER_HOME_DIR) != null ) 
  +				return (String)map.get(JBOSS_SERVER_HOME_DIR) + Path.SEPARATOR + DEPLOY;
  +
  +			if( map.get(JBOSS_SERVER_BASE_DIR) != null ) {
  +				String name = map.get(JBOSS_SERVER_NAME) != null ? 
  +						(String)map.get(JBOSS_SERVER_NAME) : DEFAULT_SERVER_NAME;
  +				return (String)map.get(JBOSS_SERVER_BASE_DIR) + Path.SEPARATOR + name + Path.SEPARATOR + DEPLOY;
  +			}
  +			
  +			if( map.get(JBOSS_HOME_DIR) != null ) {
  +				return (String)map.get(JBOSS_HOME_DIR) + Path.SEPARATOR + SERVER 
  +					+ Path.SEPARATOR + DEFAULT_SERVER_NAME + Path.SEPARATOR + DEPLOY;
   	}
   	
  -	public ServerDescriptorModel getDescriptorModel() {
  -		return DescriptorModel.getDefault().getServerModel(getServer());
  +			return null;
  +		} catch( CoreException ce ) {
  +			return null;
  +		}
   	}
   	
  -	public boolean equals(Object o2) {
  -		if( !(o2 instanceof JBossServer)) 
  -			return false;
  -		JBossServer o2Server = (JBossServer)o2;
  -		return o2Server.getServer().getId().equals(getServer().getId());
  +	// The deploy directory of the configuration in the runtime
  +	protected String getRuntimeDeployDirectory() {
  +		IJBossServerRuntime runtime = (IJBossServerRuntime)
  +		getServer().getRuntime().loadAdapter(IJBossServerRuntime.class, null);
  +
  +		return getServer().getRuntime().getLocation().toOSString() + Path.SEPARATOR + "server" + 
  +		Path.SEPARATOR + runtime.getJBossConfiguration() + Path.SEPARATOR + "deploy";
   	}
  +	
   }
  \ No newline at end of file
  
  
  
  1.11      +184 -278  jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JBossServerBehavior.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerBehavior.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- JBossServerBehavior.java	6 Nov 2006 17:03:34 -0000	1.10
  +++ JBossServerBehavior.java	10 Nov 2006 00:26:25 -0000	1.11
  @@ -21,294 +21,238 @@
    */
   package org.jboss.ide.eclipse.as.core.server;
   
  -import java.util.List;
  +import java.util.Date;
   
   import org.eclipse.core.runtime.CoreException;
   import org.eclipse.core.runtime.IProgressMonitor;
  -import org.eclipse.core.runtime.IStatus;
   import org.eclipse.core.runtime.NullProgressMonitor;
  -import org.eclipse.core.runtime.Path;
  -import org.eclipse.core.runtime.Status;
   import org.eclipse.debug.core.ILaunchConfiguration;
   import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
   import org.eclipse.debug.core.ILaunchManager;
   import org.eclipse.debug.core.model.IProcess;
  -import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
   import org.eclipse.wst.server.core.IModule;
   import org.eclipse.wst.server.core.IServer;
   import org.eclipse.wst.server.core.internal.Server;
  -import org.eclipse.wst.server.core.internal.ServerPlugin;
  +import org.eclipse.wst.server.core.internal.ServerType;
   import org.eclipse.wst.server.core.model.IModuleResourceDelta;
   import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
  -import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
  +import org.jboss.ide.eclipse.as.core.JBossServerCore;
   import org.jboss.ide.eclipse.as.core.model.ModuleModel;
   import org.jboss.ide.eclipse.as.core.model.ServerProcessModel;
  -import org.jboss.ide.eclipse.as.core.model.ServerProcessLog.ProcessLogEvent;
  -import org.jboss.ide.eclipse.as.core.model.ServerProcessModel.ProcessData;
  -import org.jboss.ide.eclipse.as.core.model.ServerProcessModel.ServerProcessModelEntity;
  -import org.jboss.ide.eclipse.as.core.server.publishers.IJbossServerPublisher;
  -import org.jboss.ide.eclipse.as.core.server.publishers.JstPublisher;
  -import org.jboss.ide.eclipse.as.core.server.publishers.NullPublisher;
  -import org.jboss.ide.eclipse.as.core.server.publishers.PackagedPublisher;
  -import org.jboss.ide.eclipse.as.core.server.runtime.AbstractServerRuntimeDelegate;
  -import org.jboss.ide.eclipse.as.core.server.runtime.IJBossServerRuntimeDelegate;
  -import org.jboss.ide.eclipse.as.core.server.runtime.JBossServerRuntime;
  -import org.jboss.ide.eclipse.as.core.util.ASDebug;
  +import org.jboss.ide.eclipse.as.core.publishers.IJBossServerPublisher;
  +import org.jboss.ide.eclipse.as.core.publishers.JstPublisher;
  +import org.jboss.ide.eclipse.as.core.publishers.NullPublisher;
  +import org.jboss.ide.eclipse.as.core.publishers.PackagedPublisher;
  +import org.jboss.ide.eclipse.as.core.runtime.IServerStatePoller;
  +import org.jboss.ide.eclipse.as.core.runtime.server.IServerPollerTimeoutListener;
  +import org.jboss.ide.eclipse.as.core.runtime.server.internal.TwiddlePoller;
  +import org.jboss.ide.eclipse.as.core.server.attributes.IServerPollingAttributes;
   
   public class JBossServerBehavior extends ServerBehaviourDelegate {
  -	public static final String ATTR_ACTION = "__ACTION__";
  -	public static final String ACTION_STOPPING = "__ACTION_STOPPING__";
  -	public static final String ACTION_STARTING = "__ACTION_STARTING__";
  -	public static final String ACTION_TWIDDLE = "__ACTION_TWIDDLE__";
  -	
   	public static final String LAUNCH_CONFIG_DEFAULT_CLASSPATH = "__JBOSS_SERVER_BEHAVIOR_LAUNCH_CONFIG_DEFAULT_CLASSPATH__";
   	
  -	private JBossServer jbServer = null;
  -	private ProcessLogEvent log = null;
  -	private ServerStateChecker checker = null;
  -	
  -	
   
  +	private PollThread pollThread = null;
   	public JBossServerBehavior() {
   		super();
   	}
   
  -	/**
  -	 * Probally called when it shouldn't be, but, 
  -	 * ensures that a stopped server is indeed stopped and 
  -	 * all process references are terminated and removed from
  -	 * the serverProcessModel.
  -	 *
  -	 * Ensures no rogue unreferenced jboss processes are left
  -	 * executing in the background draining resources. 
  -	 */
  -	public void forceStop() {
  -		getJBossServer().getProcessModel().clearAll();
  -		setServerStopped();
  -		return;
  -	}
  -	
   	public void stop(boolean force) {
  -
  -		int state = getServer().getServerState();
  -		if (state == IServer.STATE_STOPPED || force ) {
  +		if( force ) {
   			forceStop();
   			return;
   		}
   
  -		
  -		
  -		JBossServer jbServer = getJBossServer();
  -		JBossServerRuntime runtime = jbServer.getJBossRuntime();
  -		AbstractServerRuntimeDelegate runtimeDelegate = runtime.getVersionDelegate();
  -		ServerProcessModelEntity processModel = jbServer.getProcessModel();
  -
  -
  -		
  -		// If we have no reference to any start processes, give up
  -		if( processModel.getProcessDatas(ServerProcessModel.START_PROCESSES).length == 0 ) {
  -			// no start processes exist. Give it up.
  -			setServerStopped(); 
  +		// If the server's already terminated via processes, just abort
  +		IProcess[] startProcesses = 
  +			ServerProcessModel.getDefault().getModel(getServer().getId()).getProcesses(JBossServerLaunchConfiguration.START);
  +		if( ServerProcessModel.allProcessesTerminated(startProcesses)) {
  +			forceStop();
   			return;
   		}
   		
  -		// If we do have referneces but they're all terminated already, give up
  -		ProcessData[] datas = processModel.getProcessDatas(ServerProcessModel.START_PROCESSES);
  -		boolean alive = false;
  -		for( int i = 0; i < datas.length; i++ ) {
  -			if( !datas[i].getProcess().isTerminated()) {
  -				alive = true;
  -			}
  -		}
  -
  -		// and clear it for good measure
  -		if( !alive ) {
  +		// if we're starting up or shutting down and they've tried again, 
  +		// then force it to stop. 
  +		int state = getServer().getServerState();
  +		if( state == IServer.STATE_STARTING || state == IServer.STATE_STOPPING || state == IServer.STATE_STOPPED) {
  +			pollThread.cancel();
   			forceStop();
   			return;			
   		}
   		
   		
  -		
  -		// Now we actually have to shut it down. Oh well.
  -
  +		// Otherwise execute a shutdown attempt
   		try {
   			// Set up our launch configuration for a STOP call (to shutdown.jar)
  -			ILaunchConfiguration wc = JBossLaunchConfigurationDelegate.setupLaunchConfiguration(jbServer, ACTION_STOPPING);
  -			ServerAttributeHelper helper = getJBossServer().getAttributeHelper();
  -
  +			ILaunchConfiguration wc = JBossServerLaunchConfiguration.setupLaunchConfiguration(getServer(), JBossServerLaunchConfiguration.STOP);
   			wc.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());
  -			
  -			int maxWait = helper.getStopTimeout();
  -			int soFar = 0;
  -			
  -			// waiting for our stop process to be created
  -			while( processModel.getProcesses(ServerProcessModel.STOP_PROCESSES) == null ) {
  -				soFar += 250;
  -				Thread.sleep(250);
  -			}
  -			
  -			// Now waiting for them to all finish execution
  -			while( !ServerProcessModel.allProcessesTerminated(processModel.getProcesses(ServerProcessModel.STOP_PROCESSES)) 
  -					&& soFar < maxWait) {
  -				soFar += 100;
  -				try {
  -					Thread.sleep(100);
  -				} catch( InterruptedException ie ) {
  +		} catch( Exception e ) {
   				}
   			}
   			
  -			// We're going to stop the server and get rid of all processes, 
  -			// so grab a reference to them all first!
  -
  -			IProcess[] stopProcesses = processModel.getProcesses(ServerProcessModel.STOP_PROCESSES);
  -			IProcess[] startProcesses = processModel.getProcesses(ServerProcessModel.START_PROCESSES);
  -			processModel.clear(ServerProcessModel.TWIDDLE_PROCESSES);
  -			
  -
  -			if( soFar >= maxWait ) {
  -				// we timed OUT... even our stop thread didn't finish yet
  -				// time to manually terminate EVERYTHING
  -				forceStop();
  -				return;
  -			} else {
  -				// The stop process ended. Let's see if it ended successfully.
  -				
  -				if( stopProcesses[0].isTerminated()) {
  -					if( stopProcesses[0].getExitValue() != 0 ) {
  -						// Our stop process ended with exceptions. That means the server is still running.
  -						// We need to shut it down.  
  -						forceStop();
  -						return;
  +	protected void forceStop() {
  +		// just terminate the processes. All of them
  +		try {
  +			ServerProcessModel.getDefault().getModel(getServer().getId()).clearAll();
  +			setServerStopped();
  +		} catch( Throwable t ) {
  +			t.printStackTrace();
   					}
   				}
   
  -			}
  -		}
  -		catch (Exception e) {
  -		}
   
  -		/*
  -		 * Ok... if we didn't switch to forceStop already, then that means
  -		 * the server is in the process of shutting down. We can terminate the 
  -		 * stop launch (the process executing shutdown.jar) but we must let 
  -		 * the start processes (the server) to terminate on its own.
  -		 * We can, however, tell the model to delete those processes upon completion.
  -		 */
  -		processModel.clear(ServerProcessModel.STOP_PROCESSES);
  -		processModel.removeProcessOnTerminate(processModel.getProcesses(ServerProcessModel.START_PROCESSES));
   
  +	public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProgressMonitor monitor) throws CoreException {
  +		JBossServerLaunchConfiguration.setupLaunchConfiguration(workingCopy, getServer(), JBossServerLaunchConfiguration.START);
   	}
   
   
   	
   	
  -	public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProgressMonitor monitor) throws CoreException {
  -		JBossLaunchConfigurationDelegate.setupLaunchConfiguration(workingCopy, getJBossServer(), ACTION_STARTING);
  -	}
   	
  -	/**
  -	 * Outline that the server is starting.
  -	 * Launch a continuous batch of twiddles to determine 
  -	 * when the server is up.
  -	 */
   	public void serverStarting() {
   		setServerStarting();
  -		if( checker != null ) {
  -			checker.cancel();
  -		}
  -		checker = new ServerStateChecker(this, ServerStateChecker.UP);
  -		checker.start();
  +		pollServer(IServerStatePoller.SERVER_UP);
   	}
   	
  -	/**
  -	 * Outline that the server is stopping.
  -	 * Launch a continuous batch of twiddles to determine 
  -	 * when the server is down.
  -	 */
   	public void serverStopping() {
   		setServerStopping();
  -		if( checker != null ) {
  -			checker.cancel();
  +		pollServer(IServerStatePoller.SERVER_DOWN);
   		}
   
  -		checker = new ServerStateChecker(this, ServerStateChecker.DOWN);
  -		checker.start();
  -	}
   	
  -	
  -	/*
  -	 * Change the state of the server
  -	 */
  -	private void setServerStarted() {
  -		setServerState(IServer.STATE_STARTED);
  +	public class PollThread extends Thread {
  +		private boolean expectedState;
  +		private IServerStatePoller poller;
  +		private boolean abort;
  +		public PollThread(String name, IServerStatePoller poller, boolean expectedState) {
  +			super(name);
  +			this.expectedState = expectedState;
  +			this.poller = poller;
  +			this.abort = false;
   	}
   	
  -	private void setServerStarting() {
  -		setServerState(IServer.STATE_STARTING);
  +		public void cancel() {
  +			abort = true;
   	}
   	
  -	private void setServerStopped() {
  -		setServerState(IServer.STATE_STOPPED);
  +		
  +		// Getting the timeouts. First from plugin.xml as default, or from user settings.
  +		public int getTimeout() {
  +			int timeout;
  +			JBossServer jbs = ((JBossServer)getServer().loadAdapter(JBossServer.class, null));
  +			ServerAttributeHelper helper = (ServerAttributeHelper)jbs.getAttributeHelper();
  +			if( expectedState == IServerStatePoller.SERVER_UP) {
  +				int def = ((ServerType)getServer().getServerType()).getStartTimeout();
  +				timeout = helper.getAttribute(IServerPollingAttributes.START_TIMEOUT, def);
  +			} else {
  +				int def = ((ServerType)getServer().getServerType()).getStopTimeout();
  +				timeout = helper.getAttribute(IServerPollingAttributes.STOP_TIMEOUT, def);
  +			}
  +			return timeout;
   	}
   	
  -	private void setServerStopping() {
  -		setServerState(IServer.STATE_STOPPING);
  +		
  +		public void run() {
  +			int maxWait = getTimeout();
  +
  +			long startTime = new Date().getTime();
  +			boolean done = false;
  +			poller.beginPolling(getServer(), expectedState);
  +			while( !abort && !done && new Date().getTime() < startTime + maxWait ) {
  +				try {
  +					Thread.sleep(100);
  +					done = poller.isComplete();
  +				} catch( InterruptedException ie ) { }
   	}
  +			boolean currentState = !expectedState;
  +			if( abort ) {
  +				poller.cancel(IServerStatePoller.CANCEL);
  +				poller.cleanup();
  +			} else {
   
  -	/**
  -	 * This is where the ServerStateChecker responds. 
  -	 * @param serverUp whether the server is up or not. 
  -	 */
  -	public void setServerState(boolean waitingFor, boolean serverUp) {
  -		if( !serverUp ) {
  -			/* Fail safe... if the server times OUT but it IS starting 
  -			 * but not quick enough, clear / destroy all generated processes.
  -			 * 
  -			 * Otherwise, there are start processes but the gui has 'stop' greyed
  -			 * OUT and unavailable for selection. 
  -			 * 
  -			 * Included inside if statement so it doesn't prematurely
  -			 * shut down the server while it's in the process of shutting down.
  -			 */
  -			if( waitingFor == ServerStateChecker.UP ) {
  -				getJBossServer().getProcessModel().clearAll();
  +				if( done ) {
  +					// the poller has an answer
  +					currentState = poller.getState();
  +					poller.cleanup();
  +				} else {
  +					// we timed out.  get response from preferences
  +					poller.cancel(IServerStatePoller.TIMEOUT_REACHED);
  +					currentState = getTimeoutBehavior();
  +					poller.cleanup();
  +					fireTimeoutEvent();
   			}
  -			setServerStopped();
  +				
  +				if( currentState != expectedState ) {
  +					// it didnt work... cancel all processes!
  +					forceStop();
   		} else {
  +					if( currentState == IServerStatePoller.SERVER_UP ) 
   			setServerStarted();
  +					else
  +						setServerStopped();
  +				}
   		}
   	}
  +		protected boolean getTimeoutBehavior() {
  +			// timeout has been reached, so let the user's preferences override
  +			JBossServer jbs = ((JBossServer)getServer().loadAdapter(JBossServer.class, null));
  +			ServerAttributeHelper helper = (ServerAttributeHelper)jbs.getAttributeHelper();
   
  -	private JBossServer getJBossServer() {
  -		if( jbServer == null ) {
  -			jbServer = (JBossServer)getServer().loadAdapter(JBossServer.class, null);
  +			boolean behavior = helper.getAttribute(IServerPollingAttributes.TIMEOUT_BEHAVIOR, true);
  +			if( behavior == IServerPollingAttributes.TIMEOUT_ABORT ) 
  +				return !expectedState;
  +
  +			return expectedState;
  +		}
  +		
  +		protected void fireTimeoutEvent() {
  +			IServerPollerTimeoutListener[] listeners = 
  +				JBossServerCore.getDefault().getTimeoutListeners(poller.getClass().getName());
  +			for( int i = 0; i < listeners.length; i++ ) {
  +				listeners[i].serverTimedOut(getServer(), expectedState);
  +			}
   		}
  -		return jbServer;
   	}
   	
  +	protected void pollServer(final boolean expectedState) {
  +		if( this.pollThread != null ) {
  +			pollThread.cancel();
  +		}
  +		this.pollThread = new PollThread("Server Poller", new TwiddlePoller(), expectedState);
  +//		this.pollThread = new PollThread("Server Poller", new TimeoutPoller(), expectedState);
  +		pollThread.start();
  +	}
   	
   
  -	/**
  -	 * Here I go with the default implementatiion for MOST of the situations, 
  -	 * but I first check my ModuleModel to see if I have any pressing / overriding
  -	 * designations. 
  -	 */
  +	// By default, goes to check if the members are all the same or any changes
   	public IModuleResourceDelta[] getPublishedResourceDelta(IModule[] module) {
  -		// if my model has any reference to them, use that.
  -		ModuleModel model = ModuleModel.getDefault();
  -		IModuleResourceDelta[] deltas = model.getDeltaModel().getRecentDeltas(module, getServer());
  -		if( deltas.length != 0 )
  -			return deltas;
  -
   		return ((Server)getServer()).getPublishedResourceDelta(module);
   	}
   	
  -	
   	protected void publishModule(int kind, int deltaKind, IModule[] module, IProgressMonitor monitor) throws CoreException {
  +		// kind = [incremental, full, auto, clean] = [1,2,3,4]
  +		// delta = [no_change, added, changed, removed] = [0,1,2,3]
  +
  +		System.out.print("publishing module: ");
  +		switch( kind ) {
  +			case 1: System.out.print("incremental, "); break;
  +			case 2: System.out.print("full, "); break;
  +			case 3: System.out.print("auto, "); break;
  +			case 4: System.out.print("clean, "); break;
  +		}
  +		switch( deltaKind ) {
  +			case 0: System.out.print("no change"); break;
  +			case 1: System.out.print("added"); break;
  +			case 2: System.out.print("changed"); break;
  +			case 3: System.out.print("removed"); break;
  +		}
  +		System.out.println("");
  +		
   		if( module.length == 0 ) return;
   					
  -		IJbossServerPublisher publisher;
  -		ASDebug.p("Module type is " + module[0].getModuleType().getId(), this);
  +		IJBossServerPublisher publisher;
  +
   		/**
   		 * If our modules are already packaged as ejb jars, wars, aop files, 
   		 * then go ahead and publish
  @@ -316,18 +260,22 @@
   		if( hasPackagingConfiguration(module) ) {
   			// will be changed
   			publisher = new NullPublisher();
  -		} else if( ModuleModel.arePackagedModules(module)) {
  -			publisher = new PackagedPublisher(getJBossServer(), this);
  +		} else if( arePackagedModules(module)) {
  +			publisher = new PackagedPublisher(JBossServerCore.getServer(getServer()), this);
   		} else if( areJstModules(module)){
  -			publisher = new JstPublisher(getJBossServer());
  +			publisher = new JstPublisher(JBossServerCore.getServer(getServer()));
   		} else {
   			publisher = new NullPublisher();
   		}
   		
  -		
   		publisher.publishModule(kind, deltaKind, module, monitor);
   		setModulePublishState(module, publisher.getPublishState());
  -		log.addChildren(publisher.getLogEvents());
  +	}
  +	
  +	public boolean arePackagedModules(IModule[] module) {
  +		if( module.length == 1 && module[0].getModuleType().getId().equals("jboss.archive"))
  +			return true;
  +		return false;
   	}
   	
   	/* Temporary and will need to be fixed */
  @@ -346,69 +294,27 @@
   		return false;
   	}
   	
  -	public static class PublishLogEvent extends ProcessLogEvent {
  -		public static final int ROOT = 0;
  -		public static final int PUBLISH = 1;
  -		public static final int UNPUBLISH = 2;
  -		
  -		public static final String MODULE_NAME = "_MODULE_NAME_";
  -		
  -		public PublishLogEvent(int type) {
  -			super(type);
  -		}
   		
  -		public String getModuleName() {
  -			try {
  -				return (String)getProperty(MODULE_NAME);
  -			} catch( Exception e ) {}
  -			return null;
  -		}
  -		
  -	}
   	
   	
  -	/**
  -	 * Logging information for log listeners
  -	 */
  -	protected void publishStart(IProgressMonitor monitor) throws CoreException {
  -		ServerProcessModelEntity e = ServerProcessModel.getDefault().getModel(getServer().getId());
  -		log = new PublishLogEvent(PublishLogEvent.ROOT);
  -		e.getEventLog().newMajorEvent(log);
  -	}
  -
  -	/**
  -	 * Logging information for log listeners
  +	/*
  +	 * Change the state of the server
   	 */
  -	protected void publishFinish(IProgressMonitor monitor) throws CoreException {
  -		if( log.getChildren().length > 0 ) {
  -			log.getRoot().branchChanged();
  -		} else {
  -			log.getParent().deleteChild(log);
  -		}
  -		
  -		log = null;
  -	}
  -
  -	public void restart(String launchMode) throws CoreException {
  -		ASDebug.p("restart", this);
  -		 throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, "Could not restart", null));
  +	private void setServerStarted() {
  +		setServerState(IServer.STATE_STARTED);
   	}
   
  -	
  -	
  -	public boolean canControlModule(IModule[] module) {
  -		ASDebug.p("canControlModule", this);
  -		return false;
  +	private void setServerStarting() {
  +		setServerState(IServer.STATE_STARTING);
   	}
   
  -	public void startModule(IModule[] module, IProgressMonitor monitor) throws CoreException {
  +	private void setServerStopped() {
  +		setServerState(IServer.STATE_STOPPED);
   	}
   
  -	public void stopModule(IModule[] module, IProgressMonitor monitor) throws CoreException {
  +	private void setServerStopping() {
  +		setServerState(IServer.STATE_STOPPING);
   	}
   
  -	public int getJndiPort() {
  -		return getJBossServer().getDescriptorModel().getJNDIPort();
  -	}
   
   }
  
  
  
  1.14      +92 -364   jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/ServerAttributeHelper.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ServerAttributeHelper.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/ServerAttributeHelper.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -b -r1.13 -r1.14
  --- ServerAttributeHelper.java	12 Oct 2006 19:56:43 -0000	1.13
  +++ ServerAttributeHelper.java	10 Nov 2006 00:26:25 -0000	1.14
  @@ -1,375 +1,103 @@
  +/**
  + * JBoss, a Division of Red Hat
  + * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
  + * by the @authors tag. See the copyright.txt in the distribution for a
  + * full listing of individual contributors.
  + *
  +* This is free software; you can redistribute it and/or modify it
  + * under the terms of the GNU Lesser General Public License as
  + * published by the Free Software Foundation; either version 2.1 of
  + * the License, or (at your option) any later version.
  + *
  + * This software is distributed in the hope that it will be useful,
  + * but WITHOUT ANY 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 along with this software; if not, write to the Free
  + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  + */
   package org.jboss.ide.eclipse.as.core.server;
   
  -import java.io.File;
  -import java.util.ArrayList;
  -import java.util.HashMap;
  -import java.util.Iterator;
   import java.util.List;
  +import java.util.Map;
   
  +import org.eclipse.core.runtime.CoreException;
  +import org.eclipse.core.runtime.IProgressMonitor;
  +import org.eclipse.wst.server.core.IServer;
   import org.eclipse.wst.server.core.IServerWorkingCopy;
  -import org.eclipse.wst.server.core.ServerPort;
  -import org.eclipse.wst.server.core.internal.ServerType;
   import org.eclipse.wst.server.core.internal.ServerWorkingCopy;
  -import org.jboss.ide.eclipse.as.core.model.SimpleTreeItem;
  -import org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel.XPathTreeItem;
  -import org.jboss.ide.eclipse.as.core.model.DescriptorModel.ServerDescriptorModel.XPathTreeItem2;
  -import org.jboss.ide.eclipse.as.core.server.runtime.AbstractServerRuntimeDelegate;
  -import org.jboss.ide.eclipse.as.core.util.ASDebug;
   
   public class ServerAttributeHelper {
  -	public static final String PORTS_DEFAULT_CATEGORY = "Ports";
  -	public static final String PROP_MINIMAL_CONFIG = "MINIMAL_CONFIG";
  -	public static final String JBOSS_SERVER_HOME = "JBOSS_SERVER_HOME";
  -	public static final String JBOSS_CONFIG = "JBOSS_CONFIG";
  -	public static final String JBOSS_CONFIG_DEFAULT = "default";
  -
  -	public static final String PORT_CATEGORY_PREF_KEY = "_PORT_CATEGORY_NAME_";
  -	public static final String PORT_NUMBERS_LIST = "_PORT_NUMBERS_LIST_";
  -	
  -	public static final String XPATH_CATEGORIES = "_XPATH_CATEGORIES_";
  -	public static final String XPATH_CATEGORY2_PREFIX = "_XPATH_CATEGORY2_PREFIX_";
  -	public static final String XPATH_PROPERTY_PREFIX = "_XPATH_PROPERTY_PREFIX_";
  -	
  -	public static final String START_TIMEOUT = "_START_TIMEOUT_";
  -	public static final String STOP_TIMEOUT = "_STOP_TIMEOUT_";
  -
  -	
  -	public static final String TIMEOUT_BEHAVIOR = "_TIMEOUT_BEHAVIOR_";
  -	public static final boolean TIMEOUT_ABORT = true;
  -	public static final boolean TIMEOUT_IGNORE = false;
   	
  -	
  -	private ServerWorkingCopy server;
  -	private JBossServer jbServer;
  -	public ServerAttributeHelper(JBossServer jbServer, IServerWorkingCopy copy) {
  -		this.server = (ServerWorkingCopy)copy;
  -		this.jbServer = jbServer;
  +	private ServerWorkingCopy wch;
  +	private IServer server;
  +	public ServerAttributeHelper(IServer server, IServerWorkingCopy copy) {
  +		this.wch = (ServerWorkingCopy)copy;
  +		this.server = server;
   	}
   	
   
  -	
  -	public String getServerHome() {
  -		return server.getRuntime().getLocation().toOSString();
  -		//return server.getAttribute(JBOSS_SERVER_HOME, (String)null);
  -	}
  -	public String getJbossConfiguration() {
  -		return jbServer.getJBossRuntime().getConfigName();
  -		//return server.getAttribute(JBOSS_CONFIG, JBOSS_CONFIG_DEFAULT);
  +	public IServer getServer() {
  +		return server;
   	}
   	
  -	public void setServerHome( String home ) {
  -		jbServer.getJBossRuntime().setLocation(home);
  -		//server.setAttribute(ServerAttributeHelper.JBOSS_SERVER_HOME, home);
  +	public void setAttribute(String attributeName, int value) {
  +		wch.setAttribute(attributeName, value);
   	}
   	
  -	public void setJbossConfiguration( String config ) {
  -		jbServer.getJBossRuntime().setConfigName(config);
  +	public void setAttribute(String attributeName, boolean value) {
  +		wch.setAttribute(attributeName, value);
   	}	
   	
  -	public void save() {
  -		try {
  -			server.save(true, null);
  -		} catch( Exception e) {
  +	public void setAttribute(String attributeName, String value) {
  +		wch.setAttribute(attributeName, value);
   		}
  -	}
  -	
   	
  -	/*
  -	 * These methods go back to the version delegate for defaults if 
  -	 * they are not set as attributes here.
  -	 */
  -	
  -	public String[] getMinimalConfig() {
  -		String minimal;
  -		if( (minimal=server.getAttribute(PROP_MINIMAL_CONFIG, (String)null)) == null ) {
  -			return getVersionDelegate().getMinimalRequiredPaths();
  -		}
  -		return minimal.split("\n");
  +	public void setAttribute(String attributeName, List value) {
  +		wch.setAttribute(attributeName, value);
   	}
   
  -	
  -	public String getConfigurationPath() {
  -		return getServerHome() + File.separator + "server" + File.separator + getJbossConfiguration();
  +	public void setAttribute(String attributeName, Map value) {
  +		wch.setAttribute(attributeName, value);
   	}
   	
   	
  -	public String getDeployDirectory() {
  -		return getConfigurationPath() + File.separator + "deploy";
  -	}
  -	
  -	public AbstractServerRuntimeDelegate getVersionDelegate() {
  -		return jbServer.getJBossRuntime().getVersionDelegate();
  -	}
   
   	
   	
  -	public int getStartTimeout() {
  -		int prop = server.getAttribute(START_TIMEOUT, -1);
  -		int max = ((ServerType)server.getServerType()).getStartTimeout();
  -		
  -		if( prop <= 0 || prop > max ) return max;
  -		return prop;
  +	public String getAttribute(String attributeName, String defaultValue) {
  +		return wch.getAttribute(attributeName, defaultValue);
   	}
  -	public int getStopTimeout() {
  -		int prop = server.getAttribute(STOP_TIMEOUT, -1);
  -		int max = ((ServerType)server.getServerType()).getStopTimeout();
   		
  -		if( prop <= 0 || prop > max ) return max;
  -		return prop;
  +	public int getAttribute(String attributeName, int defaultValue) {
  +		return wch.getAttribute(attributeName, defaultValue);
   	}
   	
  -	public void setStartTimeout(int time) {
  -		server.setAttribute(START_TIMEOUT, time);
  -	}
  -	public void setStopTimeout(int time) {
  -		server.setAttribute(STOP_TIMEOUT, time);
  +	public boolean getAttribute(String attributeName, boolean defaultValue) {
  +		return wch.getAttribute(attributeName, defaultValue);
   	}
   	
  -	
  -	public void setTimeoutBehavior(boolean bool) {
  -		server.setAttribute(TIMEOUT_BEHAVIOR, bool);
  +	public List getAttribute(String attributeName, List defaultValue) {
  +		return wch.getAttribute(attributeName, defaultValue);
   	}
  -	public boolean getTimeoutBehavior() {
  -		return server.getAttribute(TIMEOUT_BEHAVIOR, TIMEOUT_IGNORE);
  -	}
  -	
   	
  -	public IServerWorkingCopy getServer() {
  -		return this.server;
  +	public Map getAttribute(String attributeName, Map defaultValue) {
  +		return wch.getAttribute(attributeName, defaultValue);
   	}
   	
  -	public String getDefaultPortCategoryName() {
  -		return server.getAttribute(PORT_CATEGORY_PREF_KEY, PORTS_DEFAULT_CATEGORY);
  -	}
  -	public void setDefaultPortCategoryName(String s) {
  -		server.setAttribute(PORT_CATEGORY_PREF_KEY, s);
  -	}
  -	
  -	public void setServerPorts(SimpleXPathPreferenceTreeItem root) {
  -		String portCategory = getDefaultPortCategoryName();
  -		SimpleTreeItem[] categories = root.getChildren2();
  -		SimpleTreeItem portCategoryObject = null;
  -		for( int i = 0; i < categories.length && portCategoryObject == null; i++ ) {
  -			if( categories[i].getData().equals(portCategory)) 
  -				portCategoryObject = categories[i];
  -		}
  -		
  -		ArrayList list = new ArrayList();
  -		
  -		if( portCategoryObject != null ) {
  -			SimpleTreeItem[] xpaths = portCategoryObject.getChildren2();
  -			for( int i = 0; i < xpaths.length; i++ ) {
  -				XPathPreferenceTreeItem xpItem = (XPathPreferenceTreeItem)xpaths[i];
  -				String name = xpItem.getName();
  -				SimpleTreeItem[] xpItemChildren = xpItem.getChildren2();
  -				for( int j = 0; j < xpItemChildren.length; j++ ) {
  -					SimpleTreeItem[] leafs = xpItemChildren[j].getChildren2();
  -					for( int k = 0; k < leafs.length; k++ ) {
  -						Object o = leafs[k];
  -						if( o instanceof XPathTreeItem2 ) {
  -							try {
  -								String port = ((XPathTreeItem2)o).getText();
  -								int port2 = Integer.parseInt(port);
  -								list.add(name + ":" + port2);
  -							} catch( Exception e ) {}
  -						}
  -					}
  -				}
  -			}
  -		}
   		
  -		server.setAttribute(PORT_NUMBERS_LIST, list);
  -		save();
  -	}
  -	
  -	public ServerPort[] getServerPorts() {
  -		ArrayList serverPorts = new ArrayList();
  -		List portList = server.getAttribute(PORT_NUMBERS_LIST, new ArrayList());
  -		Iterator i = portList.iterator();
  -		while(i.hasNext()) {
  -			String s = (String)i.next();
  -			int loc = s.lastIndexOf(':');
  -			String name = s.substring(0, loc);
  -			String port = s.substring(loc+1);
  -			int port2 = Integer.parseInt(port);
  -			serverPorts.add(new ServerPort(s, name, port2, null));
  -		}
   		
  -		ServerPort[] sps = (ServerPort[]) serverPorts.toArray(new ServerPort[portList.size()]);
  -		return sps;
  +	public boolean isDirty() {
  +		return wch.isDirty();
   	}
   	
  -	public SimpleXPathPreferenceTreeItem getXPathPreferenceTree() {
  -		List categories = server.getAttribute(XPATH_CATEGORIES, (List)null);
  -		if( categories == null ) {
  -			return getDefaultXPathPreferenceTree();
  -		}
  -		SimpleXPathPreferenceTreeItem model = new SimpleXPathPreferenceTreeItem(null, XPATH_CATEGORIES);
  -		Iterator i = categories.iterator();
  -		while(i.hasNext()) {
  -			String categoryName = (String)i.next();
  -			SimpleXPathPreferenceTreeItem categoryItem = new SimpleXPathPreferenceTreeItem(model, categoryName);
  -			String categoryListKey = XPATH_CATEGORY2_PREFIX + categoryName;
  -			List categoryElementsAsList = server.getAttribute(categoryListKey, new ArrayList());
  -			Iterator j = categoryElementsAsList.iterator();
  -			while(j.hasNext()) {
  -				String xpathName = (String)j.next();
  -				String finalKey = XPATH_PROPERTY_PREFIX + categoryName + xpathName;
  -				List xpathItem = server.getAttribute(finalKey, new ArrayList());
  -				if( xpathItem.size() == 2 ) {
  -					XPathPreferenceTreeItem xpi = new XPathPreferenceTreeItem(categoryItem, 
  -							(String)xpathItem.get(0), (String)xpathItem.get(1));
  -				} else if( xpathItem.size() == 3 ) {
  -					XPathPreferenceTreeItem xpi = new XPathPreferenceTreeItem(categoryItem, 
  -							(String)xpathItem.get(0), (String)xpathItem.get(1), (String)xpathItem.get(2));
  -				}
  -			}
  +	public IServer save(boolean force, IProgressMonitor monitor) throws CoreException {
  +		return wch.save(force, monitor);
   		}
   
  -		return model;
  -	}
  -	
  -	private SimpleXPathPreferenceTreeItem getDefaultXPathPreferenceTree() {
  -		SimpleXPathPreferenceTreeItem model = new SimpleXPathPreferenceTreeItem(null, XPATH_CATEGORIES);
  -		
  -		SimpleXPathPreferenceTreeItem ports = new SimpleXPathPreferenceTreeItem(model, PORTS_DEFAULT_CATEGORY);
  -		
  -		
   		
  -		XPathPreferenceTreeItem jndi = new XPathPreferenceTreeItem(ports, 
  -				"JNDI", "/server/mbean[@name='jboss:service=Naming']/attribute[@name='Port']");
  -		XPathPreferenceTreeItem jndiRMI = new XPathPreferenceTreeItem(ports, 
  -				"JNDI RMI", "/server/mbean[@name='jboss:service=Naming']/attribute[@name='RmiPort']");
  -		
  -		XPathPreferenceTreeItem haJndiStub = new XPathPreferenceTreeItem(ports, 
  -				"HA JNDI Stub", "//server/mbean[@name='jboss:service=HAJNDI']/attribute[@name='Port']");
  -
  -		XPathPreferenceTreeItem haJndiRMI = new XPathPreferenceTreeItem(ports, 
  -				"HA JNDI RMI", "//server/mbean[@name='jboss:service=HAJNDI']/attribute[@name='RmiPort']");
  -
  -		XPathPreferenceTreeItem jrmpa = new XPathPreferenceTreeItem(ports, 
  -				"JRMPA RMI Object", "//server/mbean[@name='jboss:service=invoker,type=jrmpha']/attribute[@name='RMIObjectPort']");
  -
  -		XPathPreferenceTreeItem clusterUDPMcast = new XPathPreferenceTreeItem(ports, 
  -				"Cluster UDP MCast", "//server/mbean[@name='jboss:service=${jboss.partition.name:DefaultPartition}']/attribute[@name='PartitionConfig']/Config/UDP", "mcast_port");
  -		
  -		XPathPreferenceTreeItem webservices = new XPathPreferenceTreeItem(ports, 
  -				"Web Services", "//server/mbean[@name='jboss:service=WebService']/attribute[@name='Port']");
  -		
  -//		XPathPreferenceTreeItem hypersonic = new XPathPreferenceTreeItem(ports, 
  -//				"HyperSonic", "//server/mbean[@name='jboss:service=Hypersonic']/attribute[@name='Port']");
  -		
  -		XPathPreferenceTreeItem jrmpInvoker = new XPathPreferenceTreeItem(ports, 
  -				"JRMP Invoker", "//server/mbean[@name='jboss:service=invoker,type=jrmp']/attribute[@name='RMIObjectPort']");
  -		
  -		XPathPreferenceTreeItem pooledInvoker = new XPathPreferenceTreeItem(ports, 
  -				"Pooled Invoker", "//server/mbean[@name='jboss:service=invoker,type=pooled']/attribute[@name='ServerBindPort']");
  -		
  -		
  -
  -		
  -		return model;
  -	}
  -	
  -	public void saveXPathPreferenceTree(SimpleTreeItem tree) {
  -		
  -		SimpleTreeItem[] children = tree.getChildren2();
  -		SimpleTreeItem[] grandChildren;
  -		ArrayList categoryList = new ArrayList();
  -		ArrayList xpathNameList, itemAsList;
  -		XPathPreferenceTreeItem xpathPrefItem;
  -		HashMap map = new HashMap();
  -		for( int i = 0; i < children.length; i++ ) {
  -			xpathNameList = new ArrayList();
  -			String categoryName = (String)children[i].getData();
  -			categoryList.add(categoryName);  // add "Ports"
  -			
  -			grandChildren = children[i].getChildren2(); // list of xpaths under "Ports"
  -			for( int j = 0; j < grandChildren.length; j++ ) {
  -				xpathPrefItem = ((XPathPreferenceTreeItem)grandChildren[j]);  // JNDI
  -				itemAsList = new ArrayList();
  -				itemAsList.add(xpathPrefItem.getName());
  -				itemAsList.add(xpathPrefItem.getXPath());
  -				itemAsList.add(xpathPrefItem.getAttributeName());
  -				xpathNameList.add(xpathPrefItem.getName());
  -				map.put(XPATH_PROPERTY_PREFIX + categoryName + xpathPrefItem.getName(), itemAsList);
  -			}
  -			map.put(XPATH_CATEGORY2_PREFIX + categoryName, xpathNameList);
  -		}
  -		map.put(XPATH_CATEGORIES, categoryList);
  -		
  -		Iterator i = map.keySet().iterator();
  -		while( i.hasNext()) {
  -			String key = (String)i.next();
  -			server.setAttribute(key, (List)map.get(key));
  -		}
  -
  -	}
  -	
  -	/* Just a label class */
  -	public static class SimpleXPathPreferenceTreeItem extends SimpleTreeItem {
  -		public SimpleXPathPreferenceTreeItem(SimpleTreeItem parent, Object data) {
  -			super(parent, data);
  -		}
  -	}
  -	public static class XPathPreferenceTreeItem extends SimpleXPathPreferenceTreeItem {
  -		private String name;
  -		private String elementXPath;
  -		private String attributeName = null;
  -		
  -		public XPathPreferenceTreeItem(SimpleTreeItem parent, String key, String value) {
  -			super(parent, null);
  -			this.name = key;
  -			this.elementXPath = value;
  -		}
  -		
  -		public XPathPreferenceTreeItem(SimpleTreeItem parent, String key, 
  -										String value, String attributeName ) {
  -			this(parent, key, value);
  -			this.attributeName = attributeName;
  -		}
  -		public String getName() {
  -			return name;
  -		}
  -		public String getXPath() {
  -			return elementXPath;
  -		}
  -		public void setXPath(String value) {
  -			this.elementXPath = value;
  -		}
  -		public void setName(String name) {
  -			this.name = name;
  -		}
  -		public String getAttributeName() {
  -			return attributeName;
  -		}
  -		public void setAttributeName(String attName) {
  -			this.attributeName = attName;
  -		}
  -		
  -		// actually a forced refresh
  -		public void ensureLoaded(JBossServer jbServer) {
  -			String XPATH_PROPERTY_LOADED = "_XPATH_PROPERTY_LOADED_";
  -
  -			String xpath = getXPath();
  -			String attribute = getAttributeName();
  -			XPathTreeItem[] items = new XPathTreeItem[0];
  -			if( attribute == null || attribute.equals("")) {
  -				items = jbServer.getDescriptorModel().getXPath(xpath);
  -			} else {
  -				items = jbServer.getDescriptorModel().getXPath(xpath, attribute);
  -			}
  -			
  -			if( getProperty(XPATH_PROPERTY_LOADED) != null ) {
  -				//deleteChildren();
  -				return;
  -			}
  -			for( int i = 0; i < items.length; i++ ) {
  -				addChild(items[i]);
  -			}
  -			setProperty(XPATH_PROPERTY_LOADED, new Boolean(true));
  -		}
  -		
  -	}
   	
   }
  
  
  
  1.1      date: 2006/11/10 00:26:25;  author: rawb;  state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/JBossServerLaunchConfiguration.java
  
  Index: JBossServerLaunchConfiguration.java
  ===================================================================
  /**
   * JBoss, a Division of Red Hat
   * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
  * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY 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 along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  package org.jboss.ide.eclipse.as.core.server;
  
  import java.io.File;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.IProgressMonitor;
  import org.eclipse.core.runtime.IStatus;
  import org.eclipse.core.runtime.NullProgressMonitor;
  import org.eclipse.core.runtime.Status;
  import org.eclipse.debug.core.DebugPlugin;
  import org.eclipse.debug.core.ILaunch;
  import org.eclipse.debug.core.ILaunchConfiguration;
  import org.eclipse.debug.core.ILaunchConfigurationType;
  import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
  import org.eclipse.debug.core.ILaunchManager;
  import org.eclipse.debug.core.model.IProcess;
  import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate;
  import org.eclipse.jdt.launching.ExecutionArguments;
  import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
  import org.eclipse.jdt.launching.IVMInstall;
  import org.eclipse.jdt.launching.IVMRunner;
  import org.eclipse.jdt.launching.VMRunnerConfiguration;
  import org.eclipse.wst.server.core.IServer;
  import org.eclipse.wst.server.core.ServerUtil;
  import org.eclipse.wst.server.core.internal.ServerType;
  import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
  import org.jboss.ide.eclipse.as.core.model.ServerProcessModel;
  import org.jboss.ide.eclipse.as.core.model.ServerProcessModel.ServerProcessModelEntity;
  
  public class JBossServerLaunchConfiguration extends AbstractJavaLaunchConfigurationDelegate {
  
  	public static final String START = "_START_";
  	public static final String STOP = "_STOP_";
  	public static final String TWIDDLE = "_TWIDDLE_";
  	
  	public static final String CURRENT_ACTION = "org.jboss.ide.eclipse.as.core.server.currentAction";
  	public static final String DEFAULT_SETTINGS = "org.jboss.ide.eclipse.as.core.server.defaultsSet";
  	
  	
  	protected static final char[] INVALID_CHARS = new char[] {'\\', '/', ':', '*', '?', '"', '<', '>', '|', '\0', '@', '&'};
  	public static final String PRGM_ARGS_START_SUFFIX = "org.jboss.ide.eclipse.as.core.server.start_suffix"; 
  	public static final String PRGM_ARGS_STOP_SUFFIX = "org.jboss.ide.eclipse.as.core.server.stop_suffix";
  	public static final String PRGM_ARGS_TWIDDLE_SUFFIX = "org.jboss.ide.eclipse.as.core.server.twiddle_suffix"; 
  	
  	
  	
  	public static JBossServerBehavior getServerBehavior(ILaunchConfiguration configuration) throws CoreException {
  		IServer server = ServerUtil.getServer(configuration);
  		JBossServerBehavior jbossServerBehavior = (JBossServerBehavior) server.getAdapter(JBossServerBehavior.class);
  		return jbossServerBehavior;
  
  	}
  	
  	public static JBossServer getJBossServer(ILaunchConfiguration configuration) throws CoreException {
  		// Get access to some important structures
  		return getJBossServer(ServerUtil.getServer(configuration));
  	}
  
  	public static JBossServer getJBossServer(IServer server) {
  		if( server == null ) return null;
  		JBossServer jbServer = (JBossServer)server.getAdapter(JBossServer.class);
  		if (jbServer == null) {
  			jbServer = (JBossServer) server.loadAdapter(JBossServer.class, new NullProgressMonitor());
  		}
  		return jbServer;
  	}
  	
  	
  	public static ILaunchConfigurationWorkingCopy setupLaunchConfiguration(IServer server, String action) throws CoreException {
  		ILaunchConfigurationWorkingCopy config = createLaunchConfiguration(server);
  		setupLaunchConfiguration(config, server, action);
  		return config;
  	}
  
  	public static void ensureDefaultsSet(ILaunchConfigurationWorkingCopy workingCopy, IServer server ) {
  		if( !defaultsBeenSet(workingCopy, server) ) {
  			try { 
  				getJBossServer(server).getLaunchDefaults().fillDefaults(workingCopy);
  				workingCopy.setAttribute(DEFAULT_SETTINGS, true);
  			} catch( CoreException ce ) {}
  		}
  	}
  	
  	public static void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, 
  						IServer server, String action) throws CoreException {
  
  		ensureDefaultsSet(workingCopy, server);
  
  		// Now that defaults have all been set, set it up for the action (start, stop, twiddle etc)
  		String argsKey = IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS;
  		String vmArgsKey = IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS;
  		workingCopy.setAttribute(CURRENT_ACTION, action);	
  
  		String suffix;
  		if( START.equals(action)) {
  			suffix = PRGM_ARGS_START_SUFFIX;
  		} else if( STOP.equals(action)) {
  			suffix = PRGM_ARGS_STOP_SUFFIX;
  		} else if( TWIDDLE.equals(action)) {
  			suffix = PRGM_ARGS_TWIDDLE_SUFFIX;
  		} else {
  			throw new CoreException(null);
  		}
  		
  		try {
  			String pgArgs = workingCopy.getAttribute(argsKey + suffix, (String)null); 
  			workingCopy.setAttribute(argsKey,pgArgs);
  			
  
  			String vmArgs = workingCopy.getAttribute(vmArgsKey + suffix, (String)null);
  			workingCopy.setAttribute(vmArgsKey, vmArgs);
  			
  			String main = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME + suffix, (String)null);
  			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, main);
  
  			String workingDir = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY + suffix, (String)null);
  			workingCopy.setAttribute(
  	                IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, workingDir);
  
  			
  			List classpath = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH + suffix, new ArrayList());
  			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath);
  
  		} catch( Exception e ) {
  			e.printStackTrace();
  		}
  
  	}
  		
  
  	// Have the defaults been set for this launch config yet? ever?
  	public static boolean defaultsBeenSet(ILaunchConfiguration workingCopy, IServer server) {
  		try {
  			return workingCopy.getAttribute(DEFAULT_SETTINGS, false);
  		} catch( CoreException ce ) {
  		}
  		return false;
  	}
  	
  	
  	/**
  	 * Will create a launch configuration for the server 
  	 * if one does not already exist.
  	 */
  	public static ILaunchConfigurationWorkingCopy createLaunchConfiguration(IServer server) throws CoreException {
  		ILaunchConfigurationType launchConfigType = 
  			((ServerType) server.getServerType()).getLaunchConfigurationType();
  		if (launchConfigType == null)
  			return null;
  		
  		ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
  		ILaunchConfiguration[] launchConfigs = null;
  		try {
  			launchConfigs = launchManager.getLaunchConfigurations(launchConfigType);
  		} catch (CoreException e) {
  			// ignore
  		}
  		
  		if (launchConfigs != null) {
  			int size = launchConfigs.length;
  			for (int i = 0; i < size; i++) {
  				try {
  					String serverId = launchConfigs[i].getAttribute("server-id", (String) null);
  					if (server.getId().equals(serverId)) {
  						ILaunchConfigurationWorkingCopy wc = launchConfigs[i].getWorkingCopy();
  						return wc;
  					}
  				} catch (CoreException e) {
  				}
  			}
  		}
  		
  		// create a new launch configuration
  		String launchName = getValidLaunchConfigurationName(server.getName());
  		launchName = launchManager.generateUniqueLaunchConfigurationNameFrom(launchName); 
  		ILaunchConfigurationWorkingCopy wc = launchConfigType.newInstance(null, launchName);
  		wc.setAttribute("server-id", server.getId());
  		return wc;
  	}
  
  	protected static String getValidLaunchConfigurationName(String s) {
  		if (s == null || s.length() == 0)
  			return "1";
  		int size = INVALID_CHARS.length;
  		for (int i = 0; i < size; i++) {
  			s = s.replace(INVALID_CHARS[i], '_');
  		}
  		return s;
  	}
  	
  
  	public void launch(ILaunchConfiguration configuration, String mode,
  			ILaunch launch, IProgressMonitor monitor) throws CoreException {
  
  		try {
  			String action = configuration.getAttribute(CURRENT_ACTION, START);	
  	
  			IProcess[] processes = new IProcess[0];
  			JBossServerBehavior jbossServerBehavior = getServerBehavior(configuration);
  			String serverID = jbossServerBehavior.getServer().getId();
  			ServerProcessModelEntity processModel = ServerProcessModel.getDefault().getModel(serverID);
  			if( action.equals(START)) {
  				processes = launchConfiguration(configuration, launch, monitor, mode);
  				processModel.add(processes, action, configuration);
  				jbossServerBehavior.serverStarting();
  			} else if( action.equals(STOP)) {
  				processes = launchConfiguration(configuration, launch, monitor, mode);
  				processModel.add(processes, action, configuration);
  				jbossServerBehavior.serverStopping();
  			} else if( action.equals(TWIDDLE)) {
  				processes = launchConfiguration(configuration, launch, monitor, mode);
  				processModel.add(processes, action, configuration);
  			}
  		} catch( Exception e ) {
  			throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IStatus.ERROR, "Error launching twiddle", e));
  		}
  	}
  	
  	public IProcess[] launchConfiguration(ILaunchConfiguration configuration, ILaunch launch,
  			IProgressMonitor monitor, String mode) throws CoreException {
  
  		// And off we go!
  		IVMInstall vm = verifyVMInstall(configuration);
  		IVMRunner runner = vm.getVMRunner(mode);
  		
  		File workingDir = verifyWorkingDirectory(configuration);
  		String workingDirName = null;
  		if (workingDir != null)
  			workingDirName = workingDir.getAbsolutePath();
  		
  		// Program & VM args
  		String pgmArgs = getProgramArguments(configuration);
  		String vmArgs = getVMArguments(configuration);
  		
  		
  		ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs);
  		
  		// VM-specific attributes
  		Map vmAttributesMap = getVMSpecificAttributesMap(configuration);
  		
  		// Classpath
  		String[] classpath = getClasspath(configuration);
  		
  		// Create VM config
  		String mainType = getMainTypeName(configuration);
  		VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainType, classpath);
  		runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
  		runConfig.setVMArguments(execArgs.getVMArgumentsArray());
  		runConfig.setWorkingDirectory(workingDirName);
  		runConfig.setVMSpecificAttributesMap(vmAttributesMap);
  
  		// Bootpath
  		String[] bootpath = getBootpath(configuration);
  		if (bootpath != null && bootpath.length > 0)
  			runConfig.setBootClassPath(bootpath);
  		
  		setDefaultSourceLocator(launch, configuration);
  		
  		// Launch the configuration
  		runner.run(runConfig, launch, monitor);
  		
  		return launch.getProcesses();
  	}
  
  }
  
  
  
  1.1      date: 2006/11/10 00:26:25;  author: rawb;  state: Exp;jbosside/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/TwiddleLauncher.java
  
  Index: TwiddleLauncher.java
  ===================================================================
  /**
   * JBoss, a Division of Red Hat
   * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY 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 along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  package org.jboss.ide.eclipse.as.core.server;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.NullProgressMonitor;
  import org.eclipse.debug.core.ILaunch;
  import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
  import org.eclipse.debug.core.ILaunchManager;
  import org.eclipse.debug.core.IStreamListener;
  import org.eclipse.debug.core.model.IProcess;
  import org.eclipse.debug.core.model.IStreamMonitor;
  import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
  import org.eclipse.wst.server.core.IServer;
  import org.jboss.ide.eclipse.as.core.model.ServerProcessModel.ServerProcessModelEntity;
  
  public class TwiddleLauncher {
  	
  	/**
  	 * Create one launch for each String of arguments.
  	 * Each element in the array is a COMPLETE LIST of arguments. 
  	 * For example: 
  	 *     twiddleArgs[0] = "-s localhost:1099 -a jmx/rmi/RMIAdaptor get \"whatever\""
  	 *     twiddleArgs[1] = "-s localhost:1099 -a jmx/rmi/RMIAdaptor get \"whatever2\""
  	 *     
  	 * @param twiddleArgs 
  	 * @param jbServer
  	 * @param seed
  	 * @return
  	 */
  	public static ProcessData[] launchTwiddles(String[] twiddleArgs, IServer server, boolean addPrefix) throws CoreException {
  		ILaunchConfigurationWorkingCopy wc;
  		ArrayList list = new ArrayList();
  		for( int i = 0; i < twiddleArgs.length; i++ ) {
  			wc = createTwiddleLaunch(server, twiddleArgs[i], addPrefix);
  			ILaunch launch = wc.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor(), false, false);
  			list.addAll(Arrays.asList(toProcessDatas(launch.getProcesses())));
  		}
  		
  		ProcessData[] ret = new ProcessData[list.size()];
  		list.toArray(ret);
  		
  		return ret;
  	}
  	
  	protected static ProcessData[] toProcessDatas(IProcess[] processes) {
  		ProcessData[] datas = new ProcessData[processes.length];
  		for( int i = 0; i < processes.length; i++ ) {
  			datas[i] = new ProcessData(processes[i], "");
  			datas[i].startListening();
  		}
  		return datas;
  	}
  	
  	public static ILaunchConfigurationWorkingCopy createTwiddleLaunch(IServer server, 
  			String args, boolean addPrefix) throws CoreException {
  		
  		ILaunchConfigurationWorkingCopy workingCopy =
  			JBossServerLaunchConfiguration.setupLaunchConfiguration(server, JBossServerLaunchConfiguration.TWIDDLE);
  		
  		// If we have to use the prefix from the launch config, throw it in front. 
  		if( addPrefix ) {
  			String a2 = workingCopy.getAttribute(
  					IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS 
  					+ JBossServerLaunchConfiguration.PRGM_ARGS_TWIDDLE_SUFFIX, "");
  			args = a2 + " " + args;
  		}
  		
  		workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, args);
  		return workingCopy;
  	}
  
  	private boolean canceled = false;
  	private int delay = 500;
  	
  	public void setCanceled() {
  		canceled = true;
  	}
  	
  	public ProcessData[] getTwiddleResults(IServer server, String args, boolean addPrefix ) {
  		ProcessData[] processes;
  		try {
  			processes = TwiddleLauncher.launchTwiddles(new String[] { args }, server, addPrefix);
  		} catch( CoreException ce ) {
  			return new ProcessData[0];
  		}
  		waitForThreadsToTerminate(processes);
  		
  		// stop listening 
  		for( int i = 0; i < processes.length; i++ ) {
  			processes[i].stopListening();
  			if( canceled ) {
  				try {
  					// if canceled, terminate all twiddle processes
  					processes[i].getProcess().terminate();
  				} catch( Exception e ) {}
  			}	
  		}	
  		
  		return processes;
  	}
  		
  	protected void waitForThreadsToTerminate(ProcessData[] processes) {
  		boolean allTerminated = false;
  		while( !allTerminated && !canceled) {
  			allTerminated = true;
  			for( int i = 0; i < processes.length; i++ ) {
  				if( processes[i].getProcess().isTerminated() == false ) {
  					allTerminated = false;
  				}
  			}
  			if( !allTerminated ) {
  				// sleep
  				try {
  					Thread.sleep(delay);
  				} catch( InterruptedException ie ) {
  				}
  			}
  		}
  	}
  	
  	public static class ProcessData implements IStreamListener {
  		private String args;
  		private String processType;
  
  		private IProcess process;
  		private IStreamMonitor outMonitor;
  		private IStreamMonitor errMonitor;
  		
  		private String out, err;
  
  		public ProcessData(IProcess process, String processType) {
  			this(null, process, processType);
  			try {
  				this.args = process.getLaunch().getLaunchConfiguration().
  					getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
  			} catch( CoreException ce ) {
  			}
  
  		}
  		
  		public ProcessData(String args, IProcess process, String processType) {
  			this.args = args;
  			this.process = process;
  			this.processType = processType;
  			
  			//ASDebug.p("process is " + process, this);
  			//ASDebug.p("Stream Proxy is " + process.getStreamsProxy(), this);
  			this.outMonitor = process.getStreamsProxy().getOutputStreamMonitor();
  			this.errMonitor = process.getStreamsProxy().getErrorStreamMonitor();
  			
  			out = "";
  			err = "";
  		}
  		
  		public void startListening() {
  			outMonitor.addListener(this);
  			errMonitor.addListener(this);
  		}
  		
  		public void stopListening() {
  			outMonitor.removeListener(this);
  			errMonitor.removeListener(this);
  		}
  		
  		public void resetStrings() {
  			out = "";
  			err = "";
  		}
  		
  		public void destroy() {
  			stopListening();
  			resetStrings();
  		}
  
  		public void streamAppended(String text, IStreamMonitor monitor) {
  			if( monitor == outMonitor ) {
  				out += text;
  			} else if( monitor == errMonitor ) {
  				err += text;
  			}
  		}
  
  		public String getArgs() {
  			return args;
  		}
  
  		public String getErr() {
  			return err;
  		}
  
  		public String getOut() {
  			return out;
  		}
  		
  		public String getProcesType() {
  			return processType;
  		}
  		
  		public IProcess getProcess() {
  			return process;
  		}
  
  	}
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list