KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > loading > MLetContent


1 /*
2  * @(#)MLetContent.java 1.20 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.management.loading;
9
10
11 // java import
12

13 import java.net.URL JavaDoc;
14 import java.net.MalformedURLException JavaDoc;
15 import java.util.Map JavaDoc;
16
17 /**
18  * This class represents the contents of the <CODE>MLET</CODE> tag.
19  * <p>
20  * The <CODE>MLET</CODE> tag has the following syntax:
21  * <p>
22  * &lt;<CODE>MLET</CODE><BR>
23  * <CODE>CODE = </CODE><VAR>class</VAR><CODE> | OBJECT = </CODE><VAR>serfile</VAR><BR>
24  * <CODE>ARCHIVE = &quot;</CODE><VAR>archiveList</VAR><CODE>&quot;</CODE><BR>
25  * <CODE>[CODEBASE = </CODE><VAR>codebaseURL</VAR><CODE>]</CODE><BR>
26  * <CODE>[NAME = </CODE><VAR>mbeanname</VAR><CODE>]</CODE><BR>
27  * <CODE>[VERSION = </CODE><VAR>version</VAR><CODE>]</CODE><BR>
28  * &gt;<BR>
29  * <CODE>[</CODE><VAR>arglist</VAR><CODE>]</CODE><BR>
30  * &lt;<CODE>/MLET</CODE>&gt;
31  * <p>
32  * where:
33  * <DL>
34  * <DT><CODE>CODE = </CODE><VAR>class</VAR></DT>
35  * <DD>
36  * This attribute specifies the full Java class name, including package name, of the MBean to be obtained.
37  * The compiled <CODE>.class</CODE> file of the MBean must be contained in one of the <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE>
38  * attribute. Either <CODE>CODE</CODE> or <CODE>OBJECT</CODE> must be present.
39  * </DD>
40  * <DT><CODE>OBJECT = </CODE><VAR>serfile</VAR></DT>
41  * <DD>
42  * This attribute specifies the <CODE>.ser</CODE> file that contains a serialized representation of the MBean to be obtained.
43  * This file must be contained in one of the <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE> attribute. If the <CODE>.jar</CODE> file contains a directory hierarchy, specify the path of the file within this hierarchy. Otherwise a match will not be found. Either <CODE>CODE</CODE> or <CODE>OBJECT</CODE> must be present.
44  * </DD>
45  * <DT><CODE>ARCHIVE = &quot;</CODE><VAR>archiveList</VAR><CODE>&quot;</CODE></DT>
46  * <DD>
47  * This mandatory attribute specifies one or more <CODE>.jar</CODE> files
48  * containing MBeans or other resources used by
49  * the MBean to be obtained. One of the <CODE>.jar</CODE> files must contain the file specified by the <CODE>CODE</CODE> or <CODE>OBJECT</CODE> attribute.
50  * If archivelist contains more than one file:
51  * <UL>
52  * <LI>Each file must be separated from the one that follows it by a comma (,).
53  * <LI><VAR>archivelist</VAR> must be enclosed in double quote marks.
54  * </UL>
55  * All <CODE>.jar</CODE> files in <VAR>archivelist</VAR> must be stored in the directory specified by the code base URL.
56  * </DD>
57  * <DT><CODE>CODEBASE = </CODE><VAR>codebaseURL</VAR></DT>
58  * <DD>
59  * This optional attribute specifies the code base URL of the MBean to be obtained. It identifies the directory that contains
60  * the <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE> attribute. Specify this attribute only if the <CODE>.jar</CODE> files are not in the same
61  * directory as the MLet text file. If this attribute is not specified, the base URL of the MLet text file is used.
62  * </DD>
63  * <DT><CODE>NAME = </CODE><VAR>mbeanname</VAR></DT>
64  * <DD>
65  * This optional attribute specifies the object name to be assigned to the
66  * MBean instance when the MLet service registers it. If
67  * <VAR>mbeanname</VAR> starts with the colon character (:), the domain
68  * part of the object name is the domain of the agent. The MLet service
69  * invokes the <CODE>getDomain()</CODE> method of the Framework class to
70  * obtain this information.
71  * </DD>
72  * <DT><CODE>PERSISTENT = </CODE><VAR>true | false</VAR></DT>
73  * <DD>
74  * This optional attribute specifies the persistency or not persistency of the
75  * MBean instance when the MLet service registers it.
76  * </DD>
77  * <DT><CODE>VERSION = </CODE><VAR>version</VAR></DT>
78  * <DD>
79  * This optional attribute specifies the version number of the MBean and
80  * associated <CODE>.jar</CODE> files to be obtained. This version number can
81  * be used to specify that the <CODE>.jar</CODE> files are loaded from the
82  * server to update those stored locally in the cache the next time the MLet
83  * text file is loaded. <VAR>version</VAR> must be a series of non-negative
84  * decimal integers each separated by a period from the one that precedes it.
85  * </DD>
86  * <DT><VAR>paramlist</VAR></DT>
87  * <DD>
88  * This optional attribute specifies a list of one or more parameters for the
89  * MBean to be instantiated. Each parameter in <VAR>paramlist</VAR> corresponds to a modification in the
90  * modification list. Use the following syntax to specify each item in
91  * <VAR>paramlist</VAR>:</DD>
92  * <DL>
93  * <P>
94  * <DT>&lt;<CODE>PARAM NAME=</CODE><VAR>propertyName</VAR> <CODE>VALUE=</CODE><VAR>value</VAR>&gt;</DT>
95  * <P>
96  * <DD>where:</DD>
97  * <UL>
98  * <LI><VAR>propertyName</VAR> is the name of the property in the modification
99  * <LI><VAR>value</VAR> is the value in the modification</UL>
100  * </DL>
101  * <P>The MLet service passes all the values in the modification list as
102  * <CODE>String</CODE> objects.
103  * </DL>
104  *
105  * <p><STRONG>Note - </STRONG>Multiple <CODE>MLET</CODE> tags with the same
106  * code base URL share the same instance of the <CODE>MLetClassLoader</CODE>
107  * class.
108  *
109  * @version 3.3 02/08/99
110  * @author Sun Microsystems, Inc
111  *
112  * @since 1.5
113  */

114  class MLetContent {
115
116   
117     /**
118      * A hash table of the attributes of the <CODE>MLET</CODE> tag
119      * and their values.
120      * @serial
121      */

122     private Map JavaDoc attributes;
123   
124     /**
125      * The MLet text file's base URL.
126      * @serial
127      */

128     private URL JavaDoc documentURL;
129   
130     /**
131      * The base URL.
132      * @serial
133      */

134     private URL JavaDoc baseURL;
135
136
137     /**
138      * Creates an <CODE>MLet</CODE> instance initialized with attributes read
139      * from an <CODE>MLET</CODE> tag in an MLet text file.
140      *
141      * @param url The URL of the MLet text file containing the <CODE>MLET</CODE> tag.
142      * @param attributes A list of the attributes of the <CODE>MLET</CODE> tag.
143      */

144     public MLetContent(URL JavaDoc url, Map JavaDoc attributes) {
145     this.documentURL = url;
146     this.attributes = attributes;
147
148     // Initialize baseURL
149
//
150
String JavaDoc att = (String JavaDoc)getParameter("codebase");
151     if (att != null) {
152         if (!att.endsWith("/")) {
153         att += "/";
154         }
155         try {
156         baseURL = new URL JavaDoc(documentURL, att);
157         } catch (MalformedURLException JavaDoc e) {
158         // OK : Move to next block as baseURL could not be initialized.
159
}
160     }
161     if (baseURL == null) {
162         String JavaDoc file = documentURL.getFile();
163         int i = file.lastIndexOf('/');
164         if (i > 0 && i < file.length() - 1) {
165         try {
166             baseURL = new URL JavaDoc(documentURL, file.substring(0, i + 1));
167         } catch (MalformedURLException JavaDoc e) {
168             // OK : Move to next block as baseURL could not be initialized.
169
}
170         }
171     }
172     if (baseURL == null)
173         baseURL = documentURL;
174
175     }
176     
177     // GETTERS AND SETTERS
178
//--------------------
179

180     /**
181      * Gets the attributes of the <CODE>MLET</CODE> tag.
182      * @return A hash table of the attributes of the <CODE>MLET</CODE> tag
183      * and their values.
184      */

185     public Map JavaDoc getAttributes() {
186     return attributes;
187     }
188   
189     /**
190      * Gets the MLet text file's base URL.
191      * @return The MLet text file's base URL.
192      */

193     public URL JavaDoc getDocumentBase() {
194     return documentURL;
195     }
196
197     /**
198      * Gets the code base URL.
199      * @return The code base URL.
200      */

201     public URL JavaDoc getCodeBase() {
202     return baseURL;
203     }
204   
205     /**
206      * Gets the list of <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE>
207      * attribute of the <CODE>MLET</CODE> tag.
208      * @return A comma-separated list of <CODE>.jar</CODE> file names.
209      */

210     public String JavaDoc getJarFiles() {
211     return (String JavaDoc)getParameter("archive");
212     }
213
214     /**
215      * Gets the value of the <CODE>CODE</CODE>
216      * attribute of the <CODE>MLET</CODE> tag.
217      * @return The value of the <CODE>CODE</CODE>
218      * attribute of the <CODE>MLET</CODE> tag.
219      */

220     public String JavaDoc getCode() {
221     return (String JavaDoc)getParameter("code");
222     }
223
224     /**
225      * Gets the value of the <CODE>OBJECT</CODE>
226      * attribute of the <CODE>MLET</CODE> tag.
227      * @return The value of the <CODE>OBJECT</CODE>
228      * attribute of the <CODE>MLET</CODE> tag.
229      */

230     public String JavaDoc getSerializedObject() {
231     return (String JavaDoc)getParameter("object");
232     }
233
234     /**
235      * Gets the value of the <CODE>NAME</CODE>
236      * attribute of the <CODE>MLET</CODE> tag.
237      * @return The value of the <CODE>NAME</CODE>
238      * attribute of the <CODE>MLET</CODE> tag.
239      */

240     public String JavaDoc getName() {
241     return (String JavaDoc)getParameter("name");
242     }
243
244  
245     /**
246      * Gets the value of the <CODE>VERSION</CODE>
247      * attribute of the <CODE>MLET</CODE> tag.
248      * @return The value of the <CODE>VERSION</CODE>
249      * attribute of the <CODE>MLET</CODE> tag.
250      */

251     public String JavaDoc getVersion() {
252     return (String JavaDoc)getParameter("version");
253     }
254
255     /**
256      * Gets the value of the specified
257      * attribute of the <CODE>MLET</CODE> tag.
258      *
259      * @param name A string representing the name of the attribute.
260      * @return The value of the specified
261      * attribute of the <CODE>MLET</CODE> tag.
262      */

263     public Object JavaDoc getParameter(String JavaDoc name) {
264     return (Object JavaDoc) attributes.get(name.toLowerCase());
265     }
266   
267 }
268
Popular Tags