xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From david...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases BindingTests.java
Date Tue, 07 Oct 2003 20:29:23 GMT
davidbau    2003/10/07 13:29:22

  Modified:    v2/src/binding/org/apache/xmlbeans/impl/binding
                        BindingProperty.java BindingType.java
                        ByNameBean.java JaxbBean.java ParticleProperty.java
                        PathBindingLoader.java QNameProperty.java
               v2/src/configschema/schema binding-config.xsd
               v2/test/src/drt/drtcases BindingTests.java
  Added:       v2/src/binding/org/apache/xmlbeans/impl/binding
                        BuiltinBindingLoader.java BuiltinBindingType.java
                        SimpleBindingType.java
  Log:
  OK, so I'm
  
  (1) adding something for simple-type bindings to be able to be represented
      in a binding file.
  
  (2) adding a dummy table of builtin bindings that we will know about
      (BuiltingBindingLoader)
  
  (3) removing the requirement that a BindingTypeLoader be supplied in the ctor
      for every BindingType etc.  The idea is that I'm keeping type references
      purely by-name, to be resolved at the last minute when you know the exact
      BindingTypeLoader you're using, rather than by-reference, which would
      require early resolution, and reduce flexibility.
  
  Code-review: scott
  DRT: passed
  
  Revision  Changes    Path
  1.2       +8 -12     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/BindingProperty.java
  
  Index: BindingProperty.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/BindingProperty.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BindingProperty.java	3 Oct 2003 21:18:18 -0000	1.1
  +++ BindingProperty.java	7 Oct 2003 20:29:22 -0000	1.2
  @@ -9,10 +9,8 @@
   
   public abstract class BindingProperty
   {
  -    private BindingLoader bLoader;
  -    
       private JavaName tJava;
  -    private XmlName tXml;
  +    protected XmlName tXml;
       private String getter;
       private String setter;
       private String field;
  @@ -23,9 +21,8 @@
        * 
        * Subclasses should call super(..) when defining constructors that init new BindingTypes.
        */ 
  -    protected BindingProperty(BindingLoader bFile)
  +    protected BindingProperty()
       {
  -        this.bLoader = bFile;
       }
       
       /**
  @@ -33,9 +30,8 @@
        * 
        * Subclasses should have ctors of the same signature and call super(..) first.
        */ 
  -    protected BindingProperty(BindingLoader bLoader, org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty
node)
  +    protected BindingProperty(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty
node)
       {
  -        this.bLoader = bLoader;
           this.tJava = JavaName.forString(node.getJavatype());
           this.tXml = XmlName.forString(node.getXmlcomponent());
           this.getter = node.getGetter();
  @@ -73,9 +69,9 @@
           return field != null;
       }
       
  -    public BindingType getBindingType()
  +    public BindingType getBindingType(BindingLoader loader)
       {
  -        return bLoader.getBindingType(tJava, tXml);
  +        return loader.getBindingType(tJava, tXml);
       }
       
       public void setBindingType(BindingType bType)
  @@ -131,14 +127,14 @@
       
       /* REGISTRY OF SUBCLASSES */
       
  -    private static final Class[] ctorArgs = new Class[] {BindingLoader.class, org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty.class};
  +    private static final Class[] ctorArgs = new Class[] {org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty.class};
       
  -    public static BindingProperty forNode(BindingLoader bLoader, org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty
node)
  +    public static BindingProperty forNode(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty
node)
       {
           try
           {
               Class clazz = kinds.classForType(node.schemaType());
  -            return (BindingProperty)clazz.getConstructor(ctorArgs).newInstance(new Object[]
{bLoader, node});
  +            return (BindingProperty)clazz.getConstructor(ctorArgs).newInstance(new Object[]
{node});
           }
           catch (Exception e)
           {
  
  
  
  1.2       +5 -12     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/BindingType.java
  
  Index: BindingType.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/BindingType.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BindingType.java	3 Oct 2003 21:18:18 -0000	1.1
  +++ BindingType.java	7 Oct 2003 20:29:22 -0000	1.2
  @@ -9,7 +9,6 @@
   
   public abstract class BindingType
   {
  -    private BindingLoader bLoader;
       private JavaName jName;
       private XmlName xName;
       private boolean isXmlObj;
  @@ -19,9 +18,8 @@
        * 
        * Subclasses should call super(..) when defining constructors that init new BindingTypes.
        */ 
  -    protected BindingType(BindingLoader bLoader, JavaName jName, XmlName xName, boolean
isXmlObj)
  +    protected BindingType(JavaName jName, XmlName xName, boolean isXmlObj)
       {
  -        this.bLoader = bLoader;
           this.jName = jName;
           this.xName = xName;
           this.isXmlObj = isXmlObj;
  @@ -32,9 +30,8 @@
        * 
        * Subclasses should have ctors of the same signature and call super(..) first.
        */ 
  -    protected BindingType(BindingLoader bLoader, org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType
node)
  +    protected BindingType(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
       {
  -        this.bLoader = bLoader;
           this.jName = JavaName.forString(node.getJavatype());
           this.xName = XmlName.forString(node.getXmlcomponent());
           this.isXmlObj = node.getXmlobj();
  @@ -54,11 +51,6 @@
           return node;
       }
       
  -    public final BindingLoader getBindingLoader()
  -    {
  -        return bLoader;
  -    }
  -    
       public final JavaName getJavaName()
       {
           return jName;
  @@ -77,14 +69,14 @@
       
       /* REGISTRY OF SUBCLASSES */
       
  -    private static final Class[] ctorArgs = new Class[] {BindingLoader.class, org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType.class};
  +    private static final Class[] ctorArgs = new Class[] {org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType.class};
       
       public static BindingType loadFromBindingTypeNode(BindingLoader bLoader, org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType
node)
       {
           try
           {
               Class clazz = kinds.classForType(node.schemaType());
  -            return (BindingType)clazz.getConstructor(ctorArgs).newInstance(new Object[]
{bLoader, node});
  +            return (BindingType)clazz.getConstructor(ctorArgs).newInstance(new Object[]
{node});
           }
           catch (Exception e)
           {
  @@ -110,6 +102,7 @@
       {
           registerClassAndType(JaxbBean.class, org.apache.xmlbeans.x2003.x09.bindingConfig.JaxbBean.type);
           registerClassAndType(ByNameBean.class, org.apache.xmlbeans.x2003.x09.bindingConfig.ByNameBean.type);
  +        registerClassAndType(SimpleBindingType.class, org.apache.xmlbeans.x2003.x09.bindingConfig.SimpleType.type);
       }
   
   }
  
  
  
  1.2       +5 -5      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/ByNameBean.java
  
  Index: ByNameBean.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/ByNameBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ByNameBean.java	3 Oct 2003 21:18:18 -0000	1.1
  +++ ByNameBean.java	7 Oct 2003 20:29:22 -0000	1.2
  @@ -20,21 +20,21 @@
       Map eltProps = new HashMap(); // QName -> prop (elts)
       Map attProps = new HashMap(); // QName -> prop (attrs)
       
  -    public ByNameBean(BindingLoader bLoader, JavaName jName, XmlName xName, boolean isXmlObj)
  +    public ByNameBean(JavaName jName, XmlName xName, boolean isXmlObj)
       {
  -        super(bLoader, jName, xName, isXmlObj);
  +        super(jName, xName, isXmlObj);
       }
   
  -    public ByNameBean(BindingLoader bFile, org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType
node)
  +    public ByNameBean(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
       {
  -        super(bFile, node);
  +        super(node);
           
           org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty[] propArray =
              ((org.apache.xmlbeans.x2003.x09.bindingConfig.ByNameBean)node).getQnamePropertyArray();
           
           for (int i = 0; i < propArray.length; i++)
           {
  -            addProperty((QNameProperty)BindingProperty.forNode(getBindingLoader(), propArray[i]));
  +            addProperty((QNameProperty)BindingProperty.forNode(propArray[i]));
           }
       }
       
  
  
  
  1.2       +7 -7      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/JaxbBean.java
  
  Index: JaxbBean.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/JaxbBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JaxbBean.java	3 Oct 2003 21:18:18 -0000	1.1
  +++ JaxbBean.java	7 Oct 2003 20:29:22 -0000	1.2
  @@ -20,27 +20,27 @@
       Map eltProps = new LinkedHashMap(); // QName -> prop (elts)
       Map attProps = new LinkedHashMap(); // QName -> prop (attrs)
       
  -    public JaxbBean(BindingLoader bFile, JavaName jName, XmlName xName)
  +    public JaxbBean(JavaName jName, XmlName xName)
       {
  -        super(bFile, jName, xName, false);
  +        super(jName, xName, false);
       }
   
  -    public JaxbBean(BindingLoader bFile, org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType
node)
  +    public JaxbBean(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
       {
  -        super(bFile, node);
  +        super(node);
           
           org.apache.xmlbeans.x2003.x09.bindingConfig.JaxbBean jbNode = (org.apache.xmlbeans.x2003.x09.bindingConfig.JaxbBean)node;
           
           org.apache.xmlbeans.x2003.x09.bindingConfig.ParticleProperty[] ppropArray = jbNode.getParticlePropertyArray();
           for (int i = 0; i < ppropArray.length; i++)
           {
  -            addProperty(BindingProperty.forNode(getBindingLoader(), ppropArray[i]));
  +            addProperty(BindingProperty.forNode(ppropArray[i]));
           }
           
           org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty[] qpropArray = jbNode.getQnamePropertyArray();
           for (int i = 0; i < qpropArray.length; i++)
           {
  -            addProperty(BindingProperty.forNode(getBindingLoader(), qpropArray[i]));
  +            addProperty(BindingProperty.forNode(qpropArray[i]));
           }
       }
       
  @@ -106,7 +106,7 @@
       {
           if (newProp instanceof ParticleProperty)
           {
  -            partProps.put(newProp.getBindingType().getXmlName(), newProp);
  +            partProps.put(((ParticleProperty)newProp).getXmlName(), newProp);
           }
           else if (newProp instanceof QNameProperty)
           {
  
  
  
  1.2       +9 -4      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/ParticleProperty.java
  
  Index: ParticleProperty.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/ParticleProperty.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParticleProperty.java	3 Oct 2003 21:18:18 -0000	1.1
  +++ ParticleProperty.java	7 Oct 2003 20:29:22 -0000	1.2
  @@ -7,13 +7,18 @@
   
   public class ParticleProperty extends BindingProperty
   {
  -    public ParticleProperty(BindingLoader bFile)
  +    public ParticleProperty()
       {
  -        super(bFile);
  +        super();
       }
   
  -    public ParticleProperty(BindingLoader bFile, org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty
node)
  +    public ParticleProperty(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty
node)
       {
  -        super(bFile, node);
  +        super(node);
  +    }
  +    
  +    public XmlName getXmlName()
  +    {
  +        return this.tXml;
       }
   }
  
  
  
  1.2       +15 -8     xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/PathBindingLoader.java
  
  Index: PathBindingLoader.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/PathBindingLoader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PathBindingLoader.java	3 Oct 2003 21:18:18 -0000	1.1
  +++ PathBindingLoader.java	7 Oct 2003 20:29:22 -0000	1.2
  @@ -11,27 +11,33 @@
   import java.util.IdentityHashMap;
   import java.util.Collections;
   import java.util.Collection;
  +import java.util.Arrays;
   
   public class PathBindingLoader extends BindingLoader
   {
       private final Collection loaderPath;
       public static final PathBindingLoader EMPTY_LOADER = new PathBindingLoader(Collections.EMPTY_LIST);
       
  -    public static BindingLoader forPath(BindingLoader[] pathArray)
  +    public static BindingLoader forPath(BindingLoader[] path)
  +    {
  +        return forPath(Arrays.asList(path));
  +    }
  +    
  +    public static BindingLoader forPath(Collection path)
       {
           IdentityHashMap seen = new IdentityHashMap();
           
  -        List path = new ArrayList(pathArray.length);
  -        for (int i = 0; i < pathArray.length; i++)
  -            addToPath(path, seen, pathArray[i]);
  +        List flattened = new ArrayList(path.size());
  +        for (Iterator i = path.iterator(); i.hasNext(); )
  +            addToPath(flattened, seen, (BindingLoader)i.next());
           
  -        if (path.size() == 0)
  +        if (flattened.size() == 0)
               return EMPTY_LOADER;
           
  -        if (path.size() == 1)
  -            return (BindingLoader)path.get(0);
  +        if (flattened.size() == 1)
  +            return (BindingLoader)flattened.get(0);
           
  -        return new PathBindingLoader(path);
  +        return new PathBindingLoader(flattened);
       }
       
       private static void addToPath(List path, IdentityHashMap seen, BindingLoader loader)
  @@ -99,3 +105,4 @@
           return null;
       }
   }
  +
  
  
  
  1.2       +4 -4      xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/QNameProperty.java
  
  Index: QNameProperty.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/QNameProperty.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- QNameProperty.java	3 Oct 2003 21:18:18 -0000	1.1
  +++ QNameProperty.java	7 Oct 2003 20:29:22 -0000	1.2
  @@ -15,14 +15,14 @@
       private boolean isOptional;
       private boolean isNillable;
       
  -    public QNameProperty(BindingLoader bFile)
  +    public QNameProperty()
       {
  -        super(bFile);
  +        super();
       }
   
  -    public QNameProperty(BindingLoader bFile, org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty
node)
  +    public QNameProperty(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingProperty node)
       {
  -        super(bFile, node);
  +        super(node);
           org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty qpNode =
                   (org.apache.xmlbeans.x2003.x09.bindingConfig.QnameProperty)node;
           theName = qpNode.getQname();
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/BuiltinBindingLoader.java
  
  Index: BuiltinBindingLoader.java
  ===================================================================
  /**
   * XBeans implementation.
   * Author: David Bau
   * Date: Oct 6, 2003
   */
  package org.apache.xmlbeans.impl.binding;
  
  import javax.xml.namespace.QName;
  import java.util.Map;
  import java.util.LinkedHashMap;
  
  public class BuiltinBindingLoader extends BindingLoader
  {
      private Map bindingTypes = new LinkedHashMap();    // name-pair -> BindingType
      private Map xmlFromJava = new LinkedHashMap();     // javaName -> xmlName
      private Map javaFromXmlPojo = new LinkedHashMap(); // xmlName -> javaName (pojo)
      private Map javaFromXmlObj = new LinkedHashMap();  // xmlName -> javaName (xmlobj)
      
      private static final String xsns = "http://www.w3.org/2001/XMLSchema";
      
      private void addMapping(String xmlType, String javaName, boolean pojo, boolean defaultForJava,
boolean defaultForXml)
      {
          XmlName xn = XmlName.forTypeNamed(new QName(xsns, xmlType));
          JavaName jn = JavaName.forString(javaName);
          BindingType bt = new BuiltinBindingType(jn, xn, !pojo);
          bindingTypes.put(new NamePair(jn, xn), bt);
          if (defaultForJava)
              xmlFromJava.put(jn, xn);
          if (defaultForXml)
          {
              if (pojo)
                  javaFromXmlPojo.put(xn, jn);
              else
                  javaFromXmlObj.put(xn, jn);
          }
      }
      
      private void addPojoTwoWay(String xmlType, String javaName)
      {
          addMapping(xmlType, javaName, true, true, true);
      }
  
      private void addPojoXml(String xmlType, String javaName)
      {
          addMapping(xmlType, javaName, true, false, true);
      }
      
      private void addPojoJava(String xmlType, String javaName)
      {
          addMapping(xmlType, javaName, true, true, false);
      }
      
      private void addPojo(String xmlType, String javaName)
      {
          addMapping(xmlType, javaName, true, true, false);
      }
  
      public BuiltinBindingLoader()
      {
          // todo: should each builtin binding type know about it's print/parse methods?
          
          addPojoXml("anySimpleType", "java.lang.String");
          
          addPojoTwoWay("string", "java.lang.String");
          addPojoXml("normalizedString", "java.lang.String");
          addPojoXml("token", "java.lang.String");
          addPojoXml("language", "java.lang.String");
          addPojoXml("Name", "java.lang.String");
          addPojoXml("NCName", "java.lang.String");
          addPojoXml("NMTOKEN", "java.lang.String");
          addPojoXml("ID", "java.lang.String");
          addPojoXml("IDREF", "java.lang.String");
          addPojoXml("ENTITY", "java.lang.String");
          
          addPojoTwoWay("duration", "org.apache.xmlbeans.GDuration");
          
          addPojoTwoWay("dateTime", "java.util.Calendar");
          addPojoJava("dateTime", "java.util.Date");
          addPojoXml("time", "java.util.Calendar");
          addPojoXml("date", "java.util.Calendar");
          addPojo("date", "java.util.Date");
          addPojoXml("gYearMonth", "java.util.Calendar");
          addPojoXml("gYear", "java.util.Calendar");
          addPojo("gYear", "int");
          addPojoXml("gMonthDay", "java.util.Calendar");
          addPojoXml("gMonth", "java.util.Calendar");
          addPojo("gMonth", "int");
          addPojoXml("gDay", "java.util.Calendar");
          addPojo("gDay", "int");
          
          addPojoTwoWay("boolean", "boolean");
          addPojoTwoWay("base64Binary", "byte[]");
          addPojoJava("base64Binary", "java.io.InputStream");
          addPojoXml("hexBinary", "byte[]");
          addPojo("hexBinary", "java.io.InputStream");
          addPojoTwoWay("float", "float");
          addPojoTwoWay("double", "double");
          addPojoTwoWay("decimal", "java.math.BigDecimal");
          addPojoTwoWay("integer", "java.math.BigInteger");
          addPojoTwoWay("long", "long");
          addPojoTwoWay("int", "int");
          addPojoTwoWay("short", "short");
          addPojoTwoWay("byte", "byte");
          addPojoXml("nonPositiveInteger", "java.math.BigInteger");
          addPojoXml("negativeInteger", "java.math.BigInteger");
          addPojoXml("nonNegativeInteger", "java.math.BigInteger");
          addPojoXml("positiveInteger", "java.math.BigInteger");
          addPojoXml("unsignedLong", "java.math.BigInteger");
          addPojoXml("unsignedInt", "long");
          addPojoXml("unsignedShort", "int");
          addPojoXml("unsignedByte", "short");
          addPojoXml("anyURI", "java.lang.String");
          addPojoJava("anyURI", "java.net.URI");
          addPojoTwoWay("QName", "javax.xml.namespace.QName");
          addPojoXml("NOTATION", "java.lang.String");
      }
  
      public BindingType getBindingType(JavaName jName, XmlName xName)
      {
          return null;
      }
  
      public BindingType getBindingTypeForXmlPojo(XmlName xName)
      {
          return null;
      }
  
      public BindingType getBindingTypeForXmlObj(XmlName xName)
      {
          return null;
      }
  
      public BindingType getBindingTypeForJava(JavaName jName)
      {
          return null;
      }
      
      private static class NamePair
      {
          private final JavaName jName;
          private final XmlName xName;
  
          NamePair(JavaName jName, XmlName xName)
          {
              this.jName = jName;
              this.xName = xName;
          }
  
          public JavaName getJavaName()
          {
              return jName;
          }
  
          public XmlName getXmlName()
          {
              return xName;
          }
  
          public boolean equals(Object o)
          {
              if (this == o) return true;
              if (!(o instanceof BuiltinBindingLoader.NamePair)) return false;
  
              final BuiltinBindingLoader.NamePair namePair = (BuiltinBindingLoader.NamePair)
o;
  
              if (!jName.equals(namePair.jName)) return false;
              if (!xName.equals(namePair.xName)) return false;
  
              return true;
          }
  
          public int hashCode()
          {
              int result;
              result = jName.hashCode();
              result = 29 * result + xName.hashCode();
              return result;
          }
      }
      
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/BuiltinBindingType.java
  
  Index: BuiltinBindingType.java
  ===================================================================
  /**
   * XBeans implementation.
   * Author: David Bau
   * Date: Oct 6, 2003
   */
  package org.apache.xmlbeans.impl.binding;
  
  public class BuiltinBindingType extends BindingType
  {
      // note: only this one constructor; builtin binding types can't be loaded
      public BuiltinBindingType(JavaName jName, XmlName xName, boolean isXmlObj)
      {
          super(jName, xName, isXmlObj);
      }
  }
  
  
  
  1.1                  xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/SimpleBindingType.java
  
  Index: SimpleBindingType.java
  ===================================================================
  /**
   * XBeans implementation.
   * Author: David Bau
   * Date: Oct 7, 2003
   */
  package org.apache.xmlbeans.impl.binding;
  
  public class SimpleBindingType extends BindingType
  {
      public SimpleBindingType(JavaName jName, XmlName xName, boolean isXmlObj)
      {
          super(jName, xName, isXmlObj);
      }
  
      public SimpleBindingType(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType node)
      {
          super(node);
          org.apache.xmlbeans.x2003.x09.bindingConfig.SimpleType stNode = (org.apache.xmlbeans.x2003.x09.bindingConfig.SimpleType)node;
          asIfXmlType = XmlName.forString(stNode.getAsXml());
      }
  
      protected org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType write(org.apache.xmlbeans.x2003.x09.bindingConfig.BindingType
node)
      {
          org.apache.xmlbeans.x2003.x09.bindingConfig.SimpleType stNode = (org.apache.xmlbeans.x2003.x09.bindingConfig.SimpleType)super.write(node);
          stNode.setAsXml(asIfXmlType.toString());
          return stNode;
      }
  
      private XmlName asIfXmlType;
  
      // typically the "as if" type is the closest base builtin type.
      public XmlName getAsIfXmlType()
      {
          return asIfXmlType;
      }
  
      public void setAsIfXmlType(XmlName asIfXmlType)
      {
          this.asIfXmlType = asIfXmlType;
      }
      
      // question: do we want an "as if Java type" as well?
      
      public BindingType getAsIfBindingType(BindingLoader loader)
      {
          return loader.getBindingType(getJavaName(), asIfXmlType);
      }
  }
  
  
  
  1.2       +10 -0     xml-xmlbeans/v2/src/configschema/schema/binding-config.xsd
  
  Index: binding-config.xsd
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/configschema/schema/binding-config.xsd,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- binding-config.xsd	3 Oct 2003 21:18:18 -0000	1.1
  +++ binding-config.xsd	7 Oct 2003 20:29:22 -0000	1.2
  @@ -43,6 +43,16 @@
         <!-- todo: maybe more java info, e.g., instanceType, is-interface, is-xmlobj etc?
-->
       </xs:sequence>
     </xs:complexType>
  +    
  +  <xs:complexType name="simple-type">
  +    <xs:complexContent>
  +      <xs:extension base="tns:binding-type">
  +        <xs:sequence>
  +          <xs:element name="as-xml" type="tns:xml-signature"/>
  +        </xs:sequence>
  +      </xs:extension>
  +    </xs:complexContent>
  +  </xs:complexType>
   
     <xs:complexType name="by-name-bean">
       <xs:complexContent>
  
  
  
  1.2       +32 -14    xml-xmlbeans/v2/test/src/drt/drtcases/BindingTests.java
  
  Index: BindingTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/drt/drtcases/BindingTests.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BindingTests.java	3 Oct 2003 21:18:18 -0000	1.1
  +++ BindingTests.java	7 Oct 2003 20:29:22 -0000	1.2
  @@ -10,11 +10,14 @@
   import junit.framework.TestSuite;
   import junit.framework.Assert;
   import org.apache.xmlbeans.impl.binding.BindingFile;
  -import org.apache.xmlbeans.impl.binding.BindingType;
   import org.apache.xmlbeans.impl.binding.ByNameBean;
   import org.apache.xmlbeans.impl.binding.JavaName;
   import org.apache.xmlbeans.impl.binding.XmlName;
   import org.apache.xmlbeans.impl.binding.QNameProperty;
  +import org.apache.xmlbeans.impl.binding.PathBindingLoader;
  +import org.apache.xmlbeans.impl.binding.BuiltinBindingLoader;
  +import org.apache.xmlbeans.impl.binding.BindingLoader;
  +import org.apache.xmlbeans.impl.binding.SimpleBindingType;
   import org.apache.xmlbeans.x2003.x09.bindingConfig.BindingConfigDocument;
   
   import javax.xml.namespace.QName;
  @@ -27,85 +30,100 @@
       public void testBindingFile() throws Exception
       {
           BindingFile bf = new BindingFile();
  +        BuiltinBindingLoader builtins = new BuiltinBindingLoader();
           
  -        ByNameBean bnb = new ByNameBean(bf, JavaName.forString("com.mytest.MyClass"), XmlName.forString("t=my-type@http://www.mytest.com/"),
false);
  +        // some complex types
  +        ByNameBean bnb = new ByNameBean(JavaName.forString("com.mytest.MyClass"), XmlName.forString("t=my-type@http://www.mytest.com/"),
false);
           bf.addBindingType(bnb, true, true);
  -        ByNameBean bnb2 = new ByNameBean(bf, JavaName.forString("com.mytest.YourClass"),
XmlName.forString("t=your-type@http://www.mytest.com/"), false);
  +        ByNameBean bnb2 = new ByNameBean(JavaName.forString("com.mytest.YourClass"), XmlName.forString("t=your-type@http://www.mytest.com/"),
false);
           bf.addBindingType(bnb2, true, true);
           
  +        // a custom simple type
  +        SimpleBindingType sbt = new SimpleBindingType(JavaName.forString("java.lang.String"),
XmlName.forString("t=custom-string@http://www.mytest.com/"), false);
  +        bf.addBindingType(sbt, false, true); // note not from-java-default for String
  +        
  +        
           // bnb
                           
  -        QNameProperty prop = new QNameProperty(bf);
  +        QNameProperty prop = new QNameProperty();
           prop.setQName(new QName("http://www.mytest.com/", "myelt"));
           prop.setSetterName("setMyelt");
           prop.setGetterName("getMyelt");
           prop.setBindingType(bnb2);
           bnb.addProperty(prop);
           
  -        prop = new QNameProperty(bf);
  +        prop = new QNameProperty();
           prop.setQName(new QName("http://www.mytest.com/", "myelt2"));
           prop.setSetterName("setMyelt2");
           prop.setGetterName("getMyelt2");
           prop.setBindingType(bnb);
           bnb.addProperty(prop);
           
  -        prop = new QNameProperty(bf);
  +        prop = new QNameProperty();
           prop.setQName(new QName("http://www.mytest.com/", "myatt"));
           prop.setSetterName("setMyatt");
           prop.setGetterName("getMyatt");
  -        prop.setBindingType(bnb); // need to do simples
  +        prop.setBindingType(sbt);
           bnb.addProperty(prop);
           
           // now bnb2
           
  -        prop = new QNameProperty(bf);
  +        prop = new QNameProperty();
           prop.setQName(new QName("http://www.mytest.com/", "yourelt"));
           prop.setSetterName("setYourelt");
           prop.setGetterName("getYourelt");
           prop.setBindingType(bnb2);
           bnb2.addProperty(prop);
           
  -        prop = new QNameProperty(bf);
  +        prop = new QNameProperty();
           prop.setQName(new QName("http://www.mytest.com/", "yourelt2"));
           prop.setSetterName("setYourelt2");
           prop.setGetterName("getYourelt2");
           prop.setBindingType(bnb);
           bnb2.addProperty(prop);
           
  +        // sbt
  +        sbt.setAsIfXmlType(XmlName.forString("t=string@http://www.w3.org/2001/XMLSchema"));
  +        
           // now serialize
           BindingConfigDocument doc = bf.write();
           System.out.println(doc.toString());
           
           // now load
           BindingFile bfc = BindingFile.forDoc(doc);
  +        BindingLoader lc = PathBindingLoader.forPath(new BindingLoader[] {builtins, bfc});
           ByNameBean bnbc = (ByNameBean)bfc.getBindingType(JavaName.forString("com.mytest.MyClass"),
XmlName.forString("t=my-type@http://www.mytest.com/"));
           ByNameBean bnb2c = (ByNameBean)bfc.getBindingType(JavaName.forString("com.mytest.YourClass"),
XmlName.forString("t=your-type@http://www.mytest.com/"));
  +        SimpleBindingType sbtc = (SimpleBindingType)bfc.getBindingType(JavaName.forString("java.lang.String"),
XmlName.forString("t=custom-string@http://www.mytest.com/"));
           
           // check bnb
           prop = bnbc.getPropertyForElement(new QName("http://www.mytest.com/", "myelt"));
           Assert.assertEquals("setMyelt", prop.getSetterName());
           Assert.assertEquals("getMyelt", prop.getGetterName());
  -        Assert.assertEquals(bnb2c, prop.getBindingType());
  +        Assert.assertEquals(bnb2c, prop.getBindingType(lc));
   
           prop = bnbc.getPropertyForElement(new QName("http://www.mytest.com/", "myelt2"));
           Assert.assertEquals("setMyelt2", prop.getSetterName());
           Assert.assertEquals("getMyelt2", prop.getGetterName());
  -        Assert.assertEquals(bnbc, prop.getBindingType());
  +        Assert.assertEquals(bnbc, prop.getBindingType(lc));
           
           prop = bnbc.getPropertyForElement(new QName("http://www.mytest.com/", "myatt"));
           Assert.assertEquals("setMyatt", prop.getSetterName());
           Assert.assertEquals("getMyatt", prop.getGetterName());
  -        Assert.assertEquals(bnbc, prop.getBindingType());
  +        Assert.assertEquals(sbtc, prop.getBindingType(lc));
           
           // check bnb2
           prop = bnb2c.getPropertyForElement(new QName("http://www.mytest.com/", "yourelt"));
           Assert.assertEquals("setYourelt", prop.getSetterName());
           Assert.assertEquals("getYourelt", prop.getGetterName());
  -        Assert.assertEquals(bnb2c, prop.getBindingType());
  +        Assert.assertEquals(bnb2c, prop.getBindingType(lc));
   
           prop = bnb2c.getPropertyForElement(new QName("http://www.mytest.com/", "yourelt2"));
           Assert.assertEquals("setYourelt2", prop.getSetterName());
           Assert.assertEquals("getYourelt2", prop.getGetterName());
  -        Assert.assertEquals(bnbc, prop.getBindingType());
  +        Assert.assertEquals(bnbc, prop.getBindingType(lc));
  +        
  +        // check sbtc
  +        Assert.assertEquals(XmlName.forString("t=string@http://www.w3.org/2001/XMLSchema"),
sbtc.getAsIfXmlType());
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org


Mime
View raw message