You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2004/02/08 13:11:18 UTC

cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/schema TestSchemaTranscriber.java TestSchemaValidity.java

rdonkin     2004/02/08 04:11:18

  Modified:    betwixt/src/java/org/apache/commons/betwixt Tag:
                        REFACTORING-BRANCH_2004-01-13 XMLIntrospector.java
               betwixt/src/java/org/apache/commons/betwixt/digester Tag:
                        REFACTORING-BRANCH_2004-01-13 ElementRule.java
               betwixt/src/java/org/apache/commons/betwixt/schema Tag:
                        REFACTORING-BRANCH_2004-01-13 ComplexType.java
                        Element.java LocalElement.java Schema.java
               betwixt/src/test/org/apache/commons/betwixt Tag:
                        REFACTORING-BRANCH_2004-01-13 TestCollectives.java
               betwixt/src/test/org/apache/commons/betwixt/dotbetwixt Tag:
                        REFACTORING-BRANCH_2004-01-13
                        TestIntrospection.java
               betwixt/src/test/org/apache/commons/betwixt/introspection
                        Tag: REFACTORING-BRANCH_2004-01-13
                        TestDeclarativeIntrospection.java
               betwixt/src/test/org/apache/commons/betwixt/schema Tag:
                        REFACTORING-BRANCH_2004-01-13
                        TestSchemaTranscriber.java TestSchemaValidity.java
  Log:
  Added support for complex schema generation including RSS.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.27.2.9  +6 -5      jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java
  
  Index: XMLIntrospector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/XMLIntrospector.java,v
  retrieving revision 1.27.2.8
  retrieving revision 1.27.2.9
  diff -u -r1.27.2.8 -r1.27.2.9
  --- XMLIntrospector.java	29 Jan 2004 22:15:22 -0000	1.27.2.8
  +++ XMLIntrospector.java	8 Feb 2004 12:11:17 -0000	1.27.2.9
  @@ -703,7 +703,7 @@
                   Method method = methods[i];
                   String name = method.getName();
                   if ( name.startsWith( "add" )) {
  -                    // XXX: should we filter out non-void returning methods?
  +                    // TODO: should we filter out non-void returning methods?
                       // some beans will return something as a helper
                       Class[] types = method.getParameterTypes();
                       if ( types != null) {
  @@ -765,6 +765,7 @@
                                       
               matchingDescriptor.setUpdater( new MethodUpdater( singleParameterAdderMethod ) );
               matchingDescriptor.setSingularPropertyType( singularType );
  +            matchingDescriptor.setHollow(!isPrimitiveType(singularType));
               String localName = matchingDescriptor.getLocalName();
               if ( localName == null || localName.length() == 0 ) {
                   matchingDescriptor.setLocalName( 
  
  
  
  No                   revision
  No                   revision
  1.13.2.6  +12 -7     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java
  
  Index: ElementRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java,v
  retrieving revision 1.13.2.5
  retrieving revision 1.13.2.6
  diff -u -r1.13.2.5 -r1.13.2.6
  --- ElementRule.java	1 Feb 2004 22:55:47 -0000	1.13.2.5
  +++ ElementRule.java	8 Feb 2004 12:11:17 -0000	1.13.2.6
  @@ -270,10 +270,13 @@
           Method readMethod = propertyDescriptor.getReadMethod();
           Method writeMethod = propertyDescriptor.getWriteMethod();
           
  -        elementDescriptor.setLocalName( propertyDescriptor.getName() );
  +        String existingLocalName = elementDescriptor.getLocalName();
  +        if (existingLocalName == null || "".equals(existingLocalName)) {
  +            elementDescriptor.setLocalName( propertyDescriptor.getName() );
  +        }
           elementDescriptor.setPropertyType( type );        
           
  -        // XXX: associate more bean information with the descriptor?
  +        // TODO: associate more bean information with the descriptor?
           //nodeDescriptor.setDisplayName( propertyDescriptor.getDisplayName() );
           //nodeDescriptor.setShortDescription( propertyDescriptor.getShortDescription() );
           
  @@ -288,7 +291,7 @@
           
           // choose response from property type
           
  -        // XXX: ignore class property ??
  +        // TODO: ignore class property ??
           if ( Class.class.equals( type ) && "class".equals( propertyDescriptor.getName() ) ) {
               log.trace( "Ignoring class property" );
               return;
  @@ -304,10 +307,12 @@
               elementDescriptor.setContextExpression(
                   new IteratorExpression( new MethodExpression( readMethod ) )
               );
  +            elementDescriptor.setHollow(true);
   
               writeMethod = null;
           } else {
               log.trace( "Standard property" );
  +            elementDescriptor.setHollow(true);
               elementDescriptor.setContextExpression( new MethodExpression( readMethod ) );
           }
       
  
  
  
  No                   revision
  No                   revision
  1.1.2.7   +55 -119   jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/ComplexType.java
  
  Index: ComplexType.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/ComplexType.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- ComplexType.java	7 Feb 2004 14:44:45 -0000	1.1.2.6
  +++ ComplexType.java	8 Feb 2004 12:11:17 -0000	1.1.2.7
  @@ -63,35 +63,24 @@
   
   import java.beans.IntrospectionException;
   import java.util.ArrayList;
  -import java.util.Iterator;
   import java.util.List;
   
   import org.apache.commons.betwixt.AttributeDescriptor;
   import org.apache.commons.betwixt.ElementDescriptor;
   import org.apache.commons.betwixt.XMLBeanInfo;
  -import org.apache.commons.collections.CollectionUtils;
   
   /**
  - * Models a <code>complexType</code> from an XML schema.
  - * A complex type may contain element content and may have attributes.
    * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
    * @version $Revision$
    */
  -public class ComplexType {
  -	
  -	private String name;
  -	
  -	private List elements = new ArrayList();
  -	private List attributes = new ArrayList();
  -	
  +public abstract class ComplexType {
   
  +    protected List elements = new ArrayList();
  +
  +    protected List attributes = new ArrayList();
   
       public ComplexType() {}
  -    
  -    /**
  -     * Constructs a new ComplexType from the descriptor given.
  -     * @param elementDescriptor
  -     */
  +
       public ComplexType(ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException {
           if (elementDescriptor.isHollow()) {
               // need to introspector for filled descriptor
  @@ -105,8 +94,8 @@
           init(elementDescriptor, schema);      
       }
   
  -    private void init(ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException {
  -        setName(elementDescriptor.getPropertyType().getName());
  +    protected void init(ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException {
  +        
           AttributeDescriptor[] attributeDescriptors = elementDescriptor.getAttributeDescriptors();
           for (int i=0,length=attributeDescriptors.length; i<length ; i++) {
               //TODO: need to think about computing schema types from descriptors
  @@ -120,108 +109,55 @@
           //TODO: add support for spacing elements
           ElementDescriptor[] elementDescriptors = elementDescriptor.getElementDescriptors();
           for (int i=0,length=elementDescriptors.length; i<length ; i++) {
  -                elements.add(new LocalElement(elementDescriptors[i], schema));
  +            if (elementDescriptors[i].isHollow()) {
  +                elements.add(new ElementReference(elementDescriptors[i], schema));
  +            } else if (elementDescriptors[i].isSimple()){
  +                elements.add(new SimpleLocalElement(elementDescriptors[i], schema));
  +            } else {
  +                elements.add(new ComplexLocalElement(elementDescriptors[i], schema));
  +            }
           } 
       }
   
  -	/**
  -	 * Gets the elements contained by this type
  -	 * @return 
  -	 */
  -	public List getElements() {
  -		return elements;
  -	}
  -
  -	/**
  -	 * Adds an element to those contained by this type
  -	 * @param element
  -	 */
  -	public void addElement(LocalElement element) {
  -		elements.add(element);
  -	}
  -	
  -	/**
  -	 * Gets the attributes contained by this type.
  -	 * @return
  -	 */
  -	public List getAttributes() {
  -		return attributes;
  -	}
  -	
  -	/**
  -	 * Adds an attribute to those contained by this type
  -	 * @param attribute
  -	 */
  -	public void addAttribute(Attribute attribute) {
  -		attributes.add(attribute);
  -	}
  -	
       /**
  -     * Gets the name of this type.
  -     * @return
  -     */
  -    public String getName() {
  -        return name;
  +    	 * Gets the elements contained by this type
  +    	 * @return 
  +    	 */
  +    public List getElements() {
  +    	return elements;
       }
   
       /**
  -     * Sets the name of this type.
  -     * @param string
  -     */
  -    public void setName(String string) {
  -        name = string;
  -    }
  -
  -    public boolean equals(Object obj) {
  -          boolean result = false;
  -          if (obj instanceof ComplexType) {
  -              ComplexType complexType = (ComplexType) obj;
  -              result =  isEqual(name, complexType.name) &&
  -                        CollectionUtils.isEqualCollection(attributes, complexType.attributes) &&
  -                        CollectionUtils.isEqualCollection(elements, complexType.elements);
  -                                   
  -          }
  -          return result;
  -      }
  -
  -    public int hashCode() {
  -        return 0;
  -    }
  -
  -      /**
  -       * Null safe equals method
  -       * @param one
  -       * @param two
  -       * @return
  -       */
  -      private boolean isEqual(String one, String two) {
  -          boolean result = false;
  -          if (one == null) {
  -              result = (two == null); 
  -          }
  -          else
  -          {
  -              result = one.equals(two);
  -          }
  -        
  -          return result;
  -      }
  -      
  -      public String toString() {
  -          StringBuffer buffer = new StringBuffer();
  -          buffer.append("<xsd:complexType name='");
  -          buffer.append(name);
  -          buffer.append("'>");
  -          buffer.append("<xsd:sequence>");
  -          for (Iterator it=elements.iterator(); it.hasNext();) {
  -                buffer.append(it.next());    
  -          }
  -          buffer.append("</xsd:sequence>");
  -          
  -          for (Iterator it=attributes.iterator(); it.hasNext();) {
  -                buffer.append(it.next());    
  -          }
  -          buffer.append("</xsd:complexType>");
  -          return buffer.toString();
  -      }
  +    	 * Adds an element to those contained by this type
  +    	 * @param element
  +    	 */
  +    public void addElement(ElementReference element) {
  +    	elements.add(element);
  +    }
  +    
  +    /**
  +          * Adds an element to those contained by this type
  +          * @param element
  +          */
  +     public void addElement(LocalElement element) {
  +         elements.add(element);
  +     }
  +
  +
  +    /**
  +    	 * Gets the attributes contained by this type.
  +    	 * @return
  +    	 */
  +    public List getAttributes() {
  +    	return attributes;
  +    }
  +
  +    /**
  +    	 * Adds an attribute to those contained by this type
  +    	 * @param attribute
  +    	 */
  +    public void addAttribute(Attribute attribute) {
  +    	attributes.add(attribute);
  +    }
  +
   }
  
  
  
  1.1.2.5   +9 -8      jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/Element.java
  
  Index: Element.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/Element.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- Element.java	7 Feb 2004 14:44:45 -0000	1.1.2.4
  +++ Element.java	8 Feb 2004 12:11:17 -0000	1.1.2.5
  @@ -62,6 +62,7 @@
   package org.apache.commons.betwixt.schema;
   
   
  +
   /**
    * Models the Element tag in the XML schema.
    * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
  @@ -74,7 +75,7 @@
   	private String name;
   	private String type;
   
  -    private ComplexType complexType;
  +    private GlobalComplexType complexType;
   	
   	public Element() {}
       
  @@ -83,7 +84,7 @@
           setType(type);
       }
       
  -    public Element(String name, ComplexType complexType) {
  +    public Element(String name, GlobalComplexType complexType) {
           setName(name);
           setComplexType(complexType);
       }
  @@ -128,7 +129,7 @@
        * Gets the anonymous type definition for this element, if one exists.
        * @return ComplexType, null if there is no associated anonymous type definition
        */
  -    public ComplexType getComplexType() {
  +    public GlobalComplexType getComplexType() {
           return complexType;
       }
   
  @@ -137,7 +138,7 @@
        * @param type ComplexType to be set as the anonymous type definition, 
        * null if the type is to be referenced
        */
  -    public void setComplexType(ComplexType type) {
  +    public void setComplexType(GlobalComplexType type) {
           this.type = type.getName();
           complexType = type;
       }    
  
  
  
  1.1.2.2   +24 -29    jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/LocalElement.java
  
  Index: LocalElement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/LocalElement.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- LocalElement.java	7 Feb 2004 14:45:31 -0000	1.1.2.1
  +++ LocalElement.java	8 Feb 2004 12:11:17 -0000	1.1.2.2
  @@ -69,50 +69,45 @@
    * @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
    * @version $Revision$
    */
  -public class LocalElement extends Element {
  -    /**
  -     * @param string
  -     * @param productBeanType
  -     */
  -    public LocalElement(String string, ComplexType complexType) {
  -        
  -        super(string, complexType);
  -    }
  +public class LocalElement {
  +
  +    protected String name;
  +    
  +    protected String maxOccurs = "1";
   
  -    private String maxOccurs = "1";
  -    private int minOccurs = 0;
  +    protected int minOccurs = 0;
       
  -    public LocalElement(String name, String type) {
  -        super(name, type);
  +    public LocalElement(String name) {
  +        this.name = name;
       }
   
  -    public LocalElement(ElementDescriptor elementDescriptor, Schema schema) throws IntrospectionException {
  -        setName(elementDescriptor.getLocalName());
  -        if (elementDescriptor.isHollow()) {
  -            setComplexType( new ComplexType(elementDescriptor, schema));
  -            schema.addComplexType(getComplexType());
  -            if (elementDescriptor.isCollective()) {
  -                maxOccurs = "unbounded";
  -            }
  -        } else {
  -            
  -            setType("xsd:string");
  +    public LocalElement(ElementDescriptor descriptor, Schema schema) throws IntrospectionException {
  +        setName(descriptor.getLocalName());
  +        if (descriptor.isCollective()) {
  +            setMaxOccurs("unbounded");
           }
       }
  -    
  -    
  +
  +    public String getName() {
  +        return name;
  +    }
  +
  +    public void setName(String string) {
  +        name = string;
  +    }
  +
       public int getMinOccurs() {
           return minOccurs;
       }
  -    
  +
       public void setMinOccurs(int minOccurs) {
           this.minOccurs = minOccurs;
       }
  -    
  +
       public String getMaxOccurs() {
           return maxOccurs;
       }
  -    
  +
       public void setMaxOccurs(String maxOccurs) {
           this.maxOccurs = maxOccurs;
       }
  
  
  
  1.1.2.6   +6 -6      jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/Schema.java
  
  Index: Schema.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/Schema.java,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- Schema.java	7 Feb 2004 14:44:45 -0000	1.1.2.5
  +++ Schema.java	8 Feb 2004 12:11:17 -0000	1.1.2.6
  @@ -116,7 +116,7 @@
   	 * Adds a new complex type to those defined
   	 * @param complexType not null
   	 */
  -	public void addComplexType(ComplexType complexType) {
  +	public void addComplexType(GlobalComplexType complexType) {
   		complexTypes.add(complexType);
   	}
   	
  @@ -166,7 +166,7 @@
                               elementDescriptor.getPropertyType().getName());
           addElement(element);
           
  -        ComplexType type = new ComplexType(elementDescriptor, this);
  +        GlobalComplexType type = new GlobalComplexType(elementDescriptor, this);
           addComplexType(type);
       }	
   	
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +5 -5      jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/Attic/TestCollectives.java
  
  Index: TestCollectives.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/Attic/TestCollectives.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- TestCollectives.java	7 Feb 2004 16:31:58 -0000	1.1.2.1
  +++ TestCollectives.java	8 Feb 2004 12:11:17 -0000	1.1.2.2
  @@ -118,7 +118,7 @@
           beanReader.getXMLIntrospector().setConfiguration(categoriesIntrospectionConfiguration);
           beanReader.setBindingConfiguration(noIDsBindingConfiguration);
           beanReader.registerBeanClass(Categories.class);
  -        
  +
           String xml = "<?xml version='1.0'?><Categories>" +
               "<Category><Name>Runs</Name></Category>" +
               "<Category><Name>Innings</Name></Category>" +
  
  
  
  No                   revision
  No                   revision
  1.4.2.1   +4 -4      jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestIntrospection.java
  
  Index: TestIntrospection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestIntrospection.java,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- TestIntrospection.java	19 Oct 2003 14:44:53 -0000	1.4
  +++ TestIntrospection.java	8 Feb 2004 12:11:17 -0000	1.4.2.1
  @@ -100,7 +100,7 @@
           ElementDescriptor[] elementDescriptors = beanInfo.getElementDescriptor().getElementDescriptors();
           ElementDescriptor elementsElementDescriptor = null;
           for ( int i=0, size = elementDescriptors.length; i<size ; i++ ) {
  -            if ( "examples".equals( elementDescriptors[i].getLocalName() ) ) {
  +            if ( "example".equals( elementDescriptors[i].getLocalName() ) ) {
                   elementsElementDescriptor = elementDescriptors[i];
               }
           }
  
  
  
  No                   revision
  No                   revision
  1.1.2.6   +42 -4     jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/Attic/TestDeclarativeIntrospection.java
  
  Index: TestDeclarativeIntrospection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/Attic/TestDeclarativeIntrospection.java,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- TestDeclarativeIntrospection.java	29 Jan 2004 22:15:22 -0000	1.1.2.5
  +++ TestDeclarativeIntrospection.java	8 Feb 2004 12:11:17 -0000	1.1.2.6
  @@ -67,6 +67,7 @@
   import org.apache.commons.betwixt.ElementDescriptor;
   import org.apache.commons.betwixt.XMLBeanInfo;
   import org.apache.commons.betwixt.XMLIntrospector;
  +import org.apache.commons.betwixt.examples.rss.Channel;
   
   /**
    * Tests for the new, more declarative style of introspection.
  @@ -261,4 +262,41 @@
           assertTrue("Descriptor " + phoneNumberChildDescriptors[2] + " should be simple", 
                       phoneNumberChildDescriptors[2].isSimple());
       }
  +    
  +    public void testSimpleForRSS() throws Exception {
  +        XMLIntrospector introspector = new XMLIntrospector();
  +        introspector.getConfiguration().setWrapCollectionsInElement(true);
  +        introspector.getConfiguration().setAttributesForPrimitives(false);
  +        XMLBeanInfo out = introspector.introspect(Channel.class);
  +        
  +        ElementDescriptor channelDescriptor = out.getElementDescriptor();
  +        ElementDescriptor[] childNodesOfRSS = channelDescriptor.getElementDescriptors();
  +        assertEquals("RSS has only one child, channel", 1, childNodesOfRSS.length);
  +        ElementDescriptor[] childNodesOfChannel = childNodesOfRSS[0].getElementDescriptors();
  +        
  +        boolean matched = false;
  +        for (int i=0, size=childNodesOfChannel.length; i<size; i++) {
  +            if ("item".equals(childNodesOfChannel[i].getLocalName())) {
  +                matched = true;   
  +            }   
  +        }
  +        assertTrue("Local element named item", matched);
  +        
  +        for (int i=0, size=childNodesOfChannel.length; i<size; i++) {
  +            if ("title".equals(childNodesOfChannel[i].getLocalName())) {
  +                assertFalse("Title is not hollow", childNodesOfChannel[i].isHollow());
  +            } else if ("item".equals(childNodesOfChannel[i].getLocalName())) {
  +                assertTrue("Item is hollow", childNodesOfChannel[i].isHollow());
  +            } else if ("textinput".equals(childNodesOfChannel[i].getLocalName())) {
  +                assertTrue("TextInput is hollow", childNodesOfChannel[i].isHollow());
  +            } else if ("skipDays".equals(childNodesOfChannel[i].getLocalName())) {
  +                assertFalse("skipDays is not hollow", childNodesOfChannel[i].isHollow());
  +                assertFalse("day is not hollow", childNodesOfChannel[i].getElementDescriptors()[0].isHollow());
  +            } else if ("skipHours".equals(childNodesOfChannel[i].getLocalName())) {
  +                assertFalse("skipHours is not hollow", childNodesOfChannel[i].isHollow());
  +                assertFalse("hour is not hollow", childNodesOfChannel[i].getElementDescriptors()[0].isHollow());
  +            }    
  +        }
  +    }
  +    
   }
  
  
  
  No                   revision
  No                   revision
  1.1.2.6   +23 -23    jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/schema/Attic/TestSchemaTranscriber.java
  
  Index: TestSchemaTranscriber.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/schema/Attic/TestSchemaTranscriber.java,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- TestSchemaTranscriber.java	7 Feb 2004 14:44:45 -0000	1.1.2.5
  +++ TestSchemaTranscriber.java	8 Feb 2004 12:11:17 -0000	1.1.2.6
  @@ -82,7 +82,7 @@
       public void testSimplestBeanAttribute() throws Exception {
           Schema expected = new Schema();
           
  -        ComplexType simplestBeanType = new ComplexType();
  +        GlobalComplexType simplestBeanType = new GlobalComplexType();
           simplestBeanType.setName("org.apache.commons.betwixt.schema.SimplestBean");
           simplestBeanType.addAttribute(new Attribute("name", "xsd:string"));
           
  @@ -100,9 +100,9 @@
       public void testSimplestBeanElement() throws Exception {
           Schema expected = new Schema();
           
  -        ComplexType simplestBeanType = new ComplexType();
  +        GlobalComplexType simplestBeanType = new GlobalComplexType();
           simplestBeanType.setName("org.apache.commons.betwixt.schema.SimplestElementBean");
  -        simplestBeanType.addElement(new LocalElement("name", "xsd:string"));
  +        simplestBeanType.addElement(new SimpleLocalElement("name", "xsd:string"));
           
           Element root = new Element("SimplestBean", "org.apache.commons.betwixt.schema.SimplestElementBean");
           expected.addComplexType(simplestBeanType);
  @@ -120,12 +120,12 @@
   		Schema out = transcriber.generate(SimpleBean.class);
   		
   		Schema expected = new Schema();
  -		ComplexType simpleBeanType = new ComplexType();
  +		GlobalComplexType simpleBeanType = new GlobalComplexType();
   		simpleBeanType.setName("org.apache.commons.betwixt.schema.SimpleBean");
   		simpleBeanType.addAttribute(new Attribute("one", "xsd:string"));
   		simpleBeanType.addAttribute(new Attribute("two", "xsd:string"));
  -		simpleBeanType.addElement(new LocalElement("three", "xsd:string"));
  -		simpleBeanType.addElement(new LocalElement("four", "xsd:string"));
  +		simpleBeanType.addElement(new SimpleLocalElement("three", "xsd:string"));
  +		simpleBeanType.addElement(new SimpleLocalElement("four", "xsd:string"));
   		expected.addComplexType(simpleBeanType);
           expected.addElement(new Element("simple", "org.apache.commons.betwixt.schema.SimpleBean"));
           
  @@ -141,7 +141,7 @@
           
           Schema expected = new Schema();
           
  -        ComplexType productBeanType = new ComplexType();
  +        GlobalComplexType productBeanType = new GlobalComplexType();
           productBeanType.setName(ProductBean.class.getName());
           productBeanType.addAttribute(new Attribute("barcode", "xsd:string"));
           productBeanType.addAttribute(new Attribute("code", "xsd:string"));
  @@ -149,10 +149,10 @@
           productBeanType.addAttribute(new Attribute("display-name", "xsd:string"));
           expected.addComplexType(productBeanType);
           
  -        ComplexType orderLineType = new ComplexType();       
  +        GlobalComplexType orderLineType = new GlobalComplexType();       
           orderLineType.setName(OrderLineBean.class.getName());
           orderLineType.addAttribute(new Attribute("quantity", "xsd:string"));
  -        orderLineType.addElement(new LocalElement("product", productBeanType));
  +        orderLineType.addElement(new ElementReference("product", productBeanType));
           expected.addComplexType(orderLineType);
           expected.addElement(new Element("OrderLineBean", OrderLineBean.class.getName()));
           
  @@ -171,7 +171,7 @@
           Schema expected = new Schema();
           
           
  -        ComplexType customerBeanType = new ComplexType();
  +        GlobalComplexType customerBeanType = new GlobalComplexType();
           customerBeanType.setName(CustomerBean.class.getName());
           customerBeanType.addAttribute(new Attribute("code", "xsd:string"));
           customerBeanType.addAttribute(new Attribute("name", "xsd:string"));
  @@ -181,7 +181,7 @@
           customerBeanType.addAttribute(new Attribute("postcode", "xsd:string"));
           expected.addComplexType(customerBeanType);
           
  -        ComplexType productBeanType = new ComplexType();
  +        GlobalComplexType productBeanType = new GlobalComplexType();
           productBeanType.setName(ProductBean.class.getName());
           productBeanType.addAttribute(new Attribute("barcode", "xsd:string"));
           productBeanType.addAttribute(new Attribute("code", "xsd:string"));
  @@ -189,17 +189,17 @@
           productBeanType.addAttribute(new Attribute("display-name", "xsd:string"));
           expected.addComplexType(productBeanType);
           
  -        ComplexType orderLineType = new ComplexType();       
  +        GlobalComplexType orderLineType = new GlobalComplexType();       
           orderLineType.setName(OrderLineBean.class.getName());
           orderLineType.addAttribute(new Attribute("quantity", "xsd:string"));
  -        orderLineType.addElement(new LocalElement("product", productBeanType));
  +        orderLineType.addElement(new ElementReference("product", productBeanType));
           expected.addComplexType(orderLineType);
           
  -        ComplexType orderType = new ComplexType();       
  +        GlobalComplexType orderType = new GlobalComplexType();       
           orderType.setName(OrderBean.class.getName());
           orderType.addAttribute(new Attribute("code", "xsd:string"));
  -        orderType.addElement(new LocalElement("customer", customerBeanType));
  -        orderType.addElement(new LocalElement("line", orderLineType));
  +        orderType.addElement(new ElementReference("customer", customerBeanType));
  +        orderType.addElement(new ElementReference("line", orderLineType));
           expected.addComplexType(orderType);
           expected.addElement(new Element("order-bean", OrderBean.class.getName()));
           
  @@ -208,11 +208,11 @@
       
       private void printDifferences(Schema one, Schema two) {
           for( Iterator it=one.getComplexTypes().iterator();it.hasNext(); ) {
  -            ComplexType complexType = (ComplexType)it.next();
  +            GlobalComplexType complexType = (GlobalComplexType)it.next();
               if (!two.getComplexTypes().contains(complexType)) {
                   boolean matched = false;
                   for (Iterator otherIter=two.getComplexTypes().iterator(); it.hasNext();) {
  -                    ComplexType otherType = (ComplexType) otherIter.next();
  +                    GlobalComplexType otherType = (GlobalComplexType) otherIter.next();
                       if (otherType.getName().equals(complexType.getName())) {
                           printDifferences(complexType, otherType);
                           matched = true;
  @@ -227,7 +227,7 @@
           
       }
       
  -    private void printDifferences(ComplexType one, ComplexType two) {
  +    private void printDifferences(GlobalComplexType one, GlobalComplexType two) {
           System.err.println("Type " + one + " is not equal to " + two);
           for (Iterator it = one.getElements().iterator(); it.hasNext();) {
               Element elementOne = (Element) it.next();
  
  
  
  1.1.2.7   +74 -4     jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/schema/Attic/TestSchemaValidity.java
  
  Index: TestSchemaValidity.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/schema/Attic/TestSchemaValidity.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- TestSchemaValidity.java	7 Feb 2004 14:44:45 -0000	1.1.2.6
  +++ TestSchemaValidity.java	8 Feb 2004 12:11:17 -0000	1.1.2.7
  @@ -65,6 +65,10 @@
   import java.io.StringWriter;
   
   import org.apache.commons.betwixt.AbstractTestCase;
  +import org.apache.commons.betwixt.examples.rss.Channel;
  +import org.apache.commons.betwixt.examples.rss.Image;
  +import org.apache.commons.betwixt.examples.rss.Item;
  +import org.apache.commons.betwixt.examples.rss.TextInput;
   import org.apache.commons.betwixt.io.BeanWriter;
   import org.apache.commons.betwixt.strategy.HyphenatedNameMapper;
   import org.xml.sax.InputSource;
  @@ -223,6 +227,72 @@
                 new OrderLineBean(5, new ProductBean("00112235", "A13", "Black Sheep Special", "Black Sheep Special")));
           writer.write(bean);
          
  +        String xml = out.getBuffer().toString();
  +       
  +        xmlAssertIsValid(new InputSource(new StringReader(xml)), new InputSource(new StringReader(xsd)));  
  +        
  +    }
  +    
  +    
  +    private String generateRSSSchema() throws Exception {
  +        SchemaTranscriber transcriber = new SchemaTranscriber();
  +        Schema schema = transcriber.generate(Channel.class);
  +        
  +        StringWriter out = new StringWriter();
  +        out.write("<?xml version='1.0'?>");
  +        BeanWriter writer = new BeanWriter(out);
  +        writer.setBindingConfiguration(transcriber.createSchemaBindingConfiguration());
  +        writer.getXMLIntrospector().setConfiguration(transcriber.createSchemaIntrospectionConfiguration());
  +        writer.write(schema);
  +        
  +        String xsd = out.getBuffer().toString();
  +        return xsd;
  +    }
  +    
  +    public void testRSS() throws Exception {
  +        String xsd = generateRSSSchema();
  +        StringWriter out = new StringWriter();
  +        out.write("<?xml version='1.0'?>");
  +        BeanWriter writer = new BeanWriter(out);
  +        writer.getBindingConfiguration().setMapIDs(false);
  +        
  +        Channel channel = new Channel();
  +        channel.setTitle("Betwixt News");
  +        channel.setLink("http://jakarta.apache.org/commons/betwixt");
  +        channel.setDescription("Example feed themed on Betwixt news.");
  +        channel.setRating("(PICS-1.1 'http://www.rsac.org/ratingsv01.html'" +
            " 2 gen true comment 'RSACi North America Server'" +
            " for 'http://www.rsac.org' on '1996.04.16T08:15-0500'" +
            " r (n 0 s 0 v 0 l 0))");
  +        channel.setLanguage("en-UK");
  +        
  +        Image image = new Image();
  +        image.setTitle("Apache Feather");
  +        image.setURL("http://www.apache.org/images/asf_logo_wide.gif");
  +        image.setLink("http://www.apache.org");
  +        image.setWidth(100);
  +        image.setHeight(30);
  +        image.setDescription("Example image");
  +        channel.setImage(image);
  +
  +        Item itemOne = new Item();
  +        itemOne.setTitle("Betwixt now generates w3c schema!");
  +        itemOne.setLink("http://jakarta.apache.org/commons/betwixt");
  +        itemOne.setDescription("Example description");
  +        channel.addItem(itemOne);
  +
  +        Item itemTwo = new Item();
  +        itemTwo.setTitle("Another News Item");
  +        itemTwo.setLink("http://jakarta.apache.org/commons/betwixt");
  +        itemTwo.setDescription("Blah Blah Blah");
  +        channel.addItem(itemTwo);        
  +
  +        TextInput textInput = new TextInput();
  +        textInput.setTitle("Send");
  +        textInput.setDescription("Comments about Betwixt news");
  +        textInput.setName("Response text");
  +        textInput.setLink("http://jakarta.apache.org/commons/betwixt");
  +        channel.setTextInput(textInput);
  +
  +        writer.write(channel);
  +
           String xml = out.getBuffer().toString();
          
           xmlAssertIsValid(new InputSource(new StringReader(xml)), new InputSource(new StringReader(xsd)));  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org