XML

All JavaBeans loaded by the Tweek Java GUI are describe by at least one XML file. The XML file can contain information about many Beans or about a single Bean. The XML file itself is a “beanlist” document. The four Bean categories, described above, each have an XML element that has children giving information about the specific Bean. The elements are <service>, <viewer>, <guipanel>, and <generic>.

All Bean XML entries must contain a <file> element. Through its source attribute, this element provides the path to the JAR file that contains the full Bean code. When specifying the JAR file path, environment variables may be used. They must use the syntax ${ENV_VAR} (the curly braces are required). The class element gives the fully qualified name of the class stored within the JAR file that will be instantiated. The extension .class must not be specified. This is to allow the use of serialized classes which have the extension .ser. The Tweek Bean-loading code will figure out what is available and take the right actions.

In addition to the <file> element, a <dependencies> element may be specified. Dependencies of the Bean may be named as external JAR files or other Beans may be listed therein. The <dependencies> element may contain zero of more elements of type <jar> and/or <bean>. The <jar> element has a single attribute, path, which gives the path (a semi-colon separated list of directories) where the JAR file may be found. The contents of the <jar> element defines the name of the JAR file. The <bean> element's contents defines the name of the Bean that the current Bean depends on.

Of the four Bean categories, the XML for Panel Beans can contain the most information. In addition to the previously mentioned elements, Panel Bean entries may have two optional elements: <tree> and <icon>. The element <tree> specifies the path within the Bean tree hierarchy where the Panel Bean will be placed. The path is given as a /-separated list of directories. If the named path does not exist when the Bean is loaded, it will be created. The element <icon> names a custom icon for the Bean and a tool-tip. An example of a Panel Bean XML entry is shown in Example 2.1, “PlexusGraphView.xml snippet”. Note that this is not the full file—it is only the <guipanel> element for a single Bean.

Example 2.1. PlexusGraphView.xml snippet

<guipanel name="Graph View">
  <file name="${PLX_BASE_DIR}/bin/beans/PlexusGraphView.jar" 
        class="plx.graphview.GraphView" />
  <tree path="/" />
  <dependencies>
    <jar path="${PLX_BASE_DIR}/bin">openjgraph.jar</jar>
    <jar path="${PLX_BASE_DIR}/bin">jgraph.jar</jar>
    <jar path="${PLX_BASE_DIR}/bin">PlexusComm.jar</jar>
  </dependencies>
  <icon source="jar:file:${PLX_BASE_DIR}/bin/beans/PlexusGraphView.jar!/plx/graphview/icon.gif"
        tooltip="Plexus Network Graph Visualization" />
</guipanel>

This shows the use of all the elements that may be children of <guipanel>. Note that the source attribute of <icon> gets its icon image using a JAR URL.

Another example XML file is shown in Example 2.2, “Viewers.xml”. This is the actual file used to load the two Viewer Beans that come with the Tweek distribution. This is a complete file containing two Viewer Bean entries.

Example 2.2. Viewers.xml

<?xml version="1.0" encoding="UTF-8"?>
<beanlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="http://www.vrjuggler.org/tweek/xsd/1.1/beanlist.xsd">
  <viewer name="Tree Viewer">
    <file name="${TWEEK_BASE_DIR}/bin/beans/Viewers.jar" 
          class="org.vrjuggler.tweek.treeviewer.BeanTreeViewer" />
  </viewer>
  <viewer name="Icon Viewer">
    <file name="${TWEEK_BASE_DIR}/bin/beans/Viewers.jar" 
          class="org.vrjuggler.tweek.iconviewer.BeanIconViewer" />
  </viewer>
</beanlist>