KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.List JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import org.jboss.beans.metadata.spi.LifecycleMetaData;
28 import org.jboss.beans.metadata.spi.MetaDataVisitor;
29 import org.jboss.beans.metadata.spi.MetaDataVisitorNode;
30 import org.jboss.beans.metadata.spi.ParameterMetaData;
31 import org.jboss.dependency.spi.ControllerState;
32 import org.jboss.kernel.plugins.config.Configurator;
33 import org.jboss.kernel.spi.dependency.KernelControllerContext;
34 import org.jboss.reflect.spi.ClassInfo;
35 import org.jboss.reflect.spi.MethodInfo;
36 import org.jboss.util.JBossObject;
37 import org.jboss.util.JBossStringBuilder;
38
39 /**
40  * Metadata for lifecycle.
41  *
42  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
43  * @version $Revision: 56022 $
44  */

45 public class AbstractLifecycleMetaData extends AbstractFeatureMetaData implements LifecycleMetaData
46 {
47    /** The state */
48    protected ControllerState state;
49
50    /** The method name */
51    protected String JavaDoc methodName;
52
53    /** The paramaters List<ParameterMetaData> */
54    protected List JavaDoc<ParameterMetaData> parameters;
55
56    /** The type - create, start, stop, destroy, install */
57    protected String JavaDoc type;
58
59    /**
60     * Create a new lifecycle meta data
61     */

62    public AbstractLifecycleMetaData()
63    {
64    }
65
66    public ControllerState getState()
67    {
68       return state;
69    }
70
71    public void setState(ControllerState state)
72    {
73       this.state = state;
74    }
75
76    public String JavaDoc getMethodName()
77    {
78       return methodName;
79    }
80
81    /**
82     * Set the method name
83     *
84     * @param name the factory method
85     */

86    public void setMethodName(String JavaDoc name)
87    {
88       this.methodName = name;
89       flushJBossObjectCache();
90    }
91
92    public List JavaDoc<ParameterMetaData> getParameters()
93    {
94       return parameters;
95    }
96
97    /**
98     * Set the parameters
99     *
100     * @param parameters List<ParameterMetaData>
101     */

102    public void setParameters(List JavaDoc<ParameterMetaData> parameters)
103    {
104       this.parameters = parameters;
105       flushJBossObjectCache();
106    }
107
108    public String JavaDoc getType()
109    {
110       return type;
111    }
112
113    public void setType(String JavaDoc type)
114    {
115       this.type = type;
116    }
117
118    public void initialVisit(MetaDataVisitor visitor)
119    {
120       visitor.setContextState(state);
121       super.initialVisit(visitor);
122    }
123
124    protected void addChildren(Set JavaDoc<MetaDataVisitorNode> children)
125    {
126       super.addChildren(children);
127       if (parameters != null)
128          children.addAll(parameters);
129    }
130
131    public Class JavaDoc getType(MetaDataVisitor visitor, MetaDataVisitorNode previous) throws Throwable JavaDoc
132    {
133       ParameterMetaData parameter = (ParameterMetaData) previous;
134       KernelControllerContext context = visitor.getControllerContext();
135       String JavaDoc method = (methodName != null ? methodName : type);
136       String JavaDoc[] parameterTypes = Configurator.getParameterTypes(false, parameters);
137       MethodInfo methodInfo = Configurator.findMethodInfo(getClassInfo(context), method, parameterTypes);
138       return applyCollectionOrMapCheck(methodInfo.getParameterTypes()[parameter.getIndex()].getType());
139    }
140
141    protected ClassInfo getClassInfo(KernelControllerContext context) throws Throwable JavaDoc
142    {
143       return context.getBeanInfo().getClassInfo();
144    }
145
146    public void toString(JBossStringBuilder buffer)
147    {
148       if (methodName != null)
149          buffer.append("method=").append(methodName);
150       buffer.append(" parameters=");
151       JBossObject.list(buffer, parameters);
152       buffer.append(" ");
153       super.toString(buffer);
154    }
155
156    public void toShortString(JBossStringBuilder buffer)
157    {
158       buffer.append(methodName);
159    }
160 }
161
Popular Tags