1 22 23 package org.jboss.spring.deployment; 24 25 import java.io.File ; 26 import java.net.URL ; 27 import javax.management.MBeanServer ; 28 import javax.management.MalformedObjectNameException ; 29 import javax.management.ObjectName ; 30 31 import org.jboss.deployment.DeploymentException; 32 import org.jboss.deployment.DeploymentInfo; 33 import org.jboss.deployment.SubDeployer; 34 import org.jboss.deployment.SubDeployerSupport; 35 import org.jboss.spring.factory.BeanFactoryLoader; 36 37 41 public abstract class SpringDeployer extends SubDeployerSupport implements 42 SubDeployer, SpringDeployerMBean 43 { 44 45 protected abstract BeanFactoryLoader createBeanFactoryLoader(); 46 47 private BeanFactoryLoader beanFactoryLoader = createBeanFactoryLoader(); 48 49 54 public SpringDeployer() 55 { 56 initializeMainDeployer(); 57 } 58 59 protected void initializeMainDeployer() 60 { 61 setSuffixes(new String []{".spring", "-spring.xml"}); 62 setRelativeOrder(350); } 64 65 71 public boolean accepts(DeploymentInfo di) 72 { 73 String urlStr = di.url.toString(); 74 return urlStr.endsWith(".spring") || urlStr.endsWith(".spring/") || 75 urlStr.endsWith("-spring.xml"); 76 } 77 78 85 public void init(DeploymentInfo di) throws DeploymentException 86 { 87 try 88 { 89 if (di.watch == null) 90 { 91 if (di.url.getProtocol().equals("file")) 93 { 94 File file = new File (di.url.getFile()); 95 if (!file.isDirectory()) 97 { 98 di.watch = di.url; 99 } 100 else 102 { 103 di.watch = new URL (di.url, "META-INF/jboss-spring.xml"); 104 } 105 } 106 else 107 { 108 di.watch = di.url; 110 } 111 } 112 } 113 catch (Exception e) 114 { 115 log.error("failed to parse Spring context document: ", e); 116 throw new DeploymentException(e); 117 } 118 super.init(di); 119 } 120 121 128 public void create(DeploymentInfo di) throws DeploymentException 129 { 130 try 131 { 132 beanFactoryLoader.create(di); 133 emitNotification("Spring Deploy", di); 134 log.info("Deployed Spring: " + di.url); 135 } 136 catch (Exception e) 137 { 138 throw new DeploymentException(e); 139 } 140 } 141 142 149 public void start(DeploymentInfo di) throws DeploymentException 150 { 151 beanFactoryLoader.start(di); 152 } 153 154 165 public void stop(DeploymentInfo di) 166 { 167 log.info("Undeploying Spring: " + di.url); 168 try 169 { 170 beanFactoryLoader.stop(di); 171 emitNotification("Spring Undeploy", di); 172 } 173 catch (Exception e) 174 { 175 log.error("Failed to stop bean factory: " + di.url); 176 } 177 } 178 179 185 public void destroy(DeploymentInfo di) 186 { 187 try 188 { 189 beanFactoryLoader.destroy(di); 190 emitNotification("Spring Destroy", di); 191 } 192 catch (DeploymentException e) 193 { 194 log.error("Failed to destroy deployer: " + di); 195 } 196 } 197 198 protected ObjectName getObjectName(MBeanServer server, ObjectName name) 199 throws MalformedObjectNameException 200 { 201 return name == null ? getDefaultObjectName() : name; 202 } 203 204 protected abstract ObjectName getDefaultObjectName(); 205 206 } 207 | Popular Tags |