geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1145251 - in /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core: ./ internal/ osgi/
Date Mon, 11 Jul 2011 17:38:40 GMT
Author: gawor
Date: Mon Jul 11 17:38:40 2011
New Revision: 1145251

URL: http://svn.apache.org/viewvc?rev=1145251&view=rev
Log:
GERONIMODEVTOOLS-759: Refactor the module handling code and simplify OSGi bundle handler code

Added:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/AbstractModuleHandler.java   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DefaultModuleHandler.java   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java   (with props)
Removed:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleCache.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGIBundleHelper.java
Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviour.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.properties
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/AriesHelper.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OsgiConstants.java

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/AbstractModuleHandler.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/AbstractModuleHandler.java?rev=1145251&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/AbstractModuleHandler.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/AbstractModuleHandler.java Mon Jul 11 17:38:40 2011
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.st.v30.core;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+
+public abstract class AbstractModuleHandler {
+    
+    protected GeronimoServerBehaviourDelegate serverDelegate;
+    
+    public AbstractModuleHandler(GeronimoServerBehaviourDelegate serverDelegate) {
+        this.serverDelegate = serverDelegate;
+    }
+    
+    abstract public void doAdded(IModule module, IProgressMonitor monitor) throws Exception;
+        
+    abstract public void doChanged(IModule module, IProgressMonitor monitor) throws Exception;
+    
+    abstract public void doNoChange(IModule module, IProgressMonitor monitor) throws Exception;
+        
+    abstract public void doRemoved(IModule module, IProgressMonitor monitor) throws Exception;
+
+    abstract public void doStartModule(IModule[] module, IProgressMonitor monitor) throws Exception;
+    
+    abstract public void doStopModule(IModule[] module, IProgressMonitor monitor) throws Exception;
+    
+    abstract public void doRestartModule(IModule[] module, IProgressMonitor monitor) throws Exception;
+
+    public void serverStopped() {        
+    }
+    
+    protected void doFail(IStatus status, String message) throws CoreException {
+        MultiStatus ms = new MultiStatus(Activator.PLUGIN_ID, 0, message, null);
+        ms.addAll(status);
+        throw new CoreException(ms);
+    }
+    
+    public void setModuleState(IModule[] module, int state) {
+        serverDelegate.setModulesState(module, state);
+    }
+    
+    public IServer getServer() {
+        return serverDelegate.getServer();
+    }
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/AbstractModuleHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/AbstractModuleHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/AbstractModuleHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DefaultModuleHandler.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DefaultModuleHandler.java?rev=1145251&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DefaultModuleHandler.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DefaultModuleHandler.java Mon Jul 11 17:38:40 2011
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.st.v30.core;
+
+import java.util.Arrays;
+import java.util.Map;
+
+import javax.enterprise.deploy.spi.DeploymentManager;
+import javax.enterprise.deploy.spi.TargetModuleID;
+
+import org.apache.geronimo.st.v30.core.commands.DeploymentCmdStatus;
+import org.apache.geronimo.st.v30.core.commands.DeploymentCommandFactory;
+import org.apache.geronimo.st.v30.core.commands.IDeploymentCommand;
+import org.apache.geronimo.st.v30.core.internal.Messages;
+import org.apache.geronimo.st.v30.core.internal.Trace;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+
+public class DefaultModuleHandler extends AbstractModuleHandler {
+    
+    private ModuleArtifactMapper mapper;
+    
+    public DefaultModuleHandler(GeronimoServerBehaviourDelegate serverDelegate) {
+        super(serverDelegate);
+        mapper = ModuleArtifactMapper.getInstance();
+    }
+
+    public void doAdded(IModule module, IProgressMonitor monitor) throws Exception {
+        doAdded(module, null, monitor);
+    }
+    
+    public void doAdded(IModule module, String configId, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "DefaultModuleHandler.doAdded", module.getName(), configId);
+        
+        configId = getLastKnowConfigurationId(module, configId);
+        if (configId == null) {
+            IStatus status;
+            TargetModuleID[] ids;
+            
+            Map<String, String> artifactsMap = mapper.getServerArtifactsMap(getServer());
+            if (artifactsMap != null) {
+                synchronized (artifactsMap) {
+                    status = distribute(module, monitor);
+                    if (!status.isOK()) {
+                        doFail(status, Messages.DISTRIBUTE_FAIL);
+                    }
+
+                    ids = updateServerModuleConfigIDMap(module, status);
+                } 
+            } else {             
+                status = distribute(module, monitor);
+                if (!status.isOK()) {
+                    doFail(status, Messages.DISTRIBUTE_FAIL);
+                }
+
+                ids = updateServerModuleConfigIDMap(module, status);
+            }
+
+            status = start(ids, monitor);
+            if (!status.isOK()) {
+                doFail(status, Messages.START_FAIL);
+            } else {
+                setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
+            }
+        } else {
+            //either (1) a configuration with the same module id exists already on the server
+            //or (2) the module now has a different configId and the configuration on the server using
+            //the old id as specified in the project-configId map should be uninstalled.
+            doChanged(module, configId, monitor);
+        }
+        
+        Trace.tracePoint("Exit", Activator.traceCore, "DefaultModuleHandler.doAdded");
+    }
+    
+    public void doChanged(IModule module, IProgressMonitor monitor) throws Exception {
+        doChanged(module, null, monitor);
+    }
+    
+    public void doChanged(IModule module, String configId, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "DefaultModuleHandler.doChanged", module.getName(), configId);
+        
+        configId = getLastKnowConfigurationId(module, configId);
+        if(configId != null) {
+            String moduleConfigId = getConfigId(module);
+            if (moduleConfigId.equals(configId)) {
+                IStatus status = reDeploy(module, monitor);                
+                if (!status.isOK()) {
+                    doFail(status, Messages.REDEPLOY_FAIL);
+                } else {
+                    setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
+                }
+            } else {
+                //different configIds from what needs to be undeployed to what will be deployed
+                doRemoved(module, monitor);
+                doAdded(module, null, monitor);
+            }
+        } else {
+            //The checked configuration no longer exists on the server
+            doAdded(module, configId, monitor);
+        }
+        
+        Trace.tracePoint("Exit", Activator.traceCore, "DefaultModuleHandler.doChanged");
+    }
+    
+    public void doNoChange(IModule module, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "DefaultModuleHandler.doNoChange", module.getName());
+        
+        DeploymentManager dm = DeploymentCommandFactory.getDeploymentManager(getServer());
+        String configId = DeploymentUtils.getLastKnownConfigurationId(module, getServer());
+        if (configId != null) {
+            IModule[] rootModule = new IModule[] { module };
+            if (DeploymentUtils.isStartedModule(dm, configId) != null) {
+                setModuleState(rootModule, IServer.STATE_STARTED);
+            } else if (DeploymentUtils.isStoppedModule(dm, configId) != null) {
+                setModuleState(rootModule, IServer.STATE_STOPPED);
+            } else {
+                setModuleState(rootModule, IServer.STATE_UNKNOWN);
+            }
+            mapper.addArtifactEntry(getServer(), module, configId);
+        } else {
+            doAdded(module, null, monitor);
+        }
+        
+        Trace.tracePoint("Exit ", Activator.traceCore, "DefaultModuleHandler.doNoChange");
+    }
+    
+    public void doRemoved(IModule module, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "DefaultModuleHandler.doRemoved", module.getName());
+
+        Map<String, String> artifactsMap = mapper.getServerArtifactsMap(getServer());
+        if (artifactsMap != null) {
+            synchronized (artifactsMap) {
+                try {
+                    _doRemove(module, monitor);
+                } finally {
+                    // remove the mapping - even if module failed to undeploy
+                    mapper.removeArtifactEntry(getServer(), module);
+                }
+            }    
+        } else {
+            _doRemove(module, monitor);
+        }
+
+        Trace.tracePoint("Exit ", Activator.traceCore, "DefaultModuleHandler.doRemoved");
+    }
+    
+    public void doStartModule(IModule[] module, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "DefaultModuleHandler.doStartModule", Arrays.asList(module));
+        
+        start(module[0], monitor);
+
+        Trace.tracePoint("Exit ", Activator.traceCore, "DefaultModuleHandler.doStartModule");
+    }
+    
+    public void doStopModule(IModule[] module, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "DefaultModuleHandler.doStopModule", Arrays.asList(module));
+        
+        stop(module[0], monitor);
+
+        Trace.tracePoint("Exit ", Activator.traceCore, "DefaultModuleHandler.doStopModule");
+    }
+    
+    public void doRestartModule(IModule[] module, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "DefaultModuleHandler.doRestartModule", Arrays.asList(module));
+
+        stop(module[0], monitor);            
+        start(module[0], monitor);
+
+        Trace.tracePoint("Exit ", Activator.traceCore, "DefaultModuleHandler.doRestartModule");
+    }
+    
+    private void _doRemove(IModule module, IProgressMonitor monitor) throws Exception {
+        IStatus status = unDeploy(module, monitor);
+        if (!status.isOK()) {
+            doFail(status, Messages.UNDEPLOY_FAIL);
+        }
+    }
+    
+    protected IStatus distribute(IModule module, IProgressMonitor monitor) throws Exception {
+        IDeploymentCommand cmd = DeploymentCommandFactory.createDistributeCommand(module, getServer());
+        return cmd.execute(monitor);
+    }
+    
+    protected IStatus start(IModule module, IProgressMonitor monitor) throws Exception {
+        TargetModuleID id = DeploymentUtils.getTargetModuleID(getServer(), module);
+        IDeploymentCommand cmd = DeploymentCommandFactory.createStartCommand(new TargetModuleID[] { id }, module, getServer());
+        IStatus status = cmd.execute(monitor);
+        if (status.isOK()) {
+            setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
+        }
+        return status;
+    }
+    
+    protected IStatus start(TargetModuleID[] ids, IProgressMonitor monitor) throws Exception {
+        IDeploymentCommand cmd = DeploymentCommandFactory.createStartCommand(ids, null, getServer());
+        return cmd.execute(monitor);
+    }
+
+    protected IStatus stop(IModule module, IProgressMonitor monitor) throws Exception {
+        IDeploymentCommand cmd = DeploymentCommandFactory.createStopCommand(module, getServer());
+        IStatus status = cmd.execute(monitor);
+        if (status.isOK()) {
+            setModuleState(new IModule [] { module }, IServer.STATE_STOPPED);
+        }
+        return status;
+    }
+
+    protected IStatus unDeploy(IModule module, IProgressMonitor monitor) throws Exception {
+        IDeploymentCommand cmd = DeploymentCommandFactory.createUndeployCommand(module, getServer());
+        return cmd.execute(monitor);
+    }
+
+    protected IStatus reDeploy(IModule module, IProgressMonitor monitor) throws Exception {
+        IDeploymentCommand cmd = DeploymentCommandFactory.createRedeployCommand(module, getServer());
+        return cmd.execute(monitor);
+    }
+    
+    public String getConfigId(IModule module) throws Exception {
+        return serverDelegate.getConfigId(module);
+    }
+
+    private String getLastKnowConfigurationId(IModule module, String configId) throws Exception {
+        Trace.tracePoint("Entry ", Activator.traceCore, "GeronimoServerBehaviourDelegate.getLastKnowConfigurationId", module.getName(), configId);
+
+        //use the correct configId, second from the .metadata, then from the plan
+        configId = configId != null ? configId : DeploymentUtils.getLastKnownConfigurationId(module, getServer());
+
+        Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.getLastKnowConfigurationId", configId);
+        return configId;
+    }
+    
+    private TargetModuleID[] updateServerModuleConfigIDMap(IModule module, IStatus status) {
+        TargetModuleID[] ids = ((DeploymentCmdStatus) status).getResultTargetModuleIDs();        
+        mapper.addArtifactEntry(getServer(), module, ids[0].getModuleID());
+        return ids;
+    }
+    
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DefaultModuleHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DefaultModuleHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DefaultModuleHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviour.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviour.java?rev=1145251&r1=1145250&r2=1145251&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviour.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviour.java Mon Jul 11 17:38:40 2011
@@ -71,24 +71,18 @@ public class GeronimoServerBehaviour ext
     protected void stopKernel() {
     	try {
 			MBeanServerConnection connection = getServerConnection();
-	        Set<ObjectName> objectNameSet =
-	        	connection.queryNames(new ObjectName("osgi.core:type=framework,*"), null);
-	        if (objectNameSet.isEmpty()) {
-	            throw new Exception("Framework mbean not found");
-	        } else if (objectNameSet.size() == 1) {
-	            Trace.trace(Trace.INFO, "Server shutdown starting...", Activator.traceCore);
-	            Object obj = objectNameSet.iterator().next();
-	            connection.invoke((ObjectName) obj, "stopBundle",
-	                                      new Object[] { 0 }, new String[] { long.class.getName() });
-	            Trace.trace(Trace.INFO, "Server shutdown completed", Activator.traceCore);
-	        } else {
-	            throw new Exception("Found multiple framework mbeans");
-	        }
+			Trace.trace(Trace.INFO, "Server shutdown starting...", Activator.traceCore);
+			connection.invoke(getFrameworkMBean(connection), "stopBundle",
+                     new Object[] { 0 }, new String[] { long.class.getName() });
+			Trace.trace(Trace.INFO, "Server shutdown completed", Activator.traceCore);			
 		} catch (Exception e) {
-			// TODO Auto-generated catch block
 			Trace.trace(Trace.ERROR, e.getMessage(), e, Activator.traceCore);
 		}
     }
+    
+    private ObjectName getFrameworkMBean(MBeanServerConnection connection) throws Exception {
+        return getMBean(connection, "osgi.core:type=framework,*", "Framework");
+    }
 
     /**
      * @return

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java?rev=1145251&r1=1145250&r2=1145251&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java Mon Jul 11 17:38:40 2011
@@ -36,9 +36,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
-import javax.enterprise.deploy.spi.DeploymentManager;
 import javax.enterprise.deploy.spi.Target;
-import javax.enterprise.deploy.spi.TargetModuleID;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 import javax.management.remote.JMXConnector;
@@ -46,22 +44,17 @@ import javax.management.remote.JMXConnec
 import javax.management.remote.JMXServiceURL;
 
 import org.apache.geronimo.deployment.plugin.jmx.ExtendedDeploymentManager;
-import org.apache.geronimo.deployment.plugin.jmx.RemoteDeploymentManager;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.st.v30.core.UpdateServerStateTask;
-import org.apache.geronimo.st.v30.core.commands.DeploymentCmdStatus;
 import org.apache.geronimo.st.v30.core.commands.DeploymentCommandFactory;
-import org.apache.geronimo.st.v30.core.commands.IDeploymentCommand;
 import org.apache.geronimo.st.v30.core.internal.Messages;
 import org.apache.geronimo.st.v30.core.internal.Trace;
 import org.apache.geronimo.st.v30.core.operations.ISharedLibEntryCreationDataModelProperties;
 import org.apache.geronimo.st.v30.core.operations.SharedLibEntryCreationOperation;
 import org.apache.geronimo.st.v30.core.operations.SharedLibEntryDataModelProvider;
 import org.apache.geronimo.st.v30.core.osgi.AriesHelper;
-import org.apache.geronimo.st.v30.core.osgi.OSGIBundleCache;
-import org.apache.geronimo.st.v30.core.osgi.OSGIBundleHelper;
-import org.apache.geronimo.st.v30.core.osgi.OsgiConstants;
+import org.apache.geronimo.st.v30.core.osgi.OSGiModuleHandler;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
@@ -130,6 +123,9 @@ abstract public class GeronimoServerBeha
     private Lock publishLock = new ReentrantLock();
     
     private Set<IProject> knownSourceProjects = null; 
+    
+    private DefaultModuleHandler defaultModuleHandler;
+    private OSGiModuleHandler osgiModuleHandler;
 
     /*
      * (non-Javadoc)
@@ -644,8 +640,6 @@ abstract public class GeronimoServerBeha
      */
     public void publishModule(int kind, int deltaKind, IModule[] module, IProgressMonitor monitor) throws CoreException {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.publishModule", publishKindToString(kind), deltaKindToString(deltaKind), Arrays.asList(module), monitor);
-        /* remove the OSGI bundles which are removed */
-        this.removeObsoleteOSGIBundles();
         try {
             //NO_CHANGE need if app is associated but not started and no delta
             if (deltaKind == NO_CHANGE && module.length == 1) {
@@ -702,31 +696,6 @@ abstract public class GeronimoServerBeha
         }
     }
     
-    protected void removeObsoleteOSGIBundles() throws CoreException {
-        try {
-            Set<OSGIBundleCache.BundleInfo> bundles = OSGIBundleHelper.getSpecificServerBundles(getServer());
-            synchronized(bundles) {
-                Iterator<OSGIBundleCache.BundleInfo> iter = bundles.iterator();
-                while(iter.hasNext()) {
-                    OSGIBundleCache.BundleInfo bif = iter.next();
-                    if(bif.isDirty()) {
-                        long bundleId = OSGIBundleHelper.getOSGIBundleIdFromServer(getServer(), bif);
-                        if(bundleId == -1) {
-                            iter.remove();
-                            continue;
-                        }
-                        IStatus status = this.removeOSGIBundleById(bundleId);
-                        if(status.isOK()) {
-                            iter.remove();
-                        }
-                    }
-                }
-            }
-        } catch(Exception e) {
-            throw new CoreException(Status.CANCEL_STATUS);
-        }
-
-    }
     private void doPublishFinish(IProgressMonitor monitor) throws CoreException  {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.publishFinish", monitor);
 
@@ -768,6 +737,9 @@ abstract public class GeronimoServerBeha
         publishStateListener = new PublishStateListener();
         getServer().addServerListener(publishStateListener, ServerEvent.MODULE_CHANGE | ServerEvent.PUBLISH_STATE_CHANGE);
         
+        defaultModuleHandler = new DefaultModuleHandler(this);
+        osgiModuleHandler = new OSGiModuleHandler(this);
+        
         Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.initialize");
     }
 
@@ -831,13 +803,18 @@ abstract public class GeronimoServerBeha
     public void setServerStopped() {
         setServerState(IServer.STATE_STOPPED);
         resetModuleState();
+        if (defaultModuleHandler != null) {
+            defaultModuleHandler.serverStopped();
+        }
+        if (osgiModuleHandler != null) {
+            osgiModuleHandler.serverStopped();
+        }
     }
 
     public IGeronimoServer getGeronimoServer() {
         return (IGeronimoServer) getServer().loadAdapter(IGeronimoServer.class, null);
     }
 
-
     protected void terminate() {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.terminate");
 
@@ -886,29 +863,33 @@ abstract public class GeronimoServerBeha
         Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.resetModuleState");
     }
     
+    private AbstractModuleHandler getModuleHandler(IModule module) {
+        return (GeronimoUtils.isBundleModule(module) || GeronimoUtils.isFragmentBundleModule(module)) ? osgiModuleHandler : defaultModuleHandler;
+    }
+    
     protected void invokeCommand(int deltaKind, IModule module, IProgressMonitor monitor) throws CoreException {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.invokeCommand", deltaKindToString(deltaKind), module.getName());
+        AbstractModuleHandler moduleHandler = getModuleHandler(module);
         ClassLoader old = Thread.currentThread().getContextClassLoader();
-        System.out.println("haha");
         try {
             ClassLoader cl = getContextClassLoader();
             if (cl != null)
                 Thread.currentThread().setContextClassLoader(cl);
             switch (deltaKind) {
             case ADDED: {
-                doAdded(module, null, monitor);
+                moduleHandler.doAdded(module, monitor);
                 break;
             }
             case CHANGED: {
-                doChanged(module, null, monitor);
+                moduleHandler.doChanged(module, monitor);
                 break;
             }
             case REMOVED: {
-                doRemoved(module, monitor);
+                moduleHandler.doRemoved(module, monitor);
                 break;
             }
             case NO_CHANGE: {
-                doNoChange(module, monitor);
+                moduleHandler.doNoChange(module, monitor);
                 break;
             }
             default:
@@ -925,109 +906,6 @@ abstract public class GeronimoServerBeha
         Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.invokeCommand");
     }   
 
-    /**
-     * @param module
-     * @param configId the forced configId to process this method, passed in when this method is invoked from doChanged()
-     * @throws Exception
-     */
-    protected void doAdded(IModule module, String configId, IProgressMonitor monitor) throws Exception {
-        Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.doAdded", module.getName(), configId);
-        IStatus status;
-        TargetModuleID[] ids;
-        
-        if(OSGIBundleHelper.isBundle(module)) {
-            status = this.distributeOSGIBundles(module);
-            if(status.isOK()) {
-                /* Add the bundle info into the ModuleArtifactMapper's bundle cache */
-                OSGIBundleHelper.addBundleToCache(getServer(), module);
-                /* end here */
-                setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
-            } else {
-                doFail(status, Messages.DISTRIBUTE_FAIL);
-            }
-        } else {
-            configId = getLastKnowConfigurationId(module, configId);
-            if (configId == null) {
-                Map<String, String> artifactsMap = ModuleArtifactMapper.getInstance().getServerArtifactsMap(getServer());
-                if (artifactsMap != null) {
-                    synchronized (artifactsMap) {
-                        status = distribute(module, monitor);
-                        if (!status.isOK()) {
-                            doFail(status, Messages.DISTRIBUTE_FAIL);
-                        }
-
-                        ids = updateServerModuleConfigIDMap(module, status);
-                    } 
-                } else {             
-                    status = distribute(module, monitor);
-                    if (!status.isOK()) {
-                        doFail(status, Messages.DISTRIBUTE_FAIL);
-                    }
-
-                    ids = updateServerModuleConfigIDMap(module, status);
-                }
-
-                status = start(ids, monitor);
-                if (!status.isOK()) {
-                    doFail(status, Messages.START_FAIL);
-                } else {
-                    setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
-                }
-            } else {
-                //either (1) a configuration with the same module id exists already on the server
-                //or (2) the module now has a different configId and the configuration on the server using
-                //the old id as specified in the project-configId map should be uninstalled.
-                doChanged(module, configId, monitor);
-            }
-        }
-
-        Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.doAdded");
-    }
-    /**
-     * @param module
-     * @param configId the forced configId to process this method, passed in when invoked from doAdded()
-     * @throws Exception
-     */
-    protected void doChanged(IModule module, String configId, IProgressMonitor monitor) throws Exception {
-        Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.doChanged", module.getName(), configId);
-        IStatus status = null;
-        if(OSGIBundleHelper.isBundle(module)) {
-            boolean isPublished = OSGIBundleHelper.checkBundleInCache(getServer(), module);
-//            int state = DeploymentUtils.getModuleState(getServer(), module);
-            if(isPublished) status = doOSGIBundleRedeploy(module);
-            else {
-                status = this.distributeOSGIBundles(module);
-            }
-            if(status.isOK()) {
-                if(! isPublished) OSGIBundleHelper.addBundleToCache(getServer(), module);
-                setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
-            } else {
-                doFail(status, Messages.REDEPLOY_FAIL);
-            }
-        } else {
-            configId = getLastKnowConfigurationId(module, configId);
-            if(configId != null) {
-                String moduleConfigId = getConfigId(module);
-                if (moduleConfigId.equals(configId)) {
-                    status = reDeploy(module, monitor);                
-                    if (!status.isOK()) {
-                        doFail(status, Messages.REDEPLOY_FAIL);
-                    } else {
-                        setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
-                    }
-                } else {
-                    //different configIds from what needs to be undeployed to what will be deployed
-                    doRemoved(module, monitor);
-                    doAdded(module, null, monitor);
-                }
-            } else {
-                //The checked configuration no longer exists on the server
-                doAdded(module, configId, monitor);
-            }
-        }
-        Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.doChanged");
-    }
-
     private IStatus tryFileReplace(IModule[] module) {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace", module.toString());
         
@@ -1148,212 +1026,6 @@ abstract public class GeronimoServerBeha
         return Status.OK_STATUS;
     }
 
-
-    private String getLastKnowConfigurationId(IModule module, String configId) throws Exception {
-        Trace.tracePoint("Entry ", Activator.traceCore, "GeronimoServerBehaviourDelegate.getLastKnowConfigurationId", module.getName(), configId);
-
-        //use the correct configId, second from the .metadata, then from the plan
-        configId = configId != null ? configId : DeploymentUtils.getLastKnownConfigurationId(module, getServer());
-
-        Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.getLastKnowConfigurationId", configId);
-        return configId;
-    }
-
-    protected void doRemoved(IModule module, IProgressMonitor monitor) throws Exception {
-        Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.doRemoved", module.getName());
-
-        ModuleArtifactMapper mapper = ModuleArtifactMapper.getInstance();
-        Map<String, String> artifactsMap = mapper.getServerArtifactsMap(getServer());
-        if (artifactsMap != null) {
-            synchronized (artifactsMap) {
-                try {
-                    _doRemove(module, monitor);
-                } finally {
-                    // remove the mapping - even if module failed to undeploy
-                    mapper.removeArtifactEntry(getServer(), module);
-                }
-            }    
-        } else {
-            _doRemove(module, monitor);
-        }
-
-        Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.doRemoved");
-    }
-    
-    private void _doRemove(IModule module, IProgressMonitor monitor) throws Exception {
-    	IStatus status = null;
-    	if(OSGIBundleHelper.isBundle(module)) {/* If the module is a OSGI bundle */
-    		// must consider the situation of the project name or bundle name or both have been changed, not done yet!!!
-    		status = this.removeOSGIBundle(module);
-    		if(status.isOK()) {
-    			OSGIBundleHelper.removeBundleFromCache(getServer(), module);
-    		} else {
-    			doFail(status, Messages.DISTRIBUTE_FAIL);
-    		}
-    	} else {
-            status = unDeploy(module, monitor);
-            if (!status.isOK()) {
-                doFail(status, Messages.UNDEPLOY_FAIL);
-            }
-    	}
-    	
-
-    }
-    
-    protected void doNoChange(IModule module, IProgressMonitor monitor) throws Exception {
-        Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.doNoChange", module.getName());
-        if(! OSGIBundleHelper.isBundle(module)) {/* if the module is the bundle, just return! */
-            DeploymentManager dm = DeploymentCommandFactory.getDeploymentManager(getServer());
-            String configId = DeploymentUtils.getLastKnownConfigurationId(module, getServer());
-            if (configId != null) {
-                IModule[] rootModule = new IModule[] { module };
-                if (DeploymentUtils.isStartedModule(dm, configId) != null) {
-                    setModuleState(rootModule, IServer.STATE_STARTED);
-                } else if (DeploymentUtils.isStoppedModule(dm, configId) != null) {
-                    setModuleState(rootModule, IServer.STATE_STOPPED);
-                } else {
-                    setModuleState(rootModule, IServer.STATE_UNKNOWN);
-                }
-                ModuleArtifactMapper mapper = ModuleArtifactMapper.getInstance();
-                mapper.addArtifactEntry(getServer(), module, configId);
-            } else {
-                doAdded(module, null, monitor);
-            }
-        }
-        
-        Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.doNoChange");
-    }
-
-    protected void doRestart(IModule module, IProgressMonitor monitor) throws Exception {
-        Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.doRestart", module.getName());
-        
-        IStatus status = stop(module, monitor);
-        if (!status.isOK()) {
-            doFail(status, Messages.STOP_FAIL);
-        }
-
-        status = start(module, monitor);
-        if (!status.isOK()) {
-            doFail(status, Messages.START_FAIL);
-        }
-
-        Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.doRestart");
-    }
-    
-    private TargetModuleID[] updateServerModuleConfigIDMap(IModule module, IStatus status) {
-        TargetModuleID[] ids = ((DeploymentCmdStatus) status).getResultTargetModuleIDs();
-        ModuleArtifactMapper mapper = ModuleArtifactMapper.getInstance();
-        mapper.addArtifactEntry(getServer(), module, ids[0].getModuleID());
-        return ids;
-    }
-
-    protected void doFail(IStatus status, String message) throws CoreException {
-        MultiStatus ms = new MultiStatus(Activator.PLUGIN_ID, 0, message, null);
-        ms.addAll(status);
-        throw new CoreException(ms);
-    }
-
-    protected IStatus distribute(IModule module, IProgressMonitor monitor) throws Exception {
-        IDeploymentCommand cmd = DeploymentCommandFactory.createDistributeCommand(module, getServer());
-        return cmd.execute(monitor);
-    }
-    
-    protected IStatus doOSGIBundleRedeploy(IModule module) throws Exception {
-        IStatus status = Status.CANCEL_STATUS;
-        status = this.removeOSGIBundle(module);
-        if(status.isOK()) {
-            OSGIBundleHelper.removeBundleFromCache(getServer(), module);/* remove the bundle from cache */
-            /* install the bundle as a new one */
-            status = this.distributeOSGIBundles(module);
-            if(status.isOK()) {
-                /* Add the bundle info into the ModuleArtifactMapper's bundle cache */
-                OSGIBundleHelper.addBundleToCache(getServer(), module);
-                /* end here */
-            }
-        }
-        return status;
-    }
-    protected IStatus distributeOSGIBundles(IModule module) throws Exception {
-    	RemoteDeploymentManager rDm = (RemoteDeploymentManager)DeploymentCommandFactory.getDeploymentManager(this.getServer());
-        try {
-        	/* Get target file */
-            File f = DeploymentUtils.getTargetFile(getServer(), module);
-            if (f == null) {
-                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 
-                        Messages.bind(Messages.moduleExportError, module.getProject().getName())));     
-            }
-            /* end here */
-			long bundleId = rDm.recordInstall(f, null, OsgiConstants.BUNDLE_DEFAULT_START_LEVLE);
-			boolean ss = this._startBundle(bundleId);
-			if(ss) {
-				return Status.OK_STATUS;
-			} else {
-				Trace.trace(Trace.ERROR, "The Bundle: " + module.getName() + " could not be installed", null, Activator.logCore);
-				return Status.CANCEL_STATUS;
-			}
-		} catch (IOException e) {
-			Trace.trace(Trace.ERROR, "The Bundle: " + module.getName() + " could not be installed", e, Activator.logCore);
-			return Status.CANCEL_STATUS;
-		}
-    }
-    protected IStatus removeOSGIBundle(IModule module) throws Exception {
-        try {
-        	long bundleId = OSGIBundleHelper.getOSGIBundleIdFromServer(getServer(), module);
-        	if(bundleId == -1) return Status.OK_STATUS;// indicate the bundle has been removed from server
-			return this.removeOSGIBundleById(bundleId);
-		} catch (Exception e) {
-			Trace.trace(Trace.ERROR, "The Bundle: " + module.getName() + " could not be unInstalled", e, Activator.logCore);
-			return Status.CANCEL_STATUS;
-		}
-    }
-    
-    
-    protected IStatus removeOSGIBundleById(long bundleId) throws Exception {
-        try {
-            boolean isSuccess = this._unInstallBundle(bundleId);
-            if(isSuccess) {
-                return Status.OK_STATUS;
-            } else {
-                return Status.CANCEL_STATUS;
-            }
-        } catch (Exception e) {
-            return Status.CANCEL_STATUS;
-        }
-    }
-    protected IStatus start(IModule module, IProgressMonitor monitor) throws Exception {
-        TargetModuleID id = DeploymentUtils.getTargetModuleID(getServer(), module);
-        IDeploymentCommand cmd = DeploymentCommandFactory.createStartCommand(new TargetModuleID[] { id }, module, getServer());
-        IStatus status = cmd.execute(monitor);
-        if (status.isOK()) {
-            setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
-        }
-        return status;
-    }
-    
-    protected IStatus start(TargetModuleID[] ids, IProgressMonitor monitor) throws Exception {
-        IDeploymentCommand cmd = DeploymentCommandFactory.createStartCommand(ids, null, getServer());
-        return cmd.execute(monitor);
-    }
-
-    protected IStatus stop(IModule module, IProgressMonitor monitor) throws Exception {
-        IDeploymentCommand cmd = DeploymentCommandFactory.createStopCommand(module, getServer());
-        IStatus status = cmd.execute(monitor);
-        if (status.isOK()) {
-            setModuleState(new IModule [] { module }, IServer.STATE_STOPPED);
-        }
-        return status;
-    }
-
-    protected IStatus unDeploy(IModule module, IProgressMonitor monitor) throws Exception {
-        IDeploymentCommand cmd = DeploymentCommandFactory.createUndeployCommand(module, getServer());
-        return cmd.execute(monitor);
-    }
-
-    protected IStatus reDeploy(IModule module, IProgressMonitor monitor) throws Exception {
-        IDeploymentCommand cmd = DeploymentCommandFactory.createRedeployCommand(module, getServer());
-        return cmd.execute(monitor);
-    }
-
     public Map getServerInstanceProperties() {
         return getRuntimeDelegate().getServerInstanceProperties();
     }
@@ -1586,6 +1258,18 @@ abstract public class GeronimoServerBeha
         return null;
     }
     
+    public ObjectName getMBean(MBeanServerConnection connection, String mbeanName, String name) throws Exception {
+        Set<ObjectName> objectNameSet =
+            connection.queryNames(new ObjectName(mbeanName), null);
+        if (objectNameSet.isEmpty()) {
+            throw new Exception(Messages.bind(Messages.mBeanNotFound, name));
+        } else if (objectNameSet.size() == 1) {
+            return objectNameSet.iterator().next();
+        } else {
+            throw new Exception(Messages.bind(Messages.multipleMBeansFound, name));
+        }
+    }
+    
     public Target[] getTargets() {
         return null;
     }
@@ -1639,14 +1323,7 @@ abstract public class GeronimoServerBeha
     public void startModule(IModule[] module, IProgressMonitor monitor) {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.startModule", Arrays.asList(module));
         try {
-            if(OSGIBundleHelper.isBundle(module[0])) {
-                boolean isIn = OSGIBundleHelper.checkBundleInCache(getServer(), module[0]);
-                int state = DeploymentUtils.getModuleState(getServer(), module[0]);
-                if(isIn && (state == IServer.STATE_STOPPED)) startOSGIBundle(module[0]);
-                else throw new Exception(Messages.START_FAIL);
-            } else {
-                start(module[0], monitor);
-            }
+            getModuleHandler(module[0]).doStartModule(module, monitor);
         } catch (Exception e) {
             Trace.trace(Trace.ERROR, "Error starting module " + module[0].getName(), e, Activator.logCore);
             throw new RuntimeException("Error starting module " + module[0].getName(), e);
@@ -1654,42 +1331,11 @@ abstract public class GeronimoServerBeha
         Trace.tracePoint("Exit ", Activator.traceCore, "GeronimoServerBehaviourDelegate.startModule");
     }
     
-    protected void startOSGIBundle(IModule module) throws Exception {
-       
-        long bundleId = OSGIBundleHelper.getOSGIBundleIdFromServer(getServer(), module);
-        if(bundleId == -1) throw new Exception("can not start bundle");
-        boolean ss = this._startBundle(bundleId);
-        if(ss) {
-            setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
-        } else {
-            throw new Exception("can not start bundle");
-        }
-    }
-    protected void stopOSGIBundle(IModule module) throws Exception {
-        long bundleId = OSGIBundleHelper.getOSGIBundleIdFromServer(getServer(), module);
-        if(bundleId == -1) throw new Exception("can not stop bundle");
-        boolean ss = this._stopBundle(bundleId);
-        if(ss) {
-            setModuleState(new IModule [] { module }, IServer.STATE_STOPPED);
-        } else {
-            throw new Exception("can not start bundle");
-        }   
-    }
     @Override
     public void stopModule(IModule[] module, IProgressMonitor monitor) {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.stopModule", Arrays.asList(module));
         try {
-            if(OSGIBundleHelper.isBundle(module[0])) {
-                boolean isIn = OSGIBundleHelper.checkBundleInCache(getServer(), module[0]);
-                int state = DeploymentUtils.getModuleState(getServer(), module[0]);
-                if(! isIn || state == IServer.STATE_UNKNOWN) doFail(Status.CANCEL_STATUS, Messages.DISTRIBUTE_FAIL);
-                else {
-                    this.stopOSGIBundle(module[0]);
-                }
-            } else {
-                stop(module[0], monitor);
-            }
-            
+            getModuleHandler(module[0]).doStopModule(module, monitor);
         } catch (Exception e) {
             Trace.trace(Trace.ERROR, "Error stopping module " + module[0].getName(), e, Activator.logCore);
             throw new RuntimeException("Error stopping module " + module[0].getName(), e);
@@ -1701,20 +1347,7 @@ abstract public class GeronimoServerBeha
     public void restartModule(IModule[] module, IProgressMonitor monitor) {
         Trace.tracePoint("Entry", Activator.traceCore, "GeronimoServerBehaviourDelegate.restartModule", Arrays.asList(module));
         try {
-            if(OSGIBundleHelper.isBundle(module[0])) {
-                boolean isIn = OSGIBundleHelper.checkBundleInCache(getServer(), module[0]);
-                int state = DeploymentUtils.getModuleState(getServer(), module[0]);
-                if(isIn && (state == IServer.STATE_STARTED)) {
-                    this.stopOSGIBundle(module[0]);
-                    this.startOSGIBundle(module[0]);
-                } else {
-                    doFail(Status.CANCEL_STATUS, Messages.RESTART_OSGIBUNDLE_FAIL);
-                }
-            } else {
-                stop(module[0], monitor);            
-                start(module[0], monitor);
-            }
-            
+            getModuleHandler(module[0]).doRestartModule(module, monitor);
         } catch (Exception e) {
             Trace.trace(Trace.ERROR, "Error restarting module " + module[0].getName(), e, Activator.logCore);
             throw new RuntimeException("Error restarting module " + module[0].getName(), e);
@@ -1741,54 +1374,4 @@ abstract public class GeronimoServerBeha
     public void setModulesState(IModule[] module, int state) {
         setModuleState(module, state);
     }
-    private boolean _startBundle(long bundleId) {
-    	try {
-    		MBeanServerConnection connection = getServerConnection();
-    		connection.invoke(getFramework(), "startBundle",
-                    new Object[] { bundleId }, new String[] { long.class.getName() });
-    		return true;
-    	} catch(Exception e) {
-    		Trace.trace(Trace.INFO, "Could not start bundle", Activator.traceCore);
-    		return false;
-    	}
-        
-    }
-    private boolean _stopBundle(long bundleId) {
-    	try {
-    		MBeanServerConnection connection = getServerConnection();
-    		connection.invoke(getFramework(), "stopBundle",
-                    new Object[] { bundleId }, new String[] { long.class.getName() });
-    		return true;
-    	} catch(Exception e) {
-    		Trace.trace(Trace.INFO, "Could not stop bundle", Activator.traceCore);
-    		return false;
-    	}
-    }
-    private boolean _unInstallBundle(long bundleId) throws CoreException {
-        RemoteDeploymentManager rDm = (RemoteDeploymentManager)DeploymentCommandFactory.getDeploymentManager(this.getServer());
-    	try {
-    		rDm.eraseUninstall(bundleId);
-    		return true;
-    	} catch(Exception e) {
-    		Trace.trace(Trace.INFO, e.getMessage(), Activator.traceCore);
-    		return false;
-    	}
-    }
-    public ObjectName getFramework() throws Exception {
-    	try {
-			MBeanServerConnection connection = getServerConnection();
-	        Set<ObjectName> objectNameSet =
-	        	connection.queryNames(new ObjectName("osgi.core:type=framework,*"), null);
-	        if (objectNameSet.isEmpty()) {
-	        	throw new Exception(Messages.frameworkMBeanNotFound);
-	        } else if (objectNameSet.size() == 1) {
-	        	return objectNameSet.iterator().next();
-	        } else {
-	        	throw new Exception(Messages.multipleFramworkMBeans);
-	        }
-		} catch (Exception e) {
-			throw e;
-		}
-    }
-    
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.java?rev=1145251&r1=1145250&r2=1145251&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.java Mon Jul 11 17:38:40 2011
@@ -17,7 +17,6 @@
 package org.apache.geronimo.st.v30.core;
 
 import java.io.InputStream;
-import java.lang.reflect.Method;
 import java.util.jar.Manifest;
 
 import javax.enterprise.deploy.shared.ModuleType;
@@ -32,7 +31,6 @@ import org.apache.geronimo.jee.web.WebAp
 import org.apache.geronimo.st.v30.core.internal.Trace;
 import org.apache.geronimo.st.v30.core.jaxb.JAXBUtils;
 import org.apache.geronimo.st.v30.core.osgi.AriesHelper;
-import org.apache.geronimo.st.v30.core.osgi.OSGIBundleHelper;
 import org.apache.geronimo.st.v30.core.osgi.OsgiConstants;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
@@ -45,11 +43,6 @@ import org.eclipse.wst.common.componentc
 import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants;
 import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
 import org.eclipse.wst.server.core.IModule;
-import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.internal.ModuleFactory;
-import org.eclipse.wst.server.core.internal.ServerPlugin;
-import org.osgi.framework.Version;
-
 
 /**
  * @version $Rev$ $Date$
@@ -203,29 +196,15 @@ public class GeronimoUtils {
         if (AriesHelper.isAriesInstalled()) {
             try {
                 if (isEBAModule(module)) {
-                    Class<?> ariesUtilsClass = Class.forName("com.ibm.etools.aries.internal.core.utils.AriesUtils");
-                    Method method = ariesUtilsClass.getMethod("getApplicationManifest", IProject.class);
-                    Object object = method.invoke(null, module.getProject());
-
-                    Class<?> appManifestClass = Class.forName("com.ibm.etools.aries.core.models.ApplicationManifest");
-                    method = appManifestClass.getMethod("getApplicationSymbolicName");
-                    String artifactID = (String) method.invoke(object);
-
-                    method = appManifestClass.getMethod("getApplicationVersion");
-                    String versionStr = (String) method.invoke(object);
-                    Version version = Version.parseVersion(versionStr);
-                    String newVersionStr = getVersion(version);
-
-                    if (artifactID != null && version != null) {
-                        String id = getQualifiedConfigID(OsgiConstants.ARTIFACT_GROUP, artifactID, newVersionStr, OsgiConstants.ARTIFACT_TYPE);
+                    AriesHelper.BundleInfo appInfo = AriesHelper.getApplicationBundleInfo(module.getProject());
+                    if (appInfo != null) {
+                        String id = getQualifiedConfigID(OsgiConstants.APPLICATION_ARTIFACT_GROUP, appInfo.getSymbolicName(), appInfo.getMvnVersion(), OsgiConstants.APPLICATION_ARTIFACT_TYPE);
                         Trace.tracePoint("EXIT", Activator.traceCore, "GeronimoUtils.getConfigId", id);
                         return id;
                     }
                 }
-                if(isBundleModule(module)) {
-                    return OSGIBundleHelper.getBundleSymbolicNameAndVersionString(module.getProject());  
-                }
             } catch (Exception e) {
+                // ignore
             }
         }
 
@@ -234,16 +213,6 @@ public class GeronimoUtils {
         return id;
     }
     
-    // copied from org.apache.geronimo.aries.builder.ApplicationInstaller.getVersion(Version)
-    public static String getVersion(Version version) {
-        String str = version.getMajor() + "." + version.getMinor() + "." + version.getMicro();
-        String qualifier = version.getQualifier();
-        if (qualifier != null && qualifier.trim().length() > 0) {
-            str += "-" + version.getQualifier().trim();
-        }
-        return str;
-    }
-    
     public static String getQualifiedConfigID(String groupId, String artifactId, String version, String type) {
         return groupId + "/" + artifactId + "/" + version + "/" + type;
     }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java?rev=1145251&r1=1145250&r2=1145251&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/ModuleArtifactMapper.java Mon Jul 11 17:38:40 2011
@@ -72,6 +72,7 @@ public class ModuleArtifactMapper {
             artifactEntries.put(getId(module), configId); 
         }       
     }
+    
     synchronized public void removeArtifactEntry(IServer server, IModule module) {
         Map<String, String> artifactEntries = getServerArtifactsMap(server);
         if (artifactEntries != null) {
@@ -151,10 +152,10 @@ public class ModuleArtifactMapper {
             }
         }
     }
+    
     synchronized private void load() {
         load(serverArtifactEntries, FILE_NAME);
     }
-    
 
 	protected interface IServerEntries {
         public  void loadXML (String xml);

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.java?rev=1145251&r1=1145250&r2=1145251&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.java Mon Jul 11 17:38:40 2011
@@ -78,7 +78,7 @@ public class Messages extends NLS {
     public static String moduleExportError;
     
     public static String serverStopFailed;
-    public static String frameworkMBeanNotFound;
-    public static String multipleFramworkMBeans;
+    public static String mBeanNotFound;
+    public static String multipleMBeansFound;
     
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.properties
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.properties?rev=1145251&r1=1145250&r2=1145251&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.properties (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/internal/Messages.properties Mon Jul 11 17:38:40 2011
@@ -63,5 +63,5 @@ moduleModified=Modified
 moduleExportError=Module {0} failed to export.
 
 serverStopFailed=Error stopping server.
-frameworkMBeanNotFound=Framework mbean not found.
-multipleFramworkMBeans=Found multiple framework mbeans.
+mBeanNotFound={0} mbean not found.
+multipleMBeansFound=Found multiple {0} mbeans.

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/AriesHelper.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/AriesHelper.java?rev=1145251&r1=1145250&r2=1145251&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/AriesHelper.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/AriesHelper.java Mon Jul 11 17:38:40 2011
@@ -20,11 +20,13 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 
 import org.apache.geronimo.st.v30.core.Activator;
+import org.apache.geronimo.st.v30.core.GeronimoUtils;
 import org.apache.geronimo.st.v30.core.internal.Trace;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.wst.server.core.IModule;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
 
 /**
  * <b>AriesHelper</b> is a static helper class used to encapsulate the functions related to the installation of the 
@@ -88,4 +90,78 @@ public final class AriesHelper {
         return null;
     }
 
+    public static BundleInfo getBundleInfo(IProject project) throws Exception {
+        if (AriesHelper.isAriesInstalled()) {
+            Class<?> ariesUtilsClass = Class.forName("com.ibm.etools.aries.internal.core.utils.AriesUtils");
+            Method method = ariesUtilsClass.getMethod("getBlueprintBundleManifest", IProject.class);
+            Object object = method.invoke(null, project);
+
+            Class<?> bundleManifest = Class.forName("com.ibm.etools.aries.core.models.BundleManifest");
+            method = bundleManifest.getMethod("getBundleSymbolicName");
+            String symbolicName = (String) method.invoke(object);
+
+            method = bundleManifest.getMethod("getBundleVersion");
+            String versionStr = (String) method.invoke(object);
+            Version version = Version.parseVersion(versionStr);
+
+            if (symbolicName != null && version != null) {
+                return new BundleInfo(symbolicName, version);
+            }
+        }
+        return null;
+    }
+    
+    public static BundleInfo getApplicationBundleInfo(IProject project) throws Exception {
+        if (AriesHelper.isAriesInstalled()) {
+            Class<?> ariesUtilsClass = Class.forName("com.ibm.etools.aries.internal.core.utils.AriesUtils");
+            Method method = ariesUtilsClass.getMethod("getApplicationManifest", IProject.class);
+            Object object = method.invoke(null, project);
+
+            Class<?> appManifestClass = Class.forName("com.ibm.etools.aries.core.models.ApplicationManifest");
+            method = appManifestClass.getMethod("getApplicationSymbolicName");
+            String symbolicName = (String) method.invoke(object);
+
+            method = appManifestClass.getMethod("getApplicationVersion");
+            String versionStr = (String) method.invoke(object);
+            Version version = Version.parseVersion(versionStr);
+            
+            if (symbolicName != null && version != null) {
+                return new BundleInfo(symbolicName, version);
+            }
+        }
+        return null;
+    }
+    
+    // copied from org.apache.geronimo.aries.builder.ApplicationInstaller.getVersion(Version)
+    public static String toMvnVersion(Version version) {
+        String str = version.getMajor() + "." + version.getMinor() + "." + version.getMicro();
+        String qualifier = version.getQualifier();
+        if (qualifier != null && qualifier.trim().length() > 0) {
+            str += "-" + version.getQualifier().trim();
+        }
+        return str;
+    }
+    
+    public static class BundleInfo {
+        
+        private final String symbolicName;
+        private final Version version;
+        
+        public BundleInfo(String symbolicName, Version version) {
+            this.symbolicName = symbolicName;
+            this.version = version;
+        }
+        
+        public String getSymbolicName() {
+            return symbolicName;
+        }
+        
+        public Version getVersion() {
+            return version;
+        }
+            
+        public String getMvnVersion() {
+            return toMvnVersion(version);
+        }
+    }
 }

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java?rev=1145251&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java Mon Jul 11 17:38:40 2011
@@ -0,0 +1,279 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.st.v30.core.osgi;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import org.apache.geronimo.deployment.plugin.jmx.RemoteDeploymentManager;
+import org.apache.geronimo.st.v30.core.AbstractModuleHandler;
+import org.apache.geronimo.st.v30.core.Activator;
+import org.apache.geronimo.st.v30.core.DeploymentUtils;
+import org.apache.geronimo.st.v30.core.GeronimoServerBehaviourDelegate;
+import org.apache.geronimo.st.v30.core.GeronimoUtils;
+import org.apache.geronimo.st.v30.core.commands.DeploymentCommandFactory;
+import org.apache.geronimo.st.v30.core.internal.Messages;
+import org.apache.geronimo.st.v30.core.internal.Trace;
+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.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+
+public class OSGiModuleHandler extends AbstractModuleHandler {
+    
+    private Map<String, Long> bundleMap;
+    
+    public OSGiModuleHandler(GeronimoServerBehaviourDelegate serverDelegate) {
+        super(serverDelegate);
+        bundleMap = Collections.synchronizedMap(new HashMap<String, Long>());
+    }
+
+    @Override
+    public void serverStopped() {
+        bundleMap.clear();
+    }
+    
+    private long getBundleId(IModule module) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "OSGiBundleHandler.getBundleId", module);
+        Long id = bundleMap.get(module.getId());
+        if (id == null && module.getProject() != null) {
+            RemoteDeploymentManager dm = (RemoteDeploymentManager) DeploymentCommandFactory.getDeploymentManager(this.getServer());
+            AriesHelper.BundleInfo bundleInfo = AriesHelper.getBundleInfo(module.getProject());
+            id = dm.getBundleId(bundleInfo.getSymbolicName(), bundleInfo.getVersion().toString());
+            if (id != -1) {
+                bundleMap.put(module.getId(), id);
+            }
+        }
+        Trace.tracePoint("Exit", Activator.traceCore, "OSGiBundleHandler.getBundleId", id);
+        return id;
+    }
+    
+    public void doAdded(IModule module, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "OSGiBundleHandler.doAdded", module.getName());
+        
+        long bundleId = getBundleId(module);
+        if (bundleId == -1) {
+            IStatus status = distributeBundle(module);
+            if (!status.isOK()) {
+                doFail(status, Messages.DISTRIBUTE_FAIL);
+            }
+            
+            bundleId = getBundleId(module);
+            if (GeronimoUtils.isFragmentBundleModule(module)) {
+                setModuleState(new IModule [] { module }, IServer.STATE_STOPPED);
+            } else {
+                startBundle(bundleId, module);
+            }
+        } else {
+            doChanged(module, monitor);
+        }
+                
+        Trace.tracePoint("Exit", Activator.traceCore, "OSGiBundleHandler.doAdded", bundleId);
+    }
+    
+    public void doChanged(IModule module, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "OSGiBundleHandler.doChanged", module.getName());
+        
+        long bundleId = getBundleId(module);
+        if (bundleId != -1) {
+            doRemoved(module, monitor);
+        }
+        
+        doAdded(module, monitor);       
+
+        Trace.tracePoint("Exit", Activator.traceCore, "OSGiBundleHandler.doChanged", bundleId);
+    }
+    
+    public void doNoChange(IModule module, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "OSGiBundleHandler.doNoChange", module.getName());
+        
+        long bundleId = getBundleId(module);
+        if (bundleId != -1) {
+            try {
+                String state = getBundleState(bundleId);
+                if ("active".equalsIgnoreCase(state)) {
+                    setModuleState(new IModule [] {module}, IServer.STATE_STARTED);
+                } else if ("resolved".equalsIgnoreCase(state)) {
+                    setModuleState(new IModule [] {module}, IServer.STATE_STOPPED);
+                } else {
+                    setModuleState(new IModule [] {module}, IServer.STATE_UNKNOWN);
+                }
+            } catch (Exception e) {
+                setModuleState(new IModule [] {module}, IServer.STATE_UNKNOWN);
+            }
+        } else {
+            doAdded(module, monitor);
+        }
+        
+        Trace.tracePoint("Exit ", Activator.traceCore, "OSGiBundleHandler.doNoChange", bundleId);
+    }
+    
+    public void doRemoved(IModule module, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "OSGiBundleHandler.doRemoved", module.getName());
+
+        long bundleId = getBundleId(module);
+        if (bundleId != -1) {
+            IStatus status = _unInstallBundle(bundleId);
+            bundleMap.remove(module.getId());
+            if (!status.isOK()) {
+                doFail(status, Messages.UNDEPLOY_FAIL);
+            }
+        }
+
+        Trace.tracePoint("Exit ", Activator.traceCore, "OSGiBundleHandler.doRemoved", bundleId);
+    }
+    
+    public void doStartModule(IModule[] module, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "OSGiBundleHandler.doStartModule", Arrays.asList(module));
+        
+        long bundleId = getBundleId(module[0]);
+        if (bundleId != -1) {
+            startBundle(bundleId, module[0]);
+        } else {
+            throw new Exception(Messages.START_FAIL);
+        }
+        
+        Trace.tracePoint("Exit ", Activator.traceCore, "OSGiBundleHandler.doStartModule");
+    }
+    
+    public void doStopModule(IModule[] module, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "OSGiBundleHandler.doStopModule", Arrays.asList(module));
+        
+        long bundleId = getBundleId(module[0]);
+        if (bundleId != -1) {
+            stopBundle(bundleId, module[0]);
+        } else {
+            throw new Exception(Messages.STOP_FAIL);
+        }
+
+        Trace.tracePoint("Exit ", Activator.traceCore, "OSGiBundleHandler.doStopModule");
+    }
+    
+    public void doRestartModule(IModule[] module, IProgressMonitor monitor) throws Exception {
+        Trace.tracePoint("Entry", Activator.traceCore, "OSGiBundleHandler.doRestartModule", Arrays.asList(module));
+
+        long bundleId = getBundleId(module[0]);
+        if (bundleId != -1) {
+            stopBundle(bundleId, module[0]);
+            startBundle(bundleId, module[0]);
+        } else {
+            throw new Exception(Messages.RESTART_OSGIBUNDLE_FAIL);
+        }
+
+        Trace.tracePoint("Exit ", Activator.traceCore, "OSGiBundleHandler.doRestartModule");
+    }
+        
+    private IStatus distributeBundle(IModule module) throws Exception {
+        RemoteDeploymentManager rDm = (RemoteDeploymentManager)DeploymentCommandFactory.getDeploymentManager(this.getServer());
+        try {
+            /* Get target file */
+            File f = DeploymentUtils.getTargetFile(getServer(), module);
+            if (f == null) {
+                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 
+                        Messages.bind(Messages.moduleExportError, module.getProject().getName())));     
+            }
+            /* end here */
+            long bundleId = rDm.recordInstall(f, null, OsgiConstants.BUNDLE_DEFAULT_START_LEVEL);
+            
+            bundleMap.put(module.getId(), bundleId);
+            
+            return Status.OK_STATUS;
+        } catch (Exception e) {
+            Trace.trace(Trace.ERROR, "Error installing " + module.getName() + " bundle", e, Activator.logCore);
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error installing " + module.getName() + " bundle", e);
+        }
+    }
+     
+    private void startBundle(long bundleId, IModule module) throws CoreException {
+        IStatus status = _startBundle(bundleId);            
+        if (!status.isOK()) {
+            doFail(status, Messages.START_FAIL);
+        } else {
+            setModuleState(new IModule [] { module }, IServer.STATE_STARTED);
+        }
+    }
+    
+    private void stopBundle(long bundleId, IModule module) throws CoreException {
+        IStatus status = _stopBundle(bundleId);            
+        if (!status.isOK()) {
+            doFail(status, Messages.STOP_FAIL);
+        } else {
+            setModuleState(new IModule [] { module }, IServer.STATE_STOPPED);
+        }
+    }
+    
+    private IStatus _startBundle(long bundleId) {
+        try {
+            MBeanServerConnection connection = getServerConnection();
+            connection.invoke(getFrameworkMBean(connection), "startBundle",
+                    new Object[] { bundleId }, new String[] { long.class.getName() });
+            return Status.OK_STATUS;
+        } catch(Exception e) {
+            Trace.trace(Trace.ERROR, "Error starting bundle " + bundleId, e, Activator.logCore);
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not start bundle", e);
+        }        
+    }
+    
+    private IStatus _stopBundle(long bundleId) {
+        try {
+            MBeanServerConnection connection = getServerConnection();
+            connection.invoke(getFrameworkMBean(connection), "stopBundle",
+                    new Object[] { bundleId }, new String[] { long.class.getName() });
+            return Status.OK_STATUS;
+        } catch(Exception e) {
+            Trace.trace(Trace.ERROR, "Error stopping bundle " + bundleId, e, Activator.logCore);
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not stop bundle", e);
+        }
+    }
+    
+    private String getBundleState(long bundleId) throws Exception {
+        MBeanServerConnection connection = getServerConnection();
+        return (String) connection.invoke(getBundleStateMBean(connection), "getState",
+                new Object[] { bundleId }, new String[] { long.class.getName() });
+    }
+    
+    private IStatus _unInstallBundle(long bundleId) throws CoreException {
+        RemoteDeploymentManager rDm = (RemoteDeploymentManager)DeploymentCommandFactory.getDeploymentManager(this.getServer());
+        try {
+            rDm.eraseUninstall(bundleId);
+            return Status.OK_STATUS;
+        } catch(Exception e) {
+            Trace.trace(Trace.ERROR, "Error uninstalling bundle", e, Activator.logCore);
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error uninstalling bundle", e);
+        }
+    }
+    
+    private ObjectName getFrameworkMBean(MBeanServerConnection connection) throws Exception {
+        return serverDelegate.getMBean(connection, "osgi.core:type=framework,*", "Framework");
+    }
+    
+    private ObjectName getBundleStateMBean(MBeanServerConnection connection) throws Exception {
+        return serverDelegate.getMBean(connection, "osgi.core:type=bundleState,*", "BundleState");
+    }
+    
+    private MBeanServerConnection getServerConnection() throws Exception {
+        return serverDelegate.getServerConnection();
+    }
+}

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OSGiModuleHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OsgiConstants.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OsgiConstants.java?rev=1145251&r1=1145250&r2=1145251&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OsgiConstants.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/osgi/OsgiConstants.java Mon Jul 11 17:38:40 2011
@@ -21,13 +21,11 @@ public final class OsgiConstants {
     public final static String APPLICATION = "osgi.app"; 
     public final static String APPLICATION_EXTENSION = ".eba"; 
     public final static String APPLICATION_DATAMODEL_PROVIDER_ID = "osgi.application.datamodelprovider";
-    public final static String JAR_TYPE = "jar";
 
     public final static String BUNDLE = "osgi.bundle"; 
-    public final static String BUNDLE_GROUP = "recorded-bundles";
     public final static String BUNDLE_EXTENSION = ".jar";
     public final static String BUNDLE_DATAMODEL_PROVIDER_ID = "osgi.bundle.datamodelprovider";
-    public final static int BUNDLE_DEFAULT_START_LEVLE = 60;
+    public final static int BUNDLE_DEFAULT_START_LEVEL = 60;
     
     public final static String FRAGMENT_BUNDLE = "osgi.fragment"; 
     public final static String FRAGMENT_BUNDLE_EXTENSION = ".jar"; 
@@ -37,7 +35,7 @@ public final class OsgiConstants {
     public final static String COMPOSITE_BUNDLE_EXTENSION = ".cba";  
     public final static String COMPOSITE_BUNDLE_DATAMODEL_PROVIDER_ID = "osgi.composite.datamodelprovider";
     
-    public final static String ARTIFACT_GROUP = "application";    
-    public final static String ARTIFACT_TYPE = "eba";
+    public final static String APPLICATION_ARTIFACT_GROUP = "application";    
+    public final static String APPLICATION_ARTIFACT_TYPE = "eba";
     
 }



Mime
View raw message