1 22 package org.jboss.kernel.plugins.deployment.xml; 23 24 import java.io.InputStream ; 25 import java.net.URL ; 26 27 import org.jboss.kernel.Kernel; 28 import org.jboss.kernel.plugins.deployment.AbstractKernelDeployer; 29 import org.jboss.kernel.spi.deployment.KernelDeployment; 30 import org.jboss.logging.Logger; 31 import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory; 32 import org.jboss.xb.binding.Unmarshaller; 33 import org.jboss.xb.binding.UnmarshallerFactory; 34 import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver; 35 36 44 public class BeanXMLDeployer extends AbstractKernelDeployer 45 { 46 47 private static final Logger log = Logger.getLogger(BeanXMLDeployer.class); 48 49 50 private static final UnmarshallerFactory factory = UnmarshallerFactory.newInstance(); 51 52 53 private static final SchemaBindingResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver(); 54 55 61 public BeanXMLDeployer(Kernel kernel) throws Throwable 62 { 63 super(kernel); 64 } 65 66 73 public KernelDeployment deploy(final URL url) throws Throwable 74 { 75 final boolean trace = log.isTraceEnabled(); 76 77 if (url == null) 78 throw new IllegalArgumentException ("Null url"); 79 80 if (trace) 81 log.trace("Parsing " + url); 82 83 long start = System.currentTimeMillis(); 84 85 Unmarshaller unmarshaller = factory.newUnmarshaller(); 86 KernelDeployment deployment = (KernelDeployment) unmarshaller.unmarshal(url.toString(), resolver); 87 if (deployment == null) 88 throw new RuntimeException ("The xml " + url + " is not well formed!"); 89 deployment.setName(url.toString()); 90 91 long now = System.currentTimeMillis(); 92 log.debug("Parsing " + url + " took " + (now -start) + " milliseconds"); 93 94 if (trace) 95 log.trace("Deploying " + deployment); 96 deploy(deployment); 97 98 now = System.currentTimeMillis(); 99 log.debug("Deploying " + url + " took " + (now -start) + " milliseconds"); 100 101 if (trace) 102 log.trace("Deployed " + deployment.getInstalledContexts()); 103 104 return deployment; 105 } 106 107 115 public KernelDeployment deploy(String deploymentName, final InputStream stream) throws Throwable 116 { 117 boolean trace = log.isTraceEnabled(); 118 119 if (trace) 120 log.trace("Parsing " + deploymentName); 121 Unmarshaller unmarshaller = factory.newUnmarshaller(); 122 KernelDeployment deployment = (KernelDeployment) unmarshaller.unmarshal(stream, resolver); 123 if (deployment == null) 124 throw new RuntimeException ("The deployment " + deploymentName + " is not well formed!"); 125 deployment.setName(deploymentName); 126 127 if (trace) 128 log.trace("Deploying " + deployment); 129 deploy(deployment); 130 if (trace) 131 log.trace("Deployed " + deployment.getInstalledContexts()); 132 133 return deployment; 134 } 135 } 136 | Popular Tags |