KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > beans > metadata > plugins > AbstractInstallMetaData


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.beans.metadata.plugins;
23
24 import org.jboss.beans.metadata.spi.InstallMetaData;
25 import org.jboss.beans.metadata.spi.MetaDataVisitor;
26 import org.jboss.dependency.plugins.AbstractDependencyItem;
27 import org.jboss.dependency.spi.ControllerState;
28 import org.jboss.dependency.spi.DependencyItem;
29 import org.jboss.dependency.spi.ControllerContext;
30 import org.jboss.kernel.spi.dependency.KernelControllerContext;
31 import org.jboss.kernel.spi.dependency.KernelController;
32 import org.jboss.kernel.spi.config.KernelConfigurator;
33 import org.jboss.util.JBossStringBuilder;
34 import org.jboss.reflect.spi.ClassInfo;
35
36 /**
37  * Metadata for installation.
38  *
39  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
40  * @version $Revision: 57133 $
41  */

42 public class AbstractInstallMetaData extends AbstractLifecycleMetaData implements InstallMetaData
43 {
44    /** The bean name */
45    protected String JavaDoc bean;
46
47    /** The required state of the dependency or null to look in the registry */
48    protected ControllerState dependentState = ControllerState.INSTALLED;
49
50    /**
51     * Create a new install meta data
52     */

53    public AbstractInstallMetaData()
54    {
55       setState(ControllerState.INSTALLED);
56    }
57
58    public String JavaDoc getBean()
59    {
60       return bean;
61    }
62
63    /**
64     * Set the bean
65     *
66     * @param bean the bean
67     */

68    public void setBean(String JavaDoc bean)
69    {
70       this.bean = bean;
71    }
72
73    /**
74     * Set the required state of the dependency
75     *
76     * @param dependentState the required state or null if it must be in the registry
77     */

78    public void setDependentState(ControllerState dependentState)
79    {
80       this.dependentState = dependentState;
81       flushJBossObjectCache();
82    }
83
84    public ControllerState getDependentState()
85    {
86       return dependentState;
87    }
88
89    public void initialVisit(MetaDataVisitor visitor)
90    {
91       KernelControllerContext context = visitor.getControllerContext();
92       if (bean != null)
93       {
94          DependencyItem item = new InstallationDependencyItem(context.getName());
95          visitor.addDependency(item);
96       }
97       super.initialVisit(visitor);
98    }
99
100    protected ClassInfo getClassInfo(KernelControllerContext context) throws Throwable JavaDoc
101    {
102       if (bean != null)
103       {
104          KernelController controller = (KernelController) context.getController();
105          ControllerContext beanContext = controller.getContext(bean, ControllerState.INSTANTIATED);
106          if (beanContext != null)
107          {
108             KernelConfigurator configurator = controller.getKernel().getConfigurator();
109             Object JavaDoc target = beanContext.getTarget();
110             return configurator.getClassInfo(target.getClass());
111          }
112          else
113          {
114             throw new IllegalArgumentException JavaDoc("Cannot determine install bean class: " + this);
115          }
116       }
117       return super.getClassInfo(context);
118    }
119
120    public void toString(JBossStringBuilder buffer)
121    {
122       if (bean != null)
123          buffer.append("bean=").append(bean);
124       if (dependentState != ControllerState.INSTALLED);
125          buffer.append(" dependentState=" + dependentState);
126       buffer.append(" ");
127       super.toString(buffer);
128    }
129
130    public void toShortString(JBossStringBuilder buffer)
131    {
132       if (bean != null)
133          buffer.append(bean);
134       if (methodName != null)
135          buffer.append(".").append(methodName);
136    }
137
138    /**
139     * An InstallationDependencyItem.
140     */

141    public class InstallationDependencyItem extends AbstractDependencyItem
142    {
143       /**
144        * Create a new InstallationDependencyItem.
145        *
146        * @param name the name
147        */

148       public InstallationDependencyItem(Object JavaDoc name)
149       {
150          super(name, bean, state, dependentState);
151       }
152    }
153 }
154
Popular Tags