KickJava   Java API By Example, From Geeks To Geeks.

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


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.Iterator JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import org.jboss.beans.info.spi.BeanInfo;
28 import org.jboss.beans.metadata.spi.BeanMetaData;
29 import org.jboss.joinpoint.spi.TargettedJoinpoint;
30 import org.jboss.kernel.Kernel;
31 import org.jboss.kernel.spi.config.KernelConfigurator;
32 import org.jboss.kernel.spi.dependency.KernelController;
33 import org.jboss.kernel.spi.dependency.KernelControllerContext;
34 import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
35
36 /**
37  * ConfigureAction.
38  *
39  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
40  * @version $Revision: 58411 $
41  */

42 public class ConfigureAction extends KernelControllerContextAction
43 {
44    public void installAction(KernelControllerContext context) throws Throwable JavaDoc
45    {
46       KernelController controller = (KernelController) context.getController();
47       Kernel kernel = controller.getKernel();
48       KernelConfigurator configurator = kernel.getConfigurator();
49
50       Object JavaDoc object = context.getTarget();
51       BeanInfo info = context.getBeanInfo();
52       BeanMetaData metaData = context.getBeanMetaData();
53       Set JavaDoc joinPoints = configurator.getPropertySetterJoinPoints(info, metaData);
54       setAttributes(context, object, joinPoints, false);
55       
56       if (object instanceof KernelControllerContextAware)
57          ((KernelControllerContextAware) object).setKernelControllerContext(context);
58
59    }
60
61    public void uninstallAction(KernelControllerContext context)
62    {
63       KernelController controller = (KernelController) context.getController();
64       Kernel kernel = controller.getKernel();
65       KernelConfigurator configurator = kernel.getConfigurator();
66
67       Object JavaDoc object = context.getTarget();
68
69       try
70       {
71          if (object != null)
72          {
73             if (object instanceof KernelControllerContextAware)
74                ((KernelControllerContextAware) object).unsetKernelControllerContext(context);
75          }
76       }
77       catch (Throwable JavaDoc ignored)
78       {
79          log.debug("Ignored error unsetting context ", ignored);
80       }
81       
82       
83       BeanInfo info = context.getBeanInfo();
84       BeanMetaData metaData = context.getBeanMetaData();
85       try
86       {
87          Set JavaDoc joinPoints = configurator.getPropertyNullerJoinPoints(info, metaData);
88          setAttributes(context, object, joinPoints, true);
89       }
90       catch (Throwable JavaDoc t)
91       {
92          log.warn("Error unconfiguring bean " + context, t);
93       }
94    }
95
96    /**
97     * Set the attributes
98     *
99     * @param context the context
100     * @param target the target
101     * @param joinPoints the attribute setter joinpoints
102     * @param ignoreErrors whether to ignore errors
103     * @throws Throwable for any unignored error
104     */

105    protected void setAttributes(KernelControllerContext context, Object JavaDoc target, Set JavaDoc joinPoints, boolean ignoreErrors) throws Throwable JavaDoc
106    {
107       if (joinPoints.isEmpty() == false)
108       {
109          boolean trace = log.isTraceEnabled();
110
111          for (Iterator JavaDoc i = joinPoints.iterator(); i.hasNext();)
112          {
113             TargettedJoinpoint joinPoint = (TargettedJoinpoint) i.next();
114             joinPoint.setTarget(target);
115             try
116             {
117                dispatchJoinPoint(context, joinPoint);
118             }
119             catch (Throwable JavaDoc t)
120             {
121                if (ignoreErrors)
122                {
123                   if (trace)
124                      log.trace("Ignored for " + joinPoint, t);
125                }
126                else
127                {
128                   throw t;
129                }
130             }
131          }
132       }
133    }
134
135 }
Popular Tags