User: stacycurl
Date: 01/04/10 13:50:09
Modified: src/main/org/jbossmx/cluster/watchdog/mbean/xmlet
XMLetNodeProcessor.java XMLet.java
Added: src/main/org/jbossmx/cluster/watchdog/mbean/xmlet
XMLetMetaDataNodeProcessor.java
Log:
Cleaned up System.out's
XMLetNodeProcessor now creates MBeans, XMLet does not anymore.
XMLetMetaDataNodeProcessor is a new NodeProcessor than adds meta-data
entries into the MetaDataServiceMBean. The Meta-Data objects can be any
Java object.
This can be used for custom life-cycle methods, etc.
Revision Changes Path
1.2 +20 -19
jbossmx/src/main/org/jbossmx/cluster/watchdog/mbean/xmlet/XMLetNodeProcessor.java
Index: XMLetNodeProcessor.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmx/src/main/org/jbossmx/cluster/watchdog/mbean/xmlet/XMLetNodeProcessor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLetNodeProcessor.java 2001/03/29 13:49:34 1.1
+++ XMLetNodeProcessor.java 2001/04/10 20:50:09 1.2
@@ -50,8 +50,6 @@
XMLContext xmlContext)
throws XMLScriptException
{
- System.out.println("XMLetNodeProcessor.processNodeImpl");
-
try
{
processXMLetNode(node, xmlScripter, (XMLet) xmlContext);
@@ -61,24 +59,19 @@
t.printStackTrace();
throw new XMLScriptException(t.toString());
}
-
- System.out.println("XMLetNodeProcessor.processNodeImpl - done");
}
private void processXMLetNode(final Node node, XMLScripter xmlScripter, XMLet
xmlet)
- throws ClassNotFoundException, IllegalAccessException,
InstantiationException
+ throws ClassNotFoundException, IllegalAccessException,
InstantiationException,
+ XMLScriptException
{
- System.out.println("XMLetNodeProcessor.1");
-
final Properties xmletProperties =
convertNamedNodeMapToProperties(node.getAttributes());
XMLetEntry xmletEntry = createXMLetEntry(xmlScripter.getURL(),
xmletProperties);
- processXMLetArgNodes(node.getChildNodes(), xmletEntry, xmlet);
+ processXMLetChildNodes(node.getChildNodes(), xmletEntry, xmlet);
xmlet.addXMLetEntry(xmletEntry);
-
- System.out.println("XMLetNodeProcessor.2");
}
protected XMLetEntry createXMLetEntry(final URL xmletUrl, final Properties
xmletProperties)
@@ -91,21 +84,29 @@
* @param nodeList
* @param xmletEntry
*/
- private void processXMLetArgNodes(final NodeList nodeList, XMLetEntry
xmletEntry, XMLet xmlet)
+ protected void processXMLetChildNodes(final NodeList nodeList, XMLetEntry
xmletEntry, XMLet xmlet)
+ throws XMLScriptException
{
for(int nLoop = 0; nLoop < nodeList.getLength(); ++nLoop)
{
final Node node = nodeList.item(nLoop);
- if (node != null && node.getAttributes() != null)
- {
- final Node typeNode =
node.getAttributes().getNamedItem(XMLetEntry.TYPE_ATTRIBUTE);
- final Node valueNode =
node.getAttributes().getNamedItem(XMLetEntry.VALUE_ATTRIBUTE);
+ processXMLetChildNode(node, xmletEntry, xmlet);
- if (typeNode != null && valueNode != null)
- {
- xmletEntry.addArg(typeNode.getNodeValue(),
valueNode.getNodeValue());
- }
+ }
+ }
+
+ protected void processXMLetChildNode(final Node node, XMLetEntry xmletEntry,
XMLet xmlet)
+ throws XMLScriptException
+ {
+ if (node != null && "arg".equals(node.getNodeName()) &&
node.getAttributes() != null)
+ {
+ final Node typeNode =
node.getAttributes().getNamedItem(XMLetEntry.TYPE_ATTRIBUTE);
+ final Node valueNode =
node.getAttributes().getNamedItem(XMLetEntry.VALUE_ATTRIBUTE);
+
+ if (typeNode != null && valueNode != null)
+ {
+ xmletEntry.addArg(typeNode.getNodeValue(),
valueNode.getNodeValue());
}
}
}
1.2 +19 -1
jbossmx/src/main/org/jbossmx/cluster/watchdog/mbean/xmlet/XMLet.java
Index: XMLet.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmx/src/main/org/jbossmx/cluster/watchdog/mbean/xmlet/XMLet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLet.java 2001/03/29 13:49:33 1.1
+++ XMLet.java 2001/04/10 20:50:09 1.2
@@ -11,6 +11,7 @@
import org.jbossmx.cluster.watchdog.util.xml.XMLContext;
import org.jbossmx.cluster.watchdog.util.xml.XMLScripter;
+import org.jbossmx.cluster.watchdog.util.xml.XMLScriptException;
import org.xml.sax.SAXException;
@@ -170,11 +171,15 @@
try
{
+ m_mbeans = new HashSet();
+
XMLScripter xmlScripter = new XMLScripter(this, XMLET_ROOT_NODE);
xmlScripter.addNodeProcessor(new XMLetNodeProcessor("xmlet"));
xmlScripter.processDocument(url);
+
+ return m_mbeans;
- return processXMLetEntries(m_xmletEntries);
+// return processXMLetEntries(m_xmletEntries);
}
catch(IOException ie)
{
@@ -184,9 +189,14 @@
{
throw new ServiceNotFoundException("SAXException: " + se.toString());
}
+ catch(XMLScriptException xe)
+ {
+ throw new ServiceNotFoundException("XMLScriptException: " +
xe.toString());
+ }
}
public void addXMLetEntry(XMLetEntry xmletEntry)
+ throws ServiceNotFoundException
{
if (m_xmletEntries == null)
{
@@ -194,6 +204,12 @@
}
m_xmletEntries.add(xmletEntry);
+
+ Object result = processXMLetEntry(xmletEntry);
+ if (result != null)
+ {
+ m_mbeans.add(result);
+ }
}
/**
@@ -292,6 +308,8 @@
private ObjectName m_objectName;
/** */
private List m_xmletEntries;
+ /** */
+ private Set m_mbeans;
/** */
private static final String XMLET_ROOT_NODE = "xmlets";
1.1
jbossmx/src/main/org/jbossmx/cluster/watchdog/mbean/xmlet/XMLetMetaDataNodeProcessor.java
Index: XMLetMetaDataNodeProcessor.java
===================================================================
/**
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license Version 2.1, February 1999.
* See terms of license at gnu.org.
*/
package org.jbossmx.cluster.watchdog.mbean.xmlet;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.jbossmx.util.MetaDataServiceMBean;
import org.jbossmx.util.ObjectNameMetaData;
import org.jbossmx.cluster.watchdog.util.xml.XMLObjectCreator;
import org.jbossmx.cluster.watchdog.util.xml.XMLScripter;
import org.jbossmx.cluster.watchdog.util.xml.XMLScriptException;
import javax.management.MBeanServer;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
/**
* @author
*/
public class XMLetMetaDataNodeProcessor extends XMLetNodeProcessor
{
public XMLetMetaDataNodeProcessor(final String nodeName)
{
super(nodeName);
}
public XMLetMetaDataNodeProcessor(final String nodeName, FailedMBeanPacker
failedMBeanPacker)
{
super(nodeName, failedMBeanPacker);
}
protected void processXMLetChildNode(final Node node, XMLetEntry xmletEntry,
XMLet xmlet)
throws XMLScriptException
{
if (node != null && "meta-data".equals(node.getNodeName()))
{
try
{
final NodeList entryList = node.getChildNodes();
ObjectName metaDataObjectName =
new
ObjectName(xmletEntry.getProperty(XMLetEntry.NAME_ATTRIBUTE));
ObjectNameMetaData objectNameMetaData =
new ObjectNameMetaData(metaDataObjectName);
for(int nLoop = 0; nLoop < entryList.getLength(); ++nLoop)
{
final Node metaDataEntityNode = entryList.item(nLoop);
if (metaDataEntityNode != null &&
"entity".equals(metaDataEntityNode.getNodeName()))
{
processXMLetMetaDataEntity(metaDataEntityNode,
objectNameMetaData);
}
}
MBeanServer mbeanServer = xmlet.getMBeanServer();
mbeanServer.invoke(new ObjectName(MetaDataServiceMBean.OBJECT_NAME),
"setMetaData",
new Object[] {objectNameMetaData},
new String[] {ObjectNameMetaData.class.getName()});
}
catch (Throwable t)
{
throw new XMLScriptException("Couldn't add Meta-Data for " +
xmletEntry.getProperty(XMLetEntry.NAME_ATTRIBUTE) + " " +
t.toString());
}
}
else
{
super.processXMLetChildNode(node, xmletEntry, xmlet);
}
}
private void processXMLetMetaDataEntity(final Node metaDataEntityNode,
ObjectNameMetaData objectNameMetaData)
throws Exception
{
Object key = null;
Object value = null;
final NodeList nodeList = metaDataEntityNode.getChildNodes();
for(int nLoop = 0; nLoop < nodeList.getLength(); ++nLoop)
{
final Node node = nodeList.item(nLoop);
if (node != null)
{
if ("key".equals(node.getNodeName()))
{
final Node paramNode = getParamNode(node);
if (paramNode != null)
{
key = XMLObjectCreator.createObject(paramNode);
}
}
else if ("value".equals(node.getNodeName()))
{
final Node paramNode = getParamNode(node);
if (paramNode != null)
{
value = XMLObjectCreator.createObject(paramNode);
}
}
}
}
if (key != null && value != null)
{
objectNameMetaData.setMetaData(key, value);
}
}
private Node getParamNode(final Node node)
{
Node paramNode = null;
final NodeList nodeList = node.getChildNodes();
for(int nLoop = 0; nLoop < nodeList.getLength() && paramNode == null; ++nLoop)
{
final Node childNode = nodeList.item(nLoop);
if (childNode != null && "param".equals(childNode.getNodeName()))
{
paramNode = childNode;
}
}
return paramNode;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development