More scene and spot scene refactoring. Got parsers working for those in
the new new style (or was that the new new new style). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@739 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// $Id: SceneParser.java,v 1.1 2001/12/05 03:38:09 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.tools.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
import org.apache.commons.digester.Digester;
|
||||
|
||||
import com.threerings.whirled.tools.EditableScene;
|
||||
import com.threerings.whirled.tools.EditableSceneImpl;
|
||||
|
||||
/**
|
||||
* A simple class for parsing an editable scene instance.
|
||||
*/
|
||||
public class SceneParser
|
||||
{
|
||||
/**
|
||||
* Constructs a scene parser that parses scenes with the specified XML
|
||||
* path prefix. See the {@link SceneRuleSet#SceneRuleSet}
|
||||
* documentation for more information.
|
||||
*/
|
||||
public SceneParser (String prefix)
|
||||
{
|
||||
// create and configure our digester
|
||||
_digester = new Digester();
|
||||
SceneRuleSet set = new SceneRuleSet();
|
||||
set.setPrefix(prefix);
|
||||
_digester.addRuleSet(set);
|
||||
_digester.addSetNext(prefix, "setScene", EditableScene.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the XML file at the specified path into an editable scene
|
||||
* instance.
|
||||
*/
|
||||
public EditableScene parseScene (String path)
|
||||
throws IOException, SAXException
|
||||
{
|
||||
_scene = null;
|
||||
_digester.push(this);
|
||||
_digester.parse(new FileInputStream(path));
|
||||
return _scene;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the parser once the scene is parsed.
|
||||
*/
|
||||
public void setScene (EditableScene scene)
|
||||
{
|
||||
_scene = scene;
|
||||
}
|
||||
|
||||
protected Digester _digester;
|
||||
protected EditableScene _scene;
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
//
|
||||
// $Id: SceneRuleSet.java,v 1.1 2001/11/29 19:31:52 mdb Exp $
|
||||
// $Id: SceneRuleSet.java,v 1.2 2001/12/05 03:38:09 mdb Exp $
|
||||
|
||||
package com.threerings.whirled.tools.xml;
|
||||
|
||||
import org.apache.commons.digester.Digester;
|
||||
import org.apache.commons.digester.RuleSetBase;
|
||||
|
||||
import com.samskivert.xml.SetFieldRule;
|
||||
|
||||
import com.threerings.whirled.data.SceneModel;
|
||||
import com.threerings.whirled.tools.EditableScene;
|
||||
import com.threerings.whirled.tools.EditableSceneImpl;
|
||||
|
||||
/**
|
||||
* Used to parse a {@link SceneModel} from XML.
|
||||
* Used to parse an {@link EditableScene} from XML.
|
||||
*/
|
||||
public class SceneRuleSet extends RuleSetBase
|
||||
{
|
||||
@@ -21,9 +20,9 @@ public class SceneRuleSet extends RuleSetBase
|
||||
* scene in the following XML file:
|
||||
*
|
||||
* <pre>
|
||||
* <scene>
|
||||
* <sceneId>50</sceneId>
|
||||
* <version>50</version>
|
||||
* <scene name="Scene Name" version="3">
|
||||
* <neighbor>North Scene</neighbor>
|
||||
* <neighbor>West Scene</neighbor>
|
||||
* <!-- ... -->
|
||||
* </scene>
|
||||
* </pre>
|
||||
@@ -39,26 +38,21 @@ public class SceneRuleSet extends RuleSetBase
|
||||
*/
|
||||
public void addRuleInstances (Digester digester)
|
||||
{
|
||||
// this creates the appropriate instance when we encounter our
|
||||
// prefix tag
|
||||
digester.addObjectCreate(_prefix, getSceneModelClass().getName());
|
||||
// this creates the appropriate instance when we encounter our tag
|
||||
digester.addObjectCreate(_prefix, getSceneClass().getName());
|
||||
|
||||
// set up rules to parse and set our fields
|
||||
digester.addRule(_prefix + "/sceneId",
|
||||
new SetFieldRule(digester, "sceneId"));
|
||||
digester.addRule(_prefix + "/version",
|
||||
new SetFieldRule(digester, "version"));
|
||||
digester.addRule(_prefix + "/neighborIds",
|
||||
new SetFieldRule(digester, "neighborIds"));
|
||||
digester.addSetProperties(_prefix);
|
||||
digester.addCallMethod(_prefix + "/neighbor", "addNeighbor", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This indicates the class (which should derive from {@link
|
||||
* SceneModel}) to be instantiated during the parsing process.
|
||||
* This indicates the class (which should implement {@link
|
||||
* EditableScene}) to be instantiated during the parsing process.
|
||||
*/
|
||||
protected Class getSceneModelClass ()
|
||||
protected Class getSceneClass ()
|
||||
{
|
||||
return SceneModel.class;
|
||||
return EditableSceneImpl.class;
|
||||
}
|
||||
|
||||
/** The prefix at which me match our scenes. */
|
||||
|
||||
Reference in New Issue
Block a user