[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-dev
Subject:    cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/schema TestSchemaTranscriber
From:       rdonkin () apache ! org
Date:       2004-01-31 15:38:09
Message-ID: 20040131153809.88962.qmail () minotaur ! apache ! org
[Download RAW message or body]

rdonkin     2004/01/31 07:38:09

  Modified:    betwixt/src/java/org/apache/commons/betwixt/schema Tag:
                        REFACTORING-BRANCH_2004-01-13 Attribute.java
                        ComplexType.java Element.java Schema.java
                        SimpleType.java
               betwixt/src/test/org/apache/commons/betwixt/schema Tag:
                        REFACTORING-BRANCH_2004-01-13
                        TestSchemaTranscriber.java
  Log:
  Added support for creation of models for very simple schema.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.2   +12 -4     \
jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/Attribute.java
  
  Index: Attribute.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/Attribute.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- Attribute.java	18 Jan 2004 12:34:21 -0000	1.1.2.1
  +++ Attribute.java	31 Jan 2004 15:38:09 -0000	1.1.2.2
  @@ -119,6 +119,10 @@
           type = string;
       }
   
  +    public int hashCode() {
  +        return 0;
  +    }
  +
       public boolean equals(Object obj) {
           boolean result = false;
           if (obj instanceof Attribute) {
  @@ -148,4 +152,8 @@
           return result;
       }
   
  +    public String toString() {
  +        return "<xsd:attribute name='" + name + "' type='" + type + "'/>";
  +    }
  +        
   }
  
  
  
  1.1.2.3   +33 -6     \
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.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- ComplexType.java	19 Jan 2004 21:19:36 -0000	1.1.2.2
  +++ ComplexType.java	31 Jan 2004 15:38:09 -0000	1.1.2.3
  @@ -62,6 +62,7 @@
   package org.apache.commons.betwixt.schema;
   
   import java.util.ArrayList;
  +import java.util.Iterator;
   import java.util.List;
   
   import org.apache.commons.betwixt.AttributeDescriptor;
  @@ -90,7 +91,7 @@
        * @param elementDescriptor
        */
       public ComplexType(ElementDescriptor elementDescriptor) {
  -        setName(elementDescriptor.getClass().getName());
  +        setName(elementDescriptor.getPropertyType().getName());
           AttributeDescriptor[] attributeDescriptors = \
                elementDescriptor.getAttributeDescriptors();
           for (int i=0,length=attributeDescriptors.length; i<length ; i++) {
               //TODO: need to think about computing schema types from descriptors
  @@ -98,7 +99,11 @@
               attributes.add(new Attribute(attributeDescriptors[i]));
           }
           
  -        
  +        ElementDescriptor[] elementDescriptors = \
elementDescriptor.getElementDescriptors();  +        //TODO: add support for \
referenced complex classes  +        for (int i=0,length=elementDescriptors.length; \
i<length ; i++) {  +            elements.add(new Element(elementDescriptors[i]));
  +        }       
       }
   
   	/**
  @@ -161,6 +166,10 @@
             return result;
         }
   
  +    public int hashCode() {
  +        return 0;
  +    }
  +
         /**
          * Null safe equals method
          * @param one
  @@ -178,5 +187,23 @@
             }
           
             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();
         }
   }
  
  
  
  1.1.2.2   +25 -5     \
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.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- Element.java	18 Jan 2004 12:35:57 -0000	1.1.2.1
  +++ Element.java	31 Jan 2004 15:38:09 -0000	1.1.2.2
  @@ -88,7 +88,7 @@
       }
       
       public Element(ElementDescriptor elementDescriptor) {
  -        
  +        this(elementDescriptor.getLocalName(), "xsd:string");
       }
       
   
  @@ -151,6 +151,10 @@
   		}
   		return result;
   	}
  +    
  +    public int hashCode() {
  +        return 0;
  +    }
   
   	/**
   	 * Null safe equals method
  @@ -170,5 +174,21 @@
   		
   		return result;
   	}
  +
  +    public String toString() {
  +        StringBuffer buffer = new StringBuffer();
  +        buffer.append("<xsd:element name='");
  +        buffer.append(name);
  +        buffer.append("' type='");
  +        buffer.append(type);
  +        buffer.append("'>");
  +        
  +        if (complexType != null) {
  +            buffer.append(complexType);
  +        }
  +        buffer.append("</xsd:element>");
  +        return buffer.toString();
  +    }
  +
   
   }
  
  
  
  1.1.2.2   +31 -5     \
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.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- Schema.java	18 Jan 2004 12:35:08 -0000	1.1.2.1
  +++ Schema.java	31 Jan 2004 15:38:09 -0000	1.1.2.2
  @@ -62,6 +62,8 @@
   package org.apache.commons.betwixt.schema;
   
   import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Iterator;
   import java.util.List;
   
   import org.apache.commons.betwixt.ElementDescriptor;
  @@ -140,7 +142,7 @@
           // use the fully qualified class name as the type name
           Element element = new Element(
                               elementDescriptor.getLocalName(), 
  -                            elementDescriptor.getClass().getName());
  +                            elementDescriptor.getPropertyType().getName());
           addElement(element);
           
           ComplexType type = new ComplexType(elementDescriptor);
  @@ -159,5 +161,29 @@
           return result;
       }
   
  +    public int hashCode() {
  +        return 0;
  +    }
  +
   
  +    public String toString() {
  +        StringBuffer buffer = new StringBuffer();
  +        buffer.append("<?xml version='1.0'?>");
  +        buffer.append("<xsd:schema \
xmlns:xsd='http://www.w3c.org/2001/XMLSchema'>");  +        
  +        for (Iterator it=simpleTypes.iterator(); it.hasNext();) {
  +              buffer.append(it.next());    
  +        }    
  +        
  +        for (Iterator it=complexTypes.iterator(); it.hasNext();) {
  +              buffer.append(it.next());    
  +        }
  +        
  +  
  +        for (Iterator it=elements.iterator(); it.hasNext();) {
  +              buffer.append(it.next());    
  +        } 
  +        buffer.append("</xsd:schema>");
  +        return buffer.toString();
  +    }
   }
  
  
  
  1.1.2.2   +15 -6     \
jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/SimpleType.java
  
  Index: SimpleType.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Attic/SimpleType.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- SimpleType.java	18 Jan 2004 12:36:09 -0000	1.1.2.1
  +++ SimpleType.java	31 Jan 2004 15:38:09 -0000	1.1.2.2
  @@ -84,8 +84,8 @@
        * Sets the name
        * @param string
        */
  -    public void setName(String string) {
  -        name = string;
  +    public void setName(String name) {
  +        this.name = name;
       }
   
       public boolean equals(Object obj) {
  @@ -97,6 +97,11 @@
             return result;
         }
   
  +    public int hashCode() {
  +        return 0;
  +    }
  +
  +
         /**
          * Null safe equals method
          * @param one
  @@ -114,5 +119,9 @@
             }
           
             return result;
  +      }
  +      
  +      public String toString() {
  +          return "<xsd:simpleType name='" + name +  "'/>";
         }
   }
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +45 -17    \
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.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- TestSchemaTranscriber.java	18 Jan 2004 12:35:42 -0000	1.1.2.1
  +++ TestSchemaTranscriber.java	31 Jan 2004 15:38:09 -0000	1.1.2.2
  @@ -69,34 +69,62 @@
    * @version $Revision$
    */
   public class TestSchemaTranscriber extends AbstractTestCase {
  -	
  -	private static final String SIMPLE_BEAN_SCHEMA =
  -	  "<?xml version='1.0'?>" +	  "<xsd:schema \
                xmlns:xsd='http://www.w3c.org/2001/XMLSchema'>" +
  -	  "<xsd:element name='simple' type='SimpleBean'/>'" +
  -	  "<xsd:complexType name='SimpleBean'>" +
  -	  "<xsd:sequence>" +
  -	  "<xsd:element name='three' type='xsd:string'/>" +	  "<xsd:element name='four' \
                type='xsd:string'/>" +	  "</xsd:sequence>" + 
  -	  "<xsd:attribute name='one' type='xsd:string'/>" +
  -	  "<xsd:attribute name='two' type='xsd:string'/>" +	  "</xsd:complexType>" +	  \
                "</xsd:schema>";
  -	
  +    
       public TestSchemaTranscriber(String testName) {
           super(testName);
       }
   	
       public void testEmpty() {}
       
  -	public void _testSimpleBean() throws Exception {
  +    public void testSimplestBeanAttribute() throws Exception {
  +        Schema expected = new Schema();
  +        
  +        ComplexType simplestBeanType = new ComplexType();
  +        simplestBeanType.setName("org.apache.commons.betwixt.schema.SimplestBean");
  +        simplestBeanType.addAttribute(new Attribute("name", "xsd:string"));
  +        
  +        Element root = new Element("SimplestBean", \
"org.apache.commons.betwixt.schema.SimplestBean");  +        \
expected.addComplexType(simplestBeanType);  +        expected.addElement(root);
  +        
  +        SchemaTranscriber transcriber = new SchemaTranscriber();
  +        transcriber.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
  +        Schema out = transcriber.generate(SimplestBean.class);
  +        
  +        assertEquals("Simplest bean schema", expected, out);
  +    }
  +    
  +    public void testSimplestBeanElement() throws Exception {
  +        Schema expected = new Schema();
  +        
  +        ComplexType simplestBeanType = new ComplexType();
  +        simplestBeanType.setName("org.apache.commons.betwixt.schema.SimplestBean");
  +        simplestBeanType.addElement(new Element("name", "xsd:string"));
  +        
  +        Element root = new Element("SimplestBean", \
"org.apache.commons.betwixt.schema.SimplestBean");  +        \
expected.addComplexType(simplestBeanType);  +        expected.addElement(root);
  +        
  +        SchemaTranscriber transcriber = new SchemaTranscriber();
  +        transcriber.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
  +        Schema out = transcriber.generate(SimplestBean.class);
  +        
  +        assertEquals("Simplest bean schema", expected, out);
  +    }
  +    
  +	public void testSimpleBean() throws Exception {
   		SchemaTranscriber transcriber = new SchemaTranscriber();
   		Schema out = transcriber.generate(SimpleBean.class);
   		
   		Schema expected = new Schema();
   		ComplexType simpleBeanType = new ComplexType();
  -		simpleBeanType.setName("SimpleBean");
  -		simpleBeanType.addAttribute(new Attribute("one", "xsd:string"));
  +		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 Element("three", "xsd:string"));
   		simpleBeanType.addElement(new Element("four", "xsd:string"));
   		expected.addComplexType(simpleBeanType);
  +        expected.addElement(new Element("simple", \
"org.apache.commons.betwixt.schema.SimpleBean"));  
           assertEquals("Simple bean schema", expected, out);
           
  
  
  

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic