KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > kernel > plugins > deployment > xml > BeanXMLDeployer


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.kernel.plugins.deployment.xml;
23
24 import java.io.InputStream JavaDoc;
25 import java.net.URL JavaDoc;
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 /**
37  * An XML deployer.
38  *
39  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
40  * @author <a HREF="mailto:les.hazlewood@jboss.org">Les A. Hazlewood</a>
41  * @author <a HREF="mailto:marc.fleury@jboss.com">Marc Fleury</a>
42  * @version $Revision: 57133 $
43  */

44 public class BeanXMLDeployer extends AbstractKernelDeployer
45 {
46    /** The log */
47    private static final Logger log = Logger.getLogger(BeanXMLDeployer.class);
48
49    /** Unmarshaller factory */
50    private static final UnmarshallerFactory factory = UnmarshallerFactory.newInstance();
51    
52    /** The resolver */
53    private static final SchemaBindingResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
54
55    /**
56     * Create a new XML kernel deployer
57     *
58     * @param kernel the kernel
59     * @throws Throwable for any error
60     */

61    public BeanXMLDeployer(Kernel kernel) throws Throwable JavaDoc
62    {
63       super(kernel);
64    }
65
66    /**
67     * Deploy a url
68     *
69     * @param url the url to deploy
70     * @return the kernel deployment
71     * @throws Throwable for any error
72     */

73    public KernelDeployment deploy(final URL JavaDoc url) throws Throwable JavaDoc
74    {
75       final boolean trace = log.isTraceEnabled();
76
77       if (url == null)
78          throw new IllegalArgumentException JavaDoc("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 JavaDoc("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    /**
108     * Deploy a stream. We may be deploying XML fragments.
109     *
110     * @param deploymentName the deployment name
111     * @param stream the stream
112     * @return the kernel deployment
113     * @throws Throwable for any error
114     */

115    public KernelDeployment deploy(String JavaDoc deploymentName, final InputStream JavaDoc stream) throws Throwable JavaDoc
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 JavaDoc("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