KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > kernel > plugins > dependency > InstallAction


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.dependency;
23
24 import java.util.List JavaDoc;
25
26 import org.jboss.beans.info.spi.BeanInfo;
27 import org.jboss.beans.metadata.spi.BeanMetaData;
28 import org.jboss.beans.metadata.spi.InstallMetaData;
29 import org.jboss.beans.metadata.spi.ParameterMetaData;
30 import org.jboss.joinpoint.spi.MethodJoinpoint;
31 import org.jboss.kernel.Kernel;
32 import org.jboss.kernel.plugins.config.Configurator;
33 import org.jboss.kernel.spi.config.KernelConfigurator;
34 import org.jboss.kernel.spi.dependency.KernelController;
35 import org.jboss.kernel.spi.dependency.KernelControllerContext;
36 import org.jboss.kernel.spi.registry.KernelRegistry;
37
38 /**
39  * InstallAction.
40  *
41  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
42  * @version $Revision: 46187 $
43  */

44 public class InstallAction extends KernelControllerContextAction
45 {
46    public void installAction(KernelControllerContext context) throws Throwable JavaDoc
47    {
48       KernelController controller = (KernelController) context.getController();
49       Kernel kernel = controller.getKernel();
50       KernelRegistry registry = kernel.getRegistry();
51
52       BeanMetaData metaData = context.getBeanMetaData();
53       Object JavaDoc name = metaData.getName();
54       registry.registerEntry(name, context);
55       controller.addSupplies(context);
56       
57       List JavaDoc installs = metaData.getInstalls();
58       if (installs != null)
59       {
60          for (int i = 0; i < installs.size(); ++i)
61          {
62             InstallMetaData install = (InstallMetaData) installs.get(i);
63             KernelControllerContext target = context;
64             if (install.getBean() != null)
65                target = (KernelControllerContext) controller.getContext(install.getBean(), install.getDependentState());
66             dispatch(target, install.getMethodName(), install.getParameters());
67          }
68       }
69    }
70    
71    public void uninstallAction(KernelControllerContext context)
72    {
73       KernelController controller = (KernelController) context.getController();
74       Kernel kernel = controller.getKernel();
75       KernelRegistry registry = kernel.getRegistry();
76       BeanMetaData metaData = context.getBeanMetaData();
77       Object JavaDoc name = metaData.getName();
78       
79       List JavaDoc uninstalls = metaData.getUninstalls();
80       if (uninstalls != null)
81       {
82          for (int i = uninstalls.size()-1; i >= 0; --i)
83          {
84             InstallMetaData uninstall = (InstallMetaData) uninstalls.get(i);
85             KernelControllerContext target = context;
86             if (uninstall.getBean() != null)
87             {
88                target = (KernelControllerContext) controller.getContext(uninstall.getBean(), uninstall.getDependentState());
89                if (target == null)
90                {
91                   log.warn("Ignoring uninstall action on target in incorrect state " + uninstall.getBean());
92                   continue;
93                }
94             }
95             try
96             {
97                dispatch(target, uninstall.getMethodName(), uninstall.getParameters());
98             }
99             catch (Throwable JavaDoc t)
100             {
101                log.warn("Ignoring uninstall action on target " + uninstall, t);
102                continue;
103             }
104          }
105       }
106
107       try
108       {
109          controller.removeSupplies(context);
110          registry.unregisterEntry(name);
111       }
112       catch (Throwable JavaDoc t)
113       {
114          log.warn("Ignoring unregistered entry at uninstall " + name);
115       }
116    }
117    
118    protected void dispatch(KernelControllerContext context, String JavaDoc method, List JavaDoc<ParameterMetaData> parameters) throws Throwable JavaDoc
119    {
120       KernelController controller = (KernelController) context.getController();
121       KernelConfigurator configurator = controller.getKernel().getConfigurator();
122       BeanInfo info = context.getBeanInfo();
123       BeanMetaData metaData = context.getBeanMetaData();
124       ClassLoader JavaDoc cl = Configurator.getClassLoader(metaData);
125       MethodJoinpoint joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters, false, true);
126       joinpoint.setTarget(context.getTarget());
127       dispatchJoinPoint(context, joinpoint);
128    }
129 }
Popular Tags