KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > system > metadata > ServiceDependencyValueMetaData


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.system.metadata;
23
24 import javax.management.MBeanAttributeInfo JavaDoc;
25 import javax.management.MBeanServer JavaDoc;
26 import javax.management.MalformedObjectNameException JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28
29 import org.jboss.dependency.spi.ControllerState;
30 import org.jboss.deployment.DeploymentException;
31 import org.jboss.mx.util.MBeanProxyExt;
32 import org.jboss.system.microcontainer.LifecycleDependencyItem;
33 import org.jboss.system.microcontainer.ServiceControllerContext;
34
35 /**
36  * ServiceDependencyValueMetaData.
37  *
38  * This class is based on the old ServiceConfigurator
39  *
40  * @author <a HREF="mailto:marc@jboss.org">Marc Fleury</a>
41  * @author <a HREF="mailto:hiram@jboss.org">Hiram Chirino</a>
42  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
43  * @author <a HREF="mailto:jason@planet57.com">Jason Dillon</a>
44  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
45  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
46  * @version $Revision: 1.1 $
47  */

48 public class ServiceDependencyValueMetaData extends AbstractMetaDataVisitorNode implements ServiceValueMetaData
49 {
50    /** The dependency */
51    private String JavaDoc dependency;
52
53    /** The dependency */
54    private ObjectName JavaDoc objectName;
55
56    /** The proxy type */
57    private String JavaDoc proxyType;
58    
59    /**
60     * Create a new ServiceDependencyValueMetaData.
61     */

62    public ServiceDependencyValueMetaData()
63    {
64    }
65    
66    /**
67     * Create a new ServiceDependencyValueMetaData.
68     *
69     * @param dependency the dependents object name
70     */

71    public ServiceDependencyValueMetaData(String JavaDoc dependency)
72    {
73       setDependency(dependency);
74    }
75    
76    /**
77     * Create a new ServiceDependencyValueMetaData.
78     *
79     * @param dependency the dependents object name
80     * @param proxyType the proxy type
81     */

82    public ServiceDependencyValueMetaData(String JavaDoc dependency, String JavaDoc proxyType)
83    {
84       setDependency(dependency);
85       setProxyType(proxyType);
86    }
87
88    /**
89     * Get the dependency.
90     *
91     * @return the dependency.
92     */

93    public String JavaDoc getDependency()
94    {
95       if (dependency == null)
96          return objectName.getCanonicalName();
97       return dependency;
98    }
99
100    /**
101     * Set the dependency.
102     *
103     * @param dependency the dependency.
104     */

105    public void setDependency(String JavaDoc dependency)
106    {
107       if (dependency == null)
108          throw new IllegalArgumentException JavaDoc("Null dependency");
109       this.dependency = dependency;
110       this.objectName = null;
111    }
112
113    /**
114     * Get the object name.
115     *
116     * @return the object name.
117     * @throws MalformedObjectNameException if the string was set with an invalid object name
118     */

119    public ObjectName JavaDoc getObjectName() throws MalformedObjectNameException JavaDoc
120    {
121       if (objectName == null)
122       {
123          if (dependency.trim().length() == 0)
124             throw new MalformedObjectNameException JavaDoc("Missing object name in depends");
125          ObjectName JavaDoc name = new ObjectName JavaDoc(dependency);
126          if (name.isPattern())
127             throw new MalformedObjectNameException JavaDoc("ObjectName patterns are not allowed in depends: " + objectName);
128          objectName = new ObjectName JavaDoc(dependency);
129          dependency = null;
130       }
131       return objectName;
132    }
133
134    /**
135     * Set the object name
136     *
137     * @param objectName the object name
138     */

139    public void setObjectName(ObjectName JavaDoc objectName)
140    {
141       if (objectName == null)
142          throw new IllegalArgumentException JavaDoc("Null objectName");
143       this.objectName = objectName;
144    }
145
146    /**
147     * Get the proxyType.
148     *
149     * @return the proxyType.
150     */

151    public String JavaDoc getProxyType()
152    {
153       return proxyType;
154    }
155
156    /**
157     * Set the proxyType.
158     *
159     * @param proxyType the proxyType.
160     */

161    public void setProxyType(String JavaDoc proxyType)
162    {
163       this.proxyType = proxyType;
164    }
165
166    public Object JavaDoc getValue(ServiceValueContext valueContext) throws Exception JavaDoc
167    {
168       MBeanAttributeInfo JavaDoc attributeInfo = valueContext.getAttributeInfo();
169       ClassLoader JavaDoc cl = valueContext.getClassloader();
170       MBeanServer JavaDoc server = valueContext.getServer();
171
172       ObjectName JavaDoc objectName = getObjectName();
173       
174       if (proxyType != null)
175       {
176          if (proxyType.equals("attribute"))
177          {
178             proxyType = attributeInfo.getType();
179             if (proxyType == null)
180                throw new DeploymentException("AttributeInfo for " + attributeInfo.getName() + " has no type");
181          }
182
183          Class JavaDoc proxyClass = cl.loadClass(proxyType);
184          return MBeanProxyExt.create(proxyClass, objectName, server, true);
185       }
186       
187       return objectName;
188    }
189
190    public void visit(ServiceMetaDataVisitor visitor)
191    {
192       ServiceControllerContext context = visitor.getControllerContext();
193       Object JavaDoc name = context.getName();
194       Object JavaDoc other = dependency;
195       try
196       {
197          other = getObjectName().getCanonicalName();
198       }
199       catch (MalformedObjectNameException JavaDoc ignored)
200       {
201       }
202       // TODO visitor.addDependency(new LifecycleDependencyItem(name, other, ControllerState.CONFIGURED));
203
visitor.addDependency(new LifecycleDependencyItem(name, other, ControllerState.CREATE));
204       visitor.addDependency(new LifecycleDependencyItem(name, other, ControllerState.START));
205       visitor.visit(this);
206    }
207 }
208
Popular Tags