0N/A/*
2362N/A * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.management.loading;
0N/A
0N/A
0N/A// java import
0N/A
0N/Aimport java.net.URL;
0N/Aimport java.net.MalformedURLException;
0N/Aimport java.util.Collections;
0N/Aimport java.util.List;
0N/Aimport java.util.Map;
0N/A
0N/A/**
0N/A * This class represents the contents of the <CODE>MLET</CODE> tag.
0N/A * It can be consulted by a subclass of {@link MLet} that overrides
0N/A * the {@link MLet#check MLet.check} method.
0N/A *
0N/A * @since 1.6
0N/A */
0N/Apublic class MLetContent {
0N/A
0N/A
0N/A /**
0N/A * A map of the attributes of the <CODE>MLET</CODE> tag
0N/A * and their values.
0N/A */
0N/A private Map<String,String> attributes;
0N/A
0N/A /**
0N/A * An ordered list of the TYPE attributes that appeared in nested
0N/A * &lt;PARAM&gt; tags.
0N/A */
0N/A private List<String> types;
0N/A
0N/A /**
0N/A * An ordered list of the VALUE attributes that appeared in nested
0N/A * &lt;PARAM&gt; tags.
0N/A */
0N/A private List<String> values;
0N/A
0N/A /**
0N/A * The MLet text file's base URL.
0N/A */
0N/A private URL documentURL;
0N/A /**
0N/A * The base URL.
0N/A */
0N/A private URL baseURL;
0N/A
0N/A
0N/A /**
0N/A * Creates an <CODE>MLet</CODE> instance initialized with attributes read
0N/A * from an <CODE>MLET</CODE> tag in an MLet text file.
0N/A *
0N/A * @param url The URL of the MLet text file containing the
0N/A * <CODE>MLET</CODE> tag.
0N/A * @param attributes A map of the attributes of the <CODE>MLET</CODE> tag.
0N/A * The keys in this map are the attribute names in lowercase, for
0N/A * example <code>codebase</code>. The values are the associated attribute
0N/A * values.
0N/A * @param types A list of the TYPE attributes that appeared in nested
0N/A * &lt;PARAM&gt; tags.
0N/A * @param values A list of the VALUE attributes that appeared in nested
0N/A * &lt;PARAM&gt; tags.
0N/A */
0N/A public MLetContent(URL url, Map<String,String> attributes,
0N/A List<String> types, List<String> values) {
0N/A this.documentURL = url;
0N/A this.attributes = Collections.unmodifiableMap(attributes);
0N/A this.types = Collections.unmodifiableList(types);
0N/A this.values = Collections.unmodifiableList(values);
0N/A
0N/A // Initialize baseURL
0N/A //
0N/A String att = getParameter("codebase");
0N/A if (att != null) {
0N/A if (!att.endsWith("/")) {
0N/A att += "/";
0N/A }
0N/A try {
0N/A baseURL = new URL(documentURL, att);
0N/A } catch (MalformedURLException e) {
0N/A // OK : Move to next block as baseURL could not be initialized.
0N/A }
0N/A }
0N/A if (baseURL == null) {
0N/A String file = documentURL.getFile();
0N/A int i = file.lastIndexOf('/');
0N/A if (i >= 0 && i < file.length() - 1) {
0N/A try {
0N/A baseURL = new URL(documentURL, file.substring(0, i + 1));
0N/A } catch (MalformedURLException e) {
0N/A // OK : Move to next block as baseURL could not be initialized.
0N/A }
0N/A }
0N/A }
0N/A if (baseURL == null)
0N/A baseURL = documentURL;
0N/A
0N/A }
0N/A
0N/A // GETTERS AND SETTERS
0N/A //--------------------
0N/A
0N/A /**
0N/A * Gets the attributes of the <CODE>MLET</CODE> tag. The keys in
0N/A * the returned map are the attribute names in lowercase, for
0N/A * example <code>codebase</code>. The values are the associated
0N/A * attribute values.
0N/A * @return A map of the attributes of the <CODE>MLET</CODE> tag
0N/A * and their values.
0N/A */
0N/A public Map<String,String> getAttributes() {
0N/A return attributes;
0N/A }
0N/A
0N/A /**
0N/A * Gets the MLet text file's base URL.
0N/A * @return The MLet text file's base URL.
0N/A */
0N/A public URL getDocumentBase() {
0N/A return documentURL;
0N/A }
0N/A
0N/A /**
0N/A * Gets the code base URL.
0N/A * @return The code base URL.
0N/A */
0N/A public URL getCodeBase() {
0N/A return baseURL;
0N/A }
0N/A
0N/A /**
0N/A * Gets the list of <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE>
0N/A * attribute of the <CODE>MLET</CODE> tag.
0N/A * @return A comma-separated list of <CODE>.jar</CODE> file names.
0N/A */
0N/A public String getJarFiles() {
0N/A return getParameter("archive");
0N/A }
0N/A
0N/A /**
0N/A * Gets the value of the <CODE>CODE</CODE>
0N/A * attribute of the <CODE>MLET</CODE> tag.
0N/A * @return The value of the <CODE>CODE</CODE>
0N/A * attribute of the <CODE>MLET</CODE> tag.
0N/A */
0N/A public String getCode() {
0N/A return getParameter("code");
0N/A }
0N/A
0N/A /**
0N/A * Gets the value of the <CODE>OBJECT</CODE>
0N/A * attribute of the <CODE>MLET</CODE> tag.
0N/A * @return The value of the <CODE>OBJECT</CODE>
0N/A * attribute of the <CODE>MLET</CODE> tag.
0N/A */
0N/A public String getSerializedObject() {
0N/A return getParameter("object");
0N/A }
0N/A
0N/A /**
0N/A * Gets the value of the <CODE>NAME</CODE>
0N/A * attribute of the <CODE>MLET</CODE> tag.
0N/A * @return The value of the <CODE>NAME</CODE>
0N/A * attribute of the <CODE>MLET</CODE> tag.
0N/A */
0N/A public String getName() {
0N/A return getParameter("name");
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Gets the value of the <CODE>VERSION</CODE>
0N/A * attribute of the <CODE>MLET</CODE> tag.
0N/A * @return The value of the <CODE>VERSION</CODE>
0N/A * attribute of the <CODE>MLET</CODE> tag.
0N/A */
0N/A public String getVersion() {
0N/A return getParameter("version");
0N/A }
0N/A
0N/A /**
0N/A * Gets the list of values of the <code>TYPE</code> attribute in
0N/A * each nested &lt;PARAM&gt; tag within the <code>MLET</code>
0N/A * tag.
0N/A * @return the list of types.
0N/A */
0N/A public List<String> getParameterTypes() {
0N/A return types;
0N/A }
0N/A
0N/A /**
0N/A * Gets the list of values of the <code>VALUE</code> attribute in
0N/A * each nested &lt;PARAM&gt; tag within the <code>MLET</code>
0N/A * tag.
0N/A * @return the list of values.
0N/A */
0N/A public List<String> getParameterValues() {
0N/A return values;
0N/A }
0N/A
0N/A /**
0N/A * Gets the value of the specified
0N/A * attribute of the <CODE>MLET</CODE> tag.
0N/A *
0N/A * @param name A string representing the name of the attribute.
0N/A * @return The value of the specified
0N/A * attribute of the <CODE>MLET</CODE> tag.
0N/A */
0N/A private String getParameter(String name) {
0N/A return attributes.get(name.toLowerCase());
0N/A }
0N/A
0N/A}