KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployers > plugins > deployers > kernel > KernelDeploymentDeployer


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, 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.deployers.plugins.deployers.kernel;
23
24 import java.util.List JavaDoc;
25
26 import org.jboss.beans.metadata.spi.BeanMetaData;
27 import org.jboss.deployers.plugins.deployers.helpers.AbstractComponentDeployer;
28 import org.jboss.deployers.plugins.deployers.helpers.SimpleDeploymentVisitor;
29 import org.jboss.deployers.spi.DeploymentException;
30 import org.jboss.deployers.spi.deployer.DeploymentUnit;
31 import org.jboss.kernel.spi.deployment.KernelDeployment;
32
33 public class KernelDeploymentDeployer extends AbstractComponentDeployer<KernelDeployment, BeanMetaData>
34 {
35    /**
36     * Create a new KernelDeploymentDeployer.
37     */

38    public KernelDeploymentDeployer()
39    {
40       setDeploymentVisitor(new KernelDeploymentVisitor());
41       setComponentVisitor(new BeanMetaDataVisitor());
42    }
43
44    protected static void addBeanComponent(DeploymentUnit unit, BeanMetaData bean)
45    {
46       DeploymentUnit component = unit.addComponent(bean.getName());
47       component.addAttachment(BeanMetaData.class.getName(), bean);
48    }
49
50    protected static void removeBeanComponent(DeploymentUnit unit, BeanMetaData bean)
51    {
52       unit.removeComponent(bean.getName());
53    }
54    
55    /**
56     * KernelDeploymentVisitor.
57     */

58    public static class KernelDeploymentVisitor implements SimpleDeploymentVisitor<KernelDeployment>
59    {
60       public Class JavaDoc<KernelDeployment> getVisitorType()
61       {
62          return KernelDeployment.class;
63       }
64
65       public void deploy(DeploymentUnit unit, KernelDeployment deployment) throws DeploymentException
66       {
67          List JavaDoc<BeanMetaData> beans = deployment.getBeans();
68          for (BeanMetaData bean : beans)
69             addBeanComponent(unit, bean);
70       }
71
72       public void undeploy(DeploymentUnit unit, KernelDeployment deployment)
73       {
74          List JavaDoc<BeanMetaData> beans = deployment.getBeans();
75          for (BeanMetaData bean : beans)
76             removeBeanComponent(unit, bean);
77       }
78    }
79
80    /**
81     * BeanMetaDataVisitor.
82     */

83    public static class BeanMetaDataVisitor implements SimpleDeploymentVisitor<BeanMetaData>
84    {
85       public Class JavaDoc<BeanMetaData> getVisitorType()
86       {
87          return BeanMetaData.class;
88       }
89
90       public void deploy(DeploymentUnit unit, BeanMetaData deployment) throws DeploymentException
91       {
92          addBeanComponent(unit, deployment);
93       }
94
95       public void undeploy(DeploymentUnit unit, BeanMetaData deployment)
96       {
97          removeBeanComponent(unit, deployment);
98       }
99    }
100 }
101
Popular Tags