001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package javax.management.loading;
023:
024: import java.net.URL;
025: import java.net.MalformedURLException;
026: import java.util.Map;
027:
028: /** The MLET tag representation
029: *
030: * @author Scott.Stark@jboss.org
031: * @version $Revision: 57200 $
032: */
033: class MLetContent {
034: private URL mletURL;
035: private URL codeBase;
036: private Map attributes;
037:
038: /**
039: *
040: * @param url - MLet text file
041: * @param attributes
042: */
043: public MLetContent(URL url, Map attributes) {
044: this .mletURL = url;
045: this .attributes = attributes;
046: String codebase = (String) getParameter("codebase");
047: if (codebase != null) {
048: if (codebase.endsWith("/") == false) {
049: codebase += "/";
050: }
051: try {
052: codeBase = new URL(mletURL, codebase);
053: } catch (MalformedURLException e) {
054: }
055: }
056:
057: if (codeBase == null) {
058: String file = mletURL.getFile();
059: int i = file.lastIndexOf('/');
060: if (i > 0 && i < file.length() - 1) {
061: try {
062: codeBase = new URL(mletURL, file
063: .substring(0, i + 1));
064: } catch (MalformedURLException e) {
065: }
066: }
067: }
068: if (codeBase == null)
069: codeBase = mletURL;
070: }
071:
072: public Map getAttributes() {
073: return attributes;
074: }
075:
076: public String getCode() {
077: String code = (String) getParameter("code");
078: return code;
079: }
080:
081: public URL getCodeBase() {
082: return codeBase;
083: }
084:
085: public URL getDocumentBase() {
086: return mletURL;
087: }
088:
089: public String getJarFiles() {
090: String jarFile = (String) getParameter("archives");
091: return jarFile;
092: }
093:
094: public String getName() {
095: String name = (String) getParameter("name");
096: return name;
097: }
098:
099: public String getSerializedObject() {
100: String object = (String) getParameter("object");
101: return object;
102: }
103:
104: public String getVersion() {
105: String version = (String) getParameter("version");
106: return version;
107: }
108:
109: public Object getParameter(String name) {
110: return attributes.get(name.toLowerCase());
111: }
112: }
|