mrglavas    2005/05/14 13:37:19

  Added:       java/src/org/apache/xerces/jaxp/validation
                        SimpleXMLSchema.java EmptyXMLSchema.java
                        WeakReferenceXMLSchema.java AbstractXMLSchema.java
                        XMLSchema.java
  Log:
  The RI had one concrete implementation of Schema, creating 4 concrete
  implementations in Xerces to handle different scenarios.
  
  Revision  Changes    Path
  1.1                  
xml-xerces/java/src/org/apache/xerces/jaxp/validation/SimpleXMLSchema.java
  
  Index: SimpleXMLSchema.java
  ===================================================================
  /*
   * Copyright 2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.xerces.jaxp.validation;
  
  import org.apache.xerces.xni.grammars.Grammar;
  import org.apache.xerces.xni.grammars.XMLGrammarDescription;
  import org.apache.xerces.xni.grammars.XMLGrammarPool;
  
  /**
   * <p>Implementation of Schema for W3C XML Schemas which 
   * contains schema components from one target namespace.</p>
   * 
   * @author Michael Glavassevich, IBM
   * @version $Id: SimpleXMLSchema.java,v 1.1 2005/05/14 20:37:18 mrglavas Exp $
   */
  final class SimpleXMLSchema extends AbstractXMLSchema implements 
XMLGrammarPool {
      
      /** Zero length grammar array. */
      private static final Grammar [] ZERO_LENGTH_GRAMMAR_ARRAY = new Grammar 
[0];
  
      private Grammar fGrammar;
      private Grammar[] fGrammars;
      private XMLGrammarDescription fGrammarDescription;
      
      public SimpleXMLSchema(Grammar grammar) {
          fGrammar = grammar;
          fGrammars = new Grammar[] {grammar};
          fGrammarDescription = grammar.getGrammarDescription();
      }
      
      /*
       * XMLGrammarPool methods
       */
  
      public Grammar[] retrieveInitialGrammarSet(String grammarType) {
          return XMLGrammarDescription.XML_SCHEMA.equals(grammarType) ? 
                  (Grammar[]) fGrammars.clone() : ZERO_LENGTH_GRAMMAR_ARRAY;
      }
  
      public void cacheGrammars(String grammarType, Grammar[] grammars) {}
  
      public Grammar retrieveGrammar(XMLGrammarDescription desc) {
          return fGrammarDescription.equals(desc) ? fGrammar : null;
      }
  
      public void lockPool() {}
  
      public void unlockPool() {}
  
      public void clear() {}
      
      /*
       * XSGrammarPoolContainer methods
       */
  
      public XMLGrammarPool getGrammarPool() {
          return this;
      }
  
      public boolean isFullyComposed() {
          return true;
      }
  
  } // SimpleXMLSchema
  
  
  
  1.1                  
xml-xerces/java/src/org/apache/xerces/jaxp/validation/EmptyXMLSchema.java
  
  Index: EmptyXMLSchema.java
  ===================================================================
  /*
   * Copyright 2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.xerces.jaxp.validation;
  
  import org.apache.xerces.xni.grammars.Grammar;
  import org.apache.xerces.xni.grammars.XMLGrammarDescription;
  import org.apache.xerces.xni.grammars.XMLGrammarPool;
  
  /**
   * <p>Implementation of Schema for W3C XML Schemas
   * which contains no schema components.</p>
   * 
   * @author Michael Glavassevich, IBM
   * @version $Id: EmptyXMLSchema.java,v 1.1 2005/05/14 20:37:18 mrglavas Exp $
   */
  final class EmptyXMLSchema extends AbstractXMLSchema implements 
XMLGrammarPool {
      
      private static EmptyXMLSchema EMPTY_XML_SCHEMA_INSTANCE = new 
EmptyXMLSchema();
      
      /** Zero length grammar array. */
      private static final Grammar [] ZERO_LENGTH_GRAMMAR_ARRAY = new Grammar 
[0];
  
      /** Returns the one and only instance of this class. */
      public static EmptyXMLSchema getInstance() {
          return EMPTY_XML_SCHEMA_INSTANCE;
      }
      
      private EmptyXMLSchema() {}
      
      /*
       * XMLGrammarPool methods
       */
  
      public Grammar[] retrieveInitialGrammarSet(String grammarType) {
          return ZERO_LENGTH_GRAMMAR_ARRAY;
      }
  
      public void cacheGrammars(String grammarType, Grammar[] grammars) {}
  
      public Grammar retrieveGrammar(XMLGrammarDescription desc) {
          return null;
      }
  
      public void lockPool() {}
  
      public void unlockPool() {}
  
      public void clear() {}
      
      /*
       * XSGrammarPoolContainer methods
       */
  
      public XMLGrammarPool getGrammarPool() {
          return this;
      }
  
      public boolean isFullyComposed() {
          return true;
      }
  
  } // EmptyXMLSchema
  
  
  
  1.1                  
xml-xerces/java/src/org/apache/xerces/jaxp/validation/WeakReferenceXMLSchema.java
  
  Index: WeakReferenceXMLSchema.java
  ===================================================================
  /*
   * Copyright 2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.xerces.jaxp.validation;
  
  import java.lang.ref.WeakReference;
  
  import org.apache.xerces.xni.grammars.XMLGrammarPool;
  
  /**
   * <p>An implementation of Schema for W3C XML Schemas
   * that keeps a weak reference to its grammar pool. If
   * no validators currently have a reference to the
   * grammar pool, the garbage collector is free to reclaim
   * its memory.</p>
   * 
   * @author Michael Glavassevich, IBM
   * @version $Id: WeakReferenceXMLSchema.java,v 1.1 2005/05/14 20:37:18 
mrglavas Exp $
   */
  final class WeakReferenceXMLSchema extends AbstractXMLSchema {
      
      /** Weak reference to grammar pool. */
      private WeakReference fGrammarPool = new WeakReference(null);
  
      public WeakReferenceXMLSchema() {}
      
      /*
       * XSGrammarPoolContainer methods
       */
  
      public synchronized XMLGrammarPool getGrammarPool() {
          XMLGrammarPool grammarPool = (XMLGrammarPool) fGrammarPool.get();
          // If there's no grammar pool then either we haven't created one
          // yet or the garbage collector has already cleaned out the previous 
one. 
          if (grammarPool == null) {
              grammarPool = new SoftReferenceGrammarPool();
              fGrammarPool = new WeakReference(grammarPool);
          }
          return grammarPool;
      }
  
      public boolean isFullyComposed() {
          return false;
      }
  
  } // WeakReferenceXMLSchema
  
  
  
  1.1                  
xml-xerces/java/src/org/apache/xerces/jaxp/validation/AbstractXMLSchema.java
  
  Index: AbstractXMLSchema.java
  ===================================================================
  /*
   * Copyright 2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.xerces.jaxp.validation;
  
  import javax.xml.validation.Schema;
  import javax.xml.validation.Validator;
  import javax.xml.validation.ValidatorHandler;
  
  /**
   * <p>Abstract implementation of Schema for W3C XML Schemas.</p>
   * 
   * @author Michael Glavassevich, IBM
   * @version $Id: AbstractXMLSchema.java,v 1.1 2005/05/14 20:37:18 mrglavas 
Exp $
   */
  abstract class AbstractXMLSchema extends Schema implements
          XSGrammarPoolContainer {
  
      /*
       * Schema methods
       */
  
      /* 
       * @see javax.xml.validation.Schema#newValidator()
       */
      public Validator newValidator() {
          // TODO: Integrate ValidatorImpl from the RI
          // return new ValidatorImpl(this);
          return null;
      }
  
      /* 
       * @see javax.xml.validation.Schema#newValidatorHandler()
       */
      public ValidatorHandler newValidatorHandler() {
          // TODO: Integrate ValidatorHandlerImpl from the RI
          // return new ValidatorHandlerImpl(this);
          return null;
      }
      
  } // AbstractXMLSchema
  
  
  
  1.1                  
xml-xerces/java/src/org/apache/xerces/jaxp/validation/XMLSchema.java
  
  Index: XMLSchema.java
  ===================================================================
  /*
   * Copyright 2005 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.xerces.jaxp.validation;
  
  import org.apache.xerces.xni.grammars.XMLGrammarPool;
  
  /**
   * <p>Implementation of Schema for W3C XML Schemas.</p>
   * 
   * @author Michael Glavassevich, IBM
   * @version $Id: XMLSchema.java,v 1.1 2005/05/14 20:37:18 mrglavas Exp $
   */
  final class XMLSchema extends AbstractXMLSchema {
      
      /** The grammar pool is immutable */
      private final XMLGrammarPool fGrammarPool;  
      
      /** Constructor */
      public XMLSchema(XMLGrammarPool grammarPool) {
          fGrammarPool = grammarPool;
      }
      
      /*
       * XSGrammarPoolContainer methods
       */
      
      /**
       * <p>Returns the grammar pool contained inside the container.</p>
       * 
       * @return the grammar pool contained inside the container
       */
      public XMLGrammarPool getGrammarPool() {
          return fGrammarPool;
      }
  
      /**
       * <p>Returns whether the schema components contained in this object
       * can be considered to be a fully composed schema and should be
       * used to exclusion of other schema components which may be
       * present elsewhere.</p>
       * 
       * @return whether the schema components contained in this object
       * can be considered to be a fully composed schema
       */
      public boolean isFullyComposed() {
          return true;
      }
      
  } // XMLSchema
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to