1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Copyright 2003,2004 The Apache Software Foundation.
   7  *
   8  * Licensed under the Apache License, Version 2.0 (the "License");
   9  * you may not use this file except in compliance with the License.
  10  * 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.xs.util;
  22 
  23 import java.util.ArrayList;
  24 
  25 import com.sun.org.apache.xerces.internal.impl.Constants;
  26 import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar;
  27 import com.sun.org.apache.xerces.internal.impl.xs.XSModelImpl;
  28 import com.sun.org.apache.xerces.internal.util.XMLGrammarPoolImpl;
  29 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;
  30 import com.sun.org.apache.xerces.internal.xs.XSModel;
  31 
  32 
  33 /**
  34  * Add a method that return an <code>XSModel</code> that represents components in
  35  * the schema grammars in this pool implementation.
  36  *
  37  * @xerces.internal
  38  *
  39  * @version $Id: XSGrammarPool.java,v 1.7 2010-11-01 04:40:06 joehw Exp $
  40  */
  41 public class XSGrammarPool extends XMLGrammarPoolImpl {
  42 
  43     /**
  44      * Return an <code>XSModel</code> that represents components in
  45      * the schema grammars in this pool implementation.
  46      *
  47      * @return  an <code>XSModel</code> representing this schema grammar
  48      */
  49     public XSModel toXSModel() {
  50         return toXSModel(Constants.SCHEMA_VERSION_1_0);
  51     }
  52 
  53     public XSModel toXSModel(short schemaVersion) {
  54         ArrayList list = new ArrayList();
  55         for (int i = 0; i < fGrammars.length; i++) {
  56             for (Entry entry = fGrammars[i] ; entry != null ; entry = entry.next) {
  57                 if (entry.desc.getGrammarType().equals(XMLGrammarDescription.XML_SCHEMA)) {
  58                     list.add(entry.grammar);
  59                 }
  60             }
  61         }
  62         int size = list.size();
  63         if (size == 0) {
  64             return toXSModel(new SchemaGrammar[0], schemaVersion);
  65         }
  66         SchemaGrammar[] gs = (SchemaGrammar[])list.toArray(new SchemaGrammar[size]);
  67         return toXSModel(gs, schemaVersion);
  68     }
  69 
  70     protected XSModel toXSModel(SchemaGrammar[] grammars, short schemaVersion) {
  71         return new XSModelImpl(grammars, schemaVersion);
  72     }
  73 
  74 } // class XSGrammarPool