Created rulesets for parsing scene models.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@679 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
//
|
||||||
|
// $Id: SpotSceneRuleSet.java,v 1.1 2001/11/29 19:31:52 mdb Exp $
|
||||||
|
|
||||||
|
package com.threerings.whirled.tools.spot.xml;
|
||||||
|
|
||||||
|
import org.apache.commons.digester.Digester;
|
||||||
|
import org.apache.commons.digester.RuleSetBase;
|
||||||
|
|
||||||
|
import com.samskivert.xml.SetFieldRule;
|
||||||
|
|
||||||
|
import com.threerings.whirled.spot.data.SpotSceneModel;
|
||||||
|
import com.threerings.whirled.tools.xml.SceneRuleSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to parse a {@link SpotSceneModel} from XML.
|
||||||
|
*/
|
||||||
|
public class SpotSceneRuleSet extends SceneRuleSet
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Adds the necessary rules to the digester to parse our miso scene
|
||||||
|
* data.
|
||||||
|
*/
|
||||||
|
public void addRuleInstances (Digester digester)
|
||||||
|
{
|
||||||
|
super.addRuleInstances(digester);
|
||||||
|
|
||||||
|
// add extra rules for the spot scene model fields
|
||||||
|
digester.addRule(_prefix + "/locationIds",
|
||||||
|
new SetFieldRule(digester, "locationIds"));
|
||||||
|
digester.addRule(_prefix + "/locationX",
|
||||||
|
new SetFieldRule(digester, "locationX"));
|
||||||
|
digester.addRule(_prefix + "/locationY",
|
||||||
|
new SetFieldRule(digester, "locationY"));
|
||||||
|
digester.addRule(_prefix + "/locationOrients",
|
||||||
|
new SetFieldRule(digester, "locationOrients"));
|
||||||
|
digester.addRule(_prefix + "/locationClusters",
|
||||||
|
new SetFieldRule(digester, "locationClusters"));
|
||||||
|
digester.addRule(_prefix + "/defaultEntranceId",
|
||||||
|
new SetFieldRule(digester, "defaultEntranceId"));
|
||||||
|
digester.addRule(_prefix + "/portalIds",
|
||||||
|
new SetFieldRule(digester, "portalIds"));
|
||||||
|
digester.addRule(_prefix + "/targetLocIds",
|
||||||
|
new SetFieldRule(digester, "targetLocIds"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
protected Class getSceneModelClass ()
|
||||||
|
{
|
||||||
|
return SpotSceneModel.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
//
|
||||||
|
// $Id: SceneRuleSet.java,v 1.1 2001/11/29 19:31:52 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to parse a {@link SceneModel} from XML.
|
||||||
|
*/
|
||||||
|
public class SceneRuleSet extends RuleSetBase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Configures this scene rule set to match scenes with the supplied
|
||||||
|
* prefix. For example, passing <code>scene</code> will match the
|
||||||
|
* scene in the following XML file:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* <scene>
|
||||||
|
* <sceneId>50</sceneId>
|
||||||
|
* <version>50</version>
|
||||||
|
* <!-- ... -->
|
||||||
|
* </scene>
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public void setPrefix (String prefix)
|
||||||
|
{
|
||||||
|
_prefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the necessary rules to the digester to parse our miso scene
|
||||||
|
* data.
|
||||||
|
*/
|
||||||
|
public void addRuleInstances (Digester digester)
|
||||||
|
{
|
||||||
|
// this creates the appropriate instance when we encounter our
|
||||||
|
// prefix tag
|
||||||
|
digester.addObjectCreate(_prefix, getSceneModelClass().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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This indicates the class (which should derive from {@link
|
||||||
|
* SceneModel}) to be instantiated during the parsing process.
|
||||||
|
*/
|
||||||
|
protected Class getSceneModelClass ()
|
||||||
|
{
|
||||||
|
return SceneModel.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The prefix at which me match our scenes. */
|
||||||
|
protected String _prefix = DEFAULT_SCENE_PREFIX;
|
||||||
|
|
||||||
|
/** The default prefix which matches <scene>. */
|
||||||
|
protected static final String DEFAULT_SCENE_PREFIX = "scene";
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user