You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2002/02/24 18:01:33 UTC

cvs commit: jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/res StorageHandler.java StorageParser.java storage.dtd storage.xml

baliuka     02/02/24 09:01:33

  Modified:    simplestore/src/java/org/apache/commons/simplestore/persistence/impl
                        MetaClassImpl.java
  Added:       simplestore/src/java/org/apache/commons/simplestore/res
                        StorageHandler.java StorageParser.java storage.dtd
                        storage.xml
  Log:
  Added xml DTD and generated parser for metadata
  
  Revision  Changes    Path
  1.3       +234 -17   jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/MetaClassImpl.java
  
  Index: MetaClassImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/persistence/impl/MetaClassImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MetaClassImpl.java	17 Feb 2002 14:09:04 -0000	1.2
  +++ MetaClassImpl.java	24 Feb 2002 17:01:33 -0000	1.3
  @@ -56,32 +56,144 @@
   
   import java.lang.reflect.Method;
   import org.apache.commons.simplestore.persistence.*;
  +import org.apache.commons.simplestore.res.*;
  +import org.xml.sax.*;
  +
   
   /**
    * Meta data
    *
    *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
    *     baliuka@mwm.lt</a>
  - *@version    $Id: MetaClassImpl.java,v 1.2 2002/02/17 14:09:04 baliuka Exp $
  + *@version    $Id: MetaClassImpl.java,v 1.3 2002/02/24 17:01:33 baliuka Exp $
    */
   public class MetaClassImpl implements MetaClass {
       
       private static java.util.Map persitentClasses = new java.util.Hashtable();
       private Class clasz;
       private String sqlName;
  +    private String oidName;
       private java.util.Map properties = new java.util.Hashtable();
       private java.beans.PropertyDescriptor[] descriptors;
       private Context context;
       private static OIDGenerator generator = new RandomOIDGenerator();
       
  +    private java.util.Map fields = new java.util.HashMap();
  +    
  +    
  +    private Field getField( String id ){
  +        Field field = (Field)fields.get(id);
  +        if ( field == null ){
  +            for( int i = 0; i < descriptors.length; i++ ){
  +                if ( descriptors[i].getName().equals(id) ){
  +                    field = new Field(id,null);
  +                    fields.put(id,fields);
  +                    return field;
  +                }
  +            }
  +            throw new RuntimeException("property " + id + " not found");
  +        } else return field;
  +        
  +    }
  +    
  +    static class Field {
  +        
  +        Field( String id, String name ){
  +            this.id = id;
  +            this.name = name;
  +        }
  +        
  +        /** Holds value of property id. */
  +        private String id;
  +        
  +        /** Holds value of property name. */
  +        private String name;
  +        
  +        /** Holds value of property referencedField. */
  +        private String referenceField;
  +        
  +        /** Holds value of property referencedClass. */
  +        private String referenceClass;
  +        
  +        /** Getter for property id.
  +         * @return Value of property id.
  +         */
  +        public String getId() {
  +            return this.id;
  +        }
  +        
  +        /** Setter for property id.
  +         * @param id New value of property id.
  +         */
  +        public void setId(String id) {
  +            this.id = id;
  +        }
  +        
  +        /** Getter for property name.
  +         * @return Value of property name.
  +         */
  +        public String getName() {
  +            return this.name;
  +        }
  +        
  +        /** Setter for property name.
  +         * @param name New value of property name.
  +         */
  +        public void setName(String name) {
  +            this.name = name;
  +        }
  +        
  +        /** Getter for property referencedField.
  +         * @return Value of property referencedField.
  +         */
  +        public String getReferenceField() {
  +            return this.referenceField;
  +        }
  +        
  +        /** Setter for property referencedField.
  +         * @param referencedField New value of property referencedField.
  +         */
  +        public void setReferenceField(String referenceField) {
  +            this.referenceField = referenceField;
  +        }
  +        
  +        /** Getter for property referencedClass.
  +         * @return Value of property referencedClass.
  +         */
  +        public String getReferenceClass() {
  +            return this.referenceClass;
  +        }
  +        
  +        /** Setter for property referencedClass.
  +         * @param referencedClass New value of property referencedClass.
  +         */
  +        public void setReferenceClass( String referencedClass ) {
  +            this.referenceClass = referencedClass;
  +        }
  +        
  +        /** Getter for property validator.
  +         * @return Value of property validator.
  +         */
  +        public Object getValidator() {
  +            return null;
  +        }
  +        
  +        /** Setter for property validator.
  +         * @param validator New value of property validator.
  +         */
  +        public void setValidator(Object validator) {
  +        }
  +        
  +    }
  +    
  +    
       /** Creates new MetaClassImpl */
       public MetaClassImpl(){
  -       
  +        
       }
       
       private MetaClassImpl(Class clasz) {
           this.clasz = clasz;
  -        this.sqlName = toSQLName(clasz.getName());
           indexMethods();
           if( persitentClasses.put( clasz, this ) != null )
               throw new java.lang.IllegalStateException("Dublicate MetaClass for " + clasz.getName());
  @@ -95,21 +207,22 @@
        * @return        field name
        */
       public String getPropertyName( int index ) {
  +        //TODO :
           return toSQLName(descriptors[ index ].getName());
       }
       
       public Persistent newInstance( Object oid ){
  -      
  +        
           return newInstance( nextOID(), false );
  -    
  +        
       }
       
       public Persistent newInstance(){
  -    
  +        
           return newInstance( nextOID(), true );
  -    
  +        
       }
  -     
  +    
       protected Persistent newInstance(Object oid, boolean create) {
           
           return PersistentProxy.getPersitent(clasz, oid , create , context );
  @@ -121,7 +234,7 @@
        * @return    name in storage
        */
       public String getName() {
  -        return sqlName;
  +        return sqlName == null ? toSQLName(clasz.getName()) : sqlName;
       }
       
       
  @@ -133,7 +246,7 @@
        */
       public Class getPropertyType( int index ) {
           // TODO : must return JDBC type
  -        // if Date ... 
  +        // if Date ...
           return descriptors[index].getPropertyType();
       }
       
  @@ -147,8 +260,8 @@
           MetaClass mc =  (MetaClass)persitentClasses.get(clasz);
           if( mc == null ){
               mc = new MetaClassImpl(clasz);
  -            mc.setContext(context);
           }
  +        mc.setContext(context);
           return mc;
           
       }
  @@ -246,6 +359,7 @@
        * @return         index
        */
       public int getPropertyIndex(String field) {
  +        //TODO :
           Integer index = (Integer)properties.get(field);
           return index.intValue();
           
  @@ -256,7 +370,7 @@
       }
       
       public String getOIDName() {
  -        return "ID";
  +        return oidName == null ? "ID" : oidName;
       }
       
       public Class getOIDType() {
  @@ -264,10 +378,113 @@
       }
       
       public Object nextOID() {
  -        return generator.getLongOID();        
  +        return generator.getLongOID();
       }
  -
  -     public void setContext( Context context ){
  -       this.context = context;
  -     }
  +    
  +    public void setContext( Context context ){
  +        this.context = context;
  +    }
  +    
  +    
  +    static  class StorageHandlerImpl implements StorageHandler {
  +        
  +        MetaClassImpl root = new MetaClassImpl();
  +        MetaClassImpl currentClass ;
  +        Field currentField;
  +        
  +        StorageHandlerImpl( ){
  +            
  +        }
  +        
  +        public static final boolean DEBUG = false;
  +        
  +        public void setDocumentLocator(org.xml.sax.Locator locator ){}
  +        
  +        public void startDocument()throws org.xml.sax.SAXException{}
  +        
  +        public void startPrefixMapping(String s1,String s2)throws org.xml.sax.SAXException{}
  +        
  +        public void endPrefixMapping(String s1)throws org.xml.sax.SAXException{}
  +        
  +        public void endDocument()throws org.xml.sax.SAXException{}
  +        
  +        public final void startElement(java.lang.String ns, java.lang.String name, java.lang.String qname, Attributes attrs) throws SAXException {}
  +        
  +        public final void endElement(java.lang.String ns, java.lang.String name, java.lang.String qname) throws SAXException {}
  +        
  +        public final void characters(char[] chars, int start, int len) throws SAXException {}
  +        
  +        public final void ignorableWhitespace(char[] chars, int start, int len) throws SAXException {}
  +        
  +        public final void processingInstruction(java.lang.String target, java.lang.String data) throws SAXException {}
  +        
  +        public final void skippedEntity(java.lang.String name) throws SAXException {}
  +        
  +        public void handle_reference(final Attributes meta) throws SAXException {
  +            if (DEBUG) System.err.println("handle_reference: " + meta);
  +            currentField.setReferenceClass( meta.getValue("mclass") );
  +            currentField.setReferenceField( meta.getValue("field")  );
  +        }
  +        
  +        public void start_validator(final Attributes meta) throws SAXException {
  +            if (DEBUG) System.err.println("start_validator: " + meta);
  +        }
  +        
  +        public void end_validator() throws SAXException {
  +            if (DEBUG) System.err.println("end_validator()");
  +        }
  +        
  +        public void handle_property(final java.lang.String data, final Attributes meta) throws SAXException {
  +            if (DEBUG) System.err.println("handle_property: " + data);
  +        }
  +        
  +        public void start_field(final Attributes meta) throws SAXException {
  +            if (DEBUG) System.err.println("start_field: " + meta);
  +            currentField = currentClass.getField( meta.getValue("id") );
  +            currentField.setName( meta.getValue("name") );
  +        }
  +        
  +        public void end_field() throws SAXException {
  +            if (DEBUG) System.err.println("end_field()");
  +            
  +        }
  +        
  +        public void start_storage(final Attributes meta) throws SAXException {
  +            if (DEBUG) System.err.println("start_storage: " + meta);
  +        }
  +        
  +        public void end_storage() throws SAXException {
  +            if (DEBUG) System.err.println("end_storage()");
  +        }
  +        public void start_mclass(final Attributes meta) throws SAXException {
  +            if (DEBUG) System.err.println("start_mclass: " + meta);
  +            try{
  +                currentClass = (MetaClassImpl)root.forClass( Class.forName( meta.getValue("id")) );
  +                currentClass.sqlName = meta.getValue("name");
  +                currentClass.oidName = meta.getValue("oid");
  +            }catch( Exception e ){
  +                rethrow(e);
  +            }
  +        }
  +        
  +        public void end_mclass() throws SAXException {
  +            if (DEBUG) System.err.println("end_mclass()");
  +        }
  +        
  +        private void rethrow(Exception e )throws SAXException {
  +            throw new SAXException( e.getClass().getName() + ":" +  e.getMessage());
  +        }
  +        
  +    }
  +    
  +    
  +    public static void parse(String resName) throws SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException {
  +        StorageParser.parse(new InputSource(
  +        
  +        Thread.currentThread().getContextClassLoader().getResourceAsStream(resName)
  +        
  +        ), new StorageHandlerImpl());
  +    }
  +    
  +    
   }
  
  
  
  1.1                  jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/res/StorageHandler.java
  
  Index: StorageHandler.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache Cocoon" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.simplestore.res;
  
  import org.xml.sax.*;
  /**
   *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
   *      baliuka@mwm.lt</a>
   *@version    $Id: StorageHandler.java,v 1.1 2002/02/24 17:01:33 baliuka Exp $
   */
  
  public interface StorageHandler extends ContentHandler {
      
      /**
       * An empty element event handling method.
       * @param data value or null
       */
      public void handle_reference(final Attributes meta) throws SAXException;
      
      /**
       * A container element start event handling method.
       * @param meta attributes
       */
      public void start_validator(final Attributes meta) throws SAXException;
      
      /**
       * A container element end event handling method.
       */
      public void end_validator() throws SAXException;
      
      /**
       * A data element event handling method.
       * @param data value or null
       * @param meta attributes
       */
      public void handle_property(final java.lang.String data, final Attributes meta) throws SAXException;
      
      /**
       * A container element start event handling method.
       * @param meta attributes
       */
      public void start_field(final Attributes meta) throws SAXException;
      
      /**
       * A container element end event handling method.
       */
      public void end_field() throws SAXException;
      
      /**
       * A container element start event handling method.
       * @param meta attributes
       */
      public void start_storage(final Attributes meta) throws SAXException;
      
      /**
       * A container element end event handling method.
       */
      public void end_storage() throws SAXException;
      
      /**
       * A container element start event handling method.
       * @param meta attributes
       */
      public void start_mclass(final Attributes meta) throws SAXException;
      
      /**
       * A container element end event handling method.
       */
      public void end_mclass() throws SAXException;
      
  }
  
  
  
  
  1.1                  jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/res/StorageParser.java
  
  Index: StorageParser.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache Cocoon" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.simplestore.res;
  
  import org.xml.sax.*;
  
  /**
   * The class reads XML documents according to specified DTD and
   * translates all related events into StorageHandler events.
   * <p>Usage sample:
   * <pre>
   *    StorageParser parser = new StorageParser(...);
   *    parser.parse(new InputSource("..."));
   * </pre>
   * <p><b>Warning:</b> the class is machine generated. DO NOT MODIFY</p>
   *@author     Juozas Baliuka <a href="mailto:baliuka@mwm.lt">
   *      baliuka@mwm.lt</a>
   *@version    $Id: StorageParser.java,v 1.1 2002/02/24 17:01:33 baliuka Exp $
   */
  
  
  public class StorageParser implements ContentHandler {
      
      private java.lang.StringBuffer buffer;
      
      private StorageHandler handler;
      
      private java.util.Stack context;
      
      private EntityResolver resolver;
      
      /**
       * Creates a parser instance.
       * @param handler handler interface implementation (never <code>null</code>
       * @param resolver SAX entity resolver implementation or <code>null</code>.
       * It is recommended that it could be able to resolve at least the DTD. */
      public StorageParser(final StorageHandler handler, final EntityResolver resolver) {
          this.handler = handler;
          this.resolver = resolver;
          buffer = new StringBuffer(111);
          context = new java.util.Stack();
      }
      
      /**
       * This SAX interface method is implemented by the parser.
       */
      public final void setDocumentLocator(Locator locator) {
          handler.setDocumentLocator(locator);
      }
      
      /**
       * This SAX interface method is implemented by the parser.
       */
      public final void startDocument() throws SAXException {
          handler.startDocument();
      }
      
      /**
       * This SAX interface method is implemented by the parser.
       */
      public final void endDocument() throws SAXException {
          handler.endDocument();
      }
      
      /**
       * This SAX interface method is implemented by the parser.
       */
      public final void startElement(java.lang.String ns, java.lang.String name, java.lang.String qname, Attributes attrs) throws SAXException {
          dispatch(true);
          context.push(new Object[] {qname, new org.xml.sax.helpers.AttributesImpl(attrs)});
          if ("reference".equals(name)) {
              handler.handle_reference(attrs);
          } else if ("validator".equals(name)) {
              handler.start_validator(attrs);
          } else if ("field".equals(name)) {
              handler.start_field(attrs);
          } else if ("storage".equals(name)) {
              handler.start_storage(attrs);
          } else if ("mclass".equals(name)) {
              handler.start_mclass(attrs);
          }
          handler.startElement(ns, name, qname, attrs);
      }
      
      /**
       * This SAX interface method is implemented by the parser.
       */
      public final void endElement(java.lang.String ns, java.lang.String name, java.lang.String qname) throws SAXException {
          dispatch(false);
          context.pop();
          if ("validator".equals(name)) {
              handler.end_validator();
          } else if ("field".equals(name)) {
              handler.end_field();
          } else if ("storage".equals(name)) {
              handler.end_storage();
          } else if ("mclass".equals(name)) {
              handler.end_mclass();
          }
          handler.endElement(ns, name, qname);
      }
      
      /**
       * This SAX interface method is implemented by the parser.
       */
      public final void characters(char[] chars, int start, int len) throws SAXException {
          buffer.append(chars, start, len);handler.characters(chars, start, len);
      }
      
      /**
       * This SAX interface method is implemented by the parser.
       */
      public final void ignorableWhitespace(char[] chars, int start, int len) throws SAXException {
          handler.ignorableWhitespace(chars, start, len);
      }
      
      /**
       * This SAX interface method is implemented by the parser.
       */
      public final void processingInstruction(java.lang.String target, java.lang.String data) throws SAXException {
          handler.processingInstruction(target, data);
      }
      
      /**
       * This SAX interface method is implemented by the parser.
       */
      public final void startPrefixMapping(final java.lang.String prefix, final java.lang.String uri) throws SAXException {
          handler.startPrefixMapping(prefix, uri);
      }
      
      /**
       * This SAX interface method is implemented by the parser.
       */
      public final void endPrefixMapping(final java.lang.String prefix) throws SAXException {
          handler.endPrefixMapping(prefix);
      }
      
      /**
       * This SAX interface method is implemented by the parser.
       */
      public final void skippedEntity(java.lang.String name) throws SAXException {
          handler.skippedEntity(name);
      }
      
      private void dispatch(final boolean fireOnlyIfMixed) throws SAXException {
          if (fireOnlyIfMixed && buffer.length() == 0) return; //skip it
          
          Object[] ctx = (Object[]) context.peek();
          String here = (String) ctx[0];
          Attributes attrs = (Attributes) ctx[1];
          if ("property".equals(here)) {
              if (fireOnlyIfMixed) throw new IllegalStateException("Unexpected characters() event! (Missing DTD?)");
              handler.handle_property(buffer.length() == 0 ? null : buffer.toString(), attrs);
          } else {
              //do not care
          }
          buffer.delete(0, buffer.length());
      }
      
      /**
       * The recognizer entry method taking an InputSource.
       * @param input InputSource to be parsed.
       * @throws java.io.IOException on I/O error.
       * @throws SAXException propagated exception thrown by a DocumentHandler.
       * @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created.
       * @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated.
       */
      public void parse(final InputSource input) throws SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException {
          parse(input, this);
      }
      
      /**
       * The recognizer entry method taking a URL.
       * @param url URL source to be parsed.
       * @throws java.io.IOException on I/O error.
       * @throws SAXException propagated exception thrown by a DocumentHandler.
       * @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created.
       * @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated.
       */
      public void parse(final java.net.URL url) throws SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException {
          parse(new InputSource(url.toExternalForm()), this);
      }
      
      /**
       * The recognizer entry method taking an Inputsource.
       * @param input InputSource to be parsed.
       * @throws java.io.IOException on I/O error.
       * @throws SAXException propagated exception thrown by a DocumentHandler.
       * @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created.
       * @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated.
       */
      public static void parse(final InputSource input, final StorageHandler handler) throws SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException {
          parse(input, new StorageParser(handler, null));
      }
      
      /**
       * The recognizer entry method taking a URL.
       * @param url URL source to be parsed.
       * @throws java.io.IOException on I/O error.
       * @throws SAXException propagated exception thrown by a DocumentHandler.
       * @throws javax.xml.parsers.ParserConfigurationException a parser satisfining requested configuration can not be created.
       * @throws javax.xml.parsers.FactoryConfigurationRrror if the implementation can not be instantiated.
       */
      public static void parse(final java.net.URL url, final StorageHandler handler) throws SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException {
          parse(new InputSource(url.toExternalForm()), handler);
      }
      
      private static void parse(final InputSource input, final StorageParser recognizer) throws SAXException, javax.xml.parsers.ParserConfigurationException, java.io.IOException {
          javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance();
          factory.setValidating(false);  //the code was generated according DTD
          factory.setNamespaceAware(false);  //the code was generated according DTD
          XMLReader parser = factory.newSAXParser().getXMLReader();
          parser.setContentHandler(recognizer);
          parser.setErrorHandler(recognizer.getDefaultErrorHandler());
          if (recognizer.resolver != null) parser.setEntityResolver(recognizer.resolver);
          parser.parse(input);
      }
      
      /**
       * Creates default error handler used by this parser.
       * @return org.xml.sax.ErrorHandler implementation
       */
      protected ErrorHandler getDefaultErrorHandler() {
          return new ErrorHandler() {
              public void error(SAXParseException ex) throws SAXException  {
                  if (context.isEmpty()) System.err.println("Missing DOCTYPE.");
                  throw ex;
              }
              
              public void fatalError(SAXParseException ex) throws SAXException {
                  throw ex;
              }
              
              public void warning(SAXParseException ex) throws SAXException {
                  // ignore
              }
          };
          
      }
      
  }
  
  
  
  
  1.1                  jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/res/storage.dtd
  
  Index: storage.dtd
  ===================================================================
  <?xml version='1.0' encoding='UTF-8'?>
  
  <!--
      Typical usage:
  
      <?xml version="1.0"?>
  
      <!DOCTYPE storage SYSTEM "storage.dtd">
  
      <storage>
      ...
      </storage>
  -->
  
  <!ELEMENT field (reference|validator)*>
  <!ATTLIST field
      name CDATA #IMPLIED
      id CDATA #IMPLIED
    >
  
  <!ELEMENT mclass (field)*>
  <!ATTLIST mclass
      name CDATA #IMPLIED
      id   CDATA #IMPLIED
      oid  CDATA #IMPLIED
    >
  
  <!ELEMENT property (#PCDATA)>
  <!ATTLIST property
      name CDATA #IMPLIED
    >
  
  <!ELEMENT reference EMPTY>
  <!ATTLIST reference
      field CDATA #IMPLIED
      mclass CDATA #IMPLIED
    >
  
  <!ELEMENT storage (mclass)*>
  
  <!ELEMENT validator (property)*>
  <!ATTLIST validator
      id CDATA #IMPLIED
    >
  
  
  
  1.1                  jakarta-commons-sandbox/simplestore/src/java/org/apache/commons/simplestore/res/storage.xml
  
  Index: storage.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <!DOCTYPE storage SYSTEM "storage.dtd">
  
  <storage>
      <mclass id="className" name="table" oid="fieldName">
          <field id="propName" name="fieldName">
              <reference mclass="className" field="propName"></reference>
              <validator id="SomeClass">
                  <property name="SomeProp">0</property>
              </validator>
          </field>
      </mclass>
  </storage>
  
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>