commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: [Modeler] Can I represent inheritance in the mbeans-descriptors.xml file?
Date Tue, 14 Oct 2003 16:22:55 GMT
JD Evora wrote:

> Hi everybody,
>
> I am using commons-modeler for instrument an application that has a 
> lot of sub classes with a few different details.
>
> Can I define a reference to the common base attributes and operation 
> in the mbeans-descriptors.xml file or do I have to repeat the whole 
> description of attributes and operation for each descendant class? 


The simplest way to do this is to leverage the fact that XML has a 
sort-of funky mechanism to include other files.  Simply put the chunk 
you want to copy into a separate document (typically in the same 
directory as your configuration file) -- let's say it is called 
"repeated.xml" -- and do something like this in your configuration file:

  <!DOCTYPE mbeans-descriptors PUBLIC
    "-//Apache Software Foundation//DTD Model MBeans Configuration File"
    "http://jakarta.apache.org/commons/dtds/mbeans-descriptors.dtd" [
    <!ENTITY repeated SYSTEM "repeated.xml">
  ]>

<mbeans-descriptors>

    <mbean name="base" className="mbeans.BaseMBean">
        <attribute name="unique" .../>
        &repeated;
    </mbean>

    ...

</mbean-descriptors>


One restriction of this is that the XML parser has to know the URL of 
the configuration file you are parsing.  If you're using Digester to 
parse it (for example), you'll need to do something like this:

    InputStream input = null;
    try {
        URL url = "file:///home/craigmcc/my-mbeans.xml"; // Or any other 
URL to your config file
        InputSource source = new InputSource(url.toExternalForm());
        input = url.openStream();
        source.setByteStream(input);
        digester.parse(source);
    } catch ( ... ) {
        ...
    }

If this approach doesn't work, you can always use shell scripts (or 
corresponding Ant commands) to assemble the "real" configuation file 
from various pieces.

Craig



>
> e.g. with:       beans.Child extends beans.Base
> <mbean         name="base"
>            className="mbeans.BaseMBean"
>                 type="beans.Base">
>    <attribute   name="name"
>                 type="java.lang.String"/>
>    <attribute   name="attribute1"
>                 type="int"
>            writeable="false"/>
>    <attribute   name="attribute2"
>                 type="int"
>            writeable="false"/>
>  </mbean>
>
>
> Is there some way to avoid tho describe the attributes name, 
> attribute1 and attribute2 in the bmean child?
> <mbean         name="child"
>            className="mbeans.ChildMBean"
>                 type="beans.Child">
>    <attribute   name="name"                     \
>                 type="java.lang.String"/>          |
>    <attribute   name="attribute1"                |    is there any way
>                 type="int"                                 >    for avoid
>            writeable="false"/>                        |   repeating  
> that?
>    <attribute   name="attribute2"                |
>                 type="int"                                 |
>            writeable="false"/>                        /
>   <attribute   name="attribute3"                                    
> type="java.lang.String"/>   <attribute   
> name="attribute4"                                    
> type="java.lang.String"/>  </mbean>
>
>
> Cheers
>    JD
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message