KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > services > deployment > MBeanData


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.services.deployment;
23
24 import java.io.Serializable JavaDoc;
25 import java.util.Properties JavaDoc;
26
27 /**
28  * Holds information about an MBean, suitable for use to generate the XSLT used
29  * to transform the XML configuration file containing the information about that
30  * MBean.
31  *
32  * @author <a HREF="peter.johnson2@unisys.com">Peter Johnson</a>
33  * @version $Revision: 41066 $
34  */

35 public class MBeanData implements Serializable JavaDoc
36 {
37    /** The serialVersionUID */
38    private static final long serialVersionUID = -4870385245742489112L;
39
40    /**
41     * The JNDI name for the MBean
42     */

43    private String JavaDoc name;
44
45    /**
46     * Partial XPath statement used to locate the name of the MBean. This is a
47     * read-only property set from the name property the first time this property
48     * is accessed.
49     */

50    private String JavaDoc xpath;
51
52    /**
53     * The simple file name of the Velocity template to use to generate the XSLT
54     * file.
55     */

56    private String JavaDoc templateName;
57
58    /**
59     * Collection of dependencies for this MBean. The key is the value for the
60     * optional-attribute-name property, and the value is the name of the
61     * depending MBean. The key can be an empty string to represent the default
62     * dependency. Both key and value are strings.
63     */

64    private Properties JavaDoc depends;
65
66    /**
67     * The collection of attributes for this MBean. The key is the attribute
68     * name, and the value is its value. Both key and value are strings.
69     */

70    private Properties JavaDoc attributes;
71
72    /**
73     * @return Returns the attributes.
74     */

75    public final Properties JavaDoc getAttributes()
76    {
77       return attributes;
78    }
79
80    /**
81     * @param attributes The attributes to set.
82     */

83    public final void setAttributes(Properties JavaDoc attributes)
84    {
85       this.attributes = attributes;
86    }
87
88    /**
89     * @return Returns the depends.
90     */

91    public final Properties JavaDoc getDepends()
92    {
93       return depends;
94    }
95
96    /**
97     * @param depends The depends to set.
98     */

99    public final void setDepends(Properties JavaDoc depends)
100    {
101       this.depends = depends;
102    }
103
104    /**
105     * @return Returns the name.
106     */

107    public final String JavaDoc getName()
108    {
109       return name;
110    }
111
112    /**
113     * @param name The name to set.
114     */

115    public final void setName(String JavaDoc name)
116    {
117       this.name = name;
118    }
119
120    /**
121     * Get the templateName.
122     *
123     * @return the templateName.
124     */

125    public String JavaDoc getTemplateName()
126    {
127       return templateName;
128    }
129
130    /**
131     * Set the templateName.
132     *
133     * @param templateName The templateName to set.
134     */

135    public void setTemplateName(String JavaDoc templateName)
136    {
137       this.templateName = templateName;
138    }
139
140    /**
141     * @return Returns the xpath condition.
142     */

143    public final String JavaDoc getXpath()
144    {
145       if (xpath == null)
146       {
147          asXpath();
148       }
149       return xpath;
150    }
151
152    /**
153     * @see java.lang.Object#toString()
154     */

155    public String JavaDoc toString()
156    {
157       return name;
158    }
159    
160    /**
161     * Converts an mbean name into the condition used to locate the name as part
162     * of an xpath statement.
163     * </p>
164     * <p>
165     * For example, converts
166     * </p>
167     *
168     * <pre> jboss.mq:service=InvocationLayer,type=UIL2XA,alias=UIL2XAConnectionFactory
169     * </pre>
170     *
171     * <p>
172     * into
173     * </p>
174     *
175     * <pre> starts-with(@name, 'jboss.mq:')<br/>
176     * and contains(@name, 'service=InvocationLayer')<br/>
177     * and contains(@name, 'type=UIL2XA')<br/>
178     * and contains(@name, 'alias=UIL2XAConnectionFactory')<br/>
179     * and string-length(@name) = 74</pre>
180     *
181     * <p>
182     * and converts a name such as
183     * </p>
184     *
185     * <pre> jboss.mq:service=InvocationLayer</pre>
186     *
187     * <p>
188     * into
189     * </p>
190     *
191     * <pre> @name='jboss.mq:service=InvocationLayer'</pre>
192     *
193     * <p>
194     * The number of commas that appear (thus, by inference, the number of
195     * attributes associated with the mbean name) differtiates the format used.
196     * If there is no comma (meaning exactly one attribute), the
197     * later format is used. If there is at least one comma, meaning two or more
198     * attributes, the former format is used. The string-length check prevents
199     * a mismatch with an mbean that has attributes in addition to the attributes
200     * referenced by the contains() functions.
201     * </p>
202     * <p>
203     * Perplexed as to why we should even bother to do this? It appears that when
204     * you ask for the name of an mbean, the attributes associate with the name
205     * can appear in any order. Thus, the order found in the XML file is not
206     * always what is given by the mbean.
207     *
208     */

209    private void asXpath()
210    {
211       
212       // If there is no comma in the name, use the simple form:
213
if (name.indexOf(',') == -1)
214       {
215          xpath = "@name='" + name + "'";
216       }
217       else
218       {
219          // There is a comma, need to generate the longer xpath condition
220
String JavaDoc[] parts = name.split("[,:]");
221          StringBuffer JavaDoc buf = new StringBuffer JavaDoc(2 * name.length());
222          buf.append("starts-with(@name, '");
223          buf.append(parts[0]);
224          for (int i = 1; i < parts.length; i++)
225          {
226             buf.append("') and contains(@name, '");
227             buf.append(parts[i]);
228          }
229          buf.append("') and string-length(@name) = ");
230          buf.append(name.length());
231          xpath = buf.toString();
232       }
233    }
234 }
235
Popular Tags