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. package javax.management.loading;
  8. // java import
  9. import java.net.URL;
  10. import java.net.MalformedURLException;
  11. import java.util.Map;
  12. /**
  13. * This class represents the contents of the <CODE>MLET</CODE> tag.
  14. * <p>
  15. * The <CODE>MLET</CODE> tag has the following syntax:
  16. * <p>
  17. * <<CODE>MLET</CODE><BR>
  18. * <CODE>CODE = </CODE><VAR>class</VAR><CODE> | OBJECT = </CODE><VAR>serfile</VAR><BR>
  19. * <CODE>ARCHIVE = "</CODE><VAR>archiveList</VAR><CODE>"</CODE><BR>
  20. * <CODE>[CODEBASE = </CODE><VAR>codebaseURL</VAR><CODE>]</CODE><BR>
  21. * <CODE>[NAME = </CODE><VAR>mbeanname</VAR><CODE>]</CODE><BR>
  22. * <CODE>[VERSION = </CODE><VAR>version</VAR><CODE>]</CODE><BR>
  23. * ><BR>
  24. * <CODE>[</CODE><VAR>arglist</VAR><CODE>]</CODE><BR>
  25. * <<CODE>/MLET</CODE>>
  26. * <p>
  27. * where:
  28. * <DL>
  29. * <DT><CODE>CODE = </CODE><VAR>class</VAR></DT>
  30. * <DD>
  31. * This attribute specifies the full Java class name, including package name, of the MBean to be obtained.
  32. * 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>
  33. * attribute. Either <CODE>CODE</CODE> or <CODE>OBJECT</CODE> must be present.
  34. * </DD>
  35. * <DT><CODE>OBJECT = </CODE><VAR>serfile</VAR></DT>
  36. * <DD>
  37. * This attribute specifies the <CODE>.ser</CODE> file that contains a serialized representation of the MBean to be obtained.
  38. * 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.
  39. * </DD>
  40. * <DT><CODE>ARCHIVE = "</CODE><VAR>archiveList</VAR><CODE>"</CODE></DT>
  41. * <DD>
  42. * This mandatory attribute specifies one or more <CODE>.jar</CODE> files
  43. * containing MBeans or other resources used by
  44. * 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.
  45. * If archivelist contains more than one file:
  46. * <UL>
  47. * <LI>Each file must be separated from the one that follows it by a comma (,).
  48. * <LI><VAR>archivelist</VAR> must be enclosed in double quote marks.
  49. * </UL>
  50. * All <CODE>.jar</CODE> files in <VAR>archivelist</VAR> must be stored in the directory specified by the code base URL.
  51. * </DD>
  52. * <DT><CODE>CODEBASE = </CODE><VAR>codebaseURL</VAR></DT>
  53. * <DD>
  54. * This optional attribute specifies the code base URL of the MBean to be obtained. It identifies the directory that contains
  55. * 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
  56. * directory as the MLet text file. If this attribute is not specified, the base URL of the MLet text file is used.
  57. * </DD>
  58. * <DT><CODE>NAME = </CODE><VAR>mbeanname</VAR></DT>
  59. * <DD>
  60. * This optional attribute specifies the object name to be assigned to the
  61. * MBean instance when the MLet service registers it. If
  62. * <VAR>mbeanname</VAR> starts with the colon character (:), the domain
  63. * part of the object name is the domain of the agent. The MLet service
  64. * invokes the <CODE>getDomain()</CODE> method of the Framework class to
  65. * obtain this information.
  66. * </DD>
  67. * <DT><CODE>PERSISTENT = </CODE><VAR>true | false</VAR></DT>
  68. * <DD>
  69. * This optional attribute specifies the persistency or not persistency of the
  70. * MBean instance when the MLet service registers it.
  71. * </DD>
  72. * <DT><CODE>VERSION = </CODE><VAR>version</VAR></DT>
  73. * <DD>
  74. * This optional attribute specifies the version number of the MBean and
  75. * associated <CODE>.jar</CODE> files to be obtained. This version number can
  76. * be used to specify that the <CODE>.jar</CODE> files are loaded from the
  77. * server to update those stored locally in the cache the next time the MLet
  78. * text file is loaded. <VAR>version</VAR> must be a series of non-negative
  79. * decimal integers each separated by a period from the one that precedes it.
  80. * </DD>
  81. * <DT><VAR>paramlist</VAR></DT>
  82. * <DD>
  83. * This optional attribute specifies a list of one or more parameters for the
  84. * MBean to be instantiated. Each parameter in <VAR>paramlist</VAR> corresponds to a modification in the
  85. * modification list. Use the following syntax to specify each item in
  86. * <VAR>paramlist</VAR>:</DD>
  87. * <DL>
  88. * <P>
  89. * <DT><<CODE>PARAM NAME=</CODE><VAR>propertyName</VAR> <CODE>VALUE=</CODE><VAR>value</VAR>></DT>
  90. * <P>
  91. * <DD>where:</DD>
  92. * <UL>
  93. * <LI><VAR>propertyName</VAR> is the name of the property in the modification
  94. * <LI><VAR>value</VAR> is the value in the modification</UL>
  95. * </DL>
  96. * <P>The MLet service passes all the values in the modification list as
  97. * <CODE>String</CODE> objects.
  98. * </DL>
  99. *
  100. * <p><STRONG>Note - </STRONG>Multiple <CODE>MLET</CODE> tags with the same
  101. * code base URL share the same instance of the <CODE>MLetClassLoader</CODE>
  102. * class.
  103. *
  104. * @version 3.3 02/08/99
  105. * @author Sun Microsystems, Inc
  106. *
  107. * @since 1.5
  108. */
  109. class MLetContent {
  110. /**
  111. * A hash table of the attributes of the <CODE>MLET</CODE> tag
  112. * and their values.
  113. * @serial
  114. */
  115. private Map attributes;
  116. /**
  117. * The MLet text file's base URL.
  118. * @serial
  119. */
  120. private URL documentURL;
  121. /**
  122. * The base URL.
  123. * @serial
  124. */
  125. private URL baseURL;
  126. /**
  127. * Creates an <CODE>MLet</CODE> instance initialized with attributes read
  128. * from an <CODE>MLET</CODE> tag in an MLet text file.
  129. *
  130. * @param url The URL of the MLet text file containing the <CODE>MLET</CODE> tag.
  131. * @param attributes A list of the attributes of the <CODE>MLET</CODE> tag.
  132. */
  133. public MLetContent(URL url, Map attributes) {
  134. this.documentURL = url;
  135. this.attributes = attributes;
  136. // Initialize baseURL
  137. //
  138. String att = (String)getParameter("codebase");
  139. if (att != null) {
  140. if (!att.endsWith("/")) {
  141. att += "/";
  142. }
  143. try {
  144. baseURL = new URL(documentURL, att);
  145. } catch (MalformedURLException e) {
  146. // OK : Move to next block as baseURL could not be initialized.
  147. }
  148. }
  149. if (baseURL == null) {
  150. String file = documentURL.getFile();
  151. int i = file.lastIndexOf('/');
  152. if (i > 0 && i < file.length() - 1) {
  153. try {
  154. baseURL = new URL(documentURL, file.substring(0, i + 1));
  155. } catch (MalformedURLException e) {
  156. // OK : Move to next block as baseURL could not be initialized.
  157. }
  158. }
  159. }
  160. if (baseURL == null)
  161. baseURL = documentURL;
  162. }
  163. // GETTERS AND SETTERS
  164. //--------------------
  165. /**
  166. * Gets the attributes of the <CODE>MLET</CODE> tag.
  167. * @return A hash table of the attributes of the <CODE>MLET</CODE> tag
  168. * and their values.
  169. */
  170. public Map getAttributes() {
  171. return attributes;
  172. }
  173. /**
  174. * Gets the MLet text file's base URL.
  175. * @return The MLet text file's base URL.
  176. */
  177. public URL getDocumentBase() {
  178. return documentURL;
  179. }
  180. /**
  181. * Gets the code base URL.
  182. * @return The code base URL.
  183. */
  184. public URL getCodeBase() {
  185. return baseURL;
  186. }
  187. /**
  188. * Gets the list of <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE>
  189. * attribute of the <CODE>MLET</CODE> tag.
  190. * @return A comma-separated list of <CODE>.jar</CODE> file names.
  191. */
  192. public String getJarFiles() {
  193. return (String)getParameter("archive");
  194. }
  195. /**
  196. * Gets the value of the <CODE>CODE</CODE>
  197. * attribute of the <CODE>MLET</CODE> tag.
  198. * @return The value of the <CODE>CODE</CODE>
  199. * attribute of the <CODE>MLET</CODE> tag.
  200. */
  201. public String getCode() {
  202. return (String)getParameter("code");
  203. }
  204. /**
  205. * Gets the value of the <CODE>OBJECT</CODE>
  206. * attribute of the <CODE>MLET</CODE> tag.
  207. * @return The value of the <CODE>OBJECT</CODE>
  208. * attribute of the <CODE>MLET</CODE> tag.
  209. */
  210. public String getSerializedObject() {
  211. return (String)getParameter("object");
  212. }
  213. /**
  214. * Gets the value of the <CODE>NAME</CODE>
  215. * attribute of the <CODE>MLET</CODE> tag.
  216. * @return The value of the <CODE>NAME</CODE>
  217. * attribute of the <CODE>MLET</CODE> tag.
  218. */
  219. public String getName() {
  220. return (String)getParameter("name");
  221. }
  222. /**
  223. * Gets the value of the <CODE>VERSION</CODE>
  224. * attribute of the <CODE>MLET</CODE> tag.
  225. * @return The value of the <CODE>VERSION</CODE>
  226. * attribute of the <CODE>MLET</CODE> tag.
  227. */
  228. public String getVersion() {
  229. return (String)getParameter("version");
  230. }
  231. /**
  232. * Gets the value of the specified
  233. * attribute of the <CODE>MLET</CODE> tag.
  234. *
  235. * @param name A string representing the name of the attribute.
  236. * @return The value of the specified
  237. * attribute of the <CODE>MLET</CODE> tag.
  238. */
  239. public Object getParameter(String name) {
  240. return (Object) attributes.get(name.toLowerCase());
  241. }
  242. }