[jdom-interest] Re: Getting attribute name/value pairs
Frank Cohen
fcohen at inclusion.net
Wed Jul 19 09:41:53 PDT 2000
I used CVS to get the latest code. Finding the same problem: I get a "java.lang.ClassCastException: org.jdom.Element" exception when I try to cast the Attribute object. Below is the XML document, the source and the exception thrown. Any help would be most appreciated. Thanks, in advance. -Frank
--
<!--
Load 2.0 (alpha 1)
(c) 2000 Frank Cohen. All rights reserved.
This source code is licensed under terms described in the License.txt file.
Description:
This file contains all needed configuration information for Load to operate
For more info check
http://www.inbuilders.com/inbuilders/home.html?igid=G781&rid=R4
or send email to fcohen at inclusioin.net
-->
<load>
<!-- =================================================================== -->
<!-- Initialization values -->
<!-- =================================================================== -->
<load_init_values>
<echo message="Starting Load 2.0 alpha 1"/>
<property name="scripts_directory" value="./scripts"/>
<property name="accept_script_versions" value="2"/>
<property name="log.file" value="./load.log"/>
<property name="log.append" value="true"/>
<property name="log.level" value="6"/>
<property name="url" value=""/>
<property name="cookieok" value="true"/>
<property name="bad_string" value=""/>
<property name="timeout" value="0"/>
<property name="sleeptime" value="0"/>
<property name="threadcount" value="0"/>
</load_init_values>
</load>
<!-- End of file -->
--
file://Title: Load
file://Version: 2.0
file://Copyright: (c) 2000 Frank Cohen. All rights reserved.
file://Author: Frank Cohen
file://Company: INBuilders.com
//
file://Description:
// Commander executes the Load script
// the script files is an XML format
// definitions for the Load script are
// self-documented in this class
//
file://For more info check
// http://www.inbuilders.com/inbuilders/home.html?igid=G781&rid=R4
// or send email to fcohen at inclusioin.net
//
// This source code is licensed under terms described in the License.txt file.
package load;
import java.math.*;
import java.io.*;
import java.io.IOException;
import java.util.*;
import java.net.*;
import org.jdom.*;
import org.jdom.output.XMLOutputter;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.input.DOMBuilder;
/**
* <p><code>commander</code>
* Interprets the Load script, executes elements
* </p>
*
* @author Frank Cohen
* @version 1.0
*/
public class commander {
// Instance of the JDOM XML object for the Load default settings file
SAXBuilder load_info_builder = new SAXBuilder();
// loadui object to display the UI elements
private loadui uiframe;
/** Load default setting file name */
private static final String default_settings = "load_info.xml";
/** <code>scriptsDir</code> which directory to find the scripts **/
public String scriptsDir = "./scripts/";
/** <code>acceptScriptVersions</code> year of this version **/
public int acceptScriptVersions = 2;
/** <code>logFileName</code> log file name **/
public String logFileName = "./load.log";
/** <code>logFileAppendFlag</code> if true, append new log entries to existing file **/
public boolean logFileAppendFlag = true;
/** <code>logLevel</code> 1-Informational, 6 Ludicrous **/
public int logLevel = 6;
/** <code>loadURL</code> base URL to test **/
public String loadURL = "";
/** <code>cookieOk</code> if true, accept cookies from host **/
public boolean cookieOk = true;
/** <code>badString</code> find this during a test and abort **/
public String badString = "";
/** <code>timeoutValue</code> milliseconds to timeout **/
public int timeoutValue = 60000;
/** <code>sleepTime</code> milliseconds to sleep between requests **/
public int sleepTime = 1000;
/** <code>threadCount</code> number of simulated users **/
public int threadCount = 1;
/** Get and keep the reference to the loadui object */
public void initialize_commander(loadui theframe)
{
uiframe=theframe;
}
/**
* <p><code>echo</code>
* Repeats the gaven String to the log and screen
* </p>
*/
public void echo(String theString)
{
uiframe.show(theString);
}
public void start()
{
// Load the entire document into memory
// from the network or file system
try
{
// Gets the Load settings file, parses it into a DOM tree
Document doc = load_info_builder.build( default_settings );
// If there are no well-formedness errors,
// then no exception is thrown
uiframe.show( default_settings + " is well formed.");
// Only read Load setting files
Element load_set = doc.getRootElement();
if ( load_set.getName().equals("load") )
{
// This is a load setting file so parse its contents
loadui.show( default_settings + " parsing contents");
// Within the load element is the load_init_values group
// These are the elements we want to set the defaults for Load
List children = load_set.getChild("load_init_values").getMixedContent();
Iterator iterator = children.iterator();
while (iterator.hasNext())
{
Object o = iterator.next();
if (o instanceof Element)
{
Element p = (Element) o;
// echo elements are comments that get displayed in the UI
if ( p.getName().equals("echo") )
{
echo( p.getAttribute("message").getValue() );
}
// property elements are simple name = value pairs that set a
// public variable in the commander object
if ( p.getName().equals("property") )
{
List property_list = p.getAttributes();
Iterator property_iterator = property_list.iterator();
echo( property_list.size() + " = property list size");
while ( property_iterator.hasNext() )
{
Object q = iterator.next();
Attribute r = (Attribute) q;
echo(r.getName());
echo(r.getValue());
if (q instanceof Attribute) { echo("attribute");}
if (q instanceof Element) { echo("element> " + ((Element) q).getName() );}
if (q instanceof String) { echo("string");}
}
}
}
}
}
else
{
loadui.show( default_settings + "does not appear to be a Load settings file");
}
}
catch (JDOMException e) { // indicates a well-formedness or other error
uiframe.show( default_settings + " is not well formed.");
uiframe.show( e.getMessage() );
}
}
}
--
Exception occurred during event dispatching:
java.lang.ClassCastException: org.jdom.Element
at load.commander.start(commander.java:159)
at load.loadui.buttonRun_actionPerformed(loadui.java:208)
at load.loadui$4.actionPerformed(loadui.java:124)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:10
66)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
ctButton.java:1101)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:378)
at javax.swing.JToggleButton$ToggleButtonModel.setPressed(Compiled Code)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:217)
at java.awt.Component.processMouseEvent(Compiled Code)
at java.awt.Component.processEvent(Compiled Code)
at java.awt.Container.processEvent(Compiled Code)
at java.awt.Component.dispatchEventImpl(Compiled Code)
at java.awt.Container.dispatchEventImpl(Compiled Code)
at java.awt.Component.dispatchEvent(Compiled Code)
at java.awt.LightweightDispatcher.retargetMouseEvent(Compiled Code)
at java.awt.LightweightDispatcher.processMouseEvent(Compiled Code)
at java.awt.LightweightDispatcher.dispatchEvent(Compiled Code)
at java.awt.Container.dispatchEventImpl(Compiled Code)
at java.awt.Window.dispatchEventImpl(Compiled Code)
at java.awt.Component.dispatchEvent(Compiled Code)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:258)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:68)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20000719/803b2e4a/attachment.htm
More information about the jdom-interest
mailing list