User: juhalindfors
Date: 02/02/15 04:23:11
Modified: src/main/javax/management/loading MLet.java
Log:
MLet text file parses separated to a class of its own. MBean loader parsers
can be accessed through the MBeanFileParser interface.
Revision Changes Path
1.6 +47 -177 jmx/src/main/javax/management/loading/MLet.java
Index: MLet.java
===================================================================
RCS file: /cvsroot/jboss/jmx/src/main/javax/management/loading/MLet.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MLet.java 5 Feb 2002 16:20:45 -0000 1.5
+++ MLet.java 15 Feb 2002 12:23:11 -0000 1.6
@@ -27,18 +27,32 @@
import java.util.Iterator;
import java.util.NoSuchElementException;
+import java.text.ParseException;
+
+import org.jboss.mx.loading.MBeanFileParser;
+import org.jboss.mx.loading.MLetParser;
+import org.jboss.mx.loading.MBeanElement;
+
/**
+ * URL classloader capable of parsing an MLet text file adhering to the file
+ * format defined in the JMX specification (v1.0).
+ *
+ * @see javax.management.loading.MLetMBean
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public class MLet
extends URLClassLoader
implements MLetMBean, MBeanRegistration
{
+ // FIXME: (RI javadoc) Note - The MLet class loader uses the
DefaultLoaderRepository to load classes that could not be found in the loaded jar
files.
+
// Attributes ----------------------------------------------------
+ /** Reference to the MBean server this loader is registered to. */
private MBeanServer server = null;
+ /** Object name of this loader. */
private ObjectName objectName = null;
// Constructors --------------------------------------------------
@@ -83,7 +97,7 @@
public void postDeregister()
{}
- // Public --------------------------------------------------------
+ // MLetMBean implementation --------------------------------------
public Set getMBeansFromURL(String url) throws ServiceNotFoundException
{
try
@@ -99,147 +113,50 @@
public Set getMBeansFromURL(URL url) throws ServiceNotFoundException
{
if (server == null)
- throw new ServiceNotFoundException("MLet must be registered to the server
before loading the MBeans.");
+ throw new ServiceNotFoundException("Loader must be registered to the
server before loading the MBeans.");
- HashSet mlets = new HashSet();
HashSet mbeans = new HashSet();
- MLetEntry entry = null;
- try
- {
- BufferedReader reader = new BufferedReader(new
InputStreamReader(url.openStream()));
- int c = -1;
-
- while((c = reader.read()) != -1)
- {
- if (c == '<')
- {
- StringBuffer buf = new StringBuffer(1000);
- boolean readMore = true;
-
- while(readMore)
- {
- c = reader.read();
-
- if (c == -1)
- throw new IOException("Unexpected end of file. Tag was not
closed: " + buf.toString());
-
- if (c == '>')
- {
- readMore = false;
- break;
- }
-
- buf.append((char)c);
- }
+ MBeanElement element = null;
- StringTokenizer tokenizer = new StringTokenizer(buf.toString(), "=
\n\t\r");
- String tagName = null, attributeName = null, attributeValue = null;
-
- if (tokenizer.hasMoreTokens())
- tagName = tokenizer.nextToken().trim();
-
- if (tagName.equals("MLET"))
- {
- entry = new MLetEntry();
-
- while(tokenizer.hasMoreTokens())
- {
- try
- {
- attributeName = tokenizer.nextToken("= \n\t\r").trim();
- attributeValue = tokenizer.nextToken(" \n\t\r").trim();
-
- if (attributeValue.equals("="))
- attributeValue = tokenizer.nextToken();
- else
- attributeValue = attributeValue.substring(1,
attributeValue.length());
-
- if (attributeName.equals("CODE"))
- entry.code = trimQuotes(attributeValue);
- else if (attributeName.equals("OBJECT"))
- entry.object = trimQuotes(attributeValue);
- else if (attributeName.equals("ARCHIVE"))
- // FIXME: "archivelist" must be in quotes
- entry.archive = trimQuotes(attributeValue);
- else if (attributeName.equals("CODEBASE"))
- entry.codebase = trimQuotes(attributeValue);
- else if (attributeName.equals("NAME"))
- entry.name = trimQuotes(attributeValue);
- else if (attributeName.equals("VERSION"))
- entry.version = trimQuotes(attributeValue);
- }
- catch (NoSuchElementException e)
- {
- // couldn't find a valid attribute, value pair
- // ignore and move one
-
- // FIXME: log this somewhere
- System.out.println("No value found for attribute '" +
attributeName);
- }
- }
-
- if (entry.code == null && entry.object == null)
- throw new ServiceNotFoundException("<" +
buf.toString().replace('\n', ' ').replace('\r', ' ').replace('\t', ' ').trim() + "> is
missing mandatory CODE | OBJECT attribute");
- if (entry.archive == null)
- throw new ServiceNotFoundException("<" +
buf.toString().replace('\n', ' ').replace('\r', ' ').replace('\t', ' ').trim() + "> is
missing mandatory ARCHIVE attribute");
- }
-
- else if (tagName.equals("/MLET"))
- {
- mlets.add(entry);
- entry = null;
- }
-
- else if (tagName.equals("ARG"))
- {
- try
- {
- if (!tokenizer.nextToken().equals("TYPE"))
- continue;
-
- String name = tokenizer.nextToken();
-
- if (!tokenizer.nextToken().equals("VALUE"))
- continue;
-
- String value = tokenizer.nextToken(" \n\t\r");
-
- if (entry != null)
- entry.args.add(new String[] { name, value });
- }
- catch (NoSuchElementException e)
- {
- // malformed ARG tag means the MBean can't be instantiated
- // bogus class name will fail in createMBean
- entry.args.add(new String[] { "MalformedARG", "" });
-
- // FIXME: log this
- System.out.println("Malformed element: <" + buf.toString() +
">");
- }
- }
- } // end of if (c == '<')
- } // while((c = reader.read()) != -1)
+ try
+ {
+ MBeanFileParser parser = new MLetParser();
+ Set mlets = parser.parseMBeanFile(url);
if (mlets.size() == 0)
throw new ServiceNotFoundException("The specified URL '" + url + "'
does not contain MLET tags.");
Iterator it = mlets.iterator();
- while(it.hasNext())
+ while (it.hasNext())
{
- entry = (MLetEntry)it.next();
- StringTokenizer tokenizer = new StringTokenizer(entry.archive, ", ");
+ element = (MBeanElement)it.next();
+ String codebase = element.getCodebase();
// if no codebase is specified then the url of the mlet text file is
used
- if (entry.codebase == null)
- entry.codebase = url.toString().substring(0,
url.toString().lastIndexOf('/'));
-
- while(tokenizer.hasMoreElements())
- addURL(new URL(entry.codebase + ((entry.codebase.endsWith("/")) ? ""
: "/") + tokenizer.nextToken()));
+ if (codebase == null)
+ codebase = url.toString().substring(0,
url.toString().lastIndexOf('/'));
+
+ Iterator archives = element.getArchives().iterator();
+ String codebaseURL = null;
+
+ while(archives.hasNext())
+ {
+ try
+ {
+ codebaseURL = codebase + ((codebase.endsWith("/")) ? "" : "/") +
archives.next();
+ addURL(new URL(codebaseURL));
+ }
+ catch (MalformedURLException e)
+ {
+ // FIXME: log it
+ System.out.println("MLET ERROR: malformed codebase URL: '" +
codebaseURL + "'");
+ }
+ }
try
{
// FIXME: create with args!
- mbeans.add(server.createMBean(entry.code, (entry.name != null) ? new
ObjectName(entry.name) : null, objectName));
+ mbeans.add(server.createMBean(element.getCode(), (element.getName()
!= null) ? new ObjectName(element.getName()) : null, objectName));
}
catch (Throwable t)
{
@@ -251,9 +168,9 @@
}
}
}
- catch (IOException e)
+ catch (ParseException e)
{
- throw new ServiceNotFoundException(e.toString());
+ throw new ServiceNotFoundException(e.getMessage());
}
return mbeans;
@@ -276,22 +193,6 @@
}
}
- public URL[] getURLs()
- {
- return super.getURLs();
- }
-
- public URL getResource(String name)
- {
- return super.getResource(name);
- }
-
- public InputStream getResourceAsStream(String name)
- {
- return super.getResourceAsStream(name);
- }
-
-
public String getLibraryDirectory()
{
throw new Error("NYI");
@@ -302,36 +203,5 @@
throw new Error("NYI");
}
- // Private -------------------------------------------------------
- private String trimQuotes(String str)
- {
- if (str.startsWith("\"") && str.endsWith("\""))
- return str.substring(1, str.length() - 1);
- else
- return str;
- }
-
- // Inner classes -------------------------------------------------
- private class MLetEntry
- {
- String code = null;
- String object = null;
- String archive = null;
- String codebase = null;
- String name = null;
- String version = null;
- Set args = new HashSet();
-
- public String toString()
- {
- return "MLET:\n" +
- " CODE =" + code + "\n" +
- " OBJECT =" + object + "\n" +
- " ARCHIVE =" + archive + "\n" +
- " CODEBASE=" + codebase + "\n" +
- " NAME =" + name + "\n" +
- " VERSION =" + version + "\n";
- }
- }
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development