1 17 18 package org.apache.geronimo.deployment.mavenplugin; 19 20 import java.io.IOException ; 21 import java.io.File ; 22 import java.net.URL ; 23 import java.net.URLClassLoader ; 24 25 import javax.enterprise.deploy.spi.DeploymentManager ; 26 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException ; 27 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager ; 28 29 import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl; 30 31 37 public abstract class AbstractModuleCommand { 38 private String uri; 39 private String username; 40 private String password; 41 42 public String getUri() { 43 return uri; 44 } 45 46 public void setUri(String uri) { 47 this.uri = uri; 48 } 49 50 public String getUsername() { 51 return username; 52 } 53 54 public void setUsername(String username) { 55 this.username = username; 56 } 57 58 public String getPassword() { 59 return password; 60 } 61 62 public void setPassword(String password) { 63 this.password = password; 64 } 65 66 public abstract void execute() throws Exception ; 67 68 protected DeploymentManager getDeploymentManager() throws IOException , DeploymentManagerCreationException { 69 if (getUsername() == null) { 70 throw new IllegalStateException ("No user specified"); 71 } 72 if (getPassword() == null) { 73 throw new IllegalStateException ("No password specified"); 74 } 75 if (getUri() == null) { 76 throw new IllegalStateException ("No uri specified"); 77 } 78 new DeploymentFactoryImpl(); 79 80 ClassLoader oldcl = Thread.currentThread().getContextClassLoader(); 81 try { 82 Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); 83 DeploymentFactoryManager factoryManager = DeploymentFactoryManager.getInstance(); 84 DeploymentManager manager = factoryManager.getDeploymentManager(getUri(), getUsername(), getPassword()); 85 return manager; 86 } finally { 87 Thread.currentThread().setContextClassLoader(oldcl); 88 } 89 } 90 } 91 | Popular Tags |