1 22 package org.jboss.kernel.plugins.deployment.xml; 23 24 import java.io.InputStream ; 25 import java.net.URL ; 26 import java.util.Collection ; 27 import java.util.Map ; 28 29 import org.jboss.kernel.Kernel; 30 import org.jboss.kernel.plugins.deployment.BasicKernelDeployer; 31 import org.jboss.kernel.spi.deployment.KernelDeployment; 32 import org.jboss.logging.Logger; 33 import org.jboss.util.collection.CollectionsFactory; 34 import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory; 35 import org.jboss.xb.binding.Unmarshaller; 36 import org.jboss.xb.binding.UnmarshallerFactory; 37 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver; 38 39 45 public class BasicXMLDeployer extends BasicKernelDeployer 46 { 47 48 private static final Logger log = Logger.getLogger(BasicXMLDeployer.class); 49 50 51 private static final UnmarshallerFactory factory = UnmarshallerFactory.newInstance(); 52 53 54 private static final SchemaBindingResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver(); 55 56 57 private Map <String , KernelDeployment> deploymentsByName = CollectionsFactory.createConcurrentReaderMap(); 58 59 64 public BasicXMLDeployer(Kernel kernel) 65 { 66 super(kernel); 67 } 68 69 public Collection getDeploymentNames() 70 { 71 return deploymentsByName.keySet(); 72 } 73 74 public void deploy(KernelDeployment deployment) throws Throwable 75 { 76 super.deploy(deployment); 77 deploymentsByName.put(deployment.getName(), deployment); 78 } 79 80 public void undeploy(KernelDeployment deployment) 81 { 82 deploymentsByName.remove(deployment.getName()); 83 super.undeploy(deployment); 84 } 85 86 92 public void undeploy(final URL url) 93 { 94 if (url == null) 95 throw new IllegalArgumentException ("Null url"); 96 undeploy(url.toString()); 97 } 98 99 105 public void undeploy(final String name) 106 { 107 if (name == null) 108 throw new IllegalArgumentException ("Null name"); 109 KernelDeployment deployment = deploymentsByName.remove(name); 110 if (deployment == null) 111 throw new IllegalStateException ("Unknown deployment " + name); 112 undeploy(deployment); 113 } 114 115 122 public KernelDeployment deploy(final URL url) throws Throwable 123 { 124 final boolean trace = log.isTraceEnabled(); 125 126 if (url == null) 127 throw new IllegalArgumentException ("Null url"); 128 129 if (trace) 130 log.trace("Parsing " + url); 131 132 long start = System.currentTimeMillis(); 133 134 Unmarshaller unmarshaller = factory.newUnmarshaller(); 135 KernelDeployment deployment = (KernelDeployment) unmarshaller.unmarshal(url.toString(), resolver); 136 if (deployment == null) 137 throw new RuntimeException ("The xml " + url + " is not well formed!"); 138 deployment.setName(url.toString()); 139 140 if (trace) 141 { 142 long now = System.currentTimeMillis(); 143 log.trace("Parsing " + url + " took " + (now-start) + " milliseconds"); 144 } 145 146 deploy(deployment); 147 148 if (trace) 149 { 150 long now = System.currentTimeMillis(); 151 log.trace("Deploying " + url + " took " + (now-start) + " milliseconds"); 152 } 153 154 return deployment; 155 } 156 157 165 public KernelDeployment deploy(String deploymentName, final InputStream stream) throws Throwable 166 { 167 boolean trace = log.isTraceEnabled(); 168 169 if (trace) 170 log.trace("Parsing " + deploymentName); 171 Unmarshaller unmarshaller = factory.newUnmarshaller(); 172 KernelDeployment deployment = (KernelDeployment) unmarshaller.unmarshal(stream, resolver); 173 if (deployment == null) 174 throw new RuntimeException ("The deployment " + deploymentName + " is not well formed!"); 175 deployment.setName(deploymentName); 176 177 deploy(deployment); 178 179 return deployment; 180 } 181 } 182 | Popular Tags |