org.objectweb.jonas.resource
Class ArchiveConfigMBean

java.lang.Object
  extended byorg.apache.commons.modeler.BaseModelMBean
      extended byorg.objectweb.jonas.resource.ArchiveConfigMBean
All Implemented Interfaces:
javax.management.DynamicMBean, javax.management.MBeanRegistration, javax.management.modelmbean.ModelMBean, javax.management.modelmbean.ModelMBeanNotificationBroadcaster, javax.management.NotificationBroadcaster, javax.management.PersistentMBean
Direct Known Subclasses:
RarConfigMBean

public class ArchiveConfigMBean
extends org.apache.commons.modeler.BaseModelMBean

A generic archive configuration MBean class which provides the ability to extract an XML configuration file from an archive (jar/war/ear/rar) as either a Document or as a String of XML. As well as storing an updated configuration file.

Author:
Patrick Smith, Greg Lapouchnian

Field Summary
 
Fields inherited from class org.apache.commons.modeler.BaseModelMBean
attributeBroadcaster, attributes, generalBroadcaster, info, oname, registry, resource, resourceType, source
 
Constructor Summary
ArchiveConfigMBean()
          Default constructor, constructs a BaseModelMBean.
 
Method Summary
 void addXML(java.lang.String archiveName, java.lang.String xmlFilePath, java.lang.String docString)
           
 void createArchiveWithXmlFile(java.lang.String archiveName, java.lang.String xmlFilePath, java.lang.String doc)
           
 org.w3c.dom.Document extractDocument(java.lang.String archiveName, java.lang.String xmlFilePath)
          Extracts a Document representation of the XML file provided by xmlFilePath within the archive archiveName.
 java.lang.String extractXML(java.lang.String archiveName, java.lang.String xmlFilePath)
          Extracts a String representation of the XML file provided by xmlFilePath within the archive archiveName.
protected  org.xml.sax.EntityResolver getEntityResolver()
          Return an EntityResolver for this MBean.
protected  java.util.List getSchemaList()
          Get a list of possible schema locations to validate against.
 void saveXML(java.lang.String archiveName, java.lang.String xmlFilePath, org.w3c.dom.Document doc)
          Saves the given org.w3c.dom.Document back into an archive of the name given by archiveName.
 void verifyDocument(org.w3c.dom.Document doc)
          Verifies that the Document is correct with respect to the schemas associated with the XML.
 
Methods inherited from class org.apache.commons.modeler.BaseModelMBean
addAttributeChangeNotificationListener, addNotificationListener, createDefaultModelMBeanInfo, createResource, getAttribute, getAttributes, getClassName, getManagedResource, getMBeanInfo, getModelerType, getNotificationInfo, getObjectName, getRegistry, initModelInfo, invoke, isModelMBeanInfoValid, load, postDeregister, postRegister, preDeregister, preRegister, removeAttributeChangeNotificationListener, removeAttributeChangeNotificationListener, removeNotificationListener, removeNotificationListener, removeNotificationListener, sendAttributeChangeNotification, sendAttributeChangeNotification, sendNotification, sendNotification, setAttribute, setAttributes, setManagedResource, setModeledType, setModelMBeanInfo, setRegistry, store, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArchiveConfigMBean

public ArchiveConfigMBean()
                   throws javax.management.MBeanException
Default constructor, constructs a BaseModelMBean.

Throws:
javax.management.MBeanException - from the super class.
Method Detail

createArchiveWithXmlFile

public void createArchiveWithXmlFile(java.lang.String archiveName,
                                     java.lang.String xmlFilePath,
                                     java.lang.String doc)
                              throws java.io.IOException
Throws:
java.io.IOException

addXML

public void addXML(java.lang.String archiveName,
                   java.lang.String xmlFilePath,
                   java.lang.String docString)
            throws java.io.IOException
Throws:
java.io.IOException

saveXML

public void saveXML(java.lang.String archiveName,
                    java.lang.String xmlFilePath,
                    org.w3c.dom.Document doc)
             throws java.io.IOException
Saves the given org.w3c.dom.Document back into an archive of the name given by archiveName. The Java Jar/Archive classes apparently do not provide support for simply updating a file in place in an archive, so a temporary archive must be created and have the contents of the existing archive copied over (with the exception of the updated Document file) then remove the existing archive and rename the temporary one.

Parameters:
archiveName - The name (and path) of the archive to updated.
xmlFilePath - The path within the archive to the XML file being updated.
doc - The Document representation of the XML file being updated.
Throws:
java.io.IOException - If the updating fails.

verifyDocument

public void verifyDocument(org.w3c.dom.Document doc)
                    throws org.xml.sax.SAXException,
                           java.io.IOException
Verifies that the Document is correct with respect to the schemas associated with the XML. If no exception is thrown then the XML is either valid or no schemas were available for this XML. In which case the Document can be considered verified.

Parameters:
doc - The Document to validate.
Throws:
org.xml.sax.SAXException - If the document fails validation.
java.io.IOException - If there is an error opening a schema.

getEntityResolver

protected org.xml.sax.EntityResolver getEntityResolver()
Return an EntityResolver for this MBean.

Returns:
an EntityResolver for this MBean.

extractDocument

public org.w3c.dom.Document extractDocument(java.lang.String archiveName,
                                            java.lang.String xmlFilePath)
                                     throws java.lang.Exception
Extracts a Document representation of the XML file provided by xmlFilePath within the archive archiveName.

Parameters:
archiveName - The archive from which to extract the XML.
xmlFilePath - The path within the archive to the XML file.
Returns:
A document representation of the XML file.
Throws:
java.lang.Exception - if the document cannot be extracted.

extractXML

public java.lang.String extractXML(java.lang.String archiveName,
                                   java.lang.String xmlFilePath)
                            throws java.lang.Exception
Extracts a String representation of the XML file provided by xmlFilePath within the archive archiveName.

Parameters:
archiveName - The archive from which to extract the XML.
xmlFilePath - The path within the archive to the XML file.
Returns:
A String representation of the XML file.
Throws:
java.lang.Exception - if the XML cannot be extracted.

getSchemaList

protected java.util.List getSchemaList()
Get a list of possible schema locations to validate against.

Returns:
a list of schemas that are available for this type of deployment descriptor.