1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.xerces.internal.impl.validation;
  22 
  23 import java.util.ArrayList;
  24 import java.util.List;
  25 
  26 /**
  27  * ValidationManager is a coordinator property for validators in the
  28  * pipeline. Each validator must know how to interact with
  29  * this property. Validators are not required to know what kind of
  30  * other validators present in the pipeline, but should understand
  31  * that there are others and that some coordination is required.
  32  *
  33  * @xerces.internal
  34  *
  35  * @author Elena Litani, IBM
  36  * @LastModified: Oct 2017
  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 }