User: schaefera
Date: 01/06/25 22:29:13
Modified: src/main/org/jboss/jmx/server XMLAdaptorImpl.java
XMLTestService.java
Added: src/main/org/jboss/jmx/server XMLAdaptor.dtd
Log:
Added all the major methods to the XML Adaptor which make sense. I also
added a DTD for the XML file but it is only Alpha release.
Revision Changes Path
1.3 +236 -52 jboss/src/main/org/jboss/jmx/server/XMLAdaptorImpl.java
Index: XMLAdaptorImpl.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jmx/server/XMLAdaptorImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLAdaptorImpl.java 2001/06/25 18:28:52 1.2
+++ XMLAdaptorImpl.java 2001/06/26 05:29:13 1.3
@@ -16,30 +16,27 @@
import javax.management.AttributeList;
import javax.management.ObjectName;
import javax.management.ObjectInstance;
-// import javax.management.AttributeNotFoundException;
-// import javax.management.InstanceNotFoundException;
-// import javax.management.InvalidAttributeValueException;
import javax.management.MalformedObjectNameException;
import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
import javax.management.MBeanException;
import javax.management.MBeanServer;
-// import javax.management.ReflectionException;
import javax.naming.InitialContext;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
/**
* XML Adaptor Implementation interpreting the XML wrapped JMX commands.
*
* @author Andreas Schaefer ([EMAIL PROTECTED])
* @created June 22, 2001
-* @version $Revision: 1.2 $
+* @version $Revision: 1.3 $
*/
-public class XMLAdaptorImpl
-{
+public class XMLAdaptorImpl {
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
@@ -77,6 +74,17 @@
// Public --------------------------------------------------------
+ /**
+ * Performs a set of calls to the MBean Server and returns
+ * it return values.
+ *
+ * @param pJmxOperations Complete XML Document (compliant to the
+ * XMLAdaptor.dtd) containing a list of calls
+ * to the MBean Server.
+ *
+ * @return List of return values, one for each call. If the call doesn't
+ * have a return value of the operation failed it will be null.
+ **/
public Object[] invokeXML( Document pJmxOperations ) {
Vector lReturns = new Vector();
NodeList lRoot = pJmxOperations.getChildNodes();
@@ -92,6 +100,15 @@
return (Object[]) lReturns.toArray( new Object[ 0 ] );
}
+ /**
+ * Performs a single call to the MBean Server and return its return value
+ *
+ * @param pJmxOperation Second level element (compliant to XMLAdaptor.dtd)
+ * representing one call to the MBean Server
+ *
+ * @return Return value of the call or null if call failed or doesn't have
+ * a return value.
+ **/
public Object invokeXML( Element pJmxOperation ) {
if( pJmxOperation == null ) {
return null;
@@ -99,63 +116,96 @@
// Get the requested operation
String lTag = pJmxOperation.getTagName();
System.out.println( "XMLAdaptorImpl.invokeXML(), Tag: " + lTag );
- if( "invoke".equals( lTag ) ) {
+ if( "create-mbean".equals( lTag ) ) {
+ return createMBean(
+ pJmxOperation.getAttribute( "code" ),
+ getObjectName(
+ pJmxOperation.getAttribute( "name" ),
+ pJmxOperation.getElementsByTagName( "object-name" )
+ ),
+ pJmxOperation.getElementsByTagName( "constructor" ),
+ pJmxOperation.getElementsByTagName( "attribute" )
+ );
+ }
+ else if( "invoke".equals( lTag ) ) {
// Get the operation, Object Name and attributes and invoke it
String lOperation = pJmxOperation.getAttribute( "operation" );
return invoke(
lOperation,
- pJmxOperation.getElementsByTagName( "object-name" ),
+ getObjectName( pJmxOperation.getElementsByTagName( "object-name" ) ),
pJmxOperation.getElementsByTagName( "attribute" )
);
}
- else if( !"create-mbean".equals( lTag ) ) {
- NodeList lList = pJmxOperation.getElementsByTagName( "object-name" );
- // Get the operation, Object Name and attributes and invoke it
- String lCodebase = pJmxOperation.getAttribute( "code" );
- String lName = pJmxOperation.getAttribute( "name" );
- return createMBean(
- lCodebase,
- lName,
- pJmxOperation.getElementsByTagName( "object-name" ),
- pJmxOperation.getElementsByTagName( "constructor" ),
+ else if( !"get-attribute".equals( lTag ) ) {
+ return get(
+ getObjectName( pJmxOperation.getElementsByTagName( "object-name" ) ),
+ pJmxOperation.getElementsByTagName( "attribute" )
+ );
+ }
+ else if( !"set-attribute".equals( lTag ) ) {
+ return set(
+ getObjectName( pJmxOperation.getElementsByTagName( "object-name" ) ),
pJmxOperation.getElementsByTagName( "attribute" )
);
}
+ else if( !"mbean-count".equals( lTag ) ) {
+ return mServer.getMBeanCount();
+ }
+ else if( !"mbean-info".equals( lTag ) ) {
+ return getMBeanInfo(
+ getObjectName( pJmxOperation.getElementsByTagName( "object-name" ) )
+ );
+ }
+ else if( !"object-instance".equals( lTag ) ) {
+ return getObjectInstance(
+ getObjectName( pJmxOperation.getElementsByTagName( "object-name" ) )
+ );
+ }
+ else if( !"is-instance-of".equals( lTag ) ) {
+ return isInstanceOf(
+ getObjectName( pJmxOperation.getElementsByTagName( "object-name" ) ),
+ pJmxOperation.getAttribute( "code" )
+ );
+ }
+ else if( !"is-registered".equals( lTag ) ) {
+ return isRegistered(
+ getObjectName( pJmxOperation.getElementsByTagName( "object-name" ) )
+ );
+ }
+ else if( !"unregister-mbean".equals( lTag ) ) {
+ return unregisterMBean(
+ getObjectName( pJmxOperation.getElementsByTagName( "object-name" ) )
+ );
+ }
return null;
}
public ObjectName createMBean(
String pCodebase,
- String pName,
- NodeList pObjectName,
+ ObjectName pName,
NodeList pConstructor,
NodeList pAttributes
) {
+ System.out.println( "XMLAdaptorImpl.createMBean(), code: " + pCodebase + ",
name: " + pName );
ObjectName lReturn = null;
// Check Codebase
if( pCodebase != null && !pCodebase.equals( "" ) ) {
try {
- // Create ObjectName
- ObjectName lName = null;
- if( pName != null && !pName.equals( "" ) ) {
- lName = createObjectName( pName );
- }
- else if( pObjectName != null && pObjectName.getLength() > 0 ) {
- lName = createObjectName( (Element) pObjectName.item( 0 ) );
- }
- if( lName != null ) {
+ if( pName != null ) {
ObjectInstance lNew = null;
if( pConstructor.getLength() == 0 ) {
- lNew = mServer.createMBean( pCodebase, lName );
+ System.out.println( "XMLAdaptorImpl.createMBean(), create w/o
arguments" );
+ lNew = mServer.createMBean( pCodebase, pName );
}
else {
// Get the Constructor Values
Object[][] lAttributes = getAttributes(
( (Element) pConstructor.item( 0 ) ).getElementsByTagName( "argument"
)
);
+ System.out.println( "XMLAdaptorImpl.createMBean(), create with
arguments" );
lNew = mServer.createMBean(
pCodebase,
- lName,
+ pName,
lAttributes[ 0 ],
(String[]) lAttributes[ 1 ]
);
@@ -172,6 +222,7 @@
);
lReturn = lNew.getObjectName();
+ System.out.println( "XMLAdaptorImpl.createMBean(), Object Name to return:
" + lReturn );
}
}
catch( Exception e ) {
@@ -181,21 +232,18 @@
return lReturn;
}
- public Object invoke( String pOperation, NodeList pObjectName, NodeList
pAttributes ) {
+ public Object invoke( String pOperation, ObjectName pName, NodeList pAttributes )
{
Object lReturn = null;
System.out.println( "XMLAdaptorImpl.invoke(), Operation: " + pOperation );
- if( pOperation != null && !pOperation.equals( "" ) &&
- pObjectName != null && pObjectName.getLength() > 0 )
- {
+ if( pOperation != null && !pOperation.equals( "" ) && pName != null ) {
try {
- ObjectName lName = createObjectName( (Element) pObjectName.item( 0 ) );
if( pAttributes != null && pAttributes.getLength() > 0 ) {
Object[][] lAttributes = getAttributes(
pAttributes
);
// Invoke the method and return the value
lReturn = mServer.invoke(
- lName,
+ pName,
pOperation,
lAttributes[ 0 ],
(String[]) lAttributes[ 1 ]
@@ -204,7 +252,7 @@
else {
// Invoke the method and return the value
lReturn = mServer.invoke(
- lName,
+ pName,
pOperation,
new Object[] {},
new String[] {}
@@ -217,8 +265,109 @@
}
return lReturn;
}
+
+ public Object[] get( ObjectName pName, NodeList pAttributes ) {
+ try {
+ if( pName != null ) {
+ Object[][] lAttributes = getAttributes( pName, pAttributes );
+ String[] lNames = (String[]) lAttributes[ 1 ];
+ return getAttributeValues( mServer.getAttributes( pName, lNames ) );
+ }
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public Object[] set( ObjectName pName, NodeList pAttributes ) {
+ try {
+ if( pName != null ) {
+ Object[][] lAttributes = getAttributes( pName, pAttributes );
+ return applyAttributes( pName, (String[]) lAttributes[ 1 ], lAttributes[ 0
] );
+ }
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public MBeanInfo getMBeanInfo( ObjectName pName ) {
+ try {
+ return mServer.getMBeanInfo( pName );
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public ObjectInstance getObjectInstance( ObjectName pName ) {
+ try {
+ return mServer.getObjectInstance( pName );
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public Boolean isInstanceOf( ObjectName pName, String pCodebase ) {
+ try {
+ return new Boolean( mServer.isInstanceOf( pName, pCodebase ) );
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public Boolean isRegistered( ObjectName pName ) {
+ try {
+ return new Boolean( mServer.isRegistered( pName ) );
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public Object unregisterMBean( ObjectName pName ) {
+ try {
+ mServer.unregisterMBean( pName );
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
// Protected -----------------------------------------------------
+ protected ObjectName getObjectName( NodeList pObjectName ) {
+ return getObjectName( null, pObjectName );
+ }
+
+ protected ObjectName getObjectName( String pName, NodeList pObjectName ) {
+ ObjectName lName = null;
+ try {
+ // Create ObjectName
+ if( pName != null && !pName.equals( "" ) ) {
+ System.out.println( "XMLAdaptorImpl.getObjectName(), name: " + pName );
+ lName = createObjectName( pName );
+ }
+ else if( pObjectName != null && pObjectName.getLength() > 0 ) {
+ System.out.println( "XMLAdaptorImpl.getObjectName(), name element: " +
pObjectName.item( 0 ) );
+ lName = createObjectName( (Element) pObjectName.item( 0 ) );
+ }
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ }
+ return lName;
+ }
+
protected ObjectName createObjectName( String pName )
throws
MalformedObjectNameException
@@ -242,24 +391,36 @@
NodeList lPropertyList = pObjectName.getElementsByTagName( "property" );
for( int i = 0; i < lPropertyList.getLength(); i++ ) {
Element lProperty = (Element) lPropertyList.item( i );
- if( lProperty.hasAttribute( "key" ) && lProperty.hasAttribute( "value" ) ) {
- lProperties.put( lProperty.getAttribute( "key" ), lProperty.getAttribute(
"value" ) );
+ if( lProperty.hasAttribute( "key" ) && lProperty.hasChildNodes() ) {
+ lProperties.put( lProperty.getAttribute( "key" ), ( (Text)
lProperty.getFirstChild()).getData() );
}
}
return new ObjectName( lDomain, lProperties );
}
}
+ /**
+ * Returns a list of attribute objects and types of a given Node List
+ * which must contain a attribute "type" and a text child.
+ *
+ * @param pAttributes List of nodes containing the attribute types and values
+ *
+ * @return First Array contains the objects created from the type and value string,
+ * Second Array contains the types as String
+ **/
protected Object[][] getAttributes( NodeList pAttributes ) {
- Object[] lReturn = new Object[ 2 ];
+ Object[][] lReturn = new Object[ 2 ][ 0 ];
Object[] lValues = new Object[ pAttributes.getLength() ];
String[] lTypes = new String[ pAttributes.getLength() ];
// Loop through argument list and create type and values
for( int i = 0; i < pAttributes.getLength(); i++ ) {
try {
- Element lArgument = (Element) pAttributes.item( 0 );
+ Element lArgument = (Element) pAttributes.item( i );
String lTypeString = lArgument.getAttribute( "type" );
- String lValueString = lArgument.getAttribute( "value" );
+ String lValueString = "";
+ if( lArgument.hasChildNodes() ) {
+ lValueString = ( (Text) lArgument.getFirstChild() ).getData();
+ }
Class lClass = null;
if( mPrimitives.containsKey( lTypeString ) ) {
lClass = (Class) mPrimitives.get( lTypeString );
@@ -280,18 +441,31 @@
lReturn[ 1 ] = lTypes;
return (Object[][]) lReturn;
}
+
+ /**
+ * Returns a list of attribute objects and name of a given Node List
+ * which must contain a attribute "name" and a text child.
+ *
+ * @param pAttributes List of nodes containing the attribute types and values
+ *
+ * @return First Array contains the objects created from the type and value string,
+ * Second Array contains the Attribute Names as String
+ **/
protected Object[][] getAttributes( ObjectName pName, NodeList pAttributes ) {
- Object[] lReturn = new Object[ 2 ];
+ Object[][] lReturn = new Object[ 2 ][ 0 ];
Object[] lValues = new Object[ pAttributes.getLength() ];
- String[] lTypes = new String[ pAttributes.getLength() ];
+ String[] lNames = new String[ pAttributes.getLength() ];
try {
MBeanAttributeInfo[] attributes = mServer.getMBeanInfo( pName
).getAttributes();
// Loop through argument list and create type and values
for( int i = 0; i < pAttributes.getLength(); i++ ) {
- Element lArgument = (Element) pAttributes.item( 0 );
+ Element lArgument = (Element) pAttributes.item( i );
String lNameString = lArgument.getAttribute( "name" );
- String lValueString = lArgument.getAttribute( "value" );
+ String lValueString = "";
+ if( lArgument.hasChildNodes() ) {
+ lValueString = ( (Text) lArgument.getFirstChild() ).getData();
+ }
for( int k = 0; k < attributes.length; k++ ) {
if( attributes[ k ].getName().equals( lNameString ) ) {
String lTypeString = attributes[ k ].getType();
@@ -305,7 +479,7 @@
PropertyEditor lEditor = PropertyEditorManager.findEditor( lClass );
lEditor.setAsText( lValueString );
lValues[ i ] = lEditor.getValue();
- lTypes[ i ] = lClass.getName();
+ lNames[ i ] = lClass.getName();
}
}
}
@@ -314,11 +488,11 @@
e.printStackTrace();
}
lReturn[ 0 ] = lValues;
- lReturn[ 1 ] = lTypes;
+ lReturn[ 1 ] = lNames;
return (Object[][]) lReturn;
}
- protected void applyAttributes(
+ protected Object[] applyAttributes(
ObjectName pName,
String[] pNames,
Object[] pValues
@@ -334,12 +508,22 @@
lList.add( new Attribute( lName, pValues[ i ] ) );
}
}
- mServer.setAttributes( pName, lList );
+ return getAttributeValues( mServer.setAttributes( pName, lList ) );
}
}
}
catch( Exception e ) {
e.printStackTrace();
}
+ return null;
}
+
+ protected Object[] getAttributeValues( AttributeList pList ) {
+ Object[] lReturn = new Object[ pList.size() ];
+ for( int i = 0; i < pList.size(); i++ ) {
+ lReturn[ i ] = ( (Attribute) pList.get( i ) ).getValue();
+ }
+ return lReturn;
+ }
+
}
1.3 +20 -3 jboss/src/main/org/jboss/jmx/server/XMLTestService.java
Index: XMLTestService.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jmx/server/XMLTestService.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLTestService.java 2001/06/25 18:28:52 1.2
+++ XMLTestService.java 2001/06/26 05:29:13 1.3
@@ -24,7 +24,7 @@
*
* @author Andreas Schaefer ([EMAIL PROTECTED])
* @created June 22, 2001
-* @version $Revision: 1.2 $
+* @version $Revision: 1.3 $
*/
public class XMLTestService
extends ServiceMBeanSupport
@@ -75,8 +75,25 @@
// Create Test XML Document
Document lTest =
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
new StringBufferInputStream(
- "<jmx><invoke operation=\"stop\"><object-name
name=\":service=Scheduler\"/>" +
- "</invoke></jmx>"
+ "<jmx>" +
+ "<invoke operation=\"stop\"><object-name
name=\":service=Scheduler\"/></invoke>" +
+ "<create-mbean code=\"org.jboss.util.Scheduler\">" +
+ "<object-name name=\":service=Scheduler\"/>" +
+ "<constructor>" +
+ "<argument type=\"java.lang.String\">:server=Scheduler</argument>" +
+ "<argument
type=\"java.lang.String\">org.jboss.util.Scheduler$SchedulableExample</argument>" +
+ "<argument type=\"java.lang.String\">Schedulable
Test,12345</argument>" +
+ "<argument type=\"java.lang.String\">java.lang.String,int</argument>"
+
+ "<argument type=\"long\">0</argument>" +
+ "<argument type=\"long\">10000</argument>" +
+ "<argument type=\"long\">-1</argument>" +
+ "</constructor>" +
+ "</create-mbean>" +
+ "<set-attribute>" +
+ "<object-name name=\":service=Scheduler\"/>" +
+ "<attribute name=\"PeriodTime\">5000</attribute>" +
+ "</set-attribute>" +
+ "</jmx>"
)
);
System.out.println( "Call invokeXML with: " + lTest );
1.1 jboss/src/main/org/jboss/jmx/server/XMLAdaptor.dtd
Index: XMLAdaptor.dtd
===================================================================
<!--
This DTD describes who the list JMX Calls XML files has
to look like. Please NOTE that the order of the second
level elements (operation calls) doesn't have to be in
a particular order.
-->
<!--
The jmx element is the root element of the jmx.xml file.
ATTENTION: The elements doesn't have to be in a particular
order.
ATTENTION: when the invokeXML( Element ) is used one of
the inner elements of this root element must be handed
over.
-->
<!ELEMENT jmx (create-mbean?, invoke?)>
<!--
This operation creates a MBean. Note that the operation
contains the name of the operation to be invoked and that
you have to have a Object Name. You can either set an
attribute "name" or add the "object-name" element.
-->
<!ELEMENT create-mbean (object-name?, constructor?, attribute*)>
<!--
The Object Name is to create a Name for an MBean.
The Object Name can contain either a "name" attribute
having the info for the ObjectName (<domain name>:<property>*)
form or it can contains the "domain" attribute and a list
of properties.
-->
<!ELEMENT object-name (property*)>
<!--
Contains the Property for the Object Name. It must
contain a "key" attribute for the given value.
-->
<!ELEMENT property (property-value)>
<!--
Contains the Property Value for the Object Name
-->
<!ELEMENT property-value (#PCDATA)>
<!--
Constructor contains the information about a specific, not default
Constructor. If you use the no-args constructor you do not have
to specify the constructor here
-->
<!ELEMENT constructor (argument*)>
<!--
Contains the Argument for a Constructor. It has to have
an attribute "type" which is either the fully qualified class
or the regular datatype name for primitives.
-->
<!ELEMENT argument (argument-value)>
<!--
Contains the Argument Value for a Constructor Argument
-->
<!ELEMENT argument-value (#PCDATA)>
<!--
Attribute contains the value to be set on the given MBean.
It has to have a "name" attribute which must map an attribute
in the MBean (case sensitive).
-->
<!ELEMENT attribute (attribute-value)>
<!--
Contains the Attribute value to be set on the given MBean
-->
<!ELEMENT attribute-value (#PCDATA)>
<!--
Invokes a method on the given MBean
-->
<!ELEMENT invoke (object-name, attribute*)>
<!--
Returns one or serveral attributes form the given MBean.
In this case the attributes child (value) is ignored.
-->
<!ELEMENT get-attribute (object-name, attribute*)>
<!--
Sets and Returns one or serveral attributes form the given MBean
-->
<!ELEMENT set-attribute (object-name, attribute*)>
<!--
Returns the number of registered MBeans
-->
<!ELEMENT mbean-count (object-name)>
<!--
Returns the MBean Info object of the given MBean
-->
<!ELEMENT mbean-info (object-name)>
<!--
Returns the Object Instance object of the given MBean
-->
<!ELEMENT object-instance (object-name)>
<!--
Returns true if the given MBean implements or extends the given
class. Must contain an attribute "code" containing the full
qualified path to check against.
-->
<!ELEMENT is-instance-of (object-name)>
<!--
Returns true if a MBean with this Object Name is registered.
-->
<!ELEMENT is-registered (object-name)>
<!--
Unregister the given MBean.
-->
<!ELEMENT unregister-mbean (object-name)>
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development