--- projects/cms/source/util/uk/org/iscream/cms/util/XMLPacketMaker.java 2000/11/30 02:38:17 1.5 +++ projects/cms/source/util/uk/org/iscream/cms/util/XMLPacketMaker.java 2001/03/01 16:55:11 1.10 @@ -10,13 +10,11 @@ import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; -import uk.ac.ukc.iscream.core.*; - /** * XMLPacketMaker - Creates an XMLPacket object. * - * @author $Author: ajm $ - * @version $Id: XMLPacketMaker.java,v 1.5 2000/11/30 02:38:17 ajm Exp $ + * @author $Author: tdb $ + * @version $Id: XMLPacketMaker.java,v 1.10 2001/03/01 16:55:11 tdb Exp $ */ public class XMLPacketMaker extends HandlerBase { @@ -25,20 +23,31 @@ public class XMLPacketMaker extends HandlerBase { /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.5 $"; + public final String REVISION = "$Revision: 1.10 $"; //---STATIC METHODS--- //---CONSTRUCTORS--- - // Constructor for accepting XML input. + /** + * Constructor for accepting XML input. + * + * @param xml A String of XML to process. + */ public XMLPacketMaker (String xml) { _xml = xml; } //---PUBLIC METHODS--- - public XMLPacket createXMLPacket() { + /** + * Method to create an XML packet from the data this + * class was constructed with. + * + * @return an XMLPacket representing the XML String given + * @throws InvalidXMLException if the XML cannot be parsed + */ + public XMLPacket createXMLPacket() throws InvalidXMLException { // Create the XMLPacket to store values in. XMLPacket packet = new XMLPacket(); @@ -46,18 +55,16 @@ public class XMLPacketMaker extends HandlerBase { // Use the default (non-validating) parser SAXParserFactory factory = SAXParserFactory.newInstance(); try { - // Parse the input InputSource inputSource = new InputSource(new StringReader(_xml)); SAXParser saxParser = factory.newSAXParser(); saxParser.parse(inputSource, new XMLStringParser(packet)); - } catch (Exception e) { - _logger.write(this.toString(), Logger.WARNING, "An invalid XML UDP packet has been detected: "+packet.printAll()); - return null; + // couldn't parse the XML for some reason + throw new InvalidXMLException("Could not parse the XML: "+_xml); } - + // parsed successfully, return the packet return packet; } @@ -65,10 +72,16 @@ public class XMLPacketMaker extends HandlerBase { * Overrides the {@link java.lang.Object#toString() Object.toString()} * method to provide clean logging (every class should have this). * + * This uses the uk.ac.ukc.iscream.util.NameFormat class + * to format the toString() + * * @return the name of this class and its CVS revision */ public String toString() { - return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; + return FormatName.getName( + _name, + getClass().getName(), + REVISION); } //---PRIVATE METHODS--- @@ -77,8 +90,21 @@ public class XMLPacketMaker extends HandlerBase { //---ATTRIBUTES--- + /** + * Holds the xml + */ String _xml; - Logger _logger = ReferenceManager.getInstance().getLogger(); + + /** + * This is the friendly identifier of the + * component this class is running in. + * eg, a Filter may be called "filter1", + * If this class does not have an owning + * component, a name from the configuration + * can be placed here. This name could also + * be changed to null for utility classes. + */ + private String _name = null; //---STATIC ATTRIBUTES---