< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XSGrammarBucket.java

Print this page


   1 /*
   2  * Copyright (c) 2015, 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.xs;
  23 


  35  */
  36 public class XSGrammarBucket {
  37 
  38     // Data
  39 
  40     /**
  41      * Map that maps between Namespace and a Grammar
  42      */
  43     Map<String, SchemaGrammar> fGrammarRegistry = new HashMap<>();
  44     SchemaGrammar fNoNSGrammar = null;
  45 
  46     /**
  47      * Get the schema grammar for the specified namespace
  48      *
  49      * @param namespace
  50      * @return SchemaGrammar associated with the namespace
  51      */
  52     public SchemaGrammar getGrammar(String namespace) {
  53         if (namespace == null)
  54             return fNoNSGrammar;
  55         return (SchemaGrammar)fGrammarRegistry.get(namespace);
  56     }
  57 
  58     /**
  59      * Put a schema grammar into the registry
  60      * This method is for internal use only: it assumes that a grammar with
  61      * the same target namespace is not already in the bucket.
  62      *
  63      * @param grammar   the grammar to put in the registry
  64      */
  65     public void putGrammar(SchemaGrammar grammar) {
  66         if (grammar.getTargetNamespace() == null)
  67             fNoNSGrammar = grammar;
  68         else
  69             fGrammarRegistry.put(grammar.getTargetNamespace(), grammar);
  70     }
  71 
  72     /**
  73      * put a schema grammar and any grammars imported by it (directly or
  74      * inderectly) into the registry. when a grammar with the same target
  75      * namespace is already in the bucket, and different from the one being


 174             return true;
 175         }
 176 
 177         @SuppressWarnings("unchecked")
 178         List<SchemaGrammar> grammars = ((ArrayList<SchemaGrammar>)currGrammars.clone());
 179         SchemaGrammar sg1, sg2;
 180         List<SchemaGrammar> gs;
 181         // for all (recursively) imported grammars
 182         for (int i = 0; i < grammars.size(); i++) {
 183             // get the grammar
 184             sg1 = grammars.get(i);
 185             // check whether the bucket has one with the same tns
 186             sg2 = getGrammar(sg1.fTargetNamespace);
 187             if (sg2 == null) {
 188                 // we need to add grammars imported by sg1 too
 189                 gs = sg1.getImportedGrammars();
 190                 // for all grammars imported by sg2, but not in the vector
 191                 // we add them to the vector
 192                 if(gs == null) continue;
 193                 for (int j = gs.size() - 1; j >= 0; j--) {
 194                     sg2 = (SchemaGrammar)gs.get(j);
 195                     if (!grammars.contains(sg2))
 196                         grammars.add(sg2);
 197                 }
 198             }
 199             // we found one with the same target namespace, ignore it
 200             else  {
 201                 grammars.remove(sg1);
 202             }
 203         }
 204 
 205         // now we have all imported grammars stored in the vector. add them
 206         for (int i = grammars.size() - 1; i >= 0; i--) {
 207             putGrammar(grammars.get(i));
 208         }
 209 
 210         return true;
 211     }
 212 
 213     /**
 214      * get all grammars in the registry


   1 /*
   2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Nov 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.xs;
  23 


  35  */
  36 public class XSGrammarBucket {
  37 
  38     // Data
  39 
  40     /**
  41      * Map that maps between Namespace and a Grammar
  42      */
  43     Map<String, SchemaGrammar> fGrammarRegistry = new HashMap<>();
  44     SchemaGrammar fNoNSGrammar = null;
  45 
  46     /**
  47      * Get the schema grammar for the specified namespace
  48      *
  49      * @param namespace
  50      * @return SchemaGrammar associated with the namespace
  51      */
  52     public SchemaGrammar getGrammar(String namespace) {
  53         if (namespace == null)
  54             return fNoNSGrammar;
  55         return fGrammarRegistry.get(namespace);
  56     }
  57 
  58     /**
  59      * Put a schema grammar into the registry
  60      * This method is for internal use only: it assumes that a grammar with
  61      * the same target namespace is not already in the bucket.
  62      *
  63      * @param grammar   the grammar to put in the registry
  64      */
  65     public void putGrammar(SchemaGrammar grammar) {
  66         if (grammar.getTargetNamespace() == null)
  67             fNoNSGrammar = grammar;
  68         else
  69             fGrammarRegistry.put(grammar.getTargetNamespace(), grammar);
  70     }
  71 
  72     /**
  73      * put a schema grammar and any grammars imported by it (directly or
  74      * inderectly) into the registry. when a grammar with the same target
  75      * namespace is already in the bucket, and different from the one being


 174             return true;
 175         }
 176 
 177         @SuppressWarnings("unchecked")
 178         List<SchemaGrammar> grammars = ((ArrayList<SchemaGrammar>)currGrammars.clone());
 179         SchemaGrammar sg1, sg2;
 180         List<SchemaGrammar> gs;
 181         // for all (recursively) imported grammars
 182         for (int i = 0; i < grammars.size(); i++) {
 183             // get the grammar
 184             sg1 = grammars.get(i);
 185             // check whether the bucket has one with the same tns
 186             sg2 = getGrammar(sg1.fTargetNamespace);
 187             if (sg2 == null) {
 188                 // we need to add grammars imported by sg1 too
 189                 gs = sg1.getImportedGrammars();
 190                 // for all grammars imported by sg2, but not in the vector
 191                 // we add them to the vector
 192                 if(gs == null) continue;
 193                 for (int j = gs.size() - 1; j >= 0; j--) {
 194                     sg2 = gs.get(j);
 195                     if (!grammars.contains(sg2))
 196                         grammars.add(sg2);
 197                 }
 198             }
 199             // we found one with the same target namespace, ignore it
 200             else  {
 201                 grammars.remove(sg1);
 202             }
 203         }
 204 
 205         // now we have all imported grammars stored in the vector. add them
 206         for (int i = grammars.size() - 1; i >= 0; i--) {
 207             putGrammar(grammars.get(i));
 208         }
 209 
 210         return true;
 211     }
 212 
 213     /**
 214      * get all grammars in the registry


< prev index next >