<html>
<head>
<style><!--
  body {background-color:#ffffff;}
  .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
  .pathname {font-family:monospace; float:right;}
  .fileheader {margin-bottom:.5em;}
  .diff {margin:0;}
  .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
  .tasklist ul {margin-top:0;margin-bottom:0;}
  tr.alt {background-color:#eeeeee}
  #added {background-color:#ddffdd;}
  #addedchars {background-color:#99ff99;font-weight:bolder;}
  tr.alt #added {background-color:#ccf7cc;}
  #removed {background-color:#ffdddd;}
  #removedchars {background-color:#ff9999;font-weight:bolder;}
  tr.alt #removed {background-color:#f7cccc;}
  #copied {background-color:#ccccff;}
  tr.alt #copied {background-color:#bbbbf7;}
  #info {color:#888888;}
  #context {background-color:#eeeeee;}
  td {padding-left:.3em;padding-right:.3em;}
  tr.head {border-bottom-width:1px;border-bottom-style:solid;}
  tr.head td {padding:0;padding-top:.2em;}
  .task {background-color:#ffff00;}
  .comment {white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;padding:4px;border:1px dashed #000000;background-color:#ffffdd}
  .error {color:red;}
  hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="5">Commit in <b><tt>asxsd/trunk/src</tt></b></td></tr>
<tr><td><tt>main/java/uk/co/badgersinfoil/asxsd/components/<a href="#file1">ArrayTypeDeclarationComponent.java</a></tt> </td><td></td><td align="right" id="added">+85</td><td align="right" id="removed">-4</td><td nowrap="nowrap" align="center">182 -&gt; 183</td></tr>
<tr class="alt"><td><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/<a href="#file2">ElementDeclarationComponent.java</a></tt> </td><td></td><td align="right" id="added">+37</td><td align="right" id="removed">-7</td><td nowrap="nowrap" align="center">182 -&gt; 183</td></tr>
<tr><td><tt>test/java/uk/co/badgersinfoil/asxsd/schemas/<a href="#file3">ArrayPatternCTypeTest.java</a></tt> </td><td></td><td align="right" id="added">+4</td><td align="right" id="removed">-1</td><td nowrap="nowrap" align="center">182 -&gt; 183</td></tr>
<tr class="alt"><td><tt>test/resources/xsd/<a href="#file4">ArrayPatternCTypeTest.xsd</a></tt> </td><td></td><td align="right" id="added">+16</td><td align="right" id="removed">-3</td><td nowrap="nowrap" align="center">182 -&gt; 183</td></tr>
<tr><td></td><td></td><td align="right" id="added">+142</td><td align="right" id="removed">-15</td><td></td></tr>
</table>
<small id="info">4 modified files</small><br />
<pre class="comment">
Get top-level complexTypes implementing the 'array' pattern to work again.
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd/components</span><br />
<div class="fileheader"><big><b>ArrayTypeDeclarationComponent.java</b></big> <small id="info">182 -&gt; 183</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/ArrayTypeDeclarationComponent.java        2007-11-11 23:16:43 UTC (rev 182)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/ArrayTypeDeclarationComponent.java        2007-11-11 23:29:59 UTC (rev 183)
@@ -8,17 +8,23 @@
</small></pre><pre class="diff" id="context"> import org.eclipse.xsd.XSDElementDeclaration;
 import org.eclipse.xsd.XSDSimpleTypeDefinition;
 import org.eclipse.xsd.XSDTypeDefinition;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.asxsd.BasicMappingFunction;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.asxsd.CodegenContext;
 import uk.co.badgersinfoil.asxsd.CodegenRole;
 import uk.co.badgersinfoil.asxsd.MappingFunction;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.asxsd.MarshalBuilder;
+import uk.co.badgersinfoil.asxsd.StringUtils;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.asxsd.TypeBuilder;
 import uk.co.badgersinfoil.asxsd.TypeDescriptor;
 import uk.co.badgersinfoil.asxsd.UnmarshalBuilder;
 import uk.co.badgersinfoil.asxsd.XSDUtils;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.dom.ASArg;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.ASClassType;
 import uk.co.badgersinfoil.metaas.dom.ASCompilationUnit;
 import uk.co.badgersinfoil.metaas.dom.ASConstants;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.dom.ASMethod;
</pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.StatementContainer;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.dom.Visibility;
</pre><pre class="diff" id="context"> 
 public class ArrayTypeDeclarationComponent extends AbstractMappingComponent {
 
</pre><pre class="diff"><small id="info">@@ -56,8 +62,7 @@
</small></pre><pre class="diff" id="context">                         String elementType = context.typeDescriptorFor(listElement).getTypeName();
                         String fieldAccess = "_result";
                         String childVarName = "_child";
</pre><pre class="diff" id="removed">-                        StatementContainer loop = block.newForEachIn("var "+childVarName+":"+elementType, "thisObject"
-                        );
</pre><pre class="diff" id="added">+                        StatementContainer loop = block.newForEachIn("var "+childVarName+":"+elementType, "thisObject");
</pre><pre class="diff" id="context">                         String access = "_"+context.variableNameFor(listElement);
                         loop.addStmt("var "+access + ":XML = &lt;"+listElement.getName()+"/&gt;");
                         if (listElement.getType() instanceof XSDSimpleTypeDefinition) {
</pre><pre class="diff"><small id="info">@@ -81,7 +86,13 @@
</small></pre><pre class="diff" id="context">                         block.addStmt("var _children:XMLList = thisElement.elements()");
                         StatementContainer loop = block.newForEachIn("var _child:XML", "_children");
                         MappingFunction conv = context.functionFor(listElement);
</pre><pre class="diff" id="removed">-                        String converted = conv.appliedTo("_child");
</pre><pre class="diff" id="added">+                        String access;
+                        if (listElement.getType() instanceof XSDSimpleTypeDefinition) {
+                                access = "_child.text()";
+                        } else {
+                                access = "_child";
+                        }
+                        String converted = conv.appliedTo(access);
</pre><pre class="diff" id="context">                         loop.addStmt("_result.push("+converted+")");
                         block.addStmt("return _result");
                 } else {
</pre><pre class="diff"><small id="info">@@ -92,11 +103,81 @@
</small></pre><pre class="diff" id="context">         public MappingFunction createFunctionRef(CodegenContext context,
                                                  XSDConcreteComponent component)
         {
</pre><pre class="diff" id="added">+                XSDTypeDefinition typeDef = (XSDTypeDefinition)component;
</pre><pre class="diff" id="context">                 CodegenRole role = context.getCurrentRole();
</pre><pre class="diff" id="added">+                if (role == CodegenRole.MARSHAL) {
+                        MarshalBuilder builder = context.getMarshalBuilder();
+                        ASCompilationUnit unit = builder.getClassForNamespace(typeDef.getTargetNamespace());
+                        ASClassType clazz = (ASClassType)unit.getType();
+                        String name = StringUtils.sanitize(typeDef.getName());
+                        String methodName = "marshal" + name;
+                        String qname;
+                        if (unit.getPackageName() != null) {
+                                qname = unit.getPackageName()+"."+clazz.getName()+"."+methodName;
+                        } else {
+                                qname = clazz.getName()+"."+methodName;
+                        }
+                        return new BasicMappingFunction(qname);
+                }
</pre><pre class="diff" id="context">                 if (role == CodegenRole.UNMARSHAL) {
                         UnmarshalBuilder builder = context.getUnmarshalBuilder();
</pre><pre class="diff" id="removed">-        //                return builder.createMethodForType((XSDTypeDefinition)component);
</pre><pre class="diff" id="added">+                        ASCompilationUnit unit = builder.getClassForNamespace(typeDef.getTargetNamespace());
+                        ASClassType clazz = (ASClassType)unit.getType();
+                        String name = StringUtils.sanitize(typeDef.getName());
+                        String methodName = "unmarshal" + name;
+                        String qname;
+                        if (unit.getPackageName() != null) {
+                                qname = unit.getPackageName()+"."+clazz.getName()+"."+methodName;
+                        } else {
+                                qname = clazz.getName()+"."+methodName;
+                        }
+                        return new BasicMappingFunction(qname);
</pre><pre class="diff" id="context">                 }
                 return super.createFunctionRef(context, component);
         }
</pre><pre class="diff" id="added">+
+        public ASMethod createFunction(CodegenContext context,
+                                       XSDConcreteComponent component)
+        {
+                XSDTypeDefinition typeDef = (XSDTypeDefinition)component;
+                CodegenRole role = context.getCurrentRole();
+                if (role == CodegenRole.MARSHAL) {
+                        MarshalBuilder builder = context.getMarshalBuilder();
+                        ASCompilationUnit unit = builder.getClassForNamespace(typeDef.getTargetNamespace());
+                        ASClassType clazz = (ASClassType)unit.getType();
+                        String name = StringUtils.sanitize(typeDef.getName());
+                        String methodName = "marshal" + name;
+                        TypeDescriptor typeDesc = context.typeDescriptorFor(typeDef);
+                        ASMethod meth = clazz.newMethod(methodName, Visibility.PUBLIC, "XML");
+                        ASArg resultArg = meth.addParam("_result", "XML");
+                        ASArg arg = meth.addParam("thisObject", typeDesc.getTypeName());
+                        meth.setStatic(true);
+                        context.pushAttrScope();
+                        context.setCurrentMethodCode(meth);
+                        UnmarshalBuilder.setCurrentSourceExpr(context, arg.getName());
+                        context.generateCode(typeDef);
+                        context.popAttrScope();
+                        return meth;
+                }
+                if (role == CodegenRole.UNMARSHAL) {
+                        UnmarshalBuilder builder = context.getUnmarshalBuilder();
+                        ASCompilationUnit unit = builder.getClassForNamespace(typeDef.getTargetNamespace());
+                        ASClassType clazz = (ASClassType)unit.getType();
+                        String name = StringUtils.sanitize(typeDef.getName());
+                        String methodName = "unmarshal" + name;
+                        TypeDescriptor typeDesc = context.typeDescriptorFor(typeDef);
+                        ASMethod meth = clazz.newMethod(methodName, Visibility.PUBLIC, typeDesc.getTypeName());
+                        ASArg arg = meth.addParam("thisElement", "XML");
+                        String doc = "a element of type "+typeDef.getURI();
+                        arg.setDescription(doc);
+                        meth.setStatic(true);
+                        context.pushAttrScope();
+                        context.setCurrentMethodCode(meth);
+                        UnmarshalBuilder.setCurrentSourceExpr(context, arg.getName());
+                        context.generateCode(typeDef);
+                        context.popAttrScope();
+                        return meth;
+                }
+                return super.createFunction(context, component);
+        }
</pre><pre class="diff" id="context"> }
</pre><pre class="diff"><small id="info">\ No newline at end of file
</small></pre></div>
<hr /><a name="file2" /><div class="file">
<span class="pathname">asxsd/trunk/src/main/java/uk/co/badgersinfoil/asxsd/components</span><br />
<div class="fileheader"><big><b>ElementDeclarationComponent.java</b></big> <small id="info">182 -&gt; 183</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/ElementDeclarationComponent.java        2007-11-11 23:16:43 UTC (rev 182)
+++ trunk/src/main/java/uk/co/badgersinfoil/asxsd/components/ElementDeclarationComponent.java        2007-11-11 23:29:59 UTC (rev 183)
@@ -107,13 +107,33 @@
</small></pre><pre class="diff" id="context">                 if (role == CodegenRole.UNMARSHAL) {
                         XSDTypeDefinition typeDef = elementDecl.getType();
                         StatementContainer block = context.getCurrentMethodCode();
</pre><pre class="diff" id="added">+                        String accessExpr = UnmarshalBuilder.getCurrentSourceExpr(context);
</pre><pre class="diff" id="context">                         if (typeDef instanceof XSDComplexTypeDefinition) {
</pre><pre class="diff" id="removed">-                                block.addStmt("default xml namespace = NAMESPACE");
-                                TypeDescriptor typeDesc = context.typeDescriptorFor(component);
-                                block.addStmt("var _result:"+typeDesc.getTypeName()+" = new "+typeDesc.getTypeName()+"()");
-                                context.generateCode(typeDef);
</pre><pre class="diff" id="added">+                                if (elementDecl.isGlobal()) {
+                                        TypeDescriptor typeDesc = context.typeDescriptorFor(component);
+                                        block.addStmt("var _result:"+typeDesc.getTypeName()+" = new "+typeDesc.getTypeName()+"()");
+                                        context.generateCode(typeDef);
+                                } else {
+                                        if (isCurrentFuctionElement(context, elementDecl)) {
+                                                TypeDescriptor typeDesc = context.typeDescriptorFor(typeDef);
+                                                block.addStmt("var _result:"+typeDesc.getTypeName()+" = new "+typeDesc.getTypeName()+"()");
+                                                context.generateCode(typeDef);
+                                        } else {
+                                                String result = "_result";
+                                                String propertyName = context.variableNameFor(elementDecl);
+                                                String targetExpr = result+"."+propertyName;
+                                                MappingFunction conv = context.functionFor(elementDecl);
+                                                block.addStmt(targetExpr + " = " + conv.appliedTo(accessExpr));
+                                        }
+                                }
</pre><pre class="diff" id="context">                         } else {
</pre><pre class="diff" id="removed">-                                throw new IllegalArgumentException(typeDef.toString());
</pre><pre class="diff" id="added">+                                MappingFunction conv;
+                                if (XSDUtils.isAnonymous(typeDef)) {
+                                        conv = context.functionFor(elementDecl);
+                                } else {
+                                        conv = context.functionFor(typeDef);
+                                }
+                                block.addStmt("return "+conv.appliedTo(accessExpr + ".text()"));
</pre><pre class="diff" id="context">                         }
                 } else if (role == CodegenRole.MARSHAL) {
                         XSDTypeDefinition typeDef = elementDecl.getType();
</pre><pre class="diff"><small id="info">@@ -141,8 +161,13 @@
</small></pre><pre class="diff" id="context">                                 String targetParentExpr = MarshalBuilder.getCurrentTargetParentElementExpr(context);
                                 block.addStmt("var "+propertyName+":XML = &lt;"+elementDecl.getName()+"/&gt;");
                                 MappingFunction conv = context.functionFor(elementDecl);
</pre><pre class="diff" id="removed">-                                String converted = conv.appliedTo(accessExpr);
-                                block.addStmt(propertyName+".appendChild("+converted+")");
</pre><pre class="diff" id="added">+                                if (typeDef instanceof XSDSimpleTypeDefinition || XSDUtils.isAnonymous(typeDef)) {
+                                        String converted = conv.appliedTo(accessExpr);
+                                        block.addStmt(propertyName+".appendChild("+converted+")");
+                                } else {
+                                        String converted = conv.appliedTo(propertyName+", "+accessExpr);
+                                        block.addStmt(converted);
+                                }
</pre><pre class="diff" id="context">                                 block.addStmt(targetParentExpr+".appendChild("+propertyName+")");
                         }
                 } else if (role == CodegenRole.TYPE) {
</pre><pre class="diff"><small id="info">@@ -206,7 +231,12 @@
</small></pre><pre class="diff" id="context">                                 meth.setVisibility(Visibility.PRIVATE);
                         }
                         meth.setStatic(true);
</pre><pre class="diff" id="added">+                        XSDTypeDefinition typeDef = elementDecl.getType();
+                        if (typeDef instanceof XSDComplexTypeDefinition) {
+                                meth.addStmt("default xml namespace = NAMESPACE");
+                        }
</pre><pre class="diff" id="context">                         context.pushAttrScope();
</pre><pre class="diff" id="added">+                        setCurrentFuctionElement(context, elementDecl);
</pre><pre class="diff" id="context">                         UnmarshalBuilder.setCurrentSourceExpr(context, arg.getName());
                         context.setCurrentMethodCode(meth);
                         context.generateCode(elementDecl);
</pre></div>
<hr /><a name="file3" /><div class="file">
<span class="pathname">asxsd/trunk/src/test/java/uk/co/badgersinfoil/asxsd/schemas</span><br />
<div class="fileheader"><big><b>ArrayPatternCTypeTest.java</b></big> <small id="info">182 -&gt; 183</small></div>
<pre class="diff"><small id="info">--- trunk/src/test/java/uk/co/badgersinfoil/asxsd/schemas/ArrayPatternCTypeTest.java        2007-11-11 23:16:43 UTC (rev 182)
+++ trunk/src/test/java/uk/co/badgersinfoil/asxsd/schemas/ArrayPatternCTypeTest.java        2007-11-11 23:29:59 UTC (rev 183)
@@ -10,7 +10,10 @@
</small></pre><pre class="diff" id="context">                 ASClassType clazz = (ASClassType)unit.getType();
                 assertEquals("Test", clazz.getName());
                 
</pre><pre class="diff" id="removed">-                ASField field = clazz.getField("testArray");
</pre><pre class="diff" id="added">+                ASField field = clazz.getField("testArray<span id="addedchars">1</span>");
</pre><pre class="diff" id="context">                 assertEquals("Array", field.getType());
</pre><pre class="diff" id="added">+                
+                ASField field2 = clazz.getField("testArray2");
+                assertEquals("Array", field2.getType());
</pre><pre class="diff" id="context">         }
 }
</pre></div>
<hr /><a name="file4" /><div class="file">
<span class="pathname">asxsd/trunk/src/test/resources/xsd</span><br />
<div class="fileheader"><big><b>ArrayPatternCTypeTest.xsd</b></big> <small id="info">182 -&gt; 183</small></div>
<pre class="diff"><small id="info">--- trunk/src/test/resources/xsd/ArrayPatternCTypeTest.xsd        2007-11-11 23:16:43 UTC (rev 182)
+++ trunk/src/test/resources/xsd/ArrayPatternCTypeTest.xsd        2007-11-11 23:29:59 UTC (rev 183)
@@ -1,12 +1,15 @@
</small></pre><pre class="diff" id="context"> &lt;schema xmlns="http://www.w3.org/2001/XMLSchema"
</pre><pre class="diff" id="removed">-           elementFormDefault="qualified"
-           targetNamespace="http://example.org/test"&gt;
</pre><pre class="diff" id="added">+        xmlns:t="http://example.org/test"
+        elementFormDefault="qualified"
+        targetNamespace="http://example.org/test"&gt;
</pre><pre class="diff" id="context"> 
   &lt;!-- demos the 'array' Schema Design Pattern --&gt;
 
   &lt;complexType name="Test"&gt;
     &lt;sequence&gt;
</pre><pre class="diff" id="removed">-      &lt;element name="testArray"&gt;
</pre><pre class="diff" id="added">+
+      &lt;!-- 1: local type def --&gt;
+      &lt;element name="testArray1"&gt;
</pre><pre class="diff" id="context">         &lt;complexType&gt;
           &lt;sequence&gt;
             &lt;element name="test" type="string"
</pre><pre class="diff"><small id="info">@@ -14,6 +17,16 @@
</small></pre><pre class="diff" id="context">           &lt;/sequence&gt;
         &lt;/complexType&gt;
       &lt;/element&gt;
</pre><pre class="diff" id="added">+
+      &lt;!-- 2: reference to global type def --&gt;
+      &lt;element name="testArray2" type="t:ArrayOfStuff"/&gt;
+
</pre><pre class="diff" id="context">     &lt;/sequence&gt;
   &lt;/complexType&gt;
</pre><pre class="diff" id="added">+
+  &lt;complexType name="ArrayOfStuff"&gt;
+    &lt;sequence&gt;
+      &lt;element name="entry" type="int" maxOccurs="unbounded"/&gt;
+    &lt;/sequence&gt;
+  &lt;/complexType&gt;
</pre><pre class="diff" id="context"> &lt;/schema&gt;
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.12</small></center>
</body></html>