001 package com.oxygenxml.validate.nvdl;
002
003 import org.xml.sax.SAXException;
004
005 import com.thaiopensource.validate.Schema;
006
007 /**
008 * Validate no result action.
009 *
010 */
011 class ValidateAction extends NoResultAction {
012 /**
013 * The schema to validate with.
014 */
015 private final Schema schema;
016
017 /**
018 * Creates a validate action.
019 * @param modeUsage The mode usage.
020 * @param schema The schema.
021 */
022 ValidateAction(ModeUsage modeUsage, Schema schema) {
023 super(modeUsage);
024 this.schema = schema;
025 }
026
027 /**
028 * Perform this action on the section state.
029 * @param state the section state.
030 */
031 void perform(SectionState state) throws SAXException {
032 state.addValidator(schema, getModeUsage());
033 }
034
035 /**
036 * Get a new validate action with a mode usage with the current mode changed.
037 * This is useful when we have modes extending other modes as we need to get
038 * the actions from the base mode as actions on the new mode.
039 */
040 NoResultAction changeCurrentMode(Mode mode) {
041 return new ValidateAction(getModeUsage().changeCurrentMode(mode), schema);
042 }
043
044 /**
045 * Checks if this action is equal with a given action.
046 */
047 public boolean equals(Object obj) {
048 return super.equals(obj) && schema.equals(((ValidateAction)obj).schema);
049 }
050
051 /**
052 * Computes a hashCode.
053 */
054 public int hashCode() {
055 return super.hashCode() ^ schema.hashCode();
056 }
057 }