Go AVDN
Metadata Diagnostic

You can dump arbitrary metadata in any structure from any MetaBundle with the following code:

private static void dump(Meta m, String indent)
{
   System.out.print(indent + "<" + m.getName());
   for (Map.Entry<String, String> entry : m.getAttributes().entrySet())
      System.out.print(" " + entry.getKey() + "='" + entry.getValue()
            + "'");
   System.out.println("> @ " + m.getLocation());

   String childIndent = indent + "  ";
   System.out.print(childIndent + "{{");
   System.out.print(m.getString().trim());
   System.out.println("}}");

   Meta[] sms = null;
   try
   {
      sms = m.getSubMetaArray("*");
   }
   catch (MetaNotFoundException e)
   {
   }
   if (sms != null) for (Meta sm : sms)
      dump(sm, childIndent);

   System.out.println(indent + "</" + m.getName() + ">");
}

public static void main(String[] args) throws MetaNotFoundException
{
   if (args.length < 1)
   {
      System.err
            .println("Usage: java tutor.meta.Diag <MetaBundle Name> [XPath]");
      return;
   }

   Locale sysLocale = new Locale(System.getProperty("user.language"),
         System.getProperty("user.country"));

   MetaBundle meta = MetaBundle.get(args[0]);
   if (args.length > 1)
      for (Meta m : meta.getMetaArray(args[1], sysLocale))
         dump(m, "");
   else
      dump(meta.getRootMeta(sysLocale), "");
}

This snippet is from tutor/meta/Diag.java

tutor.meta.Diag can be run locally through the same approach of Running the Brief Demo Application, just type in tutor.meta.Diag instead of tutor.meta.Brief at the last step.

A sample running journal on MS-Windows™ is shown below:

C:\Documents and Settings\Compl>cd /d d:\study\av6\tutorials\

D:\study\av6\tutorials>set CLASSPATH=examples;classes;run\allClasses.jar;d:\apps\av6\av6base.jar

D:\study\av6\tutorials>java tutor.meta.Diag
Usage: java tutor.meta.Diag <MetaBundle Name> [<XPath>]

D:\study\av6\tutorials>

If try to dump all tips of the Brief Demo App:

D:\study\av6\tutorials>java -Duser.language=en -Duser.country=US tutor.meta.Diag tutor.meta.Brief tips
<tips> @ tutor.meta.Brief(XML):tips[0]
  {{}}
  <tip title='Tips'> @ tutor.meta.Brief(XML):tips[0]/*[0]
    {{In this panel you get tips about how to play with this demo, see other tips
under each Tab.
<br>
Tip tabs here are populated by meta array <code>tips/tip</code> inside MetaBundle
<code>tutor/meta/Brief.meta</code>}}
  </tip>
  <tip title='Navigating'> @ tutor.meta.Brief(XML):tips[0]/*[1]
    {{Select a package or class in the left tree to see its localized name and
description in the right panel. These informations is from various
<em>.meta</em> files on the classpath, organized as MetaBundles.}}
  </tip>
  <tip title='Bold Classes'> @ tutor.meta.Brief(XML):tips[0]/*[2]
    {{Each <b>Bold</b> class in the left tree is marked as having localized name/desc.
This marking is via the <code>localized</code> metatree in
<code>tutor/meta/Brief.meta</code>, open that file and you'll see and be able
to modify it.}}
  </tip>
  <tip title='Bold Packages'> @ tutor.meta.Brief(XML):tips[0]/*[3]
    {{Each <b>Bold</b> package in the left tree either contains localized name/desc
itself, or contains at lease one <b>Bold</b> class or package. The package
itself may or may not have localized name/desc.}}
  </tip>
  <tip title='Info Inheritance'> @ tutor.meta.Brief(XML):tips[0]/*[4]
    {{Don't bother on seeing a package showing its parent package's name and
desc, that's intended to demo the inheritance feature of Meta Facility.}}
  </tip>
  <tip title='Hot Reloading'> @ tutor.meta.Brief(XML):tips[0]/*[5]
    {{If you are running this demo locally, try add, remove, or modify those
<em>.meta</em> files in local classpath, then press <b>[Reload MetaBundles]</b>
button. You'll see your changes take effect immediately.}}
  </tip>
</tips>

D:\study\av6\tutorials>

Pay attention to the Locations dumped for each node right to its start tag, you get to know where the node actually is from this value.

And if a nonexistent XPath had been requested, a MetaNotFoundException will be thrown, its stack trace will tell you the path that Meta Facility had ever attempted before gave up.

D:\study\av6\tutorials>java -Duser.language=en -Duser.country=US tutor.meta.Diag tutor.meta.Brief tips/joke
Exception in thread "main" av.meta.MetaNotFoundException: tips/joke
        in tutor.meta.Brief_en_US
        in tutor.meta.Brief_en
        in tutor.meta.Brief(XML)
        in tutor.meta_en_US
        in tutor.meta_en
        in tutor.meta
        in tutor_en_US
        in tutor_en
        in tutor
        in default_en_US
        in default_en
        in default(XML)
        at av.meta.Meta.getSubMetaArray(Meta.java:605)
        at av.meta.MetaOnXML.getSubMetaArray(MetaOnXML.java:861)
        at av.meta.Meta.getSubMetaArray(Meta.java:608)
        at av.meta.Meta.getSubMetaArray(Meta.java:608)
        at av.meta.MetaBundle.getMetaArray(MetaBundle.java:1454)
        at tutor.meta.Diag.main(Diag.java:58)

D:\study\av6\tutorials>