diff --git a/src/java/com/threerings/whirled/spot/tools/xml/SpotSceneRuleSet.java b/src/java/com/threerings/whirled/spot/tools/xml/SpotSceneRuleSet.java new file mode 100644 index 000000000..7c78afe16 --- /dev/null +++ b/src/java/com/threerings/whirled/spot/tools/xml/SpotSceneRuleSet.java @@ -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; + } +} diff --git a/src/java/com/threerings/whirled/tools/xml/SceneRuleSet.java b/src/java/com/threerings/whirled/tools/xml/SceneRuleSet.java new file mode 100644 index 000000000..360450ba2 --- /dev/null +++ b/src/java/com/threerings/whirled/tools/xml/SceneRuleSet.java @@ -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 scene will match the + * scene in the following XML file: + * + *
+     * <scene>
+     *   <sceneId>50</sceneId>
+     *   <version>50</version>
+     *   <!-- ... -->
+     * </scene>
+     * 
+ */ + 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"; +}