1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Oct 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.impl.validation;
  23 
  24 import java.util.ArrayList;
  25 import java.util.List;
  26 
  27 /**
  28  * ValidationManager is a coordinator property for validators in the
  29  * pipeline. Each validator must know how to interact with
  30  * this property. Validators are not required to know what kind of
  31  * other validators present in the pipeline, but should understand
  32  * that there are others and that some coordination is required.
  33  *
  34  * @xerces.internal
  35  *
  36  * @author Elena Litani, IBM
  37  */
  38 public class ValidationManager {
  39 
  40     protected final List<ValidationState> fVSs = new ArrayList<>();
  41     protected boolean fGrammarFound = false;
  42 
  43     // used by the DTD validator to tell other components that it has a
  44     // cached DTD in hand so there's no reason to
  45     // scan external subset or entity decls.
  46     protected boolean fCachedDTD = false;
  47 
  48     /**
  49      * Each validator should call this method to add its ValidationState into
  50      * the validation manager.
  51      */
  52     public final void addValidationState(ValidationState vs) {
  53         fVSs.add(vs);
  54     }
  55 
  56     /**
  57      * Set the information required to validate entity values.
  58      */
  59     public final void setEntityState(EntityState state) {
  60         for (int i = fVSs.size()-1; i >= 0; i--) {
  61             (fVSs.get(i)).setEntityState(state);
  62         }
  63     }
  64 
  65     public final void setGrammarFound(boolean grammar){
  66         fGrammarFound = grammar;
  67     }
  68 
  69     public final boolean isGrammarFound(){
  70         return fGrammarFound;
  71     }
  72 
  73     public final void setCachedDTD(boolean cachedDTD) {
  74         fCachedDTD = cachedDTD;
  75     } // setCachedDTD(boolean)
  76 
  77     public final boolean isCachedDTD() {
  78         return fCachedDTD;
  79     } // isCachedDTD():  boolean
  80 
  81 
  82     public final void reset (){
  83         fVSs.clear();
  84         fGrammarFound = false;
  85         fCachedDTD = false;
  86     }
  87 }