From 6424adf26d2356229214453398ef86632a8443e4 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 23 Jun 2006 19:40:55 +0000 Subject: [PATCH] More log fixing. The tools package will move to Nenya. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4215 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- build.xml | 2 +- src/java/com/threerings/NaryaLog.java | 4 +- .../com/threerings/io/ObjectInputStream.java | 10 +- .../com/threerings/io/ObjectOutputStream.java | 2 +- src/java/com/threerings/io/Streamer.java | 34 ++--- .../threerings/tools/CompiledConfigTask.java | 132 ------------------ .../tools/xml/CompiledConfigParser.java | 70 ---------- .../threerings/tools/xml/NestableRuleSet.java | 83 ----------- .../threerings/tools/xml/NestableWriter.java | 39 ------ 9 files changed, 24 insertions(+), 352 deletions(-) delete mode 100644 src/java/com/threerings/tools/CompiledConfigTask.java delete mode 100644 src/java/com/threerings/tools/xml/CompiledConfigParser.java delete mode 100644 src/java/com/threerings/tools/xml/NestableRuleSet.java delete mode 100644 src/java/com/threerings/tools/xml/NestableWriter.java diff --git a/build.xml b/build.xml index a1f0f2aac..f6b71f1c7 100644 --- a/build.xml +++ b/build.xml @@ -158,9 +158,9 @@ + - diff --git a/src/java/com/threerings/NaryaLog.java b/src/java/com/threerings/NaryaLog.java index d1b87ec89..878194195 100644 --- a/src/java/com/threerings/NaryaLog.java +++ b/src/java/com/threerings/NaryaLog.java @@ -24,8 +24,8 @@ package com.threerings; import java.util.logging.Logger; /** - * A placeholder class that contains a reference to the log object used by - * this project. + * A placeholder class that contains a reference to the log object used by this + * project. */ public class NaryaLog { diff --git a/src/java/com/threerings/io/ObjectInputStream.java b/src/java/com/threerings/io/ObjectInputStream.java index 5ce7d2861..cc3793f1a 100644 --- a/src/java/com/threerings/io/ObjectInputStream.java +++ b/src/java/com/threerings/io/ObjectInputStream.java @@ -29,7 +29,7 @@ import java.util.HashMap; import com.samskivert.util.HashIntMap; import com.samskivert.util.StringUtil; -import com.threerings.presents.Log; +import static com.threerings.NaryaLog.log; /** * Used to read {@link Streamable} objects from an {@link InputStream}. @@ -92,7 +92,7 @@ public class ObjectInputStream extends DataInputStream // a zero code indicates a null value if (code == 0) { if (STREAM_DEBUG) { - Log.info(hashCode() + ": Read null."); + log.info(hashCode() + ": Read null."); } return null; @@ -117,7 +117,7 @@ public class ObjectInputStream extends DataInputStream Class sclass = Class.forName(cname, true, _loader); Streamer streamer = Streamer.getStreamer(sclass); if (STREAM_DEBUG) { - Log.info(hashCode() + ": New class '" + cname + "'."); + log.info(hashCode() + ": New class '" + cname + "'."); } // sanity check @@ -137,10 +137,10 @@ public class ObjectInputStream extends DataInputStream // sanity check if (cmap == null) { // this will help with debugging - Log.warning("Internal stream error, no class metadata " + + log.warning("Internal stream error, no class metadata " + "[code=" + code + ", ois=" + this + "]."); Thread.dumpStack(); - Log.warning("ObjectInputStream mappings " + + log.warning("ObjectInputStream mappings " + StringUtil.toString(_classmap.entrySet()) + "."); String errmsg = "Read object code for which we " + diff --git a/src/java/com/threerings/io/ObjectOutputStream.java b/src/java/com/threerings/io/ObjectOutputStream.java index f538f84c3..98519ddd3 100644 --- a/src/java/com/threerings/io/ObjectOutputStream.java +++ b/src/java/com/threerings/io/ObjectOutputStream.java @@ -182,7 +182,7 @@ public class ObjectOutputStream extends DataOutputStream "defaultWriteObject() called illegally."); } -// Log.info("Writing default [cmap=" + _streamer + +// log.info("Writing default [cmap=" + _streamer + // ", current=" + _current + "]."); // write the instance data diff --git a/src/java/com/threerings/io/Streamer.java b/src/java/com/threerings/io/Streamer.java index d20ba33b4..8ca04960d 100644 --- a/src/java/com/threerings/io/Streamer.java +++ b/src/java/com/threerings/io/Streamer.java @@ -38,7 +38,7 @@ import java.util.HashMap; import com.samskivert.util.ClassUtil; -import com.threerings.presents.Log; +import static com.threerings.NaryaLog.log; /** * Handles the streaming of {@link Streamable} instances as well as a set @@ -102,7 +102,7 @@ public class Streamer // create a streamer for this class and cache it if (ObjectInputStream.STREAM_DEBUG) { - Log.info("Creating a streamer for '" + target.getName() + "'."); + log.info("Creating a streamer for '" + target.getName() + "'."); } // create our streamer in a privileged block so that it can @@ -140,7 +140,7 @@ public class Streamer if (useWriter && _writer != null) { try { if (ObjectInputStream.STREAM_DEBUG) { - Log.info("Writing with writer " + + log.info("Writing with writer " + "[class=" + _target.getName() + "]."); } _writer.invoke(object, new Object[] { out }); @@ -149,7 +149,6 @@ public class Streamer if (t instanceof InvocationTargetException) { t = ((InvocationTargetException)t).getTargetException(); } - Log.logStackTrace(t); if (t instanceof IOException) { throw (IOException)t; } @@ -212,12 +211,11 @@ public class Streamer } try { if (ObjectInputStream.STREAM_DEBUG) { - Log.info("Writing field [class=" + _target.getName() + + log.info("Writing field [class=" + _target.getName() + ", field=" + field.getName() + "]."); } fm.writeField(field, object, out); } catch (Exception e) { - Log.logStackTrace(e); String errmsg = "Failure writing streamable field " + "[class=" + _target.getName() + ", field=" + field.getName() + "]"; @@ -242,14 +240,14 @@ public class Streamer if (_target.isArray()) { int length = in.readInt(); if (ObjectInputStream.STREAM_DEBUG) { - Log.info(in.hashCode() + ": Creating array '" + + log.info(in.hashCode() + ": Creating array '" + _target.getComponentType().getName() + "[" + length + "]'."); } return Array.newInstance(_target.getComponentType(), length); } else { if (ObjectInputStream.STREAM_DEBUG) { - Log.info(in.hashCode() + ": Creating object '" + + log.info(in.hashCode() + ": Creating object '" + _target.getName() + "'."); } return _target.newInstance(); @@ -284,7 +282,7 @@ public class Streamer if (useReader && _reader != null) { try { if (ObjectInputStream.STREAM_DEBUG) { - Log.info(in.hashCode() + ": Reading with reader '" + + log.info(in.hashCode() + ": Reading with reader '" + _target.getName() + "." + _reader.getName() + "()'."); } @@ -294,7 +292,6 @@ public class Streamer if (t instanceof InvocationTargetException) { t = ((InvocationTargetException)t).getTargetException(); } - Log.logStackTrace(t); if (t instanceof IOException) { throw (IOException)t; } @@ -306,7 +303,7 @@ public class Streamer } if (ObjectInputStream.STREAM_DEBUG) { - Log.info(in.hashCode() + ": Reading '" + _target.getName() + "'."); + log.info(in.hashCode() + ": Reading '" + _target.getName() + "'."); } // if we're reading in an array, do some special business @@ -325,14 +322,14 @@ public class Streamer for (int ii = 0; ii < length; ii++) { if (mask.isSet(ii)) { if (ObjectInputStream.STREAM_DEBUG) { - Log.info(in.hashCode() + + log.info(in.hashCode() + ": Reading fixed element '" + ii + "'."); } Object element = _delegate.createObject(in); in.readBareObject(element, _delegate, useReader); Array.set(object, ii, element); } else if (ObjectInputStream.STREAM_DEBUG) { - Log.info(in.hashCode() + + log.info(in.hashCode() + ": Skipping null element '" + ii + "'."); } } @@ -341,7 +338,7 @@ public class Streamer // otherwise we had to write each object out individually for (int ii = 0; ii < length; ii++) { if (ObjectInputStream.STREAM_DEBUG) { - Log.info(in.hashCode() + + log.info(in.hashCode() + ": Reading free element '" + ii + "'."); } Array.set(object, ii, in.readObject()); @@ -364,7 +361,7 @@ public class Streamer } try { if (ObjectInputStream.STREAM_DEBUG) { - Log.info(in.hashCode() + + log.info(in.hashCode() + ": Reading field '" + field.getName() + "'."); } // gracefully deal with objects that have had new fields @@ -372,12 +369,11 @@ public class Streamer if (in.available() > 0) { fm.readField(field, object, in); } else { - Log.info("Streamed instance missing field (probably " + + log.info("Streamed instance missing field (probably " + "newly added) [class=" + _target.getName() + ", field=" + field.getName() + "]."); } } catch (Exception e) { - Log.logStackTrace(e); String errmsg = "Failure reading streamable field " + "[class=" + _target.getName() + ", field=" + field.getName() + "]"; @@ -386,7 +382,7 @@ public class Streamer } if (ObjectInputStream.STREAM_DEBUG) { - Log.info(in.hashCode() + ": Read object '" + object + "'."); + log.info(in.hashCode() + ": Read object '" + object + "'."); } } @@ -440,7 +436,7 @@ public class Streamer for (int ii = 0; ii < fcount; ii++) { _marshallers[ii] = FieldMarshaller.getFieldMarshaller(_fields[ii]); if (ObjectInputStream.STREAM_DEBUG) { - Log.info("Using " + _marshallers[ii] + " for " + + log.info("Using " + _marshallers[ii] + " for " + _target.getName() + "." + _fields[ii].getName() + "."); } } diff --git a/src/java/com/threerings/tools/CompiledConfigTask.java b/src/java/com/threerings/tools/CompiledConfigTask.java deleted file mode 100644 index b40860887..000000000 --- a/src/java/com/threerings/tools/CompiledConfigTask.java +++ /dev/null @@ -1,132 +0,0 @@ -// -// $Id$ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.tools; - -import java.io.File; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Iterator; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.FileSet; - -import com.samskivert.util.FileUtil; - -import com.threerings.tools.xml.CompiledConfigParser; -import com.threerings.util.CompiledConfig; - -/** - * Used to parse configuration information from an XML file and create the - * serialized representation that is used by the client and server. - */ -public class CompiledConfigTask extends Task -{ - public void setParser (String parser) - { - _parser = parser; - } - - public void setConfigdef (File configdef) - { - _configdef = configdef; - } - - public void setTarget (File target) - { - _target = target; - } - - public void addFileset (FileSet set) - { - _filesets.add(set); - } - - public void execute () throws BuildException - { - // instantiate and sanity check the parser class - Object pobj = null; - try { - Class pclass = Class.forName(_parser); - pobj = pclass.newInstance(); - } catch (Exception e) { - throw new BuildException("Error instantiating config parser", e); - } - if (!(pobj instanceof CompiledConfigParser)) { - throw new BuildException("Invalid parser class: " + _parser); - } - CompiledConfigParser parser = (CompiledConfigParser)pobj; - - // if we have a single file and target specified, do those - if (_configdef != null) { - parse(parser, _configdef, _target); - } - - // deal with the filesets - for (Iterator iter = _filesets.iterator(); iter.hasNext(); ) { - FileSet fs = (FileSet)iter.next(); - DirectoryScanner ds = fs.getDirectoryScanner(getProject()); - File fromDir = fs.getDir(getProject()); - String[] srcFiles = ds.getIncludedFiles(); - for (int ii = 0; ii < srcFiles.length; ii++) { - File confdef = new File(fromDir, srcFiles[ii]); - parse(parser, confdef, null); - } - } - } - - protected void parse (CompiledConfigParser parser, File confdef, File target) - throws BuildException - { - // make sure the source file exists - if (!confdef.exists()) { - String errmsg = "Config definition file not found: " + confdef; - throw new BuildException(errmsg); - } - - // if no target was specified, resuffix the source file as to .dat - if (target == null) { - target = new File(FileUtil.resuffix(confdef, ".xml", ".dat")); - } - - System.out.println("Compiling " + confdef + "..."); - Serializable config = null; - try { - // parse it on up - config = parser.parseConfig(confdef); - } catch (Exception e) { - throw new BuildException("Failure parsing config definition", e); - } - try { - // and write it on out - CompiledConfig.saveConfig(target, config); - } catch (Exception e) { - throw new BuildException("Failure writing serialized config", e); - } - } - - protected File _configdef; - protected File _target; - protected String _parser; - protected ArrayList _filesets = new ArrayList(); -} diff --git a/src/java/com/threerings/tools/xml/CompiledConfigParser.java b/src/java/com/threerings/tools/xml/CompiledConfigParser.java deleted file mode 100644 index 59bb89110..000000000 --- a/src/java/com/threerings/tools/xml/CompiledConfigParser.java +++ /dev/null @@ -1,70 +0,0 @@ -// -// $Id$ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.tools.xml; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.Serializable; - -import org.xml.sax.SAXException; -import org.apache.commons.digester.Digester; - -import com.threerings.tools.CompiledConfigTask; -import com.threerings.util.CompiledConfig; - -/** - * An abstract base implementation of a parser that is used to compile - * configuration definitions into config objects for use by the client and - * server. - * - * @see CompiledConfig - * @see CompiledConfigTask - */ -public abstract class CompiledConfigParser -{ - /** - * Parses the supplied configuration file into a serializable - * configuration object. - */ - public Serializable parseConfig (File source) - throws IOException, SAXException - { - Digester digester = new Digester(); - Serializable config = createConfigObject(); - addRules(digester); - digester.push(config); - digester.parse(new FileInputStream(source)); - return config; - } - - /** - * Creates the config object instance that will be populated during - * the parsing process. - */ - protected abstract Serializable createConfigObject (); - - /** - * Adds the necessary digester rules for parsing the config object. - */ - protected abstract void addRules (Digester digester); -} diff --git a/src/java/com/threerings/tools/xml/NestableRuleSet.java b/src/java/com/threerings/tools/xml/NestableRuleSet.java deleted file mode 100644 index eff39342e..000000000 --- a/src/java/com/threerings/tools/xml/NestableRuleSet.java +++ /dev/null @@ -1,83 +0,0 @@ -// -// $Id$ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.tools.xml; - -import org.apache.commons.digester.Digester; - -/** - * Used to define rule sets that can be nested within other rule sets. For - * example, say you have a "scene" object definition like so: - * - *

(Note that in the examples square brackets are used instead of - * angle brackets to simplify my life when composing the documentation.) - * - *

- * [scene name="Foo" version=5]
- * [/scene]
- * 
- * - * This scene is extended with some auxiliary data defined by libraries - * which can parse and generate XML for their auxiliary objects: - * - *
- * [scene sceneId=1 name="Foo" version=5]
- *   [spot]
- *     [portal portalId=1 x=1 y=1 targetSceneId=2/]
- *     [portal portalId=2 x=15 y=3 targetSceneId=3/]
- *     [portal portalId=3 x=9 y=6 targetSceneId=4/]
- *   [/spot]
- *   [miso]
- *     [object tileId=878172 x=4 y=13 action="cluck"/]
- *     [object tileId=123843 x=18 y=23 action="bark"/]
- *   [/miso]
- * [/scene]
- * 
- * - * The spot and miso services can define nestable rule sets which will be - * handed to the scene services who will instruct them to add their rule - * instances with a prefix of scene.spot and - * scene.miso respectively. They then happily parse their - * auxiliary objects without knowing that they have been nested inside - * some larger structure. - * - *

The nestable ruleset should then leave a single object on the - * digester stack that the enclosing entity can grab. - * - *

This isn't proper use of XML, but it solves the problem at hand in - * an easily extensible manner. - */ -public interface NestableRuleSet -{ - /** - * Returns the name of the nested object's outer element so that the - * parent parser can use it to compose the total path prefix. - */ - public String getOuterElement (); - - /** - * Instructs this ruleset to add its rules such that it parses its - * object from the specified path prefix. The outer element returned - * by {@link #getOuterElement} will have been included in the path - * prefix. - */ - public void addRuleInstances (String prefix, Digester digester); -} diff --git a/src/java/com/threerings/tools/xml/NestableWriter.java b/src/java/com/threerings/tools/xml/NestableWriter.java deleted file mode 100644 index 08f44d16d..000000000 --- a/src/java/com/threerings/tools/xml/NestableWriter.java +++ /dev/null @@ -1,39 +0,0 @@ -// -// $Id$ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.tools.xml; - -import org.xml.sax.SAXException; -import com.megginson.sax.DataWriter; - -/** - * Provides the writing component of the nestable parsing system described - * by {@link NestableRuleSet}. - */ -public interface NestableWriter -{ - /** - * Called to generate XML for the supplied object to the supplied data - * writer. - */ - public void write (Object object, DataWriter writer) - throws SAXException; -}