geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sppa...@apache.org
Subject svn commit: r382997 [2/7] - in /geronimo/devtools/eclipse-plugin/trunk: ./ assembly/ etc/ features/org.apache.geronimo.feature.source/ features/org.apache.geronimo.feature/ features/org.apache.geronimo.installableruntime.tomcat.feature/ geronimo-emf/ m...
Date Sat, 04 Mar 2006 01:30:47 GMT
Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerBehaviour.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerBehaviour.java?rev=382997&r1=382996&r2=382997&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerBehaviour.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerBehaviour.java Fri Mar  3 17:30:38 2006
@@ -1,493 +1,493 @@
-/**
- * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package org.apache.geronimo.core.internal;
-
-import java.net.MalformedURLException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.Timer;
-
-import javax.enterprise.deploy.spi.DeploymentManager;
-import javax.enterprise.deploy.spi.TargetModuleID;
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
-import org.apache.geronimo.core.DeploymentUtils;
-import org.apache.geronimo.core.GeronimoConnectionFactory;
-import org.apache.geronimo.core.commands.DeploymentCommandFactory;
-import org.apache.geronimo.core.commands.IDeploymentCommand;
-import org.apache.geronimo.core.commands.TargetModuleIdNotFoundException;
-import org.apache.geronimo.gbean.GBeanQuery;
-import org.apache.geronimo.kernel.GBeanNotFoundException;
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.NoSuchAttributeException;
-import org.apache.geronimo.kernel.config.PersistentConfigurationList;
-import org.apache.geronimo.kernel.jmx.KernelDelegate;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
-import org.eclipse.jst.server.generic.core.internal.CorePlugin;
-import org.eclipse.jst.server.generic.core.internal.GenericServerBehaviour;
-import org.eclipse.jst.server.generic.core.internal.GenericServerCoreMessages;
-import org.eclipse.wst.server.core.IModule;
-import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.IServerListener;
-import org.eclipse.wst.server.core.ServerEvent;
-import org.eclipse.wst.server.core.ServerPort;
-import org.eclipse.wst.server.core.util.SocketUtil;
-
-public class GeronimoServerBehaviour extends GenericServerBehaviour {
-
-	private static final String ATTR_STOP = "stop-server";
-
-	private static final int MAX_TRIES = 30;
-
-	private static final int TIMER_TASK_INTERVAL = 10;
-
-	private IProgressMonitor _monitor = null;
-
-	private Kernel kernel = null;
-
-	private Timer timer = null;
-	PingThread pingThread;
-
-	public GeronimoServerBehaviour() {
-		super();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#stop(boolean)
-	 */
-	public synchronized void stop(boolean force) {
-
-		Trace.trace(Trace.INFO, "--> stop()");
-
-		if (getServer().getServerState() != IServer.STATE_STOPPED) {
-			setServerState(IServer.STATE_STOPPING);
-			if (kernel != null) {
-				kernel.shutdown();
-			}
-		}
-
-		GeronimoConnectionFactory.getInstance().destroy(getServer());
-		kernel = null;
-
-		// kill the process
-		super.stop(true);
-
-		Trace.trace(Trace.INFO, "<-- stop()");
-	}
-
-	private String getJMXServiceURL() {
-
-		String host = getServer().getHost();
-		String rmiPort = getRMINamingPort();
-
-		if (host != null && rmiPort != null) {
-			return "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":"
-					+ rmiPort + "/JMXConnector";
-		}
-
-		return null;
-
-	}
-
-	private Kernel getKernel() throws SecurityException {
-
-		if (kernel == null) {
-			Map map = new HashMap();
-			map.put("jmx.remote.credentials", new String[] { getUserName(),
-					getPassword() });
-			try {
-				String url = getJMXServiceURL();
-				Trace.trace(Trace.INFO, "URL = " + url);
-				if (url == null)
-					return null;
-				JMXServiceURL address = new JMXServiceURL(url);
-				try {
-					JMXConnector jmxConnector = JMXConnectorFactory.connect(
-							address, map);
-					MBeanServerConnection mbServerConnection = jmxConnector
-							.getMBeanServerConnection();
-					kernel = new KernelDelegate(mbServerConnection);
-					Trace.trace(Trace.INFO, "Connected to kernel.");
-				} catch (SecurityException e) {
-					throw e;
-				} catch (Exception e) {
-					Trace.trace(Trace.WARNING, "Kernel connection failed.");
-				}
-			} catch (MalformedURLException e) {
-				e.printStackTrace();
-			}
-		}
-
-		return kernel;
-	}
-
-	protected void setServerStarted() {
-		super.setServerStarted();
-	}
-
-	protected boolean isKernelAlive() {
-		try {
-			return getKernel() != null && kernel.isRunning();
-		} catch (SecurityException e) {
-			GeronimoPlugin.log(Status.ERROR,
-					"Invalid username and/or password.", e);
-			pingThread.interrupt();
-			if (getServer().getServerState() != IServer.STATE_STOPPED) {
-				stop(true);
-			}
-		} catch (Exception e) {
-			GeronimoPlugin
-					.log(
-							Status.WARNING,
-							"Geronimo Server may have been terminated manually outside of workspace.",
-							e);
-			kernel = null;
-		}
-		return false;
-	}
-
-	protected boolean isKernelFullyStarted() {
-		if (isKernelAlive()) {
-			Set configLists = kernel.listGBeans(new GBeanQuery(null,
-					PersistentConfigurationList.class.getName()));
-			if (!configLists.isEmpty()) {
-				ObjectName on = (ObjectName) configLists.toArray()[0];
-				try {
-					Boolean b = (Boolean) kernel.getAttribute(on,
-							"kernelFullyStarted");
-					return b.booleanValue();
-				} catch (GBeanNotFoundException e) {
-					// ignore
-				} catch (NoSuchAttributeException e) {
-					// ignore
-				} catch (Exception e) {
-					e.printStackTrace();
-				}
-			} else {
-				Trace.trace(Trace.INFO, "configLists is empty");
-			}
-		}
-		return false;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#publishModule(int,
-	 *      int, org.eclipse.wst.server.core.IModule[],
-	 *      org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	public void publishModule(int kind, int deltaKind, IModule[] module,
-			IProgressMonitor monitor) throws CoreException {
-		Trace.trace(Trace.INFO, ">> publishModule(), deltaKind = " + deltaKind);
-		Trace.trace(Trace.INFO, Arrays.asList(module).toString());
-		_monitor = monitor;
-
-		if (module.length == 1 && (deltaKind == ADDED || deltaKind == REMOVED)) {
-			invokeCommand(deltaKind, module[0]);
-		} else if (deltaKind == CHANGED) {
-			// TODO This case is flawed due to WTP Bugzilla 123676
-			invokeCommand(deltaKind, module[0]);
-		}
-
-		setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
-
-		Trace.trace(Trace.INFO, "<< publishModule()");
-	}
-
-	private void invokeCommand(int deltaKind, IModule module)
-			throws CoreException {
-		try {
-			switch (deltaKind) {
-			case ADDED: {
-				doDeploy(module);
-				break;
-			}
-			case CHANGED: {
-				doRedeploy(module);
-				break;
-			}
-			case REMOVED: {
-				doUndeploy(module);
-				break;
-			}
-			default:
-				throw new IllegalArgumentException();
-			}
-		} catch (CoreException e) {
-			throw e;
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-	}
-
-	private void doDeploy(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doDeploy() " + module.toString());
-
-		DeploymentManager dm = DeploymentCommandFactory
-				.getDeploymentManager(getServer());
-
-		if (!DeploymentUtils.configurationExists(module, dm)) {
-			IStatus status = distribute(module);
-			if (!status.isOK()) {
-				doFail(status, Messages.DISTRIBUTE_FAIL);
-			}
-
-			status = start(module);
-			if (!status.isOK()) {
-				doFail(status, Messages.START_FAIL);
-			}
-		} else {
-			String id = GeronimoUtils.getConfigId(module);
-			String message = id
-					+ "already exists.  Existing configuration will be overwritten.";
-			GeronimoPlugin.log(Status.ERROR, message, null);
-			doRedeploy(module);
-		}
-
-		Trace.trace(Trace.INFO, "<< doDeploy() " + module.toString());
-	}
-
-	private void doRedeploy(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doRedeploy() " + module.toString());
-
-		try {
-			IStatus status = reDeploy(module);
-			if (!status.isOK()) {
-				doFail(status, Messages.REDEPLOY_FAIL);
-			}
-		} catch (TargetModuleIdNotFoundException e) {
-			GeronimoPlugin.log(Status.WARNING,
-					"Module may have been uninstalled outside the workspace.",
-					e);
-			doDeploy(module);
-		}
-
-		Trace.trace(Trace.INFO, "<< doRedeploy() " + module.toString());
-	}
-
-	private void doUndeploy(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doUndeploy() " + module.toString());
-
-		IStatus status = stop(module);
-		if (!status.isOK()) {
-			doFail(status, Messages.STOP_FAIL);
-		}
-
-		status = unDeploy(module);
-		if (!status.isOK()) {
-			doFail(status, Messages.UNDEPLOY_FAIL);
-		}
-
-		Trace.trace(Trace.INFO, "<< doUndeploy()" + module.toString());
-	}
-
-	private void doRestart(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doRestart() " + module.toString());
-
-		IStatus status = stop(module);
-		if (!status.isOK()) {
-			doFail(status, Messages.STOP_FAIL);
-		}
-
-		status = start(module);
-		if (!status.isOK()) {
-			doFail(status, Messages.START_FAIL);
-		}
-
-		Trace.trace(Trace.INFO, ">> doRestart() " + module.toString());
-	}
-
-	private void doFail(IStatus status, String message) throws CoreException {
-		throw new CoreException(new Status(IStatus.ERROR,
-				GeronimoPlugin.PLUGIN_ID, 0, message, new Exception(status
-						.getMessage())));
-	}
-
-	private IStatus distribute(IModule module) throws Exception {
-		IDeploymentCommand cmd = DeploymentCommandFactory
-				.createDistributeCommand(module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	private IStatus start(IModule module) throws Exception {
-		TargetModuleID id = DeploymentUtils.getTargetModuleID(module,
-				DeploymentCommandFactory.getDeploymentManager(getServer()));
-		IDeploymentCommand cmd = DeploymentCommandFactory.createStartCommand(
-				new TargetModuleID[] { id }, module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	private IStatus stop(IModule module) throws Exception {
-		IDeploymentCommand cmd = DeploymentCommandFactory.createStopCommand(
-				module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	private IStatus unDeploy(IModule module) throws Exception {
-		IDeploymentCommand cmd = DeploymentCommandFactory
-				.createUndeployCommand(module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	private IStatus reDeploy(IModule module) throws Exception {
-		IDeploymentCommand cmd = DeploymentCommandFactory
-				.createRedeployCommand(module, getServer());
-		return cmd.execute(_monitor);
-	}
-
-	public Map getServerInstanceProperties() {
-		return getRuntimeDelegate().getServerInstanceProperties();
-	}
-
-	public String getUserName() {
-		return GeronimoConnectionFactory.getInstance().getUserName(getServer());
-	}
-
-	public String getPassword() {
-		return GeronimoConnectionFactory.getInstance().getPassword(getServer());
-	}
-
-	public String getRMINamingPort() {
-		return GeronimoConnectionFactory.getInstance().getRMINamingPort(
-				getServer());
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#setupLaunchConfiguration(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy,
-	 *      org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	public void setupLaunchConfiguration(
-			ILaunchConfigurationWorkingCopy workingCopy,
-			IProgressMonitor monitor) throws CoreException {
-		String defaultArgs = getServerDefinition().getResolver()
-				.resolveProperties(
-						getServerDefinition().getStart()
-								.getProgramArgumentsAsString());
-		String existingPrgArgs = workingCopy.getAttribute(
-				IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
-				defaultArgs);
-		super.setupLaunchConfiguration(workingCopy, monitor);
-		if (existingPrgArgs != null) {
-			workingCopy.setAttribute(
-					IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
-					existingPrgArgs);
-		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.jst.server.generic.core.internal.GenericServerBehaviour#setupLaunch(org.eclipse.debug.core.ILaunch,
-	 *      java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	protected void setupLaunch(ILaunch launch, String launchMode,
-			IProgressMonitor monitor) throws CoreException {
-		Trace.trace(Trace.INFO, "--> GeronimoServerBehavior.setupLaunch()");
-
-		if ("true".equals(launch.getLaunchConfiguration().getAttribute(
-				ATTR_STOP, "false")))
-			return;
-
-		if (!SocketUtil.isLocalhost(getServer().getHost()))
-			return;
-
-		ServerPort[] ports = getServer().getServerPorts(null);
-		for (int i = 0; i < ports.length; i++) {
-			ServerPort sp = ports[i];
-			if (SocketUtil.isPortInUse(ports[i].getPort(), 5))
-				throw new CoreException(new Status(IStatus.ERROR,
-						CorePlugin.PLUGIN_ID, 0, GenericServerCoreMessages
-								.bind(GenericServerCoreMessages.errorPortInUse,
-										Integer.toString(sp.getPort()), sp
-												.getName()), null));
-		}
-
-		stopUpdateServerStateTask();
-		setServerState(IServer.STATE_STARTING);
-		setMode(launchMode);
-
-		IServerListener listener = new IServerListener() {
-			public void serverChanged(ServerEvent event) {
-				int eventKind = event.getKind();
-				if (eventKind == (ServerEvent.SERVER_CHANGE | ServerEvent.STATE_CHANGE)) {
-					IServer server = event.getServer();
-					int state = server.getServerState();
-					if (state == IServer.STATE_STARTED
-							|| state == IServer.STATE_STOPPED) {
-						GeronimoServerBehaviour.this.getServer()
-								.removeServerListener(this);
-						startUpdateServerStateTask();
-					}
-				}
-			}
-		};
-
-		getServer().addServerListener(listener);
-		pingThread = new PingThread(this);
-		pingThread.start();
-		Trace.trace(Trace.INFO, "<-- GeronimoServerBehavior.setupLaunch()");
-	}
-
-	private void startUpdateServerStateTask() {
-		Trace.trace(Trace.INFO, "startUpdateServerStateTask() " + getServer().getName());
-		timer = new Timer(true);
-		timer.schedule(new UpdateServerStateTask(this), 10000,
-				TIMER_TASK_INTERVAL * 1000);
-	}
-
-	private void stopUpdateServerStateTask() {
-		Trace.trace(Trace.INFO, "stopUpdateServerStateTask() " + getServer().getName());
-		if (timer != null)
-			timer.cancel();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#initialize(org.eclipse.core.runtime.IProgressMonitor)
-	 */
-	protected void initialize(IProgressMonitor monitor) {
-		Trace.trace(Trace.INFO, "GeronimoServerBehavior.initialize()");
-		startUpdateServerStateTask();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#dispose()
-	 */
-	public void dispose() {
-		stopUpdateServerStateTask();
-	}
-
+/**
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.core.internal;
+
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Timer;
+
+import javax.enterprise.deploy.spi.DeploymentManager;
+import javax.enterprise.deploy.spi.TargetModuleID;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.apache.geronimo.core.DeploymentUtils;
+import org.apache.geronimo.core.GeronimoConnectionFactory;
+import org.apache.geronimo.core.commands.DeploymentCommandFactory;
+import org.apache.geronimo.core.commands.IDeploymentCommand;
+import org.apache.geronimo.core.commands.TargetModuleIdNotFoundException;
+import org.apache.geronimo.gbean.GBeanQuery;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.NoSuchAttributeException;
+import org.apache.geronimo.kernel.config.PersistentConfigurationList;
+import org.apache.geronimo.kernel.jmx.KernelDelegate;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jst.server.generic.core.internal.CorePlugin;
+import org.eclipse.jst.server.generic.core.internal.GenericServerBehaviour;
+import org.eclipse.jst.server.generic.core.internal.GenericServerCoreMessages;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerListener;
+import org.eclipse.wst.server.core.ServerEvent;
+import org.eclipse.wst.server.core.ServerPort;
+import org.eclipse.wst.server.core.util.SocketUtil;
+
+public class GeronimoServerBehaviour extends GenericServerBehaviour {
+
+	private static final String ATTR_STOP = "stop-server";
+
+	private static final int MAX_TRIES = 30;
+
+	private static final int TIMER_TASK_INTERVAL = 10;
+
+	private IProgressMonitor _monitor = null;
+
+	private Kernel kernel = null;
+
+	private Timer timer = null;
+	PingThread pingThread;
+
+	public GeronimoServerBehaviour() {
+		super();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#stop(boolean)
+	 */
+	public synchronized void stop(boolean force) {
+
+		Trace.trace(Trace.INFO, "--> stop()");
+
+		if (getServer().getServerState() != IServer.STATE_STOPPED) {
+			setServerState(IServer.STATE_STOPPING);
+			if (kernel != null) {
+				kernel.shutdown();
+			}
+		}
+
+		GeronimoConnectionFactory.getInstance().destroy(getServer());
+		kernel = null;
+
+		// kill the process
+		super.stop(true);
+
+		Trace.trace(Trace.INFO, "<-- stop()");
+	}
+
+	private String getJMXServiceURL() {
+
+		String host = getServer().getHost();
+		String rmiPort = getRMINamingPort();
+
+		if (host != null && rmiPort != null) {
+			return "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":"
+					+ rmiPort + "/JMXConnector";
+		}
+
+		return null;
+
+	}
+
+	private Kernel getKernel() throws SecurityException {
+
+		if (kernel == null) {
+			Map map = new HashMap();
+			map.put("jmx.remote.credentials", new String[] { getUserName(),
+					getPassword() });
+			try {
+				String url = getJMXServiceURL();
+				Trace.trace(Trace.INFO, "URL = " + url);
+				if (url == null)
+					return null;
+				JMXServiceURL address = new JMXServiceURL(url);
+				try {
+					JMXConnector jmxConnector = JMXConnectorFactory.connect(
+							address, map);
+					MBeanServerConnection mbServerConnection = jmxConnector
+							.getMBeanServerConnection();
+					kernel = new KernelDelegate(mbServerConnection);
+					Trace.trace(Trace.INFO, "Connected to kernel.");
+				} catch (SecurityException e) {
+					throw e;
+				} catch (Exception e) {
+					Trace.trace(Trace.WARNING, "Kernel connection failed.");
+				}
+			} catch (MalformedURLException e) {
+				e.printStackTrace();
+			}
+		}
+
+		return kernel;
+	}
+
+	protected void setServerStarted() {
+		super.setServerStarted();
+	}
+
+	protected boolean isKernelAlive() {
+		try {
+			return getKernel() != null && kernel.isRunning();
+		} catch (SecurityException e) {
+			GeronimoPlugin.log(Status.ERROR,
+					"Invalid username and/or password.", e);
+			pingThread.interrupt();
+			if (getServer().getServerState() != IServer.STATE_STOPPED) {
+				stop(true);
+			}
+		} catch (Exception e) {
+			GeronimoPlugin
+					.log(
+							Status.WARNING,
+							"Geronimo Server may have been terminated manually outside of workspace.",
+							e);
+			kernel = null;
+		}
+		return false;
+	}
+
+	protected boolean isKernelFullyStarted() {
+		if (isKernelAlive()) {
+			Set configLists = kernel.listGBeans(new GBeanQuery(null,
+					PersistentConfigurationList.class.getName()));
+			if (!configLists.isEmpty()) {
+				ObjectName on = (ObjectName) configLists.toArray()[0];
+				try {
+					Boolean b = (Boolean) kernel.getAttribute(on,
+							"kernelFullyStarted");
+					return b.booleanValue();
+				} catch (GBeanNotFoundException e) {
+					// ignore
+				} catch (NoSuchAttributeException e) {
+					// ignore
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			} else {
+				Trace.trace(Trace.INFO, "configLists is empty");
+			}
+		}
+		return false;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#publishModule(int,
+	 *      int, org.eclipse.wst.server.core.IModule[],
+	 *      org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	public void publishModule(int kind, int deltaKind, IModule[] module,
+			IProgressMonitor monitor) throws CoreException {
+		Trace.trace(Trace.INFO, ">> publishModule(), deltaKind = " + deltaKind);
+		Trace.trace(Trace.INFO, Arrays.asList(module).toString());
+		_monitor = monitor;
+
+		if (module.length == 1 && (deltaKind == ADDED || deltaKind == REMOVED)) {
+			invokeCommand(deltaKind, module[0]);
+		} else if (deltaKind == CHANGED) {
+			// TODO This case is flawed due to WTP Bugzilla 123676
+			invokeCommand(deltaKind, module[0]);
+		}
+
+		setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
+
+		Trace.trace(Trace.INFO, "<< publishModule()");
+	}
+
+	private void invokeCommand(int deltaKind, IModule module)
+			throws CoreException {
+		try {
+			switch (deltaKind) {
+			case ADDED: {
+				doDeploy(module);
+				break;
+			}
+			case CHANGED: {
+				doRedeploy(module);
+				break;
+			}
+			case REMOVED: {
+				doUndeploy(module);
+				break;
+			}
+			default:
+				throw new IllegalArgumentException();
+			}
+		} catch (CoreException e) {
+			throw e;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	private void doDeploy(IModule module) throws Exception {
+		Trace.trace(Trace.INFO, ">> doDeploy() " + module.toString());
+
+		DeploymentManager dm = DeploymentCommandFactory
+				.getDeploymentManager(getServer());
+
+		if (!DeploymentUtils.configurationExists(module, dm)) {
+			IStatus status = distribute(module);
+			if (!status.isOK()) {
+				doFail(status, Messages.DISTRIBUTE_FAIL);
+			}
+
+			status = start(module);
+			if (!status.isOK()) {
+				doFail(status, Messages.START_FAIL);
+			}
+		} else {
+			String id = GeronimoUtils.getConfigId(module);
+			String message = id
+					+ "already exists.  Existing configuration will be overwritten.";
+			GeronimoPlugin.log(Status.ERROR, message, null);
+			doRedeploy(module);
+		}
+
+		Trace.trace(Trace.INFO, "<< doDeploy() " + module.toString());
+	}
+
+	private void doRedeploy(IModule module) throws Exception {
+		Trace.trace(Trace.INFO, ">> doRedeploy() " + module.toString());
+
+		try {
+			IStatus status = reDeploy(module);
+			if (!status.isOK()) {
+				doFail(status, Messages.REDEPLOY_FAIL);
+			}
+		} catch (TargetModuleIdNotFoundException e) {
+			GeronimoPlugin.log(Status.WARNING,
+					"Module may have been uninstalled outside the workspace.",
+					e);
+			doDeploy(module);
+		}
+
+		Trace.trace(Trace.INFO, "<< doRedeploy() " + module.toString());
+	}
+
+	private void doUndeploy(IModule module) throws Exception {
+		Trace.trace(Trace.INFO, ">> doUndeploy() " + module.toString());
+
+		IStatus status = stop(module);
+		if (!status.isOK()) {
+			doFail(status, Messages.STOP_FAIL);
+		}
+
+		status = unDeploy(module);
+		if (!status.isOK()) {
+			doFail(status, Messages.UNDEPLOY_FAIL);
+		}
+
+		Trace.trace(Trace.INFO, "<< doUndeploy()" + module.toString());
+	}
+
+	private void doRestart(IModule module) throws Exception {
+		Trace.trace(Trace.INFO, ">> doRestart() " + module.toString());
+
+		IStatus status = stop(module);
+		if (!status.isOK()) {
+			doFail(status, Messages.STOP_FAIL);
+		}
+
+		status = start(module);
+		if (!status.isOK()) {
+			doFail(status, Messages.START_FAIL);
+		}
+
+		Trace.trace(Trace.INFO, ">> doRestart() " + module.toString());
+	}
+
+	private void doFail(IStatus status, String message) throws CoreException {
+		throw new CoreException(new Status(IStatus.ERROR,
+				GeronimoPlugin.PLUGIN_ID, 0, message, new Exception(status
+						.getMessage())));
+	}
+
+	private IStatus distribute(IModule module) throws Exception {
+		IDeploymentCommand cmd = DeploymentCommandFactory
+				.createDistributeCommand(module, getServer());
+		return cmd.execute(_monitor);
+	}
+
+	private IStatus start(IModule module) throws Exception {
+		TargetModuleID id = DeploymentUtils.getTargetModuleID(module,
+				DeploymentCommandFactory.getDeploymentManager(getServer()));
+		IDeploymentCommand cmd = DeploymentCommandFactory.createStartCommand(
+				new TargetModuleID[] { id }, module, getServer());
+		return cmd.execute(_monitor);
+	}
+
+	private IStatus stop(IModule module) throws Exception {
+		IDeploymentCommand cmd = DeploymentCommandFactory.createStopCommand(
+				module, getServer());
+		return cmd.execute(_monitor);
+	}
+
+	private IStatus unDeploy(IModule module) throws Exception {
+		IDeploymentCommand cmd = DeploymentCommandFactory
+				.createUndeployCommand(module, getServer());
+		return cmd.execute(_monitor);
+	}
+
+	private IStatus reDeploy(IModule module) throws Exception {
+		IDeploymentCommand cmd = DeploymentCommandFactory
+				.createRedeployCommand(module, getServer());
+		return cmd.execute(_monitor);
+	}
+
+	public Map getServerInstanceProperties() {
+		return getRuntimeDelegate().getServerInstanceProperties();
+	}
+
+	public String getUserName() {
+		return GeronimoConnectionFactory.getInstance().getUserName(getServer());
+	}
+
+	public String getPassword() {
+		return GeronimoConnectionFactory.getInstance().getPassword(getServer());
+	}
+
+	public String getRMINamingPort() {
+		return GeronimoConnectionFactory.getInstance().getRMINamingPort(
+				getServer());
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#setupLaunchConfiguration(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy,
+	 *      org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	public void setupLaunchConfiguration(
+			ILaunchConfigurationWorkingCopy workingCopy,
+			IProgressMonitor monitor) throws CoreException {
+		String defaultArgs = getServerDefinition().getResolver()
+				.resolveProperties(
+						getServerDefinition().getStart()
+								.getProgramArgumentsAsString());
+		String existingPrgArgs = workingCopy.getAttribute(
+				IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
+				defaultArgs);
+		super.setupLaunchConfiguration(workingCopy, monitor);
+		if (existingPrgArgs != null) {
+			workingCopy.setAttribute(
+					IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
+					existingPrgArgs);
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.jst.server.generic.core.internal.GenericServerBehaviour#setupLaunch(org.eclipse.debug.core.ILaunch,
+	 *      java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	protected void setupLaunch(ILaunch launch, String launchMode,
+			IProgressMonitor monitor) throws CoreException {
+		Trace.trace(Trace.INFO, "--> GeronimoServerBehavior.setupLaunch()");
+
+		if ("true".equals(launch.getLaunchConfiguration().getAttribute(
+				ATTR_STOP, "false")))
+			return;
+
+		if (!SocketUtil.isLocalhost(getServer().getHost()))
+			return;
+
+		ServerPort[] ports = getServer().getServerPorts(null);
+		for (int i = 0; i < ports.length; i++) {
+			ServerPort sp = ports[i];
+			if (SocketUtil.isPortInUse(ports[i].getPort(), 5))
+				throw new CoreException(new Status(IStatus.ERROR,
+						CorePlugin.PLUGIN_ID, 0, GenericServerCoreMessages
+								.bind(GenericServerCoreMessages.errorPortInUse,
+										Integer.toString(sp.getPort()), sp
+												.getName()), null));
+		}
+
+		stopUpdateServerStateTask();
+		setServerState(IServer.STATE_STARTING);
+		setMode(launchMode);
+
+		IServerListener listener = new IServerListener() {
+			public void serverChanged(ServerEvent event) {
+				int eventKind = event.getKind();
+				if (eventKind == (ServerEvent.SERVER_CHANGE | ServerEvent.STATE_CHANGE)) {
+					IServer server = event.getServer();
+					int state = server.getServerState();
+					if (state == IServer.STATE_STARTED
+							|| state == IServer.STATE_STOPPED) {
+						GeronimoServerBehaviour.this.getServer()
+								.removeServerListener(this);
+						startUpdateServerStateTask();
+					}
+				}
+			}
+		};
+
+		getServer().addServerListener(listener);
+		pingThread = new PingThread(this);
+		pingThread.start();
+		Trace.trace(Trace.INFO, "<-- GeronimoServerBehavior.setupLaunch()");
+	}
+
+	private void startUpdateServerStateTask() {
+		Trace.trace(Trace.INFO, "startUpdateServerStateTask() " + getServer().getName());
+		timer = new Timer(true);
+		timer.schedule(new UpdateServerStateTask(this), 10000,
+				TIMER_TASK_INTERVAL * 1000);
+	}
+
+	private void stopUpdateServerStateTask() {
+		Trace.trace(Trace.INFO, "stopUpdateServerStateTask() " + getServer().getName());
+		if (timer != null)
+			timer.cancel();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#initialize(org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	protected void initialize(IProgressMonitor monitor) {
+		Trace.trace(Trace.INFO, "GeronimoServerBehavior.initialize()");
+		startUpdateServerStateTask();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#dispose()
+	 */
+	public void dispose() {
+		stopUpdateServerStateTask();
+	}
+
 }

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerBehaviour.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerBehaviour.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerBehaviour.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerRuntimeTargetHandler.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerRuntimeTargetHandler.java?rev=382997&r1=382996&r2=382997&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerRuntimeTargetHandler.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerRuntimeTargetHandler.java Fri Mar  3 17:30:38 2006
@@ -1,211 +1,211 @@
-/**
- * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package org.apache.geronimo.core.internal;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jdt.core.IAccessRule;
-import org.eclipse.jdt.core.IClasspathAttribute;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jst.server.generic.core.internal.GenericServerRuntimeTargetHandler;
-import org.eclipse.jst.server.generic.core.internal.ServerTypeDefinitionUtil;
-import org.eclipse.jst.server.generic.servertype.definition.ArchiveType;
-import org.eclipse.jst.server.generic.servertype.definition.Classpath;
-import org.eclipse.jst.server.generic.servertype.definition.ServerRuntime;
-import org.eclipse.wst.server.core.IRuntime;
-
-public class GeronimoServerRuntimeTargetHandler extends
-		GenericServerRuntimeTargetHandler {
-
-	private static final String EXTENSION_RUNTIME_ACCESS = "discouragedRuntimeAccess";
-
-	String cachedArchiveString = null;
-	IClasspathEntry[] cachedClasspath = null;
-	private static Map map;
-	private IPath runtimeLoc;
-	private String runtimeTypeId;
-
-	static {
-		loadExtensions();
-	}
-
-	private static synchronized void loadExtensions() {
-		map = new HashMap();
-		IExtensionRegistry registry = Platform.getExtensionRegistry();
-		IConfigurationElement[] cf = registry.getConfigurationElementsFor(
-				GeronimoPlugin.PLUGIN_ID, EXTENSION_RUNTIME_ACCESS);
-		for (int i = 0; i < cf.length; i++) {
-			IConfigurationElement element = cf[i];
-			if ("restriction".equals(element.getName())) {
-				String runtimeId = element.getAttribute("id");
-				if (runtimeId != null) {
-					IConfigurationElement[] children = element.getChildren();
-					for (int j = 0; j < children.length; j++) {
-						String path = children[j].getAttribute("value");
-						if (path != null) {
-							Collection c = (Collection) map.get(runtimeId);
-							if (c == null) {
-								c = new ArrayList();
-								map.put(runtimeId, c);
-							}
-							c.add(new Path(path));
-						}
-					}
-				}
-			}
-
-		}
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see ClasspathRuntimeTargetHandler#resolveClasspathContainer(IRuntime,
-	 *      java.lang.String)
-	 */
-	public IClasspathEntry[] resolveClasspathContainer(IRuntime runtime,
-			String id) {
-		this.runtimeTypeId = runtime.getRuntimeType().getId();
-		return getServerClassPathEntry(runtime);
-	}
-
-	public IClasspathEntry[] getServerClassPathEntry(IRuntime runtime) {
-		this.runtimeLoc = runtime.getLocation();
-		ServerRuntime serverDefinition = ServerTypeDefinitionUtil
-				.getServerTypeDefinition(runtime);
-		String ref = serverDefinition.getProject().getClasspathReference();
-		Classpath cp = serverDefinition.getClasspath(ref);
-		List archives = cp.getArchive();
-
-		// It's expensive to keep searching directories, so try to cache the
-		// result
-		IClasspathEntry[] savedClasspath = getCachedClasspathFor(
-				serverDefinition, archives);
-		if (savedClasspath != null)
-			return savedClasspath;
-
-		Iterator archiveIter = archives.iterator();
-		ArrayList entryList = new ArrayList();
-		while (archiveIter.hasNext()) {
-			ArchiveType archive = (ArchiveType) archiveIter.next();
-			String item = serverDefinition.getResolver().resolveProperties(
-					archive.getPath());
-			IPath path = new Path(item);
-			File file = path.toFile();
-			if (file.isDirectory()) {
-				boolean discourageAccess = isAccessDiscouraged(path);
-				File[] list = file.listFiles();
-				for (int i = 0; i < list.length; i++) {
-					if (!list[i].isDirectory()) {
-						Path p = new Path(list[i].getAbsolutePath());
-						if (!discourageAccess)
-							discourageAccess = isAccessDiscouraged(p);
-						addLibEntry(entryList, p, discourageAccess);
-					}
-				}
-			} else {
-				addLibEntry(entryList, path, isAccessDiscouraged(path));
-			}
-		}
-
-		IClasspathEntry[] classpath = (IClasspathEntry[]) entryList
-				.toArray(new IClasspathEntry[entryList.size()]);
-		setCachedClasspath(classpath);
-
-		return classpath;
-	}
-
-	private boolean isAccessDiscouraged(IPath path) {
-		Collection c = (Collection) map.get(runtimeTypeId);
-		if (c == null || c.isEmpty())
-			return false;
-
-		Iterator i = c.iterator();
-		while (i.hasNext()) {
-			IPath xPath = (IPath) i.next();
-			if (path.toFile().isDirectory()
-					&& runtimeLoc.append(xPath).isPrefixOf(path)) {
-				return true;
-			} else if (runtimeLoc.append(xPath).equals(path)) {
-				return true;
-			}
-		}
-		return false;
-	}
-
-	private void addLibEntry(ArrayList entryList, IPath path,
-			boolean discourageAccess) {
-		IClasspathEntry entry = null;
-		if (discourageAccess) {
-			IAccessRule rule = JavaCore.newAccessRule(new Path("**"),
-					IAccessRule.K_DISCOURAGED);
-			IAccessRule rules[] = new IAccessRule[] { rule };
-			entry = JavaCore.newLibraryEntry(path, null, null, rules,
-					new IClasspathAttribute[] {}, false);
-		} else {
-			entry = JavaCore.newLibraryEntry(path, null, null);
-		}
-		entryList.add(entry);
-	}
-
-	private IClasspathEntry[] getCachedClasspathFor(
-			ServerRuntime serverDefinition, List archives) {
-
-		// Need to iterate through the list, and expand the variables (in case
-		// they have changed)
-		// The simplest approach is to construct/cache a string for this
-		// That will still save the overhead of going to the filesystem
-
-		StringBuffer buffer = new StringBuffer();
-		Iterator archiveIter = archives.iterator();
-		while (archiveIter.hasNext()) {
-			ArchiveType archive = (ArchiveType) archiveIter.next();
-			String item = serverDefinition.getResolver().resolveProperties(
-					archive.getPath());
-			buffer.append(item);
-			buffer.append(File.pathSeparatorChar);
-		}
-
-		String archiveString = buffer.toString();
-
-		if (cachedArchiveString != null
-				&& cachedArchiveString.equals(archiveString))
-			return cachedClasspath;
-
-		// This is a cache miss - ensure the data is null (to be safe), but save
-		// the key (archiveString) now
-		// The data will be set once it's calculated
-		cachedClasspath = null;
-		cachedArchiveString = archiveString;
-		return null;
-	}
-
-	private void setCachedClasspath(IClasspathEntry[] classpath) {
-		cachedClasspath = classpath;
-	}
-}
+/**
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.core.internal;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.core.IAccessRule;
+import org.eclipse.jdt.core.IClasspathAttribute;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jst.server.generic.core.internal.GenericServerRuntimeTargetHandler;
+import org.eclipse.jst.server.generic.core.internal.ServerTypeDefinitionUtil;
+import org.eclipse.jst.server.generic.servertype.definition.ArchiveType;
+import org.eclipse.jst.server.generic.servertype.definition.Classpath;
+import org.eclipse.jst.server.generic.servertype.definition.ServerRuntime;
+import org.eclipse.wst.server.core.IRuntime;
+
+public class GeronimoServerRuntimeTargetHandler extends
+		GenericServerRuntimeTargetHandler {
+
+	private static final String EXTENSION_RUNTIME_ACCESS = "discouragedRuntimeAccess";
+
+	String cachedArchiveString = null;
+	IClasspathEntry[] cachedClasspath = null;
+	private static Map map;
+	private IPath runtimeLoc;
+	private String runtimeTypeId;
+
+	static {
+		loadExtensions();
+	}
+
+	private static synchronized void loadExtensions() {
+		map = new HashMap();
+		IExtensionRegistry registry = Platform.getExtensionRegistry();
+		IConfigurationElement[] cf = registry.getConfigurationElementsFor(
+				GeronimoPlugin.PLUGIN_ID, EXTENSION_RUNTIME_ACCESS);
+		for (int i = 0; i < cf.length; i++) {
+			IConfigurationElement element = cf[i];
+			if ("restriction".equals(element.getName())) {
+				String runtimeId = element.getAttribute("id");
+				if (runtimeId != null) {
+					IConfigurationElement[] children = element.getChildren();
+					for (int j = 0; j < children.length; j++) {
+						String path = children[j].getAttribute("value");
+						if (path != null) {
+							Collection c = (Collection) map.get(runtimeId);
+							if (c == null) {
+								c = new ArrayList();
+								map.put(runtimeId, c);
+							}
+							c.add(new Path(path));
+						}
+					}
+				}
+			}
+
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see ClasspathRuntimeTargetHandler#resolveClasspathContainer(IRuntime,
+	 *      java.lang.String)
+	 */
+	public IClasspathEntry[] resolveClasspathContainer(IRuntime runtime,
+			String id) {
+		this.runtimeTypeId = runtime.getRuntimeType().getId();
+		return getServerClassPathEntry(runtime);
+	}
+
+	public IClasspathEntry[] getServerClassPathEntry(IRuntime runtime) {
+		this.runtimeLoc = runtime.getLocation();
+		ServerRuntime serverDefinition = ServerTypeDefinitionUtil
+				.getServerTypeDefinition(runtime);
+		String ref = serverDefinition.getProject().getClasspathReference();
+		Classpath cp = serverDefinition.getClasspath(ref);
+		List archives = cp.getArchive();
+
+		// It's expensive to keep searching directories, so try to cache the
+		// result
+		IClasspathEntry[] savedClasspath = getCachedClasspathFor(
+				serverDefinition, archives);
+		if (savedClasspath != null)
+			return savedClasspath;
+
+		Iterator archiveIter = archives.iterator();
+		ArrayList entryList = new ArrayList();
+		while (archiveIter.hasNext()) {
+			ArchiveType archive = (ArchiveType) archiveIter.next();
+			String item = serverDefinition.getResolver().resolveProperties(
+					archive.getPath());
+			IPath path = new Path(item);
+			File file = path.toFile();
+			if (file.isDirectory()) {
+				boolean discourageAccess = isAccessDiscouraged(path);
+				File[] list = file.listFiles();
+				for (int i = 0; i < list.length; i++) {
+					if (!list[i].isDirectory()) {
+						Path p = new Path(list[i].getAbsolutePath());
+						if (!discourageAccess)
+							discourageAccess = isAccessDiscouraged(p);
+						addLibEntry(entryList, p, discourageAccess);
+					}
+				}
+			} else {
+				addLibEntry(entryList, path, isAccessDiscouraged(path));
+			}
+		}
+
+		IClasspathEntry[] classpath = (IClasspathEntry[]) entryList
+				.toArray(new IClasspathEntry[entryList.size()]);
+		setCachedClasspath(classpath);
+
+		return classpath;
+	}
+
+	private boolean isAccessDiscouraged(IPath path) {
+		Collection c = (Collection) map.get(runtimeTypeId);
+		if (c == null || c.isEmpty())
+			return false;
+
+		Iterator i = c.iterator();
+		while (i.hasNext()) {
+			IPath xPath = (IPath) i.next();
+			if (path.toFile().isDirectory()
+					&& runtimeLoc.append(xPath).isPrefixOf(path)) {
+				return true;
+			} else if (runtimeLoc.append(xPath).equals(path)) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+	private void addLibEntry(ArrayList entryList, IPath path,
+			boolean discourageAccess) {
+		IClasspathEntry entry = null;
+		if (discourageAccess) {
+			IAccessRule rule = JavaCore.newAccessRule(new Path("**"),
+					IAccessRule.K_DISCOURAGED);
+			IAccessRule rules[] = new IAccessRule[] { rule };
+			entry = JavaCore.newLibraryEntry(path, null, null, rules,
+					new IClasspathAttribute[] {}, false);
+		} else {
+			entry = JavaCore.newLibraryEntry(path, null, null);
+		}
+		entryList.add(entry);
+	}
+
+	private IClasspathEntry[] getCachedClasspathFor(
+			ServerRuntime serverDefinition, List archives) {
+
+		// Need to iterate through the list, and expand the variables (in case
+		// they have changed)
+		// The simplest approach is to construct/cache a string for this
+		// That will still save the overhead of going to the filesystem
+
+		StringBuffer buffer = new StringBuffer();
+		Iterator archiveIter = archives.iterator();
+		while (archiveIter.hasNext()) {
+			ArchiveType archive = (ArchiveType) archiveIter.next();
+			String item = serverDefinition.getResolver().resolveProperties(
+					archive.getPath());
+			buffer.append(item);
+			buffer.append(File.pathSeparatorChar);
+		}
+
+		String archiveString = buffer.toString();
+
+		if (cachedArchiveString != null
+				&& cachedArchiveString.equals(archiveString))
+			return cachedClasspath;
+
+		// This is a cache miss - ensure the data is null (to be safe), but save
+		// the key (archiveString) now
+		// The data will be set once it's calculated
+		cachedClasspath = null;
+		cachedArchiveString = archiveString;
+		return null;
+	}
+
+	private void setCachedClasspath(IClasspathEntry[] classpath) {
+		cachedClasspath = classpath;
+	}
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerRuntimeTargetHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerRuntimeTargetHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoServerRuntimeTargetHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoUtils.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoUtils.java?rev=382997&r1=382996&r2=382997&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoUtils.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoUtils.java Fri Mar  3 17:30:38 2006
@@ -1,386 +1,386 @@
-/**
- * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package org.apache.geronimo.core.internal;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-
-import javax.enterprise.deploy.shared.ModuleType;
-
-import org.apache.geronimo.xml.ns.j2ee.application.ApplicationPackage;
-import org.apache.geronimo.xml.ns.j2ee.application.ApplicationType;
-import org.apache.geronimo.xml.ns.j2ee.application.util.ApplicationResourceFactoryImpl;
-import org.apache.geronimo.xml.ns.j2ee.connector.ConnectorPackage;
-import org.apache.geronimo.xml.ns.j2ee.connector.ConnectorType;
-import org.apache.geronimo.xml.ns.j2ee.connector.util.ConnectorResourceFactoryImpl;
-import org.apache.geronimo.xml.ns.j2ee.web.DocumentRoot;
-import org.apache.geronimo.xml.ns.j2ee.web.WebAppType;
-import org.apache.geronimo.xml.ns.j2ee.web.WebPackage;
-import org.apache.geronimo.xml.ns.j2ee.web.util.WebResourceFactoryImpl;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.ecore.xmi.XMIResource;
-import org.eclipse.jst.j2ee.internal.deployables.J2EEFlexProjDeployable;
-import org.eclipse.jst.server.core.IWebModule;
-import org.eclipse.wst.common.componentcore.ArtifactEdit;
-import org.eclipse.wst.common.componentcore.ComponentCore;
-import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
-import org.eclipse.wst.server.core.IModule;
-import org.openejb.xml.ns.openejb.jar.JarPackage;
-import org.openejb.xml.ns.openejb.jar.OpenejbJarType;
-import org.openejb.xml.ns.openejb.jar.util.JarResourceFactoryImpl;
-
-public class GeronimoUtils {
-
-	public static final String WEB_PLAN_NAME = "geronimo-web.xml";
-
-	public static final String OPENEJB_PLAN_NAME = "openejb-jar.xml";
-
-	public static final String APP_PLAN_NAME = "geronimo-application.xml";
-
-	public static final String CONNECTOR_PLAN_NAME = "geronimo-connector.xml";
-
-	public static String getConfigId(IModule module) {
-
-		if (isWebModule(module)) {
-			WebAppType plan = getWebDeploymentPlan(module);
-			if (plan != null
-					&& plan.eIsSet(WebPackage.eINSTANCE
-							.getWebAppType_ConfigId())) {
-				return plan.getConfigId();
-			}
-		} else if (isEjbJarModule(module)) {
-			OpenejbJarType plan = getOpenEjbDeploymentPlan(module);
-			if (plan != null
-					&& plan.eIsSet(JarPackage.eINSTANCE
-							.getOpenejbJarType_ConfigId())) {
-				return plan.getConfigId();
-			}
-		} else if (isEarModule(module)) {
-			ApplicationType plan = getApplicationDeploymentPlan(module);
-			if (plan != null
-					&& plan.eIsSet(ApplicationPackage.eINSTANCE
-							.getApplicationType_ConfigId())) {
-				return plan.getConfigId();
-			}
-		} else if (isRARModule(module)) {
-			ConnectorType plan = getConnectorDeploymentPlan(module);
-			if (plan != null
-					&& plan.eIsSet(ConnectorPackage.eINSTANCE
-							.getConnectorType_ConfigId())) {
-				return plan.getConfigId();
-			}
-		}
-
-		return getId(module);
-	}
-
-	public static boolean isWebModule(IModule module) {
-		return "jst.web".equals(module.getModuleType().getId());
-	}
-
-	public static boolean isEjbJarModule(IModule module) {
-		return "jst.ejb".equals(module.getModuleType().getId());
-	}
-
-	public static boolean isEarModule(IModule module) {
-		return "jst.ear".equals(module.getModuleType().getId());
-	}
-
-	public static boolean isRARModule(IModule module) {
-		return "jst.connnector".equals(module.getModuleType().getId());
-	}
-
-	public static ModuleType getJSR88ModuleType(IModule module) {
-		if (isWebModule(module)) {
-			return ModuleType.WAR;
-		} else if (isEjbJarModule(module)) {
-			return ModuleType.EJB;
-		} else if (isEarModule(module)) {
-			return ModuleType.EAR;
-		} else if (isRARModule(module)) {
-			return ModuleType.RAR;
-		}
-		Trace.trace(Trace.SEVERE, "getJSR88ModuleType = null");
-		return null;
-	}
-
-	public static String getContextRoot(IModule module) {
-		String contextRoot = null;
-
-		WebAppType deploymentPlan = getWebDeploymentPlan(module);
-		if (deploymentPlan != null)
-			contextRoot = deploymentPlan.getContextRoot();
-
-		if (contextRoot == null) {
-			J2EEFlexProjDeployable j2eeModule = (J2EEFlexProjDeployable) module
-					.loadAdapter(J2EEFlexProjDeployable.class, null);
-			contextRoot = ((IWebModule) j2eeModule).getContextRoot();
-		}
-
-		if (contextRoot == null)
-			contextRoot = getId(module);
-
-		return contextRoot;
-	}
-
-	public static String getId(IModule module) {
-		// use the module ID
-		String moduleId = module.getId();
-
-		J2EEFlexProjDeployable j2eeModule = (J2EEFlexProjDeployable) module
-				.loadAdapter(J2EEFlexProjDeployable.class, null);
-		if (j2eeModule != null) {
-			// j2eeFlex
-			ArtifactEdit edit = null;
-			try {
-				edit = ArtifactEdit.getArtifactEditForRead(j2eeModule
-						.getProject());
-				XMIResource res = (XMIResource) edit.getContentModelRoot()
-						.eResource();
-				moduleId = res.getID(edit.getContentModelRoot());
-			} finally {
-				if (edit != null)
-					edit.dispose();
-			}
-		}
-
-		if (moduleId != null && moduleId.length() > 0)
-			return moduleId;
-
-		// ...but if there is no defined module ID, pick the best alternative
-
-		IPath moduleLocation = new Path(j2eeModule.getURI(module));
-		if (moduleLocation != null) {
-			moduleId = moduleLocation.removeFileExtension().lastSegment();
-		}
-
-		if (j2eeModule instanceof IWebModule) {
-			// A better choice is to use the context root
-			// For wars most appservers use the module name
-			// as the context root
-			String contextRoot = ((IWebModule) j2eeModule).getContextRoot();
-			if (contextRoot.charAt(0) == '/')
-				moduleId = contextRoot.substring(1);
-		}
-
-		return moduleId;
-	}
-
-	public static ApplicationType getApplicationDeploymentPlan(
-			IVirtualComponent comp) {
-		IFile dpPlan = getApplicationDeploymentPlanFile(comp);
-		return getApplicationDeploymentPlan(dpPlan);
-	}
-
-	public static WebAppType getWebDeploymentPlan(IVirtualComponent comp) {
-		IFile dpPlan = getWebDeploymentPlanFile(comp);
-		return getWebDeploymentPlan(dpPlan);
-	}
-
-	public static OpenejbJarType getOpenEjbDeploymentPlan(IVirtualComponent comp) {
-		IFile dpPlan = getOpenEjbDeploymentPlanFile(comp);
-		return getOpenEjbDeploymentPlan(dpPlan);
-	}
-
-	public static ConnectorType getConnectorDeploymentPlan(
-			IVirtualComponent comp) {
-		IFile dpPlan = getConnectorDeploymentPlanFile(comp);
-		return getConnectorDeploymentPlan(dpPlan);
-	}
-
-	public static ApplicationType getApplicationDeploymentPlan(IFile file) {
-		if (file.getName().equals(APP_PLAN_NAME) && file.exists()) {
-			ResourceSet resourceSet = new ResourceSetImpl();
-			registerAppFactoryAndPackage(resourceSet);
-			Resource resource = load(file, resourceSet);
-			if (resource != null) {
-				return ((org.apache.geronimo.xml.ns.j2ee.application.DocumentRoot) resource
-						.getContents().get(0)).getApplication();
-			}
-		}
-		return null;
-	}
-
-	public static WebAppType getWebDeploymentPlan(IFile file) {
-		if (file.getName().equals(WEB_PLAN_NAME) && file.exists()) {
-			ResourceSet resourceSet = new ResourceSetImpl();
-			registerWebFactoryAndPackage(resourceSet);
-			Resource resource = load(file, resourceSet);
-			if (resource != null) {
-				return ((DocumentRoot) resource.getContents().get(0))
-						.getWebApp();
-			}
-		}
-		return null;
-	}
-
-	public static OpenejbJarType getOpenEjbDeploymentPlan(IFile file) {
-		if (file.getName().equals(OPENEJB_PLAN_NAME) && file.exists()) {
-			ResourceSet resourceSet = new ResourceSetImpl();
-			registerEjbFactoryAndPackage(resourceSet);
-			Resource resource = load(file, resourceSet);
-			if (resource != null) {
-				return ((org.openejb.xml.ns.openejb.jar.DocumentRoot) resource
-						.getContents().get(0)).getOpenejbJar();
-			}
-		}
-		return null;
-	}
-
-	public static ConnectorType getConnectorDeploymentPlan(IFile file) {
-		if (file.getName().equals(CONNECTOR_PLAN_NAME) && file.exists()) {
-			ResourceSet resourceSet = new ResourceSetImpl();
-			registerConnectorFactoryAndPackage(resourceSet);
-			Resource resource = load(file, resourceSet);
-			if (resource != null) {
-				return ((org.apache.geronimo.xml.ns.j2ee.connector.DocumentRoot) resource
-						.getContents().get(0)).getConnector();
-			}
-		}
-		return null;
-	}
-
-	public static IFile getWebDeploymentPlanFile(IVirtualComponent comp) {
-		IPath deployPlanPath = comp.getRootFolder().getUnderlyingFolder()
-				.getProjectRelativePath().append("WEB-INF").append(
-						WEB_PLAN_NAME);
-		return comp.getProject().getFile(deployPlanPath);
-	}
-
-	public static IFile getOpenEjbDeploymentPlanFile(IVirtualComponent comp) {
-		IPath deployPlanPath = comp.getRootFolder().getUnderlyingFolder()
-				.getProjectRelativePath().append("META-INF").append(
-						OPENEJB_PLAN_NAME);
-		return comp.getProject().getFile(deployPlanPath);
-	}
-
-	public static IFile getApplicationDeploymentPlanFile(IVirtualComponent comp) {
-		IPath deployPlanPath = comp.getRootFolder().getUnderlyingFolder()
-				.getProjectRelativePath().append("META-INF").append(
-						APP_PLAN_NAME);
-		return comp.getProject().getFile(deployPlanPath);
-	}
-
-	public static IFile getConnectorDeploymentPlanFile(IVirtualComponent comp) {
-		IPath deployPlanPath = comp.getRootFolder().getUnderlyingFolder()
-				.getProjectRelativePath().append("META-INF").append(
-						CONNECTOR_PLAN_NAME);
-		return comp.getProject().getFile(deployPlanPath);
-	}
-
-	public static WebAppType getWebDeploymentPlan(IModule module) {
-		return getWebDeploymentPlan(getVirtualComponent(module));
-	}
-
-	public static ApplicationType getApplicationDeploymentPlan(IModule module) {
-		return getApplicationDeploymentPlan(getVirtualComponent(module));
-	}
-
-	public static OpenejbJarType getOpenEjbDeploymentPlan(IModule module) {
-		return getOpenEjbDeploymentPlan(getVirtualComponent(module));
-	}
-
-	public static ConnectorType getConnectorDeploymentPlan(IModule module) {
-		return getConnectorDeploymentPlan(getVirtualComponent(module));
-	}
-
-	private static IVirtualComponent getVirtualComponent(IModule module) {
-		return ComponentCore.createComponent(module.getProject());
-	}
-
-	private static Resource load(IFile dpFile, ResourceSet resourceSet) {
-		try {
-
-			URI uri = URI.createPlatformResourceURI(dpFile.getFullPath()
-					.toString());
-
-			Resource resource = resourceSet.createResource(uri);
-			if (!resource.isLoaded()) {
-				resource.load(null);
-			}
-			return resource;
-		} catch (MalformedURLException e) {
-			e.printStackTrace();
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-
-	/**
-	 * Register the appropriate resource factory to handle all file extentions.
-	 * Register the package to ensure it is available during loading.
-	 * 
-	 * @param resourceSet
-	 */
-	public static void registerWebFactoryAndPackage(ResourceSet resourceSet) {
-		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
-				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
-						new WebResourceFactoryImpl());
-		resourceSet.getPackageRegistry().put(WebPackage.eNS_URI,
-				WebPackage.eINSTANCE);
-	}
-
-	/**
-	 * Register the appropriate resource factory to handle all file extentions.
-	 * Register the package to ensure it is available during loading.
-	 * 
-	 * @param resourceSet
-	 */
-	public static void registerEjbFactoryAndPackage(ResourceSet resourceSet) {
-		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
-				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
-						new JarResourceFactoryImpl());
-		resourceSet.getPackageRegistry().put(JarPackage.eNS_URI,
-				JarPackage.eINSTANCE);
-	}
-
-	/**
-	 * Register the appropriate resource factory to handle all file extentions.
-	 * Register the package to ensure it is available during loading.
-	 * 
-	 * @param resourceSet
-	 */
-	public static void registerAppFactoryAndPackage(ResourceSet resourceSet) {
-		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
-				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
-						new ApplicationResourceFactoryImpl());
-		resourceSet.getPackageRegistry().put(ApplicationPackage.eNS_URI,
-				ApplicationPackage.eINSTANCE);
-	}
-
-	/**
-	 * Register the appropriate resource factory to handle all file extentions.
-	 * Register the package to ensure it is available during loading.
-	 * 
-	 * @param resourceSet
-	 */
-	public static void registerConnectorFactoryAndPackage(
-			ResourceSet resourceSet) {
-		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
-				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
-						new ConnectorResourceFactoryImpl());
-		resourceSet.getPackageRegistry().put(ConnectorPackage.eNS_URI,
-				ConnectorPackage.eINSTANCE);
-	}
-
+/**
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.core.internal;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import javax.enterprise.deploy.shared.ModuleType;
+
+import org.apache.geronimo.xml.ns.j2ee.application.ApplicationPackage;
+import org.apache.geronimo.xml.ns.j2ee.application.ApplicationType;
+import org.apache.geronimo.xml.ns.j2ee.application.util.ApplicationResourceFactoryImpl;
+import org.apache.geronimo.xml.ns.j2ee.connector.ConnectorPackage;
+import org.apache.geronimo.xml.ns.j2ee.connector.ConnectorType;
+import org.apache.geronimo.xml.ns.j2ee.connector.util.ConnectorResourceFactoryImpl;
+import org.apache.geronimo.xml.ns.j2ee.web.DocumentRoot;
+import org.apache.geronimo.xml.ns.j2ee.web.WebAppType;
+import org.apache.geronimo.xml.ns.j2ee.web.WebPackage;
+import org.apache.geronimo.xml.ns.j2ee.web.util.WebResourceFactoryImpl;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.xmi.XMIResource;
+import org.eclipse.jst.j2ee.internal.deployables.J2EEFlexProjDeployable;
+import org.eclipse.jst.server.core.IWebModule;
+import org.eclipse.wst.common.componentcore.ArtifactEdit;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.server.core.IModule;
+import org.openejb.xml.ns.openejb.jar.JarPackage;
+import org.openejb.xml.ns.openejb.jar.OpenejbJarType;
+import org.openejb.xml.ns.openejb.jar.util.JarResourceFactoryImpl;
+
+public class GeronimoUtils {
+
+	public static final String WEB_PLAN_NAME = "geronimo-web.xml";
+
+	public static final String OPENEJB_PLAN_NAME = "openejb-jar.xml";
+
+	public static final String APP_PLAN_NAME = "geronimo-application.xml";
+
+	public static final String CONNECTOR_PLAN_NAME = "geronimo-connector.xml";
+
+	public static String getConfigId(IModule module) {
+
+		if (isWebModule(module)) {
+			WebAppType plan = getWebDeploymentPlan(module);
+			if (plan != null
+					&& plan.eIsSet(WebPackage.eINSTANCE
+							.getWebAppType_ConfigId())) {
+				return plan.getConfigId();
+			}
+		} else if (isEjbJarModule(module)) {
+			OpenejbJarType plan = getOpenEjbDeploymentPlan(module);
+			if (plan != null
+					&& plan.eIsSet(JarPackage.eINSTANCE
+							.getOpenejbJarType_ConfigId())) {
+				return plan.getConfigId();
+			}
+		} else if (isEarModule(module)) {
+			ApplicationType plan = getApplicationDeploymentPlan(module);
+			if (plan != null
+					&& plan.eIsSet(ApplicationPackage.eINSTANCE
+							.getApplicationType_ConfigId())) {
+				return plan.getConfigId();
+			}
+		} else if (isRARModule(module)) {
+			ConnectorType plan = getConnectorDeploymentPlan(module);
+			if (plan != null
+					&& plan.eIsSet(ConnectorPackage.eINSTANCE
+							.getConnectorType_ConfigId())) {
+				return plan.getConfigId();
+			}
+		}
+
+		return getId(module);
+	}
+
+	public static boolean isWebModule(IModule module) {
+		return "jst.web".equals(module.getModuleType().getId());
+	}
+
+	public static boolean isEjbJarModule(IModule module) {
+		return "jst.ejb".equals(module.getModuleType().getId());
+	}
+
+	public static boolean isEarModule(IModule module) {
+		return "jst.ear".equals(module.getModuleType().getId());
+	}
+
+	public static boolean isRARModule(IModule module) {
+		return "jst.connnector".equals(module.getModuleType().getId());
+	}
+
+	public static ModuleType getJSR88ModuleType(IModule module) {
+		if (isWebModule(module)) {
+			return ModuleType.WAR;
+		} else if (isEjbJarModule(module)) {
+			return ModuleType.EJB;
+		} else if (isEarModule(module)) {
+			return ModuleType.EAR;
+		} else if (isRARModule(module)) {
+			return ModuleType.RAR;
+		}
+		Trace.trace(Trace.SEVERE, "getJSR88ModuleType = null");
+		return null;
+	}
+
+	public static String getContextRoot(IModule module) {
+		String contextRoot = null;
+
+		WebAppType deploymentPlan = getWebDeploymentPlan(module);
+		if (deploymentPlan != null)
+			contextRoot = deploymentPlan.getContextRoot();
+
+		if (contextRoot == null) {
+			J2EEFlexProjDeployable j2eeModule = (J2EEFlexProjDeployable) module
+					.loadAdapter(J2EEFlexProjDeployable.class, null);
+			contextRoot = ((IWebModule) j2eeModule).getContextRoot();
+		}
+
+		if (contextRoot == null)
+			contextRoot = getId(module);
+
+		return contextRoot;
+	}
+
+	public static String getId(IModule module) {
+		// use the module ID
+		String moduleId = module.getId();
+
+		J2EEFlexProjDeployable j2eeModule = (J2EEFlexProjDeployable) module
+				.loadAdapter(J2EEFlexProjDeployable.class, null);
+		if (j2eeModule != null) {
+			// j2eeFlex
+			ArtifactEdit edit = null;
+			try {
+				edit = ArtifactEdit.getArtifactEditForRead(j2eeModule
+						.getProject());
+				XMIResource res = (XMIResource) edit.getContentModelRoot()
+						.eResource();
+				moduleId = res.getID(edit.getContentModelRoot());
+			} finally {
+				if (edit != null)
+					edit.dispose();
+			}
+		}
+
+		if (moduleId != null && moduleId.length() > 0)
+			return moduleId;
+
+		// ...but if there is no defined module ID, pick the best alternative
+
+		IPath moduleLocation = new Path(j2eeModule.getURI(module));
+		if (moduleLocation != null) {
+			moduleId = moduleLocation.removeFileExtension().lastSegment();
+		}
+
+		if (j2eeModule instanceof IWebModule) {
+			// A better choice is to use the context root
+			// For wars most appservers use the module name
+			// as the context root
+			String contextRoot = ((IWebModule) j2eeModule).getContextRoot();
+			if (contextRoot.charAt(0) == '/')
+				moduleId = contextRoot.substring(1);
+		}
+
+		return moduleId;
+	}
+
+	public static ApplicationType getApplicationDeploymentPlan(
+			IVirtualComponent comp) {
+		IFile dpPlan = getApplicationDeploymentPlanFile(comp);
+		return getApplicationDeploymentPlan(dpPlan);
+	}
+
+	public static WebAppType getWebDeploymentPlan(IVirtualComponent comp) {
+		IFile dpPlan = getWebDeploymentPlanFile(comp);
+		return getWebDeploymentPlan(dpPlan);
+	}
+
+	public static OpenejbJarType getOpenEjbDeploymentPlan(IVirtualComponent comp) {
+		IFile dpPlan = getOpenEjbDeploymentPlanFile(comp);
+		return getOpenEjbDeploymentPlan(dpPlan);
+	}
+
+	public static ConnectorType getConnectorDeploymentPlan(
+			IVirtualComponent comp) {
+		IFile dpPlan = getConnectorDeploymentPlanFile(comp);
+		return getConnectorDeploymentPlan(dpPlan);
+	}
+
+	public static ApplicationType getApplicationDeploymentPlan(IFile file) {
+		if (file.getName().equals(APP_PLAN_NAME) && file.exists()) {
+			ResourceSet resourceSet = new ResourceSetImpl();
+			registerAppFactoryAndPackage(resourceSet);
+			Resource resource = load(file, resourceSet);
+			if (resource != null) {
+				return ((org.apache.geronimo.xml.ns.j2ee.application.DocumentRoot) resource
+						.getContents().get(0)).getApplication();
+			}
+		}
+		return null;
+	}
+
+	public static WebAppType getWebDeploymentPlan(IFile file) {
+		if (file.getName().equals(WEB_PLAN_NAME) && file.exists()) {
+			ResourceSet resourceSet = new ResourceSetImpl();
+			registerWebFactoryAndPackage(resourceSet);
+			Resource resource = load(file, resourceSet);
+			if (resource != null) {
+				return ((DocumentRoot) resource.getContents().get(0))
+						.getWebApp();
+			}
+		}
+		return null;
+	}
+
+	public static OpenejbJarType getOpenEjbDeploymentPlan(IFile file) {
+		if (file.getName().equals(OPENEJB_PLAN_NAME) && file.exists()) {
+			ResourceSet resourceSet = new ResourceSetImpl();
+			registerEjbFactoryAndPackage(resourceSet);
+			Resource resource = load(file, resourceSet);
+			if (resource != null) {
+				return ((org.openejb.xml.ns.openejb.jar.DocumentRoot) resource
+						.getContents().get(0)).getOpenejbJar();
+			}
+		}
+		return null;
+	}
+
+	public static ConnectorType getConnectorDeploymentPlan(IFile file) {
+		if (file.getName().equals(CONNECTOR_PLAN_NAME) && file.exists()) {
+			ResourceSet resourceSet = new ResourceSetImpl();
+			registerConnectorFactoryAndPackage(resourceSet);
+			Resource resource = load(file, resourceSet);
+			if (resource != null) {
+				return ((org.apache.geronimo.xml.ns.j2ee.connector.DocumentRoot) resource
+						.getContents().get(0)).getConnector();
+			}
+		}
+		return null;
+	}
+
+	public static IFile getWebDeploymentPlanFile(IVirtualComponent comp) {
+		IPath deployPlanPath = comp.getRootFolder().getUnderlyingFolder()
+				.getProjectRelativePath().append("WEB-INF").append(
+						WEB_PLAN_NAME);
+		return comp.getProject().getFile(deployPlanPath);
+	}
+
+	public static IFile getOpenEjbDeploymentPlanFile(IVirtualComponent comp) {
+		IPath deployPlanPath = comp.getRootFolder().getUnderlyingFolder()
+				.getProjectRelativePath().append("META-INF").append(
+						OPENEJB_PLAN_NAME);
+		return comp.getProject().getFile(deployPlanPath);
+	}
+
+	public static IFile getApplicationDeploymentPlanFile(IVirtualComponent comp) {
+		IPath deployPlanPath = comp.getRootFolder().getUnderlyingFolder()
+				.getProjectRelativePath().append("META-INF").append(
+						APP_PLAN_NAME);
+		return comp.getProject().getFile(deployPlanPath);
+	}
+
+	public static IFile getConnectorDeploymentPlanFile(IVirtualComponent comp) {
+		IPath deployPlanPath = comp.getRootFolder().getUnderlyingFolder()
+				.getProjectRelativePath().append("META-INF").append(
+						CONNECTOR_PLAN_NAME);
+		return comp.getProject().getFile(deployPlanPath);
+	}
+
+	public static WebAppType getWebDeploymentPlan(IModule module) {
+		return getWebDeploymentPlan(getVirtualComponent(module));
+	}
+
+	public static ApplicationType getApplicationDeploymentPlan(IModule module) {
+		return getApplicationDeploymentPlan(getVirtualComponent(module));
+	}
+
+	public static OpenejbJarType getOpenEjbDeploymentPlan(IModule module) {
+		return getOpenEjbDeploymentPlan(getVirtualComponent(module));
+	}
+
+	public static ConnectorType getConnectorDeploymentPlan(IModule module) {
+		return getConnectorDeploymentPlan(getVirtualComponent(module));
+	}
+
+	private static IVirtualComponent getVirtualComponent(IModule module) {
+		return ComponentCore.createComponent(module.getProject());
+	}
+
+	private static Resource load(IFile dpFile, ResourceSet resourceSet) {
+		try {
+
+			URI uri = URI.createPlatformResourceURI(dpFile.getFullPath()
+					.toString());
+
+			Resource resource = resourceSet.createResource(uri);
+			if (!resource.isLoaded()) {
+				resource.load(null);
+			}
+			return resource;
+		} catch (MalformedURLException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	/**
+	 * Register the appropriate resource factory to handle all file extentions.
+	 * Register the package to ensure it is available during loading.
+	 * 
+	 * @param resourceSet
+	 */
+	public static void registerWebFactoryAndPackage(ResourceSet resourceSet) {
+		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
+				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
+						new WebResourceFactoryImpl());
+		resourceSet.getPackageRegistry().put(WebPackage.eNS_URI,
+				WebPackage.eINSTANCE);
+	}
+
+	/**
+	 * Register the appropriate resource factory to handle all file extentions.
+	 * Register the package to ensure it is available during loading.
+	 * 
+	 * @param resourceSet
+	 */
+	public static void registerEjbFactoryAndPackage(ResourceSet resourceSet) {
+		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
+				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
+						new JarResourceFactoryImpl());
+		resourceSet.getPackageRegistry().put(JarPackage.eNS_URI,
+				JarPackage.eINSTANCE);
+	}
+
+	/**
+	 * Register the appropriate resource factory to handle all file extentions.
+	 * Register the package to ensure it is available during loading.
+	 * 
+	 * @param resourceSet
+	 */
+	public static void registerAppFactoryAndPackage(ResourceSet resourceSet) {
+		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
+				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
+						new ApplicationResourceFactoryImpl());
+		resourceSet.getPackageRegistry().put(ApplicationPackage.eNS_URI,
+				ApplicationPackage.eINSTANCE);
+	}
+
+	/**
+	 * Register the appropriate resource factory to handle all file extentions.
+	 * Register the package to ensure it is available during loading.
+	 * 
+	 * @param resourceSet
+	 */
+	public static void registerConnectorFactoryAndPackage(
+			ResourceSet resourceSet) {
+		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
+				.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
+						new ConnectorResourceFactoryImpl());
+		resourceSet.getPackageRegistry().put(ConnectorPackage.eNS_URI,
+				ConnectorPackage.eINSTANCE);
+	}
+
 }

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/GeronimoUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.java?rev=382997&r1=382996&r2=382997&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.java Fri Mar  3 17:30:38 2006
@@ -1,35 +1,35 @@
-/**
- * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package org.apache.geronimo.core.internal;
-
-import org.eclipse.osgi.util.NLS;
-/**
- * Translated messages.
- */
-public class Messages extends NLS {
-	
-	static {
-		NLS.initializeMessages("org.apache.geronimo.core.internal.Messages", Messages.class);
-	}
-	
-	public static String DISTRIBUTE_FAIL;
-	public static String START_FAIL;
-	public static String STOP_FAIL;
-	public static String UNDEPLOY_FAIL;
-	public static String REDEPLOY_FAIL;
-	public static String DM_CONNECTION_FAIL;
-	
+/**
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.core.internal;
+
+import org.eclipse.osgi.util.NLS;
+/**
+ * Translated messages.
+ */
+public class Messages extends NLS {
+	
+	static {
+		NLS.initializeMessages("org.apache.geronimo.core.internal.Messages", Messages.class);
+	}
+	
+	public static String DISTRIBUTE_FAIL;
+	public static String START_FAIL;
+	public static String STOP_FAIL;
+	public static String UNDEPLOY_FAIL;
+	public static String REDEPLOY_FAIL;
+	public static String DM_CONNECTION_FAIL;
+	
 }

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.properties
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.properties?rev=382997&r1=382996&r2=382997&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.properties (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.properties Fri Mar  3 17:30:38 2006
@@ -1,6 +1,6 @@
-DISTRIBUTE_FAIL=Distribution of configuration failed.  See .log for details.
-START_FAIL=Starting of configuration failed.  See .log for details.
-STOP_FAIL=Stopping of configuration failed.  See .log for details.
-UNDEPLOY_FAIL=Undeploy of configuration failed.  See .log for details.
-REDEPLOY_FAIL=Redeploy of configuration failed.  See .log for details.
+DISTRIBUTE_FAIL=Distribution of configuration failed.  See .log for details.
+START_FAIL=Starting of configuration failed.  See .log for details.
+STOP_FAIL=Stopping of configuration failed.  See .log for details.
+UNDEPLOY_FAIL=Undeploy of configuration failed.  See .log for details.
+REDEPLOY_FAIL=Redeploy of configuration failed.  See .log for details.
 DM_CONNECTION_FAIL=Connection to deployment manager failed.  See .log for details.

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.properties
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Messages.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Trace.java
URL: http://svn.apache.org/viewcvs/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Trace.java?rev=382997&r1=382996&r2=382997&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Trace.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.devtools.eclipse.core/src/org/apache/geronimo/core/internal/Trace.java Fri Mar  3 17:30:38 2006
@@ -1,70 +1,70 @@
-/**
- * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package org.apache.geronimo.core.internal;
-/**
- * Helper class to route trace output.
- */
-public class Trace {
-
-	/**
-	 * Finest trace event.
-	 */
-	public static byte INFO = 0;
-    
-    /**
-     * Warning trace event.
-     */
-    public static byte WARNING = 1;
-    
-    /**
-     * Severe trace event.
-     */
-    public static byte SEVERE = 2;
-
-
-	/**
-	 * Trace constructor comment.
-	 */
-	private Trace() {
-		super();
-	}
-
-	/**
-	 * Trace the given text.
-	 *
-	 * @param level the trace level
-	 * @param s a message
-	 */
-	public static void trace(byte level, String s) {
-		trace(level, s, null);
-	}
-
-	/**
-	 * Trace the given message and exception.
-	 *
-	 * @param level the trace level
-	 * @param s a message
-	 * @param t a throwable
-	 */
-	public static void trace(byte level, String s, Throwable t) {
-		if (!GeronimoPlugin.getInstance().isDebugging())
-			return;
-
-		System.out.println(GeronimoPlugin.PLUGIN_ID + ":  " + s);
-		if (t != null)
-			t.printStackTrace();
-	}
+/**
+ * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.core.internal;
+/**
+ * Helper class to route trace output.
+ */
+public class Trace {
+
+	/**
+	 * Finest trace event.
+	 */
+	public static byte INFO = 0;
+    
+    /**
+     * Warning trace event.
+     */
+    public static byte WARNING = 1;
+    
+    /**
+     * Severe trace event.
+     */
+    public static byte SEVERE = 2;
+
+
+	/**
+	 * Trace constructor comment.
+	 */
+	private Trace() {
+		super();
+	}
+
+	/**
+	 * Trace the given text.
+	 *
+	 * @param level the trace level
+	 * @param s a message
+	 */
+	public static void trace(byte level, String s) {
+		trace(level, s, null);
+	}
+
+	/**
+	 * Trace the given message and exception.
+	 *
+	 * @param level the trace level
+	 * @param s a message
+	 * @param t a throwable
+	 */
+	public static void trace(byte level, String s, Throwable t) {
+		if (!GeronimoPlugin.getInstance().isDebugging())
+			return;
+
+		System.out.println(GeronimoPlugin.PLUGIN_ID + ":  " + s);
+		if (t != null)
+			t.printStackTrace();
+	}
 }



Mime
View raw message