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.jaxp.validation;
  22 
  23 import java.util.HashMap;
  24 import java.util.Map;
  25 import javax.xml.validation.Schema;
  26 import javax.xml.validation.Validator;
  27 import javax.xml.validation.ValidatorHandler;
  28 
  29 /**
  30  * <p>Abstract implementation of Schema for W3C XML Schemas.</p>
  31  *
  32  * @author Michael Glavassevich, IBM
  33  * @LastModified: Oct 2017
  34  */
  35 abstract class AbstractXMLSchema extends Schema implements
  36         XSGrammarPoolContainer {
  37 
  38     /**
  39      * Map containing the initial values of features for
  40      * validators created using this grammar pool container.
  41      */
  42     private final Map<String, Boolean> fFeatures;
  43 
  44     /**
  45      * Map containing the initial values of properties for
  46      * validators created using this grammar pool container.
  47      */
  48     private final Map<String, Object> fProperties;
  49 
  50     public AbstractXMLSchema() {
  51         fFeatures = new HashMap<>();
  52         fProperties = new HashMap<>();
  53     }
  54 
  55     /*
  56      * Schema methods
  57      */
  58 
  59     /*
  60      * @see javax.xml.validation.Schema#newValidator()
  61      */
  62     public final Validator newValidator() {
  63         return new ValidatorImpl(this);
  64     }
  65 
  66     /*
  67      * @see javax.xml.validation.Schema#newValidatorHandler()
  68      */
  69     public final ValidatorHandler newValidatorHandler() {
  70         return new ValidatorHandlerImpl(this);
  71     }
  72 
  73     /*
  74      * XSGrammarPoolContainer methods
  75      */
  76 
  77     /**
  78      * Returns the initial value of a feature for validators created
  79      * using this grammar pool container or null if the validators
  80      * should use the default value.
  81      */
  82     public final Boolean getFeature(String featureId) {
  83         return fFeatures.get(featureId);
  84     }
  85 
  86     /*
  87      * Set a feature on the schema
  88      */
  89     public final void setFeature(String featureId, boolean state) {
  90         fFeatures.put(featureId, state ? Boolean.TRUE : Boolean.FALSE);
  91     }
  92 
  93     /**
  94      * Returns the initial value of a property for validators created
  95      * using this grammar pool container or null if the validators
  96      * should use the default value.
  97      */
  98     public final Object getProperty(String propertyId) {
  99         return fProperties.get(propertyId);
 100     }
 101 
 102     /*
 103      * Set a property on the schema
 104      */
 105     public final void setProperty(String propertyId, Object state) {
 106         fProperties.put(propertyId, state);
 107     }
 108 
 109 } // AbstractXMLSchema