1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
/* * @(#)MLetContent.java 1.23 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package javax.management.loading; // java import import java.net.URL; import java.net.MalformedURLException; import java.util.Collections; import java.util.List; import java.util.Map; /** * This class represents the contents of the <CODE>MLET</CODE> tag. * It can be consulted by a subclass of {@link MLet} that overrides * the {@link MLet#check MLet.check} method. * * @since 1.6 */ public class MLetContent { /** * A map of the attributes of the <CODE>MLET</CODE> tag * and their values. */ private Map<String,String> attributes; /** * An ordered list of the TYPE attributes that appeared in nested * <PARAM> tags. */ private List<String> types; /** * An ordered list of the VALUE attributes that appeared in nested * <PARAM> tags. */ private List<String> values; /** * The MLet text file's base URL. */ private URL documentURL; /** * The base URL. */ private URL baseURL; /** * Creates an <CODE>MLet</CODE> instance initialized with attributes read * from an <CODE>MLET</CODE> tag in an MLet text file. * * @param url The URL of the MLet text file containing the * <CODE>MLET</CODE> tag. * @param attributes A map of the attributes of the <CODE>MLET</CODE> tag. * The keys in this map are the attribute names in lowercase, for * example <code>codebase</code>. The values are the associated attribute * values. * @param types A list of the TYPE attributes that appeared in nested * <PARAM> tags. * @param values A list of the VALUE attributes that appeared in nested * <PARAM> tags. */ public MLetContent(URL url, Map<String,String> attributes, List<String> types, List<String> values) { this.documentURL = url; this.attributes = Collections.unmodifiableMap(attributes); this.types = Collections.unmodifiableList(types); this.values = Collections.unmodifiableList(values); // Initialize baseURL // String att = getParameter("codebase"); if (att != null) { if (!att.endsWith("/")) { att += "/"; } try { baseURL = new URL(documentURL, att); } catch (MalformedURLException e) { // OK : Move to next block as baseURL could not be initialized. } } if (baseURL == null) { String file = documentURL.getFile(); int i = file.lastIndexOf('/'); if (i > 0 && i < file.length() - 1) { try { baseURL = new URL(documentURL, file.substring(0, i + 1)); } catch (MalformedURLException e) { // OK : Move to next block as baseURL could not be initialized. } } } if (baseURL == null) baseURL = documentURL; } // GETTERS AND SETTERS //-------------------- /** * Gets the attributes of the <CODE>MLET</CODE> tag. The keys in * the returned map are the attribute names in lowercase, for * example <code>codebase</code>. The values are the associated * attribute values. * @return A map of the attributes of the <CODE>MLET</CODE> tag * and their values. */ public Map<String,String> getAttributes() { return attributes; } /** * Gets the MLet text file's base URL. * @return The MLet text file's base URL. */ public URL getDocumentBase() { return documentURL; } /** * Gets the code base URL. * @return The code base URL. */ public URL getCodeBase() { return baseURL; } /** * Gets the list of <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE> * attribute of the <CODE>MLET</CODE> tag. * @return A comma-separated list of <CODE>.jar</CODE> file names. */ public String getJarFiles() { return getParameter("archive"); } /** * Gets the value of the <CODE>CODE</CODE> * attribute of the <CODE>MLET</CODE> tag. * @return The value of the <CODE>CODE</CODE> * attribute of the <CODE>MLET</CODE> tag. */ public String getCode() { return getParameter("code"); } /** * Gets the value of the <CODE>OBJECT</CODE> * attribute of the <CODE>MLET</CODE> tag. * @return The value of the <CODE>OBJECT</CODE> * attribute of the <CODE>MLET</CODE> tag. */ public String getSerializedObject() { return getParameter("object"); } /** * Gets the value of the <CODE>NAME</CODE> * attribute of the <CODE>MLET</CODE> tag. * @return The value of the <CODE>NAME</CODE> * attribute of the <CODE>MLET</CODE> tag. */ public String getName() { return getParameter("name"); } /** * Gets the value of the <CODE>VERSION</CODE> * attribute of the <CODE>MLET</CODE> tag. * @return The value of the <CODE>VERSION</CODE> * attribute of the <CODE>MLET</CODE> tag. */ public String getVersion() { return getParameter("version"); } /** * Gets the list of values of the <code>TYPE</code> attribute in * each nested <PARAM> tag within the <code>MLET</code> * tag. * @return the list of types. */ public List<String> getParameterTypes() { return types; } /** * Gets the list of values of the <code>VALUE</code> attribute in * each nested <PARAM> tag within the <code>MLET</code> * tag. * @return the list of values. */ public List<String> getParameterValues() { return values; } /** * Gets the value of the specified * attribute of the <CODE>MLET</CODE> tag. * * @param name A string representing the name of the attribute. * @return The value of the specified * attribute of the <CODE>MLET</CODE> tag. */ private String getParameter(String name) { return attributes.get(name.toLowerCase()); } }